1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a semantic tree transformation that takes a given
10 // AST and rebuilds it, possibly transforming some nodes in the process.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
16
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/ExprOpenMP.h"
25 #include "clang/AST/Stmt.h"
26 #include "clang/AST/StmtCXX.h"
27 #include "clang/AST/StmtObjC.h"
28 #include "clang/AST/StmtOpenMP.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"
38 #include <algorithm>
39
40 namespace clang {
41 using namespace sema;
42
43 /// \brief A semantic tree transformation that allows one to transform one
44 /// abstract syntax tree into another.
45 ///
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.
54 ///
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.
60 ///
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
69 /// a new AST node.
70 ///
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.
76 ///
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.
87 ///
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>
95 class TreeTransform {
96 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
102
103 public:
ForgetPartiallySubstitutedPackRAII(Derived & Self)104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
107
~ForgetPartiallySubstitutedPackRAII()108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
112
113 protected:
114 Sema &SemaRef;
115
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;
120
121 public:
122 /// \brief Initializes a new tree transformer.
TreeTransform(Sema & SemaRef)123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
124
125 /// \brief Retrieves a reference to the derived class.
getDerived()126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
getDerived()129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
131 }
132
Owned(Expr * E)133 static inline ExprResult Owned(Expr *E) { return E; }
Owned(Stmt * S)134 static inline StmtResult Owned(Stmt *S) { return S; }
135
136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
getSema()138 Sema &getSema() const { return SemaRef; }
139
140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
145 ///
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.
AlwaysRebuild()149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
150
151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
154 /// By default, returns no source-location information. Subclasses can
155 /// provide an alternative implementation that provides better location
156 /// information.
getBaseLocation()157 SourceLocation getBaseLocation() { return SourceLocation(); }
158
159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
getBaseEntity()164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
setBase(SourceLocation Loc,DeclarationName Entity)171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
172
173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
179
180 public:
TemporaryBase(TreeTransform & Self,SourceLocation Location,DeclarationName Entity)181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
182 DeclarationName Entity) : Self(Self) {
183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
185
186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
188 }
189
~TemporaryBase()190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
194
195 /// \brief Determine whether the given type \p T has already been
196 /// transformed.
197 ///
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.
AlreadyTransformed(QualType T)202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
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).
DropCallArgument(Expr * E)212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
215
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.
219 ///
220 /// By default, the transformer never tries to expand pack expansions.
221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
229 /// \param Unexpanded The set of unexpanded parameter packs within the
230 /// pattern.
231 ///
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.
235 ///
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.
240 ///
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.
248 ///
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)
252 /// must be set.
TryExpandParameterPacks(SourceLocation EllipsisLoc,SourceRange PatternRange,ArrayRef<UnexpandedParameterPack> Unexpanded,bool & ShouldExpand,bool & RetainExpansion,Optional<unsigned> & NumExpansions)253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
255 ArrayRef<UnexpandedParameterPack> Unexpanded,
256 bool &ShouldExpand,
257 bool &RetainExpansion,
258 Optional<unsigned> &NumExpansions) {
259 ShouldExpand = false;
260 return false;
261 }
262
263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
ForgetPartiallySubstitutedPack()268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
271
272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
RememberPartiallySubstitutedPack(TemplateArgument Arg)277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
278
279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
ExpandingFunctionParameterPack(ParmVarDecl * Pack)281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
282
283 /// \brief Transforms the given type into another type.
284 ///
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.
290 ///
291 /// \returns the transformed type.
292 QualType TransformType(QualType T);
293
294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
296 ///
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);
303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
309
310 /// \brief Transform the given statement.
311 ///
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
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
319 StmtResult TransformStmt(Stmt *S);
320
321 /// \brief Transform the given statement.
322 ///
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.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341 /// \brief Transform the specified attribute.
342 ///
343 /// Subclasses should override the transformation of attributes with a pragma
344 /// spelling to transform expressions stored within the attribute.
345 ///
346 /// \returns the transformed attribute.
347 #define ATTR(X)
348 #define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350 #include "clang/Basic/AttrList.inc"
351
352 /// \brief Transform the given expression.
353 ///
354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
360 ExprResult TransformExpr(Expr *E);
361
362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
370
371 /// \brief Transform the given list of expressions.
372 ///
373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
384 /// function-call arguments, and any arguments that should be dropped, will
385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
394 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
395 SmallVectorImpl<Expr *> &Outputs,
396 bool *ArgChanged = nullptr);
397
398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
403 /// may override this function to provide alternate behavior.
TransformDecl(SourceLocation Loc,Decl * D)404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
409
410 return D;
411 }
412
413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
421 /// \brief Transform the attributes associated with the given declaration and
422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
transformAttrs(Decl * Old,Decl * New)426 void transformAttrs(Decl *Old, Decl *New) { }
427
428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
431 /// Local declarations are typically transformed via a call to
432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
transformedLocalDecl(Decl * Old,Decl * New)435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
438
439 /// \brief Transform the definition of the given declaration.
440 ///
441 /// By default, invokes TransformDecl() to transform the declaration.
442 /// Subclasses may override this function to provide alternate behavior.
TransformDefinition(SourceLocation Loc,Decl * D)443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
445 }
446
447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
450 /// This specific declaration transformation only applies to the first
451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
TransformFirstQualifierInScope(NamedDecl * D,SourceLocation Loc)456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
458 }
459
460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
470
471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
477 DeclarationNameInfo
478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
479
480 /// \brief Transform the given template name.
481 ///
482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
489 /// \param ObjectType If we're translating a template name within a member
490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
505
506 /// \brief Transform the given template argument.
507 ///
508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
517
518 /// \brief Transform the given set of template arguments.
519 ///
520 /// By default, this operation transforms all of the template arguments
521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
542 }
543
544 /// \brief Transform the given set of template arguments.
545 ///
546 /// By default, this operation transforms all of the template arguments
547 /// in the input set using \c TransformTemplateArgument(), and appends
548 /// the transformed arguments to the output list.
549 ///
550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
563
564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
568 /// \brief Fakes up a TypeSourceInfo for a type.
InventTypeSourceInfo(QualType T)569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
571 getDerived().getBaseLocation());
572 }
573
574 #define ABSTRACT_TYPELOC(CLASS, PARENT)
575 #define TYPELOC(CLASS, PARENT) \
576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
577 #include "clang/AST/TypeLocNodes.def"
578
579 template<typename Fn>
580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
590
591 StmtResult TransformSEHHandler(Stmt *Handler);
592
593 QualType
594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
598 QualType
599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
601 TemplateName Template,
602 CXXScopeSpec &SS);
603
604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
607
608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
628 int indexAdjustment,
629 Optional<unsigned> NumExpansions,
630 bool ExpectParameterPack);
631
632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
633
634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
636
TransformTemplateParameterList(TemplateParameterList * TPL)637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
642 ExprResult TransformAddressOfOperand(Expr *E);
643
644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
653
654 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655 // amount of stack usage with clang.
656 #define STMT(Node, Parent) \
657 LLVM_ATTRIBUTE_NOINLINE \
658 StmtResult Transform##Node(Node *S);
659 #define EXPR(Node, Parent) \
660 LLVM_ATTRIBUTE_NOINLINE \
661 ExprResult Transform##Node(Node *E);
662 #define ABSTRACT_STMT(Stmt)
663 #include "clang/AST/StmtNodes.inc"
664
665 #define OPENMP_CLAUSE(Name, Class) \
666 LLVM_ATTRIBUTE_NOINLINE \
667 OMPClause *Transform ## Class(Class *S);
668 #include "clang/Basic/OpenMPKinds.def"
669
670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
678 /// By default, performs semantic analysis when building the block pointer
679 /// type. Subclasses may override this routine to provide different behavior.
680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
681
682 /// \brief Build a new reference type given the type it references.
683 ///
684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
687 ///
688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
693
694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
701
702 /// \brief Build an Objective-C object type.
703 ///
704 /// By default, performs semantic analysis when building the object type.
705 /// Subclasses may override this routine to provide different behavior.
706 QualType RebuildObjCObjectType(QualType BaseType,
707 SourceLocation Loc,
708 SourceLocation TypeArgsLAngleLoc,
709 ArrayRef<TypeSourceInfo *> TypeArgs,
710 SourceLocation TypeArgsRAngleLoc,
711 SourceLocation ProtocolLAngleLoc,
712 ArrayRef<ObjCProtocolDecl *> Protocols,
713 ArrayRef<SourceLocation> ProtocolLocs,
714 SourceLocation ProtocolRAngleLoc);
715
716 /// \brief Build a new Objective-C object pointer type given the pointee type.
717 ///
718 /// By default, directly builds the pointer type, with no additional semantic
719 /// analysis.
720 QualType RebuildObjCObjectPointerType(QualType PointeeType,
721 SourceLocation Star);
722
723 /// \brief Build a new array type given the element type, size
724 /// modifier, size of the array (if known), size expression, and index type
725 /// qualifiers.
726 ///
727 /// By default, performs semantic analysis when building the array type.
728 /// Subclasses may override this routine to provide different behavior.
729 /// Also by default, all of the other Rebuild*Array
730 QualType RebuildArrayType(QualType ElementType,
731 ArrayType::ArraySizeModifier SizeMod,
732 const llvm::APInt *Size,
733 Expr *SizeExpr,
734 unsigned IndexTypeQuals,
735 SourceRange BracketsRange);
736
737 /// \brief Build a new constant array type given the element type, size
738 /// modifier, (known) size of the array, and index type qualifiers.
739 ///
740 /// By default, performs semantic analysis when building the array type.
741 /// Subclasses may override this routine to provide different behavior.
742 QualType RebuildConstantArrayType(QualType ElementType,
743 ArrayType::ArraySizeModifier SizeMod,
744 const llvm::APInt &Size,
745 unsigned IndexTypeQuals,
746 SourceRange BracketsRange);
747
748 /// \brief Build a new incomplete array type given the element type, size
749 /// modifier, and index type qualifiers.
750 ///
751 /// By default, performs semantic analysis when building the array type.
752 /// Subclasses may override this routine to provide different behavior.
753 QualType RebuildIncompleteArrayType(QualType ElementType,
754 ArrayType::ArraySizeModifier SizeMod,
755 unsigned IndexTypeQuals,
756 SourceRange BracketsRange);
757
758 /// \brief Build a new variable-length array type given the element type,
759 /// size modifier, size expression, and index type qualifiers.
760 ///
761 /// By default, performs semantic analysis when building the array type.
762 /// Subclasses may override this routine to provide different behavior.
763 QualType RebuildVariableArrayType(QualType ElementType,
764 ArrayType::ArraySizeModifier SizeMod,
765 Expr *SizeExpr,
766 unsigned IndexTypeQuals,
767 SourceRange BracketsRange);
768
769 /// \brief Build a new dependent-sized array type given the element type,
770 /// size modifier, size expression, and index type qualifiers.
771 ///
772 /// By default, performs semantic analysis when building the array type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildDependentSizedArrayType(QualType ElementType,
775 ArrayType::ArraySizeModifier SizeMod,
776 Expr *SizeExpr,
777 unsigned IndexTypeQuals,
778 SourceRange BracketsRange);
779
780 /// \brief Build a new vector type given the element type and
781 /// number of elements.
782 ///
783 /// By default, performs semantic analysis when building the vector type.
784 /// Subclasses may override this routine to provide different behavior.
785 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
786 VectorType::VectorKind VecKind);
787
788 /// \brief Build a new extended vector type given the element type and
789 /// number of elements.
790 ///
791 /// By default, performs semantic analysis when building the vector type.
792 /// Subclasses may override this routine to provide different behavior.
793 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
794 SourceLocation AttributeLoc);
795
796 /// \brief Build a new potentially dependently-sized extended vector type
797 /// given the element type and number of elements.
798 ///
799 /// By default, performs semantic analysis when building the vector type.
800 /// Subclasses may override this routine to provide different behavior.
801 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
802 Expr *SizeExpr,
803 SourceLocation AttributeLoc);
804
805 /// \brief Build a new function type.
806 ///
807 /// By default, performs semantic analysis when building the function type.
808 /// Subclasses may override this routine to provide different behavior.
809 QualType RebuildFunctionProtoType(QualType T,
810 MutableArrayRef<QualType> ParamTypes,
811 const FunctionProtoType::ExtProtoInfo &EPI);
812
813 /// \brief Build a new unprototyped function type.
814 QualType RebuildFunctionNoProtoType(QualType ResultType);
815
816 /// \brief Rebuild an unresolved typename type, given the decl that
817 /// the UnresolvedUsingTypenameDecl was transformed to.
818 QualType RebuildUnresolvedUsingType(Decl *D);
819
820 /// \brief Build a new typedef type.
RebuildTypedefType(TypedefNameDecl * Typedef)821 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
822 return SemaRef.Context.getTypeDeclType(Typedef);
823 }
824
825 /// \brief Build a new class/struct/union type.
RebuildRecordType(RecordDecl * Record)826 QualType RebuildRecordType(RecordDecl *Record) {
827 return SemaRef.Context.getTypeDeclType(Record);
828 }
829
830 /// \brief Build a new Enum type.
RebuildEnumType(EnumDecl * Enum)831 QualType RebuildEnumType(EnumDecl *Enum) {
832 return SemaRef.Context.getTypeDeclType(Enum);
833 }
834
835 /// \brief Build a new typeof(expr) type.
836 ///
837 /// By default, performs semantic analysis when building the typeof type.
838 /// Subclasses may override this routine to provide different behavior.
839 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
840
841 /// \brief Build a new typeof(type) type.
842 ///
843 /// By default, builds a new TypeOfType with the given underlying type.
844 QualType RebuildTypeOfType(QualType Underlying);
845
846 /// \brief Build a new unary transform type.
847 QualType RebuildUnaryTransformType(QualType BaseType,
848 UnaryTransformType::UTTKind UKind,
849 SourceLocation Loc);
850
851 /// \brief Build a new C++11 decltype type.
852 ///
853 /// By default, performs semantic analysis when building the decltype type.
854 /// Subclasses may override this routine to provide different behavior.
855 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
856
857 /// \brief Build a new C++11 auto type.
858 ///
859 /// By default, builds a new AutoType with the given deduced type.
RebuildAutoType(QualType Deduced,AutoTypeKeyword Keyword)860 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
861 // Note, IsDependent is always false here: we implicitly convert an 'auto'
862 // which has been deduced to a dependent type into an undeduced 'auto', so
863 // that we'll retry deduction after the transformation.
864 return SemaRef.Context.getAutoType(Deduced, Keyword,
865 /*IsDependent*/ false);
866 }
867
868 /// \brief Build a new template specialization type.
869 ///
870 /// By default, performs semantic analysis when building the template
871 /// specialization type. Subclasses may override this routine to provide
872 /// different behavior.
873 QualType RebuildTemplateSpecializationType(TemplateName Template,
874 SourceLocation TemplateLoc,
875 TemplateArgumentListInfo &Args);
876
877 /// \brief Build a new parenthesized type.
878 ///
879 /// By default, builds a new ParenType type from the inner type.
880 /// Subclasses may override this routine to provide different behavior.
RebuildParenType(QualType InnerType)881 QualType RebuildParenType(QualType InnerType) {
882 return SemaRef.Context.getParenType(InnerType);
883 }
884
885 /// \brief Build a new qualified name type.
886 ///
887 /// By default, builds a new ElaboratedType type from the keyword,
888 /// the nested-name-specifier and the named type.
889 /// Subclasses may override this routine to provide different behavior.
RebuildElaboratedType(SourceLocation KeywordLoc,ElaboratedTypeKeyword Keyword,NestedNameSpecifierLoc QualifierLoc,QualType Named)890 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
891 ElaboratedTypeKeyword Keyword,
892 NestedNameSpecifierLoc QualifierLoc,
893 QualType Named) {
894 return SemaRef.Context.getElaboratedType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
896 Named);
897 }
898
899 /// \brief Build a new typename type that refers to a template-id.
900 ///
901 /// By default, builds a new DependentNameType type from the
902 /// nested-name-specifier and the given type. Subclasses may override
903 /// this routine to provide different behavior.
RebuildDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,NestedNameSpecifierLoc QualifierLoc,const IdentifierInfo * Name,SourceLocation NameLoc,TemplateArgumentListInfo & Args)904 QualType RebuildDependentTemplateSpecializationType(
905 ElaboratedTypeKeyword Keyword,
906 NestedNameSpecifierLoc QualifierLoc,
907 const IdentifierInfo *Name,
908 SourceLocation NameLoc,
909 TemplateArgumentListInfo &Args) {
910 // Rebuild the template name.
911 // TODO: avoid TemplateName abstraction
912 CXXScopeSpec SS;
913 SS.Adopt(QualifierLoc);
914 TemplateName InstName
915 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
916 nullptr);
917
918 if (InstName.isNull())
919 return QualType();
920
921 // If it's still dependent, make a dependent specialization.
922 if (InstName.getAsDependentTemplateName())
923 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 Name,
926 Args);
927
928 // Otherwise, make an elaborated type wrapping a non-dependent
929 // specialization.
930 QualType T =
931 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
932 if (T.isNull()) return QualType();
933
934 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
935 return T;
936
937 return SemaRef.Context.getElaboratedType(Keyword,
938 QualifierLoc.getNestedNameSpecifier(),
939 T);
940 }
941
942 /// \brief Build a new typename type that refers to an identifier.
943 ///
944 /// By default, performs semantic analysis when building the typename type
945 /// (or elaborated type). Subclasses may override this routine to provide
946 /// different behavior.
RebuildDependentNameType(ElaboratedTypeKeyword Keyword,SourceLocation KeywordLoc,NestedNameSpecifierLoc QualifierLoc,const IdentifierInfo * Id,SourceLocation IdLoc)947 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
948 SourceLocation KeywordLoc,
949 NestedNameSpecifierLoc QualifierLoc,
950 const IdentifierInfo *Id,
951 SourceLocation IdLoc) {
952 CXXScopeSpec SS;
953 SS.Adopt(QualifierLoc);
954
955 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
956 // If the name is still dependent, just build a new dependent name type.
957 if (!SemaRef.computeDeclContext(SS))
958 return SemaRef.Context.getDependentNameType(Keyword,
959 QualifierLoc.getNestedNameSpecifier(),
960 Id);
961 }
962
963 if (Keyword == ETK_None || Keyword == ETK_Typename)
964 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
965 *Id, IdLoc);
966
967 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
968
969 // We had a dependent elaborated-type-specifier that has been transformed
970 // into a non-dependent elaborated-type-specifier. Find the tag we're
971 // referring to.
972 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
973 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
974 if (!DC)
975 return QualType();
976
977 if (SemaRef.RequireCompleteDeclContext(SS, DC))
978 return QualType();
979
980 TagDecl *Tag = nullptr;
981 SemaRef.LookupQualifiedName(Result, DC);
982 switch (Result.getResultKind()) {
983 case LookupResult::NotFound:
984 case LookupResult::NotFoundInCurrentInstantiation:
985 break;
986
987 case LookupResult::Found:
988 Tag = Result.getAsSingle<TagDecl>();
989 break;
990
991 case LookupResult::FoundOverloaded:
992 case LookupResult::FoundUnresolvedValue:
993 llvm_unreachable("Tag lookup cannot find non-tags");
994
995 case LookupResult::Ambiguous:
996 // Let the LookupResult structure handle ambiguities.
997 return QualType();
998 }
999
1000 if (!Tag) {
1001 // Check where the name exists but isn't a tag type and use that to emit
1002 // better diagnostics.
1003 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1004 SemaRef.LookupQualifiedName(Result, DC);
1005 switch (Result.getResultKind()) {
1006 case LookupResult::Found:
1007 case LookupResult::FoundOverloaded:
1008 case LookupResult::FoundUnresolvedValue: {
1009 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1010 unsigned Kind = 0;
1011 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
1012 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1013 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
1014 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1015 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1016 break;
1017 }
1018 default:
1019 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1020 << Kind << Id << DC << QualifierLoc.getSourceRange();
1021 break;
1022 }
1023 return QualType();
1024 }
1025
1026 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1027 IdLoc, Id)) {
1028 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1029 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1030 return QualType();
1031 }
1032
1033 // Build the elaborated-type-specifier type.
1034 QualType T = SemaRef.Context.getTypeDeclType(Tag);
1035 return SemaRef.Context.getElaboratedType(Keyword,
1036 QualifierLoc.getNestedNameSpecifier(),
1037 T);
1038 }
1039
1040 /// \brief Build a new pack expansion type.
1041 ///
1042 /// By default, builds a new PackExpansionType type from the given pattern.
1043 /// Subclasses may override this routine to provide different behavior.
RebuildPackExpansionType(QualType Pattern,SourceRange PatternRange,SourceLocation EllipsisLoc,Optional<unsigned> NumExpansions)1044 QualType RebuildPackExpansionType(QualType Pattern,
1045 SourceRange PatternRange,
1046 SourceLocation EllipsisLoc,
1047 Optional<unsigned> NumExpansions) {
1048 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1049 NumExpansions);
1050 }
1051
1052 /// \brief Build a new atomic type given its value type.
1053 ///
1054 /// By default, performs semantic analysis when building the atomic type.
1055 /// Subclasses may override this routine to provide different behavior.
1056 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1057
1058 /// \brief Build a new pipe type given its value type.
1059 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1060
1061 /// \brief Build a new template name given a nested name specifier, a flag
1062 /// indicating whether the "template" keyword was provided, and the template
1063 /// that the template name refers to.
1064 ///
1065 /// By default, builds the new template name directly. Subclasses may override
1066 /// this routine to provide different behavior.
1067 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1068 bool TemplateKW,
1069 TemplateDecl *Template);
1070
1071 /// \brief Build a new template name given a nested name specifier and the
1072 /// name that is referred to as a template.
1073 ///
1074 /// By default, performs semantic analysis to determine whether the name can
1075 /// be resolved to a specific template, then builds the appropriate kind of
1076 /// template name. Subclasses may override this routine to provide different
1077 /// behavior.
1078 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1079 const IdentifierInfo &Name,
1080 SourceLocation NameLoc,
1081 QualType ObjectType,
1082 NamedDecl *FirstQualifierInScope);
1083
1084 /// \brief Build a new template name given a nested name specifier and the
1085 /// overloaded operator name that is referred to as a template.
1086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
1091 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1092 OverloadedOperatorKind Operator,
1093 SourceLocation NameLoc,
1094 QualType ObjectType);
1095
1096 /// \brief Build a new template name given a template template parameter pack
1097 /// and the
1098 ///
1099 /// By default, performs semantic analysis to determine whether the name can
1100 /// be resolved to a specific template, then builds the appropriate kind of
1101 /// template name. Subclasses may override this routine to provide different
1102 /// behavior.
RebuildTemplateName(TemplateTemplateParmDecl * Param,const TemplateArgument & ArgPack)1103 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1104 const TemplateArgument &ArgPack) {
1105 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1106 }
1107
1108 /// \brief Build a new compound statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
RebuildCompoundStmt(SourceLocation LBraceLoc,MultiStmtArg Statements,SourceLocation RBraceLoc,bool IsStmtExpr)1112 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
1113 MultiStmtArg Statements,
1114 SourceLocation RBraceLoc,
1115 bool IsStmtExpr) {
1116 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1117 IsStmtExpr);
1118 }
1119
1120 /// \brief Build a new case statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
RebuildCaseStmt(SourceLocation CaseLoc,Expr * LHS,SourceLocation EllipsisLoc,Expr * RHS,SourceLocation ColonLoc)1124 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
1125 Expr *LHS,
1126 SourceLocation EllipsisLoc,
1127 Expr *RHS,
1128 SourceLocation ColonLoc) {
1129 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1130 ColonLoc);
1131 }
1132
1133 /// \brief Attach the body to a new case statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
RebuildCaseStmtBody(Stmt * S,Stmt * Body)1137 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
1138 getSema().ActOnCaseStmtBody(S, Body);
1139 return S;
1140 }
1141
1142 /// \brief Build a new default statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
RebuildDefaultStmt(SourceLocation DefaultLoc,SourceLocation ColonLoc,Stmt * SubStmt)1146 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
1147 SourceLocation ColonLoc,
1148 Stmt *SubStmt) {
1149 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1150 /*CurScope=*/nullptr);
1151 }
1152
1153 /// \brief Build a new label statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
RebuildLabelStmt(SourceLocation IdentLoc,LabelDecl * L,SourceLocation ColonLoc,Stmt * SubStmt)1157 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1158 SourceLocation ColonLoc, Stmt *SubStmt) {
1159 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1160 }
1161
1162 /// \brief Build a new label statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
RebuildAttributedStmt(SourceLocation AttrLoc,ArrayRef<const Attr * > Attrs,Stmt * SubStmt)1166 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1167 ArrayRef<const Attr*> Attrs,
1168 Stmt *SubStmt) {
1169 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1170 }
1171
1172 /// \brief Build a new "if" statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
RebuildIfStmt(SourceLocation IfLoc,bool IsConstexpr,Sema::ConditionResult Cond,Stmt * Init,Stmt * Then,SourceLocation ElseLoc,Stmt * Else)1176 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1177 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1178 SourceLocation ElseLoc, Stmt *Else) {
1179 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1180 ElseLoc, Else);
1181 }
1182
1183 /// \brief Start building a new switch statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
RebuildSwitchStmtStart(SourceLocation SwitchLoc,Stmt * Init,Sema::ConditionResult Cond)1187 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
1188 Sema::ConditionResult Cond) {
1189 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1190 }
1191
1192 /// \brief Attach the body to the switch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
RebuildSwitchStmtBody(SourceLocation SwitchLoc,Stmt * Switch,Stmt * Body)1196 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
1197 Stmt *Switch, Stmt *Body) {
1198 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1199 }
1200
1201 /// \brief Build a new while statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
RebuildWhileStmt(SourceLocation WhileLoc,Sema::ConditionResult Cond,Stmt * Body)1205 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1206 Sema::ConditionResult Cond, Stmt *Body) {
1207 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1208 }
1209
1210 /// \brief Build a new do-while statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
RebuildDoStmt(SourceLocation DoLoc,Stmt * Body,SourceLocation WhileLoc,SourceLocation LParenLoc,Expr * Cond,SourceLocation RParenLoc)1214 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1215 SourceLocation WhileLoc, SourceLocation LParenLoc,
1216 Expr *Cond, SourceLocation RParenLoc) {
1217 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1218 Cond, RParenLoc);
1219 }
1220
1221 /// \brief Build a new for statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
RebuildForStmt(SourceLocation ForLoc,SourceLocation LParenLoc,Stmt * Init,Sema::ConditionResult Cond,Sema::FullExprArg Inc,SourceLocation RParenLoc,Stmt * Body)1225 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1226 Stmt *Init, Sema::ConditionResult Cond,
1227 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1228 Stmt *Body) {
1229 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1230 Inc, RParenLoc, Body);
1231 }
1232
1233 /// \brief Build a new goto statement.
1234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
RebuildGotoStmt(SourceLocation GotoLoc,SourceLocation LabelLoc,LabelDecl * Label)1237 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1238 LabelDecl *Label) {
1239 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1240 }
1241
1242 /// \brief Build a new indirect goto statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
RebuildIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,Expr * Target)1246 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1247 SourceLocation StarLoc,
1248 Expr *Target) {
1249 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1250 }
1251
1252 /// \brief Build a new return statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
RebuildReturnStmt(SourceLocation ReturnLoc,Expr * Result)1256 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
1257 return getSema().BuildReturnStmt(ReturnLoc, Result);
1258 }
1259
1260 /// \brief Build a new declaration statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
RebuildDeclStmt(MutableArrayRef<Decl * > Decls,SourceLocation StartLoc,SourceLocation EndLoc)1264 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
1265 SourceLocation StartLoc, SourceLocation EndLoc) {
1266 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1267 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1268 }
1269
1270 /// \brief Build a new inline asm statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
RebuildGCCAsmStmt(SourceLocation AsmLoc,bool IsSimple,bool IsVolatile,unsigned NumOutputs,unsigned NumInputs,IdentifierInfo ** Names,MultiExprArg Constraints,MultiExprArg Exprs,Expr * AsmString,MultiExprArg Clobbers,SourceLocation RParenLoc)1274 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1275 bool IsVolatile, unsigned NumOutputs,
1276 unsigned NumInputs, IdentifierInfo **Names,
1277 MultiExprArg Constraints, MultiExprArg Exprs,
1278 Expr *AsmString, MultiExprArg Clobbers,
1279 SourceLocation RParenLoc) {
1280 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1281 NumInputs, Names, Constraints, Exprs,
1282 AsmString, Clobbers, RParenLoc);
1283 }
1284
1285 /// \brief Build a new MS style inline asm statement.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
RebuildMSAsmStmt(SourceLocation AsmLoc,SourceLocation LBraceLoc,ArrayRef<Token> AsmToks,StringRef AsmString,unsigned NumOutputs,unsigned NumInputs,ArrayRef<StringRef> Constraints,ArrayRef<StringRef> Clobbers,ArrayRef<Expr * > Exprs,SourceLocation EndLoc)1289 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1290 ArrayRef<Token> AsmToks,
1291 StringRef AsmString,
1292 unsigned NumOutputs, unsigned NumInputs,
1293 ArrayRef<StringRef> Constraints,
1294 ArrayRef<StringRef> Clobbers,
1295 ArrayRef<Expr*> Exprs,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1298 NumOutputs, NumInputs,
1299 Constraints, Clobbers, Exprs, EndLoc);
1300 }
1301
1302 /// \brief Build a new co_return statement.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
RebuildCoreturnStmt(SourceLocation CoreturnLoc,Expr * Result)1306 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1307 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1308 }
1309
1310 /// \brief Build a new co_await expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
RebuildCoawaitExpr(SourceLocation CoawaitLoc,Expr * Result)1314 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1315 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1316 }
1317
1318 /// \brief Build a new co_yield expression.
1319 ///
1320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
RebuildCoyieldExpr(SourceLocation CoyieldLoc,Expr * Result)1322 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1323 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1324 }
1325
1326 /// \brief Build a new Objective-C \@try statement.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAtTryStmt(SourceLocation AtLoc,Stmt * TryBody,MultiStmtArg CatchStmts,Stmt * Finally)1330 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
1331 Stmt *TryBody,
1332 MultiStmtArg CatchStmts,
1333 Stmt *Finally) {
1334 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1335 Finally);
1336 }
1337
1338 /// \brief Rebuild an Objective-C exception declaration.
1339 ///
1340 /// By default, performs semantic analysis to build the new declaration.
1341 /// Subclasses may override this routine to provide different behavior.
RebuildObjCExceptionDecl(VarDecl * ExceptionDecl,TypeSourceInfo * TInfo,QualType T)1342 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1343 TypeSourceInfo *TInfo, QualType T) {
1344 return getSema().BuildObjCExceptionDecl(TInfo, T,
1345 ExceptionDecl->getInnerLocStart(),
1346 ExceptionDecl->getLocation(),
1347 ExceptionDecl->getIdentifier());
1348 }
1349
1350 /// \brief Build a new Objective-C \@catch statement.
1351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAtCatchStmt(SourceLocation AtLoc,SourceLocation RParenLoc,VarDecl * Var,Stmt * Body)1354 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1355 SourceLocation RParenLoc,
1356 VarDecl *Var,
1357 Stmt *Body) {
1358 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1359 Var, Body);
1360 }
1361
1362 /// \brief Build a new Objective-C \@finally statement.
1363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAtFinallyStmt(SourceLocation AtLoc,Stmt * Body)1366 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
1367 Stmt *Body) {
1368 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1369 }
1370
1371 /// \brief Build a new Objective-C \@throw statement.
1372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAtThrowStmt(SourceLocation AtLoc,Expr * Operand)1375 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
1376 Expr *Operand) {
1377 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1378 }
1379
1380 /// \brief Build a new OpenMP executable directive.
1381 ///
1382 /// By default, performs semantic analysis to build the new statement.
1383 /// Subclasses may override this routine to provide different behavior.
RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,DeclarationNameInfo DirName,OpenMPDirectiveKind CancelRegion,ArrayRef<OMPClause * > Clauses,Stmt * AStmt,SourceLocation StartLoc,SourceLocation EndLoc)1384 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1385 DeclarationNameInfo DirName,
1386 OpenMPDirectiveKind CancelRegion,
1387 ArrayRef<OMPClause *> Clauses,
1388 Stmt *AStmt, SourceLocation StartLoc,
1389 SourceLocation EndLoc) {
1390 return getSema().ActOnOpenMPExecutableDirective(
1391 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1392 }
1393
1394 /// \brief Build a new OpenMP 'if' clause.
1395 ///
1396 /// By default, performs semantic analysis to build the new OpenMP clause.
1397 /// Subclasses may override this routine to provide different behavior.
RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,Expr * Condition,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation NameModifierLoc,SourceLocation ColonLoc,SourceLocation EndLoc)1398 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1399 Expr *Condition, SourceLocation StartLoc,
1400 SourceLocation LParenLoc,
1401 SourceLocation NameModifierLoc,
1402 SourceLocation ColonLoc,
1403 SourceLocation EndLoc) {
1404 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1405 LParenLoc, NameModifierLoc, ColonLoc,
1406 EndLoc);
1407 }
1408
1409 /// \brief Build a new OpenMP 'final' clause.
1410 ///
1411 /// By default, performs semantic analysis to build the new OpenMP clause.
1412 /// Subclasses may override this routine to provide different behavior.
RebuildOMPFinalClause(Expr * Condition,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1413 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1417 EndLoc);
1418 }
1419
1420 /// \brief Build a new OpenMP 'num_threads' clause.
1421 ///
1422 /// By default, performs semantic analysis to build the new OpenMP clause.
1423 /// Subclasses may override this routine to provide different behavior.
RebuildOMPNumThreadsClause(Expr * NumThreads,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1424 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1425 SourceLocation StartLoc,
1426 SourceLocation LParenLoc,
1427 SourceLocation EndLoc) {
1428 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1429 LParenLoc, EndLoc);
1430 }
1431
1432 /// \brief Build a new OpenMP 'safelen' clause.
1433 ///
1434 /// By default, performs semantic analysis to build the new OpenMP clause.
1435 /// Subclasses may override this routine to provide different behavior.
RebuildOMPSafelenClause(Expr * Len,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1436 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1437 SourceLocation LParenLoc,
1438 SourceLocation EndLoc) {
1439 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1440 }
1441
1442 /// \brief Build a new OpenMP 'simdlen' clause.
1443 ///
1444 /// By default, performs semantic analysis to build the new OpenMP clause.
1445 /// Subclasses may override this routine to provide different behavior.
RebuildOMPSimdlenClause(Expr * Len,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1446 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1450 }
1451
1452 /// \brief Build a new OpenMP 'collapse' clause.
1453 ///
1454 /// By default, performs semantic analysis to build the new OpenMP clause.
1455 /// Subclasses may override this routine to provide different behavior.
RebuildOMPCollapseClause(Expr * Num,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1456 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1457 SourceLocation LParenLoc,
1458 SourceLocation EndLoc) {
1459 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1460 EndLoc);
1461 }
1462
1463 /// \brief Build a new OpenMP 'default' clause.
1464 ///
1465 /// By default, performs semantic analysis to build the new OpenMP clause.
1466 /// Subclasses may override this routine to provide different behavior.
RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,SourceLocation KindKwLoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1467 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1468 SourceLocation KindKwLoc,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1473 StartLoc, LParenLoc, EndLoc);
1474 }
1475
1476 /// \brief Build a new OpenMP 'proc_bind' clause.
1477 ///
1478 /// By default, performs semantic analysis to build the new OpenMP clause.
1479 /// Subclasses may override this routine to provide different behavior.
RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,SourceLocation KindKwLoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1480 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1481 SourceLocation KindKwLoc,
1482 SourceLocation StartLoc,
1483 SourceLocation LParenLoc,
1484 SourceLocation EndLoc) {
1485 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1486 StartLoc, LParenLoc, EndLoc);
1487 }
1488
1489 /// \brief Build a new OpenMP 'schedule' clause.
1490 ///
1491 /// By default, performs semantic analysis to build the new OpenMP clause.
1492 /// Subclasses may override this routine to provide different behavior.
RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1,OpenMPScheduleClauseModifier M2,OpenMPScheduleClauseKind Kind,Expr * ChunkSize,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation M1Loc,SourceLocation M2Loc,SourceLocation KindLoc,SourceLocation CommaLoc,SourceLocation EndLoc)1493 OMPClause *RebuildOMPScheduleClause(
1494 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1495 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1496 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1497 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1498 return getSema().ActOnOpenMPScheduleClause(
1499 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1500 CommaLoc, EndLoc);
1501 }
1502
1503 /// \brief Build a new OpenMP 'ordered' clause.
1504 ///
1505 /// By default, performs semantic analysis to build the new OpenMP clause.
1506 /// Subclasses may override this routine to provide different behavior.
RebuildOMPOrderedClause(SourceLocation StartLoc,SourceLocation EndLoc,SourceLocation LParenLoc,Expr * Num)1507 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1508 SourceLocation EndLoc,
1509 SourceLocation LParenLoc, Expr *Num) {
1510 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1511 }
1512
1513 /// \brief Build a new OpenMP 'private' clause.
1514 ///
1515 /// By default, performs semantic analysis to build the new OpenMP clause.
1516 /// Subclasses may override this routine to provide different behavior.
RebuildOMPPrivateClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1517 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1518 SourceLocation StartLoc,
1519 SourceLocation LParenLoc,
1520 SourceLocation EndLoc) {
1521 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1522 EndLoc);
1523 }
1524
1525 /// \brief Build a new OpenMP 'firstprivate' clause.
1526 ///
1527 /// By default, performs semantic analysis to build the new OpenMP clause.
1528 /// Subclasses may override this routine to provide different behavior.
RebuildOMPFirstprivateClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1529 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1530 SourceLocation StartLoc,
1531 SourceLocation LParenLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1534 EndLoc);
1535 }
1536
1537 /// \brief Build a new OpenMP 'lastprivate' clause.
1538 ///
1539 /// By default, performs semantic analysis to build the new OpenMP clause.
1540 /// Subclasses may override this routine to provide different behavior.
RebuildOMPLastprivateClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1541 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1546 EndLoc);
1547 }
1548
1549 /// \brief Build a new OpenMP 'shared' clause.
1550 ///
1551 /// By default, performs semantic analysis to build the new OpenMP clause.
1552 /// Subclasses may override this routine to provide different behavior.
RebuildOMPSharedClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1553 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1554 SourceLocation StartLoc,
1555 SourceLocation LParenLoc,
1556 SourceLocation EndLoc) {
1557 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1558 EndLoc);
1559 }
1560
1561 /// \brief Build a new OpenMP 'reduction' clause.
1562 ///
1563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
RebuildOMPReductionClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,CXXScopeSpec & ReductionIdScopeSpec,const DeclarationNameInfo & ReductionId,ArrayRef<Expr * > UnresolvedReductions)1565 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1566 SourceLocation StartLoc,
1567 SourceLocation LParenLoc,
1568 SourceLocation ColonLoc,
1569 SourceLocation EndLoc,
1570 CXXScopeSpec &ReductionIdScopeSpec,
1571 const DeclarationNameInfo &ReductionId,
1572 ArrayRef<Expr *> UnresolvedReductions) {
1573 return getSema().ActOnOpenMPReductionClause(
1574 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1575 ReductionId, UnresolvedReductions);
1576 }
1577
1578 /// \brief Build a new OpenMP 'linear' clause.
1579 ///
1580 /// By default, performs semantic analysis to build the new OpenMP clause.
1581 /// Subclasses may override this routine to provide different behavior.
RebuildOMPLinearClause(ArrayRef<Expr * > VarList,Expr * Step,SourceLocation StartLoc,SourceLocation LParenLoc,OpenMPLinearClauseKind Modifier,SourceLocation ModifierLoc,SourceLocation ColonLoc,SourceLocation EndLoc)1582 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1583 SourceLocation StartLoc,
1584 SourceLocation LParenLoc,
1585 OpenMPLinearClauseKind Modifier,
1586 SourceLocation ModifierLoc,
1587 SourceLocation ColonLoc,
1588 SourceLocation EndLoc) {
1589 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1590 Modifier, ModifierLoc, ColonLoc,
1591 EndLoc);
1592 }
1593
1594 /// \brief Build a new OpenMP 'aligned' clause.
1595 ///
1596 /// By default, performs semantic analysis to build the new OpenMP clause.
1597 /// Subclasses may override this routine to provide different behavior.
RebuildOMPAlignedClause(ArrayRef<Expr * > VarList,Expr * Alignment,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc)1598 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1599 SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation ColonLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1604 LParenLoc, ColonLoc, EndLoc);
1605 }
1606
1607 /// \brief Build a new OpenMP 'copyin' clause.
1608 ///
1609 /// By default, performs semantic analysis to build the new OpenMP clause.
1610 /// Subclasses may override this routine to provide different behavior.
RebuildOMPCopyinClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1611 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1612 SourceLocation StartLoc,
1613 SourceLocation LParenLoc,
1614 SourceLocation EndLoc) {
1615 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1616 EndLoc);
1617 }
1618
1619 /// \brief Build a new OpenMP 'copyprivate' clause.
1620 ///
1621 /// By default, performs semantic analysis to build the new OpenMP clause.
1622 /// Subclasses may override this routine to provide different behavior.
RebuildOMPCopyprivateClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1623 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
1631 /// \brief Build a new OpenMP 'flush' pseudo clause.
1632 ///
1633 /// By default, performs semantic analysis to build the new OpenMP clause.
1634 /// Subclasses may override this routine to provide different behavior.
RebuildOMPFlushClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1635 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1636 SourceLocation StartLoc,
1637 SourceLocation LParenLoc,
1638 SourceLocation EndLoc) {
1639 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1640 EndLoc);
1641 }
1642
1643 /// \brief Build a new OpenMP 'depend' pseudo clause.
1644 ///
1645 /// By default, performs semantic analysis to build the new OpenMP clause.
1646 /// Subclasses may override this routine to provide different behavior.
1647 OMPClause *
RebuildOMPDependClause(OpenMPDependClauseKind DepKind,SourceLocation DepLoc,SourceLocation ColonLoc,ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1648 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1649 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1650 SourceLocation StartLoc, SourceLocation LParenLoc,
1651 SourceLocation EndLoc) {
1652 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1653 StartLoc, LParenLoc, EndLoc);
1654 }
1655
1656 /// \brief Build a new OpenMP 'device' clause.
1657 ///
1658 /// By default, performs semantic analysis to build the new statement.
1659 /// Subclasses may override this routine to provide different behavior.
RebuildOMPDeviceClause(Expr * Device,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1660 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1661 SourceLocation LParenLoc,
1662 SourceLocation EndLoc) {
1663 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1664 EndLoc);
1665 }
1666
1667 /// \brief Build a new OpenMP 'map' clause.
1668 ///
1669 /// By default, performs semantic analysis to build the new OpenMP clause.
1670 /// Subclasses may override this routine to provide different behavior.
1671 OMPClause *
RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,OpenMPMapClauseKind MapType,bool IsMapTypeImplicit,SourceLocation MapLoc,SourceLocation ColonLoc,ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1672 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1673 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1674 SourceLocation MapLoc, SourceLocation ColonLoc,
1675 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1676 SourceLocation LParenLoc, SourceLocation EndLoc) {
1677 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1678 IsMapTypeImplicit, MapLoc, ColonLoc,
1679 VarList, StartLoc, LParenLoc, EndLoc);
1680 }
1681
1682 /// \brief Build a new OpenMP 'num_teams' clause.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
RebuildOMPNumTeamsClause(Expr * NumTeams,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1686 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation EndLoc) {
1689 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1690 EndLoc);
1691 }
1692
1693 /// \brief Build a new OpenMP 'thread_limit' clause.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
RebuildOMPThreadLimitClause(Expr * ThreadLimit,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1697 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1698 SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation EndLoc) {
1701 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1702 LParenLoc, EndLoc);
1703 }
1704
1705 /// \brief Build a new OpenMP 'priority' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new statement.
1708 /// Subclasses may override this routine to provide different behavior.
RebuildOMPPriorityClause(Expr * Priority,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1709 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1710 SourceLocation LParenLoc,
1711 SourceLocation EndLoc) {
1712 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1713 EndLoc);
1714 }
1715
1716 /// \brief Build a new OpenMP 'grainsize' clause.
1717 ///
1718 /// By default, performs semantic analysis to build the new statement.
1719 /// Subclasses may override this routine to provide different behavior.
RebuildOMPGrainsizeClause(Expr * Grainsize,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1720 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1721 SourceLocation LParenLoc,
1722 SourceLocation EndLoc) {
1723 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1724 EndLoc);
1725 }
1726
1727 /// \brief Build a new OpenMP 'num_tasks' clause.
1728 ///
1729 /// By default, performs semantic analysis to build the new statement.
1730 /// Subclasses may override this routine to provide different behavior.
RebuildOMPNumTasksClause(Expr * NumTasks,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1731 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
1738 /// \brief Build a new OpenMP 'hint' clause.
1739 ///
1740 /// By default, performs semantic analysis to build the new statement.
1741 /// Subclasses may override this routine to provide different behavior.
RebuildOMPHintClause(Expr * Hint,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1742 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation EndLoc) {
1745 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1746 }
1747
1748 /// \brief Build a new OpenMP 'dist_schedule' clause.
1749 ///
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1752 OMPClause *
RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,Expr * ChunkSize,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation KindLoc,SourceLocation CommaLoc,SourceLocation EndLoc)1753 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1754 Expr *ChunkSize, SourceLocation StartLoc,
1755 SourceLocation LParenLoc, SourceLocation KindLoc,
1756 SourceLocation CommaLoc, SourceLocation EndLoc) {
1757 return getSema().ActOnOpenMPDistScheduleClause(
1758 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1759 }
1760
1761 /// \brief Build a new OpenMP 'to' clause.
1762 ///
1763 /// By default, performs semantic analysis to build the new statement.
1764 /// Subclasses may override this routine to provide different behavior.
RebuildOMPToClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1765 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1766 SourceLocation StartLoc,
1767 SourceLocation LParenLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1770 }
1771
1772 /// \brief Build a new OpenMP 'from' clause.
1773 ///
1774 /// By default, performs semantic analysis to build the new statement.
1775 /// Subclasses may override this routine to provide different behavior.
RebuildOMPFromClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1776 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1777 SourceLocation StartLoc,
1778 SourceLocation LParenLoc,
1779 SourceLocation EndLoc) {
1780 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1781 EndLoc);
1782 }
1783
1784 /// Build a new OpenMP 'use_device_ptr' clause.
1785 ///
1786 /// By default, performs semantic analysis to build the new OpenMP clause.
1787 /// Subclasses may override this routine to provide different behavior.
RebuildOMPUseDevicePtrClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1788 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1789 SourceLocation StartLoc,
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
1792 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1793 EndLoc);
1794 }
1795
1796 /// Build a new OpenMP 'is_device_ptr' clause.
1797 ///
1798 /// By default, performs semantic analysis to build the new OpenMP clause.
1799 /// Subclasses may override this routine to provide different behavior.
RebuildOMPIsDevicePtrClause(ArrayRef<Expr * > VarList,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1800 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1801 SourceLocation StartLoc,
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1805 EndLoc);
1806 }
1807
1808 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1809 ///
1810 /// By default, performs semantic analysis to build the new statement.
1811 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,Expr * object)1812 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1813 Expr *object) {
1814 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1815 }
1816
1817 /// \brief Build a new Objective-C \@synchronized statement.
1818 ///
1819 /// By default, performs semantic analysis to build the new statement.
1820 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,Expr * Object,Stmt * Body)1821 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
1822 Expr *Object, Stmt *Body) {
1823 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1824 }
1825
1826 /// \brief Build a new Objective-C \@autoreleasepool statement.
1827 ///
1828 /// By default, performs semantic analysis to build the new statement.
1829 /// Subclasses may override this routine to provide different behavior.
RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,Stmt * Body)1830 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1831 Stmt *Body) {
1832 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1833 }
1834
1835 /// \brief Build a new Objective-C fast enumeration statement.
1836 ///
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
RebuildObjCForCollectionStmt(SourceLocation ForLoc,Stmt * Element,Expr * Collection,SourceLocation RParenLoc,Stmt * Body)1839 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1840 Stmt *Element,
1841 Expr *Collection,
1842 SourceLocation RParenLoc,
1843 Stmt *Body) {
1844 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1845 Element,
1846 Collection,
1847 RParenLoc);
1848 if (ForEachStmt.isInvalid())
1849 return StmtError();
1850
1851 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1852 }
1853
1854 /// \brief Build a new C++ exception declaration.
1855 ///
1856 /// By default, performs semantic analysis to build the new decaration.
1857 /// Subclasses may override this routine to provide different behavior.
RebuildExceptionDecl(VarDecl * ExceptionDecl,TypeSourceInfo * Declarator,SourceLocation StartLoc,SourceLocation IdLoc,IdentifierInfo * Id)1858 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1859 TypeSourceInfo *Declarator,
1860 SourceLocation StartLoc,
1861 SourceLocation IdLoc,
1862 IdentifierInfo *Id) {
1863 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1864 StartLoc, IdLoc, Id);
1865 if (Var)
1866 getSema().CurContext->addDecl(Var);
1867 return Var;
1868 }
1869
1870 /// \brief Build a new C++ catch statement.
1871 ///
1872 /// By default, performs semantic analysis to build the new statement.
1873 /// Subclasses may override this routine to provide different behavior.
RebuildCXXCatchStmt(SourceLocation CatchLoc,VarDecl * ExceptionDecl,Stmt * Handler)1874 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1875 VarDecl *ExceptionDecl,
1876 Stmt *Handler) {
1877 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1878 Handler));
1879 }
1880
1881 /// \brief Build a new C++ try statement.
1882 ///
1883 /// By default, performs semantic analysis to build the new statement.
1884 /// Subclasses may override this routine to provide different behavior.
RebuildCXXTryStmt(SourceLocation TryLoc,Stmt * TryBlock,ArrayRef<Stmt * > Handlers)1885 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1886 ArrayRef<Stmt *> Handlers) {
1887 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1888 }
1889
1890 /// \brief Build a new C++0x range-based for statement.
1891 ///
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
RebuildCXXForRangeStmt(SourceLocation ForLoc,SourceLocation CoawaitLoc,SourceLocation ColonLoc,Stmt * Range,Stmt * Begin,Stmt * End,Expr * Cond,Expr * Inc,Stmt * LoopVar,SourceLocation RParenLoc)1894 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1895 SourceLocation CoawaitLoc,
1896 SourceLocation ColonLoc,
1897 Stmt *Range, Stmt *Begin, Stmt *End,
1898 Expr *Cond, Expr *Inc,
1899 Stmt *LoopVar,
1900 SourceLocation RParenLoc) {
1901 // If we've just learned that the range is actually an Objective-C
1902 // collection, treat this as an Objective-C fast enumeration loop.
1903 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1904 if (RangeStmt->isSingleDecl()) {
1905 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1906 if (RangeVar->isInvalidDecl())
1907 return StmtError();
1908
1909 Expr *RangeExpr = RangeVar->getInit();
1910 if (!RangeExpr->isTypeDependent() &&
1911 RangeExpr->getType()->isObjCObjectPointerType())
1912 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1913 RParenLoc);
1914 }
1915 }
1916 }
1917
1918 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1919 Range, Begin, End,
1920 Cond, Inc, LoopVar, RParenLoc,
1921 Sema::BFRK_Rebuild);
1922 }
1923
1924 /// \brief Build a new C++0x range-based for statement.
1925 ///
1926 /// By default, performs semantic analysis to build the new statement.
1927 /// Subclasses may override this routine to provide different behavior.
RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,bool IsIfExists,NestedNameSpecifierLoc QualifierLoc,DeclarationNameInfo NameInfo,Stmt * Nested)1928 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1929 bool IsIfExists,
1930 NestedNameSpecifierLoc QualifierLoc,
1931 DeclarationNameInfo NameInfo,
1932 Stmt *Nested) {
1933 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1934 QualifierLoc, NameInfo, Nested);
1935 }
1936
1937 /// \brief Attach body to a C++0x range-based for statement.
1938 ///
1939 /// By default, performs semantic analysis to finish the new statement.
1940 /// Subclasses may override this routine to provide different behavior.
FinishCXXForRangeStmt(Stmt * ForRange,Stmt * Body)1941 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1942 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1943 }
1944
RebuildSEHTryStmt(bool IsCXXTry,SourceLocation TryLoc,Stmt * TryBlock,Stmt * Handler)1945 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1946 Stmt *TryBlock, Stmt *Handler) {
1947 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
1948 }
1949
RebuildSEHExceptStmt(SourceLocation Loc,Expr * FilterExpr,Stmt * Block)1950 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
1951 Stmt *Block) {
1952 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1953 }
1954
RebuildSEHFinallyStmt(SourceLocation Loc,Stmt * Block)1955 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1956 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
1957 }
1958
1959 /// \brief Build a new predefined expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
RebuildPredefinedExpr(SourceLocation Loc,PredefinedExpr::IdentType IT)1963 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1964 PredefinedExpr::IdentType IT) {
1965 return getSema().BuildPredefinedExpr(Loc, IT);
1966 }
1967
1968 /// \brief Build a new expression that references a declaration.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
RebuildDeclarationNameExpr(const CXXScopeSpec & SS,LookupResult & R,bool RequiresADL)1972 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1973 LookupResult &R,
1974 bool RequiresADL) {
1975 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1976 }
1977
1978
1979 /// \brief Build a new expression that references a declaration.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,ValueDecl * VD,const DeclarationNameInfo & NameInfo,TemplateArgumentListInfo * TemplateArgs)1983 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1984 ValueDecl *VD,
1985 const DeclarationNameInfo &NameInfo,
1986 TemplateArgumentListInfo *TemplateArgs) {
1987 CXXScopeSpec SS;
1988 SS.Adopt(QualifierLoc);
1989
1990 // FIXME: loses template args.
1991
1992 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1993 }
1994
1995 /// \brief Build a new expression in parentheses.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
RebuildParenExpr(Expr * SubExpr,SourceLocation LParen,SourceLocation RParen)1999 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
2000 SourceLocation RParen) {
2001 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2002 }
2003
2004 /// \brief Build a new pseudo-destructor expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
2008 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2009 SourceLocation OperatorLoc,
2010 bool isArrow,
2011 CXXScopeSpec &SS,
2012 TypeSourceInfo *ScopeType,
2013 SourceLocation CCLoc,
2014 SourceLocation TildeLoc,
2015 PseudoDestructorTypeStorage Destroyed);
2016
2017 /// \brief Build a new unary operator expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
RebuildUnaryOperator(SourceLocation OpLoc,UnaryOperatorKind Opc,Expr * SubExpr)2021 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
2022 UnaryOperatorKind Opc,
2023 Expr *SubExpr) {
2024 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2025 }
2026
2027 /// \brief Build a new builtin offsetof expression.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
RebuildOffsetOfExpr(SourceLocation OperatorLoc,TypeSourceInfo * Type,ArrayRef<Sema::OffsetOfComponent> Components,SourceLocation RParenLoc)2031 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
2032 TypeSourceInfo *Type,
2033 ArrayRef<Sema::OffsetOfComponent> Components,
2034 SourceLocation RParenLoc) {
2035 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2036 RParenLoc);
2037 }
2038
2039 /// \brief Build a new sizeof, alignof or vec_step expression with a
2040 /// type argument.
2041 ///
2042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
RebuildUnaryExprOrTypeTrait(TypeSourceInfo * TInfo,SourceLocation OpLoc,UnaryExprOrTypeTrait ExprKind,SourceRange R)2044 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2045 SourceLocation OpLoc,
2046 UnaryExprOrTypeTrait ExprKind,
2047 SourceRange R) {
2048 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2049 }
2050
2051 /// \brief Build a new sizeof, alignof or vec step expression with an
2052 /// expression argument.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
RebuildUnaryExprOrTypeTrait(Expr * SubExpr,SourceLocation OpLoc,UnaryExprOrTypeTrait ExprKind,SourceRange R)2056 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2057 UnaryExprOrTypeTrait ExprKind,
2058 SourceRange R) {
2059 ExprResult Result
2060 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2061 if (Result.isInvalid())
2062 return ExprError();
2063
2064 return Result;
2065 }
2066
2067 /// \brief Build a new array subscript expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
RebuildArraySubscriptExpr(Expr * LHS,SourceLocation LBracketLoc,Expr * RHS,SourceLocation RBracketLoc)2071 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
2072 SourceLocation LBracketLoc,
2073 Expr *RHS,
2074 SourceLocation RBracketLoc) {
2075 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2076 LBracketLoc, RHS,
2077 RBracketLoc);
2078 }
2079
2080 /// \brief Build a new array section expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
RebuildOMPArraySectionExpr(Expr * Base,SourceLocation LBracketLoc,Expr * LowerBound,SourceLocation ColonLoc,Expr * Length,SourceLocation RBracketLoc)2084 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2085 Expr *LowerBound,
2086 SourceLocation ColonLoc, Expr *Length,
2087 SourceLocation RBracketLoc) {
2088 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2089 ColonLoc, Length, RBracketLoc);
2090 }
2091
2092 /// \brief Build a new call expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
2096 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
2097 MultiExprArg Args,
2098 SourceLocation RParenLoc,
2099 Expr *ExecConfig = nullptr) {
2100 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2101 Args, RParenLoc, ExecConfig);
2102 }
2103
2104 /// \brief Build a new member access expression.
2105 ///
2106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
RebuildMemberExpr(Expr * Base,SourceLocation OpLoc,bool isArrow,NestedNameSpecifierLoc QualifierLoc,SourceLocation TemplateKWLoc,const DeclarationNameInfo & MemberNameInfo,ValueDecl * Member,NamedDecl * FoundDecl,const TemplateArgumentListInfo * ExplicitTemplateArgs,NamedDecl * FirstQualifierInScope)2108 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
2109 bool isArrow,
2110 NestedNameSpecifierLoc QualifierLoc,
2111 SourceLocation TemplateKWLoc,
2112 const DeclarationNameInfo &MemberNameInfo,
2113 ValueDecl *Member,
2114 NamedDecl *FoundDecl,
2115 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2116 NamedDecl *FirstQualifierInScope) {
2117 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2118 isArrow);
2119 if (!Member->getDeclName()) {
2120 // We have a reference to an unnamed field. This is always the
2121 // base of an anonymous struct/union member access, i.e. the
2122 // field is always of record type.
2123 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2124 assert(Member->getType()->isRecordType() &&
2125 "unnamed member not of record type?");
2126
2127 BaseResult =
2128 getSema().PerformObjectMemberConversion(BaseResult.get(),
2129 QualifierLoc.getNestedNameSpecifier(),
2130 FoundDecl, Member);
2131 if (BaseResult.isInvalid())
2132 return ExprError();
2133 Base = BaseResult.get();
2134 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2135 MemberExpr *ME = new (getSema().Context)
2136 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2137 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2138 return ME;
2139 }
2140
2141 CXXScopeSpec SS;
2142 SS.Adopt(QualifierLoc);
2143
2144 Base = BaseResult.get();
2145 QualType BaseType = Base->getType();
2146
2147 // FIXME: this involves duplicating earlier analysis in a lot of
2148 // cases; we should avoid this when possible.
2149 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2150 R.addDecl(FoundDecl);
2151 R.resolveKind();
2152
2153 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2154 SS, TemplateKWLoc,
2155 FirstQualifierInScope,
2156 R, ExplicitTemplateArgs,
2157 /*S*/nullptr);
2158 }
2159
2160 /// \brief Build a new binary operator expression.
2161 ///
2162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
RebuildBinaryOperator(SourceLocation OpLoc,BinaryOperatorKind Opc,Expr * LHS,Expr * RHS)2164 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
2165 BinaryOperatorKind Opc,
2166 Expr *LHS, Expr *RHS) {
2167 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2168 }
2169
2170 /// \brief Build a new conditional operator expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
RebuildConditionalOperator(Expr * Cond,SourceLocation QuestionLoc,Expr * LHS,SourceLocation ColonLoc,Expr * RHS)2174 ExprResult RebuildConditionalOperator(Expr *Cond,
2175 SourceLocation QuestionLoc,
2176 Expr *LHS,
2177 SourceLocation ColonLoc,
2178 Expr *RHS) {
2179 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2180 LHS, RHS);
2181 }
2182
2183 /// \brief Build a new C-style cast expression.
2184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
RebuildCStyleCastExpr(SourceLocation LParenLoc,TypeSourceInfo * TInfo,SourceLocation RParenLoc,Expr * SubExpr)2187 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
2188 TypeSourceInfo *TInfo,
2189 SourceLocation RParenLoc,
2190 Expr *SubExpr) {
2191 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2192 SubExpr);
2193 }
2194
2195 /// \brief Build a new compound literal expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
RebuildCompoundLiteralExpr(SourceLocation LParenLoc,TypeSourceInfo * TInfo,SourceLocation RParenLoc,Expr * Init)2199 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
2200 TypeSourceInfo *TInfo,
2201 SourceLocation RParenLoc,
2202 Expr *Init) {
2203 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2204 Init);
2205 }
2206
2207 /// \brief Build a new extended vector element access expression.
2208 ///
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
RebuildExtVectorElementExpr(Expr * Base,SourceLocation OpLoc,SourceLocation AccessorLoc,IdentifierInfo & Accessor)2211 ExprResult RebuildExtVectorElementExpr(Expr *Base,
2212 SourceLocation OpLoc,
2213 SourceLocation AccessorLoc,
2214 IdentifierInfo &Accessor) {
2215
2216 CXXScopeSpec SS;
2217 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2218 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2219 OpLoc, /*IsArrow*/ false,
2220 SS, SourceLocation(),
2221 /*FirstQualifierInScope*/ nullptr,
2222 NameInfo,
2223 /* TemplateArgs */ nullptr,
2224 /*S*/ nullptr);
2225 }
2226
2227 /// \brief Build a new initializer list expression.
2228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
RebuildInitList(SourceLocation LBraceLoc,MultiExprArg Inits,SourceLocation RBraceLoc,QualType ResultTy)2231 ExprResult RebuildInitList(SourceLocation LBraceLoc,
2232 MultiExprArg Inits,
2233 SourceLocation RBraceLoc,
2234 QualType ResultTy) {
2235 ExprResult Result
2236 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2237 if (Result.isInvalid() || ResultTy->isDependentType())
2238 return Result;
2239
2240 // Patch in the result type we were given, which may have been computed
2241 // when the initial InitListExpr was built.
2242 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2243 ILE->setType(ResultTy);
2244 return Result;
2245 }
2246
2247 /// \brief Build a new designated initializer expression.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
RebuildDesignatedInitExpr(Designation & Desig,MultiExprArg ArrayExprs,SourceLocation EqualOrColonLoc,bool GNUSyntax,Expr * Init)2251 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
2252 MultiExprArg ArrayExprs,
2253 SourceLocation EqualOrColonLoc,
2254 bool GNUSyntax,
2255 Expr *Init) {
2256 ExprResult Result
2257 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2258 Init);
2259 if (Result.isInvalid())
2260 return ExprError();
2261
2262 return Result;
2263 }
2264
2265 /// \brief Build a new value-initialized expression.
2266 ///
2267 /// By default, builds the implicit value initialization without performing
2268 /// any semantic analysis. Subclasses may override this routine to provide
2269 /// different behavior.
RebuildImplicitValueInitExpr(QualType T)2270 ExprResult RebuildImplicitValueInitExpr(QualType T) {
2271 return new (SemaRef.Context) ImplicitValueInitExpr(T);
2272 }
2273
2274 /// \brief Build a new \c va_arg expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
RebuildVAArgExpr(SourceLocation BuiltinLoc,Expr * SubExpr,TypeSourceInfo * TInfo,SourceLocation RParenLoc)2278 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
2279 Expr *SubExpr, TypeSourceInfo *TInfo,
2280 SourceLocation RParenLoc) {
2281 return getSema().BuildVAArgExpr(BuiltinLoc,
2282 SubExpr, TInfo,
2283 RParenLoc);
2284 }
2285
2286 /// \brief Build a new expression list in parentheses.
2287 ///
2288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
RebuildParenListExpr(SourceLocation LParenLoc,MultiExprArg SubExprs,SourceLocation RParenLoc)2290 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
2291 MultiExprArg SubExprs,
2292 SourceLocation RParenLoc) {
2293 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2294 }
2295
2296 /// \brief Build a new address-of-label expression.
2297 ///
2298 /// By default, performs semantic analysis, using the name of the label
2299 /// rather than attempting to map the label statement itself.
2300 /// Subclasses may override this routine to provide different behavior.
RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,SourceLocation LabelLoc,LabelDecl * Label)2301 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
2302 SourceLocation LabelLoc, LabelDecl *Label) {
2303 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2304 }
2305
2306 /// \brief Build a new GNU statement expression.
2307 ///
2308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
RebuildStmtExpr(SourceLocation LParenLoc,Stmt * SubStmt,SourceLocation RParenLoc)2310 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
2311 Stmt *SubStmt,
2312 SourceLocation RParenLoc) {
2313 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2314 }
2315
2316 /// \brief Build a new __builtin_choose_expr expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
RebuildChooseExpr(SourceLocation BuiltinLoc,Expr * Cond,Expr * LHS,Expr * RHS,SourceLocation RParenLoc)2320 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
2321 Expr *Cond, Expr *LHS, Expr *RHS,
2322 SourceLocation RParenLoc) {
2323 return SemaRef.ActOnChooseExpr(BuiltinLoc,
2324 Cond, LHS, RHS,
2325 RParenLoc);
2326 }
2327
2328 /// \brief Build a new generic selection expression.
2329 ///
2330 /// By default, performs semantic analysis to build the new expression.
2331 /// Subclasses may override this routine to provide different behavior.
RebuildGenericSelectionExpr(SourceLocation KeyLoc,SourceLocation DefaultLoc,SourceLocation RParenLoc,Expr * ControllingExpr,ArrayRef<TypeSourceInfo * > Types,ArrayRef<Expr * > Exprs)2332 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2333 SourceLocation DefaultLoc,
2334 SourceLocation RParenLoc,
2335 Expr *ControllingExpr,
2336 ArrayRef<TypeSourceInfo *> Types,
2337 ArrayRef<Expr *> Exprs) {
2338 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2339 ControllingExpr, Types, Exprs);
2340 }
2341
2342 /// \brief Build a new overloaded operator call expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// The semantic analysis provides the behavior of template instantiation,
2346 /// copying with transformations that turn what looks like an overloaded
2347 /// operator call into a use of a builtin operator, performing
2348 /// argument-dependent lookup, etc. Subclasses may override this routine to
2349 /// provide different behavior.
2350 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2351 SourceLocation OpLoc,
2352 Expr *Callee,
2353 Expr *First,
2354 Expr *Second);
2355
2356 /// \brief Build a new C++ "named" cast expression, such as static_cast or
2357 /// reinterpret_cast.
2358 ///
2359 /// By default, this routine dispatches to one of the more-specific routines
2360 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2361 /// Subclasses may override this routine to provide different behavior.
RebuildCXXNamedCastExpr(SourceLocation OpLoc,Stmt::StmtClass Class,SourceLocation LAngleLoc,TypeSourceInfo * TInfo,SourceLocation RAngleLoc,SourceLocation LParenLoc,Expr * SubExpr,SourceLocation RParenLoc)2362 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
2363 Stmt::StmtClass Class,
2364 SourceLocation LAngleLoc,
2365 TypeSourceInfo *TInfo,
2366 SourceLocation RAngleLoc,
2367 SourceLocation LParenLoc,
2368 Expr *SubExpr,
2369 SourceLocation RParenLoc) {
2370 switch (Class) {
2371 case Stmt::CXXStaticCastExprClass:
2372 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2373 RAngleLoc, LParenLoc,
2374 SubExpr, RParenLoc);
2375
2376 case Stmt::CXXDynamicCastExprClass:
2377 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2378 RAngleLoc, LParenLoc,
2379 SubExpr, RParenLoc);
2380
2381 case Stmt::CXXReinterpretCastExprClass:
2382 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2383 RAngleLoc, LParenLoc,
2384 SubExpr,
2385 RParenLoc);
2386
2387 case Stmt::CXXConstCastExprClass:
2388 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2389 RAngleLoc, LParenLoc,
2390 SubExpr, RParenLoc);
2391
2392 default:
2393 llvm_unreachable("Invalid C++ named cast");
2394 }
2395 }
2396
2397 /// \brief Build a new C++ static_cast expression.
2398 ///
2399 /// By default, performs semantic analysis to build the new expression.
2400 /// Subclasses may override this routine to provide different behavior.
RebuildCXXStaticCastExpr(SourceLocation OpLoc,SourceLocation LAngleLoc,TypeSourceInfo * TInfo,SourceLocation RAngleLoc,SourceLocation LParenLoc,Expr * SubExpr,SourceLocation RParenLoc)2401 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
2402 SourceLocation LAngleLoc,
2403 TypeSourceInfo *TInfo,
2404 SourceLocation RAngleLoc,
2405 SourceLocation LParenLoc,
2406 Expr *SubExpr,
2407 SourceLocation RParenLoc) {
2408 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2409 TInfo, SubExpr,
2410 SourceRange(LAngleLoc, RAngleLoc),
2411 SourceRange(LParenLoc, RParenLoc));
2412 }
2413
2414 /// \brief Build a new C++ dynamic_cast expression.
2415 ///
2416 /// By default, performs semantic analysis to build the new expression.
2417 /// Subclasses may override this routine to provide different behavior.
RebuildCXXDynamicCastExpr(SourceLocation OpLoc,SourceLocation LAngleLoc,TypeSourceInfo * TInfo,SourceLocation RAngleLoc,SourceLocation LParenLoc,Expr * SubExpr,SourceLocation RParenLoc)2418 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
2419 SourceLocation LAngleLoc,
2420 TypeSourceInfo *TInfo,
2421 SourceLocation RAngleLoc,
2422 SourceLocation LParenLoc,
2423 Expr *SubExpr,
2424 SourceLocation RParenLoc) {
2425 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2426 TInfo, SubExpr,
2427 SourceRange(LAngleLoc, RAngleLoc),
2428 SourceRange(LParenLoc, RParenLoc));
2429 }
2430
2431 /// \brief Build a new C++ reinterpret_cast expression.
2432 ///
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,SourceLocation LAngleLoc,TypeSourceInfo * TInfo,SourceLocation RAngleLoc,SourceLocation LParenLoc,Expr * SubExpr,SourceLocation RParenLoc)2435 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
2436 SourceLocation LAngleLoc,
2437 TypeSourceInfo *TInfo,
2438 SourceLocation RAngleLoc,
2439 SourceLocation LParenLoc,
2440 Expr *SubExpr,
2441 SourceLocation RParenLoc) {
2442 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2443 TInfo, SubExpr,
2444 SourceRange(LAngleLoc, RAngleLoc),
2445 SourceRange(LParenLoc, RParenLoc));
2446 }
2447
2448 /// \brief Build a new C++ const_cast expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
RebuildCXXConstCastExpr(SourceLocation OpLoc,SourceLocation LAngleLoc,TypeSourceInfo * TInfo,SourceLocation RAngleLoc,SourceLocation LParenLoc,Expr * SubExpr,SourceLocation RParenLoc)2452 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
2453 SourceLocation LAngleLoc,
2454 TypeSourceInfo *TInfo,
2455 SourceLocation RAngleLoc,
2456 SourceLocation LParenLoc,
2457 Expr *SubExpr,
2458 SourceLocation RParenLoc) {
2459 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2460 TInfo, SubExpr,
2461 SourceRange(LAngleLoc, RAngleLoc),
2462 SourceRange(LParenLoc, RParenLoc));
2463 }
2464
2465 /// \brief Build a new C++ functional-style cast expression.
2466 ///
2467 /// By default, performs semantic analysis to build the new expression.
2468 /// Subclasses may override this routine to provide different behavior.
RebuildCXXFunctionalCastExpr(TypeSourceInfo * TInfo,SourceLocation LParenLoc,Expr * Sub,SourceLocation RParenLoc)2469 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2470 SourceLocation LParenLoc,
2471 Expr *Sub,
2472 SourceLocation RParenLoc) {
2473 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2474 MultiExprArg(&Sub, 1),
2475 RParenLoc);
2476 }
2477
2478 /// \brief Build a new C++ typeid(type) expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
RebuildCXXTypeidExpr(QualType TypeInfoType,SourceLocation TypeidLoc,TypeSourceInfo * Operand,SourceLocation RParenLoc)2482 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2483 SourceLocation TypeidLoc,
2484 TypeSourceInfo *Operand,
2485 SourceLocation RParenLoc) {
2486 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2487 RParenLoc);
2488 }
2489
2490
2491 /// \brief Build a new C++ typeid(expr) expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
RebuildCXXTypeidExpr(QualType TypeInfoType,SourceLocation TypeidLoc,Expr * Operand,SourceLocation RParenLoc)2495 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
2496 SourceLocation TypeidLoc,
2497 Expr *Operand,
2498 SourceLocation RParenLoc) {
2499 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2500 RParenLoc);
2501 }
2502
2503 /// \brief Build a new C++ __uuidof(type) expression.
2504 ///
2505 /// By default, performs semantic analysis to build the new expression.
2506 /// Subclasses may override this routine to provide different behavior.
RebuildCXXUuidofExpr(QualType TypeInfoType,SourceLocation TypeidLoc,TypeSourceInfo * Operand,SourceLocation RParenLoc)2507 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2508 SourceLocation TypeidLoc,
2509 TypeSourceInfo *Operand,
2510 SourceLocation RParenLoc) {
2511 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2512 RParenLoc);
2513 }
2514
2515 /// \brief Build a new C++ __uuidof(expr) expression.
2516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
RebuildCXXUuidofExpr(QualType TypeInfoType,SourceLocation TypeidLoc,Expr * Operand,SourceLocation RParenLoc)2519 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2520 SourceLocation TypeidLoc,
2521 Expr *Operand,
2522 SourceLocation RParenLoc) {
2523 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2524 RParenLoc);
2525 }
2526
2527 /// \brief Build a new C++ "this" expression.
2528 ///
2529 /// By default, builds a new "this" expression without performing any
2530 /// semantic analysis. Subclasses may override this routine to provide
2531 /// different behavior.
RebuildCXXThisExpr(SourceLocation ThisLoc,QualType ThisType,bool isImplicit)2532 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
2533 QualType ThisType,
2534 bool isImplicit) {
2535 getSema().CheckCXXThisCapture(ThisLoc);
2536 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2537 }
2538
2539 /// \brief Build a new C++ throw expression.
2540 ///
2541 /// By default, performs semantic analysis to build the new expression.
2542 /// Subclasses may override this routine to provide different behavior.
RebuildCXXThrowExpr(SourceLocation ThrowLoc,Expr * Sub,bool IsThrownVariableInScope)2543 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2544 bool IsThrownVariableInScope) {
2545 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2546 }
2547
2548 /// \brief Build a new C++ default-argument expression.
2549 ///
2550 /// By default, builds a new default-argument expression, which does not
2551 /// require any semantic analysis. Subclasses may override this routine to
2552 /// provide different behavior.
RebuildCXXDefaultArgExpr(SourceLocation Loc,ParmVarDecl * Param)2553 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
2554 ParmVarDecl *Param) {
2555 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2556 }
2557
2558 /// \brief Build a new C++11 default-initialization expression.
2559 ///
2560 /// By default, builds a new default field initialization expression, which
2561 /// does not require any semantic analysis. Subclasses may override this
2562 /// routine to provide different behavior.
RebuildCXXDefaultInitExpr(SourceLocation Loc,FieldDecl * Field)2563 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2564 FieldDecl *Field) {
2565 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2566 }
2567
2568 /// \brief Build a new C++ zero-initialization expression.
2569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
RebuildCXXScalarValueInitExpr(TypeSourceInfo * TSInfo,SourceLocation LParenLoc,SourceLocation RParenLoc)2572 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2573 SourceLocation LParenLoc,
2574 SourceLocation RParenLoc) {
2575 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2576 None, RParenLoc);
2577 }
2578
2579 /// \brief Build a new C++ "new" expression.
2580 ///
2581 /// By default, performs semantic analysis to build the new expression.
2582 /// Subclasses may override this routine to provide different behavior.
RebuildCXXNewExpr(SourceLocation StartLoc,bool UseGlobal,SourceLocation PlacementLParen,MultiExprArg PlacementArgs,SourceLocation PlacementRParen,SourceRange TypeIdParens,QualType AllocatedType,TypeSourceInfo * AllocatedTypeInfo,Expr * ArraySize,SourceRange DirectInitRange,Expr * Initializer)2583 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
2584 bool UseGlobal,
2585 SourceLocation PlacementLParen,
2586 MultiExprArg PlacementArgs,
2587 SourceLocation PlacementRParen,
2588 SourceRange TypeIdParens,
2589 QualType AllocatedType,
2590 TypeSourceInfo *AllocatedTypeInfo,
2591 Expr *ArraySize,
2592 SourceRange DirectInitRange,
2593 Expr *Initializer) {
2594 return getSema().BuildCXXNew(StartLoc, UseGlobal,
2595 PlacementLParen,
2596 PlacementArgs,
2597 PlacementRParen,
2598 TypeIdParens,
2599 AllocatedType,
2600 AllocatedTypeInfo,
2601 ArraySize,
2602 DirectInitRange,
2603 Initializer);
2604 }
2605
2606 /// \brief Build a new C++ "delete" expression.
2607 ///
2608 /// By default, performs semantic analysis to build the new expression.
2609 /// Subclasses may override this routine to provide different behavior.
RebuildCXXDeleteExpr(SourceLocation StartLoc,bool IsGlobalDelete,bool IsArrayForm,Expr * Operand)2610 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2611 bool IsGlobalDelete,
2612 bool IsArrayForm,
2613 Expr *Operand) {
2614 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2615 Operand);
2616 }
2617
2618 /// \brief Build a new type trait expression.
2619 ///
2620 /// By default, performs semantic analysis to build the new expression.
2621 /// Subclasses may override this routine to provide different behavior.
RebuildTypeTrait(TypeTrait Trait,SourceLocation StartLoc,ArrayRef<TypeSourceInfo * > Args,SourceLocation RParenLoc)2622 ExprResult RebuildTypeTrait(TypeTrait Trait,
2623 SourceLocation StartLoc,
2624 ArrayRef<TypeSourceInfo *> Args,
2625 SourceLocation RParenLoc) {
2626 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2627 }
2628
2629 /// \brief Build a new array type trait expression.
2630 ///
2631 /// By default, performs semantic analysis to build the new expression.
2632 /// Subclasses may override this routine to provide different behavior.
RebuildArrayTypeTrait(ArrayTypeTrait Trait,SourceLocation StartLoc,TypeSourceInfo * TSInfo,Expr * DimExpr,SourceLocation RParenLoc)2633 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2634 SourceLocation StartLoc,
2635 TypeSourceInfo *TSInfo,
2636 Expr *DimExpr,
2637 SourceLocation RParenLoc) {
2638 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2639 }
2640
2641 /// \brief Build a new expression trait expression.
2642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
RebuildExpressionTrait(ExpressionTrait Trait,SourceLocation StartLoc,Expr * Queried,SourceLocation RParenLoc)2645 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2646 SourceLocation StartLoc,
2647 Expr *Queried,
2648 SourceLocation RParenLoc) {
2649 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2650 }
2651
2652 /// \brief Build a new (previously unresolved) declaration reference
2653 /// expression.
2654 ///
2655 /// By default, performs semantic analysis to build the new expression.
2656 /// Subclasses may override this routine to provide different behavior.
RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,SourceLocation TemplateKWLoc,const DeclarationNameInfo & NameInfo,const TemplateArgumentListInfo * TemplateArgs,bool IsAddressOfOperand,TypeSourceInfo ** RecoveryTSI)2657 ExprResult RebuildDependentScopeDeclRefExpr(
2658 NestedNameSpecifierLoc QualifierLoc,
2659 SourceLocation TemplateKWLoc,
2660 const DeclarationNameInfo &NameInfo,
2661 const TemplateArgumentListInfo *TemplateArgs,
2662 bool IsAddressOfOperand,
2663 TypeSourceInfo **RecoveryTSI) {
2664 CXXScopeSpec SS;
2665 SS.Adopt(QualifierLoc);
2666
2667 if (TemplateArgs || TemplateKWLoc.isValid())
2668 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2669 TemplateArgs);
2670
2671 return getSema().BuildQualifiedDeclarationNameExpr(
2672 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2673 }
2674
2675 /// \brief Build a new template-id expression.
2676 ///
2677 /// By default, performs semantic analysis to build the new expression.
2678 /// Subclasses may override this routine to provide different behavior.
RebuildTemplateIdExpr(const CXXScopeSpec & SS,SourceLocation TemplateKWLoc,LookupResult & R,bool RequiresADL,const TemplateArgumentListInfo * TemplateArgs)2679 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2680 SourceLocation TemplateKWLoc,
2681 LookupResult &R,
2682 bool RequiresADL,
2683 const TemplateArgumentListInfo *TemplateArgs) {
2684 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2685 TemplateArgs);
2686 }
2687
2688 /// \brief Build a new object-construction expression.
2689 ///
2690 /// By default, performs semantic analysis to build the new expression.
2691 /// Subclasses may override this routine to provide different behavior.
RebuildCXXConstructExpr(QualType T,SourceLocation Loc,CXXConstructorDecl * Constructor,bool IsElidable,MultiExprArg Args,bool HadMultipleCandidates,bool ListInitialization,bool StdInitListInitialization,bool RequiresZeroInit,CXXConstructExpr::ConstructionKind ConstructKind,SourceRange ParenRange)2692 ExprResult RebuildCXXConstructExpr(QualType T,
2693 SourceLocation Loc,
2694 CXXConstructorDecl *Constructor,
2695 bool IsElidable,
2696 MultiExprArg Args,
2697 bool HadMultipleCandidates,
2698 bool ListInitialization,
2699 bool StdInitListInitialization,
2700 bool RequiresZeroInit,
2701 CXXConstructExpr::ConstructionKind ConstructKind,
2702 SourceRange ParenRange) {
2703 SmallVector<Expr*, 8> ConvertedArgs;
2704 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2705 ConvertedArgs))
2706 return ExprError();
2707
2708 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2709 IsElidable,
2710 ConvertedArgs,
2711 HadMultipleCandidates,
2712 ListInitialization,
2713 StdInitListInitialization,
2714 RequiresZeroInit, ConstructKind,
2715 ParenRange);
2716 }
2717
2718 /// \brief Build a new implicit construction via inherited constructor
2719 /// expression.
RebuildCXXInheritedCtorInitExpr(QualType T,SourceLocation Loc,CXXConstructorDecl * Constructor,bool ConstructsVBase,bool InheritedFromVBase)2720 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2721 CXXConstructorDecl *Constructor,
2722 bool ConstructsVBase,
2723 bool InheritedFromVBase) {
2724 return new (getSema().Context) CXXInheritedCtorInitExpr(
2725 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2726 }
2727
2728 /// \brief Build a new object-construction expression.
2729 ///
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
RebuildCXXTemporaryObjectExpr(TypeSourceInfo * TSInfo,SourceLocation LParenLoc,MultiExprArg Args,SourceLocation RParenLoc)2732 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2733 SourceLocation LParenLoc,
2734 MultiExprArg Args,
2735 SourceLocation RParenLoc) {
2736 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2737 LParenLoc,
2738 Args,
2739 RParenLoc);
2740 }
2741
2742 /// \brief Build a new object-construction expression.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
RebuildCXXUnresolvedConstructExpr(TypeSourceInfo * TSInfo,SourceLocation LParenLoc,MultiExprArg Args,SourceLocation RParenLoc)2746 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2747 SourceLocation LParenLoc,
2748 MultiExprArg Args,
2749 SourceLocation RParenLoc) {
2750 return getSema().BuildCXXTypeConstructExpr(TSInfo,
2751 LParenLoc,
2752 Args,
2753 RParenLoc);
2754 }
2755
2756 /// \brief Build a new member reference expression.
2757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
RebuildCXXDependentScopeMemberExpr(Expr * BaseE,QualType BaseType,bool IsArrow,SourceLocation OperatorLoc,NestedNameSpecifierLoc QualifierLoc,SourceLocation TemplateKWLoc,NamedDecl * FirstQualifierInScope,const DeclarationNameInfo & MemberNameInfo,const TemplateArgumentListInfo * TemplateArgs)2760 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
2761 QualType BaseType,
2762 bool IsArrow,
2763 SourceLocation OperatorLoc,
2764 NestedNameSpecifierLoc QualifierLoc,
2765 SourceLocation TemplateKWLoc,
2766 NamedDecl *FirstQualifierInScope,
2767 const DeclarationNameInfo &MemberNameInfo,
2768 const TemplateArgumentListInfo *TemplateArgs) {
2769 CXXScopeSpec SS;
2770 SS.Adopt(QualifierLoc);
2771
2772 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2773 OperatorLoc, IsArrow,
2774 SS, TemplateKWLoc,
2775 FirstQualifierInScope,
2776 MemberNameInfo,
2777 TemplateArgs, /*S*/nullptr);
2778 }
2779
2780 /// \brief Build a new member reference expression.
2781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
RebuildUnresolvedMemberExpr(Expr * BaseE,QualType BaseType,SourceLocation OperatorLoc,bool IsArrow,NestedNameSpecifierLoc QualifierLoc,SourceLocation TemplateKWLoc,NamedDecl * FirstQualifierInScope,LookupResult & R,const TemplateArgumentListInfo * TemplateArgs)2784 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2785 SourceLocation OperatorLoc,
2786 bool IsArrow,
2787 NestedNameSpecifierLoc QualifierLoc,
2788 SourceLocation TemplateKWLoc,
2789 NamedDecl *FirstQualifierInScope,
2790 LookupResult &R,
2791 const TemplateArgumentListInfo *TemplateArgs) {
2792 CXXScopeSpec SS;
2793 SS.Adopt(QualifierLoc);
2794
2795 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2796 OperatorLoc, IsArrow,
2797 SS, TemplateKWLoc,
2798 FirstQualifierInScope,
2799 R, TemplateArgs, /*S*/nullptr);
2800 }
2801
2802 /// \brief Build a new noexcept expression.
2803 ///
2804 /// By default, performs semantic analysis to build the new expression.
2805 /// Subclasses may override this routine to provide different behavior.
RebuildCXXNoexceptExpr(SourceRange Range,Expr * Arg)2806 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2807 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2808 }
2809
2810 /// \brief Build a new expression to compute the length of a parameter pack.
RebuildSizeOfPackExpr(SourceLocation OperatorLoc,NamedDecl * Pack,SourceLocation PackLoc,SourceLocation RParenLoc,Optional<unsigned> Length,ArrayRef<TemplateArgument> PartialArgs)2811 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2812 NamedDecl *Pack,
2813 SourceLocation PackLoc,
2814 SourceLocation RParenLoc,
2815 Optional<unsigned> Length,
2816 ArrayRef<TemplateArgument> PartialArgs) {
2817 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2818 RParenLoc, Length, PartialArgs);
2819 }
2820
2821 /// \brief Build a new Objective-C boxed expression.
2822 ///
2823 /// By default, performs semantic analysis to build the new expression.
2824 /// Subclasses may override this routine to provide different behavior.
RebuildObjCBoxedExpr(SourceRange SR,Expr * ValueExpr)2825 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2826 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2827 }
2828
2829 /// \brief Build a new Objective-C array literal.
2830 ///
2831 /// By default, performs semantic analysis to build the new expression.
2832 /// Subclasses may override this routine to provide different behavior.
RebuildObjCArrayLiteral(SourceRange Range,Expr ** Elements,unsigned NumElements)2833 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2834 Expr **Elements, unsigned NumElements) {
2835 return getSema().BuildObjCArrayLiteral(Range,
2836 MultiExprArg(Elements, NumElements));
2837 }
2838
RebuildObjCSubscriptRefExpr(SourceLocation RB,Expr * Base,Expr * Key,ObjCMethodDecl * getterMethod,ObjCMethodDecl * setterMethod)2839 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2840 Expr *Base, Expr *Key,
2841 ObjCMethodDecl *getterMethod,
2842 ObjCMethodDecl *setterMethod) {
2843 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2844 getterMethod, setterMethod);
2845 }
2846
2847 /// \brief Build a new Objective-C dictionary literal.
2848 ///
2849 /// By default, performs semantic analysis to build the new expression.
2850 /// Subclasses may override this routine to provide different behavior.
RebuildObjCDictionaryLiteral(SourceRange Range,MutableArrayRef<ObjCDictionaryElement> Elements)2851 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2852 MutableArrayRef<ObjCDictionaryElement> Elements) {
2853 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2854 }
2855
2856 /// \brief Build a new Objective-C \@encode expression.
2857 ///
2858 /// By default, performs semantic analysis to build the new expression.
2859 /// Subclasses may override this routine to provide different behavior.
RebuildObjCEncodeExpr(SourceLocation AtLoc,TypeSourceInfo * EncodeTypeInfo,SourceLocation RParenLoc)2860 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
2861 TypeSourceInfo *EncodeTypeInfo,
2862 SourceLocation RParenLoc) {
2863 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2864 }
2865
2866 /// \brief Build a new Objective-C class message.
RebuildObjCMessageExpr(TypeSourceInfo * ReceiverTypeInfo,Selector Sel,ArrayRef<SourceLocation> SelectorLocs,ObjCMethodDecl * Method,SourceLocation LBracLoc,MultiExprArg Args,SourceLocation RBracLoc)2867 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
2868 Selector Sel,
2869 ArrayRef<SourceLocation> SelectorLocs,
2870 ObjCMethodDecl *Method,
2871 SourceLocation LBracLoc,
2872 MultiExprArg Args,
2873 SourceLocation RBracLoc) {
2874 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2875 ReceiverTypeInfo->getType(),
2876 /*SuperLoc=*/SourceLocation(),
2877 Sel, Method, LBracLoc, SelectorLocs,
2878 RBracLoc, Args);
2879 }
2880
2881 /// \brief Build a new Objective-C instance message.
RebuildObjCMessageExpr(Expr * Receiver,Selector Sel,ArrayRef<SourceLocation> SelectorLocs,ObjCMethodDecl * Method,SourceLocation LBracLoc,MultiExprArg Args,SourceLocation RBracLoc)2882 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
2883 Selector Sel,
2884 ArrayRef<SourceLocation> SelectorLocs,
2885 ObjCMethodDecl *Method,
2886 SourceLocation LBracLoc,
2887 MultiExprArg Args,
2888 SourceLocation RBracLoc) {
2889 return SemaRef.BuildInstanceMessage(Receiver,
2890 Receiver->getType(),
2891 /*SuperLoc=*/SourceLocation(),
2892 Sel, Method, LBracLoc, SelectorLocs,
2893 RBracLoc, Args);
2894 }
2895
2896 /// \brief Build a new Objective-C instance/class message to 'super'.
RebuildObjCMessageExpr(SourceLocation SuperLoc,Selector Sel,ArrayRef<SourceLocation> SelectorLocs,QualType SuperType,ObjCMethodDecl * Method,SourceLocation LBracLoc,MultiExprArg Args,SourceLocation RBracLoc)2897 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2898 Selector Sel,
2899 ArrayRef<SourceLocation> SelectorLocs,
2900 QualType SuperType,
2901 ObjCMethodDecl *Method,
2902 SourceLocation LBracLoc,
2903 MultiExprArg Args,
2904 SourceLocation RBracLoc) {
2905 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2906 SuperType,
2907 SuperLoc,
2908 Sel, Method, LBracLoc, SelectorLocs,
2909 RBracLoc, Args)
2910 : SemaRef.BuildClassMessage(nullptr,
2911 SuperType,
2912 SuperLoc,
2913 Sel, Method, LBracLoc, SelectorLocs,
2914 RBracLoc, Args);
2915
2916
2917 }
2918
2919 /// \brief Build a new Objective-C ivar reference expression.
2920 ///
2921 /// By default, performs semantic analysis to build the new expression.
2922 /// Subclasses may override this routine to provide different behavior.
RebuildObjCIvarRefExpr(Expr * BaseArg,ObjCIvarDecl * Ivar,SourceLocation IvarLoc,bool IsArrow,bool IsFreeIvar)2923 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2924 SourceLocation IvarLoc,
2925 bool IsArrow, bool IsFreeIvar) {
2926 // FIXME: We lose track of the IsFreeIvar bit.
2927 CXXScopeSpec SS;
2928 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2929 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2930 /*FIXME:*/IvarLoc, IsArrow,
2931 SS, SourceLocation(),
2932 /*FirstQualifierInScope=*/nullptr,
2933 NameInfo,
2934 /*TemplateArgs=*/nullptr,
2935 /*S=*/nullptr);
2936 }
2937
2938 /// \brief Build a new Objective-C property reference expression.
2939 ///
2940 /// By default, performs semantic analysis to build the new expression.
2941 /// Subclasses may override this routine to provide different behavior.
RebuildObjCPropertyRefExpr(Expr * BaseArg,ObjCPropertyDecl * Property,SourceLocation PropertyLoc)2942 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2943 ObjCPropertyDecl *Property,
2944 SourceLocation PropertyLoc) {
2945 CXXScopeSpec SS;
2946 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2947 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2948 /*FIXME:*/PropertyLoc,
2949 /*IsArrow=*/false,
2950 SS, SourceLocation(),
2951 /*FirstQualifierInScope=*/nullptr,
2952 NameInfo,
2953 /*TemplateArgs=*/nullptr,
2954 /*S=*/nullptr);
2955 }
2956
2957 /// \brief Build a new Objective-C property reference expression.
2958 ///
2959 /// By default, performs semantic analysis to build the new expression.
2960 /// Subclasses may override this routine to provide different behavior.
RebuildObjCPropertyRefExpr(Expr * Base,QualType T,ObjCMethodDecl * Getter,ObjCMethodDecl * Setter,SourceLocation PropertyLoc)2961 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2962 ObjCMethodDecl *Getter,
2963 ObjCMethodDecl *Setter,
2964 SourceLocation PropertyLoc) {
2965 // Since these expressions can only be value-dependent, we do not
2966 // need to perform semantic analysis again.
2967 return Owned(
2968 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2969 VK_LValue, OK_ObjCProperty,
2970 PropertyLoc, Base));
2971 }
2972
2973 /// \brief Build a new Objective-C "isa" expression.
2974 ///
2975 /// By default, performs semantic analysis to build the new expression.
2976 /// Subclasses may override this routine to provide different behavior.
RebuildObjCIsaExpr(Expr * BaseArg,SourceLocation IsaLoc,SourceLocation OpLoc,bool IsArrow)2977 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2978 SourceLocation OpLoc, bool IsArrow) {
2979 CXXScopeSpec SS;
2980 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2981 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2982 OpLoc, IsArrow,
2983 SS, SourceLocation(),
2984 /*FirstQualifierInScope=*/nullptr,
2985 NameInfo,
2986 /*TemplateArgs=*/nullptr,
2987 /*S=*/nullptr);
2988 }
2989
2990 /// \brief Build a new shuffle vector expression.
2991 ///
2992 /// By default, performs semantic analysis to build the new expression.
2993 /// Subclasses may override this routine to provide different behavior.
RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,MultiExprArg SubExprs,SourceLocation RParenLoc)2994 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2995 MultiExprArg SubExprs,
2996 SourceLocation RParenLoc) {
2997 // Find the declaration for __builtin_shufflevector
2998 const IdentifierInfo &Name
2999 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3000 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3001 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3002 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3003
3004 // Build a reference to the __builtin_shufflevector builtin
3005 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3006 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3007 SemaRef.Context.BuiltinFnTy,
3008 VK_RValue, BuiltinLoc);
3009 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3010 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3011 CK_BuiltinFnToFnPtr).get();
3012
3013 // Build the CallExpr
3014 ExprResult TheCall = new (SemaRef.Context) CallExpr(
3015 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3016 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3017
3018 // Type-check the __builtin_shufflevector expression.
3019 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3020 }
3021
3022 /// \brief Build a new convert vector expression.
RebuildConvertVectorExpr(SourceLocation BuiltinLoc,Expr * SrcExpr,TypeSourceInfo * DstTInfo,SourceLocation RParenLoc)3023 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3024 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3025 SourceLocation RParenLoc) {
3026 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3027 BuiltinLoc, RParenLoc);
3028 }
3029
3030 /// \brief Build a new template argument pack expansion.
3031 ///
3032 /// By default, performs semantic analysis to build a new pack expansion
3033 /// for a template argument. Subclasses may override this routine to provide
3034 /// different behavior.
RebuildPackExpansion(TemplateArgumentLoc Pattern,SourceLocation EllipsisLoc,Optional<unsigned> NumExpansions)3035 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
3036 SourceLocation EllipsisLoc,
3037 Optional<unsigned> NumExpansions) {
3038 switch (Pattern.getArgument().getKind()) {
3039 case TemplateArgument::Expression: {
3040 ExprResult Result
3041 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3042 EllipsisLoc, NumExpansions);
3043 if (Result.isInvalid())
3044 return TemplateArgumentLoc();
3045
3046 return TemplateArgumentLoc(Result.get(), Result.get());
3047 }
3048
3049 case TemplateArgument::Template:
3050 return TemplateArgumentLoc(TemplateArgument(
3051 Pattern.getArgument().getAsTemplate(),
3052 NumExpansions),
3053 Pattern.getTemplateQualifierLoc(),
3054 Pattern.getTemplateNameLoc(),
3055 EllipsisLoc);
3056
3057 case TemplateArgument::Null:
3058 case TemplateArgument::Integral:
3059 case TemplateArgument::Declaration:
3060 case TemplateArgument::Pack:
3061 case TemplateArgument::TemplateExpansion:
3062 case TemplateArgument::NullPtr:
3063 llvm_unreachable("Pack expansion pattern has no parameter packs");
3064
3065 case TemplateArgument::Type:
3066 if (TypeSourceInfo *Expansion
3067 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3068 EllipsisLoc,
3069 NumExpansions))
3070 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3071 Expansion);
3072 break;
3073 }
3074
3075 return TemplateArgumentLoc();
3076 }
3077
3078 /// \brief Build a new expression pack expansion.
3079 ///
3080 /// By default, performs semantic analysis to build a new pack expansion
3081 /// for an expression. Subclasses may override this routine to provide
3082 /// different behavior.
RebuildPackExpansion(Expr * Pattern,SourceLocation EllipsisLoc,Optional<unsigned> NumExpansions)3083 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
3084 Optional<unsigned> NumExpansions) {
3085 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3086 }
3087
3088 /// \brief Build a new C++1z fold-expression.
3089 ///
3090 /// By default, performs semantic analysis in order to build a new fold
3091 /// expression.
RebuildCXXFoldExpr(SourceLocation LParenLoc,Expr * LHS,BinaryOperatorKind Operator,SourceLocation EllipsisLoc,Expr * RHS,SourceLocation RParenLoc)3092 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3093 BinaryOperatorKind Operator,
3094 SourceLocation EllipsisLoc, Expr *RHS,
3095 SourceLocation RParenLoc) {
3096 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3097 RHS, RParenLoc);
3098 }
3099
3100 /// \brief Build an empty C++1z fold-expression with the given operator.
3101 ///
3102 /// By default, produces the fallback value for the fold-expression, or
3103 /// produce an error if there is no fallback value.
RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,BinaryOperatorKind Operator)3104 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3105 BinaryOperatorKind Operator) {
3106 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3107 }
3108
3109 /// \brief Build a new atomic operation expression.
3110 ///
3111 /// By default, performs semantic analysis to build the new expression.
3112 /// Subclasses may override this routine to provide different behavior.
RebuildAtomicExpr(SourceLocation BuiltinLoc,MultiExprArg SubExprs,QualType RetTy,AtomicExpr::AtomicOp Op,SourceLocation RParenLoc)3113 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3114 MultiExprArg SubExprs,
3115 QualType RetTy,
3116 AtomicExpr::AtomicOp Op,
3117 SourceLocation RParenLoc) {
3118 // Just create the expression; there is not any interesting semantic
3119 // analysis here because we can't actually build an AtomicExpr until
3120 // we are sure it is semantically sound.
3121 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3122 RParenLoc);
3123 }
3124
3125 private:
3126 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3127 QualType ObjectType,
3128 NamedDecl *FirstQualifierInScope,
3129 CXXScopeSpec &SS);
3130
3131 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3132 QualType ObjectType,
3133 NamedDecl *FirstQualifierInScope,
3134 CXXScopeSpec &SS);
3135
3136 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3137 NamedDecl *FirstQualifierInScope,
3138 CXXScopeSpec &SS);
3139 };
3140
3141 template<typename Derived>
TransformStmt(Stmt * S)3142 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
3143 if (!S)
3144 return S;
3145
3146 switch (S->getStmtClass()) {
3147 case Stmt::NoStmtClass: break;
3148
3149 // Transform individual statement nodes
3150 #define STMT(Node, Parent) \
3151 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3152 #define ABSTRACT_STMT(Node)
3153 #define EXPR(Node, Parent)
3154 #include "clang/AST/StmtNodes.inc"
3155
3156 // Transform expressions by calling TransformExpr.
3157 #define STMT(Node, Parent)
3158 #define ABSTRACT_STMT(Stmt)
3159 #define EXPR(Node, Parent) case Stmt::Node##Class:
3160 #include "clang/AST/StmtNodes.inc"
3161 {
3162 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3163 if (E.isInvalid())
3164 return StmtError();
3165
3166 return getSema().ActOnExprStmt(E);
3167 }
3168 }
3169
3170 return S;
3171 }
3172
3173 template<typename Derived>
TransformOMPClause(OMPClause * S)3174 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3175 if (!S)
3176 return S;
3177
3178 switch (S->getClauseKind()) {
3179 default: break;
3180 // Transform individual clause nodes
3181 #define OPENMP_CLAUSE(Name, Class) \
3182 case OMPC_ ## Name : \
3183 return getDerived().Transform ## Class(cast<Class>(S));
3184 #include "clang/Basic/OpenMPKinds.def"
3185 }
3186
3187 return S;
3188 }
3189
3190
3191 template<typename Derived>
TransformExpr(Expr * E)3192 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
3193 if (!E)
3194 return E;
3195
3196 switch (E->getStmtClass()) {
3197 case Stmt::NoStmtClass: break;
3198 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3199 #define ABSTRACT_STMT(Stmt)
3200 #define EXPR(Node, Parent) \
3201 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3202 #include "clang/AST/StmtNodes.inc"
3203 }
3204
3205 return E;
3206 }
3207
3208 template<typename Derived>
TransformInitializer(Expr * Init,bool NotCopyInit)3209 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
3210 bool NotCopyInit) {
3211 // Initializers are instantiated like expressions, except that various outer
3212 // layers are stripped.
3213 if (!Init)
3214 return Init;
3215
3216 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3217 Init = ExprTemp->getSubExpr();
3218
3219 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3220 Init = MTE->GetTemporaryExpr();
3221
3222 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3223 Init = Binder->getSubExpr();
3224
3225 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3226 Init = ICE->getSubExprAsWritten();
3227
3228 if (CXXStdInitializerListExpr *ILE =
3229 dyn_cast<CXXStdInitializerListExpr>(Init))
3230 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3231
3232 // If this is copy-initialization, we only need to reconstruct
3233 // InitListExprs. Other forms of copy-initialization will be a no-op if
3234 // the initializer is already the right type.
3235 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3236 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3237 return getDerived().TransformExpr(Init);
3238
3239 // Revert value-initialization back to empty parens.
3240 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3241 SourceRange Parens = VIE->getSourceRange();
3242 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3243 Parens.getEnd());
3244 }
3245
3246 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3247 if (isa<ImplicitValueInitExpr>(Init))
3248 return getDerived().RebuildParenListExpr(SourceLocation(), None,
3249 SourceLocation());
3250
3251 // Revert initialization by constructor back to a parenthesized or braced list
3252 // of expressions. Any other form of initializer can just be reused directly.
3253 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3254 return getDerived().TransformExpr(Init);
3255
3256 // If the initialization implicitly converted an initializer list to a
3257 // std::initializer_list object, unwrap the std::initializer_list too.
3258 if (Construct && Construct->isStdInitListInitialization())
3259 return TransformInitializer(Construct->getArg(0), NotCopyInit);
3260
3261 SmallVector<Expr*, 8> NewArgs;
3262 bool ArgChanged = false;
3263 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3264 /*IsCall*/true, NewArgs, &ArgChanged))
3265 return ExprError();
3266
3267 // If this was list initialization, revert to list form.
3268 if (Construct->isListInitialization())
3269 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3270 Construct->getLocEnd(),
3271 Construct->getType());
3272
3273 // Build a ParenListExpr to represent anything else.
3274 SourceRange Parens = Construct->getParenOrBraceRange();
3275 if (Parens.isInvalid()) {
3276 // This was a variable declaration's initialization for which no initializer
3277 // was specified.
3278 assert(NewArgs.empty() &&
3279 "no parens or braces but have direct init with arguments?");
3280 return ExprEmpty();
3281 }
3282 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3283 Parens.getEnd());
3284 }
3285
3286 template<typename Derived>
TransformExprs(Expr * const * Inputs,unsigned NumInputs,bool IsCall,SmallVectorImpl<Expr * > & Outputs,bool * ArgChanged)3287 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
3288 unsigned NumInputs,
3289 bool IsCall,
3290 SmallVectorImpl<Expr *> &Outputs,
3291 bool *ArgChanged) {
3292 for (unsigned I = 0; I != NumInputs; ++I) {
3293 // If requested, drop call arguments that need to be dropped.
3294 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3295 if (ArgChanged)
3296 *ArgChanged = true;
3297
3298 break;
3299 }
3300
3301 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3302 Expr *Pattern = Expansion->getPattern();
3303
3304 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3305 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3306 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3307
3308 // Determine whether the set of unexpanded parameter packs can and should
3309 // be expanded.
3310 bool Expand = true;
3311 bool RetainExpansion = false;
3312 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3313 Optional<unsigned> NumExpansions = OrigNumExpansions;
3314 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3315 Pattern->getSourceRange(),
3316 Unexpanded,
3317 Expand, RetainExpansion,
3318 NumExpansions))
3319 return true;
3320
3321 if (!Expand) {
3322 // The transform has determined that we should perform a simple
3323 // transformation on the pack expansion, producing another pack
3324 // expansion.
3325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3326 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3327 if (OutPattern.isInvalid())
3328 return true;
3329
3330 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3331 Expansion->getEllipsisLoc(),
3332 NumExpansions);
3333 if (Out.isInvalid())
3334 return true;
3335
3336 if (ArgChanged)
3337 *ArgChanged = true;
3338 Outputs.push_back(Out.get());
3339 continue;
3340 }
3341
3342 // Record right away that the argument was changed. This needs
3343 // to happen even if the array expands to nothing.
3344 if (ArgChanged) *ArgChanged = true;
3345
3346 // The transform has determined that we should perform an elementwise
3347 // expansion of the pattern. Do so.
3348 for (unsigned I = 0; I != *NumExpansions; ++I) {
3349 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3350 ExprResult Out = getDerived().TransformExpr(Pattern);
3351 if (Out.isInvalid())
3352 return true;
3353
3354 if (Out.get()->containsUnexpandedParameterPack()) {
3355 Out = getDerived().RebuildPackExpansion(
3356 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3357 if (Out.isInvalid())
3358 return true;
3359 }
3360
3361 Outputs.push_back(Out.get());
3362 }
3363
3364 // If we're supposed to retain a pack expansion, do so by temporarily
3365 // forgetting the partially-substituted parameter pack.
3366 if (RetainExpansion) {
3367 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3368
3369 ExprResult Out = getDerived().TransformExpr(Pattern);
3370 if (Out.isInvalid())
3371 return true;
3372
3373 Out = getDerived().RebuildPackExpansion(
3374 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3375 if (Out.isInvalid())
3376 return true;
3377
3378 Outputs.push_back(Out.get());
3379 }
3380
3381 continue;
3382 }
3383
3384 ExprResult Result =
3385 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3386 : getDerived().TransformExpr(Inputs[I]);
3387 if (Result.isInvalid())
3388 return true;
3389
3390 if (Result.get() != Inputs[I] && ArgChanged)
3391 *ArgChanged = true;
3392
3393 Outputs.push_back(Result.get());
3394 }
3395
3396 return false;
3397 }
3398
3399 template <typename Derived>
TransformCondition(SourceLocation Loc,VarDecl * Var,Expr * Expr,Sema::ConditionKind Kind)3400 Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3401 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3402 if (Var) {
3403 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3404 getDerived().TransformDefinition(Var->getLocation(), Var));
3405
3406 if (!ConditionVar)
3407 return Sema::ConditionError();
3408
3409 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3410 }
3411
3412 if (Expr) {
3413 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3414
3415 if (CondExpr.isInvalid())
3416 return Sema::ConditionError();
3417
3418 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3419 }
3420
3421 return Sema::ConditionResult();
3422 }
3423
3424 template<typename Derived>
3425 NestedNameSpecifierLoc
TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,QualType ObjectType,NamedDecl * FirstQualifierInScope)3426 TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3427 NestedNameSpecifierLoc NNS,
3428 QualType ObjectType,
3429 NamedDecl *FirstQualifierInScope) {
3430 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
3431 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3432 Qualifier = Qualifier.getPrefix())
3433 Qualifiers.push_back(Qualifier);
3434
3435 CXXScopeSpec SS;
3436 while (!Qualifiers.empty()) {
3437 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3438 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
3439
3440 switch (QNNS->getKind()) {
3441 case NestedNameSpecifier::Identifier:
3442 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
3443 *QNNS->getAsIdentifier(),
3444 Q.getLocalBeginLoc(),
3445 Q.getLocalEndLoc(),
3446 ObjectType, false, SS,
3447 FirstQualifierInScope, false))
3448 return NestedNameSpecifierLoc();
3449
3450 break;
3451
3452 case NestedNameSpecifier::Namespace: {
3453 NamespaceDecl *NS
3454 = cast_or_null<NamespaceDecl>(
3455 getDerived().TransformDecl(
3456 Q.getLocalBeginLoc(),
3457 QNNS->getAsNamespace()));
3458 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3459 break;
3460 }
3461
3462 case NestedNameSpecifier::NamespaceAlias: {
3463 NamespaceAliasDecl *Alias
3464 = cast_or_null<NamespaceAliasDecl>(
3465 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3466 QNNS->getAsNamespaceAlias()));
3467 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3468 Q.getLocalEndLoc());
3469 break;
3470 }
3471
3472 case NestedNameSpecifier::Global:
3473 // There is no meaningful transformation that one could perform on the
3474 // global scope.
3475 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3476 break;
3477
3478 case NestedNameSpecifier::Super: {
3479 CXXRecordDecl *RD =
3480 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3481 SourceLocation(), QNNS->getAsRecordDecl()));
3482 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3483 break;
3484 }
3485
3486 case NestedNameSpecifier::TypeSpecWithTemplate:
3487 case NestedNameSpecifier::TypeSpec: {
3488 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3489 FirstQualifierInScope, SS);
3490
3491 if (!TL)
3492 return NestedNameSpecifierLoc();
3493
3494 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3495 (SemaRef.getLangOpts().CPlusPlus11 &&
3496 TL.getType()->isEnumeralType())) {
3497 assert(!TL.getType().hasLocalQualifiers() &&
3498 "Can't get cv-qualifiers here");
3499 if (TL.getType()->isEnumeralType())
3500 SemaRef.Diag(TL.getBeginLoc(),
3501 diag::warn_cxx98_compat_enum_nested_name_spec);
3502 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3503 Q.getLocalEndLoc());
3504 break;
3505 }
3506 // If the nested-name-specifier is an invalid type def, don't emit an
3507 // error because a previous error should have already been emitted.
3508 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3509 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3510 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3511 << TL.getType() << SS.getRange();
3512 }
3513 return NestedNameSpecifierLoc();
3514 }
3515 }
3516
3517 // The qualifier-in-scope and object type only apply to the leftmost entity.
3518 FirstQualifierInScope = nullptr;
3519 ObjectType = QualType();
3520 }
3521
3522 // Don't rebuild the nested-name-specifier if we don't have to.
3523 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3524 !getDerived().AlwaysRebuild())
3525 return NNS;
3526
3527 // If we can re-use the source-location data from the original
3528 // nested-name-specifier, do so.
3529 if (SS.location_size() == NNS.getDataLength() &&
3530 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3531 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3532
3533 // Allocate new nested-name-specifier location information.
3534 return SS.getWithLocInContext(SemaRef.Context);
3535 }
3536
3537 template<typename Derived>
3538 DeclarationNameInfo
3539 TreeTransform<Derived>
TransformDeclarationNameInfo(const DeclarationNameInfo & NameInfo)3540 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
3541 DeclarationName Name = NameInfo.getName();
3542 if (!Name)
3543 return DeclarationNameInfo();
3544
3545 switch (Name.getNameKind()) {
3546 case DeclarationName::Identifier:
3547 case DeclarationName::ObjCZeroArgSelector:
3548 case DeclarationName::ObjCOneArgSelector:
3549 case DeclarationName::ObjCMultiArgSelector:
3550 case DeclarationName::CXXOperatorName:
3551 case DeclarationName::CXXLiteralOperatorName:
3552 case DeclarationName::CXXUsingDirective:
3553 return NameInfo;
3554
3555 case DeclarationName::CXXConstructorName:
3556 case DeclarationName::CXXDestructorName:
3557 case DeclarationName::CXXConversionFunctionName: {
3558 TypeSourceInfo *NewTInfo;
3559 CanQualType NewCanTy;
3560 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3561 NewTInfo = getDerived().TransformType(OldTInfo);
3562 if (!NewTInfo)
3563 return DeclarationNameInfo();
3564 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3565 }
3566 else {
3567 NewTInfo = nullptr;
3568 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3569 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3570 if (NewT.isNull())
3571 return DeclarationNameInfo();
3572 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3573 }
3574
3575 DeclarationName NewName
3576 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3577 NewCanTy);
3578 DeclarationNameInfo NewNameInfo(NameInfo);
3579 NewNameInfo.setName(NewName);
3580 NewNameInfo.setNamedTypeInfo(NewTInfo);
3581 return NewNameInfo;
3582 }
3583 }
3584
3585 llvm_unreachable("Unknown name kind.");
3586 }
3587
3588 template<typename Derived>
3589 TemplateName
TransformTemplateName(CXXScopeSpec & SS,TemplateName Name,SourceLocation NameLoc,QualType ObjectType,NamedDecl * FirstQualifierInScope)3590 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3591 TemplateName Name,
3592 SourceLocation NameLoc,
3593 QualType ObjectType,
3594 NamedDecl *FirstQualifierInScope) {
3595 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3596 TemplateDecl *Template = QTN->getTemplateDecl();
3597 assert(Template && "qualified template name must refer to a template");
3598
3599 TemplateDecl *TransTemplate
3600 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3601 Template));
3602 if (!TransTemplate)
3603 return TemplateName();
3604
3605 if (!getDerived().AlwaysRebuild() &&
3606 SS.getScopeRep() == QTN->getQualifier() &&
3607 TransTemplate == Template)
3608 return Name;
3609
3610 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3611 TransTemplate);
3612 }
3613
3614 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3615 if (SS.getScopeRep()) {
3616 // These apply to the scope specifier, not the template.
3617 ObjectType = QualType();
3618 FirstQualifierInScope = nullptr;
3619 }
3620
3621 if (!getDerived().AlwaysRebuild() &&
3622 SS.getScopeRep() == DTN->getQualifier() &&
3623 ObjectType.isNull())
3624 return Name;
3625
3626 if (DTN->isIdentifier()) {
3627 return getDerived().RebuildTemplateName(SS,
3628 *DTN->getIdentifier(),
3629 NameLoc,
3630 ObjectType,
3631 FirstQualifierInScope);
3632 }
3633
3634 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3635 ObjectType);
3636 }
3637
3638 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3639 TemplateDecl *TransTemplate
3640 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3641 Template));
3642 if (!TransTemplate)
3643 return TemplateName();
3644
3645 if (!getDerived().AlwaysRebuild() &&
3646 TransTemplate == Template)
3647 return Name;
3648
3649 return TemplateName(TransTemplate);
3650 }
3651
3652 if (SubstTemplateTemplateParmPackStorage *SubstPack
3653 = Name.getAsSubstTemplateTemplateParmPack()) {
3654 TemplateTemplateParmDecl *TransParam
3655 = cast_or_null<TemplateTemplateParmDecl>(
3656 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3657 if (!TransParam)
3658 return TemplateName();
3659
3660 if (!getDerived().AlwaysRebuild() &&
3661 TransParam == SubstPack->getParameterPack())
3662 return Name;
3663
3664 return getDerived().RebuildTemplateName(TransParam,
3665 SubstPack->getArgumentPack());
3666 }
3667
3668 // These should be getting filtered out before they reach the AST.
3669 llvm_unreachable("overloaded function decl survived to here");
3670 }
3671
3672 template<typename Derived>
InventTemplateArgumentLoc(const TemplateArgument & Arg,TemplateArgumentLoc & Output)3673 void TreeTransform<Derived>::InventTemplateArgumentLoc(
3674 const TemplateArgument &Arg,
3675 TemplateArgumentLoc &Output) {
3676 SourceLocation Loc = getDerived().getBaseLocation();
3677 switch (Arg.getKind()) {
3678 case TemplateArgument::Null:
3679 llvm_unreachable("null template argument in TreeTransform");
3680 break;
3681
3682 case TemplateArgument::Type:
3683 Output = TemplateArgumentLoc(Arg,
3684 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3685
3686 break;
3687
3688 case TemplateArgument::Template:
3689 case TemplateArgument::TemplateExpansion: {
3690 NestedNameSpecifierLocBuilder Builder;
3691 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
3692 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3693 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3694 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3695 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3696
3697 if (Arg.getKind() == TemplateArgument::Template)
3698 Output = TemplateArgumentLoc(Arg,
3699 Builder.getWithLocInContext(SemaRef.Context),
3700 Loc);
3701 else
3702 Output = TemplateArgumentLoc(Arg,
3703 Builder.getWithLocInContext(SemaRef.Context),
3704 Loc, Loc);
3705
3706 break;
3707 }
3708
3709 case TemplateArgument::Expression:
3710 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3711 break;
3712
3713 case TemplateArgument::Declaration:
3714 case TemplateArgument::Integral:
3715 case TemplateArgument::Pack:
3716 case TemplateArgument::NullPtr:
3717 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
3718 break;
3719 }
3720 }
3721
3722 template<typename Derived>
TransformTemplateArgument(const TemplateArgumentLoc & Input,TemplateArgumentLoc & Output,bool Uneval)3723 bool TreeTransform<Derived>::TransformTemplateArgument(
3724 const TemplateArgumentLoc &Input,
3725 TemplateArgumentLoc &Output, bool Uneval) {
3726 const TemplateArgument &Arg = Input.getArgument();
3727 switch (Arg.getKind()) {
3728 case TemplateArgument::Null:
3729 case TemplateArgument::Integral:
3730 case TemplateArgument::Pack:
3731 case TemplateArgument::Declaration:
3732 case TemplateArgument::NullPtr:
3733 llvm_unreachable("Unexpected TemplateArgument");
3734
3735 case TemplateArgument::Type: {
3736 TypeSourceInfo *DI = Input.getTypeSourceInfo();
3737 if (!DI)
3738 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3739
3740 DI = getDerived().TransformType(DI);
3741 if (!DI) return true;
3742
3743 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3744 return false;
3745 }
3746
3747 case TemplateArgument::Template: {
3748 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3749 if (QualifierLoc) {
3750 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3751 if (!QualifierLoc)
3752 return true;
3753 }
3754
3755 CXXScopeSpec SS;
3756 SS.Adopt(QualifierLoc);
3757 TemplateName Template
3758 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3759 Input.getTemplateNameLoc());
3760 if (Template.isNull())
3761 return true;
3762
3763 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3764 Input.getTemplateNameLoc());
3765 return false;
3766 }
3767
3768 case TemplateArgument::TemplateExpansion:
3769 llvm_unreachable("Caller should expand pack expansions");
3770
3771 case TemplateArgument::Expression: {
3772 // Template argument expressions are constant expressions.
3773 EnterExpressionEvaluationContext Unevaluated(
3774 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
3775
3776 Expr *InputExpr = Input.getSourceExpression();
3777 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3778
3779 ExprResult E = getDerived().TransformExpr(InputExpr);
3780 E = SemaRef.ActOnConstantExpression(E);
3781 if (E.isInvalid()) return true;
3782 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3783 return false;
3784 }
3785 }
3786
3787 // Work around bogus GCC warning
3788 return true;
3789 }
3790
3791 /// \brief Iterator adaptor that invents template argument location information
3792 /// for each of the template arguments in its underlying iterator.
3793 template<typename Derived, typename InputIterator>
3794 class TemplateArgumentLocInventIterator {
3795 TreeTransform<Derived> &Self;
3796 InputIterator Iter;
3797
3798 public:
3799 typedef TemplateArgumentLoc value_type;
3800 typedef TemplateArgumentLoc reference;
3801 typedef typename std::iterator_traits<InputIterator>::difference_type
3802 difference_type;
3803 typedef std::input_iterator_tag iterator_category;
3804
3805 class pointer {
3806 TemplateArgumentLoc Arg;
3807
3808 public:
pointer(TemplateArgumentLoc Arg)3809 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3810
3811 const TemplateArgumentLoc *operator->() const { return &Arg; }
3812 };
3813
TemplateArgumentLocInventIterator()3814 TemplateArgumentLocInventIterator() { }
3815
TemplateArgumentLocInventIterator(TreeTransform<Derived> & Self,InputIterator Iter)3816 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3817 InputIterator Iter)
3818 : Self(Self), Iter(Iter) { }
3819
3820 TemplateArgumentLocInventIterator &operator++() {
3821 ++Iter;
3822 return *this;
3823 }
3824
3825 TemplateArgumentLocInventIterator operator++(int) {
3826 TemplateArgumentLocInventIterator Old(*this);
3827 ++(*this);
3828 return Old;
3829 }
3830
3831 reference operator*() const {
3832 TemplateArgumentLoc Result;
3833 Self.InventTemplateArgumentLoc(*Iter, Result);
3834 return Result;
3835 }
3836
3837 pointer operator->() const { return pointer(**this); }
3838
3839 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3840 const TemplateArgumentLocInventIterator &Y) {
3841 return X.Iter == Y.Iter;
3842 }
3843
3844 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3845 const TemplateArgumentLocInventIterator &Y) {
3846 return X.Iter != Y.Iter;
3847 }
3848 };
3849
3850 template<typename Derived>
3851 template<typename InputIterator>
TransformTemplateArguments(InputIterator First,InputIterator Last,TemplateArgumentListInfo & Outputs,bool Uneval)3852 bool TreeTransform<Derived>::TransformTemplateArguments(
3853 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3854 bool Uneval) {
3855 for (; First != Last; ++First) {
3856 TemplateArgumentLoc Out;
3857 TemplateArgumentLoc In = *First;
3858
3859 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3860 // Unpack argument packs, which we translate them into separate
3861 // arguments.
3862 // FIXME: We could do much better if we could guarantee that the
3863 // TemplateArgumentLocInfo for the pack expansion would be usable for
3864 // all of the template arguments in the argument pack.
3865 typedef TemplateArgumentLocInventIterator<Derived,
3866 TemplateArgument::pack_iterator>
3867 PackLocIterator;
3868 if (TransformTemplateArguments(PackLocIterator(*this,
3869 In.getArgument().pack_begin()),
3870 PackLocIterator(*this,
3871 In.getArgument().pack_end()),
3872 Outputs, Uneval))
3873 return true;
3874
3875 continue;
3876 }
3877
3878 if (In.getArgument().isPackExpansion()) {
3879 // We have a pack expansion, for which we will be substituting into
3880 // the pattern.
3881 SourceLocation Ellipsis;
3882 Optional<unsigned> OrigNumExpansions;
3883 TemplateArgumentLoc Pattern
3884 = getSema().getTemplateArgumentPackExpansionPattern(
3885 In, Ellipsis, OrigNumExpansions);
3886
3887 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3888 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3889 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3890
3891 // Determine whether the set of unexpanded parameter packs can and should
3892 // be expanded.
3893 bool Expand = true;
3894 bool RetainExpansion = false;
3895 Optional<unsigned> NumExpansions = OrigNumExpansions;
3896 if (getDerived().TryExpandParameterPacks(Ellipsis,
3897 Pattern.getSourceRange(),
3898 Unexpanded,
3899 Expand,
3900 RetainExpansion,
3901 NumExpansions))
3902 return true;
3903
3904 if (!Expand) {
3905 // The transform has determined that we should perform a simple
3906 // transformation on the pack expansion, producing another pack
3907 // expansion.
3908 TemplateArgumentLoc OutPattern;
3909 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3910 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
3911 return true;
3912
3913 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3914 NumExpansions);
3915 if (Out.getArgument().isNull())
3916 return true;
3917
3918 Outputs.addArgument(Out);
3919 continue;
3920 }
3921
3922 // The transform has determined that we should perform an elementwise
3923 // expansion of the pattern. Do so.
3924 for (unsigned I = 0; I != *NumExpansions; ++I) {
3925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3926
3927 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3928 return true;
3929
3930 if (Out.getArgument().containsUnexpandedParameterPack()) {
3931 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3932 OrigNumExpansions);
3933 if (Out.getArgument().isNull())
3934 return true;
3935 }
3936
3937 Outputs.addArgument(Out);
3938 }
3939
3940 // If we're supposed to retain a pack expansion, do so by temporarily
3941 // forgetting the partially-substituted parameter pack.
3942 if (RetainExpansion) {
3943 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3944
3945 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3946 return true;
3947
3948 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3949 OrigNumExpansions);
3950 if (Out.getArgument().isNull())
3951 return true;
3952
3953 Outputs.addArgument(Out);
3954 }
3955
3956 continue;
3957 }
3958
3959 // The simple case:
3960 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
3961 return true;
3962
3963 Outputs.addArgument(Out);
3964 }
3965
3966 return false;
3967
3968 }
3969
3970 //===----------------------------------------------------------------------===//
3971 // Type transformation
3972 //===----------------------------------------------------------------------===//
3973
3974 template<typename Derived>
TransformType(QualType T)3975 QualType TreeTransform<Derived>::TransformType(QualType T) {
3976 if (getDerived().AlreadyTransformed(T))
3977 return T;
3978
3979 // Temporary workaround. All of these transformations should
3980 // eventually turn into transformations on TypeLocs.
3981 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3982 getDerived().getBaseLocation());
3983
3984 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3985
3986 if (!NewDI)
3987 return QualType();
3988
3989 return NewDI->getType();
3990 }
3991
3992 template<typename Derived>
TransformType(TypeSourceInfo * DI)3993 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3994 // Refine the base location to the type's location.
3995 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3996 getDerived().getBaseEntity());
3997 if (getDerived().AlreadyTransformed(DI->getType()))
3998 return DI;
3999
4000 TypeLocBuilder TLB;
4001
4002 TypeLoc TL = DI->getTypeLoc();
4003 TLB.reserve(TL.getFullDataSize());
4004
4005 QualType Result = getDerived().TransformType(TLB, TL);
4006 if (Result.isNull())
4007 return nullptr;
4008
4009 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4010 }
4011
4012 template<typename Derived>
4013 QualType
TransformType(TypeLocBuilder & TLB,TypeLoc T)4014 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
4015 switch (T.getTypeLocClass()) {
4016 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4017 #define TYPELOC(CLASS, PARENT) \
4018 case TypeLoc::CLASS: \
4019 return getDerived().Transform##CLASS##Type(TLB, \
4020 T.castAs<CLASS##TypeLoc>());
4021 #include "clang/AST/TypeLocNodes.def"
4022 }
4023
4024 llvm_unreachable("unhandled type loc!");
4025 }
4026
4027 /// FIXME: By default, this routine adds type qualifiers only to types
4028 /// that can have qualifiers, and silently suppresses those qualifiers
4029 /// that are not permitted (e.g., qualifiers on reference or function
4030 /// types). This is the right thing for template instantiation, but
4031 /// probably not for other clients.
4032 template<typename Derived>
4033 QualType
TransformQualifiedType(TypeLocBuilder & TLB,QualifiedTypeLoc T)4034 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
4035 QualifiedTypeLoc T) {
4036 Qualifiers Quals = T.getType().getLocalQualifiers();
4037
4038 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4039 if (Result.isNull())
4040 return QualType();
4041
4042 // Silently suppress qualifiers if the result type can't be qualified.
4043 // FIXME: this is the right thing for template instantiation, but
4044 // probably not for other clients.
4045 if (Result->isFunctionType() || Result->isReferenceType())
4046 return Result;
4047
4048 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4049 // resulting type.
4050 if (Quals.hasObjCLifetime()) {
4051 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4052 Quals.removeObjCLifetime();
4053 else if (Result.getObjCLifetime()) {
4054 // Objective-C ARC:
4055 // A lifetime qualifier applied to a substituted template parameter
4056 // overrides the lifetime qualifier from the template argument.
4057 const AutoType *AutoTy;
4058 if (const SubstTemplateTypeParmType *SubstTypeParam
4059 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4060 QualType Replacement = SubstTypeParam->getReplacementType();
4061 Qualifiers Qs = Replacement.getQualifiers();
4062 Qs.removeObjCLifetime();
4063 Replacement
4064 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4065 Qs);
4066 Result = SemaRef.Context.getSubstTemplateTypeParmType(
4067 SubstTypeParam->getReplacedParameter(),
4068 Replacement);
4069 TLB.TypeWasModifiedSafely(Result);
4070 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4071 // 'auto' types behave the same way as template parameters.
4072 QualType Deduced = AutoTy->getDeducedType();
4073 Qualifiers Qs = Deduced.getQualifiers();
4074 Qs.removeObjCLifetime();
4075 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4076 Qs);
4077 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4078 AutoTy->isDependentType());
4079 TLB.TypeWasModifiedSafely(Result);
4080 } else {
4081 // Otherwise, complain about the addition of a qualifier to an
4082 // already-qualified type.
4083 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
4084 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
4085 << Result << R;
4086
4087 Quals.removeObjCLifetime();
4088 }
4089 }
4090 }
4091 if (!Quals.empty()) {
4092 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
4093 // BuildQualifiedType might not add qualifiers if they are invalid.
4094 if (Result.hasLocalQualifiers())
4095 TLB.push<QualifiedTypeLoc>(Result);
4096 // No location information to preserve.
4097 }
4098
4099 return Result;
4100 }
4101
4102 template<typename Derived>
4103 TypeLoc
TransformTypeInObjectScope(TypeLoc TL,QualType ObjectType,NamedDecl * UnqualLookup,CXXScopeSpec & SS)4104 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4105 QualType ObjectType,
4106 NamedDecl *UnqualLookup,
4107 CXXScopeSpec &SS) {
4108 if (getDerived().AlreadyTransformed(TL.getType()))
4109 return TL;
4110
4111 TypeSourceInfo *TSI =
4112 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4113 if (TSI)
4114 return TSI->getTypeLoc();
4115 return TypeLoc();
4116 }
4117
4118 template<typename Derived>
4119 TypeSourceInfo *
TransformTypeInObjectScope(TypeSourceInfo * TSInfo,QualType ObjectType,NamedDecl * UnqualLookup,CXXScopeSpec & SS)4120 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4121 QualType ObjectType,
4122 NamedDecl *UnqualLookup,
4123 CXXScopeSpec &SS) {
4124 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4125 return TSInfo;
4126
4127 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4128 UnqualLookup, SS);
4129 }
4130
4131 template <typename Derived>
TransformTSIInObjectScope(TypeLoc TL,QualType ObjectType,NamedDecl * UnqualLookup,CXXScopeSpec & SS)4132 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4133 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4134 CXXScopeSpec &SS) {
4135 QualType T = TL.getType();
4136 assert(!getDerived().AlreadyTransformed(T));
4137
4138 TypeLocBuilder TLB;
4139 QualType Result;
4140
4141 if (isa<TemplateSpecializationType>(T)) {
4142 TemplateSpecializationTypeLoc SpecTL =
4143 TL.castAs<TemplateSpecializationTypeLoc>();
4144
4145 TemplateName Template
4146 = getDerived().TransformTemplateName(SS,
4147 SpecTL.getTypePtr()->getTemplateName(),
4148 SpecTL.getTemplateNameLoc(),
4149 ObjectType, UnqualLookup);
4150 if (Template.isNull())
4151 return nullptr;
4152
4153 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4154 Template);
4155 } else if (isa<DependentTemplateSpecializationType>(T)) {
4156 DependentTemplateSpecializationTypeLoc SpecTL =
4157 TL.castAs<DependentTemplateSpecializationTypeLoc>();
4158
4159 TemplateName Template
4160 = getDerived().RebuildTemplateName(SS,
4161 *SpecTL.getTypePtr()->getIdentifier(),
4162 SpecTL.getTemplateNameLoc(),
4163 ObjectType, UnqualLookup);
4164 if (Template.isNull())
4165 return nullptr;
4166
4167 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4168 SpecTL,
4169 Template,
4170 SS);
4171 } else {
4172 // Nothing special needs to be done for these.
4173 Result = getDerived().TransformType(TLB, TL);
4174 }
4175
4176 if (Result.isNull())
4177 return nullptr;
4178
4179 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4180 }
4181
4182 template <class TyLoc> static inline
TransformTypeSpecType(TypeLocBuilder & TLB,TyLoc T)4183 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4184 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4185 NewT.setNameLoc(T.getNameLoc());
4186 return T.getType();
4187 }
4188
4189 template<typename Derived>
TransformBuiltinType(TypeLocBuilder & TLB,BuiltinTypeLoc T)4190 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4191 BuiltinTypeLoc T) {
4192 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4193 NewT.setBuiltinLoc(T.getBuiltinLoc());
4194 if (T.needsExtraLocalData())
4195 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4196 return T.getType();
4197 }
4198
4199 template<typename Derived>
TransformComplexType(TypeLocBuilder & TLB,ComplexTypeLoc T)4200 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4201 ComplexTypeLoc T) {
4202 // FIXME: recurse?
4203 return TransformTypeSpecType(TLB, T);
4204 }
4205
4206 template <typename Derived>
TransformAdjustedType(TypeLocBuilder & TLB,AdjustedTypeLoc TL)4207 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4208 AdjustedTypeLoc TL) {
4209 // Adjustments applied during transformation are handled elsewhere.
4210 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4211 }
4212
4213 template<typename Derived>
TransformDecayedType(TypeLocBuilder & TLB,DecayedTypeLoc TL)4214 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4215 DecayedTypeLoc TL) {
4216 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4217 if (OriginalType.isNull())
4218 return QualType();
4219
4220 QualType Result = TL.getType();
4221 if (getDerived().AlwaysRebuild() ||
4222 OriginalType != TL.getOriginalLoc().getType())
4223 Result = SemaRef.Context.getDecayedType(OriginalType);
4224 TLB.push<DecayedTypeLoc>(Result);
4225 // Nothing to set for DecayedTypeLoc.
4226 return Result;
4227 }
4228
4229 template<typename Derived>
TransformPointerType(TypeLocBuilder & TLB,PointerTypeLoc TL)4230 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4231 PointerTypeLoc TL) {
4232 QualType PointeeType
4233 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4234 if (PointeeType.isNull())
4235 return QualType();
4236
4237 QualType Result = TL.getType();
4238 if (PointeeType->getAs<ObjCObjectType>()) {
4239 // A dependent pointer type 'T *' has is being transformed such
4240 // that an Objective-C class type is being replaced for 'T'. The
4241 // resulting pointer type is an ObjCObjectPointerType, not a
4242 // PointerType.
4243 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4244
4245 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4246 NewT.setStarLoc(TL.getStarLoc());
4247 return Result;
4248 }
4249
4250 if (getDerived().AlwaysRebuild() ||
4251 PointeeType != TL.getPointeeLoc().getType()) {
4252 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4253 if (Result.isNull())
4254 return QualType();
4255 }
4256
4257 // Objective-C ARC can add lifetime qualifiers to the type that we're
4258 // pointing to.
4259 TLB.TypeWasModifiedSafely(Result->getPointeeType());
4260
4261 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4262 NewT.setSigilLoc(TL.getSigilLoc());
4263 return Result;
4264 }
4265
4266 template<typename Derived>
4267 QualType
TransformBlockPointerType(TypeLocBuilder & TLB,BlockPointerTypeLoc TL)4268 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4269 BlockPointerTypeLoc TL) {
4270 QualType PointeeType
4271 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4272 if (PointeeType.isNull())
4273 return QualType();
4274
4275 QualType Result = TL.getType();
4276 if (getDerived().AlwaysRebuild() ||
4277 PointeeType != TL.getPointeeLoc().getType()) {
4278 Result = getDerived().RebuildBlockPointerType(PointeeType,
4279 TL.getSigilLoc());
4280 if (Result.isNull())
4281 return QualType();
4282 }
4283
4284 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4285 NewT.setSigilLoc(TL.getSigilLoc());
4286 return Result;
4287 }
4288
4289 /// Transforms a reference type. Note that somewhat paradoxically we
4290 /// don't care whether the type itself is an l-value type or an r-value
4291 /// type; we only care if the type was *written* as an l-value type
4292 /// or an r-value type.
4293 template<typename Derived>
4294 QualType
TransformReferenceType(TypeLocBuilder & TLB,ReferenceTypeLoc TL)4295 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
4296 ReferenceTypeLoc TL) {
4297 const ReferenceType *T = TL.getTypePtr();
4298
4299 // Note that this works with the pointee-as-written.
4300 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4301 if (PointeeType.isNull())
4302 return QualType();
4303
4304 QualType Result = TL.getType();
4305 if (getDerived().AlwaysRebuild() ||
4306 PointeeType != T->getPointeeTypeAsWritten()) {
4307 Result = getDerived().RebuildReferenceType(PointeeType,
4308 T->isSpelledAsLValue(),
4309 TL.getSigilLoc());
4310 if (Result.isNull())
4311 return QualType();
4312 }
4313
4314 // Objective-C ARC can add lifetime qualifiers to the type that we're
4315 // referring to.
4316 TLB.TypeWasModifiedSafely(
4317 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4318
4319 // r-value references can be rebuilt as l-value references.
4320 ReferenceTypeLoc NewTL;
4321 if (isa<LValueReferenceType>(Result))
4322 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4323 else
4324 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4325 NewTL.setSigilLoc(TL.getSigilLoc());
4326
4327 return Result;
4328 }
4329
4330 template<typename Derived>
4331 QualType
TransformLValueReferenceType(TypeLocBuilder & TLB,LValueReferenceTypeLoc TL)4332 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
4333 LValueReferenceTypeLoc TL) {
4334 return TransformReferenceType(TLB, TL);
4335 }
4336
4337 template<typename Derived>
4338 QualType
TransformRValueReferenceType(TypeLocBuilder & TLB,RValueReferenceTypeLoc TL)4339 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4340 RValueReferenceTypeLoc TL) {
4341 return TransformReferenceType(TLB, TL);
4342 }
4343
4344 template<typename Derived>
4345 QualType
TransformMemberPointerType(TypeLocBuilder & TLB,MemberPointerTypeLoc TL)4346 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4347 MemberPointerTypeLoc TL) {
4348 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4349 if (PointeeType.isNull())
4350 return QualType();
4351
4352 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4353 TypeSourceInfo *NewClsTInfo = nullptr;
4354 if (OldClsTInfo) {
4355 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4356 if (!NewClsTInfo)
4357 return QualType();
4358 }
4359
4360 const MemberPointerType *T = TL.getTypePtr();
4361 QualType OldClsType = QualType(T->getClass(), 0);
4362 QualType NewClsType;
4363 if (NewClsTInfo)
4364 NewClsType = NewClsTInfo->getType();
4365 else {
4366 NewClsType = getDerived().TransformType(OldClsType);
4367 if (NewClsType.isNull())
4368 return QualType();
4369 }
4370
4371 QualType Result = TL.getType();
4372 if (getDerived().AlwaysRebuild() ||
4373 PointeeType != T->getPointeeType() ||
4374 NewClsType != OldClsType) {
4375 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4376 TL.getStarLoc());
4377 if (Result.isNull())
4378 return QualType();
4379 }
4380
4381 // If we had to adjust the pointee type when building a member pointer, make
4382 // sure to push TypeLoc info for it.
4383 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4384 if (MPT && PointeeType != MPT->getPointeeType()) {
4385 assert(isa<AdjustedType>(MPT->getPointeeType()));
4386 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4387 }
4388
4389 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4390 NewTL.setSigilLoc(TL.getSigilLoc());
4391 NewTL.setClassTInfo(NewClsTInfo);
4392
4393 return Result;
4394 }
4395
4396 template<typename Derived>
4397 QualType
TransformConstantArrayType(TypeLocBuilder & TLB,ConstantArrayTypeLoc TL)4398 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4399 ConstantArrayTypeLoc TL) {
4400 const ConstantArrayType *T = TL.getTypePtr();
4401 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4402 if (ElementType.isNull())
4403 return QualType();
4404
4405 QualType Result = TL.getType();
4406 if (getDerived().AlwaysRebuild() ||
4407 ElementType != T->getElementType()) {
4408 Result = getDerived().RebuildConstantArrayType(ElementType,
4409 T->getSizeModifier(),
4410 T->getSize(),
4411 T->getIndexTypeCVRQualifiers(),
4412 TL.getBracketsRange());
4413 if (Result.isNull())
4414 return QualType();
4415 }
4416
4417 // We might have either a ConstantArrayType or a VariableArrayType now:
4418 // a ConstantArrayType is allowed to have an element type which is a
4419 // VariableArrayType if the type is dependent. Fortunately, all array
4420 // types have the same location layout.
4421 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4422 NewTL.setLBracketLoc(TL.getLBracketLoc());
4423 NewTL.setRBracketLoc(TL.getRBracketLoc());
4424
4425 Expr *Size = TL.getSizeExpr();
4426 if (Size) {
4427 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4428 Sema::ConstantEvaluated);
4429 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4430 Size = SemaRef.ActOnConstantExpression(Size).get();
4431 }
4432 NewTL.setSizeExpr(Size);
4433
4434 return Result;
4435 }
4436
4437 template<typename Derived>
TransformIncompleteArrayType(TypeLocBuilder & TLB,IncompleteArrayTypeLoc TL)4438 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4439 TypeLocBuilder &TLB,
4440 IncompleteArrayTypeLoc TL) {
4441 const IncompleteArrayType *T = TL.getTypePtr();
4442 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4443 if (ElementType.isNull())
4444 return QualType();
4445
4446 QualType Result = TL.getType();
4447 if (getDerived().AlwaysRebuild() ||
4448 ElementType != T->getElementType()) {
4449 Result = getDerived().RebuildIncompleteArrayType(ElementType,
4450 T->getSizeModifier(),
4451 T->getIndexTypeCVRQualifiers(),
4452 TL.getBracketsRange());
4453 if (Result.isNull())
4454 return QualType();
4455 }
4456
4457 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4458 NewTL.setLBracketLoc(TL.getLBracketLoc());
4459 NewTL.setRBracketLoc(TL.getRBracketLoc());
4460 NewTL.setSizeExpr(nullptr);
4461
4462 return Result;
4463 }
4464
4465 template<typename Derived>
4466 QualType
TransformVariableArrayType(TypeLocBuilder & TLB,VariableArrayTypeLoc TL)4467 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4468 VariableArrayTypeLoc TL) {
4469 const VariableArrayType *T = TL.getTypePtr();
4470 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4471 if (ElementType.isNull())
4472 return QualType();
4473
4474 ExprResult SizeResult
4475 = getDerived().TransformExpr(T->getSizeExpr());
4476 if (SizeResult.isInvalid())
4477 return QualType();
4478
4479 Expr *Size = SizeResult.get();
4480
4481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 ElementType != T->getElementType() ||
4484 Size != T->getSizeExpr()) {
4485 Result = getDerived().RebuildVariableArrayType(ElementType,
4486 T->getSizeModifier(),
4487 Size,
4488 T->getIndexTypeCVRQualifiers(),
4489 TL.getBracketsRange());
4490 if (Result.isNull())
4491 return QualType();
4492 }
4493
4494 // We might have constant size array now, but fortunately it has the same
4495 // location layout.
4496 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4497 NewTL.setLBracketLoc(TL.getLBracketLoc());
4498 NewTL.setRBracketLoc(TL.getRBracketLoc());
4499 NewTL.setSizeExpr(Size);
4500
4501 return Result;
4502 }
4503
4504 template<typename Derived>
4505 QualType
TransformDependentSizedArrayType(TypeLocBuilder & TLB,DependentSizedArrayTypeLoc TL)4506 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4507 DependentSizedArrayTypeLoc TL) {
4508 const DependentSizedArrayType *T = TL.getTypePtr();
4509 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4510 if (ElementType.isNull())
4511 return QualType();
4512
4513 // Array bounds are constant expressions.
4514 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4515 Sema::ConstantEvaluated);
4516
4517 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4518 Expr *origSize = TL.getSizeExpr();
4519 if (!origSize) origSize = T->getSizeExpr();
4520
4521 ExprResult sizeResult
4522 = getDerived().TransformExpr(origSize);
4523 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4524 if (sizeResult.isInvalid())
4525 return QualType();
4526
4527 Expr *size = sizeResult.get();
4528
4529 QualType Result = TL.getType();
4530 if (getDerived().AlwaysRebuild() ||
4531 ElementType != T->getElementType() ||
4532 size != origSize) {
4533 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4534 T->getSizeModifier(),
4535 size,
4536 T->getIndexTypeCVRQualifiers(),
4537 TL.getBracketsRange());
4538 if (Result.isNull())
4539 return QualType();
4540 }
4541
4542 // We might have any sort of array type now, but fortunately they
4543 // all have the same location layout.
4544 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4545 NewTL.setLBracketLoc(TL.getLBracketLoc());
4546 NewTL.setRBracketLoc(TL.getRBracketLoc());
4547 NewTL.setSizeExpr(size);
4548
4549 return Result;
4550 }
4551
4552 template<typename Derived>
TransformDependentSizedExtVectorType(TypeLocBuilder & TLB,DependentSizedExtVectorTypeLoc TL)4553 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4554 TypeLocBuilder &TLB,
4555 DependentSizedExtVectorTypeLoc TL) {
4556 const DependentSizedExtVectorType *T = TL.getTypePtr();
4557
4558 // FIXME: ext vector locs should be nested
4559 QualType ElementType = getDerived().TransformType(T->getElementType());
4560 if (ElementType.isNull())
4561 return QualType();
4562
4563 // Vector sizes are constant expressions.
4564 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4565 Sema::ConstantEvaluated);
4566
4567 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4568 Size = SemaRef.ActOnConstantExpression(Size);
4569 if (Size.isInvalid())
4570 return QualType();
4571
4572 QualType Result = TL.getType();
4573 if (getDerived().AlwaysRebuild() ||
4574 ElementType != T->getElementType() ||
4575 Size.get() != T->getSizeExpr()) {
4576 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4577 Size.get(),
4578 T->getAttributeLoc());
4579 if (Result.isNull())
4580 return QualType();
4581 }
4582
4583 // Result might be dependent or not.
4584 if (isa<DependentSizedExtVectorType>(Result)) {
4585 DependentSizedExtVectorTypeLoc NewTL
4586 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4587 NewTL.setNameLoc(TL.getNameLoc());
4588 } else {
4589 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4590 NewTL.setNameLoc(TL.getNameLoc());
4591 }
4592
4593 return Result;
4594 }
4595
4596 template<typename Derived>
TransformVectorType(TypeLocBuilder & TLB,VectorTypeLoc TL)4597 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4598 VectorTypeLoc TL) {
4599 const VectorType *T = TL.getTypePtr();
4600 QualType ElementType = getDerived().TransformType(T->getElementType());
4601 if (ElementType.isNull())
4602 return QualType();
4603
4604 QualType Result = TL.getType();
4605 if (getDerived().AlwaysRebuild() ||
4606 ElementType != T->getElementType()) {
4607 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4608 T->getVectorKind());
4609 if (Result.isNull())
4610 return QualType();
4611 }
4612
4613 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4614 NewTL.setNameLoc(TL.getNameLoc());
4615
4616 return Result;
4617 }
4618
4619 template<typename Derived>
TransformExtVectorType(TypeLocBuilder & TLB,ExtVectorTypeLoc TL)4620 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4621 ExtVectorTypeLoc TL) {
4622 const VectorType *T = TL.getTypePtr();
4623 QualType ElementType = getDerived().TransformType(T->getElementType());
4624 if (ElementType.isNull())
4625 return QualType();
4626
4627 QualType Result = TL.getType();
4628 if (getDerived().AlwaysRebuild() ||
4629 ElementType != T->getElementType()) {
4630 Result = getDerived().RebuildExtVectorType(ElementType,
4631 T->getNumElements(),
4632 /*FIXME*/ SourceLocation());
4633 if (Result.isNull())
4634 return QualType();
4635 }
4636
4637 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4638 NewTL.setNameLoc(TL.getNameLoc());
4639
4640 return Result;
4641 }
4642
4643 template <typename Derived>
TransformFunctionTypeParam(ParmVarDecl * OldParm,int indexAdjustment,Optional<unsigned> NumExpansions,bool ExpectParameterPack)4644 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4645 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4646 bool ExpectParameterPack) {
4647 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4648 TypeSourceInfo *NewDI = nullptr;
4649
4650 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4651 // If we're substituting into a pack expansion type and we know the
4652 // length we want to expand to, just substitute for the pattern.
4653 TypeLoc OldTL = OldDI->getTypeLoc();
4654 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4655
4656 TypeLocBuilder TLB;
4657 TypeLoc NewTL = OldDI->getTypeLoc();
4658 TLB.reserve(NewTL.getFullDataSize());
4659
4660 QualType Result = getDerived().TransformType(TLB,
4661 OldExpansionTL.getPatternLoc());
4662 if (Result.isNull())
4663 return nullptr;
4664
4665 Result = RebuildPackExpansionType(Result,
4666 OldExpansionTL.getPatternLoc().getSourceRange(),
4667 OldExpansionTL.getEllipsisLoc(),
4668 NumExpansions);
4669 if (Result.isNull())
4670 return nullptr;
4671
4672 PackExpansionTypeLoc NewExpansionTL
4673 = TLB.push<PackExpansionTypeLoc>(Result);
4674 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4675 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4676 } else
4677 NewDI = getDerived().TransformType(OldDI);
4678 if (!NewDI)
4679 return nullptr;
4680
4681 if (NewDI == OldDI && indexAdjustment == 0)
4682 return OldParm;
4683
4684 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4685 OldParm->getDeclContext(),
4686 OldParm->getInnerLocStart(),
4687 OldParm->getLocation(),
4688 OldParm->getIdentifier(),
4689 NewDI->getType(),
4690 NewDI,
4691 OldParm->getStorageClass(),
4692 /* DefArg */ nullptr);
4693 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4694 OldParm->getFunctionScopeIndex() + indexAdjustment);
4695 return newParm;
4696 }
4697
4698 template <typename Derived>
TransformFunctionTypeParams(SourceLocation Loc,ArrayRef<ParmVarDecl * > Params,const QualType * ParamTypes,const FunctionProtoType::ExtParameterInfo * ParamInfos,SmallVectorImpl<QualType> & OutParamTypes,SmallVectorImpl<ParmVarDecl * > * PVars,Sema::ExtParameterInfoBuilder & PInfos)4699 bool TreeTransform<Derived>::TransformFunctionTypeParams(
4700 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4701 const QualType *ParamTypes,
4702 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4703 SmallVectorImpl<QualType> &OutParamTypes,
4704 SmallVectorImpl<ParmVarDecl *> *PVars,
4705 Sema::ExtParameterInfoBuilder &PInfos) {
4706 int indexAdjustment = 0;
4707
4708 unsigned NumParams = Params.size();
4709 for (unsigned i = 0; i != NumParams; ++i) {
4710 if (ParmVarDecl *OldParm = Params[i]) {
4711 assert(OldParm->getFunctionScopeIndex() == i);
4712
4713 Optional<unsigned> NumExpansions;
4714 ParmVarDecl *NewParm = nullptr;
4715 if (OldParm->isParameterPack()) {
4716 // We have a function parameter pack that may need to be expanded.
4717 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4718
4719 // Find the parameter packs that could be expanded.
4720 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4721 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4722 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4723 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4724 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4725
4726 // Determine whether we should expand the parameter packs.
4727 bool ShouldExpand = false;
4728 bool RetainExpansion = false;
4729 Optional<unsigned> OrigNumExpansions =
4730 ExpansionTL.getTypePtr()->getNumExpansions();
4731 NumExpansions = OrigNumExpansions;
4732 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4733 Pattern.getSourceRange(),
4734 Unexpanded,
4735 ShouldExpand,
4736 RetainExpansion,
4737 NumExpansions)) {
4738 return true;
4739 }
4740
4741 if (ShouldExpand) {
4742 // Expand the function parameter pack into multiple, separate
4743 // parameters.
4744 getDerived().ExpandingFunctionParameterPack(OldParm);
4745 for (unsigned I = 0; I != *NumExpansions; ++I) {
4746 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4747 ParmVarDecl *NewParm
4748 = getDerived().TransformFunctionTypeParam(OldParm,
4749 indexAdjustment++,
4750 OrigNumExpansions,
4751 /*ExpectParameterPack=*/false);
4752 if (!NewParm)
4753 return true;
4754
4755 if (ParamInfos)
4756 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4757 OutParamTypes.push_back(NewParm->getType());
4758 if (PVars)
4759 PVars->push_back(NewParm);
4760 }
4761
4762 // If we're supposed to retain a pack expansion, do so by temporarily
4763 // forgetting the partially-substituted parameter pack.
4764 if (RetainExpansion) {
4765 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4766 ParmVarDecl *NewParm
4767 = getDerived().TransformFunctionTypeParam(OldParm,
4768 indexAdjustment++,
4769 OrigNumExpansions,
4770 /*ExpectParameterPack=*/false);
4771 if (!NewParm)
4772 return true;
4773
4774 if (ParamInfos)
4775 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4776 OutParamTypes.push_back(NewParm->getType());
4777 if (PVars)
4778 PVars->push_back(NewParm);
4779 }
4780
4781 // The next parameter should have the same adjustment as the
4782 // last thing we pushed, but we post-incremented indexAdjustment
4783 // on every push. Also, if we push nothing, the adjustment should
4784 // go down by one.
4785 indexAdjustment--;
4786
4787 // We're done with the pack expansion.
4788 continue;
4789 }
4790
4791 // We'll substitute the parameter now without expanding the pack
4792 // expansion.
4793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4794 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4795 indexAdjustment,
4796 NumExpansions,
4797 /*ExpectParameterPack=*/true);
4798 } else {
4799 NewParm = getDerived().TransformFunctionTypeParam(
4800 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4801 }
4802
4803 if (!NewParm)
4804 return true;
4805
4806 if (ParamInfos)
4807 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4808 OutParamTypes.push_back(NewParm->getType());
4809 if (PVars)
4810 PVars->push_back(NewParm);
4811 continue;
4812 }
4813
4814 // Deal with the possibility that we don't have a parameter
4815 // declaration for this parameter.
4816 QualType OldType = ParamTypes[i];
4817 bool IsPackExpansion = false;
4818 Optional<unsigned> NumExpansions;
4819 QualType NewType;
4820 if (const PackExpansionType *Expansion
4821 = dyn_cast<PackExpansionType>(OldType)) {
4822 // We have a function parameter pack that may need to be expanded.
4823 QualType Pattern = Expansion->getPattern();
4824 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4825 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4826
4827 // Determine whether we should expand the parameter packs.
4828 bool ShouldExpand = false;
4829 bool RetainExpansion = false;
4830 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4831 Unexpanded,
4832 ShouldExpand,
4833 RetainExpansion,
4834 NumExpansions)) {
4835 return true;
4836 }
4837
4838 if (ShouldExpand) {
4839 // Expand the function parameter pack into multiple, separate
4840 // parameters.
4841 for (unsigned I = 0; I != *NumExpansions; ++I) {
4842 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4843 QualType NewType = getDerived().TransformType(Pattern);
4844 if (NewType.isNull())
4845 return true;
4846
4847 if (NewType->containsUnexpandedParameterPack()) {
4848 NewType =
4849 getSema().getASTContext().getPackExpansionType(NewType, None);
4850
4851 if (NewType.isNull())
4852 return true;
4853 }
4854
4855 if (ParamInfos)
4856 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4857 OutParamTypes.push_back(NewType);
4858 if (PVars)
4859 PVars->push_back(nullptr);
4860 }
4861
4862 // We're done with the pack expansion.
4863 continue;
4864 }
4865
4866 // If we're supposed to retain a pack expansion, do so by temporarily
4867 // forgetting the partially-substituted parameter pack.
4868 if (RetainExpansion) {
4869 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4870 QualType NewType = getDerived().TransformType(Pattern);
4871 if (NewType.isNull())
4872 return true;
4873
4874 if (ParamInfos)
4875 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4876 OutParamTypes.push_back(NewType);
4877 if (PVars)
4878 PVars->push_back(nullptr);
4879 }
4880
4881 // We'll substitute the parameter now without expanding the pack
4882 // expansion.
4883 OldType = Expansion->getPattern();
4884 IsPackExpansion = true;
4885 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4886 NewType = getDerived().TransformType(OldType);
4887 } else {
4888 NewType = getDerived().TransformType(OldType);
4889 }
4890
4891 if (NewType.isNull())
4892 return true;
4893
4894 if (IsPackExpansion)
4895 NewType = getSema().Context.getPackExpansionType(NewType,
4896 NumExpansions);
4897
4898 if (ParamInfos)
4899 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4900 OutParamTypes.push_back(NewType);
4901 if (PVars)
4902 PVars->push_back(nullptr);
4903 }
4904
4905 #ifndef NDEBUG
4906 if (PVars) {
4907 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4908 if (ParmVarDecl *parm = (*PVars)[i])
4909 assert(parm->getFunctionScopeIndex() == i);
4910 }
4911 #endif
4912
4913 return false;
4914 }
4915
4916 template<typename Derived>
4917 QualType
TransformFunctionProtoType(TypeLocBuilder & TLB,FunctionProtoTypeLoc TL)4918 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4919 FunctionProtoTypeLoc TL) {
4920 SmallVector<QualType, 4> ExceptionStorage;
4921 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
4922 return getDerived().TransformFunctionProtoType(
4923 TLB, TL, nullptr, 0,
4924 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4925 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4926 ExceptionStorage, Changed);
4927 });
4928 }
4929
4930 template<typename Derived> template<typename Fn>
TransformFunctionProtoType(TypeLocBuilder & TLB,FunctionProtoTypeLoc TL,CXXRecordDecl * ThisContext,unsigned ThisTypeQuals,Fn TransformExceptionSpec)4931 QualType TreeTransform<Derived>::TransformFunctionProtoType(
4932 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4933 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
4934
4935 // Transform the parameters and return type.
4936 //
4937 // We are required to instantiate the params and return type in source order.
4938 // When the function has a trailing return type, we instantiate the
4939 // parameters before the return type, since the return type can then refer
4940 // to the parameters themselves (via decltype, sizeof, etc.).
4941 //
4942 SmallVector<QualType, 4> ParamTypes;
4943 SmallVector<ParmVarDecl*, 4> ParamDecls;
4944 Sema::ExtParameterInfoBuilder ExtParamInfos;
4945 const FunctionProtoType *T = TL.getTypePtr();
4946
4947 QualType ResultType;
4948
4949 if (T->hasTrailingReturn()) {
4950 if (getDerived().TransformFunctionTypeParams(
4951 TL.getBeginLoc(), TL.getParams(),
4952 TL.getTypePtr()->param_type_begin(),
4953 T->getExtParameterInfosOrNull(),
4954 ParamTypes, &ParamDecls, ExtParamInfos))
4955 return QualType();
4956
4957 {
4958 // C++11 [expr.prim.general]p3:
4959 // If a declaration declares a member function or member function
4960 // template of a class X, the expression this is a prvalue of type
4961 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4962 // and the end of the function-definition, member-declarator, or
4963 // declarator.
4964 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4965
4966 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4967 if (ResultType.isNull())
4968 return QualType();
4969 }
4970 }
4971 else {
4972 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4973 if (ResultType.isNull())
4974 return QualType();
4975
4976 if (getDerived().TransformFunctionTypeParams(
4977 TL.getBeginLoc(), TL.getParams(),
4978 TL.getTypePtr()->param_type_begin(),
4979 T->getExtParameterInfosOrNull(),
4980 ParamTypes, &ParamDecls, ExtParamInfos))
4981 return QualType();
4982 }
4983
4984 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4985
4986 bool EPIChanged = false;
4987 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4988 return QualType();
4989
4990 // Handle extended parameter information.
4991 if (auto NewExtParamInfos =
4992 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4993 if (!EPI.ExtParameterInfos ||
4994 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4995 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4996 EPIChanged = true;
4997 }
4998 EPI.ExtParameterInfos = NewExtParamInfos;
4999 } else if (EPI.ExtParameterInfos) {
5000 EPIChanged = true;
5001 EPI.ExtParameterInfos = nullptr;
5002 }
5003
5004 QualType Result = TL.getType();
5005 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5006 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5007 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5008 if (Result.isNull())
5009 return QualType();
5010 }
5011
5012 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5013 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5014 NewTL.setLParenLoc(TL.getLParenLoc());
5015 NewTL.setRParenLoc(TL.getRParenLoc());
5016 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5017 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5018 NewTL.setParam(i, ParamDecls[i]);
5019
5020 return Result;
5021 }
5022
5023 template<typename Derived>
TransformExceptionSpec(SourceLocation Loc,FunctionProtoType::ExceptionSpecInfo & ESI,SmallVectorImpl<QualType> & Exceptions,bool & Changed)5024 bool TreeTransform<Derived>::TransformExceptionSpec(
5025 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5026 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5027 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5028
5029 // Instantiate a dynamic noexcept expression, if any.
5030 if (ESI.Type == EST_ComputedNoexcept) {
5031 EnterExpressionEvaluationContext Unevaluated(getSema(),
5032 Sema::ConstantEvaluated);
5033 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5034 if (NoexceptExpr.isInvalid())
5035 return true;
5036
5037 // FIXME: This is bogus, a noexcept expression is not a condition.
5038 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5039 if (NoexceptExpr.isInvalid())
5040 return true;
5041
5042 if (!NoexceptExpr.get()->isValueDependent()) {
5043 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5044 NoexceptExpr.get(), nullptr,
5045 diag::err_noexcept_needs_constant_expression,
5046 /*AllowFold*/false);
5047 if (NoexceptExpr.isInvalid())
5048 return true;
5049 }
5050
5051 if (ESI.NoexceptExpr != NoexceptExpr.get())
5052 Changed = true;
5053 ESI.NoexceptExpr = NoexceptExpr.get();
5054 }
5055
5056 if (ESI.Type != EST_Dynamic)
5057 return false;
5058
5059 // Instantiate a dynamic exception specification's type.
5060 for (QualType T : ESI.Exceptions) {
5061 if (const PackExpansionType *PackExpansion =
5062 T->getAs<PackExpansionType>()) {
5063 Changed = true;
5064
5065 // We have a pack expansion. Instantiate it.
5066 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5067 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5068 Unexpanded);
5069 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5070
5071 // Determine whether the set of unexpanded parameter packs can and
5072 // should
5073 // be expanded.
5074 bool Expand = false;
5075 bool RetainExpansion = false;
5076 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5077 // FIXME: Track the location of the ellipsis (and track source location
5078 // information for the types in the exception specification in general).
5079 if (getDerived().TryExpandParameterPacks(
5080 Loc, SourceRange(), Unexpanded, Expand,
5081 RetainExpansion, NumExpansions))
5082 return true;
5083
5084 if (!Expand) {
5085 // We can't expand this pack expansion into separate arguments yet;
5086 // just substitute into the pattern and create a new pack expansion
5087 // type.
5088 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5089 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5090 if (U.isNull())
5091 return true;
5092
5093 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5094 Exceptions.push_back(U);
5095 continue;
5096 }
5097
5098 // Substitute into the pack expansion pattern for each slice of the
5099 // pack.
5100 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5101 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5102
5103 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5104 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5105 return true;
5106
5107 Exceptions.push_back(U);
5108 }
5109 } else {
5110 QualType U = getDerived().TransformType(T);
5111 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5112 return true;
5113 if (T != U)
5114 Changed = true;
5115
5116 Exceptions.push_back(U);
5117 }
5118 }
5119
5120 ESI.Exceptions = Exceptions;
5121 return false;
5122 }
5123
5124 template<typename Derived>
TransformFunctionNoProtoType(TypeLocBuilder & TLB,FunctionNoProtoTypeLoc TL)5125 QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
5126 TypeLocBuilder &TLB,
5127 FunctionNoProtoTypeLoc TL) {
5128 const FunctionNoProtoType *T = TL.getTypePtr();
5129 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5130 if (ResultType.isNull())
5131 return QualType();
5132
5133 QualType Result = TL.getType();
5134 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5135 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5136
5137 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5138 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
5139 NewTL.setLParenLoc(TL.getLParenLoc());
5140 NewTL.setRParenLoc(TL.getRParenLoc());
5141 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5142
5143 return Result;
5144 }
5145
5146 template<typename Derived> QualType
TransformUnresolvedUsingType(TypeLocBuilder & TLB,UnresolvedUsingTypeLoc TL)5147 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5148 UnresolvedUsingTypeLoc TL) {
5149 const UnresolvedUsingType *T = TL.getTypePtr();
5150 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5151 if (!D)
5152 return QualType();
5153
5154 QualType Result = TL.getType();
5155 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5156 Result = getDerived().RebuildUnresolvedUsingType(D);
5157 if (Result.isNull())
5158 return QualType();
5159 }
5160
5161 // We might get an arbitrary type spec type back. We should at
5162 // least always get a type spec type, though.
5163 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5164 NewTL.setNameLoc(TL.getNameLoc());
5165
5166 return Result;
5167 }
5168
5169 template<typename Derived>
TransformTypedefType(TypeLocBuilder & TLB,TypedefTypeLoc TL)5170 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5171 TypedefTypeLoc TL) {
5172 const TypedefType *T = TL.getTypePtr();
5173 TypedefNameDecl *Typedef
5174 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5175 T->getDecl()));
5176 if (!Typedef)
5177 return QualType();
5178
5179 QualType Result = TL.getType();
5180 if (getDerived().AlwaysRebuild() ||
5181 Typedef != T->getDecl()) {
5182 Result = getDerived().RebuildTypedefType(Typedef);
5183 if (Result.isNull())
5184 return QualType();
5185 }
5186
5187 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5188 NewTL.setNameLoc(TL.getNameLoc());
5189
5190 return Result;
5191 }
5192
5193 template<typename Derived>
TransformTypeOfExprType(TypeLocBuilder & TLB,TypeOfExprTypeLoc TL)5194 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5195 TypeOfExprTypeLoc TL) {
5196 // typeof expressions are not potentially evaluated contexts
5197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5198 Sema::ReuseLambdaContextDecl);
5199
5200 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5201 if (E.isInvalid())
5202 return QualType();
5203
5204 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5205 if (E.isInvalid())
5206 return QualType();
5207
5208 QualType Result = TL.getType();
5209 if (getDerived().AlwaysRebuild() ||
5210 E.get() != TL.getUnderlyingExpr()) {
5211 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5212 if (Result.isNull())
5213 return QualType();
5214 }
5215 else E.get();
5216
5217 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5218 NewTL.setTypeofLoc(TL.getTypeofLoc());
5219 NewTL.setLParenLoc(TL.getLParenLoc());
5220 NewTL.setRParenLoc(TL.getRParenLoc());
5221
5222 return Result;
5223 }
5224
5225 template<typename Derived>
TransformTypeOfType(TypeLocBuilder & TLB,TypeOfTypeLoc TL)5226 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5227 TypeOfTypeLoc TL) {
5228 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5229 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5230 if (!New_Under_TI)
5231 return QualType();
5232
5233 QualType Result = TL.getType();
5234 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5235 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5236 if (Result.isNull())
5237 return QualType();
5238 }
5239
5240 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5241 NewTL.setTypeofLoc(TL.getTypeofLoc());
5242 NewTL.setLParenLoc(TL.getLParenLoc());
5243 NewTL.setRParenLoc(TL.getRParenLoc());
5244 NewTL.setUnderlyingTInfo(New_Under_TI);
5245
5246 return Result;
5247 }
5248
5249 template<typename Derived>
TransformDecltypeType(TypeLocBuilder & TLB,DecltypeTypeLoc TL)5250 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5251 DecltypeTypeLoc TL) {
5252 const DecltypeType *T = TL.getTypePtr();
5253
5254 // decltype expressions are not potentially evaluated contexts
5255 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5256 nullptr, /*IsDecltype=*/ true);
5257
5258 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5259 if (E.isInvalid())
5260 return QualType();
5261
5262 E = getSema().ActOnDecltypeExpression(E.get());
5263 if (E.isInvalid())
5264 return QualType();
5265
5266 QualType Result = TL.getType();
5267 if (getDerived().AlwaysRebuild() ||
5268 E.get() != T->getUnderlyingExpr()) {
5269 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5270 if (Result.isNull())
5271 return QualType();
5272 }
5273 else E.get();
5274
5275 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5276 NewTL.setNameLoc(TL.getNameLoc());
5277
5278 return Result;
5279 }
5280
5281 template<typename Derived>
TransformUnaryTransformType(TypeLocBuilder & TLB,UnaryTransformTypeLoc TL)5282 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5283 TypeLocBuilder &TLB,
5284 UnaryTransformTypeLoc TL) {
5285 QualType Result = TL.getType();
5286 if (Result->isDependentType()) {
5287 const UnaryTransformType *T = TL.getTypePtr();
5288 QualType NewBase =
5289 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5290 Result = getDerived().RebuildUnaryTransformType(NewBase,
5291 T->getUTTKind(),
5292 TL.getKWLoc());
5293 if (Result.isNull())
5294 return QualType();
5295 }
5296
5297 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5298 NewTL.setKWLoc(TL.getKWLoc());
5299 NewTL.setParensRange(TL.getParensRange());
5300 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5301 return Result;
5302 }
5303
5304 template<typename Derived>
TransformAutoType(TypeLocBuilder & TLB,AutoTypeLoc TL)5305 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5306 AutoTypeLoc TL) {
5307 const AutoType *T = TL.getTypePtr();
5308 QualType OldDeduced = T->getDeducedType();
5309 QualType NewDeduced;
5310 if (!OldDeduced.isNull()) {
5311 NewDeduced = getDerived().TransformType(OldDeduced);
5312 if (NewDeduced.isNull())
5313 return QualType();
5314 }
5315
5316 QualType Result = TL.getType();
5317 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5318 T->isDependentType()) {
5319 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5320 if (Result.isNull())
5321 return QualType();
5322 }
5323
5324 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5325 NewTL.setNameLoc(TL.getNameLoc());
5326
5327 return Result;
5328 }
5329
5330 template<typename Derived>
TransformRecordType(TypeLocBuilder & TLB,RecordTypeLoc TL)5331 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5332 RecordTypeLoc TL) {
5333 const RecordType *T = TL.getTypePtr();
5334 RecordDecl *Record
5335 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5336 T->getDecl()));
5337 if (!Record)
5338 return QualType();
5339
5340 QualType Result = TL.getType();
5341 if (getDerived().AlwaysRebuild() ||
5342 Record != T->getDecl()) {
5343 Result = getDerived().RebuildRecordType(Record);
5344 if (Result.isNull())
5345 return QualType();
5346 }
5347
5348 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5349 NewTL.setNameLoc(TL.getNameLoc());
5350
5351 return Result;
5352 }
5353
5354 template<typename Derived>
TransformEnumType(TypeLocBuilder & TLB,EnumTypeLoc TL)5355 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5356 EnumTypeLoc TL) {
5357 const EnumType *T = TL.getTypePtr();
5358 EnumDecl *Enum
5359 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5360 T->getDecl()));
5361 if (!Enum)
5362 return QualType();
5363
5364 QualType Result = TL.getType();
5365 if (getDerived().AlwaysRebuild() ||
5366 Enum != T->getDecl()) {
5367 Result = getDerived().RebuildEnumType(Enum);
5368 if (Result.isNull())
5369 return QualType();
5370 }
5371
5372 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5373 NewTL.setNameLoc(TL.getNameLoc());
5374
5375 return Result;
5376 }
5377
5378 template<typename Derived>
TransformInjectedClassNameType(TypeLocBuilder & TLB,InjectedClassNameTypeLoc TL)5379 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5380 TypeLocBuilder &TLB,
5381 InjectedClassNameTypeLoc TL) {
5382 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5383 TL.getTypePtr()->getDecl());
5384 if (!D) return QualType();
5385
5386 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5387 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5388 return T;
5389 }
5390
5391 template<typename Derived>
TransformTemplateTypeParmType(TypeLocBuilder & TLB,TemplateTypeParmTypeLoc TL)5392 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5393 TypeLocBuilder &TLB,
5394 TemplateTypeParmTypeLoc TL) {
5395 return TransformTypeSpecType(TLB, TL);
5396 }
5397
5398 template<typename Derived>
TransformSubstTemplateTypeParmType(TypeLocBuilder & TLB,SubstTemplateTypeParmTypeLoc TL)5399 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5400 TypeLocBuilder &TLB,
5401 SubstTemplateTypeParmTypeLoc TL) {
5402 const SubstTemplateTypeParmType *T = TL.getTypePtr();
5403
5404 // Substitute into the replacement type, which itself might involve something
5405 // that needs to be transformed. This only tends to occur with default
5406 // template arguments of template template parameters.
5407 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5408 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5409 if (Replacement.isNull())
5410 return QualType();
5411
5412 // Always canonicalize the replacement type.
5413 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5414 QualType Result
5415 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5416 Replacement);
5417
5418 // Propagate type-source information.
5419 SubstTemplateTypeParmTypeLoc NewTL
5420 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5421 NewTL.setNameLoc(TL.getNameLoc());
5422 return Result;
5423
5424 }
5425
5426 template<typename Derived>
TransformSubstTemplateTypeParmPackType(TypeLocBuilder & TLB,SubstTemplateTypeParmPackTypeLoc TL)5427 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5428 TypeLocBuilder &TLB,
5429 SubstTemplateTypeParmPackTypeLoc TL) {
5430 return TransformTypeSpecType(TLB, TL);
5431 }
5432
5433 template<typename Derived>
TransformTemplateSpecializationType(TypeLocBuilder & TLB,TemplateSpecializationTypeLoc TL)5434 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5435 TypeLocBuilder &TLB,
5436 TemplateSpecializationTypeLoc TL) {
5437 const TemplateSpecializationType *T = TL.getTypePtr();
5438
5439 // The nested-name-specifier never matters in a TemplateSpecializationType,
5440 // because we can't have a dependent nested-name-specifier anyway.
5441 CXXScopeSpec SS;
5442 TemplateName Template
5443 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5444 TL.getTemplateNameLoc());
5445 if (Template.isNull())
5446 return QualType();
5447
5448 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5449 }
5450
5451 template<typename Derived>
TransformAtomicType(TypeLocBuilder & TLB,AtomicTypeLoc TL)5452 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5453 AtomicTypeLoc TL) {
5454 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5455 if (ValueType.isNull())
5456 return QualType();
5457
5458 QualType Result = TL.getType();
5459 if (getDerived().AlwaysRebuild() ||
5460 ValueType != TL.getValueLoc().getType()) {
5461 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5462 if (Result.isNull())
5463 return QualType();
5464 }
5465
5466 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5467 NewTL.setKWLoc(TL.getKWLoc());
5468 NewTL.setLParenLoc(TL.getLParenLoc());
5469 NewTL.setRParenLoc(TL.getRParenLoc());
5470
5471 return Result;
5472 }
5473
5474 template <typename Derived>
TransformPipeType(TypeLocBuilder & TLB,PipeTypeLoc TL)5475 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5476 PipeTypeLoc TL) {
5477 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5478 if (ValueType.isNull())
5479 return QualType();
5480
5481 QualType Result = TL.getType();
5482 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5483 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5484 if (Result.isNull())
5485 return QualType();
5486 }
5487
5488 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5489 NewTL.setKWLoc(TL.getKWLoc());
5490
5491 return Result;
5492 }
5493
5494 /// \brief Simple iterator that traverses the template arguments in a
5495 /// container that provides a \c getArgLoc() member function.
5496 ///
5497 /// This iterator is intended to be used with the iterator form of
5498 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5499 template<typename ArgLocContainer>
5500 class TemplateArgumentLocContainerIterator {
5501 ArgLocContainer *Container;
5502 unsigned Index;
5503
5504 public:
5505 typedef TemplateArgumentLoc value_type;
5506 typedef TemplateArgumentLoc reference;
5507 typedef int difference_type;
5508 typedef std::input_iterator_tag iterator_category;
5509
5510 class pointer {
5511 TemplateArgumentLoc Arg;
5512
5513 public:
pointer(TemplateArgumentLoc Arg)5514 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5515
5516 const TemplateArgumentLoc *operator->() const {
5517 return &Arg;
5518 }
5519 };
5520
5521
TemplateArgumentLocContainerIterator()5522 TemplateArgumentLocContainerIterator() {}
5523
TemplateArgumentLocContainerIterator(ArgLocContainer & Container,unsigned Index)5524 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5525 unsigned Index)
5526 : Container(&Container), Index(Index) { }
5527
5528 TemplateArgumentLocContainerIterator &operator++() {
5529 ++Index;
5530 return *this;
5531 }
5532
5533 TemplateArgumentLocContainerIterator operator++(int) {
5534 TemplateArgumentLocContainerIterator Old(*this);
5535 ++(*this);
5536 return Old;
5537 }
5538
5539 TemplateArgumentLoc operator*() const {
5540 return Container->getArgLoc(Index);
5541 }
5542
5543 pointer operator->() const {
5544 return pointer(Container->getArgLoc(Index));
5545 }
5546
5547 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
5548 const TemplateArgumentLocContainerIterator &Y) {
5549 return X.Container == Y.Container && X.Index == Y.Index;
5550 }
5551
5552 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
5553 const TemplateArgumentLocContainerIterator &Y) {
5554 return !(X == Y);
5555 }
5556 };
5557
5558
5559 template <typename Derived>
TransformTemplateSpecializationType(TypeLocBuilder & TLB,TemplateSpecializationTypeLoc TL,TemplateName Template)5560 QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5561 TypeLocBuilder &TLB,
5562 TemplateSpecializationTypeLoc TL,
5563 TemplateName Template) {
5564 TemplateArgumentListInfo NewTemplateArgs;
5565 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5566 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5567 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5568 ArgIterator;
5569 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5570 ArgIterator(TL, TL.getNumArgs()),
5571 NewTemplateArgs))
5572 return QualType();
5573
5574 // FIXME: maybe don't rebuild if all the template arguments are the same.
5575
5576 QualType Result =
5577 getDerived().RebuildTemplateSpecializationType(Template,
5578 TL.getTemplateNameLoc(),
5579 NewTemplateArgs);
5580
5581 if (!Result.isNull()) {
5582 // Specializations of template template parameters are represented as
5583 // TemplateSpecializationTypes, and substitution of type alias templates
5584 // within a dependent context can transform them into
5585 // DependentTemplateSpecializationTypes.
5586 if (isa<DependentTemplateSpecializationType>(Result)) {
5587 DependentTemplateSpecializationTypeLoc NewTL
5588 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5589 NewTL.setElaboratedKeywordLoc(SourceLocation());
5590 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5591 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5592 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5593 NewTL.setLAngleLoc(TL.getLAngleLoc());
5594 NewTL.setRAngleLoc(TL.getRAngleLoc());
5595 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5596 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5597 return Result;
5598 }
5599
5600 TemplateSpecializationTypeLoc NewTL
5601 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5602 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5603 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5604 NewTL.setLAngleLoc(TL.getLAngleLoc());
5605 NewTL.setRAngleLoc(TL.getRAngleLoc());
5606 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5607 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5608 }
5609
5610 return Result;
5611 }
5612
5613 template <typename Derived>
TransformDependentTemplateSpecializationType(TypeLocBuilder & TLB,DependentTemplateSpecializationTypeLoc TL,TemplateName Template,CXXScopeSpec & SS)5614 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5615 TypeLocBuilder &TLB,
5616 DependentTemplateSpecializationTypeLoc TL,
5617 TemplateName Template,
5618 CXXScopeSpec &SS) {
5619 TemplateArgumentListInfo NewTemplateArgs;
5620 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5621 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5622 typedef TemplateArgumentLocContainerIterator<
5623 DependentTemplateSpecializationTypeLoc> ArgIterator;
5624 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5625 ArgIterator(TL, TL.getNumArgs()),
5626 NewTemplateArgs))
5627 return QualType();
5628
5629 // FIXME: maybe don't rebuild if all the template arguments are the same.
5630
5631 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5632 QualType Result
5633 = getSema().Context.getDependentTemplateSpecializationType(
5634 TL.getTypePtr()->getKeyword(),
5635 DTN->getQualifier(),
5636 DTN->getIdentifier(),
5637 NewTemplateArgs);
5638
5639 DependentTemplateSpecializationTypeLoc NewTL
5640 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5641 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5642 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5643 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5644 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5645 NewTL.setLAngleLoc(TL.getLAngleLoc());
5646 NewTL.setRAngleLoc(TL.getRAngleLoc());
5647 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5648 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5649 return Result;
5650 }
5651
5652 QualType Result
5653 = getDerived().RebuildTemplateSpecializationType(Template,
5654 TL.getTemplateNameLoc(),
5655 NewTemplateArgs);
5656
5657 if (!Result.isNull()) {
5658 /// FIXME: Wrap this in an elaborated-type-specifier?
5659 TemplateSpecializationTypeLoc NewTL
5660 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5661 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5662 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5663 NewTL.setLAngleLoc(TL.getLAngleLoc());
5664 NewTL.setRAngleLoc(TL.getRAngleLoc());
5665 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5666 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5667 }
5668
5669 return Result;
5670 }
5671
5672 template<typename Derived>
5673 QualType
TransformElaboratedType(TypeLocBuilder & TLB,ElaboratedTypeLoc TL)5674 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
5675 ElaboratedTypeLoc TL) {
5676 const ElaboratedType *T = TL.getTypePtr();
5677
5678 NestedNameSpecifierLoc QualifierLoc;
5679 // NOTE: the qualifier in an ElaboratedType is optional.
5680 if (TL.getQualifierLoc()) {
5681 QualifierLoc
5682 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5683 if (!QualifierLoc)
5684 return QualType();
5685 }
5686
5687 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5688 if (NamedT.isNull())
5689 return QualType();
5690
5691 // C++0x [dcl.type.elab]p2:
5692 // If the identifier resolves to a typedef-name or the simple-template-id
5693 // resolves to an alias template specialization, the
5694 // elaborated-type-specifier is ill-formed.
5695 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5696 if (const TemplateSpecializationType *TST =
5697 NamedT->getAs<TemplateSpecializationType>()) {
5698 TemplateName Template = TST->getTemplateName();
5699 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5700 Template.getAsTemplateDecl())) {
5701 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5702 diag::err_tag_reference_non_tag) << 4;
5703 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5704 }
5705 }
5706 }
5707
5708 QualType Result = TL.getType();
5709 if (getDerived().AlwaysRebuild() ||
5710 QualifierLoc != TL.getQualifierLoc() ||
5711 NamedT != T->getNamedType()) {
5712 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5713 T->getKeyword(),
5714 QualifierLoc, NamedT);
5715 if (Result.isNull())
5716 return QualType();
5717 }
5718
5719 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5720 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5721 NewTL.setQualifierLoc(QualifierLoc);
5722 return Result;
5723 }
5724
5725 template<typename Derived>
TransformAttributedType(TypeLocBuilder & TLB,AttributedTypeLoc TL)5726 QualType TreeTransform<Derived>::TransformAttributedType(
5727 TypeLocBuilder &TLB,
5728 AttributedTypeLoc TL) {
5729 const AttributedType *oldType = TL.getTypePtr();
5730 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5731 if (modifiedType.isNull())
5732 return QualType();
5733
5734 QualType result = TL.getType();
5735
5736 // FIXME: dependent operand expressions?
5737 if (getDerived().AlwaysRebuild() ||
5738 modifiedType != oldType->getModifiedType()) {
5739 // TODO: this is really lame; we should really be rebuilding the
5740 // equivalent type from first principles.
5741 QualType equivalentType
5742 = getDerived().TransformType(oldType->getEquivalentType());
5743 if (equivalentType.isNull())
5744 return QualType();
5745
5746 // Check whether we can add nullability; it is only represented as
5747 // type sugar, and therefore cannot be diagnosed in any other way.
5748 if (auto nullability = oldType->getImmediateNullability()) {
5749 if (!modifiedType->canHaveNullability()) {
5750 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5751 << DiagNullabilityKind(*nullability, false) << modifiedType;
5752 return QualType();
5753 }
5754 }
5755
5756 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5757 modifiedType,
5758 equivalentType);
5759 }
5760
5761 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5762 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5763 if (TL.hasAttrOperand())
5764 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5765 if (TL.hasAttrExprOperand())
5766 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5767 else if (TL.hasAttrEnumOperand())
5768 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5769
5770 return result;
5771 }
5772
5773 template<typename Derived>
5774 QualType
TransformParenType(TypeLocBuilder & TLB,ParenTypeLoc TL)5775 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5776 ParenTypeLoc TL) {
5777 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5778 if (Inner.isNull())
5779 return QualType();
5780
5781 QualType Result = TL.getType();
5782 if (getDerived().AlwaysRebuild() ||
5783 Inner != TL.getInnerLoc().getType()) {
5784 Result = getDerived().RebuildParenType(Inner);
5785 if (Result.isNull())
5786 return QualType();
5787 }
5788
5789 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5790 NewTL.setLParenLoc(TL.getLParenLoc());
5791 NewTL.setRParenLoc(TL.getRParenLoc());
5792 return Result;
5793 }
5794
5795 template<typename Derived>
TransformDependentNameType(TypeLocBuilder & TLB,DependentNameTypeLoc TL)5796 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5797 DependentNameTypeLoc TL) {
5798 const DependentNameType *T = TL.getTypePtr();
5799
5800 NestedNameSpecifierLoc QualifierLoc
5801 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5802 if (!QualifierLoc)
5803 return QualType();
5804
5805 QualType Result
5806 = getDerived().RebuildDependentNameType(T->getKeyword(),
5807 TL.getElaboratedKeywordLoc(),
5808 QualifierLoc,
5809 T->getIdentifier(),
5810 TL.getNameLoc());
5811 if (Result.isNull())
5812 return QualType();
5813
5814 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5815 QualType NamedT = ElabT->getNamedType();
5816 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5817
5818 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5819 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5820 NewTL.setQualifierLoc(QualifierLoc);
5821 } else {
5822 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5823 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5824 NewTL.setQualifierLoc(QualifierLoc);
5825 NewTL.setNameLoc(TL.getNameLoc());
5826 }
5827 return Result;
5828 }
5829
5830 template<typename Derived>
5831 QualType TreeTransform<Derived>::
TransformDependentTemplateSpecializationType(TypeLocBuilder & TLB,DependentTemplateSpecializationTypeLoc TL)5832 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5833 DependentTemplateSpecializationTypeLoc TL) {
5834 NestedNameSpecifierLoc QualifierLoc;
5835 if (TL.getQualifierLoc()) {
5836 QualifierLoc
5837 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5838 if (!QualifierLoc)
5839 return QualType();
5840 }
5841
5842 return getDerived()
5843 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5844 }
5845
5846 template<typename Derived>
5847 QualType TreeTransform<Derived>::
TransformDependentTemplateSpecializationType(TypeLocBuilder & TLB,DependentTemplateSpecializationTypeLoc TL,NestedNameSpecifierLoc QualifierLoc)5848 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5849 DependentTemplateSpecializationTypeLoc TL,
5850 NestedNameSpecifierLoc QualifierLoc) {
5851 const DependentTemplateSpecializationType *T = TL.getTypePtr();
5852
5853 TemplateArgumentListInfo NewTemplateArgs;
5854 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5855 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5856
5857 typedef TemplateArgumentLocContainerIterator<
5858 DependentTemplateSpecializationTypeLoc> ArgIterator;
5859 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5860 ArgIterator(TL, TL.getNumArgs()),
5861 NewTemplateArgs))
5862 return QualType();
5863
5864 QualType Result
5865 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5866 QualifierLoc,
5867 T->getIdentifier(),
5868 TL.getTemplateNameLoc(),
5869 NewTemplateArgs);
5870 if (Result.isNull())
5871 return QualType();
5872
5873 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5874 QualType NamedT = ElabT->getNamedType();
5875
5876 // Copy information relevant to the template specialization.
5877 TemplateSpecializationTypeLoc NamedTL
5878 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5879 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5880 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5881 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5882 NamedTL.setRAngleLoc(TL.getRAngleLoc());
5883 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5884 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5885
5886 // Copy information relevant to the elaborated type.
5887 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5888 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5889 NewTL.setQualifierLoc(QualifierLoc);
5890 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5891 DependentTemplateSpecializationTypeLoc SpecTL
5892 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5893 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5894 SpecTL.setQualifierLoc(QualifierLoc);
5895 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5896 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5897 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5898 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5899 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5900 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5901 } else {
5902 TemplateSpecializationTypeLoc SpecTL
5903 = TLB.push<TemplateSpecializationTypeLoc>(Result);
5904 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5905 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5906 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5907 SpecTL.setRAngleLoc(TL.getRAngleLoc());
5908 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5909 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5910 }
5911 return Result;
5912 }
5913
5914 template<typename Derived>
TransformPackExpansionType(TypeLocBuilder & TLB,PackExpansionTypeLoc TL)5915 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5916 PackExpansionTypeLoc TL) {
5917 QualType Pattern
5918 = getDerived().TransformType(TLB, TL.getPatternLoc());
5919 if (Pattern.isNull())
5920 return QualType();
5921
5922 QualType Result = TL.getType();
5923 if (getDerived().AlwaysRebuild() ||
5924 Pattern != TL.getPatternLoc().getType()) {
5925 Result = getDerived().RebuildPackExpansionType(Pattern,
5926 TL.getPatternLoc().getSourceRange(),
5927 TL.getEllipsisLoc(),
5928 TL.getTypePtr()->getNumExpansions());
5929 if (Result.isNull())
5930 return QualType();
5931 }
5932
5933 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5934 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5935 return Result;
5936 }
5937
5938 template<typename Derived>
5939 QualType
TransformObjCInterfaceType(TypeLocBuilder & TLB,ObjCInterfaceTypeLoc TL)5940 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5941 ObjCInterfaceTypeLoc TL) {
5942 // ObjCInterfaceType is never dependent.
5943 TLB.pushFullCopy(TL);
5944 return TL.getType();
5945 }
5946
5947 template<typename Derived>
5948 QualType
TransformObjCObjectType(TypeLocBuilder & TLB,ObjCObjectTypeLoc TL)5949 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5950 ObjCObjectTypeLoc TL) {
5951 // Transform base type.
5952 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5953 if (BaseType.isNull())
5954 return QualType();
5955
5956 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5957
5958 // Transform type arguments.
5959 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5960 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5961 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5962 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5963 QualType TypeArg = TypeArgInfo->getType();
5964 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5965 AnyChanged = true;
5966
5967 // We have a pack expansion. Instantiate it.
5968 const auto *PackExpansion = PackExpansionLoc.getType()
5969 ->castAs<PackExpansionType>();
5970 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5971 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5972 Unexpanded);
5973 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5974
5975 // Determine whether the set of unexpanded parameter packs can
5976 // and should be expanded.
5977 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5978 bool Expand = false;
5979 bool RetainExpansion = false;
5980 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5981 if (getDerived().TryExpandParameterPacks(
5982 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5983 Unexpanded, Expand, RetainExpansion, NumExpansions))
5984 return QualType();
5985
5986 if (!Expand) {
5987 // We can't expand this pack expansion into separate arguments yet;
5988 // just substitute into the pattern and create a new pack expansion
5989 // type.
5990 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5991
5992 TypeLocBuilder TypeArgBuilder;
5993 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5994 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5995 PatternLoc);
5996 if (NewPatternType.isNull())
5997 return QualType();
5998
5999 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6000 NewPatternType, NumExpansions);
6001 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6002 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6003 NewTypeArgInfos.push_back(
6004 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6005 continue;
6006 }
6007
6008 // Substitute into the pack expansion pattern for each slice of the
6009 // pack.
6010 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6011 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6012
6013 TypeLocBuilder TypeArgBuilder;
6014 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6015
6016 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6017 PatternLoc);
6018 if (NewTypeArg.isNull())
6019 return QualType();
6020
6021 NewTypeArgInfos.push_back(
6022 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6023 }
6024
6025 continue;
6026 }
6027
6028 TypeLocBuilder TypeArgBuilder;
6029 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6030 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6031 if (NewTypeArg.isNull())
6032 return QualType();
6033
6034 // If nothing changed, just keep the old TypeSourceInfo.
6035 if (NewTypeArg == TypeArg) {
6036 NewTypeArgInfos.push_back(TypeArgInfo);
6037 continue;
6038 }
6039
6040 NewTypeArgInfos.push_back(
6041 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6042 AnyChanged = true;
6043 }
6044
6045 QualType Result = TL.getType();
6046 if (getDerived().AlwaysRebuild() || AnyChanged) {
6047 // Rebuild the type.
6048 Result = getDerived().RebuildObjCObjectType(
6049 BaseType,
6050 TL.getLocStart(),
6051 TL.getTypeArgsLAngleLoc(),
6052 NewTypeArgInfos,
6053 TL.getTypeArgsRAngleLoc(),
6054 TL.getProtocolLAngleLoc(),
6055 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6056 TL.getNumProtocols()),
6057 TL.getProtocolLocs(),
6058 TL.getProtocolRAngleLoc());
6059
6060 if (Result.isNull())
6061 return QualType();
6062 }
6063
6064 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6065 NewT.setHasBaseTypeAsWritten(true);
6066 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6067 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6068 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6069 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6070 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6071 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6072 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6073 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6074 return Result;
6075 }
6076
6077 template<typename Derived>
6078 QualType
TransformObjCObjectPointerType(TypeLocBuilder & TLB,ObjCObjectPointerTypeLoc TL)6079 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6080 ObjCObjectPointerTypeLoc TL) {
6081 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6082 if (PointeeType.isNull())
6083 return QualType();
6084
6085 QualType Result = TL.getType();
6086 if (getDerived().AlwaysRebuild() ||
6087 PointeeType != TL.getPointeeLoc().getType()) {
6088 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6089 TL.getStarLoc());
6090 if (Result.isNull())
6091 return QualType();
6092 }
6093
6094 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6095 NewT.setStarLoc(TL.getStarLoc());
6096 return Result;
6097 }
6098
6099 //===----------------------------------------------------------------------===//
6100 // Statement transformation
6101 //===----------------------------------------------------------------------===//
6102 template<typename Derived>
6103 StmtResult
TransformNullStmt(NullStmt * S)6104 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6105 return S;
6106 }
6107
6108 template<typename Derived>
6109 StmtResult
TransformCompoundStmt(CompoundStmt * S)6110 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6111 return getDerived().TransformCompoundStmt(S, false);
6112 }
6113
6114 template<typename Derived>
6115 StmtResult
TransformCompoundStmt(CompoundStmt * S,bool IsStmtExpr)6116 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
6117 bool IsStmtExpr) {
6118 Sema::CompoundScopeRAII CompoundScope(getSema());
6119
6120 bool SubStmtInvalid = false;
6121 bool SubStmtChanged = false;
6122 SmallVector<Stmt*, 8> Statements;
6123 for (auto *B : S->body()) {
6124 StmtResult Result = getDerived().TransformStmt(B);
6125 if (Result.isInvalid()) {
6126 // Immediately fail if this was a DeclStmt, since it's very
6127 // likely that this will cause problems for future statements.
6128 if (isa<DeclStmt>(B))
6129 return StmtError();
6130
6131 // Otherwise, just keep processing substatements and fail later.
6132 SubStmtInvalid = true;
6133 continue;
6134 }
6135
6136 SubStmtChanged = SubStmtChanged || Result.get() != B;
6137 Statements.push_back(Result.getAs<Stmt>());
6138 }
6139
6140 if (SubStmtInvalid)
6141 return StmtError();
6142
6143 if (!getDerived().AlwaysRebuild() &&
6144 !SubStmtChanged)
6145 return S;
6146
6147 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6148 Statements,
6149 S->getRBracLoc(),
6150 IsStmtExpr);
6151 }
6152
6153 template<typename Derived>
6154 StmtResult
TransformCaseStmt(CaseStmt * S)6155 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6156 ExprResult LHS, RHS;
6157 {
6158 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6159 Sema::ConstantEvaluated);
6160
6161 // Transform the left-hand case value.
6162 LHS = getDerived().TransformExpr(S->getLHS());
6163 LHS = SemaRef.ActOnConstantExpression(LHS);
6164 if (LHS.isInvalid())
6165 return StmtError();
6166
6167 // Transform the right-hand case value (for the GNU case-range extension).
6168 RHS = getDerived().TransformExpr(S->getRHS());
6169 RHS = SemaRef.ActOnConstantExpression(RHS);
6170 if (RHS.isInvalid())
6171 return StmtError();
6172 }
6173
6174 // Build the case statement.
6175 // Case statements are always rebuilt so that they will attached to their
6176 // transformed switch statement.
6177 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6178 LHS.get(),
6179 S->getEllipsisLoc(),
6180 RHS.get(),
6181 S->getColonLoc());
6182 if (Case.isInvalid())
6183 return StmtError();
6184
6185 // Transform the statement following the case
6186 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6187 if (SubStmt.isInvalid())
6188 return StmtError();
6189
6190 // Attach the body to the case statement
6191 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6192 }
6193
6194 template<typename Derived>
6195 StmtResult
TransformDefaultStmt(DefaultStmt * S)6196 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6197 // Transform the statement following the default case
6198 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6199 if (SubStmt.isInvalid())
6200 return StmtError();
6201
6202 // Default statements are always rebuilt
6203 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6204 SubStmt.get());
6205 }
6206
6207 template<typename Derived>
6208 StmtResult
TransformLabelStmt(LabelStmt * S)6209 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6210 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6211 if (SubStmt.isInvalid())
6212 return StmtError();
6213
6214 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6215 S->getDecl());
6216 if (!LD)
6217 return StmtError();
6218
6219
6220 // FIXME: Pass the real colon location in.
6221 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6222 cast<LabelDecl>(LD), SourceLocation(),
6223 SubStmt.get());
6224 }
6225
6226 template <typename Derived>
TransformAttr(const Attr * R)6227 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6228 if (!R)
6229 return R;
6230
6231 switch (R->getKind()) {
6232 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6233 #define ATTR(X)
6234 #define PRAGMA_SPELLING_ATTR(X) \
6235 case attr::X: \
6236 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6237 #include "clang/Basic/AttrList.inc"
6238 default:
6239 return R;
6240 }
6241 }
6242
6243 template <typename Derived>
TransformAttributedStmt(AttributedStmt * S)6244 StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6245 bool AttrsChanged = false;
6246 SmallVector<const Attr *, 1> Attrs;
6247
6248 // Visit attributes and keep track if any are transformed.
6249 for (const auto *I : S->getAttrs()) {
6250 const Attr *R = getDerived().TransformAttr(I);
6251 AttrsChanged |= (I != R);
6252 Attrs.push_back(R);
6253 }
6254
6255 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6256 if (SubStmt.isInvalid())
6257 return StmtError();
6258
6259 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6260 return S;
6261
6262 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6263 SubStmt.get());
6264 }
6265
6266 template<typename Derived>
6267 StmtResult
TransformIfStmt(IfStmt * S)6268 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6269 // Transform the initialization statement
6270 StmtResult Init = getDerived().TransformStmt(S->getInit());
6271 if (Init.isInvalid())
6272 return StmtError();
6273
6274 // Transform the condition
6275 Sema::ConditionResult Cond = getDerived().TransformCondition(
6276 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6277 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6278 : Sema::ConditionKind::Boolean);
6279 if (Cond.isInvalid())
6280 return StmtError();
6281
6282 // If this is a constexpr if, determine which arm we should instantiate.
6283 llvm::Optional<bool> ConstexprConditionValue;
6284 if (S->isConstexpr())
6285 ConstexprConditionValue = Cond.getKnownValue();
6286
6287 // Transform the "then" branch.
6288 StmtResult Then;
6289 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6290 Then = getDerived().TransformStmt(S->getThen());
6291 if (Then.isInvalid())
6292 return StmtError();
6293 } else {
6294 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6295 }
6296
6297 // Transform the "else" branch.
6298 StmtResult Else;
6299 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6300 Else = getDerived().TransformStmt(S->getElse());
6301 if (Else.isInvalid())
6302 return StmtError();
6303 }
6304
6305 if (!getDerived().AlwaysRebuild() &&
6306 Init.get() == S->getInit() &&
6307 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6308 Then.get() == S->getThen() &&
6309 Else.get() == S->getElse())
6310 return S;
6311
6312 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6313 Init.get(), Then.get(), S->getElseLoc(),
6314 Else.get());
6315 }
6316
6317 template<typename Derived>
6318 StmtResult
TransformSwitchStmt(SwitchStmt * S)6319 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6320 // Transform the initialization statement
6321 StmtResult Init = getDerived().TransformStmt(S->getInit());
6322 if (Init.isInvalid())
6323 return StmtError();
6324
6325 // Transform the condition.
6326 Sema::ConditionResult Cond = getDerived().TransformCondition(
6327 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6328 Sema::ConditionKind::Switch);
6329 if (Cond.isInvalid())
6330 return StmtError();
6331
6332 // Rebuild the switch statement.
6333 StmtResult Switch
6334 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6335 S->getInit(), Cond);
6336 if (Switch.isInvalid())
6337 return StmtError();
6338
6339 // Transform the body of the switch statement.
6340 StmtResult Body = getDerived().TransformStmt(S->getBody());
6341 if (Body.isInvalid())
6342 return StmtError();
6343
6344 // Complete the switch statement.
6345 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6346 Body.get());
6347 }
6348
6349 template<typename Derived>
6350 StmtResult
TransformWhileStmt(WhileStmt * S)6351 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6352 // Transform the condition
6353 Sema::ConditionResult Cond = getDerived().TransformCondition(
6354 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6355 Sema::ConditionKind::Boolean);
6356 if (Cond.isInvalid())
6357 return StmtError();
6358
6359 // Transform the body
6360 StmtResult Body = getDerived().TransformStmt(S->getBody());
6361 if (Body.isInvalid())
6362 return StmtError();
6363
6364 if (!getDerived().AlwaysRebuild() &&
6365 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6366 Body.get() == S->getBody())
6367 return Owned(S);
6368
6369 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6370 }
6371
6372 template<typename Derived>
6373 StmtResult
TransformDoStmt(DoStmt * S)6374 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6375 // Transform the body
6376 StmtResult Body = getDerived().TransformStmt(S->getBody());
6377 if (Body.isInvalid())
6378 return StmtError();
6379
6380 // Transform the condition
6381 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6382 if (Cond.isInvalid())
6383 return StmtError();
6384
6385 if (!getDerived().AlwaysRebuild() &&
6386 Cond.get() == S->getCond() &&
6387 Body.get() == S->getBody())
6388 return S;
6389
6390 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6391 /*FIXME:*/S->getWhileLoc(), Cond.get(),
6392 S->getRParenLoc());
6393 }
6394
6395 template<typename Derived>
6396 StmtResult
TransformForStmt(ForStmt * S)6397 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6398 // Transform the initialization statement
6399 StmtResult Init = getDerived().TransformStmt(S->getInit());
6400 if (Init.isInvalid())
6401 return StmtError();
6402
6403 // In OpenMP loop region loop control variable must be captured and be
6404 // private. Perform analysis of first part (if any).
6405 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6406 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6407
6408 // Transform the condition
6409 Sema::ConditionResult Cond = getDerived().TransformCondition(
6410 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6411 Sema::ConditionKind::Boolean);
6412 if (Cond.isInvalid())
6413 return StmtError();
6414
6415 // Transform the increment
6416 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6417 if (Inc.isInvalid())
6418 return StmtError();
6419
6420 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6421 if (S->getInc() && !FullInc.get())
6422 return StmtError();
6423
6424 // Transform the body
6425 StmtResult Body = getDerived().TransformStmt(S->getBody());
6426 if (Body.isInvalid())
6427 return StmtError();
6428
6429 if (!getDerived().AlwaysRebuild() &&
6430 Init.get() == S->getInit() &&
6431 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6432 Inc.get() == S->getInc() &&
6433 Body.get() == S->getBody())
6434 return S;
6435
6436 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6437 Init.get(), Cond, FullInc,
6438 S->getRParenLoc(), Body.get());
6439 }
6440
6441 template<typename Derived>
6442 StmtResult
TransformGotoStmt(GotoStmt * S)6443 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6444 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6445 S->getLabel());
6446 if (!LD)
6447 return StmtError();
6448
6449 // Goto statements must always be rebuilt, to resolve the label.
6450 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6451 cast<LabelDecl>(LD));
6452 }
6453
6454 template<typename Derived>
6455 StmtResult
TransformIndirectGotoStmt(IndirectGotoStmt * S)6456 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6457 ExprResult Target = getDerived().TransformExpr(S->getTarget());
6458 if (Target.isInvalid())
6459 return StmtError();
6460 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6461
6462 if (!getDerived().AlwaysRebuild() &&
6463 Target.get() == S->getTarget())
6464 return S;
6465
6466 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6467 Target.get());
6468 }
6469
6470 template<typename Derived>
6471 StmtResult
TransformContinueStmt(ContinueStmt * S)6472 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6473 return S;
6474 }
6475
6476 template<typename Derived>
6477 StmtResult
TransformBreakStmt(BreakStmt * S)6478 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6479 return S;
6480 }
6481
6482 template<typename Derived>
6483 StmtResult
TransformReturnStmt(ReturnStmt * S)6484 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6485 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6486 /*NotCopyInit*/false);
6487 if (Result.isInvalid())
6488 return StmtError();
6489
6490 // FIXME: We always rebuild the return statement because there is no way
6491 // to tell whether the return type of the function has changed.
6492 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6493 }
6494
6495 template<typename Derived>
6496 StmtResult
TransformDeclStmt(DeclStmt * S)6497 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6498 bool DeclChanged = false;
6499 SmallVector<Decl *, 4> Decls;
6500 for (auto *D : S->decls()) {
6501 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6502 if (!Transformed)
6503 return StmtError();
6504
6505 if (Transformed != D)
6506 DeclChanged = true;
6507
6508 Decls.push_back(Transformed);
6509 }
6510
6511 if (!getDerived().AlwaysRebuild() && !DeclChanged)
6512 return S;
6513
6514 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6515 }
6516
6517 template<typename Derived>
6518 StmtResult
TransformGCCAsmStmt(GCCAsmStmt * S)6519 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6520
6521 SmallVector<Expr*, 8> Constraints;
6522 SmallVector<Expr*, 8> Exprs;
6523 SmallVector<IdentifierInfo *, 4> Names;
6524
6525 ExprResult AsmString;
6526 SmallVector<Expr*, 8> Clobbers;
6527
6528 bool ExprsChanged = false;
6529
6530 // Go through the outputs.
6531 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6532 Names.push_back(S->getOutputIdentifier(I));
6533
6534 // No need to transform the constraint literal.
6535 Constraints.push_back(S->getOutputConstraintLiteral(I));
6536
6537 // Transform the output expr.
6538 Expr *OutputExpr = S->getOutputExpr(I);
6539 ExprResult Result = getDerived().TransformExpr(OutputExpr);
6540 if (Result.isInvalid())
6541 return StmtError();
6542
6543 ExprsChanged |= Result.get() != OutputExpr;
6544
6545 Exprs.push_back(Result.get());
6546 }
6547
6548 // Go through the inputs.
6549 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6550 Names.push_back(S->getInputIdentifier(I));
6551
6552 // No need to transform the constraint literal.
6553 Constraints.push_back(S->getInputConstraintLiteral(I));
6554
6555 // Transform the input expr.
6556 Expr *InputExpr = S->getInputExpr(I);
6557 ExprResult Result = getDerived().TransformExpr(InputExpr);
6558 if (Result.isInvalid())
6559 return StmtError();
6560
6561 ExprsChanged |= Result.get() != InputExpr;
6562
6563 Exprs.push_back(Result.get());
6564 }
6565
6566 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6567 return S;
6568
6569 // Go through the clobbers.
6570 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6571 Clobbers.push_back(S->getClobberStringLiteral(I));
6572
6573 // No need to transform the asm string literal.
6574 AsmString = S->getAsmString();
6575 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6576 S->isVolatile(), S->getNumOutputs(),
6577 S->getNumInputs(), Names.data(),
6578 Constraints, Exprs, AsmString.get(),
6579 Clobbers, S->getRParenLoc());
6580 }
6581
6582 template<typename Derived>
6583 StmtResult
TransformMSAsmStmt(MSAsmStmt * S)6584 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6585 ArrayRef<Token> AsmToks =
6586 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6587
6588 bool HadError = false, HadChange = false;
6589
6590 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6591 SmallVector<Expr*, 8> TransformedExprs;
6592 TransformedExprs.reserve(SrcExprs.size());
6593 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6594 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6595 if (!Result.isUsable()) {
6596 HadError = true;
6597 } else {
6598 HadChange |= (Result.get() != SrcExprs[i]);
6599 TransformedExprs.push_back(Result.get());
6600 }
6601 }
6602
6603 if (HadError) return StmtError();
6604 if (!HadChange && !getDerived().AlwaysRebuild())
6605 return Owned(S);
6606
6607 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6608 AsmToks, S->getAsmString(),
6609 S->getNumOutputs(), S->getNumInputs(),
6610 S->getAllConstraints(), S->getClobbers(),
6611 TransformedExprs, S->getEndLoc());
6612 }
6613
6614 // C++ Coroutines TS
6615
6616 template<typename Derived>
6617 StmtResult
TransformCoroutineBodyStmt(CoroutineBodyStmt * S)6618 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6619 // The coroutine body should be re-formed by the caller if necessary.
6620 return getDerived().TransformStmt(S->getBody());
6621 }
6622
6623 template<typename Derived>
6624 StmtResult
TransformCoreturnStmt(CoreturnStmt * S)6625 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6626 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6627 /*NotCopyInit*/false);
6628 if (Result.isInvalid())
6629 return StmtError();
6630
6631 // Always rebuild; we don't know if this needs to be injected into a new
6632 // context or if the promise type has changed.
6633 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6634 }
6635
6636 template<typename Derived>
6637 ExprResult
TransformCoawaitExpr(CoawaitExpr * E)6638 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6639 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6640 /*NotCopyInit*/false);
6641 if (Result.isInvalid())
6642 return ExprError();
6643
6644 // Always rebuild; we don't know if this needs to be injected into a new
6645 // context or if the promise type has changed.
6646 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6647 }
6648
6649 template<typename Derived>
6650 ExprResult
TransformCoyieldExpr(CoyieldExpr * E)6651 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6652 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6653 /*NotCopyInit*/false);
6654 if (Result.isInvalid())
6655 return ExprError();
6656
6657 // Always rebuild; we don't know if this needs to be injected into a new
6658 // context or if the promise type has changed.
6659 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6660 }
6661
6662 // Objective-C Statements.
6663
6664 template<typename Derived>
6665 StmtResult
TransformObjCAtTryStmt(ObjCAtTryStmt * S)6666 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
6667 // Transform the body of the @try.
6668 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
6669 if (TryBody.isInvalid())
6670 return StmtError();
6671
6672 // Transform the @catch statements (if present).
6673 bool AnyCatchChanged = false;
6674 SmallVector<Stmt*, 8> CatchStmts;
6675 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
6676 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
6677 if (Catch.isInvalid())
6678 return StmtError();
6679 if (Catch.get() != S->getCatchStmt(I))
6680 AnyCatchChanged = true;
6681 CatchStmts.push_back(Catch.get());
6682 }
6683
6684 // Transform the @finally statement (if present).
6685 StmtResult Finally;
6686 if (S->getFinallyStmt()) {
6687 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6688 if (Finally.isInvalid())
6689 return StmtError();
6690 }
6691
6692 // If nothing changed, just retain this statement.
6693 if (!getDerived().AlwaysRebuild() &&
6694 TryBody.get() == S->getTryBody() &&
6695 !AnyCatchChanged &&
6696 Finally.get() == S->getFinallyStmt())
6697 return S;
6698
6699 // Build a new statement.
6700 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
6701 CatchStmts, Finally.get());
6702 }
6703
6704 template<typename Derived>
6705 StmtResult
TransformObjCAtCatchStmt(ObjCAtCatchStmt * S)6706 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
6707 // Transform the @catch parameter, if there is one.
6708 VarDecl *Var = nullptr;
6709 if (VarDecl *FromVar = S->getCatchParamDecl()) {
6710 TypeSourceInfo *TSInfo = nullptr;
6711 if (FromVar->getTypeSourceInfo()) {
6712 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6713 if (!TSInfo)
6714 return StmtError();
6715 }
6716
6717 QualType T;
6718 if (TSInfo)
6719 T = TSInfo->getType();
6720 else {
6721 T = getDerived().TransformType(FromVar->getType());
6722 if (T.isNull())
6723 return StmtError();
6724 }
6725
6726 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6727 if (!Var)
6728 return StmtError();
6729 }
6730
6731 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6732 if (Body.isInvalid())
6733 return StmtError();
6734
6735 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6736 S->getRParenLoc(),
6737 Var, Body.get());
6738 }
6739
6740 template<typename Derived>
6741 StmtResult
TransformObjCAtFinallyStmt(ObjCAtFinallyStmt * S)6742 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6743 // Transform the body.
6744 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6745 if (Body.isInvalid())
6746 return StmtError();
6747
6748 // If nothing changed, just retain this statement.
6749 if (!getDerived().AlwaysRebuild() &&
6750 Body.get() == S->getFinallyBody())
6751 return S;
6752
6753 // Build a new statement.
6754 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6755 Body.get());
6756 }
6757
6758 template<typename Derived>
6759 StmtResult
TransformObjCAtThrowStmt(ObjCAtThrowStmt * S)6760 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6761 ExprResult Operand;
6762 if (S->getThrowExpr()) {
6763 Operand = getDerived().TransformExpr(S->getThrowExpr());
6764 if (Operand.isInvalid())
6765 return StmtError();
6766 }
6767
6768 if (!getDerived().AlwaysRebuild() &&
6769 Operand.get() == S->getThrowExpr())
6770 return S;
6771
6772 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6773 }
6774
6775 template<typename Derived>
6776 StmtResult
TransformObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt * S)6777 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6778 ObjCAtSynchronizedStmt *S) {
6779 // Transform the object we are locking.
6780 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6781 if (Object.isInvalid())
6782 return StmtError();
6783 Object =
6784 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6785 Object.get());
6786 if (Object.isInvalid())
6787 return StmtError();
6788
6789 // Transform the body.
6790 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6791 if (Body.isInvalid())
6792 return StmtError();
6793
6794 // If nothing change, just retain the current statement.
6795 if (!getDerived().AlwaysRebuild() &&
6796 Object.get() == S->getSynchExpr() &&
6797 Body.get() == S->getSynchBody())
6798 return S;
6799
6800 // Build a new statement.
6801 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6802 Object.get(), Body.get());
6803 }
6804
6805 template<typename Derived>
6806 StmtResult
TransformObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt * S)6807 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6808 ObjCAutoreleasePoolStmt *S) {
6809 // Transform the body.
6810 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6811 if (Body.isInvalid())
6812 return StmtError();
6813
6814 // If nothing changed, just retain this statement.
6815 if (!getDerived().AlwaysRebuild() &&
6816 Body.get() == S->getSubStmt())
6817 return S;
6818
6819 // Build a new statement.
6820 return getDerived().RebuildObjCAutoreleasePoolStmt(
6821 S->getAtLoc(), Body.get());
6822 }
6823
6824 template<typename Derived>
6825 StmtResult
TransformObjCForCollectionStmt(ObjCForCollectionStmt * S)6826 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6827 ObjCForCollectionStmt *S) {
6828 // Transform the element statement.
6829 StmtResult Element = getDerived().TransformStmt(S->getElement());
6830 if (Element.isInvalid())
6831 return StmtError();
6832
6833 // Transform the collection expression.
6834 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6835 if (Collection.isInvalid())
6836 return StmtError();
6837
6838 // Transform the body.
6839 StmtResult Body = getDerived().TransformStmt(S->getBody());
6840 if (Body.isInvalid())
6841 return StmtError();
6842
6843 // If nothing changed, just retain this statement.
6844 if (!getDerived().AlwaysRebuild() &&
6845 Element.get() == S->getElement() &&
6846 Collection.get() == S->getCollection() &&
6847 Body.get() == S->getBody())
6848 return S;
6849
6850 // Build a new statement.
6851 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6852 Element.get(),
6853 Collection.get(),
6854 S->getRParenLoc(),
6855 Body.get());
6856 }
6857
6858 template <typename Derived>
TransformCXXCatchStmt(CXXCatchStmt * S)6859 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6860 // Transform the exception declaration, if any.
6861 VarDecl *Var = nullptr;
6862 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6863 TypeSourceInfo *T =
6864 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6865 if (!T)
6866 return StmtError();
6867
6868 Var = getDerived().RebuildExceptionDecl(
6869 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6870 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6871 if (!Var || Var->isInvalidDecl())
6872 return StmtError();
6873 }
6874
6875 // Transform the actual exception handler.
6876 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6877 if (Handler.isInvalid())
6878 return StmtError();
6879
6880 if (!getDerived().AlwaysRebuild() && !Var &&
6881 Handler.get() == S->getHandlerBlock())
6882 return S;
6883
6884 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6885 }
6886
6887 template <typename Derived>
TransformCXXTryStmt(CXXTryStmt * S)6888 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6889 // Transform the try block itself.
6890 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6891 if (TryBlock.isInvalid())
6892 return StmtError();
6893
6894 // Transform the handlers.
6895 bool HandlerChanged = false;
6896 SmallVector<Stmt *, 8> Handlers;
6897 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6898 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6899 if (Handler.isInvalid())
6900 return StmtError();
6901
6902 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6903 Handlers.push_back(Handler.getAs<Stmt>());
6904 }
6905
6906 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6907 !HandlerChanged)
6908 return S;
6909
6910 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6911 Handlers);
6912 }
6913
6914 template<typename Derived>
6915 StmtResult
TransformCXXForRangeStmt(CXXForRangeStmt * S)6916 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6917 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6918 if (Range.isInvalid())
6919 return StmtError();
6920
6921 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6922 if (Begin.isInvalid())
6923 return StmtError();
6924 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6925 if (End.isInvalid())
6926 return StmtError();
6927
6928 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6929 if (Cond.isInvalid())
6930 return StmtError();
6931 if (Cond.get())
6932 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
6933 if (Cond.isInvalid())
6934 return StmtError();
6935 if (Cond.get())
6936 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6937
6938 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6939 if (Inc.isInvalid())
6940 return StmtError();
6941 if (Inc.get())
6942 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6943
6944 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6945 if (LoopVar.isInvalid())
6946 return StmtError();
6947
6948 StmtResult NewStmt = S;
6949 if (getDerived().AlwaysRebuild() ||
6950 Range.get() != S->getRangeStmt() ||
6951 Begin.get() != S->getBeginStmt() ||
6952 End.get() != S->getEndStmt() ||
6953 Cond.get() != S->getCond() ||
6954 Inc.get() != S->getInc() ||
6955 LoopVar.get() != S->getLoopVarStmt()) {
6956 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6957 S->getCoawaitLoc(),
6958 S->getColonLoc(), Range.get(),
6959 Begin.get(), End.get(),
6960 Cond.get(),
6961 Inc.get(), LoopVar.get(),
6962 S->getRParenLoc());
6963 if (NewStmt.isInvalid())
6964 return StmtError();
6965 }
6966
6967 StmtResult Body = getDerived().TransformStmt(S->getBody());
6968 if (Body.isInvalid())
6969 return StmtError();
6970
6971 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6972 // it now so we have a new statement to attach the body to.
6973 if (Body.get() != S->getBody() && NewStmt.get() == S) {
6974 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6975 S->getCoawaitLoc(),
6976 S->getColonLoc(), Range.get(),
6977 Begin.get(), End.get(),
6978 Cond.get(),
6979 Inc.get(), LoopVar.get(),
6980 S->getRParenLoc());
6981 if (NewStmt.isInvalid())
6982 return StmtError();
6983 }
6984
6985 if (NewStmt.get() == S)
6986 return S;
6987
6988 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6989 }
6990
6991 template<typename Derived>
6992 StmtResult
TransformMSDependentExistsStmt(MSDependentExistsStmt * S)6993 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6994 MSDependentExistsStmt *S) {
6995 // Transform the nested-name-specifier, if any.
6996 NestedNameSpecifierLoc QualifierLoc;
6997 if (S->getQualifierLoc()) {
6998 QualifierLoc
6999 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7000 if (!QualifierLoc)
7001 return StmtError();
7002 }
7003
7004 // Transform the declaration name.
7005 DeclarationNameInfo NameInfo = S->getNameInfo();
7006 if (NameInfo.getName()) {
7007 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7008 if (!NameInfo.getName())
7009 return StmtError();
7010 }
7011
7012 // Check whether anything changed.
7013 if (!getDerived().AlwaysRebuild() &&
7014 QualifierLoc == S->getQualifierLoc() &&
7015 NameInfo.getName() == S->getNameInfo().getName())
7016 return S;
7017
7018 // Determine whether this name exists, if we can.
7019 CXXScopeSpec SS;
7020 SS.Adopt(QualifierLoc);
7021 bool Dependent = false;
7022 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7023 case Sema::IER_Exists:
7024 if (S->isIfExists())
7025 break;
7026
7027 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7028
7029 case Sema::IER_DoesNotExist:
7030 if (S->isIfNotExists())
7031 break;
7032
7033 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7034
7035 case Sema::IER_Dependent:
7036 Dependent = true;
7037 break;
7038
7039 case Sema::IER_Error:
7040 return StmtError();
7041 }
7042
7043 // We need to continue with the instantiation, so do so now.
7044 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7045 if (SubStmt.isInvalid())
7046 return StmtError();
7047
7048 // If we have resolved the name, just transform to the substatement.
7049 if (!Dependent)
7050 return SubStmt;
7051
7052 // The name is still dependent, so build a dependent expression again.
7053 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7054 S->isIfExists(),
7055 QualifierLoc,
7056 NameInfo,
7057 SubStmt.get());
7058 }
7059
7060 template<typename Derived>
7061 ExprResult
TransformMSPropertyRefExpr(MSPropertyRefExpr * E)7062 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7063 NestedNameSpecifierLoc QualifierLoc;
7064 if (E->getQualifierLoc()) {
7065 QualifierLoc
7066 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7067 if (!QualifierLoc)
7068 return ExprError();
7069 }
7070
7071 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7072 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7073 if (!PD)
7074 return ExprError();
7075
7076 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7077 if (Base.isInvalid())
7078 return ExprError();
7079
7080 return new (SemaRef.getASTContext())
7081 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7082 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7083 QualifierLoc, E->getMemberLoc());
7084 }
7085
7086 template <typename Derived>
TransformMSPropertySubscriptExpr(MSPropertySubscriptExpr * E)7087 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7088 MSPropertySubscriptExpr *E) {
7089 auto BaseRes = getDerived().TransformExpr(E->getBase());
7090 if (BaseRes.isInvalid())
7091 return ExprError();
7092 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7093 if (IdxRes.isInvalid())
7094 return ExprError();
7095
7096 if (!getDerived().AlwaysRebuild() &&
7097 BaseRes.get() == E->getBase() &&
7098 IdxRes.get() == E->getIdx())
7099 return E;
7100
7101 return getDerived().RebuildArraySubscriptExpr(
7102 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7103 }
7104
7105 template <typename Derived>
TransformSEHTryStmt(SEHTryStmt * S)7106 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7107 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7108 if (TryBlock.isInvalid())
7109 return StmtError();
7110
7111 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7112 if (Handler.isInvalid())
7113 return StmtError();
7114
7115 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7116 Handler.get() == S->getHandler())
7117 return S;
7118
7119 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7120 TryBlock.get(), Handler.get());
7121 }
7122
7123 template <typename Derived>
TransformSEHFinallyStmt(SEHFinallyStmt * S)7124 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7125 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7126 if (Block.isInvalid())
7127 return StmtError();
7128
7129 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7130 }
7131
7132 template <typename Derived>
TransformSEHExceptStmt(SEHExceptStmt * S)7133 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7134 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7135 if (FilterExpr.isInvalid())
7136 return StmtError();
7137
7138 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7139 if (Block.isInvalid())
7140 return StmtError();
7141
7142 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7143 Block.get());
7144 }
7145
7146 template <typename Derived>
TransformSEHHandler(Stmt * Handler)7147 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7148 if (isa<SEHFinallyStmt>(Handler))
7149 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7150 else
7151 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7152 }
7153
7154 template<typename Derived>
7155 StmtResult
TransformSEHLeaveStmt(SEHLeaveStmt * S)7156 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7157 return S;
7158 }
7159
7160 //===----------------------------------------------------------------------===//
7161 // OpenMP directive transformation
7162 //===----------------------------------------------------------------------===//
7163 template <typename Derived>
TransformOMPExecutableDirective(OMPExecutableDirective * D)7164 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7165 OMPExecutableDirective *D) {
7166
7167 // Transform the clauses
7168 llvm::SmallVector<OMPClause *, 16> TClauses;
7169 ArrayRef<OMPClause *> Clauses = D->clauses();
7170 TClauses.reserve(Clauses.size());
7171 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7172 I != E; ++I) {
7173 if (*I) {
7174 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7175 OMPClause *Clause = getDerived().TransformOMPClause(*I);
7176 getDerived().getSema().EndOpenMPClause();
7177 if (Clause)
7178 TClauses.push_back(Clause);
7179 } else {
7180 TClauses.push_back(nullptr);
7181 }
7182 }
7183 StmtResult AssociatedStmt;
7184 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7185 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7186 /*CurScope=*/nullptr);
7187 StmtResult Body;
7188 {
7189 Sema::CompoundScopeRAII CompoundScope(getSema());
7190 Body = getDerived().TransformStmt(
7191 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7192 }
7193 AssociatedStmt =
7194 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7195 if (AssociatedStmt.isInvalid()) {
7196 return StmtError();
7197 }
7198 }
7199 if (TClauses.size() != Clauses.size()) {
7200 return StmtError();
7201 }
7202
7203 // Transform directive name for 'omp critical' directive.
7204 DeclarationNameInfo DirName;
7205 if (D->getDirectiveKind() == OMPD_critical) {
7206 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7207 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7208 }
7209 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7210 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7211 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7212 } else if (D->getDirectiveKind() == OMPD_cancel) {
7213 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7214 }
7215
7216 return getDerived().RebuildOMPExecutableDirective(
7217 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7218 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7219 }
7220
7221 template <typename Derived>
7222 StmtResult
TransformOMPParallelDirective(OMPParallelDirective * D)7223 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7224 DeclarationNameInfo DirName;
7225 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7226 D->getLocStart());
7227 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7228 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7229 return Res;
7230 }
7231
7232 template <typename Derived>
7233 StmtResult
TransformOMPSimdDirective(OMPSimdDirective * D)7234 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7235 DeclarationNameInfo DirName;
7236 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7237 D->getLocStart());
7238 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7239 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7240 return Res;
7241 }
7242
7243 template <typename Derived>
7244 StmtResult
TransformOMPForDirective(OMPForDirective * D)7245 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7246 DeclarationNameInfo DirName;
7247 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7248 D->getLocStart());
7249 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7250 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7251 return Res;
7252 }
7253
7254 template <typename Derived>
7255 StmtResult
TransformOMPForSimdDirective(OMPForSimdDirective * D)7256 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7257 DeclarationNameInfo DirName;
7258 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7259 D->getLocStart());
7260 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7261 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7262 return Res;
7263 }
7264
7265 template <typename Derived>
7266 StmtResult
TransformOMPSectionsDirective(OMPSectionsDirective * D)7267 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7268 DeclarationNameInfo DirName;
7269 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7270 D->getLocStart());
7271 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7272 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7273 return Res;
7274 }
7275
7276 template <typename Derived>
7277 StmtResult
TransformOMPSectionDirective(OMPSectionDirective * D)7278 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7279 DeclarationNameInfo DirName;
7280 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7281 D->getLocStart());
7282 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7283 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7284 return Res;
7285 }
7286
7287 template <typename Derived>
7288 StmtResult
TransformOMPSingleDirective(OMPSingleDirective * D)7289 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7290 DeclarationNameInfo DirName;
7291 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7292 D->getLocStart());
7293 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7294 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7295 return Res;
7296 }
7297
7298 template <typename Derived>
7299 StmtResult
TransformOMPMasterDirective(OMPMasterDirective * D)7300 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7301 DeclarationNameInfo DirName;
7302 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7303 D->getLocStart());
7304 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7305 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7306 return Res;
7307 }
7308
7309 template <typename Derived>
7310 StmtResult
TransformOMPCriticalDirective(OMPCriticalDirective * D)7311 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7312 getDerived().getSema().StartOpenMPDSABlock(
7313 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7314 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7315 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7316 return Res;
7317 }
7318
7319 template <typename Derived>
TransformOMPParallelForDirective(OMPParallelForDirective * D)7320 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7321 OMPParallelForDirective *D) {
7322 DeclarationNameInfo DirName;
7323 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7324 nullptr, D->getLocStart());
7325 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7326 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7327 return Res;
7328 }
7329
7330 template <typename Derived>
TransformOMPParallelForSimdDirective(OMPParallelForSimdDirective * D)7331 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7332 OMPParallelForSimdDirective *D) {
7333 DeclarationNameInfo DirName;
7334 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7335 nullptr, D->getLocStart());
7336 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7337 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7338 return Res;
7339 }
7340
7341 template <typename Derived>
TransformOMPParallelSectionsDirective(OMPParallelSectionsDirective * D)7342 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7343 OMPParallelSectionsDirective *D) {
7344 DeclarationNameInfo DirName;
7345 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7346 nullptr, D->getLocStart());
7347 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7348 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7349 return Res;
7350 }
7351
7352 template <typename Derived>
7353 StmtResult
TransformOMPTaskDirective(OMPTaskDirective * D)7354 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7355 DeclarationNameInfo DirName;
7356 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7357 D->getLocStart());
7358 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7359 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7360 return Res;
7361 }
7362
7363 template <typename Derived>
TransformOMPTaskyieldDirective(OMPTaskyieldDirective * D)7364 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7365 OMPTaskyieldDirective *D) {
7366 DeclarationNameInfo DirName;
7367 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7368 D->getLocStart());
7369 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7370 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7371 return Res;
7372 }
7373
7374 template <typename Derived>
7375 StmtResult
TransformOMPBarrierDirective(OMPBarrierDirective * D)7376 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7377 DeclarationNameInfo DirName;
7378 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7379 D->getLocStart());
7380 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7381 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7382 return Res;
7383 }
7384
7385 template <typename Derived>
7386 StmtResult
TransformOMPTaskwaitDirective(OMPTaskwaitDirective * D)7387 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7388 DeclarationNameInfo DirName;
7389 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7390 D->getLocStart());
7391 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7392 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7393 return Res;
7394 }
7395
7396 template <typename Derived>
TransformOMPTaskgroupDirective(OMPTaskgroupDirective * D)7397 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7398 OMPTaskgroupDirective *D) {
7399 DeclarationNameInfo DirName;
7400 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7401 D->getLocStart());
7402 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7403 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7404 return Res;
7405 }
7406
7407 template <typename Derived>
7408 StmtResult
TransformOMPFlushDirective(OMPFlushDirective * D)7409 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7410 DeclarationNameInfo DirName;
7411 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7412 D->getLocStart());
7413 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7414 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7415 return Res;
7416 }
7417
7418 template <typename Derived>
7419 StmtResult
TransformOMPOrderedDirective(OMPOrderedDirective * D)7420 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7421 DeclarationNameInfo DirName;
7422 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7423 D->getLocStart());
7424 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7425 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7426 return Res;
7427 }
7428
7429 template <typename Derived>
7430 StmtResult
TransformOMPAtomicDirective(OMPAtomicDirective * D)7431 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7432 DeclarationNameInfo DirName;
7433 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7434 D->getLocStart());
7435 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7436 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7437 return Res;
7438 }
7439
7440 template <typename Derived>
7441 StmtResult
TransformOMPTargetDirective(OMPTargetDirective * D)7442 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7443 DeclarationNameInfo DirName;
7444 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7445 D->getLocStart());
7446 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7447 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7448 return Res;
7449 }
7450
7451 template <typename Derived>
TransformOMPTargetDataDirective(OMPTargetDataDirective * D)7452 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7453 OMPTargetDataDirective *D) {
7454 DeclarationNameInfo DirName;
7455 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7456 D->getLocStart());
7457 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7458 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7459 return Res;
7460 }
7461
7462 template <typename Derived>
TransformOMPTargetEnterDataDirective(OMPTargetEnterDataDirective * D)7463 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7464 OMPTargetEnterDataDirective *D) {
7465 DeclarationNameInfo DirName;
7466 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7467 nullptr, D->getLocStart());
7468 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7469 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7470 return Res;
7471 }
7472
7473 template <typename Derived>
TransformOMPTargetExitDataDirective(OMPTargetExitDataDirective * D)7474 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7475 OMPTargetExitDataDirective *D) {
7476 DeclarationNameInfo DirName;
7477 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7478 nullptr, D->getLocStart());
7479 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7480 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7481 return Res;
7482 }
7483
7484 template <typename Derived>
TransformOMPTargetParallelDirective(OMPTargetParallelDirective * D)7485 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7486 OMPTargetParallelDirective *D) {
7487 DeclarationNameInfo DirName;
7488 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7489 nullptr, D->getLocStart());
7490 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7491 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7492 return Res;
7493 }
7494
7495 template <typename Derived>
TransformOMPTargetParallelForDirective(OMPTargetParallelForDirective * D)7496 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7497 OMPTargetParallelForDirective *D) {
7498 DeclarationNameInfo DirName;
7499 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7500 nullptr, D->getLocStart());
7501 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7502 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7503 return Res;
7504 }
7505
7506 template <typename Derived>
TransformOMPTargetUpdateDirective(OMPTargetUpdateDirective * D)7507 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7508 OMPTargetUpdateDirective *D) {
7509 DeclarationNameInfo DirName;
7510 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7511 nullptr, D->getLocStart());
7512 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7513 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7514 return Res;
7515 }
7516
7517 template <typename Derived>
7518 StmtResult
TransformOMPTeamsDirective(OMPTeamsDirective * D)7519 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7520 DeclarationNameInfo DirName;
7521 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7522 D->getLocStart());
7523 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7524 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7525 return Res;
7526 }
7527
7528 template <typename Derived>
TransformOMPCancellationPointDirective(OMPCancellationPointDirective * D)7529 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7530 OMPCancellationPointDirective *D) {
7531 DeclarationNameInfo DirName;
7532 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7533 nullptr, D->getLocStart());
7534 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7535 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7536 return Res;
7537 }
7538
7539 template <typename Derived>
7540 StmtResult
TransformOMPCancelDirective(OMPCancelDirective * D)7541 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7542 DeclarationNameInfo DirName;
7543 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7544 D->getLocStart());
7545 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7546 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7547 return Res;
7548 }
7549
7550 template <typename Derived>
7551 StmtResult
TransformOMPTaskLoopDirective(OMPTaskLoopDirective * D)7552 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7553 DeclarationNameInfo DirName;
7554 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7555 D->getLocStart());
7556 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7557 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7558 return Res;
7559 }
7560
7561 template <typename Derived>
TransformOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective * D)7562 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7563 OMPTaskLoopSimdDirective *D) {
7564 DeclarationNameInfo DirName;
7565 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7566 nullptr, D->getLocStart());
7567 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7568 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7569 return Res;
7570 }
7571
7572 template <typename Derived>
TransformOMPDistributeDirective(OMPDistributeDirective * D)7573 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7574 OMPDistributeDirective *D) {
7575 DeclarationNameInfo DirName;
7576 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7577 D->getLocStart());
7578 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7579 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7580 return Res;
7581 }
7582
7583 template <typename Derived>
TransformOMPDistributeParallelForDirective(OMPDistributeParallelForDirective * D)7584 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7585 OMPDistributeParallelForDirective *D) {
7586 DeclarationNameInfo DirName;
7587 getDerived().getSema().StartOpenMPDSABlock(
7588 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7589 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7590 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7591 return Res;
7592 }
7593
7594 template <typename Derived>
7595 StmtResult
TransformOMPDistributeParallelForSimdDirective(OMPDistributeParallelForSimdDirective * D)7596 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7597 OMPDistributeParallelForSimdDirective *D) {
7598 DeclarationNameInfo DirName;
7599 getDerived().getSema().StartOpenMPDSABlock(
7600 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7601 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7602 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7603 return Res;
7604 }
7605
7606 template <typename Derived>
TransformOMPDistributeSimdDirective(OMPDistributeSimdDirective * D)7607 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7608 OMPDistributeSimdDirective *D) {
7609 DeclarationNameInfo DirName;
7610 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7611 nullptr, D->getLocStart());
7612 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7613 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7614 return Res;
7615 }
7616
7617 template <typename Derived>
TransformOMPTargetParallelForSimdDirective(OMPTargetParallelForSimdDirective * D)7618 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7619 OMPTargetParallelForSimdDirective *D) {
7620 DeclarationNameInfo DirName;
7621 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7622 DirName, nullptr,
7623 D->getLocStart());
7624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7625 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7626 return Res;
7627 }
7628
7629 //===----------------------------------------------------------------------===//
7630 // OpenMP clause transformation
7631 //===----------------------------------------------------------------------===//
7632 template <typename Derived>
TransformOMPIfClause(OMPIfClause * C)7633 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
7634 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7635 if (Cond.isInvalid())
7636 return nullptr;
7637 return getDerived().RebuildOMPIfClause(
7638 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7639 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
7640 }
7641
7642 template <typename Derived>
TransformOMPFinalClause(OMPFinalClause * C)7643 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7644 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7645 if (Cond.isInvalid())
7646 return nullptr;
7647 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7648 C->getLParenLoc(), C->getLocEnd());
7649 }
7650
7651 template <typename Derived>
7652 OMPClause *
TransformOMPNumThreadsClause(OMPNumThreadsClause * C)7653 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7654 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7655 if (NumThreads.isInvalid())
7656 return nullptr;
7657 return getDerived().RebuildOMPNumThreadsClause(
7658 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7659 }
7660
7661 template <typename Derived>
7662 OMPClause *
TransformOMPSafelenClause(OMPSafelenClause * C)7663 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7664 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7665 if (E.isInvalid())
7666 return nullptr;
7667 return getDerived().RebuildOMPSafelenClause(
7668 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7669 }
7670
7671 template <typename Derived>
7672 OMPClause *
TransformOMPSimdlenClause(OMPSimdlenClause * C)7673 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7674 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7675 if (E.isInvalid())
7676 return nullptr;
7677 return getDerived().RebuildOMPSimdlenClause(
7678 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7679 }
7680
7681 template <typename Derived>
7682 OMPClause *
TransformOMPCollapseClause(OMPCollapseClause * C)7683 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7684 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7685 if (E.isInvalid())
7686 return nullptr;
7687 return getDerived().RebuildOMPCollapseClause(
7688 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7689 }
7690
7691 template <typename Derived>
7692 OMPClause *
TransformOMPDefaultClause(OMPDefaultClause * C)7693 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
7694 return getDerived().RebuildOMPDefaultClause(
7695 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7696 C->getLParenLoc(), C->getLocEnd());
7697 }
7698
7699 template <typename Derived>
7700 OMPClause *
TransformOMPProcBindClause(OMPProcBindClause * C)7701 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
7702 return getDerived().RebuildOMPProcBindClause(
7703 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7704 C->getLParenLoc(), C->getLocEnd());
7705 }
7706
7707 template <typename Derived>
7708 OMPClause *
TransformOMPScheduleClause(OMPScheduleClause * C)7709 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7710 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7711 if (E.isInvalid())
7712 return nullptr;
7713 return getDerived().RebuildOMPScheduleClause(
7714 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
7715 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7716 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
7717 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7718 }
7719
7720 template <typename Derived>
7721 OMPClause *
TransformOMPOrderedClause(OMPOrderedClause * C)7722 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7723 ExprResult E;
7724 if (auto *Num = C->getNumForLoops()) {
7725 E = getDerived().TransformExpr(Num);
7726 if (E.isInvalid())
7727 return nullptr;
7728 }
7729 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7730 C->getLParenLoc(), E.get());
7731 }
7732
7733 template <typename Derived>
7734 OMPClause *
TransformOMPNowaitClause(OMPNowaitClause * C)7735 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7736 // No need to rebuild this clause, no template-dependent parameters.
7737 return C;
7738 }
7739
7740 template <typename Derived>
7741 OMPClause *
TransformOMPUntiedClause(OMPUntiedClause * C)7742 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7743 // No need to rebuild this clause, no template-dependent parameters.
7744 return C;
7745 }
7746
7747 template <typename Derived>
7748 OMPClause *
TransformOMPMergeableClause(OMPMergeableClause * C)7749 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7750 // No need to rebuild this clause, no template-dependent parameters.
7751 return C;
7752 }
7753
7754 template <typename Derived>
TransformOMPReadClause(OMPReadClause * C)7755 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7756 // No need to rebuild this clause, no template-dependent parameters.
7757 return C;
7758 }
7759
7760 template <typename Derived>
TransformOMPWriteClause(OMPWriteClause * C)7761 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7762 // No need to rebuild this clause, no template-dependent parameters.
7763 return C;
7764 }
7765
7766 template <typename Derived>
7767 OMPClause *
TransformOMPUpdateClause(OMPUpdateClause * C)7768 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7769 // No need to rebuild this clause, no template-dependent parameters.
7770 return C;
7771 }
7772
7773 template <typename Derived>
7774 OMPClause *
TransformOMPCaptureClause(OMPCaptureClause * C)7775 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7776 // No need to rebuild this clause, no template-dependent parameters.
7777 return C;
7778 }
7779
7780 template <typename Derived>
7781 OMPClause *
TransformOMPSeqCstClause(OMPSeqCstClause * C)7782 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7783 // No need to rebuild this clause, no template-dependent parameters.
7784 return C;
7785 }
7786
7787 template <typename Derived>
7788 OMPClause *
TransformOMPThreadsClause(OMPThreadsClause * C)7789 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7790 // No need to rebuild this clause, no template-dependent parameters.
7791 return C;
7792 }
7793
7794 template <typename Derived>
TransformOMPSIMDClause(OMPSIMDClause * C)7795 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7796 // No need to rebuild this clause, no template-dependent parameters.
7797 return C;
7798 }
7799
7800 template <typename Derived>
7801 OMPClause *
TransformOMPNogroupClause(OMPNogroupClause * C)7802 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7803 // No need to rebuild this clause, no template-dependent parameters.
7804 return C;
7805 }
7806
7807 template <typename Derived>
7808 OMPClause *
TransformOMPPrivateClause(OMPPrivateClause * C)7809 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
7810 llvm::SmallVector<Expr *, 16> Vars;
7811 Vars.reserve(C->varlist_size());
7812 for (auto *VE : C->varlists()) {
7813 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7814 if (EVar.isInvalid())
7815 return nullptr;
7816 Vars.push_back(EVar.get());
7817 }
7818 return getDerived().RebuildOMPPrivateClause(
7819 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7820 }
7821
7822 template <typename Derived>
TransformOMPFirstprivateClause(OMPFirstprivateClause * C)7823 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7824 OMPFirstprivateClause *C) {
7825 llvm::SmallVector<Expr *, 16> Vars;
7826 Vars.reserve(C->varlist_size());
7827 for (auto *VE : C->varlists()) {
7828 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7829 if (EVar.isInvalid())
7830 return nullptr;
7831 Vars.push_back(EVar.get());
7832 }
7833 return getDerived().RebuildOMPFirstprivateClause(
7834 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7835 }
7836
7837 template <typename Derived>
7838 OMPClause *
TransformOMPLastprivateClause(OMPLastprivateClause * C)7839 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7840 llvm::SmallVector<Expr *, 16> Vars;
7841 Vars.reserve(C->varlist_size());
7842 for (auto *VE : C->varlists()) {
7843 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7844 if (EVar.isInvalid())
7845 return nullptr;
7846 Vars.push_back(EVar.get());
7847 }
7848 return getDerived().RebuildOMPLastprivateClause(
7849 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7850 }
7851
7852 template <typename Derived>
7853 OMPClause *
TransformOMPSharedClause(OMPSharedClause * C)7854 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7855 llvm::SmallVector<Expr *, 16> Vars;
7856 Vars.reserve(C->varlist_size());
7857 for (auto *VE : C->varlists()) {
7858 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7859 if (EVar.isInvalid())
7860 return nullptr;
7861 Vars.push_back(EVar.get());
7862 }
7863 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7864 C->getLParenLoc(), C->getLocEnd());
7865 }
7866
7867 template <typename Derived>
7868 OMPClause *
TransformOMPReductionClause(OMPReductionClause * C)7869 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7870 llvm::SmallVector<Expr *, 16> Vars;
7871 Vars.reserve(C->varlist_size());
7872 for (auto *VE : C->varlists()) {
7873 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7874 if (EVar.isInvalid())
7875 return nullptr;
7876 Vars.push_back(EVar.get());
7877 }
7878 CXXScopeSpec ReductionIdScopeSpec;
7879 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7880
7881 DeclarationNameInfo NameInfo = C->getNameInfo();
7882 if (NameInfo.getName()) {
7883 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7884 if (!NameInfo.getName())
7885 return nullptr;
7886 }
7887 // Build a list of all UDR decls with the same names ranged by the Scopes.
7888 // The Scope boundary is a duplication of the previous decl.
7889 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7890 for (auto *E : C->reduction_ops()) {
7891 // Transform all the decls.
7892 if (E) {
7893 auto *ULE = cast<UnresolvedLookupExpr>(E);
7894 UnresolvedSet<8> Decls;
7895 for (auto *D : ULE->decls()) {
7896 NamedDecl *InstD =
7897 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7898 Decls.addDecl(InstD, InstD->getAccess());
7899 }
7900 UnresolvedReductions.push_back(
7901 UnresolvedLookupExpr::Create(
7902 SemaRef.Context, /*NamingClass=*/nullptr,
7903 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7904 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7905 Decls.begin(), Decls.end()));
7906 } else
7907 UnresolvedReductions.push_back(nullptr);
7908 }
7909 return getDerived().RebuildOMPReductionClause(
7910 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7911 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
7912 }
7913
7914 template <typename Derived>
7915 OMPClause *
TransformOMPLinearClause(OMPLinearClause * C)7916 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7917 llvm::SmallVector<Expr *, 16> Vars;
7918 Vars.reserve(C->varlist_size());
7919 for (auto *VE : C->varlists()) {
7920 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7921 if (EVar.isInvalid())
7922 return nullptr;
7923 Vars.push_back(EVar.get());
7924 }
7925 ExprResult Step = getDerived().TransformExpr(C->getStep());
7926 if (Step.isInvalid())
7927 return nullptr;
7928 return getDerived().RebuildOMPLinearClause(
7929 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7930 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
7931 }
7932
7933 template <typename Derived>
7934 OMPClause *
TransformOMPAlignedClause(OMPAlignedClause * C)7935 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7936 llvm::SmallVector<Expr *, 16> Vars;
7937 Vars.reserve(C->varlist_size());
7938 for (auto *VE : C->varlists()) {
7939 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7940 if (EVar.isInvalid())
7941 return nullptr;
7942 Vars.push_back(EVar.get());
7943 }
7944 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7945 if (Alignment.isInvalid())
7946 return nullptr;
7947 return getDerived().RebuildOMPAlignedClause(
7948 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7949 C->getColonLoc(), C->getLocEnd());
7950 }
7951
7952 template <typename Derived>
7953 OMPClause *
TransformOMPCopyinClause(OMPCopyinClause * C)7954 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7955 llvm::SmallVector<Expr *, 16> Vars;
7956 Vars.reserve(C->varlist_size());
7957 for (auto *VE : C->varlists()) {
7958 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7959 if (EVar.isInvalid())
7960 return nullptr;
7961 Vars.push_back(EVar.get());
7962 }
7963 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7964 C->getLParenLoc(), C->getLocEnd());
7965 }
7966
7967 template <typename Derived>
7968 OMPClause *
TransformOMPCopyprivateClause(OMPCopyprivateClause * C)7969 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7970 llvm::SmallVector<Expr *, 16> Vars;
7971 Vars.reserve(C->varlist_size());
7972 for (auto *VE : C->varlists()) {
7973 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7974 if (EVar.isInvalid())
7975 return nullptr;
7976 Vars.push_back(EVar.get());
7977 }
7978 return getDerived().RebuildOMPCopyprivateClause(
7979 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7980 }
7981
7982 template <typename Derived>
TransformOMPFlushClause(OMPFlushClause * C)7983 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7984 llvm::SmallVector<Expr *, 16> Vars;
7985 Vars.reserve(C->varlist_size());
7986 for (auto *VE : C->varlists()) {
7987 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7988 if (EVar.isInvalid())
7989 return nullptr;
7990 Vars.push_back(EVar.get());
7991 }
7992 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7993 C->getLParenLoc(), C->getLocEnd());
7994 }
7995
7996 template <typename Derived>
7997 OMPClause *
TransformOMPDependClause(OMPDependClause * C)7998 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7999 llvm::SmallVector<Expr *, 16> Vars;
8000 Vars.reserve(C->varlist_size());
8001 for (auto *VE : C->varlists()) {
8002 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8003 if (EVar.isInvalid())
8004 return nullptr;
8005 Vars.push_back(EVar.get());
8006 }
8007 return getDerived().RebuildOMPDependClause(
8008 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8009 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8010 }
8011
8012 template <typename Derived>
8013 OMPClause *
TransformOMPDeviceClause(OMPDeviceClause * C)8014 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8015 ExprResult E = getDerived().TransformExpr(C->getDevice());
8016 if (E.isInvalid())
8017 return nullptr;
8018 return getDerived().RebuildOMPDeviceClause(
8019 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8020 }
8021
8022 template <typename Derived>
TransformOMPMapClause(OMPMapClause * C)8023 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8024 llvm::SmallVector<Expr *, 16> Vars;
8025 Vars.reserve(C->varlist_size());
8026 for (auto *VE : C->varlists()) {
8027 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8028 if (EVar.isInvalid())
8029 return nullptr;
8030 Vars.push_back(EVar.get());
8031 }
8032 return getDerived().RebuildOMPMapClause(
8033 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8034 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8035 C->getLParenLoc(), C->getLocEnd());
8036 }
8037
8038 template <typename Derived>
8039 OMPClause *
TransformOMPNumTeamsClause(OMPNumTeamsClause * C)8040 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8041 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8042 if (E.isInvalid())
8043 return nullptr;
8044 return getDerived().RebuildOMPNumTeamsClause(
8045 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8046 }
8047
8048 template <typename Derived>
8049 OMPClause *
TransformOMPThreadLimitClause(OMPThreadLimitClause * C)8050 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8051 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8052 if (E.isInvalid())
8053 return nullptr;
8054 return getDerived().RebuildOMPThreadLimitClause(
8055 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8056 }
8057
8058 template <typename Derived>
8059 OMPClause *
TransformOMPPriorityClause(OMPPriorityClause * C)8060 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8061 ExprResult E = getDerived().TransformExpr(C->getPriority());
8062 if (E.isInvalid())
8063 return nullptr;
8064 return getDerived().RebuildOMPPriorityClause(
8065 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8066 }
8067
8068 template <typename Derived>
8069 OMPClause *
TransformOMPGrainsizeClause(OMPGrainsizeClause * C)8070 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8071 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8072 if (E.isInvalid())
8073 return nullptr;
8074 return getDerived().RebuildOMPGrainsizeClause(
8075 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8076 }
8077
8078 template <typename Derived>
8079 OMPClause *
TransformOMPNumTasksClause(OMPNumTasksClause * C)8080 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8081 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8082 if (E.isInvalid())
8083 return nullptr;
8084 return getDerived().RebuildOMPNumTasksClause(
8085 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8086 }
8087
8088 template <typename Derived>
TransformOMPHintClause(OMPHintClause * C)8089 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8090 ExprResult E = getDerived().TransformExpr(C->getHint());
8091 if (E.isInvalid())
8092 return nullptr;
8093 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8094 C->getLParenLoc(), C->getLocEnd());
8095 }
8096
8097 template <typename Derived>
TransformOMPDistScheduleClause(OMPDistScheduleClause * C)8098 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8099 OMPDistScheduleClause *C) {
8100 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8101 if (E.isInvalid())
8102 return nullptr;
8103 return getDerived().RebuildOMPDistScheduleClause(
8104 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8105 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8106 }
8107
8108 template <typename Derived>
8109 OMPClause *
TransformOMPDefaultmapClause(OMPDefaultmapClause * C)8110 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8111 return C;
8112 }
8113
8114 template <typename Derived>
TransformOMPToClause(OMPToClause * C)8115 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8116 llvm::SmallVector<Expr *, 16> Vars;
8117 Vars.reserve(C->varlist_size());
8118 for (auto *VE : C->varlists()) {
8119 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8120 if (EVar.isInvalid())
8121 return 0;
8122 Vars.push_back(EVar.get());
8123 }
8124 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8125 C->getLParenLoc(), C->getLocEnd());
8126 }
8127
8128 template <typename Derived>
TransformOMPFromClause(OMPFromClause * C)8129 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8130 llvm::SmallVector<Expr *, 16> Vars;
8131 Vars.reserve(C->varlist_size());
8132 for (auto *VE : C->varlists()) {
8133 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8134 if (EVar.isInvalid())
8135 return 0;
8136 Vars.push_back(EVar.get());
8137 }
8138 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8139 C->getLParenLoc(), C->getLocEnd());
8140 }
8141
8142 template <typename Derived>
TransformOMPUseDevicePtrClause(OMPUseDevicePtrClause * C)8143 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8144 OMPUseDevicePtrClause *C) {
8145 llvm::SmallVector<Expr *, 16> Vars;
8146 Vars.reserve(C->varlist_size());
8147 for (auto *VE : C->varlists()) {
8148 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8149 if (EVar.isInvalid())
8150 return nullptr;
8151 Vars.push_back(EVar.get());
8152 }
8153 return getDerived().RebuildOMPUseDevicePtrClause(
8154 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8155 }
8156
8157 template <typename Derived>
8158 OMPClause *
TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause * C)8159 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8160 llvm::SmallVector<Expr *, 16> Vars;
8161 Vars.reserve(C->varlist_size());
8162 for (auto *VE : C->varlists()) {
8163 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8164 if (EVar.isInvalid())
8165 return nullptr;
8166 Vars.push_back(EVar.get());
8167 }
8168 return getDerived().RebuildOMPIsDevicePtrClause(
8169 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8170 }
8171
8172 //===----------------------------------------------------------------------===//
8173 // Expression transformation
8174 //===----------------------------------------------------------------------===//
8175 template<typename Derived>
8176 ExprResult
TransformPredefinedExpr(PredefinedExpr * E)8177 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8178 if (!E->isTypeDependent())
8179 return E;
8180
8181 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8182 E->getIdentType());
8183 }
8184
8185 template<typename Derived>
8186 ExprResult
TransformDeclRefExpr(DeclRefExpr * E)8187 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8188 NestedNameSpecifierLoc QualifierLoc;
8189 if (E->getQualifierLoc()) {
8190 QualifierLoc
8191 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8192 if (!QualifierLoc)
8193 return ExprError();
8194 }
8195
8196 ValueDecl *ND
8197 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8198 E->getDecl()));
8199 if (!ND)
8200 return ExprError();
8201
8202 DeclarationNameInfo NameInfo = E->getNameInfo();
8203 if (NameInfo.getName()) {
8204 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8205 if (!NameInfo.getName())
8206 return ExprError();
8207 }
8208
8209 if (!getDerived().AlwaysRebuild() &&
8210 QualifierLoc == E->getQualifierLoc() &&
8211 ND == E->getDecl() &&
8212 NameInfo.getName() == E->getDecl()->getDeclName() &&
8213 !E->hasExplicitTemplateArgs()) {
8214
8215 // Mark it referenced in the new context regardless.
8216 // FIXME: this is a bit instantiation-specific.
8217 SemaRef.MarkDeclRefReferenced(E);
8218
8219 return E;
8220 }
8221
8222 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8223 if (E->hasExplicitTemplateArgs()) {
8224 TemplateArgs = &TransArgs;
8225 TransArgs.setLAngleLoc(E->getLAngleLoc());
8226 TransArgs.setRAngleLoc(E->getRAngleLoc());
8227 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8228 E->getNumTemplateArgs(),
8229 TransArgs))
8230 return ExprError();
8231 }
8232
8233 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8234 TemplateArgs);
8235 }
8236
8237 template<typename Derived>
8238 ExprResult
TransformIntegerLiteral(IntegerLiteral * E)8239 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8240 return E;
8241 }
8242
8243 template<typename Derived>
8244 ExprResult
TransformFloatingLiteral(FloatingLiteral * E)8245 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8246 return E;
8247 }
8248
8249 template<typename Derived>
8250 ExprResult
TransformImaginaryLiteral(ImaginaryLiteral * E)8251 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8252 return E;
8253 }
8254
8255 template<typename Derived>
8256 ExprResult
TransformStringLiteral(StringLiteral * E)8257 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8258 return E;
8259 }
8260
8261 template<typename Derived>
8262 ExprResult
TransformCharacterLiteral(CharacterLiteral * E)8263 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8264 return E;
8265 }
8266
8267 template<typename Derived>
8268 ExprResult
TransformUserDefinedLiteral(UserDefinedLiteral * E)8269 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8270 if (FunctionDecl *FD = E->getDirectCallee())
8271 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8272 return SemaRef.MaybeBindToTemporary(E);
8273 }
8274
8275 template<typename Derived>
8276 ExprResult
TransformGenericSelectionExpr(GenericSelectionExpr * E)8277 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8278 ExprResult ControllingExpr =
8279 getDerived().TransformExpr(E->getControllingExpr());
8280 if (ControllingExpr.isInvalid())
8281 return ExprError();
8282
8283 SmallVector<Expr *, 4> AssocExprs;
8284 SmallVector<TypeSourceInfo *, 4> AssocTypes;
8285 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8286 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8287 if (TS) {
8288 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8289 if (!AssocType)
8290 return ExprError();
8291 AssocTypes.push_back(AssocType);
8292 } else {
8293 AssocTypes.push_back(nullptr);
8294 }
8295
8296 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8297 if (AssocExpr.isInvalid())
8298 return ExprError();
8299 AssocExprs.push_back(AssocExpr.get());
8300 }
8301
8302 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8303 E->getDefaultLoc(),
8304 E->getRParenLoc(),
8305 ControllingExpr.get(),
8306 AssocTypes,
8307 AssocExprs);
8308 }
8309
8310 template<typename Derived>
8311 ExprResult
TransformParenExpr(ParenExpr * E)8312 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8313 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8314 if (SubExpr.isInvalid())
8315 return ExprError();
8316
8317 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8318 return E;
8319
8320 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8321 E->getRParen());
8322 }
8323
8324 /// \brief The operand of a unary address-of operator has special rules: it's
8325 /// allowed to refer to a non-static member of a class even if there's no 'this'
8326 /// object available.
8327 template<typename Derived>
8328 ExprResult
TransformAddressOfOperand(Expr * E)8329 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8330 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8331 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8332 else
8333 return getDerived().TransformExpr(E);
8334 }
8335
8336 template<typename Derived>
8337 ExprResult
TransformUnaryOperator(UnaryOperator * E)8338 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
8339 ExprResult SubExpr;
8340 if (E->getOpcode() == UO_AddrOf)
8341 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8342 else
8343 SubExpr = TransformExpr(E->getSubExpr());
8344 if (SubExpr.isInvalid())
8345 return ExprError();
8346
8347 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8348 return E;
8349
8350 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8351 E->getOpcode(),
8352 SubExpr.get());
8353 }
8354
8355 template<typename Derived>
8356 ExprResult
TransformOffsetOfExpr(OffsetOfExpr * E)8357 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8358 // Transform the type.
8359 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8360 if (!Type)
8361 return ExprError();
8362
8363 // Transform all of the components into components similar to what the
8364 // parser uses.
8365 // FIXME: It would be slightly more efficient in the non-dependent case to
8366 // just map FieldDecls, rather than requiring the rebuilder to look for
8367 // the fields again. However, __builtin_offsetof is rare enough in
8368 // template code that we don't care.
8369 bool ExprChanged = false;
8370 typedef Sema::OffsetOfComponent Component;
8371 SmallVector<Component, 4> Components;
8372 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8373 const OffsetOfNode &ON = E->getComponent(I);
8374 Component Comp;
8375 Comp.isBrackets = true;
8376 Comp.LocStart = ON.getSourceRange().getBegin();
8377 Comp.LocEnd = ON.getSourceRange().getEnd();
8378 switch (ON.getKind()) {
8379 case OffsetOfNode::Array: {
8380 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8381 ExprResult Index = getDerived().TransformExpr(FromIndex);
8382 if (Index.isInvalid())
8383 return ExprError();
8384
8385 ExprChanged = ExprChanged || Index.get() != FromIndex;
8386 Comp.isBrackets = true;
8387 Comp.U.E = Index.get();
8388 break;
8389 }
8390
8391 case OffsetOfNode::Field:
8392 case OffsetOfNode::Identifier:
8393 Comp.isBrackets = false;
8394 Comp.U.IdentInfo = ON.getFieldName();
8395 if (!Comp.U.IdentInfo)
8396 continue;
8397
8398 break;
8399
8400 case OffsetOfNode::Base:
8401 // Will be recomputed during the rebuild.
8402 continue;
8403 }
8404
8405 Components.push_back(Comp);
8406 }
8407
8408 // If nothing changed, retain the existing expression.
8409 if (!getDerived().AlwaysRebuild() &&
8410 Type == E->getTypeSourceInfo() &&
8411 !ExprChanged)
8412 return E;
8413
8414 // Build a new offsetof expression.
8415 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8416 Components, E->getRParenLoc());
8417 }
8418
8419 template<typename Derived>
8420 ExprResult
TransformOpaqueValueExpr(OpaqueValueExpr * E)8421 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8422 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8423 "opaque value expression requires transformation");
8424 return E;
8425 }
8426
8427 template<typename Derived>
8428 ExprResult
TransformTypoExpr(TypoExpr * E)8429 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8430 return E;
8431 }
8432
8433 template<typename Derived>
8434 ExprResult
TransformPseudoObjectExpr(PseudoObjectExpr * E)8435 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8436 // Rebuild the syntactic form. The original syntactic form has
8437 // opaque-value expressions in it, so strip those away and rebuild
8438 // the result. This is a really awful way of doing this, but the
8439 // better solution (rebuilding the semantic expressions and
8440 // rebinding OVEs as necessary) doesn't work; we'd need
8441 // TreeTransform to not strip away implicit conversions.
8442 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8443 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8444 if (result.isInvalid()) return ExprError();
8445
8446 // If that gives us a pseudo-object result back, the pseudo-object
8447 // expression must have been an lvalue-to-rvalue conversion which we
8448 // should reapply.
8449 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8450 result = SemaRef.checkPseudoObjectRValue(result.get());
8451
8452 return result;
8453 }
8454
8455 template<typename Derived>
8456 ExprResult
TransformUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * E)8457 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8458 UnaryExprOrTypeTraitExpr *E) {
8459 if (E->isArgumentType()) {
8460 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
8461
8462 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8463 if (!NewT)
8464 return ExprError();
8465
8466 if (!getDerived().AlwaysRebuild() && OldT == NewT)
8467 return E;
8468
8469 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8470 E->getKind(),
8471 E->getSourceRange());
8472 }
8473
8474 // C++0x [expr.sizeof]p1:
8475 // The operand is either an expression, which is an unevaluated operand
8476 // [...]
8477 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8478 Sema::ReuseLambdaContextDecl);
8479
8480 // Try to recover if we have something like sizeof(T::X) where X is a type.
8481 // Notably, there must be *exactly* one set of parens if X is a type.
8482 TypeSourceInfo *RecoveryTSI = nullptr;
8483 ExprResult SubExpr;
8484 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8485 if (auto *DRE =
8486 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8487 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8488 PE, DRE, false, &RecoveryTSI);
8489 else
8490 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8491
8492 if (RecoveryTSI) {
8493 return getDerived().RebuildUnaryExprOrTypeTrait(
8494 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8495 } else if (SubExpr.isInvalid())
8496 return ExprError();
8497
8498 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
8499 return E;
8500
8501 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8502 E->getOperatorLoc(),
8503 E->getKind(),
8504 E->getSourceRange());
8505 }
8506
8507 template<typename Derived>
8508 ExprResult
TransformArraySubscriptExpr(ArraySubscriptExpr * E)8509 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
8510 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8511 if (LHS.isInvalid())
8512 return ExprError();
8513
8514 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8515 if (RHS.isInvalid())
8516 return ExprError();
8517
8518
8519 if (!getDerived().AlwaysRebuild() &&
8520 LHS.get() == E->getLHS() &&
8521 RHS.get() == E->getRHS())
8522 return E;
8523
8524 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
8525 /*FIXME:*/E->getLHS()->getLocStart(),
8526 RHS.get(),
8527 E->getRBracketLoc());
8528 }
8529
8530 template <typename Derived>
8531 ExprResult
TransformOMPArraySectionExpr(OMPArraySectionExpr * E)8532 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8533 ExprResult Base = getDerived().TransformExpr(E->getBase());
8534 if (Base.isInvalid())
8535 return ExprError();
8536
8537 ExprResult LowerBound;
8538 if (E->getLowerBound()) {
8539 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8540 if (LowerBound.isInvalid())
8541 return ExprError();
8542 }
8543
8544 ExprResult Length;
8545 if (E->getLength()) {
8546 Length = getDerived().TransformExpr(E->getLength());
8547 if (Length.isInvalid())
8548 return ExprError();
8549 }
8550
8551 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8552 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8553 return E;
8554
8555 return getDerived().RebuildOMPArraySectionExpr(
8556 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8557 Length.get(), E->getRBracketLoc());
8558 }
8559
8560 template<typename Derived>
8561 ExprResult
TransformCallExpr(CallExpr * E)8562 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
8563 // Transform the callee.
8564 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8565 if (Callee.isInvalid())
8566 return ExprError();
8567
8568 // Transform arguments.
8569 bool ArgChanged = false;
8570 SmallVector<Expr*, 8> Args;
8571 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8572 &ArgChanged))
8573 return ExprError();
8574
8575 if (!getDerived().AlwaysRebuild() &&
8576 Callee.get() == E->getCallee() &&
8577 !ArgChanged)
8578 return SemaRef.MaybeBindToTemporary(E);
8579
8580 // FIXME: Wrong source location information for the '('.
8581 SourceLocation FakeLParenLoc
8582 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8583 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
8584 Args,
8585 E->getRParenLoc());
8586 }
8587
8588 template<typename Derived>
8589 ExprResult
TransformMemberExpr(MemberExpr * E)8590 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
8591 ExprResult Base = getDerived().TransformExpr(E->getBase());
8592 if (Base.isInvalid())
8593 return ExprError();
8594
8595 NestedNameSpecifierLoc QualifierLoc;
8596 if (E->hasQualifier()) {
8597 QualifierLoc
8598 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8599
8600 if (!QualifierLoc)
8601 return ExprError();
8602 }
8603 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8604
8605 ValueDecl *Member
8606 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8607 E->getMemberDecl()));
8608 if (!Member)
8609 return ExprError();
8610
8611 NamedDecl *FoundDecl = E->getFoundDecl();
8612 if (FoundDecl == E->getMemberDecl()) {
8613 FoundDecl = Member;
8614 } else {
8615 FoundDecl = cast_or_null<NamedDecl>(
8616 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8617 if (!FoundDecl)
8618 return ExprError();
8619 }
8620
8621 if (!getDerived().AlwaysRebuild() &&
8622 Base.get() == E->getBase() &&
8623 QualifierLoc == E->getQualifierLoc() &&
8624 Member == E->getMemberDecl() &&
8625 FoundDecl == E->getFoundDecl() &&
8626 !E->hasExplicitTemplateArgs()) {
8627
8628 // Mark it referenced in the new context regardless.
8629 // FIXME: this is a bit instantiation-specific.
8630 SemaRef.MarkMemberReferenced(E);
8631
8632 return E;
8633 }
8634
8635 TemplateArgumentListInfo TransArgs;
8636 if (E->hasExplicitTemplateArgs()) {
8637 TransArgs.setLAngleLoc(E->getLAngleLoc());
8638 TransArgs.setRAngleLoc(E->getRAngleLoc());
8639 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8640 E->getNumTemplateArgs(),
8641 TransArgs))
8642 return ExprError();
8643 }
8644
8645 // FIXME: Bogus source location for the operator
8646 SourceLocation FakeOperatorLoc =
8647 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
8648
8649 // FIXME: to do this check properly, we will need to preserve the
8650 // first-qualifier-in-scope here, just in case we had a dependent
8651 // base (and therefore couldn't do the check) and a
8652 // nested-name-qualifier (and therefore could do the lookup).
8653 NamedDecl *FirstQualifierInScope = nullptr;
8654
8655 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
8656 E->isArrow(),
8657 QualifierLoc,
8658 TemplateKWLoc,
8659 E->getMemberNameInfo(),
8660 Member,
8661 FoundDecl,
8662 (E->hasExplicitTemplateArgs()
8663 ? &TransArgs : nullptr),
8664 FirstQualifierInScope);
8665 }
8666
8667 template<typename Derived>
8668 ExprResult
TransformBinaryOperator(BinaryOperator * E)8669 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
8670 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8671 if (LHS.isInvalid())
8672 return ExprError();
8673
8674 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8675 if (RHS.isInvalid())
8676 return ExprError();
8677
8678 if (!getDerived().AlwaysRebuild() &&
8679 LHS.get() == E->getLHS() &&
8680 RHS.get() == E->getRHS())
8681 return E;
8682
8683 Sema::FPContractStateRAII FPContractState(getSema());
8684 getSema().FPFeatures.fp_contract = E->isFPContractable();
8685
8686 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
8687 LHS.get(), RHS.get());
8688 }
8689
8690 template<typename Derived>
8691 ExprResult
TransformCompoundAssignOperator(CompoundAssignOperator * E)8692 TreeTransform<Derived>::TransformCompoundAssignOperator(
8693 CompoundAssignOperator *E) {
8694 return getDerived().TransformBinaryOperator(E);
8695 }
8696
8697 template<typename Derived>
8698 ExprResult TreeTransform<Derived>::
TransformBinaryConditionalOperator(BinaryConditionalOperator * e)8699 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8700 // Just rebuild the common and RHS expressions and see whether we
8701 // get any changes.
8702
8703 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8704 if (commonExpr.isInvalid())
8705 return ExprError();
8706
8707 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8708 if (rhs.isInvalid())
8709 return ExprError();
8710
8711 if (!getDerived().AlwaysRebuild() &&
8712 commonExpr.get() == e->getCommon() &&
8713 rhs.get() == e->getFalseExpr())
8714 return e;
8715
8716 return getDerived().RebuildConditionalOperator(commonExpr.get(),
8717 e->getQuestionLoc(),
8718 nullptr,
8719 e->getColonLoc(),
8720 rhs.get());
8721 }
8722
8723 template<typename Derived>
8724 ExprResult
TransformConditionalOperator(ConditionalOperator * E)8725 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
8726 ExprResult Cond = getDerived().TransformExpr(E->getCond());
8727 if (Cond.isInvalid())
8728 return ExprError();
8729
8730 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8731 if (LHS.isInvalid())
8732 return ExprError();
8733
8734 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8735 if (RHS.isInvalid())
8736 return ExprError();
8737
8738 if (!getDerived().AlwaysRebuild() &&
8739 Cond.get() == E->getCond() &&
8740 LHS.get() == E->getLHS() &&
8741 RHS.get() == E->getRHS())
8742 return E;
8743
8744 return getDerived().RebuildConditionalOperator(Cond.get(),
8745 E->getQuestionLoc(),
8746 LHS.get(),
8747 E->getColonLoc(),
8748 RHS.get());
8749 }
8750
8751 template<typename Derived>
8752 ExprResult
TransformImplicitCastExpr(ImplicitCastExpr * E)8753 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
8754 // Implicit casts are eliminated during transformation, since they
8755 // will be recomputed by semantic analysis after transformation.
8756 return getDerived().TransformExpr(E->getSubExprAsWritten());
8757 }
8758
8759 template<typename Derived>
8760 ExprResult
TransformCStyleCastExpr(CStyleCastExpr * E)8761 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
8762 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8763 if (!Type)
8764 return ExprError();
8765
8766 ExprResult SubExpr
8767 = getDerived().TransformExpr(E->getSubExprAsWritten());
8768 if (SubExpr.isInvalid())
8769 return ExprError();
8770
8771 if (!getDerived().AlwaysRebuild() &&
8772 Type == E->getTypeInfoAsWritten() &&
8773 SubExpr.get() == E->getSubExpr())
8774 return E;
8775
8776 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
8777 Type,
8778 E->getRParenLoc(),
8779 SubExpr.get());
8780 }
8781
8782 template<typename Derived>
8783 ExprResult
TransformCompoundLiteralExpr(CompoundLiteralExpr * E)8784 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
8785 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8786 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8787 if (!NewT)
8788 return ExprError();
8789
8790 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
8791 if (Init.isInvalid())
8792 return ExprError();
8793
8794 if (!getDerived().AlwaysRebuild() &&
8795 OldT == NewT &&
8796 Init.get() == E->getInitializer())
8797 return SemaRef.MaybeBindToTemporary(E);
8798
8799 // Note: the expression type doesn't necessarily match the
8800 // type-as-written, but that's okay, because it should always be
8801 // derivable from the initializer.
8802
8803 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
8804 /*FIXME:*/E->getInitializer()->getLocEnd(),
8805 Init.get());
8806 }
8807
8808 template<typename Derived>
8809 ExprResult
TransformExtVectorElementExpr(ExtVectorElementExpr * E)8810 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
8811 ExprResult Base = getDerived().TransformExpr(E->getBase());
8812 if (Base.isInvalid())
8813 return ExprError();
8814
8815 if (!getDerived().AlwaysRebuild() &&
8816 Base.get() == E->getBase())
8817 return E;
8818
8819 // FIXME: Bad source location
8820 SourceLocation FakeOperatorLoc =
8821 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
8822 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
8823 E->getAccessorLoc(),
8824 E->getAccessor());
8825 }
8826
8827 template<typename Derived>
8828 ExprResult
TransformInitListExpr(InitListExpr * E)8829 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
8830 if (InitListExpr *Syntactic = E->getSyntacticForm())
8831 E = Syntactic;
8832
8833 bool InitChanged = false;
8834
8835 SmallVector<Expr*, 4> Inits;
8836 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
8837 Inits, &InitChanged))
8838 return ExprError();
8839
8840 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8841 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8842 // in some cases. We can't reuse it in general, because the syntactic and
8843 // semantic forms are linked, and we can't know that semantic form will
8844 // match even if the syntactic form does.
8845 }
8846
8847 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
8848 E->getRBraceLoc(), E->getType());
8849 }
8850
8851 template<typename Derived>
8852 ExprResult
TransformDesignatedInitExpr(DesignatedInitExpr * E)8853 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
8854 Designation Desig;
8855
8856 // transform the initializer value
8857 ExprResult Init = getDerived().TransformExpr(E->getInit());
8858 if (Init.isInvalid())
8859 return ExprError();
8860
8861 // transform the designators.
8862 SmallVector<Expr*, 4> ArrayExprs;
8863 bool ExprChanged = false;
8864 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8865 if (D.isFieldDesignator()) {
8866 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8867 D.getDotLoc(),
8868 D.getFieldLoc()));
8869 continue;
8870 }
8871
8872 if (D.isArrayDesignator()) {
8873 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
8874 if (Index.isInvalid())
8875 return ExprError();
8876
8877 Desig.AddDesignator(
8878 Designator::getArray(Index.get(), D.getLBracketLoc()));
8879
8880 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
8881 ArrayExprs.push_back(Index.get());
8882 continue;
8883 }
8884
8885 assert(D.isArrayRangeDesignator() && "New kind of designator?");
8886 ExprResult Start
8887 = getDerived().TransformExpr(E->getArrayRangeStart(D));
8888 if (Start.isInvalid())
8889 return ExprError();
8890
8891 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
8892 if (End.isInvalid())
8893 return ExprError();
8894
8895 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
8896 End.get(),
8897 D.getLBracketLoc(),
8898 D.getEllipsisLoc()));
8899
8900 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8901 End.get() != E->getArrayRangeEnd(D);
8902
8903 ArrayExprs.push_back(Start.get());
8904 ArrayExprs.push_back(End.get());
8905 }
8906
8907 if (!getDerived().AlwaysRebuild() &&
8908 Init.get() == E->getInit() &&
8909 !ExprChanged)
8910 return E;
8911
8912 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
8913 E->getEqualOrColonLoc(),
8914 E->usesGNUSyntax(), Init.get());
8915 }
8916
8917 // Seems that if TransformInitListExpr() only works on the syntactic form of an
8918 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8919 template<typename Derived>
8920 ExprResult
TransformDesignatedInitUpdateExpr(DesignatedInitUpdateExpr * E)8921 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8922 DesignatedInitUpdateExpr *E) {
8923 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8924 "initializer");
8925 return ExprError();
8926 }
8927
8928 template<typename Derived>
8929 ExprResult
TransformNoInitExpr(NoInitExpr * E)8930 TreeTransform<Derived>::TransformNoInitExpr(
8931 NoInitExpr *E) {
8932 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8933 return ExprError();
8934 }
8935
8936 template<typename Derived>
8937 ExprResult
TransformImplicitValueInitExpr(ImplicitValueInitExpr * E)8938 TreeTransform<Derived>::TransformImplicitValueInitExpr(
8939 ImplicitValueInitExpr *E) {
8940 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
8941
8942 // FIXME: Will we ever have proper type location here? Will we actually
8943 // need to transform the type?
8944 QualType T = getDerived().TransformType(E->getType());
8945 if (T.isNull())
8946 return ExprError();
8947
8948 if (!getDerived().AlwaysRebuild() &&
8949 T == E->getType())
8950 return E;
8951
8952 return getDerived().RebuildImplicitValueInitExpr(T);
8953 }
8954
8955 template<typename Derived>
8956 ExprResult
TransformVAArgExpr(VAArgExpr * E)8957 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
8958 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8959 if (!TInfo)
8960 return ExprError();
8961
8962 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8963 if (SubExpr.isInvalid())
8964 return ExprError();
8965
8966 if (!getDerived().AlwaysRebuild() &&
8967 TInfo == E->getWrittenTypeInfo() &&
8968 SubExpr.get() == E->getSubExpr())
8969 return E;
8970
8971 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
8972 TInfo, E->getRParenLoc());
8973 }
8974
8975 template<typename Derived>
8976 ExprResult
TransformParenListExpr(ParenListExpr * E)8977 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
8978 bool ArgumentChanged = false;
8979 SmallVector<Expr*, 4> Inits;
8980 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8981 &ArgumentChanged))
8982 return ExprError();
8983
8984 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
8985 Inits,
8986 E->getRParenLoc());
8987 }
8988
8989 /// \brief Transform an address-of-label expression.
8990 ///
8991 /// By default, the transformation of an address-of-label expression always
8992 /// rebuilds the expression, so that the label identifier can be resolved to
8993 /// the corresponding label statement by semantic analysis.
8994 template<typename Derived>
8995 ExprResult
TransformAddrLabelExpr(AddrLabelExpr * E)8996 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
8997 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8998 E->getLabel());
8999 if (!LD)
9000 return ExprError();
9001
9002 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9003 cast<LabelDecl>(LD));
9004 }
9005
9006 template<typename Derived>
9007 ExprResult
TransformStmtExpr(StmtExpr * E)9008 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9009 SemaRef.ActOnStartStmtExpr();
9010 StmtResult SubStmt
9011 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9012 if (SubStmt.isInvalid()) {
9013 SemaRef.ActOnStmtExprError();
9014 return ExprError();
9015 }
9016
9017 if (!getDerived().AlwaysRebuild() &&
9018 SubStmt.get() == E->getSubStmt()) {
9019 // Calling this an 'error' is unintuitive, but it does the right thing.
9020 SemaRef.ActOnStmtExprError();
9021 return SemaRef.MaybeBindToTemporary(E);
9022 }
9023
9024 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9025 SubStmt.get(),
9026 E->getRParenLoc());
9027 }
9028
9029 template<typename Derived>
9030 ExprResult
TransformChooseExpr(ChooseExpr * E)9031 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9032 ExprResult Cond = getDerived().TransformExpr(E->getCond());
9033 if (Cond.isInvalid())
9034 return ExprError();
9035
9036 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9037 if (LHS.isInvalid())
9038 return ExprError();
9039
9040 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9041 if (RHS.isInvalid())
9042 return ExprError();
9043
9044 if (!getDerived().AlwaysRebuild() &&
9045 Cond.get() == E->getCond() &&
9046 LHS.get() == E->getLHS() &&
9047 RHS.get() == E->getRHS())
9048 return E;
9049
9050 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9051 Cond.get(), LHS.get(), RHS.get(),
9052 E->getRParenLoc());
9053 }
9054
9055 template<typename Derived>
9056 ExprResult
TransformGNUNullExpr(GNUNullExpr * E)9057 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9058 return E;
9059 }
9060
9061 template<typename Derived>
9062 ExprResult
TransformCXXOperatorCallExpr(CXXOperatorCallExpr * E)9063 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9064 switch (E->getOperator()) {
9065 case OO_New:
9066 case OO_Delete:
9067 case OO_Array_New:
9068 case OO_Array_Delete:
9069 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9070
9071 case OO_Call: {
9072 // This is a call to an object's operator().
9073 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9074
9075 // Transform the object itself.
9076 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9077 if (Object.isInvalid())
9078 return ExprError();
9079
9080 // FIXME: Poor location information
9081 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9082 static_cast<Expr *>(Object.get())->getLocEnd());
9083
9084 // Transform the call arguments.
9085 SmallVector<Expr*, 8> Args;
9086 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9087 Args))
9088 return ExprError();
9089
9090 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9091 Args,
9092 E->getLocEnd());
9093 }
9094
9095 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9096 case OO_##Name:
9097 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9098 #include "clang/Basic/OperatorKinds.def"
9099 case OO_Subscript:
9100 // Handled below.
9101 break;
9102
9103 case OO_Conditional:
9104 llvm_unreachable("conditional operator is not actually overloadable");
9105
9106 case OO_None:
9107 case NUM_OVERLOADED_OPERATORS:
9108 llvm_unreachable("not an overloaded operator?");
9109 }
9110
9111 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9112 if (Callee.isInvalid())
9113 return ExprError();
9114
9115 ExprResult First;
9116 if (E->getOperator() == OO_Amp)
9117 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9118 else
9119 First = getDerived().TransformExpr(E->getArg(0));
9120 if (First.isInvalid())
9121 return ExprError();
9122
9123 ExprResult Second;
9124 if (E->getNumArgs() == 2) {
9125 Second = getDerived().TransformExpr(E->getArg(1));
9126 if (Second.isInvalid())
9127 return ExprError();
9128 }
9129
9130 if (!getDerived().AlwaysRebuild() &&
9131 Callee.get() == E->getCallee() &&
9132 First.get() == E->getArg(0) &&
9133 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9134 return SemaRef.MaybeBindToTemporary(E);
9135
9136 Sema::FPContractStateRAII FPContractState(getSema());
9137 getSema().FPFeatures.fp_contract = E->isFPContractable();
9138
9139 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9140 E->getOperatorLoc(),
9141 Callee.get(),
9142 First.get(),
9143 Second.get());
9144 }
9145
9146 template<typename Derived>
9147 ExprResult
TransformCXXMemberCallExpr(CXXMemberCallExpr * E)9148 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9149 return getDerived().TransformCallExpr(E);
9150 }
9151
9152 template<typename Derived>
9153 ExprResult
TransformCUDAKernelCallExpr(CUDAKernelCallExpr * E)9154 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9155 // Transform the callee.
9156 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9157 if (Callee.isInvalid())
9158 return ExprError();
9159
9160 // Transform exec config.
9161 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9162 if (EC.isInvalid())
9163 return ExprError();
9164
9165 // Transform arguments.
9166 bool ArgChanged = false;
9167 SmallVector<Expr*, 8> Args;
9168 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9169 &ArgChanged))
9170 return ExprError();
9171
9172 if (!getDerived().AlwaysRebuild() &&
9173 Callee.get() == E->getCallee() &&
9174 !ArgChanged)
9175 return SemaRef.MaybeBindToTemporary(E);
9176
9177 // FIXME: Wrong source location information for the '('.
9178 SourceLocation FakeLParenLoc
9179 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9180 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9181 Args,
9182 E->getRParenLoc(), EC.get());
9183 }
9184
9185 template<typename Derived>
9186 ExprResult
TransformCXXNamedCastExpr(CXXNamedCastExpr * E)9187 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
9188 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9189 if (!Type)
9190 return ExprError();
9191
9192 ExprResult SubExpr
9193 = getDerived().TransformExpr(E->getSubExprAsWritten());
9194 if (SubExpr.isInvalid())
9195 return ExprError();
9196
9197 if (!getDerived().AlwaysRebuild() &&
9198 Type == E->getTypeInfoAsWritten() &&
9199 SubExpr.get() == E->getSubExpr())
9200 return E;
9201 return getDerived().RebuildCXXNamedCastExpr(
9202 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9203 Type, E->getAngleBrackets().getEnd(),
9204 // FIXME. this should be '(' location
9205 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9206 }
9207
9208 template<typename Derived>
9209 ExprResult
TransformCXXStaticCastExpr(CXXStaticCastExpr * E)9210 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9211 return getDerived().TransformCXXNamedCastExpr(E);
9212 }
9213
9214 template<typename Derived>
9215 ExprResult
TransformCXXDynamicCastExpr(CXXDynamicCastExpr * E)9216 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9217 return getDerived().TransformCXXNamedCastExpr(E);
9218 }
9219
9220 template<typename Derived>
9221 ExprResult
TransformCXXReinterpretCastExpr(CXXReinterpretCastExpr * E)9222 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9223 CXXReinterpretCastExpr *E) {
9224 return getDerived().TransformCXXNamedCastExpr(E);
9225 }
9226
9227 template<typename Derived>
9228 ExprResult
TransformCXXConstCastExpr(CXXConstCastExpr * E)9229 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9230 return getDerived().TransformCXXNamedCastExpr(E);
9231 }
9232
9233 template<typename Derived>
9234 ExprResult
TransformCXXFunctionalCastExpr(CXXFunctionalCastExpr * E)9235 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9236 CXXFunctionalCastExpr *E) {
9237 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9238 if (!Type)
9239 return ExprError();
9240
9241 ExprResult SubExpr
9242 = getDerived().TransformExpr(E->getSubExprAsWritten());
9243 if (SubExpr.isInvalid())
9244 return ExprError();
9245
9246 if (!getDerived().AlwaysRebuild() &&
9247 Type == E->getTypeInfoAsWritten() &&
9248 SubExpr.get() == E->getSubExpr())
9249 return E;
9250
9251 return getDerived().RebuildCXXFunctionalCastExpr(Type,
9252 E->getLParenLoc(),
9253 SubExpr.get(),
9254 E->getRParenLoc());
9255 }
9256
9257 template<typename Derived>
9258 ExprResult
TransformCXXTypeidExpr(CXXTypeidExpr * E)9259 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9260 if (E->isTypeOperand()) {
9261 TypeSourceInfo *TInfo
9262 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9263 if (!TInfo)
9264 return ExprError();
9265
9266 if (!getDerived().AlwaysRebuild() &&
9267 TInfo == E->getTypeOperandSourceInfo())
9268 return E;
9269
9270 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9271 E->getLocStart(),
9272 TInfo,
9273 E->getLocEnd());
9274 }
9275
9276 // We don't know whether the subexpression is potentially evaluated until
9277 // after we perform semantic analysis. We speculatively assume it is
9278 // unevaluated; it will get fixed later if the subexpression is in fact
9279 // potentially evaluated.
9280 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9281 Sema::ReuseLambdaContextDecl);
9282
9283 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9284 if (SubExpr.isInvalid())
9285 return ExprError();
9286
9287 if (!getDerived().AlwaysRebuild() &&
9288 SubExpr.get() == E->getExprOperand())
9289 return E;
9290
9291 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9292 E->getLocStart(),
9293 SubExpr.get(),
9294 E->getLocEnd());
9295 }
9296
9297 template<typename Derived>
9298 ExprResult
TransformCXXUuidofExpr(CXXUuidofExpr * E)9299 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9300 if (E->isTypeOperand()) {
9301 TypeSourceInfo *TInfo
9302 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9303 if (!TInfo)
9304 return ExprError();
9305
9306 if (!getDerived().AlwaysRebuild() &&
9307 TInfo == E->getTypeOperandSourceInfo())
9308 return E;
9309
9310 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9311 E->getLocStart(),
9312 TInfo,
9313 E->getLocEnd());
9314 }
9315
9316 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9317
9318 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9319 if (SubExpr.isInvalid())
9320 return ExprError();
9321
9322 if (!getDerived().AlwaysRebuild() &&
9323 SubExpr.get() == E->getExprOperand())
9324 return E;
9325
9326 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9327 E->getLocStart(),
9328 SubExpr.get(),
9329 E->getLocEnd());
9330 }
9331
9332 template<typename Derived>
9333 ExprResult
TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr * E)9334 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9335 return E;
9336 }
9337
9338 template<typename Derived>
9339 ExprResult
TransformCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr * E)9340 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9341 CXXNullPtrLiteralExpr *E) {
9342 return E;
9343 }
9344
9345 template<typename Derived>
9346 ExprResult
TransformCXXThisExpr(CXXThisExpr * E)9347 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9348 QualType T = getSema().getCurrentThisType();
9349
9350 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9351 // Make sure that we capture 'this'.
9352 getSema().CheckCXXThisCapture(E->getLocStart());
9353 return E;
9354 }
9355
9356 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9357 }
9358
9359 template<typename Derived>
9360 ExprResult
TransformCXXThrowExpr(CXXThrowExpr * E)9361 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9362 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9363 if (SubExpr.isInvalid())
9364 return ExprError();
9365
9366 if (!getDerived().AlwaysRebuild() &&
9367 SubExpr.get() == E->getSubExpr())
9368 return E;
9369
9370 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9371 E->isThrownVariableInScope());
9372 }
9373
9374 template<typename Derived>
9375 ExprResult
TransformCXXDefaultArgExpr(CXXDefaultArgExpr * E)9376 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9377 ParmVarDecl *Param
9378 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9379 E->getParam()));
9380 if (!Param)
9381 return ExprError();
9382
9383 if (!getDerived().AlwaysRebuild() &&
9384 Param == E->getParam())
9385 return E;
9386
9387 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9388 }
9389
9390 template<typename Derived>
9391 ExprResult
TransformCXXDefaultInitExpr(CXXDefaultInitExpr * E)9392 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9393 FieldDecl *Field
9394 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9395 E->getField()));
9396 if (!Field)
9397 return ExprError();
9398
9399 if (!getDerived().AlwaysRebuild() && Field == E->getField())
9400 return E;
9401
9402 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9403 }
9404
9405 template<typename Derived>
9406 ExprResult
TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr * E)9407 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9408 CXXScalarValueInitExpr *E) {
9409 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9410 if (!T)
9411 return ExprError();
9412
9413 if (!getDerived().AlwaysRebuild() &&
9414 T == E->getTypeSourceInfo())
9415 return E;
9416
9417 return getDerived().RebuildCXXScalarValueInitExpr(T,
9418 /*FIXME:*/T->getTypeLoc().getEndLoc(),
9419 E->getRParenLoc());
9420 }
9421
9422 template<typename Derived>
9423 ExprResult
TransformCXXNewExpr(CXXNewExpr * E)9424 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
9425 // Transform the type that we're allocating
9426 TypeSourceInfo *AllocTypeInfo
9427 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9428 if (!AllocTypeInfo)
9429 return ExprError();
9430
9431 // Transform the size of the array we're allocating (if any).
9432 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
9433 if (ArraySize.isInvalid())
9434 return ExprError();
9435
9436 // Transform the placement arguments (if any).
9437 bool ArgumentChanged = false;
9438 SmallVector<Expr*, 8> PlacementArgs;
9439 if (getDerived().TransformExprs(E->getPlacementArgs(),
9440 E->getNumPlacementArgs(), true,
9441 PlacementArgs, &ArgumentChanged))
9442 return ExprError();
9443
9444 // Transform the initializer (if any).
9445 Expr *OldInit = E->getInitializer();
9446 ExprResult NewInit;
9447 if (OldInit)
9448 NewInit = getDerived().TransformInitializer(OldInit, true);
9449 if (NewInit.isInvalid())
9450 return ExprError();
9451
9452 // Transform new operator and delete operator.
9453 FunctionDecl *OperatorNew = nullptr;
9454 if (E->getOperatorNew()) {
9455 OperatorNew = cast_or_null<FunctionDecl>(
9456 getDerived().TransformDecl(E->getLocStart(),
9457 E->getOperatorNew()));
9458 if (!OperatorNew)
9459 return ExprError();
9460 }
9461
9462 FunctionDecl *OperatorDelete = nullptr;
9463 if (E->getOperatorDelete()) {
9464 OperatorDelete = cast_or_null<FunctionDecl>(
9465 getDerived().TransformDecl(E->getLocStart(),
9466 E->getOperatorDelete()));
9467 if (!OperatorDelete)
9468 return ExprError();
9469 }
9470
9471 if (!getDerived().AlwaysRebuild() &&
9472 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
9473 ArraySize.get() == E->getArraySize() &&
9474 NewInit.get() == OldInit &&
9475 OperatorNew == E->getOperatorNew() &&
9476 OperatorDelete == E->getOperatorDelete() &&
9477 !ArgumentChanged) {
9478 // Mark any declarations we need as referenced.
9479 // FIXME: instantiation-specific.
9480 if (OperatorNew)
9481 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
9482 if (OperatorDelete)
9483 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9484
9485 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
9486 QualType ElementType
9487 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9488 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9489 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9490 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
9491 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
9492 }
9493 }
9494 }
9495
9496 return E;
9497 }
9498
9499 QualType AllocType = AllocTypeInfo->getType();
9500 if (!ArraySize.get()) {
9501 // If no array size was specified, but the new expression was
9502 // instantiated with an array type (e.g., "new T" where T is
9503 // instantiated with "int[4]"), extract the outer bound from the
9504 // array type as our array size. We do this with constant and
9505 // dependently-sized array types.
9506 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9507 if (!ArrayT) {
9508 // Do nothing
9509 } else if (const ConstantArrayType *ConsArrayT
9510 = dyn_cast<ConstantArrayType>(ArrayT)) {
9511 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9512 SemaRef.Context.getSizeType(),
9513 /*FIXME:*/ E->getLocStart());
9514 AllocType = ConsArrayT->getElementType();
9515 } else if (const DependentSizedArrayType *DepArrayT
9516 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9517 if (DepArrayT->getSizeExpr()) {
9518 ArraySize = DepArrayT->getSizeExpr();
9519 AllocType = DepArrayT->getElementType();
9520 }
9521 }
9522 }
9523
9524 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9525 E->isGlobalNew(),
9526 /*FIXME:*/E->getLocStart(),
9527 PlacementArgs,
9528 /*FIXME:*/E->getLocStart(),
9529 E->getTypeIdParens(),
9530 AllocType,
9531 AllocTypeInfo,
9532 ArraySize.get(),
9533 E->getDirectInitRange(),
9534 NewInit.get());
9535 }
9536
9537 template<typename Derived>
9538 ExprResult
TransformCXXDeleteExpr(CXXDeleteExpr * E)9539 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
9540 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
9541 if (Operand.isInvalid())
9542 return ExprError();
9543
9544 // Transform the delete operator, if known.
9545 FunctionDecl *OperatorDelete = nullptr;
9546 if (E->getOperatorDelete()) {
9547 OperatorDelete = cast_or_null<FunctionDecl>(
9548 getDerived().TransformDecl(E->getLocStart(),
9549 E->getOperatorDelete()));
9550 if (!OperatorDelete)
9551 return ExprError();
9552 }
9553
9554 if (!getDerived().AlwaysRebuild() &&
9555 Operand.get() == E->getArgument() &&
9556 OperatorDelete == E->getOperatorDelete()) {
9557 // Mark any declarations we need as referenced.
9558 // FIXME: instantiation-specific.
9559 if (OperatorDelete)
9560 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9561
9562 if (!E->getArgument()->isTypeDependent()) {
9563 QualType Destroyed = SemaRef.Context.getBaseElementType(
9564 E->getDestroyedType());
9565 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9566 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
9567 SemaRef.MarkFunctionReferenced(E->getLocStart(),
9568 SemaRef.LookupDestructor(Record));
9569 }
9570 }
9571
9572 return E;
9573 }
9574
9575 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9576 E->isGlobalDelete(),
9577 E->isArrayForm(),
9578 Operand.get());
9579 }
9580
9581 template<typename Derived>
9582 ExprResult
TransformCXXPseudoDestructorExpr(CXXPseudoDestructorExpr * E)9583 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
9584 CXXPseudoDestructorExpr *E) {
9585 ExprResult Base = getDerived().TransformExpr(E->getBase());
9586 if (Base.isInvalid())
9587 return ExprError();
9588
9589 ParsedType ObjectTypePtr;
9590 bool MayBePseudoDestructor = false;
9591 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9592 E->getOperatorLoc(),
9593 E->isArrow()? tok::arrow : tok::period,
9594 ObjectTypePtr,
9595 MayBePseudoDestructor);
9596 if (Base.isInvalid())
9597 return ExprError();
9598
9599 QualType ObjectType = ObjectTypePtr.get();
9600 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9601 if (QualifierLoc) {
9602 QualifierLoc
9603 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9604 if (!QualifierLoc)
9605 return ExprError();
9606 }
9607 CXXScopeSpec SS;
9608 SS.Adopt(QualifierLoc);
9609
9610 PseudoDestructorTypeStorage Destroyed;
9611 if (E->getDestroyedTypeInfo()) {
9612 TypeSourceInfo *DestroyedTypeInfo
9613 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
9614 ObjectType, nullptr, SS);
9615 if (!DestroyedTypeInfo)
9616 return ExprError();
9617 Destroyed = DestroyedTypeInfo;
9618 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
9619 // We aren't likely to be able to resolve the identifier down to a type
9620 // now anyway, so just retain the identifier.
9621 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9622 E->getDestroyedTypeLoc());
9623 } else {
9624 // Look for a destructor known with the given name.
9625 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
9626 *E->getDestroyedTypeIdentifier(),
9627 E->getDestroyedTypeLoc(),
9628 /*Scope=*/nullptr,
9629 SS, ObjectTypePtr,
9630 false);
9631 if (!T)
9632 return ExprError();
9633
9634 Destroyed
9635 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9636 E->getDestroyedTypeLoc());
9637 }
9638
9639 TypeSourceInfo *ScopeTypeInfo = nullptr;
9640 if (E->getScopeTypeInfo()) {
9641 CXXScopeSpec EmptySS;
9642 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
9643 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
9644 if (!ScopeTypeInfo)
9645 return ExprError();
9646 }
9647
9648 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
9649 E->getOperatorLoc(),
9650 E->isArrow(),
9651 SS,
9652 ScopeTypeInfo,
9653 E->getColonColonLoc(),
9654 E->getTildeLoc(),
9655 Destroyed);
9656 }
9657
9658 template<typename Derived>
9659 ExprResult
TransformUnresolvedLookupExpr(UnresolvedLookupExpr * Old)9660 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
9661 UnresolvedLookupExpr *Old) {
9662 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9663 Sema::LookupOrdinaryName);
9664
9665 // Transform all the decls.
9666 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9667 E = Old->decls_end(); I != E; ++I) {
9668 NamedDecl *InstD = static_cast<NamedDecl*>(
9669 getDerived().TransformDecl(Old->getNameLoc(),
9670 *I));
9671 if (!InstD) {
9672 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9673 // This can happen because of dependent hiding.
9674 if (isa<UsingShadowDecl>(*I))
9675 continue;
9676 else {
9677 R.clear();
9678 return ExprError();
9679 }
9680 }
9681
9682 // Expand using declarations.
9683 if (isa<UsingDecl>(InstD)) {
9684 UsingDecl *UD = cast<UsingDecl>(InstD);
9685 for (auto *I : UD->shadows())
9686 R.addDecl(I);
9687 continue;
9688 }
9689
9690 R.addDecl(InstD);
9691 }
9692
9693 // Resolve a kind, but don't do any further analysis. If it's
9694 // ambiguous, the callee needs to deal with it.
9695 R.resolveKind();
9696
9697 // Rebuild the nested-name qualifier, if present.
9698 CXXScopeSpec SS;
9699 if (Old->getQualifierLoc()) {
9700 NestedNameSpecifierLoc QualifierLoc
9701 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9702 if (!QualifierLoc)
9703 return ExprError();
9704
9705 SS.Adopt(QualifierLoc);
9706 }
9707
9708 if (Old->getNamingClass()) {
9709 CXXRecordDecl *NamingClass
9710 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9711 Old->getNameLoc(),
9712 Old->getNamingClass()));
9713 if (!NamingClass) {
9714 R.clear();
9715 return ExprError();
9716 }
9717
9718 R.setNamingClass(NamingClass);
9719 }
9720
9721 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9722
9723 // If we have neither explicit template arguments, nor the template keyword,
9724 // it's a normal declaration name or member reference.
9725 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9726 NamedDecl *D = R.getAsSingle<NamedDecl>();
9727 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9728 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9729 // give a good diagnostic.
9730 if (D && D->isCXXInstanceMember()) {
9731 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9732 /*TemplateArgs=*/nullptr,
9733 /*Scope=*/nullptr);
9734 }
9735
9736 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9737 }
9738
9739 // If we have template arguments, rebuild them, then rebuild the
9740 // templateid expression.
9741 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
9742 if (Old->hasExplicitTemplateArgs() &&
9743 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9744 Old->getNumTemplateArgs(),
9745 TransArgs)) {
9746 R.clear();
9747 return ExprError();
9748 }
9749
9750 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
9751 Old->requiresADL(), &TransArgs);
9752 }
9753
9754 template<typename Derived>
9755 ExprResult
TransformTypeTraitExpr(TypeTraitExpr * E)9756 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9757 bool ArgChanged = false;
9758 SmallVector<TypeSourceInfo *, 4> Args;
9759 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9760 TypeSourceInfo *From = E->getArg(I);
9761 TypeLoc FromTL = From->getTypeLoc();
9762 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
9763 TypeLocBuilder TLB;
9764 TLB.reserve(FromTL.getFullDataSize());
9765 QualType To = getDerived().TransformType(TLB, FromTL);
9766 if (To.isNull())
9767 return ExprError();
9768
9769 if (To == From->getType())
9770 Args.push_back(From);
9771 else {
9772 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9773 ArgChanged = true;
9774 }
9775 continue;
9776 }
9777
9778 ArgChanged = true;
9779
9780 // We have a pack expansion. Instantiate it.
9781 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
9782 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9783 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9784 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
9785
9786 // Determine whether the set of unexpanded parameter packs can and should
9787 // be expanded.
9788 bool Expand = true;
9789 bool RetainExpansion = false;
9790 Optional<unsigned> OrigNumExpansions =
9791 ExpansionTL.getTypePtr()->getNumExpansions();
9792 Optional<unsigned> NumExpansions = OrigNumExpansions;
9793 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9794 PatternTL.getSourceRange(),
9795 Unexpanded,
9796 Expand, RetainExpansion,
9797 NumExpansions))
9798 return ExprError();
9799
9800 if (!Expand) {
9801 // The transform has determined that we should perform a simple
9802 // transformation on the pack expansion, producing another pack
9803 // expansion.
9804 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9805
9806 TypeLocBuilder TLB;
9807 TLB.reserve(From->getTypeLoc().getFullDataSize());
9808
9809 QualType To = getDerived().TransformType(TLB, PatternTL);
9810 if (To.isNull())
9811 return ExprError();
9812
9813 To = getDerived().RebuildPackExpansionType(To,
9814 PatternTL.getSourceRange(),
9815 ExpansionTL.getEllipsisLoc(),
9816 NumExpansions);
9817 if (To.isNull())
9818 return ExprError();
9819
9820 PackExpansionTypeLoc ToExpansionTL
9821 = TLB.push<PackExpansionTypeLoc>(To);
9822 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9823 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9824 continue;
9825 }
9826
9827 // Expand the pack expansion by substituting for each argument in the
9828 // pack(s).
9829 for (unsigned I = 0; I != *NumExpansions; ++I) {
9830 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9831 TypeLocBuilder TLB;
9832 TLB.reserve(PatternTL.getFullDataSize());
9833 QualType To = getDerived().TransformType(TLB, PatternTL);
9834 if (To.isNull())
9835 return ExprError();
9836
9837 if (To->containsUnexpandedParameterPack()) {
9838 To = getDerived().RebuildPackExpansionType(To,
9839 PatternTL.getSourceRange(),
9840 ExpansionTL.getEllipsisLoc(),
9841 NumExpansions);
9842 if (To.isNull())
9843 return ExprError();
9844
9845 PackExpansionTypeLoc ToExpansionTL
9846 = TLB.push<PackExpansionTypeLoc>(To);
9847 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9848 }
9849
9850 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9851 }
9852
9853 if (!RetainExpansion)
9854 continue;
9855
9856 // If we're supposed to retain a pack expansion, do so by temporarily
9857 // forgetting the partially-substituted parameter pack.
9858 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9859
9860 TypeLocBuilder TLB;
9861 TLB.reserve(From->getTypeLoc().getFullDataSize());
9862
9863 QualType To = getDerived().TransformType(TLB, PatternTL);
9864 if (To.isNull())
9865 return ExprError();
9866
9867 To = getDerived().RebuildPackExpansionType(To,
9868 PatternTL.getSourceRange(),
9869 ExpansionTL.getEllipsisLoc(),
9870 NumExpansions);
9871 if (To.isNull())
9872 return ExprError();
9873
9874 PackExpansionTypeLoc ToExpansionTL
9875 = TLB.push<PackExpansionTypeLoc>(To);
9876 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9877 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9878 }
9879
9880 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9881 return E;
9882
9883 return getDerived().RebuildTypeTrait(E->getTrait(),
9884 E->getLocStart(),
9885 Args,
9886 E->getLocEnd());
9887 }
9888
9889 template<typename Derived>
9890 ExprResult
TransformArrayTypeTraitExpr(ArrayTypeTraitExpr * E)9891 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9892 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9893 if (!T)
9894 return ExprError();
9895
9896 if (!getDerived().AlwaysRebuild() &&
9897 T == E->getQueriedTypeSourceInfo())
9898 return E;
9899
9900 ExprResult SubExpr;
9901 {
9902 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9903 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9904 if (SubExpr.isInvalid())
9905 return ExprError();
9906
9907 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
9908 return E;
9909 }
9910
9911 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9912 E->getLocStart(),
9913 T,
9914 SubExpr.get(),
9915 E->getLocEnd());
9916 }
9917
9918 template<typename Derived>
9919 ExprResult
TransformExpressionTraitExpr(ExpressionTraitExpr * E)9920 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9921 ExprResult SubExpr;
9922 {
9923 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9924 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9925 if (SubExpr.isInvalid())
9926 return ExprError();
9927
9928 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
9929 return E;
9930 }
9931
9932 return getDerived().RebuildExpressionTrait(
9933 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9934 }
9935
9936 template <typename Derived>
TransformParenDependentScopeDeclRefExpr(ParenExpr * PE,DependentScopeDeclRefExpr * DRE,bool AddrTaken,TypeSourceInfo ** RecoveryTSI)9937 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9938 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9939 TypeSourceInfo **RecoveryTSI) {
9940 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9941 DRE, AddrTaken, RecoveryTSI);
9942
9943 // Propagate both errors and recovered types, which return ExprEmpty.
9944 if (!NewDRE.isUsable())
9945 return NewDRE;
9946
9947 // We got an expr, wrap it up in parens.
9948 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9949 return PE;
9950 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9951 PE->getRParen());
9952 }
9953
9954 template <typename Derived>
TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr * E)9955 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9956 DependentScopeDeclRefExpr *E) {
9957 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9958 nullptr);
9959 }
9960
9961 template<typename Derived>
9962 ExprResult
TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr * E,bool IsAddressOfOperand,TypeSourceInfo ** RecoveryTSI)9963 TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9964 DependentScopeDeclRefExpr *E,
9965 bool IsAddressOfOperand,
9966 TypeSourceInfo **RecoveryTSI) {
9967 assert(E->getQualifierLoc());
9968 NestedNameSpecifierLoc QualifierLoc
9969 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9970 if (!QualifierLoc)
9971 return ExprError();
9972 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9973
9974 // TODO: If this is a conversion-function-id, verify that the
9975 // destination type name (if present) resolves the same way after
9976 // instantiation as it did in the local scope.
9977
9978 DeclarationNameInfo NameInfo
9979 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9980 if (!NameInfo.getName())
9981 return ExprError();
9982
9983 if (!E->hasExplicitTemplateArgs()) {
9984 if (!getDerived().AlwaysRebuild() &&
9985 QualifierLoc == E->getQualifierLoc() &&
9986 // Note: it is sufficient to compare the Name component of NameInfo:
9987 // if name has not changed, DNLoc has not changed either.
9988 NameInfo.getName() == E->getDeclName())
9989 return E;
9990
9991 return getDerived().RebuildDependentScopeDeclRefExpr(
9992 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9993 IsAddressOfOperand, RecoveryTSI);
9994 }
9995
9996 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
9997 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9998 E->getNumTemplateArgs(),
9999 TransArgs))
10000 return ExprError();
10001
10002 return getDerived().RebuildDependentScopeDeclRefExpr(
10003 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10004 RecoveryTSI);
10005 }
10006
10007 template<typename Derived>
10008 ExprResult
TransformCXXConstructExpr(CXXConstructExpr * E)10009 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10010 // CXXConstructExprs other than for list-initialization and
10011 // CXXTemporaryObjectExpr are always implicit, so when we have
10012 // a 1-argument construction we just transform that argument.
10013 if ((E->getNumArgs() == 1 ||
10014 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10015 (!getDerived().DropCallArgument(E->getArg(0))) &&
10016 !E->isListInitialization())
10017 return getDerived().TransformExpr(E->getArg(0));
10018
10019 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10020
10021 QualType T = getDerived().TransformType(E->getType());
10022 if (T.isNull())
10023 return ExprError();
10024
10025 CXXConstructorDecl *Constructor
10026 = cast_or_null<CXXConstructorDecl>(
10027 getDerived().TransformDecl(E->getLocStart(),
10028 E->getConstructor()));
10029 if (!Constructor)
10030 return ExprError();
10031
10032 bool ArgumentChanged = false;
10033 SmallVector<Expr*, 8> Args;
10034 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10035 &ArgumentChanged))
10036 return ExprError();
10037
10038 if (!getDerived().AlwaysRebuild() &&
10039 T == E->getType() &&
10040 Constructor == E->getConstructor() &&
10041 !ArgumentChanged) {
10042 // Mark the constructor as referenced.
10043 // FIXME: Instantiation-specific
10044 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10045 return E;
10046 }
10047
10048 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10049 Constructor,
10050 E->isElidable(), Args,
10051 E->hadMultipleCandidates(),
10052 E->isListInitialization(),
10053 E->isStdInitListInitialization(),
10054 E->requiresZeroInitialization(),
10055 E->getConstructionKind(),
10056 E->getParenOrBraceRange());
10057 }
10058
10059 template<typename Derived>
TransformCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr * E)10060 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10061 CXXInheritedCtorInitExpr *E) {
10062 QualType T = getDerived().TransformType(E->getType());
10063 if (T.isNull())
10064 return ExprError();
10065
10066 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10067 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10068 if (!Constructor)
10069 return ExprError();
10070
10071 if (!getDerived().AlwaysRebuild() &&
10072 T == E->getType() &&
10073 Constructor == E->getConstructor()) {
10074 // Mark the constructor as referenced.
10075 // FIXME: Instantiation-specific
10076 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10077 return E;
10078 }
10079
10080 return getDerived().RebuildCXXInheritedCtorInitExpr(
10081 T, E->getLocation(), Constructor,
10082 E->constructsVBase(), E->inheritedFromVBase());
10083 }
10084
10085 /// \brief Transform a C++ temporary-binding expression.
10086 ///
10087 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10088 /// transform the subexpression and return that.
10089 template<typename Derived>
10090 ExprResult
TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr * E)10091 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10092 return getDerived().TransformExpr(E->getSubExpr());
10093 }
10094
10095 /// \brief Transform a C++ expression that contains cleanups that should
10096 /// be run after the expression is evaluated.
10097 ///
10098 /// Since ExprWithCleanups nodes are implicitly generated, we
10099 /// just transform the subexpression and return that.
10100 template<typename Derived>
10101 ExprResult
TransformExprWithCleanups(ExprWithCleanups * E)10102 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10103 return getDerived().TransformExpr(E->getSubExpr());
10104 }
10105
10106 template<typename Derived>
10107 ExprResult
TransformCXXTemporaryObjectExpr(CXXTemporaryObjectExpr * E)10108 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10109 CXXTemporaryObjectExpr *E) {
10110 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10111 if (!T)
10112 return ExprError();
10113
10114 CXXConstructorDecl *Constructor
10115 = cast_or_null<CXXConstructorDecl>(
10116 getDerived().TransformDecl(E->getLocStart(),
10117 E->getConstructor()));
10118 if (!Constructor)
10119 return ExprError();
10120
10121 bool ArgumentChanged = false;
10122 SmallVector<Expr*, 8> Args;
10123 Args.reserve(E->getNumArgs());
10124 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10125 &ArgumentChanged))
10126 return ExprError();
10127
10128 if (!getDerived().AlwaysRebuild() &&
10129 T == E->getTypeSourceInfo() &&
10130 Constructor == E->getConstructor() &&
10131 !ArgumentChanged) {
10132 // FIXME: Instantiation-specific
10133 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10134 return SemaRef.MaybeBindToTemporary(E);
10135 }
10136
10137 // FIXME: Pass in E->isListInitialization().
10138 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10139 /*FIXME:*/T->getTypeLoc().getEndLoc(),
10140 Args,
10141 E->getLocEnd());
10142 }
10143
10144 template<typename Derived>
10145 ExprResult
TransformLambdaExpr(LambdaExpr * E)10146 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10147 // Transform any init-capture expressions before entering the scope of the
10148 // lambda body, because they are not semantically within that scope.
10149 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10150 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10151 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10152 E->explicit_capture_begin());
10153 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10154 CEnd = E->capture_end();
10155 C != CEnd; ++C) {
10156 if (!E->isInitCapture(C))
10157 continue;
10158 EnterExpressionEvaluationContext EEEC(getSema(),
10159 Sema::PotentiallyEvaluated);
10160 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10161 C->getCapturedVar()->getInit(),
10162 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10163
10164 if (NewExprInitResult.isInvalid())
10165 return ExprError();
10166 Expr *NewExprInit = NewExprInitResult.get();
10167
10168 VarDecl *OldVD = C->getCapturedVar();
10169 QualType NewInitCaptureType =
10170 getSema().buildLambdaInitCaptureInitialization(
10171 C->getLocation(), OldVD->getType()->isReferenceType(),
10172 OldVD->getIdentifier(),
10173 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10174 NewExprInitResult = NewExprInit;
10175 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10176 std::make_pair(NewExprInitResult, NewInitCaptureType);
10177 }
10178
10179 // Transform the template parameters, and add them to the current
10180 // instantiation scope. The null case is handled correctly.
10181 auto TPL = getDerived().TransformTemplateParameterList(
10182 E->getTemplateParameterList());
10183
10184 // Transform the type of the original lambda's call operator.
10185 // The transformation MUST be done in the CurrentInstantiationScope since
10186 // it introduces a mapping of the original to the newly created
10187 // transformed parameters.
10188 TypeSourceInfo *NewCallOpTSI = nullptr;
10189 {
10190 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10191 FunctionProtoTypeLoc OldCallOpFPTL =
10192 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10193
10194 TypeLocBuilder NewCallOpTLBuilder;
10195 SmallVector<QualType, 4> ExceptionStorage;
10196 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10197 QualType NewCallOpType = TransformFunctionProtoType(
10198 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10199 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10200 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10201 ExceptionStorage, Changed);
10202 });
10203 if (NewCallOpType.isNull())
10204 return ExprError();
10205 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10206 NewCallOpType);
10207 }
10208
10209 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10210 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10211 LSI->GLTemplateParameterList = TPL;
10212
10213 // Create the local class that will describe the lambda.
10214 CXXRecordDecl *Class
10215 = getSema().createLambdaClosureType(E->getIntroducerRange(),
10216 NewCallOpTSI,
10217 /*KnownDependent=*/false,
10218 E->getCaptureDefault());
10219 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10220
10221 // Build the call operator.
10222 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10223 Class, E->getIntroducerRange(), NewCallOpTSI,
10224 E->getCallOperator()->getLocEnd(),
10225 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10226 E->getCallOperator()->isConstexpr());
10227
10228 LSI->CallOperator = NewCallOperator;
10229
10230 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10231 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10232
10233 // Introduce the context of the call operator.
10234 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10235 /*NewThisContext*/false);
10236
10237 // Enter the scope of the lambda.
10238 getSema().buildLambdaScope(LSI, NewCallOperator,
10239 E->getIntroducerRange(),
10240 E->getCaptureDefault(),
10241 E->getCaptureDefaultLoc(),
10242 E->hasExplicitParameters(),
10243 E->hasExplicitResultType(),
10244 E->isMutable());
10245
10246 bool Invalid = false;
10247
10248 // Transform captures.
10249 bool FinishedExplicitCaptures = false;
10250 for (LambdaExpr::capture_iterator C = E->capture_begin(),
10251 CEnd = E->capture_end();
10252 C != CEnd; ++C) {
10253 // When we hit the first implicit capture, tell Sema that we've finished
10254 // the list of explicit captures.
10255 if (!FinishedExplicitCaptures && C->isImplicit()) {
10256 getSema().finishLambdaExplicitCaptures(LSI);
10257 FinishedExplicitCaptures = true;
10258 }
10259
10260 // Capturing 'this' is trivial.
10261 if (C->capturesThis()) {
10262 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10263 /*BuildAndDiagnose*/ true, nullptr,
10264 C->getCaptureKind() == LCK_StarThis);
10265 continue;
10266 }
10267 // Captured expression will be recaptured during captured variables
10268 // rebuilding.
10269 if (C->capturesVLAType())
10270 continue;
10271
10272 // Rebuild init-captures, including the implied field declaration.
10273 if (E->isInitCapture(C)) {
10274 InitCaptureInfoTy InitExprTypePair =
10275 InitCaptureExprsAndTypes[C - E->capture_begin()];
10276 ExprResult Init = InitExprTypePair.first;
10277 QualType InitQualType = InitExprTypePair.second;
10278 if (Init.isInvalid() || InitQualType.isNull()) {
10279 Invalid = true;
10280 continue;
10281 }
10282 VarDecl *OldVD = C->getCapturedVar();
10283 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
10284 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10285 OldVD->getInitStyle(), Init.get());
10286 if (!NewVD)
10287 Invalid = true;
10288 else {
10289 getDerived().transformedLocalDecl(OldVD, NewVD);
10290 }
10291 getSema().buildInitCaptureField(LSI, NewVD);
10292 continue;
10293 }
10294
10295 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10296
10297 // Determine the capture kind for Sema.
10298 Sema::TryCaptureKind Kind
10299 = C->isImplicit()? Sema::TryCapture_Implicit
10300 : C->getCaptureKind() == LCK_ByCopy
10301 ? Sema::TryCapture_ExplicitByVal
10302 : Sema::TryCapture_ExplicitByRef;
10303 SourceLocation EllipsisLoc;
10304 if (C->isPackExpansion()) {
10305 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10306 bool ShouldExpand = false;
10307 bool RetainExpansion = false;
10308 Optional<unsigned> NumExpansions;
10309 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10310 C->getLocation(),
10311 Unexpanded,
10312 ShouldExpand, RetainExpansion,
10313 NumExpansions)) {
10314 Invalid = true;
10315 continue;
10316 }
10317
10318 if (ShouldExpand) {
10319 // The transform has determined that we should perform an expansion;
10320 // transform and capture each of the arguments.
10321 // expansion of the pattern. Do so.
10322 VarDecl *Pack = C->getCapturedVar();
10323 for (unsigned I = 0; I != *NumExpansions; ++I) {
10324 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10325 VarDecl *CapturedVar
10326 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10327 Pack));
10328 if (!CapturedVar) {
10329 Invalid = true;
10330 continue;
10331 }
10332
10333 // Capture the transformed variable.
10334 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10335 }
10336
10337 // FIXME: Retain a pack expansion if RetainExpansion is true.
10338
10339 continue;
10340 }
10341
10342 EllipsisLoc = C->getEllipsisLoc();
10343 }
10344
10345 // Transform the captured variable.
10346 VarDecl *CapturedVar
10347 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10348 C->getCapturedVar()));
10349 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10350 Invalid = true;
10351 continue;
10352 }
10353
10354 // Capture the transformed variable.
10355 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10356 EllipsisLoc);
10357 }
10358 if (!FinishedExplicitCaptures)
10359 getSema().finishLambdaExplicitCaptures(LSI);
10360
10361 // Enter a new evaluation context to insulate the lambda from any
10362 // cleanups from the enclosing full-expression.
10363 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
10364
10365 // Instantiate the body of the lambda expression.
10366 StmtResult Body =
10367 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10368
10369 // ActOnLambda* will pop the function scope for us.
10370 FuncScopeCleanup.disable();
10371
10372 if (Body.isInvalid()) {
10373 SavedContext.pop();
10374 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
10375 /*IsInstantiation=*/true);
10376 return ExprError();
10377 }
10378
10379 // Copy the LSI before ActOnFinishFunctionBody removes it.
10380 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10381 // the call operator.
10382 auto LSICopy = *LSI;
10383 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10384 /*IsInstantiation*/ true);
10385 SavedContext.pop();
10386
10387 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10388 &LSICopy);
10389 }
10390
10391 template<typename Derived>
10392 ExprResult
TransformCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr * E)10393 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
10394 CXXUnresolvedConstructExpr *E) {
10395 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10396 if (!T)
10397 return ExprError();
10398
10399 bool ArgumentChanged = false;
10400 SmallVector<Expr*, 8> Args;
10401 Args.reserve(E->arg_size());
10402 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
10403 &ArgumentChanged))
10404 return ExprError();
10405
10406 if (!getDerived().AlwaysRebuild() &&
10407 T == E->getTypeSourceInfo() &&
10408 !ArgumentChanged)
10409 return E;
10410
10411 // FIXME: we're faking the locations of the commas
10412 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
10413 E->getLParenLoc(),
10414 Args,
10415 E->getRParenLoc());
10416 }
10417
10418 template<typename Derived>
10419 ExprResult
TransformCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr * E)10420 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
10421 CXXDependentScopeMemberExpr *E) {
10422 // Transform the base of the expression.
10423 ExprResult Base((Expr*) nullptr);
10424 Expr *OldBase;
10425 QualType BaseType;
10426 QualType ObjectType;
10427 if (!E->isImplicitAccess()) {
10428 OldBase = E->getBase();
10429 Base = getDerived().TransformExpr(OldBase);
10430 if (Base.isInvalid())
10431 return ExprError();
10432
10433 // Start the member reference and compute the object's type.
10434 ParsedType ObjectTy;
10435 bool MayBePseudoDestructor = false;
10436 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10437 E->getOperatorLoc(),
10438 E->isArrow()? tok::arrow : tok::period,
10439 ObjectTy,
10440 MayBePseudoDestructor);
10441 if (Base.isInvalid())
10442 return ExprError();
10443
10444 ObjectType = ObjectTy.get();
10445 BaseType = ((Expr*) Base.get())->getType();
10446 } else {
10447 OldBase = nullptr;
10448 BaseType = getDerived().TransformType(E->getBaseType());
10449 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10450 }
10451
10452 // Transform the first part of the nested-name-specifier that qualifies
10453 // the member name.
10454 NamedDecl *FirstQualifierInScope
10455 = getDerived().TransformFirstQualifierInScope(
10456 E->getFirstQualifierFoundInScope(),
10457 E->getQualifierLoc().getBeginLoc());
10458
10459 NestedNameSpecifierLoc QualifierLoc;
10460 if (E->getQualifier()) {
10461 QualifierLoc
10462 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10463 ObjectType,
10464 FirstQualifierInScope);
10465 if (!QualifierLoc)
10466 return ExprError();
10467 }
10468
10469 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10470
10471 // TODO: If this is a conversion-function-id, verify that the
10472 // destination type name (if present) resolves the same way after
10473 // instantiation as it did in the local scope.
10474
10475 DeclarationNameInfo NameInfo
10476 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
10477 if (!NameInfo.getName())
10478 return ExprError();
10479
10480 if (!E->hasExplicitTemplateArgs()) {
10481 // This is a reference to a member without an explicitly-specified
10482 // template argument list. Optimize for this common case.
10483 if (!getDerived().AlwaysRebuild() &&
10484 Base.get() == OldBase &&
10485 BaseType == E->getBaseType() &&
10486 QualifierLoc == E->getQualifierLoc() &&
10487 NameInfo.getName() == E->getMember() &&
10488 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
10489 return E;
10490
10491 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10492 BaseType,
10493 E->isArrow(),
10494 E->getOperatorLoc(),
10495 QualifierLoc,
10496 TemplateKWLoc,
10497 FirstQualifierInScope,
10498 NameInfo,
10499 /*TemplateArgs*/nullptr);
10500 }
10501
10502 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10503 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10504 E->getNumTemplateArgs(),
10505 TransArgs))
10506 return ExprError();
10507
10508 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10509 BaseType,
10510 E->isArrow(),
10511 E->getOperatorLoc(),
10512 QualifierLoc,
10513 TemplateKWLoc,
10514 FirstQualifierInScope,
10515 NameInfo,
10516 &TransArgs);
10517 }
10518
10519 template<typename Derived>
10520 ExprResult
TransformUnresolvedMemberExpr(UnresolvedMemberExpr * Old)10521 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
10522 // Transform the base of the expression.
10523 ExprResult Base((Expr*) nullptr);
10524 QualType BaseType;
10525 if (!Old->isImplicitAccess()) {
10526 Base = getDerived().TransformExpr(Old->getBase());
10527 if (Base.isInvalid())
10528 return ExprError();
10529 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
10530 Old->isArrow());
10531 if (Base.isInvalid())
10532 return ExprError();
10533 BaseType = Base.get()->getType();
10534 } else {
10535 BaseType = getDerived().TransformType(Old->getBaseType());
10536 }
10537
10538 NestedNameSpecifierLoc QualifierLoc;
10539 if (Old->getQualifierLoc()) {
10540 QualifierLoc
10541 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10542 if (!QualifierLoc)
10543 return ExprError();
10544 }
10545
10546 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10547
10548 LookupResult R(SemaRef, Old->getMemberNameInfo(),
10549 Sema::LookupOrdinaryName);
10550
10551 // Transform all the decls.
10552 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10553 E = Old->decls_end(); I != E; ++I) {
10554 NamedDecl *InstD = static_cast<NamedDecl*>(
10555 getDerived().TransformDecl(Old->getMemberLoc(),
10556 *I));
10557 if (!InstD) {
10558 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10559 // This can happen because of dependent hiding.
10560 if (isa<UsingShadowDecl>(*I))
10561 continue;
10562 else {
10563 R.clear();
10564 return ExprError();
10565 }
10566 }
10567
10568 // Expand using declarations.
10569 if (isa<UsingDecl>(InstD)) {
10570 UsingDecl *UD = cast<UsingDecl>(InstD);
10571 for (auto *I : UD->shadows())
10572 R.addDecl(I);
10573 continue;
10574 }
10575
10576 R.addDecl(InstD);
10577 }
10578
10579 R.resolveKind();
10580
10581 // Determine the naming class.
10582 if (Old->getNamingClass()) {
10583 CXXRecordDecl *NamingClass
10584 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10585 Old->getMemberLoc(),
10586 Old->getNamingClass()));
10587 if (!NamingClass)
10588 return ExprError();
10589
10590 R.setNamingClass(NamingClass);
10591 }
10592
10593 TemplateArgumentListInfo TransArgs;
10594 if (Old->hasExplicitTemplateArgs()) {
10595 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10596 TransArgs.setRAngleLoc(Old->getRAngleLoc());
10597 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10598 Old->getNumTemplateArgs(),
10599 TransArgs))
10600 return ExprError();
10601 }
10602
10603 // FIXME: to do this check properly, we will need to preserve the
10604 // first-qualifier-in-scope here, just in case we had a dependent
10605 // base (and therefore couldn't do the check) and a
10606 // nested-name-qualifier (and therefore could do the lookup).
10607 NamedDecl *FirstQualifierInScope = nullptr;
10608
10609 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
10610 BaseType,
10611 Old->getOperatorLoc(),
10612 Old->isArrow(),
10613 QualifierLoc,
10614 TemplateKWLoc,
10615 FirstQualifierInScope,
10616 R,
10617 (Old->hasExplicitTemplateArgs()
10618 ? &TransArgs : nullptr));
10619 }
10620
10621 template<typename Derived>
10622 ExprResult
TransformCXXNoexceptExpr(CXXNoexceptExpr * E)10623 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
10624 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10625 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10626 if (SubExpr.isInvalid())
10627 return ExprError();
10628
10629 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
10630 return E;
10631
10632 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10633 }
10634
10635 template<typename Derived>
10636 ExprResult
TransformPackExpansionExpr(PackExpansionExpr * E)10637 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
10638 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10639 if (Pattern.isInvalid())
10640 return ExprError();
10641
10642 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
10643 return E;
10644
10645 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10646 E->getNumExpansions());
10647 }
10648
10649 template<typename Derived>
10650 ExprResult
TransformSizeOfPackExpr(SizeOfPackExpr * E)10651 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10652 // If E is not value-dependent, then nothing will change when we transform it.
10653 // Note: This is an instantiation-centric view.
10654 if (!E->isValueDependent())
10655 return E;
10656
10657 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
10658
10659 ArrayRef<TemplateArgument> PackArgs;
10660 TemplateArgument ArgStorage;
10661
10662 // Find the argument list to transform.
10663 if (E->isPartiallySubstituted()) {
10664 PackArgs = E->getPartialArguments();
10665 } else if (E->isValueDependent()) {
10666 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10667 bool ShouldExpand = false;
10668 bool RetainExpansion = false;
10669 Optional<unsigned> NumExpansions;
10670 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10671 Unexpanded,
10672 ShouldExpand, RetainExpansion,
10673 NumExpansions))
10674 return ExprError();
10675
10676 // If we need to expand the pack, build a template argument from it and
10677 // expand that.
10678 if (ShouldExpand) {
10679 auto *Pack = E->getPack();
10680 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10681 ArgStorage = getSema().Context.getPackExpansionType(
10682 getSema().Context.getTypeDeclType(TTPD), None);
10683 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10684 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10685 } else {
10686 auto *VD = cast<ValueDecl>(Pack);
10687 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10688 VK_RValue, E->getPackLoc());
10689 if (DRE.isInvalid())
10690 return ExprError();
10691 ArgStorage = new (getSema().Context) PackExpansionExpr(
10692 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10693 }
10694 PackArgs = ArgStorage;
10695 }
10696 }
10697
10698 // If we're not expanding the pack, just transform the decl.
10699 if (!PackArgs.size()) {
10700 auto *Pack = cast_or_null<NamedDecl>(
10701 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
10702 if (!Pack)
10703 return ExprError();
10704 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10705 E->getPackLoc(),
10706 E->getRParenLoc(), None, None);
10707 }
10708
10709 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10710 E->getPackLoc());
10711 {
10712 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10713 typedef TemplateArgumentLocInventIterator<
10714 Derived, const TemplateArgument*> PackLocIterator;
10715 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10716 PackLocIterator(*this, PackArgs.end()),
10717 TransformedPackArgs, /*Uneval*/true))
10718 return ExprError();
10719 }
10720
10721 SmallVector<TemplateArgument, 8> Args;
10722 bool PartialSubstitution = false;
10723 for (auto &Loc : TransformedPackArgs.arguments()) {
10724 Args.push_back(Loc.getArgument());
10725 if (Loc.getArgument().isPackExpansion())
10726 PartialSubstitution = true;
10727 }
10728
10729 if (PartialSubstitution)
10730 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10731 E->getPackLoc(),
10732 E->getRParenLoc(), None, Args);
10733
10734 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10735 E->getPackLoc(), E->getRParenLoc(),
10736 Args.size(), None);
10737 }
10738
10739 template<typename Derived>
10740 ExprResult
TransformSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr * E)10741 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10742 SubstNonTypeTemplateParmPackExpr *E) {
10743 // Default behavior is to do nothing with this transformation.
10744 return E;
10745 }
10746
10747 template<typename Derived>
10748 ExprResult
TransformSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr * E)10749 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10750 SubstNonTypeTemplateParmExpr *E) {
10751 // Default behavior is to do nothing with this transformation.
10752 return E;
10753 }
10754
10755 template<typename Derived>
10756 ExprResult
TransformFunctionParmPackExpr(FunctionParmPackExpr * E)10757 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10758 // Default behavior is to do nothing with this transformation.
10759 return E;
10760 }
10761
10762 template<typename Derived>
10763 ExprResult
TransformMaterializeTemporaryExpr(MaterializeTemporaryExpr * E)10764 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10765 MaterializeTemporaryExpr *E) {
10766 return getDerived().TransformExpr(E->GetTemporaryExpr());
10767 }
10768
10769 template<typename Derived>
10770 ExprResult
TransformCXXFoldExpr(CXXFoldExpr * E)10771 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10772 Expr *Pattern = E->getPattern();
10773
10774 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10775 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10776 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10777
10778 // Determine whether the set of unexpanded parameter packs can and should
10779 // be expanded.
10780 bool Expand = true;
10781 bool RetainExpansion = false;
10782 Optional<unsigned> NumExpansions;
10783 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10784 Pattern->getSourceRange(),
10785 Unexpanded,
10786 Expand, RetainExpansion,
10787 NumExpansions))
10788 return true;
10789
10790 if (!Expand) {
10791 // Do not expand any packs here, just transform and rebuild a fold
10792 // expression.
10793 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10794
10795 ExprResult LHS =
10796 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10797 if (LHS.isInvalid())
10798 return true;
10799
10800 ExprResult RHS =
10801 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10802 if (RHS.isInvalid())
10803 return true;
10804
10805 if (!getDerived().AlwaysRebuild() &&
10806 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10807 return E;
10808
10809 return getDerived().RebuildCXXFoldExpr(
10810 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10811 RHS.get(), E->getLocEnd());
10812 }
10813
10814 // The transform has determined that we should perform an elementwise
10815 // expansion of the pattern. Do so.
10816 ExprResult Result = getDerived().TransformExpr(E->getInit());
10817 if (Result.isInvalid())
10818 return true;
10819 bool LeftFold = E->isLeftFold();
10820
10821 // If we're retaining an expansion for a right fold, it is the innermost
10822 // component and takes the init (if any).
10823 if (!LeftFold && RetainExpansion) {
10824 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10825
10826 ExprResult Out = getDerived().TransformExpr(Pattern);
10827 if (Out.isInvalid())
10828 return true;
10829
10830 Result = getDerived().RebuildCXXFoldExpr(
10831 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10832 Result.get(), E->getLocEnd());
10833 if (Result.isInvalid())
10834 return true;
10835 }
10836
10837 for (unsigned I = 0; I != *NumExpansions; ++I) {
10838 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10839 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10840 ExprResult Out = getDerived().TransformExpr(Pattern);
10841 if (Out.isInvalid())
10842 return true;
10843
10844 if (Out.get()->containsUnexpandedParameterPack()) {
10845 // We still have a pack; retain a pack expansion for this slice.
10846 Result = getDerived().RebuildCXXFoldExpr(
10847 E->getLocStart(),
10848 LeftFold ? Result.get() : Out.get(),
10849 E->getOperator(), E->getEllipsisLoc(),
10850 LeftFold ? Out.get() : Result.get(),
10851 E->getLocEnd());
10852 } else if (Result.isUsable()) {
10853 // We've got down to a single element; build a binary operator.
10854 Result = getDerived().RebuildBinaryOperator(
10855 E->getEllipsisLoc(), E->getOperator(),
10856 LeftFold ? Result.get() : Out.get(),
10857 LeftFold ? Out.get() : Result.get());
10858 } else
10859 Result = Out;
10860
10861 if (Result.isInvalid())
10862 return true;
10863 }
10864
10865 // If we're retaining an expansion for a left fold, it is the outermost
10866 // component and takes the complete expansion so far as its init (if any).
10867 if (LeftFold && RetainExpansion) {
10868 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10869
10870 ExprResult Out = getDerived().TransformExpr(Pattern);
10871 if (Out.isInvalid())
10872 return true;
10873
10874 Result = getDerived().RebuildCXXFoldExpr(
10875 E->getLocStart(), Result.get(),
10876 E->getOperator(), E->getEllipsisLoc(),
10877 Out.get(), E->getLocEnd());
10878 if (Result.isInvalid())
10879 return true;
10880 }
10881
10882 // If we had no init and an empty pack, and we're not retaining an expansion,
10883 // then produce a fallback value or error.
10884 if (Result.isUnset())
10885 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10886 E->getOperator());
10887
10888 return Result;
10889 }
10890
10891 template<typename Derived>
10892 ExprResult
TransformCXXStdInitializerListExpr(CXXStdInitializerListExpr * E)10893 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10894 CXXStdInitializerListExpr *E) {
10895 return getDerived().TransformExpr(E->getSubExpr());
10896 }
10897
10898 template<typename Derived>
10899 ExprResult
TransformObjCStringLiteral(ObjCStringLiteral * E)10900 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
10901 return SemaRef.MaybeBindToTemporary(E);
10902 }
10903
10904 template<typename Derived>
10905 ExprResult
TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr * E)10906 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
10907 return E;
10908 }
10909
10910 template<typename Derived>
10911 ExprResult
TransformObjCBoxedExpr(ObjCBoxedExpr * E)10912 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10913 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10914 if (SubExpr.isInvalid())
10915 return ExprError();
10916
10917 if (!getDerived().AlwaysRebuild() &&
10918 SubExpr.get() == E->getSubExpr())
10919 return E;
10920
10921 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
10922 }
10923
10924 template<typename Derived>
10925 ExprResult
TransformObjCArrayLiteral(ObjCArrayLiteral * E)10926 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10927 // Transform each of the elements.
10928 SmallVector<Expr *, 8> Elements;
10929 bool ArgChanged = false;
10930 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
10931 /*IsCall=*/false, Elements, &ArgChanged))
10932 return ExprError();
10933
10934 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10935 return SemaRef.MaybeBindToTemporary(E);
10936
10937 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10938 Elements.data(),
10939 Elements.size());
10940 }
10941
10942 template<typename Derived>
10943 ExprResult
TransformObjCDictionaryLiteral(ObjCDictionaryLiteral * E)10944 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
10945 ObjCDictionaryLiteral *E) {
10946 // Transform each of the elements.
10947 SmallVector<ObjCDictionaryElement, 8> Elements;
10948 bool ArgChanged = false;
10949 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10950 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
10951
10952 if (OrigElement.isPackExpansion()) {
10953 // This key/value element is a pack expansion.
10954 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10955 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10956 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10957 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10958
10959 // Determine whether the set of unexpanded parameter packs can
10960 // and should be expanded.
10961 bool Expand = true;
10962 bool RetainExpansion = false;
10963 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10964 Optional<unsigned> NumExpansions = OrigNumExpansions;
10965 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10966 OrigElement.Value->getLocEnd());
10967 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10968 PatternRange,
10969 Unexpanded,
10970 Expand, RetainExpansion,
10971 NumExpansions))
10972 return ExprError();
10973
10974 if (!Expand) {
10975 // The transform has determined that we should perform a simple
10976 // transformation on the pack expansion, producing another pack
10977 // expansion.
10978 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10979 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10980 if (Key.isInvalid())
10981 return ExprError();
10982
10983 if (Key.get() != OrigElement.Key)
10984 ArgChanged = true;
10985
10986 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10987 if (Value.isInvalid())
10988 return ExprError();
10989
10990 if (Value.get() != OrigElement.Value)
10991 ArgChanged = true;
10992
10993 ObjCDictionaryElement Expansion = {
10994 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10995 };
10996 Elements.push_back(Expansion);
10997 continue;
10998 }
10999
11000 // Record right away that the argument was changed. This needs
11001 // to happen even if the array expands to nothing.
11002 ArgChanged = true;
11003
11004 // The transform has determined that we should perform an elementwise
11005 // expansion of the pattern. Do so.
11006 for (unsigned I = 0; I != *NumExpansions; ++I) {
11007 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11008 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11009 if (Key.isInvalid())
11010 return ExprError();
11011
11012 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11013 if (Value.isInvalid())
11014 return ExprError();
11015
11016 ObjCDictionaryElement Element = {
11017 Key.get(), Value.get(), SourceLocation(), NumExpansions
11018 };
11019
11020 // If any unexpanded parameter packs remain, we still have a
11021 // pack expansion.
11022 // FIXME: Can this really happen?
11023 if (Key.get()->containsUnexpandedParameterPack() ||
11024 Value.get()->containsUnexpandedParameterPack())
11025 Element.EllipsisLoc = OrigElement.EllipsisLoc;
11026
11027 Elements.push_back(Element);
11028 }
11029
11030 // FIXME: Retain a pack expansion if RetainExpansion is true.
11031
11032 // We've finished with this pack expansion.
11033 continue;
11034 }
11035
11036 // Transform and check key.
11037 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11038 if (Key.isInvalid())
11039 return ExprError();
11040
11041 if (Key.get() != OrigElement.Key)
11042 ArgChanged = true;
11043
11044 // Transform and check value.
11045 ExprResult Value
11046 = getDerived().TransformExpr(OrigElement.Value);
11047 if (Value.isInvalid())
11048 return ExprError();
11049
11050 if (Value.get() != OrigElement.Value)
11051 ArgChanged = true;
11052
11053 ObjCDictionaryElement Element = {
11054 Key.get(), Value.get(), SourceLocation(), None
11055 };
11056 Elements.push_back(Element);
11057 }
11058
11059 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11060 return SemaRef.MaybeBindToTemporary(E);
11061
11062 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11063 Elements);
11064 }
11065
11066 template<typename Derived>
11067 ExprResult
TransformObjCEncodeExpr(ObjCEncodeExpr * E)11068 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11069 TypeSourceInfo *EncodedTypeInfo
11070 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11071 if (!EncodedTypeInfo)
11072 return ExprError();
11073
11074 if (!getDerived().AlwaysRebuild() &&
11075 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11076 return E;
11077
11078 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11079 EncodedTypeInfo,
11080 E->getRParenLoc());
11081 }
11082
11083 template<typename Derived>
11084 ExprResult TreeTransform<Derived>::
TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr * E)11085 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11086 // This is a kind of implicit conversion, and it needs to get dropped
11087 // and recomputed for the same general reasons that ImplicitCastExprs
11088 // do, as well a more specific one: this expression is only valid when
11089 // it appears *immediately* as an argument expression.
11090 return getDerived().TransformExpr(E->getSubExpr());
11091 }
11092
11093 template<typename Derived>
11094 ExprResult TreeTransform<Derived>::
TransformObjCBridgedCastExpr(ObjCBridgedCastExpr * E)11095 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11096 TypeSourceInfo *TSInfo
11097 = getDerived().TransformType(E->getTypeInfoAsWritten());
11098 if (!TSInfo)
11099 return ExprError();
11100
11101 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11102 if (Result.isInvalid())
11103 return ExprError();
11104
11105 if (!getDerived().AlwaysRebuild() &&
11106 TSInfo == E->getTypeInfoAsWritten() &&
11107 Result.get() == E->getSubExpr())
11108 return E;
11109
11110 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11111 E->getBridgeKeywordLoc(), TSInfo,
11112 Result.get());
11113 }
11114
11115 template<typename Derived>
11116 ExprResult
TransformObjCMessageExpr(ObjCMessageExpr * E)11117 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11118 // Transform arguments.
11119 bool ArgChanged = false;
11120 SmallVector<Expr*, 8> Args;
11121 Args.reserve(E->getNumArgs());
11122 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11123 &ArgChanged))
11124 return ExprError();
11125
11126 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11127 // Class message: transform the receiver type.
11128 TypeSourceInfo *ReceiverTypeInfo
11129 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11130 if (!ReceiverTypeInfo)
11131 return ExprError();
11132
11133 // If nothing changed, just retain the existing message send.
11134 if (!getDerived().AlwaysRebuild() &&
11135 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11136 return SemaRef.MaybeBindToTemporary(E);
11137
11138 // Build a new class message send.
11139 SmallVector<SourceLocation, 16> SelLocs;
11140 E->getSelectorLocs(SelLocs);
11141 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11142 E->getSelector(),
11143 SelLocs,
11144 E->getMethodDecl(),
11145 E->getLeftLoc(),
11146 Args,
11147 E->getRightLoc());
11148 }
11149 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11150 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11151 // Build a new class message send to 'super'.
11152 SmallVector<SourceLocation, 16> SelLocs;
11153 E->getSelectorLocs(SelLocs);
11154 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11155 E->getSelector(),
11156 SelLocs,
11157 E->getReceiverType(),
11158 E->getMethodDecl(),
11159 E->getLeftLoc(),
11160 Args,
11161 E->getRightLoc());
11162 }
11163
11164 // Instance message: transform the receiver
11165 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11166 "Only class and instance messages may be instantiated");
11167 ExprResult Receiver
11168 = getDerived().TransformExpr(E->getInstanceReceiver());
11169 if (Receiver.isInvalid())
11170 return ExprError();
11171
11172 // If nothing changed, just retain the existing message send.
11173 if (!getDerived().AlwaysRebuild() &&
11174 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11175 return SemaRef.MaybeBindToTemporary(E);
11176
11177 // Build a new instance message send.
11178 SmallVector<SourceLocation, 16> SelLocs;
11179 E->getSelectorLocs(SelLocs);
11180 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11181 E->getSelector(),
11182 SelLocs,
11183 E->getMethodDecl(),
11184 E->getLeftLoc(),
11185 Args,
11186 E->getRightLoc());
11187 }
11188
11189 template<typename Derived>
11190 ExprResult
TransformObjCSelectorExpr(ObjCSelectorExpr * E)11191 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11192 return E;
11193 }
11194
11195 template<typename Derived>
11196 ExprResult
TransformObjCProtocolExpr(ObjCProtocolExpr * E)11197 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11198 return E;
11199 }
11200
11201 template<typename Derived>
11202 ExprResult
TransformObjCIvarRefExpr(ObjCIvarRefExpr * E)11203 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11204 // Transform the base expression.
11205 ExprResult Base = getDerived().TransformExpr(E->getBase());
11206 if (Base.isInvalid())
11207 return ExprError();
11208
11209 // We don't need to transform the ivar; it will never change.
11210
11211 // If nothing changed, just retain the existing expression.
11212 if (!getDerived().AlwaysRebuild() &&
11213 Base.get() == E->getBase())
11214 return E;
11215
11216 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11217 E->getLocation(),
11218 E->isArrow(), E->isFreeIvar());
11219 }
11220
11221 template<typename Derived>
11222 ExprResult
TransformObjCPropertyRefExpr(ObjCPropertyRefExpr * E)11223 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
11224 // 'super' and types never change. Property never changes. Just
11225 // retain the existing expression.
11226 if (!E->isObjectReceiver())
11227 return E;
11228
11229 // Transform the base expression.
11230 ExprResult Base = getDerived().TransformExpr(E->getBase());
11231 if (Base.isInvalid())
11232 return ExprError();
11233
11234 // We don't need to transform the property; it will never change.
11235
11236 // If nothing changed, just retain the existing expression.
11237 if (!getDerived().AlwaysRebuild() &&
11238 Base.get() == E->getBase())
11239 return E;
11240
11241 if (E->isExplicitProperty())
11242 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11243 E->getExplicitProperty(),
11244 E->getLocation());
11245
11246 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11247 SemaRef.Context.PseudoObjectTy,
11248 E->getImplicitPropertyGetter(),
11249 E->getImplicitPropertySetter(),
11250 E->getLocation());
11251 }
11252
11253 template<typename Derived>
11254 ExprResult
TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr * E)11255 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11256 // Transform the base expression.
11257 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11258 if (Base.isInvalid())
11259 return ExprError();
11260
11261 // Transform the key expression.
11262 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11263 if (Key.isInvalid())
11264 return ExprError();
11265
11266 // If nothing changed, just retain the existing expression.
11267 if (!getDerived().AlwaysRebuild() &&
11268 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
11269 return E;
11270
11271 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
11272 Base.get(), Key.get(),
11273 E->getAtIndexMethodDecl(),
11274 E->setAtIndexMethodDecl());
11275 }
11276
11277 template<typename Derived>
11278 ExprResult
TransformObjCIsaExpr(ObjCIsaExpr * E)11279 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
11280 // Transform the base expression.
11281 ExprResult Base = getDerived().TransformExpr(E->getBase());
11282 if (Base.isInvalid())
11283 return ExprError();
11284
11285 // If nothing changed, just retain the existing expression.
11286 if (!getDerived().AlwaysRebuild() &&
11287 Base.get() == E->getBase())
11288 return E;
11289
11290 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
11291 E->getOpLoc(),
11292 E->isArrow());
11293 }
11294
11295 template<typename Derived>
11296 ExprResult
TransformShuffleVectorExpr(ShuffleVectorExpr * E)11297 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
11298 bool ArgumentChanged = false;
11299 SmallVector<Expr*, 8> SubExprs;
11300 SubExprs.reserve(E->getNumSubExprs());
11301 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11302 SubExprs, &ArgumentChanged))
11303 return ExprError();
11304
11305 if (!getDerived().AlwaysRebuild() &&
11306 !ArgumentChanged)
11307 return E;
11308
11309 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11310 SubExprs,
11311 E->getRParenLoc());
11312 }
11313
11314 template<typename Derived>
11315 ExprResult
TransformConvertVectorExpr(ConvertVectorExpr * E)11316 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11317 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11318 if (SrcExpr.isInvalid())
11319 return ExprError();
11320
11321 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11322 if (!Type)
11323 return ExprError();
11324
11325 if (!getDerived().AlwaysRebuild() &&
11326 Type == E->getTypeSourceInfo() &&
11327 SrcExpr.get() == E->getSrcExpr())
11328 return E;
11329
11330 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11331 SrcExpr.get(), Type,
11332 E->getRParenLoc());
11333 }
11334
11335 template<typename Derived>
11336 ExprResult
TransformBlockExpr(BlockExpr * E)11337 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
11338 BlockDecl *oldBlock = E->getBlockDecl();
11339
11340 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
11341 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11342
11343 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
11344 blockScope->TheDecl->setBlockMissingReturnType(
11345 oldBlock->blockMissingReturnType());
11346
11347 SmallVector<ParmVarDecl*, 4> params;
11348 SmallVector<QualType, 4> paramTypes;
11349
11350 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11351
11352 // Parameter substitution.
11353 Sema::ExtParameterInfoBuilder extParamInfos;
11354 if (getDerived().TransformFunctionTypeParams(
11355 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11356 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
11357 extParamInfos)) {
11358 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11359 return ExprError();
11360 }
11361
11362 QualType exprResultType =
11363 getDerived().TransformType(exprFunctionType->getReturnType());
11364
11365 auto epi = exprFunctionType->getExtProtoInfo();
11366 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11367
11368 QualType functionType =
11369 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
11370 blockScope->FunctionType = functionType;
11371
11372 // Set the parameters on the block decl.
11373 if (!params.empty())
11374 blockScope->TheDecl->setParams(params);
11375
11376 if (!oldBlock->blockMissingReturnType()) {
11377 blockScope->HasImplicitReturnType = false;
11378 blockScope->ReturnType = exprResultType;
11379 }
11380
11381 // Transform the body
11382 StmtResult body = getDerived().TransformStmt(E->getBody());
11383 if (body.isInvalid()) {
11384 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11385 return ExprError();
11386 }
11387
11388 #ifndef NDEBUG
11389 // In builds with assertions, make sure that we captured everything we
11390 // captured before.
11391 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
11392 for (const auto &I : oldBlock->captures()) {
11393 VarDecl *oldCapture = I.getVariable();
11394
11395 // Ignore parameter packs.
11396 if (isa<ParmVarDecl>(oldCapture) &&
11397 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11398 continue;
11399
11400 VarDecl *newCapture =
11401 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11402 oldCapture));
11403 assert(blockScope->CaptureMap.count(newCapture));
11404 }
11405 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
11406 }
11407 #endif
11408
11409 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
11410 /*Scope=*/nullptr);
11411 }
11412
11413 template<typename Derived>
11414 ExprResult
TransformAsTypeExpr(AsTypeExpr * E)11415 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
11416 llvm_unreachable("Cannot transform asType expressions yet");
11417 }
11418
11419 template<typename Derived>
11420 ExprResult
TransformAtomicExpr(AtomicExpr * E)11421 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
11422 QualType RetTy = getDerived().TransformType(E->getType());
11423 bool ArgumentChanged = false;
11424 SmallVector<Expr*, 8> SubExprs;
11425 SubExprs.reserve(E->getNumSubExprs());
11426 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11427 SubExprs, &ArgumentChanged))
11428 return ExprError();
11429
11430 if (!getDerived().AlwaysRebuild() &&
11431 !ArgumentChanged)
11432 return E;
11433
11434 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
11435 RetTy, E->getOp(), E->getRParenLoc());
11436 }
11437
11438 //===----------------------------------------------------------------------===//
11439 // Type reconstruction
11440 //===----------------------------------------------------------------------===//
11441
11442 template<typename Derived>
RebuildPointerType(QualType PointeeType,SourceLocation Star)11443 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11444 SourceLocation Star) {
11445 return SemaRef.BuildPointerType(PointeeType, Star,
11446 getDerived().getBaseEntity());
11447 }
11448
11449 template<typename Derived>
RebuildBlockPointerType(QualType PointeeType,SourceLocation Star)11450 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11451 SourceLocation Star) {
11452 return SemaRef.BuildBlockPointerType(PointeeType, Star,
11453 getDerived().getBaseEntity());
11454 }
11455
11456 template<typename Derived>
11457 QualType
RebuildReferenceType(QualType ReferentType,bool WrittenAsLValue,SourceLocation Sigil)11458 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11459 bool WrittenAsLValue,
11460 SourceLocation Sigil) {
11461 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
11462 Sigil, getDerived().getBaseEntity());
11463 }
11464
11465 template<typename Derived>
11466 QualType
RebuildMemberPointerType(QualType PointeeType,QualType ClassType,SourceLocation Sigil)11467 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11468 QualType ClassType,
11469 SourceLocation Sigil) {
11470 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11471 getDerived().getBaseEntity());
11472 }
11473
11474 template<typename Derived>
RebuildObjCObjectType(QualType BaseType,SourceLocation Loc,SourceLocation TypeArgsLAngleLoc,ArrayRef<TypeSourceInfo * > TypeArgs,SourceLocation TypeArgsRAngleLoc,SourceLocation ProtocolLAngleLoc,ArrayRef<ObjCProtocolDecl * > Protocols,ArrayRef<SourceLocation> ProtocolLocs,SourceLocation ProtocolRAngleLoc)11475 QualType TreeTransform<Derived>::RebuildObjCObjectType(
11476 QualType BaseType,
11477 SourceLocation Loc,
11478 SourceLocation TypeArgsLAngleLoc,
11479 ArrayRef<TypeSourceInfo *> TypeArgs,
11480 SourceLocation TypeArgsRAngleLoc,
11481 SourceLocation ProtocolLAngleLoc,
11482 ArrayRef<ObjCProtocolDecl *> Protocols,
11483 ArrayRef<SourceLocation> ProtocolLocs,
11484 SourceLocation ProtocolRAngleLoc) {
11485 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11486 TypeArgs, TypeArgsRAngleLoc,
11487 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11488 ProtocolRAngleLoc,
11489 /*FailOnError=*/true);
11490 }
11491
11492 template<typename Derived>
RebuildObjCObjectPointerType(QualType PointeeType,SourceLocation Star)11493 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11494 QualType PointeeType,
11495 SourceLocation Star) {
11496 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11497 }
11498
11499 template<typename Derived>
11500 QualType
RebuildArrayType(QualType ElementType,ArrayType::ArraySizeModifier SizeMod,const llvm::APInt * Size,Expr * SizeExpr,unsigned IndexTypeQuals,SourceRange BracketsRange)11501 TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11502 ArrayType::ArraySizeModifier SizeMod,
11503 const llvm::APInt *Size,
11504 Expr *SizeExpr,
11505 unsigned IndexTypeQuals,
11506 SourceRange BracketsRange) {
11507 if (SizeExpr || !Size)
11508 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11509 IndexTypeQuals, BracketsRange,
11510 getDerived().getBaseEntity());
11511
11512 QualType Types[] = {
11513 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11514 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11515 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
11516 };
11517 const unsigned NumTypes = llvm::array_lengthof(Types);
11518 QualType SizeType;
11519 for (unsigned I = 0; I != NumTypes; ++I)
11520 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11521 SizeType = Types[I];
11522 break;
11523 }
11524
11525 // Note that we can return a VariableArrayType here in the case where
11526 // the element type was a dependent VariableArrayType.
11527 IntegerLiteral *ArraySize
11528 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11529 /*FIXME*/BracketsRange.getBegin());
11530 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
11531 IndexTypeQuals, BracketsRange,
11532 getDerived().getBaseEntity());
11533 }
11534
11535 template<typename Derived>
11536 QualType
RebuildConstantArrayType(QualType ElementType,ArrayType::ArraySizeModifier SizeMod,const llvm::APInt & Size,unsigned IndexTypeQuals,SourceRange BracketsRange)11537 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
11538 ArrayType::ArraySizeModifier SizeMod,
11539 const llvm::APInt &Size,
11540 unsigned IndexTypeQuals,
11541 SourceRange BracketsRange) {
11542 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
11543 IndexTypeQuals, BracketsRange);
11544 }
11545
11546 template<typename Derived>
11547 QualType
RebuildIncompleteArrayType(QualType ElementType,ArrayType::ArraySizeModifier SizeMod,unsigned IndexTypeQuals,SourceRange BracketsRange)11548 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
11549 ArrayType::ArraySizeModifier SizeMod,
11550 unsigned IndexTypeQuals,
11551 SourceRange BracketsRange) {
11552 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
11553 IndexTypeQuals, BracketsRange);
11554 }
11555
11556 template<typename Derived>
11557 QualType
RebuildVariableArrayType(QualType ElementType,ArrayType::ArraySizeModifier SizeMod,Expr * SizeExpr,unsigned IndexTypeQuals,SourceRange BracketsRange)11558 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
11559 ArrayType::ArraySizeModifier SizeMod,
11560 Expr *SizeExpr,
11561 unsigned IndexTypeQuals,
11562 SourceRange BracketsRange) {
11563 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11564 SizeExpr,
11565 IndexTypeQuals, BracketsRange);
11566 }
11567
11568 template<typename Derived>
11569 QualType
RebuildDependentSizedArrayType(QualType ElementType,ArrayType::ArraySizeModifier SizeMod,Expr * SizeExpr,unsigned IndexTypeQuals,SourceRange BracketsRange)11570 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
11571 ArrayType::ArraySizeModifier SizeMod,
11572 Expr *SizeExpr,
11573 unsigned IndexTypeQuals,
11574 SourceRange BracketsRange) {
11575 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11576 SizeExpr,
11577 IndexTypeQuals, BracketsRange);
11578 }
11579
11580 template<typename Derived>
RebuildVectorType(QualType ElementType,unsigned NumElements,VectorType::VectorKind VecKind)11581 QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
11582 unsigned NumElements,
11583 VectorType::VectorKind VecKind) {
11584 // FIXME: semantic checking!
11585 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
11586 }
11587
11588 template<typename Derived>
RebuildExtVectorType(QualType ElementType,unsigned NumElements,SourceLocation AttributeLoc)11589 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11590 unsigned NumElements,
11591 SourceLocation AttributeLoc) {
11592 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11593 NumElements, true);
11594 IntegerLiteral *VectorSize
11595 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11596 AttributeLoc);
11597 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
11598 }
11599
11600 template<typename Derived>
11601 QualType
RebuildDependentSizedExtVectorType(QualType ElementType,Expr * SizeExpr,SourceLocation AttributeLoc)11602 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
11603 Expr *SizeExpr,
11604 SourceLocation AttributeLoc) {
11605 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
11606 }
11607
11608 template<typename Derived>
RebuildFunctionProtoType(QualType T,MutableArrayRef<QualType> ParamTypes,const FunctionProtoType::ExtProtoInfo & EPI)11609 QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11610 QualType T,
11611 MutableArrayRef<QualType> ParamTypes,
11612 const FunctionProtoType::ExtProtoInfo &EPI) {
11613 return SemaRef.BuildFunctionType(T, ParamTypes,
11614 getDerived().getBaseLocation(),
11615 getDerived().getBaseEntity(),
11616 EPI);
11617 }
11618
11619 template<typename Derived>
RebuildFunctionNoProtoType(QualType T)11620 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11621 return SemaRef.Context.getFunctionNoProtoType(T);
11622 }
11623
11624 template<typename Derived>
RebuildUnresolvedUsingType(Decl * D)11625 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11626 assert(D && "no decl found");
11627 if (D->isInvalidDecl()) return QualType();
11628
11629 // FIXME: Doesn't account for ObjCInterfaceDecl!
11630 TypeDecl *Ty;
11631 if (isa<UsingDecl>(D)) {
11632 UsingDecl *Using = cast<UsingDecl>(D);
11633 assert(Using->hasTypename() &&
11634 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11635
11636 // A valid resolved using typename decl points to exactly one type decl.
11637 assert(++Using->shadow_begin() == Using->shadow_end());
11638 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
11639
11640 } else {
11641 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11642 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11643 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11644 }
11645
11646 return SemaRef.Context.getTypeDeclType(Ty);
11647 }
11648
11649 template<typename Derived>
RebuildTypeOfExprType(Expr * E,SourceLocation Loc)11650 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11651 SourceLocation Loc) {
11652 return SemaRef.BuildTypeofExprType(E, Loc);
11653 }
11654
11655 template<typename Derived>
RebuildTypeOfType(QualType Underlying)11656 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11657 return SemaRef.Context.getTypeOfType(Underlying);
11658 }
11659
11660 template<typename Derived>
RebuildDecltypeType(Expr * E,SourceLocation Loc)11661 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11662 SourceLocation Loc) {
11663 return SemaRef.BuildDecltypeType(E, Loc);
11664 }
11665
11666 template<typename Derived>
RebuildUnaryTransformType(QualType BaseType,UnaryTransformType::UTTKind UKind,SourceLocation Loc)11667 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11668 UnaryTransformType::UTTKind UKind,
11669 SourceLocation Loc) {
11670 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11671 }
11672
11673 template<typename Derived>
RebuildTemplateSpecializationType(TemplateName Template,SourceLocation TemplateNameLoc,TemplateArgumentListInfo & TemplateArgs)11674 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
11675 TemplateName Template,
11676 SourceLocation TemplateNameLoc,
11677 TemplateArgumentListInfo &TemplateArgs) {
11678 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
11679 }
11680
11681 template<typename Derived>
RebuildAtomicType(QualType ValueType,SourceLocation KWLoc)11682 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11683 SourceLocation KWLoc) {
11684 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11685 }
11686
11687 template<typename Derived>
RebuildPipeType(QualType ValueType,SourceLocation KWLoc)11688 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
11689 SourceLocation KWLoc) {
11690 return SemaRef.BuildPipeType(ValueType, KWLoc);
11691 }
11692
11693 template<typename Derived>
11694 TemplateName
RebuildTemplateName(CXXScopeSpec & SS,bool TemplateKW,TemplateDecl * Template)11695 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11696 bool TemplateKW,
11697 TemplateDecl *Template) {
11698 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
11699 Template);
11700 }
11701
11702 template<typename Derived>
11703 TemplateName
RebuildTemplateName(CXXScopeSpec & SS,const IdentifierInfo & Name,SourceLocation NameLoc,QualType ObjectType,NamedDecl * FirstQualifierInScope)11704 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11705 const IdentifierInfo &Name,
11706 SourceLocation NameLoc,
11707 QualType ObjectType,
11708 NamedDecl *FirstQualifierInScope) {
11709 UnqualifiedId TemplateName;
11710 TemplateName.setIdentifier(&Name, NameLoc);
11711 Sema::TemplateTy Template;
11712 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11713 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11714 SS, TemplateKWLoc, TemplateName,
11715 ParsedType::make(ObjectType),
11716 /*EnteringContext=*/false,
11717 Template);
11718 return Template.get();
11719 }
11720
11721 template<typename Derived>
11722 TemplateName
RebuildTemplateName(CXXScopeSpec & SS,OverloadedOperatorKind Operator,SourceLocation NameLoc,QualType ObjectType)11723 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11724 OverloadedOperatorKind Operator,
11725 SourceLocation NameLoc,
11726 QualType ObjectType) {
11727 UnqualifiedId Name;
11728 // FIXME: Bogus location information.
11729 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
11730 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
11731 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11732 Sema::TemplateTy Template;
11733 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11734 SS, TemplateKWLoc, Name,
11735 ParsedType::make(ObjectType),
11736 /*EnteringContext=*/false,
11737 Template);
11738 return Template.get();
11739 }
11740
11741 template<typename Derived>
11742 ExprResult
RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,SourceLocation OpLoc,Expr * OrigCallee,Expr * First,Expr * Second)11743 TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11744 SourceLocation OpLoc,
11745 Expr *OrigCallee,
11746 Expr *First,
11747 Expr *Second) {
11748 Expr *Callee = OrigCallee->IgnoreParenCasts();
11749 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
11750
11751 if (First->getObjectKind() == OK_ObjCProperty) {
11752 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11753 if (BinaryOperator::isAssignmentOp(Opc))
11754 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11755 First, Second);
11756 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11757 if (Result.isInvalid())
11758 return ExprError();
11759 First = Result.get();
11760 }
11761
11762 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11763 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11764 if (Result.isInvalid())
11765 return ExprError();
11766 Second = Result.get();
11767 }
11768
11769 // Determine whether this should be a builtin operation.
11770 if (Op == OO_Subscript) {
11771 if (!First->getType()->isOverloadableType() &&
11772 !Second->getType()->isOverloadableType())
11773 return getSema().CreateBuiltinArraySubscriptExpr(First,
11774 Callee->getLocStart(),
11775 Second, OpLoc);
11776 } else if (Op == OO_Arrow) {
11777 // -> is never a builtin operation.
11778 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11779 } else if (Second == nullptr || isPostIncDec) {
11780 if (!First->getType()->isOverloadableType()) {
11781 // The argument is not of overloadable type, so try to create a
11782 // built-in unary operation.
11783 UnaryOperatorKind Opc
11784 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
11785
11786 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
11787 }
11788 } else {
11789 if (!First->getType()->isOverloadableType() &&
11790 !Second->getType()->isOverloadableType()) {
11791 // Neither of the arguments is an overloadable type, so try to
11792 // create a built-in binary operation.
11793 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11794 ExprResult Result
11795 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
11796 if (Result.isInvalid())
11797 return ExprError();
11798
11799 return Result;
11800 }
11801 }
11802
11803 // Compute the transformed set of functions (and function templates) to be
11804 // used during overload resolution.
11805 UnresolvedSet<16> Functions;
11806
11807 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
11808 assert(ULE->requiresADL());
11809 Functions.append(ULE->decls_begin(), ULE->decls_end());
11810 } else {
11811 // If we've resolved this to a particular non-member function, just call
11812 // that function. If we resolved it to a member function,
11813 // CreateOverloaded* will find that function for us.
11814 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11815 if (!isa<CXXMethodDecl>(ND))
11816 Functions.addDecl(ND);
11817 }
11818
11819 // Add any functions found via argument-dependent lookup.
11820 Expr *Args[2] = { First, Second };
11821 unsigned NumArgs = 1 + (Second != nullptr);
11822
11823 // Create the overloaded operator invocation for unary operators.
11824 if (NumArgs == 1 || isPostIncDec) {
11825 UnaryOperatorKind Opc
11826 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
11827 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
11828 }
11829
11830 if (Op == OO_Subscript) {
11831 SourceLocation LBrace;
11832 SourceLocation RBrace;
11833
11834 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
11835 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
11836 LBrace = SourceLocation::getFromRawEncoding(
11837 NameLoc.CXXOperatorName.BeginOpNameLoc);
11838 RBrace = SourceLocation::getFromRawEncoding(
11839 NameLoc.CXXOperatorName.EndOpNameLoc);
11840 } else {
11841 LBrace = Callee->getLocStart();
11842 RBrace = OpLoc;
11843 }
11844
11845 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11846 First, Second);
11847 }
11848
11849 // Create the overloaded operator invocation for binary operators.
11850 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11851 ExprResult Result
11852 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11853 if (Result.isInvalid())
11854 return ExprError();
11855
11856 return Result;
11857 }
11858
11859 template<typename Derived>
11860 ExprResult
RebuildCXXPseudoDestructorExpr(Expr * Base,SourceLocation OperatorLoc,bool isArrow,CXXScopeSpec & SS,TypeSourceInfo * ScopeType,SourceLocation CCLoc,SourceLocation TildeLoc,PseudoDestructorTypeStorage Destroyed)11861 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
11862 SourceLocation OperatorLoc,
11863 bool isArrow,
11864 CXXScopeSpec &SS,
11865 TypeSourceInfo *ScopeType,
11866 SourceLocation CCLoc,
11867 SourceLocation TildeLoc,
11868 PseudoDestructorTypeStorage Destroyed) {
11869 QualType BaseType = Base->getType();
11870 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
11871 (!isArrow && !BaseType->getAs<RecordType>()) ||
11872 (isArrow && BaseType->getAs<PointerType>() &&
11873 !BaseType->getAs<PointerType>()->getPointeeType()
11874 ->template getAs<RecordType>())){
11875 // This pseudo-destructor expression is still a pseudo-destructor.
11876 return SemaRef.BuildPseudoDestructorExpr(
11877 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11878 CCLoc, TildeLoc, Destroyed);
11879 }
11880
11881 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
11882 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11883 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11884 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11885 NameInfo.setNamedTypeInfo(DestroyedType);
11886
11887 // The scope type is now known to be a valid nested name specifier
11888 // component. Tack it on to the end of the nested name specifier.
11889 if (ScopeType) {
11890 if (!ScopeType->getType()->getAs<TagType>()) {
11891 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11892 diag::err_expected_class_or_namespace)
11893 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11894 return ExprError();
11895 }
11896 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11897 CCLoc);
11898 }
11899
11900 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11901 return getSema().BuildMemberReferenceExpr(Base, BaseType,
11902 OperatorLoc, isArrow,
11903 SS, TemplateKWLoc,
11904 /*FIXME: FirstQualifier*/ nullptr,
11905 NameInfo,
11906 /*TemplateArgs*/ nullptr,
11907 /*S*/nullptr);
11908 }
11909
11910 template<typename Derived>
11911 StmtResult
TransformCapturedStmt(CapturedStmt * S)11912 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
11913 SourceLocation Loc = S->getLocStart();
11914 CapturedDecl *CD = S->getCapturedDecl();
11915 unsigned NumParams = CD->getNumParams();
11916 unsigned ContextParamPos = CD->getContextParamPosition();
11917 SmallVector<Sema::CapturedParamNameType, 4> Params;
11918 for (unsigned I = 0; I < NumParams; ++I) {
11919 if (I != ContextParamPos) {
11920 Params.push_back(
11921 std::make_pair(
11922 CD->getParam(I)->getName(),
11923 getDerived().TransformType(CD->getParam(I)->getType())));
11924 } else {
11925 Params.push_back(std::make_pair(StringRef(), QualType()));
11926 }
11927 }
11928 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
11929 S->getCapturedRegionKind(), Params);
11930 StmtResult Body;
11931 {
11932 Sema::CompoundScopeRAII CompoundScope(getSema());
11933 Body = getDerived().TransformStmt(S->getCapturedStmt());
11934 }
11935
11936 if (Body.isInvalid()) {
11937 getSema().ActOnCapturedRegionError();
11938 return StmtError();
11939 }
11940
11941 return getSema().ActOnCapturedRegionEnd(Body.get());
11942 }
11943
11944 } // end namespace clang
11945
11946 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
11947