clang  5.0.0
TreeTransform.h
Go to the documentation of this file.
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 "CoroutineStmtBuilder.h"
18 #include "TypeLocBuilder.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/DeclTemplate.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/ExprCXX.h"
24 #include "clang/AST/ExprObjC.h"
25 #include "clang/AST/ExprOpenMP.h"
26 #include "clang/AST/Stmt.h"
27 #include "clang/AST/StmtCXX.h"
28 #include "clang/AST/StmtObjC.h"
29 #include "clang/AST/StmtOpenMP.h"
30 #include "clang/Sema/Designator.h"
31 #include "clang/Sema/Lookup.h"
32 #include "clang/Sema/Ownership.h"
34 #include "clang/Sema/ScopeInfo.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include <algorithm>
40 
41 namespace clang {
42 using namespace sema;
43 
44 /// \brief A semantic tree transformation that allows one to transform one
45 /// abstract syntax tree into another.
46 ///
47 /// A new tree transformation is defined by creating a new subclass \c X of
48 /// \c TreeTransform<X> and then overriding certain operations to provide
49 /// behavior specific to that transformation. For example, template
50 /// instantiation is implemented as a tree transformation where the
51 /// transformation of TemplateTypeParmType nodes involves substituting the
52 /// template arguments for their corresponding template parameters; a similar
53 /// transformation is performed for non-type template parameters and
54 /// template template parameters.
55 ///
56 /// This tree-transformation template uses static polymorphism to allow
57 /// subclasses to customize any of its operations. Thus, a subclass can
58 /// override any of the transformation or rebuild operators by providing an
59 /// operation with the same signature as the default implementation. The
60 /// overridding function should not be virtual.
61 ///
62 /// Semantic tree transformations are split into two stages, either of which
63 /// can be replaced by a subclass. The "transform" step transforms an AST node
64 /// or the parts of an AST node using the various transformation functions,
65 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
66 /// node of the appropriate kind from the pieces. The default transformation
67 /// routines recursively transform the operands to composite AST nodes (e.g.,
68 /// the pointee type of a PointerType node) and, if any of those operand nodes
69 /// were changed by the transformation, invokes the rebuild operation to create
70 /// a new AST node.
71 ///
72 /// Subclasses can customize the transformation at various levels. The
73 /// most coarse-grained transformations involve replacing TransformType(),
74 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
75 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
76 /// new implementations.
77 ///
78 /// For more fine-grained transformations, subclasses can replace any of the
79 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
80 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
81 /// replacing TransformTemplateTypeParmType() allows template instantiation
82 /// to substitute template arguments for their corresponding template
83 /// parameters. Additionally, subclasses can override the \c RebuildXXX
84 /// functions to control how AST nodes are rebuilt when their operands change.
85 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
86 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
87 /// be able to use more efficient rebuild steps.
88 ///
89 /// There are a handful of other functions that can be overridden, allowing one
90 /// to avoid traversing nodes that don't need any transformation
91 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
92 /// operands have not changed (\c AlwaysRebuild()), and customize the
93 /// default locations and entity names used for type-checking
94 /// (\c getBaseLocation(), \c getBaseEntity()).
95 template<typename Derived>
97  /// \brief Private RAII object that helps us forget and then re-remember
98  /// the template argument corresponding to a partially-substituted parameter
99  /// pack.
100  class ForgetPartiallySubstitutedPackRAII {
101  Derived &Self;
102  TemplateArgument Old;
103 
104  public:
105  ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
106  Old = Self.ForgetPartiallySubstitutedPack();
107  }
108 
109  ~ForgetPartiallySubstitutedPackRAII() {
110  Self.RememberPartiallySubstitutedPack(Old);
111  }
112  };
113 
114 protected:
116 
117  /// \brief The set of local declarations that have been transformed, for
118  /// cases where we are forced to build new declarations within the transformer
119  /// rather than in the subclass (e.g., lambda closure types).
120  llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
121 
122 public:
123  /// \brief Initializes a new tree transformer.
124  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
125 
126  /// \brief Retrieves a reference to the derived class.
127  Derived &getDerived() { return static_cast<Derived&>(*this); }
128 
129  /// \brief Retrieves a reference to the derived class.
130  const Derived &getDerived() const {
131  return static_cast<const Derived&>(*this);
132  }
133 
134  static inline ExprResult Owned(Expr *E) { return E; }
135  static inline StmtResult Owned(Stmt *S) { return S; }
136 
137  /// \brief Retrieves a reference to the semantic analysis object used for
138  /// this tree transform.
139  Sema &getSema() const { return SemaRef; }
140 
141  /// \brief Whether the transformation should always rebuild AST nodes, even
142  /// if none of the children have changed.
143  ///
144  /// Subclasses may override this function to specify when the transformation
145  /// should rebuild all AST nodes.
146  ///
147  /// We must always rebuild all AST nodes when performing variadic template
148  /// pack expansion, in order to avoid violating the AST invariant that each
149  /// statement node appears at most once in its containing declaration.
150  bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
151 
152  /// \brief Returns the location of the entity being transformed, if that
153  /// information was not available elsewhere in the AST.
154  ///
155  /// By default, returns no source-location information. Subclasses can
156  /// provide an alternative implementation that provides better location
157  /// information.
159 
160  /// \brief Returns the name of the entity being transformed, if that
161  /// information was not available elsewhere in the AST.
162  ///
163  /// By default, returns an empty name. Subclasses can provide an alternative
164  /// implementation with a more precise name.
166 
167  /// \brief Sets the "base" location and entity when that
168  /// information is known based on another transformation.
169  ///
170  /// By default, the source location and entity are ignored. Subclasses can
171  /// override this function to provide a customized implementation.
172  void setBase(SourceLocation Loc, DeclarationName Entity) { }
173 
174  /// \brief RAII object that temporarily sets the base location and entity
175  /// used for reporting diagnostics in types.
177  TreeTransform &Self;
178  SourceLocation OldLocation;
179  DeclarationName OldEntity;
180 
181  public:
183  DeclarationName Entity) : Self(Self) {
184  OldLocation = Self.getDerived().getBaseLocation();
185  OldEntity = Self.getDerived().getBaseEntity();
186 
187  if (Location.isValid())
188  Self.getDerived().setBase(Location, Entity);
189  }
190 
192  Self.getDerived().setBase(OldLocation, OldEntity);
193  }
194  };
195 
196  /// \brief Determine whether the given type \p T has already been
197  /// transformed.
198  ///
199  /// Subclasses can provide an alternative implementation of this routine
200  /// to short-circuit evaluation when it is known that a given type will
201  /// not change. For example, template instantiation need not traverse
202  /// non-dependent types.
204  return T.isNull();
205  }
206 
207  /// \brief Determine whether the given call argument should be dropped, e.g.,
208  /// because it is a default argument.
209  ///
210  /// Subclasses can provide an alternative implementation of this routine to
211  /// determine which kinds of call arguments get dropped. By default,
212  /// CXXDefaultArgument nodes are dropped (prior to transformation).
214  return E->isDefaultArgument();
215  }
216 
217  /// \brief Determine whether we should expand a pack expansion with the
218  /// given set of parameter packs into separate arguments by repeatedly
219  /// transforming the pattern.
220  ///
221  /// By default, the transformer never tries to expand pack expansions.
222  /// Subclasses can override this routine to provide different behavior.
223  ///
224  /// \param EllipsisLoc The location of the ellipsis that identifies the
225  /// pack expansion.
226  ///
227  /// \param PatternRange The source range that covers the entire pattern of
228  /// the pack expansion.
229  ///
230  /// \param Unexpanded The set of unexpanded parameter packs within the
231  /// pattern.
232  ///
233  /// \param ShouldExpand Will be set to \c true if the transformer should
234  /// expand the corresponding pack expansions into separate arguments. When
235  /// set, \c NumExpansions must also be set.
236  ///
237  /// \param RetainExpansion Whether the caller should add an unexpanded
238  /// pack expansion after all of the expanded arguments. This is used
239  /// when extending explicitly-specified template argument packs per
240  /// C++0x [temp.arg.explicit]p9.
241  ///
242  /// \param NumExpansions The number of separate arguments that will be in
243  /// the expanded form of the corresponding pack expansion. This is both an
244  /// input and an output parameter, which can be set by the caller if the
245  /// number of expansions is known a priori (e.g., due to a prior substitution)
246  /// and will be set by the callee when the number of expansions is known.
247  /// The callee must set this value when \c ShouldExpand is \c true; it may
248  /// set this value in other cases.
249  ///
250  /// \returns true if an error occurred (e.g., because the parameter packs
251  /// are to be instantiated with arguments of different lengths), false
252  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
253  /// must be set.
255  SourceRange PatternRange,
257  bool &ShouldExpand,
258  bool &RetainExpansion,
259  Optional<unsigned> &NumExpansions) {
260  ShouldExpand = false;
261  return false;
262  }
263 
264  /// \brief "Forget" about the partially-substituted pack template argument,
265  /// when performing an instantiation that must preserve the parameter pack
266  /// use.
267  ///
268  /// This routine is meant to be overridden by the template instantiator.
270  return TemplateArgument();
271  }
272 
273  /// \brief "Remember" the partially-substituted pack template argument
274  /// after performing an instantiation that must preserve the parameter pack
275  /// use.
276  ///
277  /// This routine is meant to be overridden by the template instantiator.
279 
280  /// \brief Note to the derived class when a function parameter pack is
281  /// being expanded.
283 
284  /// \brief Transforms the given type into another type.
285  ///
286  /// By default, this routine transforms a type by creating a
287  /// TypeSourceInfo for it and delegating to the appropriate
288  /// function. This is expensive, but we don't mind, because
289  /// this method is deprecated anyway; all users should be
290  /// switched to storing TypeSourceInfos.
291  ///
292  /// \returns the transformed type.
293  QualType TransformType(QualType T);
294 
295  /// \brief Transforms the given type-with-location into a new
296  /// type-with-location.
297  ///
298  /// By default, this routine transforms a type by delegating to the
299  /// appropriate TransformXXXType to build a new type. Subclasses
300  /// may override this function (to take over all type
301  /// transformations) or some set of the TransformXXXType functions
302  /// to alter the transformation.
303  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
304 
305  /// \brief Transform the given type-with-location into a new
306  /// type, collecting location information in the given builder
307  /// as necessary.
308  ///
309  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
310 
311  /// \brief Transform a type that is permitted to produce a
312  /// DeducedTemplateSpecializationType.
313  ///
314  /// This is used in the (relatively rare) contexts where it is acceptable
315  /// for transformation to produce a class template type with deduced
316  /// template arguments.
317  /// @{
318  QualType TransformTypeWithDeducedTST(QualType T);
319  TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
320  /// @}
321 
322  /// \brief Transform the given statement.
323  ///
324  /// By default, this routine transforms a statement by delegating to the
325  /// appropriate TransformXXXStmt function to transform a specific kind of
326  /// statement or the TransformExpr() function to transform an expression.
327  /// Subclasses may override this function to transform statements using some
328  /// other mechanism.
329  ///
330  /// \returns the transformed statement.
331  StmtResult TransformStmt(Stmt *S);
332 
333  /// \brief Transform the given statement.
334  ///
335  /// By default, this routine transforms a statement by delegating to the
336  /// appropriate TransformOMPXXXClause function to transform a specific kind
337  /// of clause. Subclasses may override this function to transform statements
338  /// using some other mechanism.
339  ///
340  /// \returns the transformed OpenMP clause.
341  OMPClause *TransformOMPClause(OMPClause *S);
342 
343  /// \brief Transform the given attribute.
344  ///
345  /// By default, this routine transforms a statement by delegating to the
346  /// appropriate TransformXXXAttr function to transform a specific kind
347  /// of attribute. Subclasses may override this function to transform
348  /// attributed statements using some other mechanism.
349  ///
350  /// \returns the transformed attribute
351  const Attr *TransformAttr(const Attr *S);
352 
353 /// \brief Transform the specified attribute.
354 ///
355 /// Subclasses should override the transformation of attributes with a pragma
356 /// spelling to transform expressions stored within the attribute.
357 ///
358 /// \returns the transformed attribute.
359 #define ATTR(X)
360 #define PRAGMA_SPELLING_ATTR(X) \
361  const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
362 #include "clang/Basic/AttrList.inc"
363 
364  /// \brief Transform the given expression.
365  ///
366  /// By default, this routine transforms an expression by delegating to the
367  /// appropriate TransformXXXExpr function to build a new expression.
368  /// Subclasses may override this function to transform expressions using some
369  /// other mechanism.
370  ///
371  /// \returns the transformed expression.
372  ExprResult TransformExpr(Expr *E);
373 
374  /// \brief Transform the given initializer.
375  ///
376  /// By default, this routine transforms an initializer by stripping off the
377  /// semantic nodes added by initialization, then passing the result to
378  /// TransformExpr or TransformExprs.
379  ///
380  /// \returns the transformed initializer.
381  ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
382 
383  /// \brief Transform the given list of expressions.
384  ///
385  /// This routine transforms a list of expressions by invoking
386  /// \c TransformExpr() for each subexpression. However, it also provides
387  /// support for variadic templates by expanding any pack expansions (if the
388  /// derived class permits such expansion) along the way. When pack expansions
389  /// are present, the number of outputs may not equal the number of inputs.
390  ///
391  /// \param Inputs The set of expressions to be transformed.
392  ///
393  /// \param NumInputs The number of expressions in \c Inputs.
394  ///
395  /// \param IsCall If \c true, then this transform is being performed on
396  /// function-call arguments, and any arguments that should be dropped, will
397  /// be.
398  ///
399  /// \param Outputs The transformed input expressions will be added to this
400  /// vector.
401  ///
402  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
403  /// due to transformation.
404  ///
405  /// \returns true if an error occurred, false otherwise.
406  bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
407  SmallVectorImpl<Expr *> &Outputs,
408  bool *ArgChanged = nullptr);
409 
410  /// \brief Transform the given declaration, which is referenced from a type
411  /// or expression.
412  ///
413  /// By default, acts as the identity function on declarations, unless the
414  /// transformer has had to transform the declaration itself. Subclasses
415  /// may override this function to provide alternate behavior.
417  llvm::DenseMap<Decl *, Decl *>::iterator Known
418  = TransformedLocalDecls.find(D);
419  if (Known != TransformedLocalDecls.end())
420  return Known->second;
421 
422  return D;
423  }
424 
425  /// \brief Transform the specified condition.
426  ///
427  /// By default, this transforms the variable and expression and rebuilds
428  /// the condition.
429  Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
430  Expr *Expr,
432 
433  /// \brief Transform the attributes associated with the given declaration and
434  /// place them on the new declaration.
435  ///
436  /// By default, this operation does nothing. Subclasses may override this
437  /// behavior to transform attributes.
438  void transformAttrs(Decl *Old, Decl *New) { }
439 
440  /// \brief Note that a local declaration has been transformed by this
441  /// transformer.
442  ///
443  /// Local declarations are typically transformed via a call to
444  /// TransformDefinition. However, in some cases (e.g., lambda expressions),
445  /// the transformer itself has to transform the declarations. This routine
446  /// can be overridden by a subclass that keeps track of such mappings.
447  void transformedLocalDecl(Decl *Old, Decl *New) {
448  TransformedLocalDecls[Old] = New;
449  }
450 
451  /// \brief Transform the definition of the given declaration.
452  ///
453  /// By default, invokes TransformDecl() to transform the declaration.
454  /// Subclasses may override this function to provide alternate behavior.
456  return getDerived().TransformDecl(Loc, D);
457  }
458 
459  /// \brief Transform the given declaration, which was the first part of a
460  /// nested-name-specifier in a member access expression.
461  ///
462  /// This specific declaration transformation only applies to the first
463  /// identifier in a nested-name-specifier of a member access expression, e.g.,
464  /// the \c T in \c x->T::member
465  ///
466  /// By default, invokes TransformDecl() to transform the declaration.
467  /// Subclasses may override this function to provide alternate behavior.
469  return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
470  }
471 
472  /// Transform the set of declarations in an OverloadExpr.
473  bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
474  LookupResult &R);
475 
476  /// \brief Transform the given nested-name-specifier with source-location
477  /// information.
478  ///
479  /// By default, transforms all of the types and declarations within the
480  /// nested-name-specifier. Subclasses may override this function to provide
481  /// alternate behavior.
483  TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
484  QualType ObjectType = QualType(),
485  NamedDecl *FirstQualifierInScope = nullptr);
486 
487  /// \brief Transform the given declaration name.
488  ///
489  /// By default, transforms the types of conversion function, constructor,
490  /// and destructor names and then (if needed) rebuilds the declaration name.
491  /// Identifiers and selectors are returned unmodified. Sublcasses may
492  /// override this function to provide alternate behavior.
494  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
495 
496  /// \brief Transform the given template name.
497  ///
498  /// \param SS The nested-name-specifier that qualifies the template
499  /// name. This nested-name-specifier must already have been transformed.
500  ///
501  /// \param Name The template name to transform.
502  ///
503  /// \param NameLoc The source location of the template name.
504  ///
505  /// \param ObjectType If we're translating a template name within a member
506  /// access expression, this is the type of the object whose member template
507  /// is being referenced.
508  ///
509  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
510  /// also refers to a name within the current (lexical) scope, this is the
511  /// declaration it refers to.
512  ///
513  /// By default, transforms the template name by transforming the declarations
514  /// and nested-name-specifiers that occur within the template name.
515  /// Subclasses may override this function to provide alternate behavior.
517  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
518  SourceLocation NameLoc,
519  QualType ObjectType = QualType(),
520  NamedDecl *FirstQualifierInScope = nullptr,
521  bool AllowInjectedClassName = false);
522 
523  /// \brief Transform the given template argument.
524  ///
525  /// By default, this operation transforms the type, expression, or
526  /// declaration stored within the template argument and constructs a
527  /// new template argument from the transformed result. Subclasses may
528  /// override this function to provide alternate behavior.
529  ///
530  /// Returns true if there was an error.
531  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
532  TemplateArgumentLoc &Output,
533  bool Uneval = false);
534 
535  /// \brief Transform the given set of template arguments.
536  ///
537  /// By default, this operation transforms all of the template arguments
538  /// in the input set using \c TransformTemplateArgument(), and appends
539  /// the transformed arguments to the output list.
540  ///
541  /// Note that this overload of \c TransformTemplateArguments() is merely
542  /// a convenience function. Subclasses that wish to override this behavior
543  /// should override the iterator-based member template version.
544  ///
545  /// \param Inputs The set of template arguments to be transformed.
546  ///
547  /// \param NumInputs The number of template arguments in \p Inputs.
548  ///
549  /// \param Outputs The set of transformed template arguments output by this
550  /// routine.
551  ///
552  /// Returns true if an error occurred.
554  unsigned NumInputs,
555  TemplateArgumentListInfo &Outputs,
556  bool Uneval = false) {
557  return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
558  Uneval);
559  }
560 
561  /// \brief Transform the given set of template arguments.
562  ///
563  /// By default, this operation transforms all of the template arguments
564  /// in the input set using \c TransformTemplateArgument(), and appends
565  /// the transformed arguments to the output list.
566  ///
567  /// \param First An iterator to the first template argument.
568  ///
569  /// \param Last An iterator one step past the last template argument.
570  ///
571  /// \param Outputs The set of transformed template arguments output by this
572  /// routine.
573  ///
574  /// Returns true if an error occurred.
575  template<typename InputIterator>
576  bool TransformTemplateArguments(InputIterator First,
577  InputIterator Last,
578  TemplateArgumentListInfo &Outputs,
579  bool Uneval = false);
580 
581  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
582  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583  TemplateArgumentLoc &ArgLoc);
584 
585  /// \brief Fakes up a TypeSourceInfo for a type.
587  return SemaRef.Context.getTrivialTypeSourceInfo(T,
588  getDerived().getBaseLocation());
589  }
590 
591 #define ABSTRACT_TYPELOC(CLASS, PARENT)
592 #define TYPELOC(CLASS, PARENT) \
593  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
594 #include "clang/AST/TypeLocNodes.def"
595 
596  template<typename Fn>
597  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
598  FunctionProtoTypeLoc TL,
599  CXXRecordDecl *ThisContext,
600  unsigned ThisTypeQuals,
601  Fn TransformExceptionSpec);
602 
603  bool TransformExceptionSpec(SourceLocation Loc,
604  FunctionProtoType::ExceptionSpecInfo &ESI,
605  SmallVectorImpl<QualType> &Exceptions,
606  bool &Changed);
607 
608  StmtResult TransformSEHHandler(Stmt *Handler);
609 
610  QualType
611  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
612  TemplateSpecializationTypeLoc TL,
613  TemplateName Template);
614 
615  QualType
616  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
617  DependentTemplateSpecializationTypeLoc TL,
618  TemplateName Template,
619  CXXScopeSpec &SS);
620 
621  QualType TransformDependentTemplateSpecializationType(
622  TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
623  NestedNameSpecifierLoc QualifierLoc);
624 
625  /// \brief Transforms the parameters of a function type into the
626  /// given vectors.
627  ///
628  /// The result vectors should be kept in sync; null entries in the
629  /// variables vector are acceptable.
630  ///
631  /// Return true on error.
632  bool TransformFunctionTypeParams(
633  SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
634  const QualType *ParamTypes,
635  const FunctionProtoType::ExtParameterInfo *ParamInfos,
636  SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
637  Sema::ExtParameterInfoBuilder &PInfos);
638 
639  /// \brief Transforms a single function-type parameter. Return null
640  /// on error.
641  ///
642  /// \param indexAdjustment - A number to add to the parameter's
643  /// scope index; can be negative
644  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
645  int indexAdjustment,
646  Optional<unsigned> NumExpansions,
647  bool ExpectParameterPack);
648 
649  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
650 
651  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
652  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
653 
655  TemplateParameterList *TPL) {
656  return TPL;
657  }
658 
659  ExprResult TransformAddressOfOperand(Expr *E);
660 
661  ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
662  bool IsAddressOfOperand,
663  TypeSourceInfo **RecoveryTSI);
664 
665  ExprResult TransformParenDependentScopeDeclRefExpr(
666  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
667  TypeSourceInfo **RecoveryTSI);
668 
669  StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
670 
671 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
672 // amount of stack usage with clang.
673 #define STMT(Node, Parent) \
674  LLVM_ATTRIBUTE_NOINLINE \
675  StmtResult Transform##Node(Node *S);
676 #define EXPR(Node, Parent) \
677  LLVM_ATTRIBUTE_NOINLINE \
678  ExprResult Transform##Node(Node *E);
679 #define ABSTRACT_STMT(Stmt)
680 #include "clang/AST/StmtNodes.inc"
681 
682 #define OPENMP_CLAUSE(Name, Class) \
683  LLVM_ATTRIBUTE_NOINLINE \
684  OMPClause *Transform ## Class(Class *S);
685 #include "clang/Basic/OpenMPKinds.def"
686 
687  /// \brief Build a new qualified type given its unqualified type and type
688  /// qualifiers.
689  ///
690  /// By default, this routine adds type qualifiers only to types that can
691  /// have qualifiers, and silently suppresses those qualifiers that are not
692  /// permitted. Subclasses may override this routine to provide different
693  /// behavior.
694  QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
695  Qualifiers Quals);
696 
697  /// \brief Build a new pointer type given its pointee type.
698  ///
699  /// By default, performs semantic analysis when building the pointer type.
700  /// Subclasses may override this routine to provide different behavior.
701  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
702 
703  /// \brief Build a new block pointer type given its pointee type.
704  ///
705  /// By default, performs semantic analysis when building the block pointer
706  /// type. Subclasses may override this routine to provide different behavior.
707  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
708 
709  /// \brief Build a new reference type given the type it references.
710  ///
711  /// By default, performs semantic analysis when building the
712  /// reference type. Subclasses may override this routine to provide
713  /// different behavior.
714  ///
715  /// \param LValue whether the type was written with an lvalue sigil
716  /// or an rvalue sigil.
717  QualType RebuildReferenceType(QualType ReferentType,
718  bool LValue,
719  SourceLocation Sigil);
720 
721  /// \brief Build a new member pointer type given the pointee type and the
722  /// class type it refers into.
723  ///
724  /// By default, performs semantic analysis when building the member pointer
725  /// type. Subclasses may override this routine to provide different behavior.
726  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
727  SourceLocation Sigil);
728 
729  QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
730  SourceLocation ProtocolLAngleLoc,
731  ArrayRef<ObjCProtocolDecl *> Protocols,
732  ArrayRef<SourceLocation> ProtocolLocs,
733  SourceLocation ProtocolRAngleLoc);
734 
735  /// \brief Build an Objective-C object type.
736  ///
737  /// By default, performs semantic analysis when building the object type.
738  /// Subclasses may override this routine to provide different behavior.
739  QualType RebuildObjCObjectType(QualType BaseType,
740  SourceLocation Loc,
741  SourceLocation TypeArgsLAngleLoc,
742  ArrayRef<TypeSourceInfo *> TypeArgs,
743  SourceLocation TypeArgsRAngleLoc,
744  SourceLocation ProtocolLAngleLoc,
745  ArrayRef<ObjCProtocolDecl *> Protocols,
746  ArrayRef<SourceLocation> ProtocolLocs,
747  SourceLocation ProtocolRAngleLoc);
748 
749  /// \brief Build a new Objective-C object pointer type given the pointee type.
750  ///
751  /// By default, directly builds the pointer type, with no additional semantic
752  /// analysis.
753  QualType RebuildObjCObjectPointerType(QualType PointeeType,
754  SourceLocation Star);
755 
756  /// \brief Build a new array type given the element type, size
757  /// modifier, size of the array (if known), size expression, and index type
758  /// qualifiers.
759  ///
760  /// By default, performs semantic analysis when building the array type.
761  /// Subclasses may override this routine to provide different behavior.
762  /// Also by default, all of the other Rebuild*Array
763  QualType RebuildArrayType(QualType ElementType,
765  const llvm::APInt *Size,
766  Expr *SizeExpr,
767  unsigned IndexTypeQuals,
768  SourceRange BracketsRange);
769 
770  /// \brief Build a new constant array type given the element type, size
771  /// modifier, (known) size of the array, and index type qualifiers.
772  ///
773  /// By default, performs semantic analysis when building the array type.
774  /// Subclasses may override this routine to provide different behavior.
775  QualType RebuildConstantArrayType(QualType ElementType,
777  const llvm::APInt &Size,
778  unsigned IndexTypeQuals,
779  SourceRange BracketsRange);
780 
781  /// \brief Build a new incomplete array type given the element type, size
782  /// modifier, and index type qualifiers.
783  ///
784  /// By default, performs semantic analysis when building the array type.
785  /// Subclasses may override this routine to provide different behavior.
786  QualType RebuildIncompleteArrayType(QualType ElementType,
788  unsigned IndexTypeQuals,
789  SourceRange BracketsRange);
790 
791  /// \brief Build a new variable-length array type given the element type,
792  /// size modifier, size expression, and index type qualifiers.
793  ///
794  /// By default, performs semantic analysis when building the array type.
795  /// Subclasses may override this routine to provide different behavior.
796  QualType RebuildVariableArrayType(QualType ElementType,
798  Expr *SizeExpr,
799  unsigned IndexTypeQuals,
800  SourceRange BracketsRange);
801 
802  /// \brief Build a new dependent-sized array type given the element type,
803  /// size modifier, size expression, and index type qualifiers.
804  ///
805  /// By default, performs semantic analysis when building the array type.
806  /// Subclasses may override this routine to provide different behavior.
807  QualType RebuildDependentSizedArrayType(QualType ElementType,
809  Expr *SizeExpr,
810  unsigned IndexTypeQuals,
811  SourceRange BracketsRange);
812 
813  /// \brief Build a new vector type given the element type and
814  /// number of elements.
815  ///
816  /// By default, performs semantic analysis when building the vector type.
817  /// Subclasses may override this routine to provide different behavior.
818  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
819  VectorType::VectorKind VecKind);
820 
821  /// \brief Build a new extended vector type given the element type and
822  /// number of elements.
823  ///
824  /// By default, performs semantic analysis when building the vector type.
825  /// Subclasses may override this routine to provide different behavior.
826  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
827  SourceLocation AttributeLoc);
828 
829  /// \brief Build a new potentially dependently-sized extended vector type
830  /// given the element type and number of elements.
831  ///
832  /// By default, performs semantic analysis when building the vector type.
833  /// Subclasses may override this routine to provide different behavior.
834  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
835  Expr *SizeExpr,
836  SourceLocation AttributeLoc);
837 
838  /// \brief Build a new function type.
839  ///
840  /// By default, performs semantic analysis when building the function type.
841  /// Subclasses may override this routine to provide different behavior.
842  QualType RebuildFunctionProtoType(QualType T,
843  MutableArrayRef<QualType> ParamTypes,
844  const FunctionProtoType::ExtProtoInfo &EPI);
845 
846  /// \brief Build a new unprototyped function type.
847  QualType RebuildFunctionNoProtoType(QualType ResultType);
848 
849  /// \brief Rebuild an unresolved typename type, given the decl that
850  /// the UnresolvedUsingTypenameDecl was transformed to.
851  QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
852 
853  /// \brief Build a new typedef type.
855  return SemaRef.Context.getTypeDeclType(Typedef);
856  }
857 
858  /// \brief Build a new class/struct/union type.
860  return SemaRef.Context.getTypeDeclType(Record);
861  }
862 
863  /// \brief Build a new Enum type.
865  return SemaRef.Context.getTypeDeclType(Enum);
866  }
867 
868  /// \brief Build a new typeof(expr) type.
869  ///
870  /// By default, performs semantic analysis when building the typeof type.
871  /// Subclasses may override this routine to provide different behavior.
872  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
873 
874  /// \brief Build a new typeof(type) type.
875  ///
876  /// By default, builds a new TypeOfType with the given underlying type.
877  QualType RebuildTypeOfType(QualType Underlying);
878 
879  /// \brief Build a new unary transform type.
880  QualType RebuildUnaryTransformType(QualType BaseType,
882  SourceLocation Loc);
883 
884  /// \brief Build a new C++11 decltype type.
885  ///
886  /// By default, performs semantic analysis when building the decltype type.
887  /// Subclasses may override this routine to provide different behavior.
888  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
889 
890  /// \brief Build a new C++11 auto type.
891  ///
892  /// By default, builds a new AutoType with the given deduced type.
894  // Note, IsDependent is always false here: we implicitly convert an 'auto'
895  // which has been deduced to a dependent type into an undeduced 'auto', so
896  // that we'll retry deduction after the transformation.
897  return SemaRef.Context.getAutoType(Deduced, Keyword,
898  /*IsDependent*/ false);
899  }
900 
901  /// By default, builds a new DeducedTemplateSpecializationType with the given
902  /// deduced type.
904  QualType Deduced) {
905  return SemaRef.Context.getDeducedTemplateSpecializationType(
906  Template, Deduced, /*IsDependent*/ false);
907  }
908 
909  /// \brief Build a new template specialization type.
910  ///
911  /// By default, performs semantic analysis when building the template
912  /// specialization type. Subclasses may override this routine to provide
913  /// different behavior.
914  QualType RebuildTemplateSpecializationType(TemplateName Template,
915  SourceLocation TemplateLoc,
917 
918  /// \brief Build a new parenthesized type.
919  ///
920  /// By default, builds a new ParenType type from the inner type.
921  /// Subclasses may override this routine to provide different behavior.
923  return SemaRef.BuildParenType(InnerType);
924  }
925 
926  /// \brief Build a new qualified name type.
927  ///
928  /// By default, builds a new ElaboratedType type from the keyword,
929  /// the nested-name-specifier and the named type.
930  /// Subclasses may override this routine to provide different behavior.
932  ElaboratedTypeKeyword Keyword,
933  NestedNameSpecifierLoc QualifierLoc,
934  QualType Named) {
935  return SemaRef.Context.getElaboratedType(Keyword,
936  QualifierLoc.getNestedNameSpecifier(),
937  Named);
938  }
939 
940  /// \brief Build a new typename type that refers to a template-id.
941  ///
942  /// By default, builds a new DependentNameType type from the
943  /// nested-name-specifier and the given type. Subclasses may override
944  /// this routine to provide different behavior.
946  ElaboratedTypeKeyword Keyword,
947  NestedNameSpecifierLoc QualifierLoc,
948  const IdentifierInfo *Name,
949  SourceLocation NameLoc,
951  bool AllowInjectedClassName) {
952  // Rebuild the template name.
953  // TODO: avoid TemplateName abstraction
954  CXXScopeSpec SS;
955  SS.Adopt(QualifierLoc);
956  TemplateName InstName
957  = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
958  nullptr, AllowInjectedClassName);
959 
960  if (InstName.isNull())
961  return QualType();
962 
963  // If it's still dependent, make a dependent specialization.
964  if (InstName.getAsDependentTemplateName())
965  return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
966  QualifierLoc.getNestedNameSpecifier(),
967  Name,
968  Args);
969 
970  // Otherwise, make an elaborated type wrapping a non-dependent
971  // specialization.
972  QualType T =
973  getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
974  if (T.isNull()) return QualType();
975 
976  if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
977  return T;
978 
979  return SemaRef.Context.getElaboratedType(Keyword,
980  QualifierLoc.getNestedNameSpecifier(),
981  T);
982  }
983 
984  /// \brief Build a new typename type that refers to an identifier.
985  ///
986  /// By default, performs semantic analysis when building the typename type
987  /// (or elaborated type). Subclasses may override this routine to provide
988  /// different behavior.
990  SourceLocation KeywordLoc,
991  NestedNameSpecifierLoc QualifierLoc,
992  const IdentifierInfo *Id,
993  SourceLocation IdLoc,
994  bool DeducedTSTContext) {
995  CXXScopeSpec SS;
996  SS.Adopt(QualifierLoc);
997 
998  if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
999  // If the name is still dependent, just build a new dependent name type.
1000  if (!SemaRef.computeDeclContext(SS))
1001  return SemaRef.Context.getDependentNameType(Keyword,
1002  QualifierLoc.getNestedNameSpecifier(),
1003  Id);
1004  }
1005 
1006  if (Keyword == ETK_None || Keyword == ETK_Typename) {
1007  QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1008  *Id, IdLoc);
1009  // If a dependent name resolves to a deduced template specialization type,
1010  // check that we're in one of the syntactic contexts permitting it.
1011  if (!DeducedTSTContext) {
1012  if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1013  T.isNull() ? nullptr : T->getContainedDeducedType())) {
1014  SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1015  << (int)SemaRef.getTemplateNameKindForDiagnostics(
1016  Deduced->getTemplateName())
1017  << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1018  if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1019  SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1020  return QualType();
1021  }
1022  }
1023  return T;
1024  }
1025 
1027 
1028  // We had a dependent elaborated-type-specifier that has been transformed
1029  // into a non-dependent elaborated-type-specifier. Find the tag we're
1030  // referring to.
1031  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1032  DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1033  if (!DC)
1034  return QualType();
1035 
1036  if (SemaRef.RequireCompleteDeclContext(SS, DC))
1037  return QualType();
1038 
1039  TagDecl *Tag = nullptr;
1040  SemaRef.LookupQualifiedName(Result, DC);
1041  switch (Result.getResultKind()) {
1044  break;
1045 
1046  case LookupResult::Found:
1047  Tag = Result.getAsSingle<TagDecl>();
1048  break;
1049 
1052  llvm_unreachable("Tag lookup cannot find non-tags");
1053 
1055  // Let the LookupResult structure handle ambiguities.
1056  return QualType();
1057  }
1058 
1059  if (!Tag) {
1060  // Check where the name exists but isn't a tag type and use that to emit
1061  // better diagnostics.
1062  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1063  SemaRef.LookupQualifiedName(Result, DC);
1064  switch (Result.getResultKind()) {
1065  case LookupResult::Found:
1068  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1069  Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1070  SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1071  << NTK << Kind;
1072  SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1073  break;
1074  }
1075  default:
1076  SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1077  << Kind << Id << DC << QualifierLoc.getSourceRange();
1078  break;
1079  }
1080  return QualType();
1081  }
1082 
1083  if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1084  IdLoc, Id)) {
1085  SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1086  SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1087  return QualType();
1088  }
1089 
1090  // Build the elaborated-type-specifier type.
1091  QualType T = SemaRef.Context.getTypeDeclType(Tag);
1092  return SemaRef.Context.getElaboratedType(Keyword,
1093  QualifierLoc.getNestedNameSpecifier(),
1094  T);
1095  }
1096 
1097  /// \brief Build a new pack expansion type.
1098  ///
1099  /// By default, builds a new PackExpansionType type from the given pattern.
1100  /// Subclasses may override this routine to provide different behavior.
1102  SourceRange PatternRange,
1103  SourceLocation EllipsisLoc,
1104  Optional<unsigned> NumExpansions) {
1105  return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1106  NumExpansions);
1107  }
1108 
1109  /// \brief Build a new atomic type given its value type.
1110  ///
1111  /// By default, performs semantic analysis when building the atomic type.
1112  /// Subclasses may override this routine to provide different behavior.
1113  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1114 
1115  /// \brief Build a new pipe type given its value type.
1116  QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1117  bool isReadPipe);
1118 
1119  /// \brief Build a new template name given a nested name specifier, a flag
1120  /// indicating whether the "template" keyword was provided, and the template
1121  /// that the template name refers to.
1122  ///
1123  /// By default, builds the new template name directly. Subclasses may override
1124  /// this routine to provide different behavior.
1125  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1126  bool TemplateKW,
1127  TemplateDecl *Template);
1128 
1129  /// \brief Build a new template name given a nested name specifier and the
1130  /// name that is referred to as a template.
1131  ///
1132  /// By default, performs semantic analysis to determine whether the name can
1133  /// be resolved to a specific template, then builds the appropriate kind of
1134  /// template name. Subclasses may override this routine to provide different
1135  /// behavior.
1136  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1137  const IdentifierInfo &Name,
1138  SourceLocation NameLoc,
1139  QualType ObjectType,
1140  NamedDecl *FirstQualifierInScope,
1141  bool AllowInjectedClassName);
1142 
1143  /// \brief Build a new template name given a nested name specifier and the
1144  /// overloaded operator name that is referred to as a template.
1145  ///
1146  /// By default, performs semantic analysis to determine whether the name can
1147  /// be resolved to a specific template, then builds the appropriate kind of
1148  /// template name. Subclasses may override this routine to provide different
1149  /// behavior.
1150  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1151  OverloadedOperatorKind Operator,
1152  SourceLocation NameLoc,
1153  QualType ObjectType,
1154  bool AllowInjectedClassName);
1155 
1156  /// \brief Build a new template name given a template template parameter pack
1157  /// and the
1158  ///
1159  /// By default, performs semantic analysis to determine whether the name can
1160  /// be resolved to a specific template, then builds the appropriate kind of
1161  /// template name. Subclasses may override this routine to provide different
1162  /// behavior.
1164  const TemplateArgument &ArgPack) {
1165  return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1166  }
1167 
1168  /// \brief Build a new compound statement.
1169  ///
1170  /// By default, performs semantic analysis to build the new statement.
1171  /// Subclasses may override this routine to provide different behavior.
1173  MultiStmtArg Statements,
1174  SourceLocation RBraceLoc,
1175  bool IsStmtExpr) {
1176  return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1177  IsStmtExpr);
1178  }
1179 
1180  /// \brief Build a new case statement.
1181  ///
1182  /// By default, performs semantic analysis to build the new statement.
1183  /// Subclasses may override this routine to provide different behavior.
1185  Expr *LHS,
1186  SourceLocation EllipsisLoc,
1187  Expr *RHS,
1189  return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1190  ColonLoc);
1191  }
1192 
1193  /// \brief Attach the body to a new case statement.
1194  ///
1195  /// By default, performs semantic analysis to build the new statement.
1196  /// Subclasses may override this routine to provide different behavior.
1198  getSema().ActOnCaseStmtBody(S, Body);
1199  return S;
1200  }
1201 
1202  /// \brief Build a new default statement.
1203  ///
1204  /// By default, performs semantic analysis to build the new statement.
1205  /// Subclasses may override this routine to provide different behavior.
1208  Stmt *SubStmt) {
1209  return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1210  /*CurScope=*/nullptr);
1211  }
1212 
1213  /// \brief Build a new label statement.
1214  ///
1215  /// By default, performs semantic analysis to build the new statement.
1216  /// Subclasses may override this routine to provide different behavior.
1218  SourceLocation ColonLoc, Stmt *SubStmt) {
1219  return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1220  }
1221 
1222  /// \brief Build a new label statement.
1223  ///
1224  /// By default, performs semantic analysis to build the new statement.
1225  /// Subclasses may override this routine to provide different behavior.
1227  ArrayRef<const Attr*> Attrs,
1228  Stmt *SubStmt) {
1229  return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1230  }
1231 
1232  /// \brief Build a new "if" statement.
1233  ///
1234  /// By default, performs semantic analysis to build the new statement.
1235  /// Subclasses may override this routine to provide different behavior.
1236  StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1237  Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1238  SourceLocation ElseLoc, Stmt *Else) {
1239  return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1240  ElseLoc, Else);
1241  }
1242 
1243  /// \brief Start building a new switch statement.
1244  ///
1245  /// By default, performs semantic analysis to build the new statement.
1246  /// Subclasses may override this routine to provide different behavior.
1248  Sema::ConditionResult Cond) {
1249  return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1250  }
1251 
1252  /// \brief Attach the body to the switch statement.
1253  ///
1254  /// By default, performs semantic analysis to build the new statement.
1255  /// Subclasses may override this routine to provide different behavior.
1257  Stmt *Switch, Stmt *Body) {
1258  return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1259  }
1260 
1261  /// \brief Build a new while statement.
1262  ///
1263  /// By default, performs semantic analysis to build the new statement.
1264  /// Subclasses may override this routine to provide different behavior.
1266  Sema::ConditionResult Cond, Stmt *Body) {
1267  return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1268  }
1269 
1270  /// \brief Build a new do-while statement.
1271  ///
1272  /// By default, performs semantic analysis to build the new statement.
1273  /// Subclasses may override this routine to provide different behavior.
1275  SourceLocation WhileLoc, SourceLocation LParenLoc,
1276  Expr *Cond, SourceLocation RParenLoc) {
1277  return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1278  Cond, RParenLoc);
1279  }
1280 
1281  /// \brief Build a new for statement.
1282  ///
1283  /// By default, performs semantic analysis to build the new statement.
1284  /// Subclasses may override this routine to provide different behavior.
1286  Stmt *Init, Sema::ConditionResult Cond,
1287  Sema::FullExprArg Inc, SourceLocation RParenLoc,
1288  Stmt *Body) {
1289  return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1290  Inc, RParenLoc, Body);
1291  }
1292 
1293  /// \brief Build a new goto statement.
1294  ///
1295  /// By default, performs semantic analysis to build the new statement.
1296  /// Subclasses may override this routine to provide different behavior.
1298  LabelDecl *Label) {
1299  return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1300  }
1301 
1302  /// \brief Build a new indirect goto statement.
1303  ///
1304  /// By default, performs semantic analysis to build the new statement.
1305  /// Subclasses may override this routine to provide different behavior.
1307  SourceLocation StarLoc,
1308  Expr *Target) {
1309  return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1310  }
1311 
1312  /// \brief Build a new return statement.
1313  ///
1314  /// By default, performs semantic analysis to build the new statement.
1315  /// Subclasses may override this routine to provide different behavior.
1317  return getSema().BuildReturnStmt(ReturnLoc, Result);
1318  }
1319 
1320  /// \brief Build a new declaration statement.
1321  ///
1322  /// By default, performs semantic analysis to build the new statement.
1323  /// Subclasses may override this routine to provide different behavior.
1325  SourceLocation StartLoc, SourceLocation EndLoc) {
1326  Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1327  return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1328  }
1329 
1330  /// \brief Build a new inline asm statement.
1331  ///
1332  /// By default, performs semantic analysis to build the new statement.
1333  /// Subclasses may override this routine to provide different behavior.
1335  bool IsVolatile, unsigned NumOutputs,
1336  unsigned NumInputs, IdentifierInfo **Names,
1337  MultiExprArg Constraints, MultiExprArg Exprs,
1338  Expr *AsmString, MultiExprArg Clobbers,
1339  SourceLocation RParenLoc) {
1340  return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1341  NumInputs, Names, Constraints, Exprs,
1342  AsmString, Clobbers, RParenLoc);
1343  }
1344 
1345  /// \brief Build a new MS style inline asm statement.
1346  ///
1347  /// By default, performs semantic analysis to build the new statement.
1348  /// Subclasses may override this routine to provide different behavior.
1350  ArrayRef<Token> AsmToks,
1351  StringRef AsmString,
1352  unsigned NumOutputs, unsigned NumInputs,
1353  ArrayRef<StringRef> Constraints,
1354  ArrayRef<StringRef> Clobbers,
1355  ArrayRef<Expr*> Exprs,
1356  SourceLocation EndLoc) {
1357  return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1358  NumOutputs, NumInputs,
1359  Constraints, Clobbers, Exprs, EndLoc);
1360  }
1361 
1362  /// \brief Build a new co_return statement.
1363  ///
1364  /// By default, performs semantic analysis to build the new statement.
1365  /// Subclasses may override this routine to provide different behavior.
1367  bool IsImplicit) {
1368  return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1369  }
1370 
1371  /// \brief Build a new co_await expression.
1372  ///
1373  /// By default, performs semantic analysis to build the new expression.
1374  /// Subclasses may override this routine to provide different behavior.
1376  bool IsImplicit) {
1377  return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1378  }
1379 
1380  /// \brief Build a new co_await expression.
1381  ///
1382  /// By default, performs semantic analysis to build the new expression.
1383  /// Subclasses may override this routine to provide different behavior.
1385  Expr *Result,
1386  UnresolvedLookupExpr *Lookup) {
1387  return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1388  }
1389 
1390  /// \brief Build a new co_yield expression.
1391  ///
1392  /// By default, performs semantic analysis to build the new expression.
1393  /// Subclasses may override this routine to provide different behavior.
1395  return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1396  }
1397 
1399  return getSema().BuildCoroutineBodyStmt(Args);
1400  }
1401 
1402  /// \brief Build a new Objective-C \@try statement.
1403  ///
1404  /// By default, performs semantic analysis to build the new statement.
1405  /// Subclasses may override this routine to provide different behavior.
1407  Stmt *TryBody,
1408  MultiStmtArg CatchStmts,
1409  Stmt *Finally) {
1410  return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1411  Finally);
1412  }
1413 
1414  /// \brief Rebuild an Objective-C exception declaration.
1415  ///
1416  /// By default, performs semantic analysis to build the new declaration.
1417  /// Subclasses may override this routine to provide different behavior.
1419  TypeSourceInfo *TInfo, QualType T) {
1420  return getSema().BuildObjCExceptionDecl(TInfo, T,
1421  ExceptionDecl->getInnerLocStart(),
1422  ExceptionDecl->getLocation(),
1423  ExceptionDecl->getIdentifier());
1424  }
1425 
1426  /// \brief Build a new Objective-C \@catch statement.
1427  ///
1428  /// By default, performs semantic analysis to build the new statement.
1429  /// Subclasses may override this routine to provide different behavior.
1431  SourceLocation RParenLoc,
1432  VarDecl *Var,
1433  Stmt *Body) {
1434  return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1435  Var, Body);
1436  }
1437 
1438  /// \brief Build a new Objective-C \@finally statement.
1439  ///
1440  /// By default, performs semantic analysis to build the new statement.
1441  /// Subclasses may override this routine to provide different behavior.
1443  Stmt *Body) {
1444  return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1445  }
1446 
1447  /// \brief Build a new Objective-C \@throw statement.
1448  ///
1449  /// By default, performs semantic analysis to build the new statement.
1450  /// Subclasses may override this routine to provide different behavior.
1452  Expr *Operand) {
1453  return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1454  }
1455 
1456  /// \brief Build a new OpenMP executable directive.
1457  ///
1458  /// By default, performs semantic analysis to build the new statement.
1459  /// Subclasses may override this routine to provide different behavior.
1461  DeclarationNameInfo DirName,
1462  OpenMPDirectiveKind CancelRegion,
1463  ArrayRef<OMPClause *> Clauses,
1464  Stmt *AStmt, SourceLocation StartLoc,
1465  SourceLocation EndLoc) {
1466  return getSema().ActOnOpenMPExecutableDirective(
1467  Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1468  }
1469 
1470  /// \brief Build a new OpenMP 'if' clause.
1471  ///
1472  /// By default, performs semantic analysis to build the new OpenMP clause.
1473  /// Subclasses may override this routine to provide different behavior.
1475  Expr *Condition, SourceLocation StartLoc,
1476  SourceLocation LParenLoc,
1477  SourceLocation NameModifierLoc,
1479  SourceLocation EndLoc) {
1480  return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1481  LParenLoc, NameModifierLoc, ColonLoc,
1482  EndLoc);
1483  }
1484 
1485  /// \brief Build a new OpenMP 'final' clause.
1486  ///
1487  /// By default, performs semantic analysis to build the new OpenMP clause.
1488  /// Subclasses may override this routine to provide different behavior.
1490  SourceLocation LParenLoc,
1491  SourceLocation EndLoc) {
1492  return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1493  EndLoc);
1494  }
1495 
1496  /// \brief Build a new OpenMP 'num_threads' clause.
1497  ///
1498  /// By default, performs semantic analysis to build the new OpenMP clause.
1499  /// Subclasses may override this routine to provide different behavior.
1501  SourceLocation StartLoc,
1502  SourceLocation LParenLoc,
1503  SourceLocation EndLoc) {
1504  return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1505  LParenLoc, EndLoc);
1506  }
1507 
1508  /// \brief Build a new OpenMP 'safelen' clause.
1509  ///
1510  /// By default, performs semantic analysis to build the new OpenMP clause.
1511  /// Subclasses may override this routine to provide different behavior.
1513  SourceLocation LParenLoc,
1514  SourceLocation EndLoc) {
1515  return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1516  }
1517 
1518  /// \brief Build a new OpenMP 'simdlen' clause.
1519  ///
1520  /// By default, performs semantic analysis to build the new OpenMP clause.
1521  /// Subclasses may override this routine to provide different behavior.
1523  SourceLocation LParenLoc,
1524  SourceLocation EndLoc) {
1525  return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1526  }
1527 
1528  /// \brief Build a new OpenMP 'collapse' clause.
1529  ///
1530  /// By default, performs semantic analysis to build the new OpenMP clause.
1531  /// Subclasses may override this routine to provide different behavior.
1533  SourceLocation LParenLoc,
1534  SourceLocation EndLoc) {
1535  return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1536  EndLoc);
1537  }
1538 
1539  /// \brief Build a new OpenMP 'default' clause.
1540  ///
1541  /// By default, performs semantic analysis to build the new OpenMP clause.
1542  /// Subclasses may override this routine to provide different behavior.
1544  SourceLocation KindKwLoc,
1545  SourceLocation StartLoc,
1546  SourceLocation LParenLoc,
1547  SourceLocation EndLoc) {
1548  return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1549  StartLoc, LParenLoc, EndLoc);
1550  }
1551 
1552  /// \brief Build a new OpenMP 'proc_bind' clause.
1553  ///
1554  /// By default, performs semantic analysis to build the new OpenMP clause.
1555  /// Subclasses may override this routine to provide different behavior.
1557  SourceLocation KindKwLoc,
1558  SourceLocation StartLoc,
1559  SourceLocation LParenLoc,
1560  SourceLocation EndLoc) {
1561  return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1562  StartLoc, LParenLoc, EndLoc);
1563  }
1564 
1565  /// \brief Build a new OpenMP 'schedule' clause.
1566  ///
1567  /// By default, performs semantic analysis to build the new OpenMP clause.
1568  /// Subclasses may override this routine to provide different behavior.
1571  OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1572  SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1573  SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1574  return getSema().ActOnOpenMPScheduleClause(
1575  M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1576  CommaLoc, EndLoc);
1577  }
1578 
1579  /// \brief Build a new OpenMP 'ordered' clause.
1580  ///
1581  /// By default, performs semantic analysis to build the new OpenMP clause.
1582  /// Subclasses may override this routine to provide different behavior.
1584  SourceLocation EndLoc,
1585  SourceLocation LParenLoc, Expr *Num) {
1586  return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1587  }
1588 
1589  /// \brief Build a new OpenMP 'private' clause.
1590  ///
1591  /// By default, performs semantic analysis to build the new OpenMP clause.
1592  /// Subclasses may override this routine to provide different behavior.
1594  SourceLocation StartLoc,
1595  SourceLocation LParenLoc,
1596  SourceLocation EndLoc) {
1597  return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1598  EndLoc);
1599  }
1600 
1601  /// \brief Build a new OpenMP 'firstprivate' clause.
1602  ///
1603  /// By default, performs semantic analysis to build the new OpenMP clause.
1604  /// Subclasses may override this routine to provide different behavior.
1606  SourceLocation StartLoc,
1607  SourceLocation LParenLoc,
1608  SourceLocation EndLoc) {
1609  return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1610  EndLoc);
1611  }
1612 
1613  /// \brief Build a new OpenMP 'lastprivate' clause.
1614  ///
1615  /// By default, performs semantic analysis to build the new OpenMP clause.
1616  /// Subclasses may override this routine to provide different behavior.
1618  SourceLocation StartLoc,
1619  SourceLocation LParenLoc,
1620  SourceLocation EndLoc) {
1621  return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1622  EndLoc);
1623  }
1624 
1625  /// \brief Build a new OpenMP 'shared' clause.
1626  ///
1627  /// By default, performs semantic analysis to build the new OpenMP clause.
1628  /// Subclasses may override this routine to provide different behavior.
1630  SourceLocation StartLoc,
1631  SourceLocation LParenLoc,
1632  SourceLocation EndLoc) {
1633  return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1634  EndLoc);
1635  }
1636 
1637  /// \brief Build a new OpenMP 'reduction' clause.
1638  ///
1639  /// By default, performs semantic analysis to build the new statement.
1640  /// Subclasses may override this routine to provide different behavior.
1642  SourceLocation StartLoc,
1643  SourceLocation LParenLoc,
1645  SourceLocation EndLoc,
1646  CXXScopeSpec &ReductionIdScopeSpec,
1647  const DeclarationNameInfo &ReductionId,
1648  ArrayRef<Expr *> UnresolvedReductions) {
1649  return getSema().ActOnOpenMPReductionClause(
1650  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1651  ReductionId, UnresolvedReductions);
1652  }
1653 
1654  /// Build a new OpenMP 'task_reduction' clause.
1655  ///
1656  /// By default, performs semantic analysis to build the new statement.
1657  /// Subclasses may override this routine to provide different behavior.
1659  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1661  CXXScopeSpec &ReductionIdScopeSpec,
1662  const DeclarationNameInfo &ReductionId,
1663  ArrayRef<Expr *> UnresolvedReductions) {
1664  return getSema().ActOnOpenMPTaskReductionClause(
1665  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1666  ReductionId, UnresolvedReductions);
1667  }
1668 
1669  /// \brief Build a new OpenMP 'linear' clause.
1670  ///
1671  /// By default, performs semantic analysis to build the new OpenMP clause.
1672  /// Subclasses may override this routine to provide different behavior.
1674  SourceLocation StartLoc,
1675  SourceLocation LParenLoc,
1679  SourceLocation EndLoc) {
1680  return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1681  Modifier, ModifierLoc, ColonLoc,
1682  EndLoc);
1683  }
1684 
1685  /// \brief Build a new OpenMP 'aligned' clause.
1686  ///
1687  /// By default, performs semantic analysis to build the new OpenMP clause.
1688  /// Subclasses may override this routine to provide different behavior.
1690  SourceLocation StartLoc,
1691  SourceLocation LParenLoc,
1693  SourceLocation EndLoc) {
1694  return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1695  LParenLoc, ColonLoc, EndLoc);
1696  }
1697 
1698  /// \brief Build a new OpenMP 'copyin' clause.
1699  ///
1700  /// By default, performs semantic analysis to build the new OpenMP clause.
1701  /// Subclasses may override this routine to provide different behavior.
1703  SourceLocation StartLoc,
1704  SourceLocation LParenLoc,
1705  SourceLocation EndLoc) {
1706  return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1707  EndLoc);
1708  }
1709 
1710  /// \brief Build a new OpenMP 'copyprivate' clause.
1711  ///
1712  /// By default, performs semantic analysis to build the new OpenMP clause.
1713  /// Subclasses may override this routine to provide different behavior.
1715  SourceLocation StartLoc,
1716  SourceLocation LParenLoc,
1717  SourceLocation EndLoc) {
1718  return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1719  EndLoc);
1720  }
1721 
1722  /// \brief Build a new OpenMP 'flush' pseudo clause.
1723  ///
1724  /// By default, performs semantic analysis to build the new OpenMP clause.
1725  /// Subclasses may override this routine to provide different behavior.
1727  SourceLocation StartLoc,
1728  SourceLocation LParenLoc,
1729  SourceLocation EndLoc) {
1730  return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1731  EndLoc);
1732  }
1733 
1734  /// \brief Build a new OpenMP 'depend' pseudo clause.
1735  ///
1736  /// By default, performs semantic analysis to build the new OpenMP clause.
1737  /// Subclasses may override this routine to provide different behavior.
1738  OMPClause *
1741  SourceLocation StartLoc, SourceLocation LParenLoc,
1742  SourceLocation EndLoc) {
1743  return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1744  StartLoc, LParenLoc, EndLoc);
1745  }
1746 
1747  /// \brief Build a new OpenMP 'device' clause.
1748  ///
1749  /// By default, performs semantic analysis to build the new statement.
1750  /// Subclasses may override this routine to provide different behavior.
1752  SourceLocation LParenLoc,
1753  SourceLocation EndLoc) {
1754  return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1755  EndLoc);
1756  }
1757 
1758  /// \brief Build a new OpenMP 'map' clause.
1759  ///
1760  /// By default, performs semantic analysis to build the new OpenMP clause.
1761  /// Subclasses may override this routine to provide different behavior.
1762  OMPClause *
1764  OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1766  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1767  SourceLocation LParenLoc, SourceLocation EndLoc) {
1768  return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1769  IsMapTypeImplicit, MapLoc, ColonLoc,
1770  VarList, StartLoc, LParenLoc, EndLoc);
1771  }
1772 
1773  /// \brief Build a new OpenMP 'num_teams' clause.
1774  ///
1775  /// By default, performs semantic analysis to build the new statement.
1776  /// Subclasses may override this routine to provide different behavior.
1778  SourceLocation LParenLoc,
1779  SourceLocation EndLoc) {
1780  return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1781  EndLoc);
1782  }
1783 
1784  /// \brief Build a new OpenMP 'thread_limit' clause.
1785  ///
1786  /// By default, performs semantic analysis to build the new statement.
1787  /// Subclasses may override this routine to provide different behavior.
1789  SourceLocation StartLoc,
1790  SourceLocation LParenLoc,
1791  SourceLocation EndLoc) {
1792  return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1793  LParenLoc, EndLoc);
1794  }
1795 
1796  /// \brief Build a new OpenMP 'priority' clause.
1797  ///
1798  /// By default, performs semantic analysis to build the new statement.
1799  /// Subclasses may override this routine to provide different behavior.
1801  SourceLocation LParenLoc,
1802  SourceLocation EndLoc) {
1803  return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1804  EndLoc);
1805  }
1806 
1807  /// \brief Build a new OpenMP 'grainsize' clause.
1808  ///
1809  /// By default, performs semantic analysis to build the new statement.
1810  /// Subclasses may override this routine to provide different behavior.
1812  SourceLocation LParenLoc,
1813  SourceLocation EndLoc) {
1814  return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1815  EndLoc);
1816  }
1817 
1818  /// \brief Build a new OpenMP 'num_tasks' clause.
1819  ///
1820  /// By default, performs semantic analysis to build the new statement.
1821  /// Subclasses may override this routine to provide different behavior.
1823  SourceLocation LParenLoc,
1824  SourceLocation EndLoc) {
1825  return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1826  EndLoc);
1827  }
1828 
1829  /// \brief Build a new OpenMP 'hint' clause.
1830  ///
1831  /// By default, performs semantic analysis to build the new statement.
1832  /// Subclasses may override this routine to provide different behavior.
1834  SourceLocation LParenLoc,
1835  SourceLocation EndLoc) {
1836  return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1837  }
1838 
1839  /// \brief Build a new OpenMP 'dist_schedule' clause.
1840  ///
1841  /// By default, performs semantic analysis to build the new OpenMP clause.
1842  /// Subclasses may override this routine to provide different behavior.
1843  OMPClause *
1845  Expr *ChunkSize, SourceLocation StartLoc,
1846  SourceLocation LParenLoc, SourceLocation KindLoc,
1847  SourceLocation CommaLoc, SourceLocation EndLoc) {
1848  return getSema().ActOnOpenMPDistScheduleClause(
1849  Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1850  }
1851 
1852  /// \brief Build a new OpenMP 'to' clause.
1853  ///
1854  /// By default, performs semantic analysis to build the new statement.
1855  /// Subclasses may override this routine to provide different behavior.
1857  SourceLocation StartLoc,
1858  SourceLocation LParenLoc,
1859  SourceLocation EndLoc) {
1860  return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1861  }
1862 
1863  /// \brief Build a new OpenMP 'from' clause.
1864  ///
1865  /// By default, performs semantic analysis to build the new statement.
1866  /// Subclasses may override this routine to provide different behavior.
1868  SourceLocation StartLoc,
1869  SourceLocation LParenLoc,
1870  SourceLocation EndLoc) {
1871  return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1872  EndLoc);
1873  }
1874 
1875  /// Build a new OpenMP 'use_device_ptr' clause.
1876  ///
1877  /// By default, performs semantic analysis to build the new OpenMP clause.
1878  /// Subclasses may override this routine to provide different behavior.
1880  SourceLocation StartLoc,
1881  SourceLocation LParenLoc,
1882  SourceLocation EndLoc) {
1883  return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1884  EndLoc);
1885  }
1886 
1887  /// Build a new OpenMP 'is_device_ptr' clause.
1888  ///
1889  /// By default, performs semantic analysis to build the new OpenMP clause.
1890  /// Subclasses may override this routine to provide different behavior.
1892  SourceLocation StartLoc,
1893  SourceLocation LParenLoc,
1894  SourceLocation EndLoc) {
1895  return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1896  EndLoc);
1897  }
1898 
1899  /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1900  ///
1901  /// By default, performs semantic analysis to build the new statement.
1902  /// Subclasses may override this routine to provide different behavior.
1904  Expr *object) {
1905  return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1906  }
1907 
1908  /// \brief Build a new Objective-C \@synchronized statement.
1909  ///
1910  /// By default, performs semantic analysis to build the new statement.
1911  /// Subclasses may override this routine to provide different behavior.
1913  Expr *Object, Stmt *Body) {
1914  return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1915  }
1916 
1917  /// \brief Build a new Objective-C \@autoreleasepool statement.
1918  ///
1919  /// By default, performs semantic analysis to build the new statement.
1920  /// Subclasses may override this routine to provide different behavior.
1922  Stmt *Body) {
1923  return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1924  }
1925 
1926  /// \brief Build a new Objective-C fast enumeration statement.
1927  ///
1928  /// By default, performs semantic analysis to build the new statement.
1929  /// Subclasses may override this routine to provide different behavior.
1931  Stmt *Element,
1932  Expr *Collection,
1933  SourceLocation RParenLoc,
1934  Stmt *Body) {
1935  StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1936  Element,
1937  Collection,
1938  RParenLoc);
1939  if (ForEachStmt.isInvalid())
1940  return StmtError();
1941 
1942  return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1943  }
1944 
1945  /// \brief Build a new C++ exception declaration.
1946  ///
1947  /// By default, performs semantic analysis to build the new decaration.
1948  /// Subclasses may override this routine to provide different behavior.
1951  SourceLocation StartLoc,
1952  SourceLocation IdLoc,
1953  IdentifierInfo *Id) {
1954  VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1955  StartLoc, IdLoc, Id);
1956  if (Var)
1957  getSema().CurContext->addDecl(Var);
1958  return Var;
1959  }
1960 
1961  /// \brief Build a new C++ catch statement.
1962  ///
1963  /// By default, performs semantic analysis to build the new statement.
1964  /// Subclasses may override this routine to provide different behavior.
1966  VarDecl *ExceptionDecl,
1967  Stmt *Handler) {
1968  return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1969  Handler));
1970  }
1971 
1972  /// \brief Build a new C++ try statement.
1973  ///
1974  /// By default, performs semantic analysis to build the new statement.
1975  /// Subclasses may override this routine to provide different behavior.
1977  ArrayRef<Stmt *> Handlers) {
1978  return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1979  }
1980 
1981  /// \brief Build a new C++0x range-based for statement.
1982  ///
1983  /// By default, performs semantic analysis to build the new statement.
1984  /// Subclasses may override this routine to provide different behavior.
1986  SourceLocation CoawaitLoc,
1988  Stmt *Range, Stmt *Begin, Stmt *End,
1989  Expr *Cond, Expr *Inc,
1990  Stmt *LoopVar,
1991  SourceLocation RParenLoc) {
1992  // If we've just learned that the range is actually an Objective-C
1993  // collection, treat this as an Objective-C fast enumeration loop.
1994  if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1995  if (RangeStmt->isSingleDecl()) {
1996  if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1997  if (RangeVar->isInvalidDecl())
1998  return StmtError();
1999 
2000  Expr *RangeExpr = RangeVar->getInit();
2001  if (!RangeExpr->isTypeDependent() &&
2002  RangeExpr->getType()->isObjCObjectPointerType())
2003  return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2004  RParenLoc);
2005  }
2006  }
2007  }
2008 
2009  return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
2010  Range, Begin, End,
2011  Cond, Inc, LoopVar, RParenLoc,
2013  }
2014 
2015  /// \brief Build a new C++0x range-based for statement.
2016  ///
2017  /// By default, performs semantic analysis to build the new statement.
2018  /// Subclasses may override this routine to provide different behavior.
2020  bool IsIfExists,
2021  NestedNameSpecifierLoc QualifierLoc,
2022  DeclarationNameInfo NameInfo,
2023  Stmt *Nested) {
2024  return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2025  QualifierLoc, NameInfo, Nested);
2026  }
2027 
2028  /// \brief Attach body to a C++0x range-based for statement.
2029  ///
2030  /// By default, performs semantic analysis to finish the new statement.
2031  /// Subclasses may override this routine to provide different behavior.
2033  return getSema().FinishCXXForRangeStmt(ForRange, Body);
2034  }
2035 
2037  Stmt *TryBlock, Stmt *Handler) {
2038  return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2039  }
2040 
2042  Stmt *Block) {
2043  return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2044  }
2045 
2047  return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2048  }
2049 
2050  /// \brief Build a new predefined expression.
2051  ///
2052  /// By default, performs semantic analysis to build the new expression.
2053  /// Subclasses may override this routine to provide different behavior.
2056  return getSema().BuildPredefinedExpr(Loc, IT);
2057  }
2058 
2059  /// \brief Build a new expression that references a declaration.
2060  ///
2061  /// By default, performs semantic analysis to build the new expression.
2062  /// Subclasses may override this routine to provide different behavior.
2064  LookupResult &R,
2065  bool RequiresADL) {
2066  return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2067  }
2068 
2069 
2070  /// \brief Build a new expression that references a declaration.
2071  ///
2072  /// By default, performs semantic analysis to build the new expression.
2073  /// Subclasses may override this routine to provide different behavior.
2075  ValueDecl *VD,
2076  const DeclarationNameInfo &NameInfo,
2077  TemplateArgumentListInfo *TemplateArgs) {
2078  CXXScopeSpec SS;
2079  SS.Adopt(QualifierLoc);
2080 
2081  // FIXME: loses template args.
2082 
2083  return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
2084  }
2085 
2086  /// \brief Build a new expression in parentheses.
2087  ///
2088  /// By default, performs semantic analysis to build the new expression.
2089  /// Subclasses may override this routine to provide different behavior.
2091  SourceLocation RParen) {
2092  return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2093  }
2094 
2095  /// \brief Build a new pseudo-destructor expression.
2096  ///
2097  /// By default, performs semantic analysis to build the new expression.
2098  /// Subclasses may override this routine to provide different behavior.
2099  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2100  SourceLocation OperatorLoc,
2101  bool isArrow,
2102  CXXScopeSpec &SS,
2103  TypeSourceInfo *ScopeType,
2104  SourceLocation CCLoc,
2105  SourceLocation TildeLoc,
2106  PseudoDestructorTypeStorage Destroyed);
2107 
2108  /// \brief Build a new unary operator expression.
2109  ///
2110  /// By default, performs semantic analysis to build the new expression.
2111  /// Subclasses may override this routine to provide different behavior.
2113  UnaryOperatorKind Opc,
2114  Expr *SubExpr) {
2115  return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2116  }
2117 
2118  /// \brief Build a new builtin offsetof expression.
2119  ///
2120  /// By default, performs semantic analysis to build the new expression.
2121  /// Subclasses may override this routine to provide different behavior.
2125  SourceLocation RParenLoc) {
2126  return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2127  RParenLoc);
2128  }
2129 
2130  /// \brief Build a new sizeof, alignof or vec_step expression with a
2131  /// type argument.
2132  ///
2133  /// By default, performs semantic analysis to build the new expression.
2134  /// Subclasses may override this routine to provide different behavior.
2136  SourceLocation OpLoc,
2137  UnaryExprOrTypeTrait ExprKind,
2138  SourceRange R) {
2139  return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2140  }
2141 
2142  /// \brief Build a new sizeof, alignof or vec step expression with an
2143  /// expression argument.
2144  ///
2145  /// By default, performs semantic analysis to build the new expression.
2146  /// Subclasses may override this routine to provide different behavior.
2148  UnaryExprOrTypeTrait ExprKind,
2149  SourceRange R) {
2151  = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2152  if (Result.isInvalid())
2153  return ExprError();
2154 
2155  return Result;
2156  }
2157 
2158  /// \brief Build a new array subscript expression.
2159  ///
2160  /// By default, performs semantic analysis to build the new expression.
2161  /// Subclasses may override this routine to provide different behavior.
2163  SourceLocation LBracketLoc,
2164  Expr *RHS,
2165  SourceLocation RBracketLoc) {
2166  return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2167  LBracketLoc, RHS,
2168  RBracketLoc);
2169  }
2170 
2171  /// \brief Build a new array section expression.
2172  ///
2173  /// By default, performs semantic analysis to build the new expression.
2174  /// Subclasses may override this routine to provide different behavior.
2176  Expr *LowerBound,
2178  SourceLocation RBracketLoc) {
2179  return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2180  ColonLoc, Length, RBracketLoc);
2181  }
2182 
2183  /// \brief Build a new call expression.
2184  ///
2185  /// By default, performs semantic analysis to build the new expression.
2186  /// Subclasses may override this routine to provide different behavior.
2188  MultiExprArg Args,
2189  SourceLocation RParenLoc,
2190  Expr *ExecConfig = nullptr) {
2191  return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2192  Args, RParenLoc, ExecConfig);
2193  }
2194 
2195  /// \brief Build a new member access expression.
2196  ///
2197  /// By default, performs semantic analysis to build the new expression.
2198  /// Subclasses may override this routine to provide different behavior.
2200  bool isArrow,
2201  NestedNameSpecifierLoc QualifierLoc,
2202  SourceLocation TemplateKWLoc,
2203  const DeclarationNameInfo &MemberNameInfo,
2204  ValueDecl *Member,
2206  const TemplateArgumentListInfo *ExplicitTemplateArgs,
2207  NamedDecl *FirstQualifierInScope) {
2208  ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2209  isArrow);
2210  if (!Member->getDeclName()) {
2211  // We have a reference to an unnamed field. This is always the
2212  // base of an anonymous struct/union member access, i.e. the
2213  // field is always of record type.
2214  assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2215  assert(Member->getType()->isRecordType() &&
2216  "unnamed member not of record type?");
2217 
2218  BaseResult =
2219  getSema().PerformObjectMemberConversion(BaseResult.get(),
2220  QualifierLoc.getNestedNameSpecifier(),
2221  FoundDecl, Member);
2222  if (BaseResult.isInvalid())
2223  return ExprError();
2224  Base = BaseResult.get();
2225  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2226  MemberExpr *ME = new (getSema().Context)
2227  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2228  cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2229  return ME;
2230  }
2231 
2232  CXXScopeSpec SS;
2233  SS.Adopt(QualifierLoc);
2234 
2235  Base = BaseResult.get();
2236  QualType BaseType = Base->getType();
2237 
2238  if (isArrow && !BaseType->isPointerType())
2239  return ExprError();
2240 
2241  // FIXME: this involves duplicating earlier analysis in a lot of
2242  // cases; we should avoid this when possible.
2243  LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2244  R.addDecl(FoundDecl);
2245  R.resolveKind();
2246 
2247  return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2248  SS, TemplateKWLoc,
2249  FirstQualifierInScope,
2250  R, ExplicitTemplateArgs,
2251  /*S*/nullptr);
2252  }
2253 
2254  /// \brief Build a new binary operator expression.
2255  ///
2256  /// By default, performs semantic analysis to build the new expression.
2257  /// Subclasses may override this routine to provide different behavior.
2259  BinaryOperatorKind Opc,
2260  Expr *LHS, Expr *RHS) {
2261  return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2262  }
2263 
2264  /// \brief Build a new conditional operator expression.
2265  ///
2266  /// By default, performs semantic analysis to build the new expression.
2267  /// Subclasses may override this routine to provide different behavior.
2269  SourceLocation QuestionLoc,
2270  Expr *LHS,
2272  Expr *RHS) {
2273  return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2274  LHS, RHS);
2275  }
2276 
2277  /// \brief Build a new C-style cast expression.
2278  ///
2279  /// By default, performs semantic analysis to build the new expression.
2280  /// Subclasses may override this routine to provide different behavior.
2282  TypeSourceInfo *TInfo,
2283  SourceLocation RParenLoc,
2284  Expr *SubExpr) {
2285  return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2286  SubExpr);
2287  }
2288 
2289  /// \brief Build a new compound literal expression.
2290  ///
2291  /// By default, performs semantic analysis to build the new expression.
2292  /// Subclasses may override this routine to provide different behavior.
2294  TypeSourceInfo *TInfo,
2295  SourceLocation RParenLoc,
2296  Expr *Init) {
2297  return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2298  Init);
2299  }
2300 
2301  /// \brief Build a new extended vector element access expression.
2302  ///
2303  /// By default, performs semantic analysis to build the new expression.
2304  /// Subclasses may override this routine to provide different behavior.
2306  SourceLocation OpLoc,
2307  SourceLocation AccessorLoc,
2308  IdentifierInfo &Accessor) {
2309 
2310  CXXScopeSpec SS;
2311  DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2312  return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2313  OpLoc, /*IsArrow*/ false,
2314  SS, SourceLocation(),
2315  /*FirstQualifierInScope*/ nullptr,
2316  NameInfo,
2317  /* TemplateArgs */ nullptr,
2318  /*S*/ nullptr);
2319  }
2320 
2321  /// \brief Build a new initializer list expression.
2322  ///
2323  /// By default, performs semantic analysis to build the new expression.
2324  /// Subclasses may override this routine to provide different behavior.
2327  SourceLocation RBraceLoc,
2328  QualType ResultTy) {
2330  = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2331  if (Result.isInvalid() || ResultTy->isDependentType())
2332  return Result;
2333 
2334  // Patch in the result type we were given, which may have been computed
2335  // when the initial InitListExpr was built.
2336  InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2337  ILE->setType(ResultTy);
2338  return Result;
2339  }
2340 
2341  /// \brief Build a new designated initializer expression.
2342  ///
2343  /// By default, performs semantic analysis to build the new expression.
2344  /// Subclasses may override this routine to provide different behavior.
2346  MultiExprArg ArrayExprs,
2347  SourceLocation EqualOrColonLoc,
2348  bool GNUSyntax,
2349  Expr *Init) {
2351  = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2352  Init);
2353  if (Result.isInvalid())
2354  return ExprError();
2355 
2356  return Result;
2357  }
2358 
2359  /// \brief Build a new value-initialized expression.
2360  ///
2361  /// By default, builds the implicit value initialization without performing
2362  /// any semantic analysis. Subclasses may override this routine to provide
2363  /// different behavior.
2365  return new (SemaRef.Context) ImplicitValueInitExpr(T);
2366  }
2367 
2368  /// \brief Build a new \c va_arg expression.
2369  ///
2370  /// By default, performs semantic analysis to build the new expression.
2371  /// Subclasses may override this routine to provide different behavior.
2373  Expr *SubExpr, TypeSourceInfo *TInfo,
2374  SourceLocation RParenLoc) {
2375  return getSema().BuildVAArgExpr(BuiltinLoc,
2376  SubExpr, TInfo,
2377  RParenLoc);
2378  }
2379 
2380  /// \brief Build a new expression list in parentheses.
2381  ///
2382  /// By default, performs semantic analysis to build the new expression.
2383  /// Subclasses may override this routine to provide different behavior.
2385  MultiExprArg SubExprs,
2386  SourceLocation RParenLoc) {
2387  return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2388  }
2389 
2390  /// \brief Build a new address-of-label expression.
2391  ///
2392  /// By default, performs semantic analysis, using the name of the label
2393  /// rather than attempting to map the label statement itself.
2394  /// Subclasses may override this routine to provide different behavior.
2396  SourceLocation LabelLoc, LabelDecl *Label) {
2397  return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2398  }
2399 
2400  /// \brief Build a new GNU statement expression.
2401  ///
2402  /// By default, performs semantic analysis to build the new expression.
2403  /// Subclasses may override this routine to provide different behavior.
2405  Stmt *SubStmt,
2406  SourceLocation RParenLoc) {
2407  return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2408  }
2409 
2410  /// \brief Build a new __builtin_choose_expr expression.
2411  ///
2412  /// By default, performs semantic analysis to build the new expression.
2413  /// Subclasses may override this routine to provide different behavior.
2415  Expr *Cond, Expr *LHS, Expr *RHS,
2416  SourceLocation RParenLoc) {
2417  return SemaRef.ActOnChooseExpr(BuiltinLoc,
2418  Cond, LHS, RHS,
2419  RParenLoc);
2420  }
2421 
2422  /// \brief Build a new generic selection expression.
2423  ///
2424  /// By default, performs semantic analysis to build the new expression.
2425  /// Subclasses may override this routine to provide different behavior.
2427  SourceLocation DefaultLoc,
2428  SourceLocation RParenLoc,
2429  Expr *ControllingExpr,
2431  ArrayRef<Expr *> Exprs) {
2432  return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2433  ControllingExpr, Types, Exprs);
2434  }
2435 
2436  /// \brief Build a new overloaded operator call expression.
2437  ///
2438  /// By default, performs semantic analysis to build the new expression.
2439  /// The semantic analysis provides the behavior of template instantiation,
2440  /// copying with transformations that turn what looks like an overloaded
2441  /// operator call into a use of a builtin operator, performing
2442  /// argument-dependent lookup, etc. Subclasses may override this routine to
2443  /// provide different behavior.
2444  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2445  SourceLocation OpLoc,
2446  Expr *Callee,
2447  Expr *First,
2448  Expr *Second);
2449 
2450  /// \brief Build a new C++ "named" cast expression, such as static_cast or
2451  /// reinterpret_cast.
2452  ///
2453  /// By default, this routine dispatches to one of the more-specific routines
2454  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2455  /// Subclasses may override this routine to provide different behavior.
2457  Stmt::StmtClass Class,
2458  SourceLocation LAngleLoc,
2459  TypeSourceInfo *TInfo,
2460  SourceLocation RAngleLoc,
2461  SourceLocation LParenLoc,
2462  Expr *SubExpr,
2463  SourceLocation RParenLoc) {
2464  switch (Class) {
2465  case Stmt::CXXStaticCastExprClass:
2466  return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2467  RAngleLoc, LParenLoc,
2468  SubExpr, RParenLoc);
2469 
2470  case Stmt::CXXDynamicCastExprClass:
2471  return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2472  RAngleLoc, LParenLoc,
2473  SubExpr, RParenLoc);
2474 
2475  case Stmt::CXXReinterpretCastExprClass:
2476  return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2477  RAngleLoc, LParenLoc,
2478  SubExpr,
2479  RParenLoc);
2480 
2481  case Stmt::CXXConstCastExprClass:
2482  return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2483  RAngleLoc, LParenLoc,
2484  SubExpr, RParenLoc);
2485 
2486  default:
2487  llvm_unreachable("Invalid C++ named cast");
2488  }
2489  }
2490 
2491  /// \brief Build a new C++ static_cast expression.
2492  ///
2493  /// By default, performs semantic analysis to build the new expression.
2494  /// Subclasses may override this routine to provide different behavior.
2496  SourceLocation LAngleLoc,
2497  TypeSourceInfo *TInfo,
2498  SourceLocation RAngleLoc,
2499  SourceLocation LParenLoc,
2500  Expr *SubExpr,
2501  SourceLocation RParenLoc) {
2502  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2503  TInfo, SubExpr,
2504  SourceRange(LAngleLoc, RAngleLoc),
2505  SourceRange(LParenLoc, RParenLoc));
2506  }
2507 
2508  /// \brief Build a new C++ dynamic_cast expression.
2509  ///
2510  /// By default, performs semantic analysis to build the new expression.
2511  /// Subclasses may override this routine to provide different behavior.
2513  SourceLocation LAngleLoc,
2514  TypeSourceInfo *TInfo,
2515  SourceLocation RAngleLoc,
2516  SourceLocation LParenLoc,
2517  Expr *SubExpr,
2518  SourceLocation RParenLoc) {
2519  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2520  TInfo, SubExpr,
2521  SourceRange(LAngleLoc, RAngleLoc),
2522  SourceRange(LParenLoc, RParenLoc));
2523  }
2524 
2525  /// \brief Build a new C++ reinterpret_cast expression.
2526  ///
2527  /// By default, performs semantic analysis to build the new expression.
2528  /// Subclasses may override this routine to provide different behavior.
2530  SourceLocation LAngleLoc,
2531  TypeSourceInfo *TInfo,
2532  SourceLocation RAngleLoc,
2533  SourceLocation LParenLoc,
2534  Expr *SubExpr,
2535  SourceLocation RParenLoc) {
2536  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2537  TInfo, SubExpr,
2538  SourceRange(LAngleLoc, RAngleLoc),
2539  SourceRange(LParenLoc, RParenLoc));
2540  }
2541 
2542  /// \brief Build a new C++ const_cast expression.
2543  ///
2544  /// By default, performs semantic analysis to build the new expression.
2545  /// Subclasses may override this routine to provide different behavior.
2547  SourceLocation LAngleLoc,
2548  TypeSourceInfo *TInfo,
2549  SourceLocation RAngleLoc,
2550  SourceLocation LParenLoc,
2551  Expr *SubExpr,
2552  SourceLocation RParenLoc) {
2553  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2554  TInfo, SubExpr,
2555  SourceRange(LAngleLoc, RAngleLoc),
2556  SourceRange(LParenLoc, RParenLoc));
2557  }
2558 
2559  /// \brief Build a new C++ functional-style cast expression.
2560  ///
2561  /// By default, performs semantic analysis to build the new expression.
2562  /// Subclasses may override this routine to provide different behavior.
2564  SourceLocation LParenLoc,
2565  Expr *Sub,
2566  SourceLocation RParenLoc) {
2567  return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2568  MultiExprArg(&Sub, 1),
2569  RParenLoc);
2570  }
2571 
2572  /// \brief Build a new C++ typeid(type) expression.
2573  ///
2574  /// By default, performs semantic analysis to build the new expression.
2575  /// Subclasses may override this routine to provide different behavior.
2577  SourceLocation TypeidLoc,
2578  TypeSourceInfo *Operand,
2579  SourceLocation RParenLoc) {
2580  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2581  RParenLoc);
2582  }
2583 
2584 
2585  /// \brief Build a new C++ typeid(expr) expression.
2586  ///
2587  /// By default, performs semantic analysis to build the new expression.
2588  /// Subclasses may override this routine to provide different behavior.
2590  SourceLocation TypeidLoc,
2591  Expr *Operand,
2592  SourceLocation RParenLoc) {
2593  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2594  RParenLoc);
2595  }
2596 
2597  /// \brief Build a new C++ __uuidof(type) expression.
2598  ///
2599  /// By default, performs semantic analysis to build the new expression.
2600  /// Subclasses may override this routine to provide different behavior.
2602  SourceLocation TypeidLoc,
2603  TypeSourceInfo *Operand,
2604  SourceLocation RParenLoc) {
2605  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2606  RParenLoc);
2607  }
2608 
2609  /// \brief Build a new C++ __uuidof(expr) expression.
2610  ///
2611  /// By default, performs semantic analysis to build the new expression.
2612  /// Subclasses may override this routine to provide different behavior.
2614  SourceLocation TypeidLoc,
2615  Expr *Operand,
2616  SourceLocation RParenLoc) {
2617  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2618  RParenLoc);
2619  }
2620 
2621  /// \brief Build a new C++ "this" expression.
2622  ///
2623  /// By default, builds a new "this" expression without performing any
2624  /// semantic analysis. Subclasses may override this routine to provide
2625  /// different behavior.
2627  QualType ThisType,
2628  bool isImplicit) {
2629  getSema().CheckCXXThisCapture(ThisLoc);
2630  return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2631  }
2632 
2633  /// \brief Build a new C++ throw expression.
2634  ///
2635  /// By default, performs semantic analysis to build the new expression.
2636  /// Subclasses may override this routine to provide different behavior.
2638  bool IsThrownVariableInScope) {
2639  return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2640  }
2641 
2642  /// \brief Build a new C++ default-argument expression.
2643  ///
2644  /// By default, builds a new default-argument expression, which does not
2645  /// require any semantic analysis. Subclasses may override this routine to
2646  /// provide different behavior.
2648  ParmVarDecl *Param) {
2649  return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2650  }
2651 
2652  /// \brief Build a new C++11 default-initialization expression.
2653  ///
2654  /// By default, builds a new default field initialization expression, which
2655  /// does not require any semantic analysis. Subclasses may override this
2656  /// routine to provide different behavior.
2658  FieldDecl *Field) {
2659  return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2660  }
2661 
2662  /// \brief Build a new C++ zero-initialization expression.
2663  ///
2664  /// By default, performs semantic analysis to build the new expression.
2665  /// Subclasses may override this routine to provide different behavior.
2667  SourceLocation LParenLoc,
2668  SourceLocation RParenLoc) {
2669  return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2670  None, RParenLoc);
2671  }
2672 
2673  /// \brief Build a new C++ "new" expression.
2674  ///
2675  /// By default, performs semantic analysis to build the new expression.
2676  /// Subclasses may override this routine to provide different behavior.
2678  bool UseGlobal,
2679  SourceLocation PlacementLParen,
2680  MultiExprArg PlacementArgs,
2681  SourceLocation PlacementRParen,
2682  SourceRange TypeIdParens,
2683  QualType AllocatedType,
2684  TypeSourceInfo *AllocatedTypeInfo,
2685  Expr *ArraySize,
2686  SourceRange DirectInitRange,
2687  Expr *Initializer) {
2688  return getSema().BuildCXXNew(StartLoc, UseGlobal,
2689  PlacementLParen,
2690  PlacementArgs,
2691  PlacementRParen,
2692  TypeIdParens,
2693  AllocatedType,
2694  AllocatedTypeInfo,
2695  ArraySize,
2696  DirectInitRange,
2697  Initializer);
2698  }
2699 
2700  /// \brief Build a new C++ "delete" expression.
2701  ///
2702  /// By default, performs semantic analysis to build the new expression.
2703  /// Subclasses may override this routine to provide different behavior.
2705  bool IsGlobalDelete,
2706  bool IsArrayForm,
2707  Expr *Operand) {
2708  return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2709  Operand);
2710  }
2711 
2712  /// \brief Build a new type trait expression.
2713  ///
2714  /// By default, performs semantic analysis to build the new expression.
2715  /// Subclasses may override this routine to provide different behavior.
2717  SourceLocation StartLoc,
2719  SourceLocation RParenLoc) {
2720  return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2721  }
2722 
2723  /// \brief Build a new array type trait expression.
2724  ///
2725  /// By default, performs semantic analysis to build the new expression.
2726  /// Subclasses may override this routine to provide different behavior.
2728  SourceLocation StartLoc,
2729  TypeSourceInfo *TSInfo,
2730  Expr *DimExpr,
2731  SourceLocation RParenLoc) {
2732  return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2733  }
2734 
2735  /// \brief Build a new expression trait expression.
2736  ///
2737  /// By default, performs semantic analysis to build the new expression.
2738  /// Subclasses may override this routine to provide different behavior.
2740  SourceLocation StartLoc,
2741  Expr *Queried,
2742  SourceLocation RParenLoc) {
2743  return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2744  }
2745 
2746  /// \brief Build a new (previously unresolved) declaration reference
2747  /// expression.
2748  ///
2749  /// By default, performs semantic analysis to build the new expression.
2750  /// Subclasses may override this routine to provide different behavior.
2752  NestedNameSpecifierLoc QualifierLoc,
2753  SourceLocation TemplateKWLoc,
2754  const DeclarationNameInfo &NameInfo,
2755  const TemplateArgumentListInfo *TemplateArgs,
2756  bool IsAddressOfOperand,
2757  TypeSourceInfo **RecoveryTSI) {
2758  CXXScopeSpec SS;
2759  SS.Adopt(QualifierLoc);
2760 
2761  if (TemplateArgs || TemplateKWLoc.isValid())
2762  return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2763  TemplateArgs);
2764 
2765  return getSema().BuildQualifiedDeclarationNameExpr(
2766  SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2767  }
2768 
2769  /// \brief Build a new template-id expression.
2770  ///
2771  /// By default, performs semantic analysis to build the new expression.
2772  /// Subclasses may override this routine to provide different behavior.
2774  SourceLocation TemplateKWLoc,
2775  LookupResult &R,
2776  bool RequiresADL,
2777  const TemplateArgumentListInfo *TemplateArgs) {
2778  return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2779  TemplateArgs);
2780  }
2781 
2782  /// \brief Build a new object-construction expression.
2783  ///
2784  /// By default, performs semantic analysis to build the new expression.
2785  /// Subclasses may override this routine to provide different behavior.
2787  SourceLocation Loc,
2788  CXXConstructorDecl *Constructor,
2789  bool IsElidable,
2790  MultiExprArg Args,
2791  bool HadMultipleCandidates,
2792  bool ListInitialization,
2793  bool StdInitListInitialization,
2794  bool RequiresZeroInit,
2795  CXXConstructExpr::ConstructionKind ConstructKind,
2796  SourceRange ParenRange) {
2797  SmallVector<Expr*, 8> ConvertedArgs;
2798  if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2799  ConvertedArgs))
2800  return ExprError();
2801 
2802  return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2803  IsElidable,
2804  ConvertedArgs,
2805  HadMultipleCandidates,
2806  ListInitialization,
2807  StdInitListInitialization,
2808  RequiresZeroInit, ConstructKind,
2809  ParenRange);
2810  }
2811 
2812  /// \brief Build a new implicit construction via inherited constructor
2813  /// expression.
2815  CXXConstructorDecl *Constructor,
2816  bool ConstructsVBase,
2817  bool InheritedFromVBase) {
2818  return new (getSema().Context) CXXInheritedCtorInitExpr(
2819  Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2820  }
2821 
2822  /// \brief Build a new object-construction expression.
2823  ///
2824  /// By default, performs semantic analysis to build the new expression.
2825  /// Subclasses may override this routine to provide different behavior.
2827  SourceLocation LParenLoc,
2828  MultiExprArg Args,
2829  SourceLocation RParenLoc) {
2830  return getSema().BuildCXXTypeConstructExpr(TSInfo,
2831  LParenLoc,
2832  Args,
2833  RParenLoc);
2834  }
2835 
2836  /// \brief Build a new object-construction expression.
2837  ///
2838  /// By default, performs semantic analysis to build the new expression.
2839  /// Subclasses may override this routine to provide different behavior.
2841  SourceLocation LParenLoc,
2842  MultiExprArg Args,
2843  SourceLocation RParenLoc) {
2844  return getSema().BuildCXXTypeConstructExpr(TSInfo,
2845  LParenLoc,
2846  Args,
2847  RParenLoc);
2848  }
2849 
2850  /// \brief Build a new member reference expression.
2851  ///
2852  /// By default, performs semantic analysis to build the new expression.
2853  /// Subclasses may override this routine to provide different behavior.
2855  QualType BaseType,
2856  bool IsArrow,
2857  SourceLocation OperatorLoc,
2858  NestedNameSpecifierLoc QualifierLoc,
2859  SourceLocation TemplateKWLoc,
2860  NamedDecl *FirstQualifierInScope,
2861  const DeclarationNameInfo &MemberNameInfo,
2862  const TemplateArgumentListInfo *TemplateArgs) {
2863  CXXScopeSpec SS;
2864  SS.Adopt(QualifierLoc);
2865 
2866  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2867  OperatorLoc, IsArrow,
2868  SS, TemplateKWLoc,
2869  FirstQualifierInScope,
2870  MemberNameInfo,
2871  TemplateArgs, /*S*/nullptr);
2872  }
2873 
2874  /// \brief Build a new member reference expression.
2875  ///
2876  /// By default, performs semantic analysis to build the new expression.
2877  /// Subclasses may override this routine to provide different behavior.
2879  SourceLocation OperatorLoc,
2880  bool IsArrow,
2881  NestedNameSpecifierLoc QualifierLoc,
2882  SourceLocation TemplateKWLoc,
2883  NamedDecl *FirstQualifierInScope,
2884  LookupResult &R,
2885  const TemplateArgumentListInfo *TemplateArgs) {
2886  CXXScopeSpec SS;
2887  SS.Adopt(QualifierLoc);
2888 
2889  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2890  OperatorLoc, IsArrow,
2891  SS, TemplateKWLoc,
2892  FirstQualifierInScope,
2893  R, TemplateArgs, /*S*/nullptr);
2894  }
2895 
2896  /// \brief Build a new noexcept expression.
2897  ///
2898  /// By default, performs semantic analysis to build the new expression.
2899  /// Subclasses may override this routine to provide different behavior.
2901  return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2902  }
2903 
2904  /// \brief Build a new expression to compute the length of a parameter pack.
2906  NamedDecl *Pack,
2907  SourceLocation PackLoc,
2908  SourceLocation RParenLoc,
2910  ArrayRef<TemplateArgument> PartialArgs) {
2911  return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2912  RParenLoc, Length, PartialArgs);
2913  }
2914 
2915  /// \brief Build a new Objective-C boxed expression.
2916  ///
2917  /// By default, performs semantic analysis to build the new expression.
2918  /// Subclasses may override this routine to provide different behavior.
2920  return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2921  }
2922 
2923  /// \brief Build a new Objective-C array literal.
2924  ///
2925  /// By default, performs semantic analysis to build the new expression.
2926  /// Subclasses may override this routine to provide different behavior.
2928  Expr **Elements, unsigned NumElements) {
2929  return getSema().BuildObjCArrayLiteral(Range,
2930  MultiExprArg(Elements, NumElements));
2931  }
2932 
2934  Expr *Base, Expr *Key,
2935  ObjCMethodDecl *getterMethod,
2936  ObjCMethodDecl *setterMethod) {
2937  return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2938  getterMethod, setterMethod);
2939  }
2940 
2941  /// \brief Build a new Objective-C dictionary literal.
2942  ///
2943  /// By default, performs semantic analysis to build the new expression.
2944  /// Subclasses may override this routine to provide different behavior.
2947  return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2948  }
2949 
2950  /// \brief Build a new Objective-C \@encode expression.
2951  ///
2952  /// By default, performs semantic analysis to build the new expression.
2953  /// Subclasses may override this routine to provide different behavior.
2955  TypeSourceInfo *EncodeTypeInfo,
2956  SourceLocation RParenLoc) {
2957  return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2958  }
2959 
2960  /// \brief Build a new Objective-C class message.
2962  Selector Sel,
2963  ArrayRef<SourceLocation> SelectorLocs,
2964  ObjCMethodDecl *Method,
2965  SourceLocation LBracLoc,
2966  MultiExprArg Args,
2967  SourceLocation RBracLoc) {
2968  return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2969  ReceiverTypeInfo->getType(),
2970  /*SuperLoc=*/SourceLocation(),
2971  Sel, Method, LBracLoc, SelectorLocs,
2972  RBracLoc, Args);
2973  }
2974 
2975  /// \brief Build a new Objective-C instance message.
2977  Selector Sel,
2978  ArrayRef<SourceLocation> SelectorLocs,
2979  ObjCMethodDecl *Method,
2980  SourceLocation LBracLoc,
2981  MultiExprArg Args,
2982  SourceLocation RBracLoc) {
2983  return SemaRef.BuildInstanceMessage(Receiver,
2984  Receiver->getType(),
2985  /*SuperLoc=*/SourceLocation(),
2986  Sel, Method, LBracLoc, SelectorLocs,
2987  RBracLoc, Args);
2988  }
2989 
2990  /// \brief Build a new Objective-C instance/class message to 'super'.
2992  Selector Sel,
2993  ArrayRef<SourceLocation> SelectorLocs,
2994  QualType SuperType,
2995  ObjCMethodDecl *Method,
2996  SourceLocation LBracLoc,
2997  MultiExprArg Args,
2998  SourceLocation RBracLoc) {
2999  return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3000  SuperType,
3001  SuperLoc,
3002  Sel, Method, LBracLoc, SelectorLocs,
3003  RBracLoc, Args)
3004  : SemaRef.BuildClassMessage(nullptr,
3005  SuperType,
3006  SuperLoc,
3007  Sel, Method, LBracLoc, SelectorLocs,
3008  RBracLoc, Args);
3009 
3010 
3011  }
3012 
3013  /// \brief Build a new Objective-C ivar reference expression.
3014  ///
3015  /// By default, performs semantic analysis to build the new expression.
3016  /// Subclasses may override this routine to provide different behavior.
3018  SourceLocation IvarLoc,
3019  bool IsArrow, bool IsFreeIvar) {
3020  CXXScopeSpec SS;
3021  DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3022  ExprResult Result = getSema().BuildMemberReferenceExpr(
3023  BaseArg, BaseArg->getType(),
3024  /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3025  /*FirstQualifierInScope=*/nullptr, NameInfo,
3026  /*TemplateArgs=*/nullptr,
3027  /*S=*/nullptr);
3028  if (IsFreeIvar && Result.isUsable())
3029  cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3030  return Result;
3031  }
3032 
3033  /// \brief Build a new Objective-C property reference expression.
3034  ///
3035  /// By default, performs semantic analysis to build the new expression.
3036  /// Subclasses may override this routine to provide different behavior.
3038  ObjCPropertyDecl *Property,
3039  SourceLocation PropertyLoc) {
3040  CXXScopeSpec SS;
3041  DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3042  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3043  /*FIXME:*/PropertyLoc,
3044  /*IsArrow=*/false,
3045  SS, SourceLocation(),
3046  /*FirstQualifierInScope=*/nullptr,
3047  NameInfo,
3048  /*TemplateArgs=*/nullptr,
3049  /*S=*/nullptr);
3050  }
3051 
3052  /// \brief Build a new Objective-C property reference expression.
3053  ///
3054  /// By default, performs semantic analysis to build the new expression.
3055  /// Subclasses may override this routine to provide different behavior.
3057  ObjCMethodDecl *Getter,
3058  ObjCMethodDecl *Setter,
3059  SourceLocation PropertyLoc) {
3060  // Since these expressions can only be value-dependent, we do not
3061  // need to perform semantic analysis again.
3062  return Owned(
3063  new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3065  PropertyLoc, Base));
3066  }
3067 
3068  /// \brief Build a new Objective-C "isa" expression.
3069  ///
3070  /// By default, performs semantic analysis to build the new expression.
3071  /// Subclasses may override this routine to provide different behavior.
3073  SourceLocation OpLoc, bool IsArrow) {
3074  CXXScopeSpec SS;
3075  DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3076  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3077  OpLoc, IsArrow,
3078  SS, SourceLocation(),
3079  /*FirstQualifierInScope=*/nullptr,
3080  NameInfo,
3081  /*TemplateArgs=*/nullptr,
3082  /*S=*/nullptr);
3083  }
3084 
3085  /// \brief Build a new shuffle vector expression.
3086  ///
3087  /// By default, performs semantic analysis to build the new expression.
3088  /// Subclasses may override this routine to provide different behavior.
3090  MultiExprArg SubExprs,
3091  SourceLocation RParenLoc) {
3092  // Find the declaration for __builtin_shufflevector
3093  const IdentifierInfo &Name
3094  = SemaRef.Context.Idents.get("__builtin_shufflevector");
3095  TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3096  DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3097  assert(!Lookup.empty() && "No __builtin_shufflevector?");
3098 
3099  // Build a reference to the __builtin_shufflevector builtin
3100  FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3101  Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3102  SemaRef.Context.BuiltinFnTy,
3103  VK_RValue, BuiltinLoc);
3104  QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3105  Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3106  CK_BuiltinFnToFnPtr).get();
3107 
3108  // Build the CallExpr
3109  ExprResult TheCall = new (SemaRef.Context) CallExpr(
3110  SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3111  Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3112 
3113  // Type-check the __builtin_shufflevector expression.
3114  return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3115  }
3116 
3117  /// \brief Build a new convert vector expression.
3119  Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3120  SourceLocation RParenLoc) {
3121  return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3122  BuiltinLoc, RParenLoc);
3123  }
3124 
3125  /// \brief Build a new template argument pack expansion.
3126  ///
3127  /// By default, performs semantic analysis to build a new pack expansion
3128  /// for a template argument. Subclasses may override this routine to provide
3129  /// different behavior.
3131  SourceLocation EllipsisLoc,
3132  Optional<unsigned> NumExpansions) {
3133  switch (Pattern.getArgument().getKind()) {
3136  = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3137  EllipsisLoc, NumExpansions);
3138  if (Result.isInvalid())
3139  return TemplateArgumentLoc();
3140 
3141  return TemplateArgumentLoc(Result.get(), Result.get());
3142  }
3143 
3146  Pattern.getArgument().getAsTemplate(),
3147  NumExpansions),
3148  Pattern.getTemplateQualifierLoc(),
3149  Pattern.getTemplateNameLoc(),
3150  EllipsisLoc);
3151 
3158  llvm_unreachable("Pack expansion pattern has no parameter packs");
3159 
3161  if (TypeSourceInfo *Expansion
3162  = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3163  EllipsisLoc,
3164  NumExpansions))
3165  return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3166  Expansion);
3167  break;
3168  }
3169 
3170  return TemplateArgumentLoc();
3171  }
3172 
3173  /// \brief Build a new expression pack expansion.
3174  ///
3175  /// By default, performs semantic analysis to build a new pack expansion
3176  /// for an expression. Subclasses may override this routine to provide
3177  /// different behavior.
3179  Optional<unsigned> NumExpansions) {
3180  return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3181  }
3182 
3183  /// \brief Build a new C++1z fold-expression.
3184  ///
3185  /// By default, performs semantic analysis in order to build a new fold
3186  /// expression.
3188  BinaryOperatorKind Operator,
3189  SourceLocation EllipsisLoc, Expr *RHS,
3190  SourceLocation RParenLoc) {
3191  return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3192  RHS, RParenLoc);
3193  }
3194 
3195  /// \brief Build an empty C++1z fold-expression with the given operator.
3196  ///
3197  /// By default, produces the fallback value for the fold-expression, or
3198  /// produce an error if there is no fallback value.
3200  BinaryOperatorKind Operator) {
3201  return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3202  }
3203 
3204  /// \brief Build a new atomic operation expression.
3205  ///
3206  /// By default, performs semantic analysis to build the new expression.
3207  /// Subclasses may override this routine to provide different behavior.
3209  MultiExprArg SubExprs,
3210  QualType RetTy,
3212  SourceLocation RParenLoc) {
3213  // Just create the expression; there is not any interesting semantic
3214  // analysis here because we can't actually build an AtomicExpr until
3215  // we are sure it is semantically sound.
3216  return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3217  RParenLoc);
3218  }
3219 
3220 private:
3221  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3222  QualType ObjectType,
3223  NamedDecl *FirstQualifierInScope,
3224  CXXScopeSpec &SS);
3225 
3226  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3227  QualType ObjectType,
3228  NamedDecl *FirstQualifierInScope,
3229  CXXScopeSpec &SS);
3230 
3231  TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3232  NamedDecl *FirstQualifierInScope,
3233  CXXScopeSpec &SS);
3234 
3235  QualType TransformDependentNameType(TypeLocBuilder &TLB,
3237  bool DeducibleTSTContext);
3238 };
3239 
3240 template<typename Derived>
3242  if (!S)
3243  return S;
3244 
3245  switch (S->getStmtClass()) {
3246  case Stmt::NoStmtClass: break;
3247 
3248  // Transform individual statement nodes
3249 #define STMT(Node, Parent) \
3250  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3251 #define ABSTRACT_STMT(Node)
3252 #define EXPR(Node, Parent)
3253 #include "clang/AST/StmtNodes.inc"
3254 
3255  // Transform expressions by calling TransformExpr.
3256 #define STMT(Node, Parent)
3257 #define ABSTRACT_STMT(Stmt)
3258 #define EXPR(Node, Parent) case Stmt::Node##Class:
3259 #include "clang/AST/StmtNodes.inc"
3260  {
3261  ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3262  if (E.isInvalid())
3263  return StmtError();
3264 
3265  return getSema().ActOnExprStmt(E);
3266  }
3267  }
3268 
3269  return S;
3270 }
3271 
3272 template<typename Derived>
3274  if (!S)
3275  return S;
3276 
3277  switch (S->getClauseKind()) {
3278  default: break;
3279  // Transform individual clause nodes
3280 #define OPENMP_CLAUSE(Name, Class) \
3281  case OMPC_ ## Name : \
3282  return getDerived().Transform ## Class(cast<Class>(S));
3283 #include "clang/Basic/OpenMPKinds.def"
3284  }
3285 
3286  return S;
3287 }
3288 
3289 
3290 template<typename Derived>
3292  if (!E)
3293  return E;
3294 
3295  switch (E->getStmtClass()) {
3296  case Stmt::NoStmtClass: break;
3297 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3298 #define ABSTRACT_STMT(Stmt)
3299 #define EXPR(Node, Parent) \
3300  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3301 #include "clang/AST/StmtNodes.inc"
3302  }
3303 
3304  return E;
3305 }
3306 
3307 template<typename Derived>
3309  bool NotCopyInit) {
3310  // Initializers are instantiated like expressions, except that various outer
3311  // layers are stripped.
3312  if (!Init)
3313  return Init;
3314 
3315  if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3316  Init = ExprTemp->getSubExpr();
3317 
3318  if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3319  Init = AIL->getCommonExpr();
3320 
3321  if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3322  Init = MTE->GetTemporaryExpr();
3323 
3324  while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3325  Init = Binder->getSubExpr();
3326 
3327  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3328  Init = ICE->getSubExprAsWritten();
3329 
3330  if (CXXStdInitializerListExpr *ILE =
3331  dyn_cast<CXXStdInitializerListExpr>(Init))
3332  return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3333 
3334  // If this is copy-initialization, we only need to reconstruct
3335  // InitListExprs. Other forms of copy-initialization will be a no-op if
3336  // the initializer is already the right type.
3337  CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3338  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3339  return getDerived().TransformExpr(Init);
3340 
3341  // Revert value-initialization back to empty parens.
3342  if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3343  SourceRange Parens = VIE->getSourceRange();
3344  return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3345  Parens.getEnd());
3346  }
3347 
3348  // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3349  if (isa<ImplicitValueInitExpr>(Init))
3350  return getDerived().RebuildParenListExpr(SourceLocation(), None,
3351  SourceLocation());
3352 
3353  // Revert initialization by constructor back to a parenthesized or braced list
3354  // of expressions. Any other form of initializer can just be reused directly.
3355  if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3356  return getDerived().TransformExpr(Init);
3357 
3358  // If the initialization implicitly converted an initializer list to a
3359  // std::initializer_list object, unwrap the std::initializer_list too.
3360  if (Construct && Construct->isStdInitListInitialization())
3361  return TransformInitializer(Construct->getArg(0), NotCopyInit);
3362 
3363  SmallVector<Expr*, 8> NewArgs;
3364  bool ArgChanged = false;
3365  if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3366  /*IsCall*/true, NewArgs, &ArgChanged))
3367  return ExprError();
3368 
3369  // If this was list initialization, revert to list form.
3370  if (Construct->isListInitialization())
3371  return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3372  Construct->getLocEnd(),
3373  Construct->getType());
3374 
3375  // Build a ParenListExpr to represent anything else.
3376  SourceRange Parens = Construct->getParenOrBraceRange();
3377  if (Parens.isInvalid()) {
3378  // This was a variable declaration's initialization for which no initializer
3379  // was specified.
3380  assert(NewArgs.empty() &&
3381  "no parens or braces but have direct init with arguments?");
3382  return ExprEmpty();
3383  }
3384  return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3385  Parens.getEnd());
3386 }
3387 
3388 template<typename Derived>
3390  unsigned NumInputs,
3391  bool IsCall,
3392  SmallVectorImpl<Expr *> &Outputs,
3393  bool *ArgChanged) {
3394  for (unsigned I = 0; I != NumInputs; ++I) {
3395  // If requested, drop call arguments that need to be dropped.
3396  if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3397  if (ArgChanged)
3398  *ArgChanged = true;
3399 
3400  break;
3401  }
3402 
3403  if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3404  Expr *Pattern = Expansion->getPattern();
3405 
3407  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3408  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3409 
3410  // Determine whether the set of unexpanded parameter packs can and should
3411  // be expanded.
3412  bool Expand = true;
3413  bool RetainExpansion = false;
3414  Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3415  Optional<unsigned> NumExpansions = OrigNumExpansions;
3416  if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3417  Pattern->getSourceRange(),
3418  Unexpanded,
3419  Expand, RetainExpansion,
3420  NumExpansions))
3421  return true;
3422 
3423  if (!Expand) {
3424  // The transform has determined that we should perform a simple
3425  // transformation on the pack expansion, producing another pack
3426  // expansion.
3427  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3428  ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3429  if (OutPattern.isInvalid())
3430  return true;
3431 
3432  ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3433  Expansion->getEllipsisLoc(),
3434  NumExpansions);
3435  if (Out.isInvalid())
3436  return true;
3437 
3438  if (ArgChanged)
3439  *ArgChanged = true;
3440  Outputs.push_back(Out.get());
3441  continue;
3442  }
3443 
3444  // Record right away that the argument was changed. This needs
3445  // to happen even if the array expands to nothing.
3446  if (ArgChanged) *ArgChanged = true;
3447 
3448  // The transform has determined that we should perform an elementwise
3449  // expansion of the pattern. Do so.
3450  for (unsigned I = 0; I != *NumExpansions; ++I) {
3451  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3452  ExprResult Out = getDerived().TransformExpr(Pattern);
3453  if (Out.isInvalid())
3454  return true;
3455 
3456  if (Out.get()->containsUnexpandedParameterPack()) {
3457  Out = getDerived().RebuildPackExpansion(
3458  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3459  if (Out.isInvalid())
3460  return true;
3461  }
3462 
3463  Outputs.push_back(Out.get());
3464  }
3465 
3466  // If we're supposed to retain a pack expansion, do so by temporarily
3467  // forgetting the partially-substituted parameter pack.
3468  if (RetainExpansion) {
3469  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3470 
3471  ExprResult Out = getDerived().TransformExpr(Pattern);
3472  if (Out.isInvalid())
3473  return true;
3474 
3475  Out = getDerived().RebuildPackExpansion(
3476  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3477  if (Out.isInvalid())
3478  return true;
3479 
3480  Outputs.push_back(Out.get());
3481  }
3482 
3483  continue;
3484  }
3485 
3486  ExprResult Result =
3487  IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3488  : getDerived().TransformExpr(Inputs[I]);
3489  if (Result.isInvalid())
3490  return true;
3491 
3492  if (Result.get() != Inputs[I] && ArgChanged)
3493  *ArgChanged = true;
3494 
3495  Outputs.push_back(Result.get());
3496  }
3497 
3498  return false;
3499 }
3500 
3501 template <typename Derived>
3504  if (Var) {
3505  VarDecl *ConditionVar = cast_or_null<VarDecl>(
3506  getDerived().TransformDefinition(Var->getLocation(), Var));
3507 
3508  if (!ConditionVar)
3509  return Sema::ConditionError();
3510 
3511  return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3512  }
3513 
3514  if (Expr) {
3515  ExprResult CondExpr = getDerived().TransformExpr(Expr);
3516 
3517  if (CondExpr.isInvalid())
3518  return Sema::ConditionError();
3519 
3520  return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3521  }
3522 
3523  return Sema::ConditionResult();
3524 }
3525 
3526 template<typename Derived>
3530  QualType ObjectType,
3531  NamedDecl *FirstQualifierInScope) {
3533  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3534  Qualifier = Qualifier.getPrefix())
3535  Qualifiers.push_back(Qualifier);
3536 
3537  CXXScopeSpec SS;
3538  while (!Qualifiers.empty()) {
3539  NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3541 
3542  switch (QNNS->getKind()) {
3545  Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3546  if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3547  SS, FirstQualifierInScope, false))
3548  return NestedNameSpecifierLoc();
3549  }
3550  break;
3551 
3553  NamespaceDecl *NS
3554  = cast_or_null<NamespaceDecl>(
3555  getDerived().TransformDecl(
3556  Q.getLocalBeginLoc(),
3557  QNNS->getAsNamespace()));
3558  SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3559  break;
3560  }
3561 
3563  NamespaceAliasDecl *Alias
3564  = cast_or_null<NamespaceAliasDecl>(
3565  getDerived().TransformDecl(Q.getLocalBeginLoc(),
3566  QNNS->getAsNamespaceAlias()));
3567  SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3568  Q.getLocalEndLoc());
3569  break;
3570  }
3571 
3573  // There is no meaningful transformation that one could perform on the
3574  // global scope.
3575  SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3576  break;
3577 
3579  CXXRecordDecl *RD =
3580  cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3581  SourceLocation(), QNNS->getAsRecordDecl()));
3582  SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3583  break;
3584  }
3585 
3588  TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3589  FirstQualifierInScope, SS);
3590 
3591  if (!TL)
3592  return NestedNameSpecifierLoc();
3593 
3594  if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3595  (SemaRef.getLangOpts().CPlusPlus11 &&
3596  TL.getType()->isEnumeralType())) {
3597  assert(!TL.getType().hasLocalQualifiers() &&
3598  "Can't get cv-qualifiers here");
3599  if (TL.getType()->isEnumeralType())
3600  SemaRef.Diag(TL.getBeginLoc(),
3601  diag::warn_cxx98_compat_enum_nested_name_spec);
3602  SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3603  Q.getLocalEndLoc());
3604  break;
3605  }
3606  // If the nested-name-specifier is an invalid type def, don't emit an
3607  // error because a previous error should have already been emitted.
3608  TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3609  if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3610  SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3611  << TL.getType() << SS.getRange();
3612  }
3613  return NestedNameSpecifierLoc();
3614  }
3615  }
3616 
3617  // The qualifier-in-scope and object type only apply to the leftmost entity.
3618  FirstQualifierInScope = nullptr;
3619  ObjectType = QualType();
3620  }
3621 
3622  // Don't rebuild the nested-name-specifier if we don't have to.
3623  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3624  !getDerived().AlwaysRebuild())
3625  return NNS;
3626 
3627  // If we can re-use the source-location data from the original
3628  // nested-name-specifier, do so.
3629  if (SS.location_size() == NNS.getDataLength() &&
3630  memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3631  return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3632 
3633  // Allocate new nested-name-specifier location information.
3634  return SS.getWithLocInContext(SemaRef.Context);
3635 }
3636 
3637 template<typename Derived>
3641  DeclarationName Name = NameInfo.getName();
3642  if (!Name)
3643  return DeclarationNameInfo();
3644 
3645  switch (Name.getNameKind()) {
3653  return NameInfo;
3654 
3656  TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3657  TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3658  getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3659  if (!NewTemplate)
3660  return DeclarationNameInfo();
3661 
3662  DeclarationNameInfo NewNameInfo(NameInfo);
3663  NewNameInfo.setName(
3664  SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3665  return NewNameInfo;
3666  }
3667 
3671  TypeSourceInfo *NewTInfo;
3672  CanQualType NewCanTy;
3673  if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3674  NewTInfo = getDerived().TransformType(OldTInfo);
3675  if (!NewTInfo)
3676  return DeclarationNameInfo();
3677  NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3678  }
3679  else {
3680  NewTInfo = nullptr;
3681  TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3682  QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3683  if (NewT.isNull())
3684  return DeclarationNameInfo();
3685  NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3686  }
3687 
3688  DeclarationName NewName
3689  = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3690  NewCanTy);
3691  DeclarationNameInfo NewNameInfo(NameInfo);
3692  NewNameInfo.setName(NewName);
3693  NewNameInfo.setNamedTypeInfo(NewTInfo);
3694  return NewNameInfo;
3695  }
3696  }
3697 
3698  llvm_unreachable("Unknown name kind.");
3699 }
3700 
3701 template<typename Derived>
3705  SourceLocation NameLoc,
3706  QualType ObjectType,
3707  NamedDecl *FirstQualifierInScope,
3708  bool AllowInjectedClassName) {
3710  TemplateDecl *Template = QTN->getTemplateDecl();
3711  assert(Template && "qualified template name must refer to a template");
3712 
3713  TemplateDecl *TransTemplate
3714  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3715  Template));
3716  if (!TransTemplate)
3717  return TemplateName();
3718 
3719  if (!getDerived().AlwaysRebuild() &&
3720  SS.getScopeRep() == QTN->getQualifier() &&
3721  TransTemplate == Template)
3722  return Name;
3723 
3724  return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3725  TransTemplate);
3726  }
3727 
3729  if (SS.getScopeRep()) {
3730  // These apply to the scope specifier, not the template.
3731  ObjectType = QualType();
3732  FirstQualifierInScope = nullptr;
3733  }
3734 
3735  if (!getDerived().AlwaysRebuild() &&
3736  SS.getScopeRep() == DTN->getQualifier() &&
3737  ObjectType.isNull())
3738  return Name;
3739 
3740  if (DTN->isIdentifier()) {
3741  return getDerived().RebuildTemplateName(SS,
3742  *DTN->getIdentifier(),
3743  NameLoc,
3744  ObjectType,
3745  FirstQualifierInScope,
3746  AllowInjectedClassName);
3747  }
3748 
3749  return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3750  ObjectType, AllowInjectedClassName);
3751  }
3752 
3753  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3754  TemplateDecl *TransTemplate
3755  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3756  Template));
3757  if (!TransTemplate)
3758  return TemplateName();
3759 
3760  if (!getDerived().AlwaysRebuild() &&
3761  TransTemplate == Template)
3762  return Name;
3763 
3764  return TemplateName(TransTemplate);
3765  }
3766 
3769  TemplateTemplateParmDecl *TransParam
3770  = cast_or_null<TemplateTemplateParmDecl>(
3771  getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3772  if (!TransParam)
3773  return TemplateName();
3774 
3775  if (!getDerived().AlwaysRebuild() &&
3776  TransParam == SubstPack->getParameterPack())
3777  return Name;
3778 
3779  return getDerived().RebuildTemplateName(TransParam,
3780  SubstPack->getArgumentPack());
3781  }
3782 
3783  // These should be getting filtered out before they reach the AST.
3784  llvm_unreachable("overloaded function decl survived to here");
3785 }
3786 
3787 template<typename Derived>
3789  const TemplateArgument &Arg,
3790  TemplateArgumentLoc &Output) {
3791  SourceLocation Loc = getDerived().getBaseLocation();
3792  switch (Arg.getKind()) {
3794  llvm_unreachable("null template argument in TreeTransform");
3795  break;
3796 
3798  Output = TemplateArgumentLoc(Arg,
3799  SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3800 
3801  break;
3802 
3807  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3808  Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3809  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3810  Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3811 
3812  if (Arg.getKind() == TemplateArgument::Template)
3813  Output = TemplateArgumentLoc(Arg,
3814  Builder.getWithLocInContext(SemaRef.Context),
3815  Loc);
3816  else
3817  Output = TemplateArgumentLoc(Arg,
3818  Builder.getWithLocInContext(SemaRef.Context),
3819  Loc, Loc);
3820 
3821  break;
3822  }
3823 
3825  Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3826  break;
3827 
3833  break;
3834  }
3835 }
3836 
3837 template<typename Derived>
3839  const TemplateArgumentLoc &Input,
3840  TemplateArgumentLoc &Output, bool Uneval) {
3841  const TemplateArgument &Arg = Input.getArgument();
3842  switch (Arg.getKind()) {
3848  llvm_unreachable("Unexpected TemplateArgument");
3849 
3850  case TemplateArgument::Type: {
3851  TypeSourceInfo *DI = Input.getTypeSourceInfo();
3852  if (!DI)
3853  DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3854 
3855  DI = getDerived().TransformType(DI);
3856  if (!DI) return true;
3857 
3858  Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3859  return false;
3860  }
3861 
3863  NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3864  if (QualifierLoc) {
3865  QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3866  if (!QualifierLoc)
3867  return true;
3868  }
3869 
3870  CXXScopeSpec SS;
3871  SS.Adopt(QualifierLoc);
3872  TemplateName Template
3873  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3874  Input.getTemplateNameLoc());
3875  if (Template.isNull())
3876  return true;
3877 
3878  Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3879  Input.getTemplateNameLoc());
3880  return false;
3881  }
3882 
3884  llvm_unreachable("Caller should expand pack expansions");
3885 
3887  // Template argument expressions are constant expressions.
3889  getSema(), Uneval
3892 
3893  Expr *InputExpr = Input.getSourceExpression();
3894  if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3895 
3896  ExprResult E = getDerived().TransformExpr(InputExpr);
3897  E = SemaRef.ActOnConstantExpression(E);
3898  if (E.isInvalid()) return true;
3899  Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3900  return false;
3901  }
3902  }
3903 
3904  // Work around bogus GCC warning
3905  return true;
3906 }
3907 
3908 /// \brief Iterator adaptor that invents template argument location information
3909 /// for each of the template arguments in its underlying iterator.
3910 template<typename Derived, typename InputIterator>
3912  TreeTransform<Derived> &Self;
3913  InputIterator Iter;
3914 
3915 public:
3918  typedef typename std::iterator_traits<InputIterator>::difference_type
3920  typedef std::input_iterator_tag iterator_category;
3921 
3922  class pointer {
3923  TemplateArgumentLoc Arg;
3924 
3925  public:
3926  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3927 
3928  const TemplateArgumentLoc *operator->() const { return &Arg; }
3929  };
3930 
3932 
3934  InputIterator Iter)
3935  : Self(Self), Iter(Iter) { }
3936 
3938  ++Iter;
3939  return *this;
3940  }
3941 
3944  ++(*this);
3945  return Old;
3946  }
3947 
3950  Self.InventTemplateArgumentLoc(*Iter, Result);
3951  return Result;
3952  }
3953 
3954  pointer operator->() const { return pointer(**this); }
3955 
3958  return X.Iter == Y.Iter;
3959  }
3960 
3963  return X.Iter != Y.Iter;
3964  }
3965 };
3966 
3967 template<typename Derived>
3968 template<typename InputIterator>
3970  InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3971  bool Uneval) {
3972  for (; First != Last; ++First) {
3973  TemplateArgumentLoc Out;
3974  TemplateArgumentLoc In = *First;
3975 
3976  if (In.getArgument().getKind() == TemplateArgument::Pack) {
3977  // Unpack argument packs, which we translate them into separate
3978  // arguments.
3979  // FIXME: We could do much better if we could guarantee that the
3980  // TemplateArgumentLocInfo for the pack expansion would be usable for
3981  // all of the template arguments in the argument pack.
3982  typedef TemplateArgumentLocInventIterator<Derived,
3984  PackLocIterator;
3985  if (TransformTemplateArguments(PackLocIterator(*this,
3986  In.getArgument().pack_begin()),
3987  PackLocIterator(*this,
3988  In.getArgument().pack_end()),
3989  Outputs, Uneval))
3990  return true;
3991 
3992  continue;
3993  }
3994 
3995  if (In.getArgument().isPackExpansion()) {
3996  // We have a pack expansion, for which we will be substituting into
3997  // the pattern.
3998  SourceLocation Ellipsis;
3999  Optional<unsigned> OrigNumExpansions;
4000  TemplateArgumentLoc Pattern
4001  = getSema().getTemplateArgumentPackExpansionPattern(
4002  In, Ellipsis, OrigNumExpansions);
4003 
4005  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4006  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4007 
4008  // Determine whether the set of unexpanded parameter packs can and should
4009  // be expanded.
4010  bool Expand = true;
4011  bool RetainExpansion = false;
4012  Optional<unsigned> NumExpansions = OrigNumExpansions;
4013  if (getDerived().TryExpandParameterPacks(Ellipsis,
4014  Pattern.getSourceRange(),
4015  Unexpanded,
4016  Expand,
4017  RetainExpansion,
4018  NumExpansions))
4019  return true;
4020 
4021  if (!Expand) {
4022  // The transform has determined that we should perform a simple
4023  // transformation on the pack expansion, producing another pack
4024  // expansion.
4025  TemplateArgumentLoc OutPattern;
4026  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4027  if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4028  return true;
4029 
4030  Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4031  NumExpansions);
4032  if (Out.getArgument().isNull())
4033  return true;
4034 
4035  Outputs.addArgument(Out);
4036  continue;
4037  }
4038 
4039  // The transform has determined that we should perform an elementwise
4040  // expansion of the pattern. Do so.
4041  for (unsigned I = 0; I != *NumExpansions; ++I) {
4042  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4043 
4044  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4045  return true;
4046 
4048  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4049  OrigNumExpansions);
4050  if (Out.getArgument().isNull())
4051  return true;
4052  }
4053 
4054  Outputs.addArgument(Out);
4055  }
4056 
4057  // If we're supposed to retain a pack expansion, do so by temporarily
4058  // forgetting the partially-substituted parameter pack.
4059  if (RetainExpansion) {
4060  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4061 
4062  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4063  return true;
4064 
4065  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4066  OrigNumExpansions);
4067  if (Out.getArgument().isNull())
4068  return true;
4069 
4070  Outputs.addArgument(Out);
4071  }
4072 
4073  continue;
4074  }
4075 
4076  // The simple case:
4077  if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4078  return true;
4079 
4080  Outputs.addArgument(Out);
4081  }
4082 
4083  return false;
4084 
4085 }
4086 
4087 //===----------------------------------------------------------------------===//
4088 // Type transformation
4089 //===----------------------------------------------------------------------===//
4090 
4091 template<typename Derived>
4093  if (getDerived().AlreadyTransformed(T))
4094  return T;
4095 
4096  // Temporary workaround. All of these transformations should
4097  // eventually turn into transformations on TypeLocs.
4098  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4099  getDerived().getBaseLocation());
4100 
4101  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4102 
4103  if (!NewDI)
4104  return QualType();
4105 
4106  return NewDI->getType();
4107 }
4108 
4109 template<typename Derived>
4111  // Refine the base location to the type's location.
4112  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4113  getDerived().getBaseEntity());
4114  if (getDerived().AlreadyTransformed(DI->getType()))
4115  return DI;
4116 
4117  TypeLocBuilder TLB;
4118 
4119  TypeLoc TL = DI->getTypeLoc();
4120  TLB.reserve(TL.getFullDataSize());
4121 
4122  QualType Result = getDerived().TransformType(TLB, TL);
4123  if (Result.isNull())
4124  return nullptr;
4125 
4126  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4127 }
4128 
4129 template<typename Derived>
4130 QualType
4132  switch (T.getTypeLocClass()) {
4133 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4134 #define TYPELOC(CLASS, PARENT) \
4135  case TypeLoc::CLASS: \
4136  return getDerived().Transform##CLASS##Type(TLB, \
4137  T.castAs<CLASS##TypeLoc>());
4138 #include "clang/AST/TypeLocNodes.def"
4139  }
4140 
4141  llvm_unreachable("unhandled type loc!");
4142 }
4143 
4144 template<typename Derived>
4146  if (!isa<DependentNameType>(T))
4147  return TransformType(T);
4148 
4149  if (getDerived().AlreadyTransformed(T))
4150  return T;
4151  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4152  getDerived().getBaseLocation());
4153  TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4154  return NewDI ? NewDI->getType() : QualType();
4155 }
4156 
4157 template<typename Derived>
4160  if (!isa<DependentNameType>(DI->getType()))
4161  return TransformType(DI);
4162 
4163  // Refine the base location to the type's location.
4164  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4165  getDerived().getBaseEntity());
4166  if (getDerived().AlreadyTransformed(DI->getType()))
4167  return DI;
4168 
4169  TypeLocBuilder TLB;
4170 
4171  TypeLoc TL = DI->getTypeLoc();
4172  TLB.reserve(TL.getFullDataSize());
4173 
4174  Qualifiers Quals;
4175  auto QTL = TL.getAs<QualifiedTypeLoc>();
4176  if (QTL)
4177  TL = QTL.getUnqualifiedLoc();
4178 
4179  auto DNTL = TL.castAs<DependentNameTypeLoc>();
4180 
4181  QualType Result = getDerived().TransformDependentNameType(
4182  TLB, DNTL, /*DeducedTSTContext*/true);
4183  if (Result.isNull())
4184  return nullptr;
4185 
4186  if (QTL) {
4187  Result = getDerived().RebuildQualifiedType(
4188  Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4189  TLB.TypeWasModifiedSafely(Result);
4190  }
4191 
4192  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4193 }
4194 
4195 template<typename Derived>
4196 QualType
4198  QualifiedTypeLoc T) {
4199  Qualifiers Quals = T.getType().getLocalQualifiers();
4200 
4201  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4202  if (Result.isNull())
4203  return QualType();
4204 
4205  Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4206 
4207  // RebuildQualifiedType might have updated the type, but not in a way
4208  // that invalidates the TypeLoc. (There's no location information for
4209  // qualifiers.)
4210  TLB.TypeWasModifiedSafely(Result);
4211 
4212  return Result;
4213 }
4214 
4215 template<typename Derived>
4217  SourceLocation Loc,
4218  Qualifiers Quals) {
4219  // C++ [dcl.fct]p7:
4220  // [When] adding cv-qualifications on top of the function type [...] the
4221  // cv-qualifiers are ignored.
4222  // C++ [dcl.ref]p1:
4223  // when the cv-qualifiers are introduced through the use of a typedef-name
4224  // or decltype-specifier [...] the cv-qualifiers are ignored.
4225  // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4226  // applied to a reference type.
4227  // FIXME: This removes all qualifiers, not just cv-qualifiers!
4228  if (T->isFunctionType() || T->isReferenceType())
4229  return T;
4230 
4231  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4232  // resulting type.
4233  if (Quals.hasObjCLifetime()) {
4234  if (!T->isObjCLifetimeType() && !T->isDependentType())
4235  Quals.removeObjCLifetime();
4236  else if (T.getObjCLifetime()) {
4237  // Objective-C ARC:
4238  // A lifetime qualifier applied to a substituted template parameter
4239  // overrides the lifetime qualifier from the template argument.
4240  const AutoType *AutoTy;
4241  if (const SubstTemplateTypeParmType *SubstTypeParam
4242  = dyn_cast<SubstTemplateTypeParmType>(T)) {
4243  QualType Replacement = SubstTypeParam->getReplacementType();
4244  Qualifiers Qs = Replacement.getQualifiers();
4245  Qs.removeObjCLifetime();
4246  Replacement = SemaRef.Context.getQualifiedType(
4247  Replacement.getUnqualifiedType(), Qs);
4248  T = SemaRef.Context.getSubstTemplateTypeParmType(
4249  SubstTypeParam->getReplacedParameter(), Replacement);
4250  } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4251  // 'auto' types behave the same way as template parameters.
4252  QualType Deduced = AutoTy->getDeducedType();
4253  Qualifiers Qs = Deduced.getQualifiers();
4254  Qs.removeObjCLifetime();
4255  Deduced =
4256  SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4257  T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4258  AutoTy->isDependentType());
4259  } else {
4260  // Otherwise, complain about the addition of a qualifier to an
4261  // already-qualified type.
4262  // FIXME: Why is this check not in Sema::BuildQualifiedType?
4263  SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4264  Quals.removeObjCLifetime();
4265  }
4266  }
4267  }
4268 
4269  return SemaRef.BuildQualifiedType(T, Loc, Quals);
4270 }
4271 
4272 template<typename Derived>
4273 TypeLoc
4275  QualType ObjectType,
4276  NamedDecl *UnqualLookup,
4277  CXXScopeSpec &SS) {
4278  if (getDerived().AlreadyTransformed(TL.getType()))
4279  return TL;
4280 
4281  TypeSourceInfo *TSI =
4282  TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4283  if (TSI)
4284  return TSI->getTypeLoc();
4285  return TypeLoc();
4286 }
4287 
4288 template<typename Derived>
4289 TypeSourceInfo *
4290 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4291  QualType ObjectType,
4292  NamedDecl *UnqualLookup,
4293  CXXScopeSpec &SS) {
4294  if (getDerived().AlreadyTransformed(TSInfo->getType()))
4295  return TSInfo;
4296 
4297  return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4298  UnqualLookup, SS);
4299 }
4300 
4301 template <typename Derived>
4302 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4303  TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4304  CXXScopeSpec &SS) {
4305  QualType T = TL.getType();
4306  assert(!getDerived().AlreadyTransformed(T));
4307 
4308  TypeLocBuilder TLB;
4309  QualType Result;
4310 
4311  if (isa<TemplateSpecializationType>(T)) {
4312  TemplateSpecializationTypeLoc SpecTL =
4313  TL.castAs<TemplateSpecializationTypeLoc>();
4314 
4315  TemplateName Template = getDerived().TransformTemplateName(
4316  SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4317  ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4318  if (Template.isNull())
4319  return nullptr;
4320 
4321  Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4322  Template);
4323  } else if (isa<DependentTemplateSpecializationType>(T)) {
4324  DependentTemplateSpecializationTypeLoc SpecTL =
4325  TL.castAs<DependentTemplateSpecializationTypeLoc>();
4326 
4327  TemplateName Template
4328  = getDerived().RebuildTemplateName(SS,
4329  *SpecTL.getTypePtr()->getIdentifier(),
4330  SpecTL.getTemplateNameLoc(),
4331  ObjectType, UnqualLookup,
4332  /*AllowInjectedClassName*/true);
4333  if (Template.isNull())
4334  return nullptr;
4335 
4336  Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4337  SpecTL,
4338  Template,
4339  SS);
4340  } else {
4341  // Nothing special needs to be done for these.
4342  Result = getDerived().TransformType(TLB, TL);
4343  }
4344 
4345  if (Result.isNull())
4346  return nullptr;
4347 
4348  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4349 }
4350 
4351 template <class TyLoc> static inline
4353  TyLoc NewT = TLB.push<TyLoc>(T.getType());
4354  NewT.setNameLoc(T.getNameLoc());
4355  return T.getType();
4356 }
4357 
4358 template<typename Derived>
4359 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4360  BuiltinTypeLoc T) {
4361  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4362  NewT.setBuiltinLoc(T.getBuiltinLoc());
4363  if (T.needsExtraLocalData())
4364  NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4365  return T.getType();
4366 }
4367 
4368 template<typename Derived>
4369 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4370  ComplexTypeLoc T) {
4371  // FIXME: recurse?
4372  return TransformTypeSpecType(TLB, T);
4373 }
4374 
4375 template <typename Derived>
4376 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4377  AdjustedTypeLoc TL) {
4378  // Adjustments applied during transformation are handled elsewhere.
4379  return getDerived().TransformType(TLB, TL.getOriginalLoc());
4380 }
4381 
4382 template<typename Derived>
4383 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4384  DecayedTypeLoc TL) {
4385  QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4386  if (OriginalType.isNull())
4387  return QualType();
4388 
4389  QualType Result = TL.getType();
4390  if (getDerived().AlwaysRebuild() ||
4391  OriginalType != TL.getOriginalLoc().getType())
4392  Result = SemaRef.Context.getDecayedType(OriginalType);
4393  TLB.push<DecayedTypeLoc>(Result);
4394  // Nothing to set for DecayedTypeLoc.
4395  return Result;
4396 }
4397 
4398 template<typename Derived>
4399 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4400  PointerTypeLoc TL) {
4401  QualType PointeeType
4402  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4403  if (PointeeType.isNull())
4404  return QualType();
4405 
4406  QualType Result = TL.getType();
4407  if (PointeeType->getAs<ObjCObjectType>()) {
4408  // A dependent pointer type 'T *' has is being transformed such
4409  // that an Objective-C class type is being replaced for 'T'. The
4410  // resulting pointer type is an ObjCObjectPointerType, not a
4411  // PointerType.
4412  Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4413 
4414  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4415  NewT.setStarLoc(TL.getStarLoc());
4416  return Result;
4417  }
4418 
4419  if (getDerived().AlwaysRebuild() ||
4420  PointeeType != TL.getPointeeLoc().getType()) {
4421  Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4422  if (Result.isNull())
4423  return QualType();
4424  }
4425 
4426  // Objective-C ARC can add lifetime qualifiers to the type that we're
4427  // pointing to.
4428  TLB.TypeWasModifiedSafely(Result->getPointeeType());
4429 
4430  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4431  NewT.setSigilLoc(TL.getSigilLoc());
4432  return Result;
4433 }
4434 
4435 template<typename Derived>
4436 QualType
4437 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4438  BlockPointerTypeLoc TL) {
4439  QualType PointeeType
4440  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4441  if (PointeeType.isNull())
4442  return QualType();
4443 
4444  QualType Result = TL.getType();
4445  if (getDerived().AlwaysRebuild() ||
4446  PointeeType != TL.getPointeeLoc().getType()) {
4447  Result = getDerived().RebuildBlockPointerType(PointeeType,
4448  TL.getSigilLoc());
4449  if (Result.isNull())
4450  return QualType();
4451  }
4452 
4453  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4454  NewT.setSigilLoc(TL.getSigilLoc());
4455  return Result;
4456 }
4457 
4458 /// Transforms a reference type. Note that somewhat paradoxically we
4459 /// don't care whether the type itself is an l-value type or an r-value
4460 /// type; we only care if the type was *written* as an l-value type
4461 /// or an r-value type.
4462 template<typename Derived>
4463 QualType
4465  ReferenceTypeLoc TL) {
4466  const ReferenceType *T = TL.getTypePtr();
4467 
4468  // Note that this works with the pointee-as-written.
4469  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4470  if (PointeeType.isNull())
4471  return QualType();
4472 
4473  QualType Result = TL.getType();
4474  if (getDerived().AlwaysRebuild() ||
4475  PointeeType != T->getPointeeTypeAsWritten()) {
4476  Result = getDerived().RebuildReferenceType(PointeeType,
4477  T->isSpelledAsLValue(),
4478  TL.getSigilLoc());
4479  if (Result.isNull())
4480  return QualType();
4481  }
4482 
4483  // Objective-C ARC can add lifetime qualifiers to the type that we're
4484  // referring to.
4487 
4488  // r-value references can be rebuilt as l-value references.
4489  ReferenceTypeLoc NewTL;
4490  if (isa<LValueReferenceType>(Result))
4491  NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4492  else
4493  NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4494  NewTL.setSigilLoc(TL.getSigilLoc());
4495 
4496  return Result;
4497 }
4498 
4499 template<typename Derived>
4500 QualType
4503  return TransformReferenceType(TLB, TL);
4504 }
4505 
4506 template<typename Derived>
4507 QualType
4508 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4509  RValueReferenceTypeLoc TL) {
4510  return TransformReferenceType(TLB, TL);
4511 }
4512 
4513 template<typename Derived>
4514 QualType
4515 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4516  MemberPointerTypeLoc TL) {
4517  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4518  if (PointeeType.isNull())
4519  return QualType();
4520 
4521  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4522  TypeSourceInfo *NewClsTInfo = nullptr;
4523  if (OldClsTInfo) {
4524  NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4525  if (!NewClsTInfo)
4526  return QualType();
4527  }
4528 
4529  const MemberPointerType *T = TL.getTypePtr();
4530  QualType OldClsType = QualType(T->getClass(), 0);
4531  QualType NewClsType;
4532  if (NewClsTInfo)
4533  NewClsType = NewClsTInfo->getType();
4534  else {
4535  NewClsType = getDerived().TransformType(OldClsType);
4536  if (NewClsType.isNull())
4537  return QualType();
4538  }
4539 
4540  QualType Result = TL.getType();
4541  if (getDerived().AlwaysRebuild() ||
4542  PointeeType != T->getPointeeType() ||
4543  NewClsType != OldClsType) {
4544  Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4545  TL.getStarLoc());
4546  if (Result.isNull())
4547  return QualType();
4548  }
4549 
4550  // If we had to adjust the pointee type when building a member pointer, make
4551  // sure to push TypeLoc info for it.
4552  const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4553  if (MPT && PointeeType != MPT->getPointeeType()) {
4554  assert(isa<AdjustedType>(MPT->getPointeeType()));
4555  TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4556  }
4557 
4558  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4559  NewTL.setSigilLoc(TL.getSigilLoc());
4560  NewTL.setClassTInfo(NewClsTInfo);
4561 
4562  return Result;
4563 }
4564 
4565 template<typename Derived>
4566 QualType
4567 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4568  ConstantArrayTypeLoc TL) {
4569  const ConstantArrayType *T = TL.getTypePtr();
4570  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4571  if (ElementType.isNull())
4572  return QualType();
4573 
4574  QualType Result = TL.getType();
4575  if (getDerived().AlwaysRebuild() ||
4576  ElementType != T->getElementType()) {
4577  Result = getDerived().RebuildConstantArrayType(ElementType,
4578  T->getSizeModifier(),
4579  T->getSize(),
4580  T->getIndexTypeCVRQualifiers(),
4581  TL.getBracketsRange());
4582  if (Result.isNull())
4583  return QualType();
4584  }
4585 
4586  // We might have either a ConstantArrayType or a VariableArrayType now:
4587  // a ConstantArrayType is allowed to have an element type which is a
4588  // VariableArrayType if the type is dependent. Fortunately, all array
4589  // types have the same location layout.
4590  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4591  NewTL.setLBracketLoc(TL.getLBracketLoc());
4592  NewTL.setRBracketLoc(TL.getRBracketLoc());
4593 
4594  Expr *Size = TL.getSizeExpr();
4595  if (Size) {
4596  EnterExpressionEvaluationContext Unevaluated(
4598  Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4599  Size = SemaRef.ActOnConstantExpression(Size).get();
4600  }
4601  NewTL.setSizeExpr(Size);
4602 
4603  return Result;
4604 }
4605 
4606 template<typename Derived>
4607 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4608  TypeLocBuilder &TLB,
4609  IncompleteArrayTypeLoc TL) {
4610  const IncompleteArrayType *T = TL.getTypePtr();
4611  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4612  if (ElementType.isNull())
4613  return QualType();
4614 
4615  QualType Result = TL.getType();
4616  if (getDerived().AlwaysRebuild() ||
4617  ElementType != T->getElementType()) {
4618  Result = getDerived().RebuildIncompleteArrayType(ElementType,
4619  T->getSizeModifier(),
4620  T->getIndexTypeCVRQualifiers(),
4621  TL.getBracketsRange());
4622  if (Result.isNull())
4623  return QualType();
4624  }
4625 
4626  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4627  NewTL.setLBracketLoc(TL.getLBracketLoc());
4628  NewTL.setRBracketLoc(TL.getRBracketLoc());
4629  NewTL.setSizeExpr(nullptr);
4630 
4631  return Result;
4632 }
4633 
4634 template<typename Derived>
4635 QualType
4636 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4637  VariableArrayTypeLoc TL) {
4638  const VariableArrayType *T = TL.getTypePtr();
4639  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4640  if (ElementType.isNull())
4641  return QualType();
4642 
4643  ExprResult SizeResult;
4644  {
4645  EnterExpressionEvaluationContext Context(
4647  SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4648  }
4649  if (SizeResult.isInvalid())
4650  return QualType();
4651  SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
4652  if (SizeResult.isInvalid())
4653  return QualType();
4654 
4655  Expr *Size = SizeResult.get();
4656 
4657  QualType Result = TL.getType();
4658  if (getDerived().AlwaysRebuild() ||
4659  ElementType != T->getElementType() ||
4660  Size != T->getSizeExpr()) {
4661  Result = getDerived().RebuildVariableArrayType(ElementType,
4662  T->getSizeModifier(),
4663  Size,
4664  T->getIndexTypeCVRQualifiers(),
4665  TL.getBracketsRange());
4666  if (Result.isNull())
4667  return QualType();
4668  }
4669 
4670  // We might have constant size array now, but fortunately it has the same
4671  // location layout.
4672  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4673  NewTL.setLBracketLoc(TL.getLBracketLoc());
4674  NewTL.setRBracketLoc(TL.getRBracketLoc());
4675  NewTL.setSizeExpr(Size);
4676 
4677  return Result;
4678 }
4679 
4680 template<typename Derived>
4681 QualType
4682 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4683  DependentSizedArrayTypeLoc TL) {
4684  const DependentSizedArrayType *T = TL.getTypePtr();
4685  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4686  if (ElementType.isNull())
4687  return QualType();
4688 
4689  // Array bounds are constant expressions.
4690  EnterExpressionEvaluationContext Unevaluated(
4692 
4693  // Prefer the expression from the TypeLoc; the other may have been uniqued.
4694  Expr *origSize = TL.getSizeExpr();
4695  if (!origSize) origSize = T->getSizeExpr();
4696 
4697  ExprResult sizeResult
4698  = getDerived().TransformExpr(origSize);
4699  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4700  if (sizeResult.isInvalid())
4701  return QualType();
4702 
4703  Expr *size = sizeResult.get();
4704 
4705  QualType Result = TL.getType();
4706  if (getDerived().AlwaysRebuild() ||
4707  ElementType != T->getElementType() ||
4708  size != origSize) {
4709  Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4710  T->getSizeModifier(),
4711  size,
4712  T->getIndexTypeCVRQualifiers(),
4713  TL.getBracketsRange());
4714  if (Result.isNull())
4715  return QualType();
4716  }
4717 
4718  // We might have any sort of array type now, but fortunately they
4719  // all have the same location layout.
4720  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4721  NewTL.setLBracketLoc(TL.getLBracketLoc());
4722  NewTL.setRBracketLoc(TL.getRBracketLoc());
4723  NewTL.setSizeExpr(size);
4724 
4725  return Result;
4726 }
4727 
4728 template<typename Derived>
4729 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4730  TypeLocBuilder &TLB,
4731  DependentSizedExtVectorTypeLoc TL) {
4732  const DependentSizedExtVectorType *T = TL.getTypePtr();
4733 
4734  // FIXME: ext vector locs should be nested
4735  QualType ElementType = getDerived().TransformType(T->getElementType());
4736  if (ElementType.isNull())
4737  return QualType();
4738 
4739  // Vector sizes are constant expressions.
4740  EnterExpressionEvaluationContext Unevaluated(
4742 
4743  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4744  Size = SemaRef.ActOnConstantExpression(Size);
4745  if (Size.isInvalid())
4746  return QualType();
4747 
4748  QualType Result = TL.getType();
4749  if (getDerived().AlwaysRebuild() ||
4750  ElementType != T->getElementType() ||
4751  Size.get() != T->getSizeExpr()) {
4752  Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4753  Size.get(),
4754  T->getAttributeLoc());
4755  if (Result.isNull())
4756  return QualType();
4757  }
4758 
4759  // Result might be dependent or not.
4760  if (isa<DependentSizedExtVectorType>(Result)) {
4761  DependentSizedExtVectorTypeLoc NewTL
4762  = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4763  NewTL.setNameLoc(TL.getNameLoc());
4764  } else {
4765  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4766  NewTL.setNameLoc(TL.getNameLoc());
4767  }
4768 
4769  return Result;
4770 }
4771 
4772 template<typename Derived>
4773 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4774  VectorTypeLoc TL) {
4775  const VectorType *T = TL.getTypePtr();
4776  QualType ElementType = getDerived().TransformType(T->getElementType());
4777  if (ElementType.isNull())
4778  return QualType();
4779 
4780  QualType Result = TL.getType();
4781  if (getDerived().AlwaysRebuild() ||
4782  ElementType != T->getElementType()) {
4783  Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4784  T->getVectorKind());
4785  if (Result.isNull())
4786  return QualType();
4787  }
4788 
4789  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4790  NewTL.setNameLoc(TL.getNameLoc());
4791 
4792  return Result;
4793 }
4794 
4795 template<typename Derived>
4796 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4797  ExtVectorTypeLoc TL) {
4798  const VectorType *T = TL.getTypePtr();
4799  QualType ElementType = getDerived().TransformType(T->getElementType());
4800  if (ElementType.isNull())
4801  return QualType();
4802 
4803  QualType Result = TL.getType();
4804  if (getDerived().AlwaysRebuild() ||
4805  ElementType != T->getElementType()) {
4806  Result = getDerived().RebuildExtVectorType(ElementType,
4807  T->getNumElements(),
4808  /*FIXME*/ SourceLocation());
4809  if (Result.isNull())
4810  return QualType();
4811  }
4812 
4813  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4814  NewTL.setNameLoc(TL.getNameLoc());
4815 
4816  return Result;
4817 }
4818 
4819 template <typename Derived>
4821  ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4822  bool ExpectParameterPack) {
4823  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4824  TypeSourceInfo *NewDI = nullptr;
4825 
4826  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4827  // If we're substituting into a pack expansion type and we know the
4828  // length we want to expand to, just substitute for the pattern.
4829  TypeLoc OldTL = OldDI->getTypeLoc();
4830  PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4831 
4832  TypeLocBuilder TLB;
4833  TypeLoc NewTL = OldDI->getTypeLoc();
4834  TLB.reserve(NewTL.getFullDataSize());
4835 
4836  QualType Result = getDerived().TransformType(TLB,
4837  OldExpansionTL.getPatternLoc());
4838  if (Result.isNull())
4839  return nullptr;
4840 
4841  Result = RebuildPackExpansionType(Result,
4842  OldExpansionTL.getPatternLoc().getSourceRange(),
4843  OldExpansionTL.getEllipsisLoc(),
4844  NumExpansions);
4845  if (Result.isNull())
4846  return nullptr;
4847 
4848  PackExpansionTypeLoc NewExpansionTL
4849  = TLB.push<PackExpansionTypeLoc>(Result);
4850  NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4851  NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4852  } else
4853  NewDI = getDerived().TransformType(OldDI);
4854  if (!NewDI)
4855  return nullptr;
4856 
4857  if (NewDI == OldDI && indexAdjustment == 0)
4858  return OldParm;
4859 
4860  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4861  OldParm->getDeclContext(),
4862  OldParm->getInnerLocStart(),
4863  OldParm->getLocation(),
4864  OldParm->getIdentifier(),
4865  NewDI->getType(),
4866  NewDI,
4867  OldParm->getStorageClass(),
4868  /* DefArg */ nullptr);
4869  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4870  OldParm->getFunctionScopeIndex() + indexAdjustment);
4871  return newParm;
4872 }
4873 
4874 template <typename Derived>
4877  const QualType *ParamTypes,
4878  const FunctionProtoType::ExtParameterInfo *ParamInfos,
4879  SmallVectorImpl<QualType> &OutParamTypes,
4882  int indexAdjustment = 0;
4883 
4884  unsigned NumParams = Params.size();
4885  for (unsigned i = 0; i != NumParams; ++i) {
4886  if (ParmVarDecl *OldParm = Params[i]) {
4887  assert(OldParm->getFunctionScopeIndex() == i);
4888 
4889  Optional<unsigned> NumExpansions;
4890  ParmVarDecl *NewParm = nullptr;
4891  if (OldParm->isParameterPack()) {
4892  // We have a function parameter pack that may need to be expanded.
4894 
4895  // Find the parameter packs that could be expanded.
4896  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4897  PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4898  TypeLoc Pattern = ExpansionTL.getPatternLoc();
4899  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4900  assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4901 
4902  // Determine whether we should expand the parameter packs.
4903  bool ShouldExpand = false;
4904  bool RetainExpansion = false;
4905  Optional<unsigned> OrigNumExpansions =
4906  ExpansionTL.getTypePtr()->getNumExpansions();
4907  NumExpansions = OrigNumExpansions;
4908  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4909  Pattern.getSourceRange(),
4910  Unexpanded,
4911  ShouldExpand,
4912  RetainExpansion,
4913  NumExpansions)) {
4914  return true;
4915  }
4916 
4917  if (ShouldExpand) {
4918  // Expand the function parameter pack into multiple, separate
4919  // parameters.
4920  getDerived().ExpandingFunctionParameterPack(OldParm);
4921  for (unsigned I = 0; I != *NumExpansions; ++I) {
4922  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4923  ParmVarDecl *NewParm
4924  = getDerived().TransformFunctionTypeParam(OldParm,
4925  indexAdjustment++,
4926  OrigNumExpansions,
4927  /*ExpectParameterPack=*/false);
4928  if (!NewParm)
4929  return true;
4930 
4931  if (ParamInfos)
4932  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4933  OutParamTypes.push_back(NewParm->getType());
4934  if (PVars)
4935  PVars->push_back(NewParm);
4936  }
4937 
4938  // If we're supposed to retain a pack expansion, do so by temporarily
4939  // forgetting the partially-substituted parameter pack.
4940  if (RetainExpansion) {
4941  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4942  ParmVarDecl *NewParm
4943  = getDerived().TransformFunctionTypeParam(OldParm,
4944  indexAdjustment++,
4945  OrigNumExpansions,
4946  /*ExpectParameterPack=*/false);
4947  if (!NewParm)
4948  return true;
4949 
4950  if (ParamInfos)
4951  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4952  OutParamTypes.push_back(NewParm->getType());
4953  if (PVars)
4954  PVars->push_back(NewParm);
4955  }
4956 
4957  // The next parameter should have the same adjustment as the
4958  // last thing we pushed, but we post-incremented indexAdjustment
4959  // on every push. Also, if we push nothing, the adjustment should
4960  // go down by one.
4961  indexAdjustment--;
4962 
4963  // We're done with the pack expansion.
4964  continue;
4965  }
4966 
4967  // We'll substitute the parameter now without expanding the pack
4968  // expansion.
4969  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4970  NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4971  indexAdjustment,
4972  NumExpansions,
4973  /*ExpectParameterPack=*/true);
4974  } else {
4975  NewParm = getDerived().TransformFunctionTypeParam(
4976  OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4977  }
4978 
4979  if (!NewParm)
4980  return true;
4981 
4982  if (ParamInfos)
4983  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4984  OutParamTypes.push_back(NewParm->getType());
4985  if (PVars)
4986  PVars->push_back(NewParm);
4987  continue;
4988  }
4989 
4990  // Deal with the possibility that we don't have a parameter
4991  // declaration for this parameter.
4992  QualType OldType = ParamTypes[i];
4993  bool IsPackExpansion = false;
4994  Optional<unsigned> NumExpansions;
4995  QualType NewType;
4996  if (const PackExpansionType *Expansion
4997  = dyn_cast<PackExpansionType>(OldType)) {
4998  // We have a function parameter pack that may need to be expanded.
4999  QualType Pattern = Expansion->getPattern();
5001  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5002 
5003  // Determine whether we should expand the parameter packs.
5004  bool ShouldExpand = false;
5005  bool RetainExpansion = false;
5006  if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
5007  Unexpanded,
5008  ShouldExpand,
5009  RetainExpansion,
5010  NumExpansions)) {
5011  return true;
5012  }
5013 
5014  if (ShouldExpand) {
5015  // Expand the function parameter pack into multiple, separate
5016  // parameters.
5017  for (unsigned I = 0; I != *NumExpansions; ++I) {
5018  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5019  QualType NewType = getDerived().TransformType(Pattern);
5020  if (NewType.isNull())
5021  return true;
5022 
5023  if (NewType->containsUnexpandedParameterPack()) {
5024  NewType =
5025  getSema().getASTContext().getPackExpansionType(NewType, None);
5026 
5027  if (NewType.isNull())
5028  return true;
5029  }
5030 
5031  if (ParamInfos)
5032  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5033  OutParamTypes.push_back(NewType);
5034  if (PVars)
5035  PVars->push_back(nullptr);
5036  }
5037 
5038  // We're done with the pack expansion.
5039  continue;
5040  }
5041 
5042  // If we're supposed to retain a pack expansion, do so by temporarily
5043  // forgetting the partially-substituted parameter pack.
5044  if (RetainExpansion) {
5045  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5046  QualType NewType = getDerived().TransformType(Pattern);
5047  if (NewType.isNull())
5048  return true;
5049 
5050  if (ParamInfos)
5051  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5052  OutParamTypes.push_back(NewType);
5053  if (PVars)
5054  PVars->push_back(nullptr);
5055  }
5056 
5057  // We'll substitute the parameter now without expanding the pack
5058  // expansion.
5059  OldType = Expansion->getPattern();
5060  IsPackExpansion = true;
5061  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5062  NewType = getDerived().TransformType(OldType);
5063  } else {
5064  NewType = getDerived().TransformType(OldType);
5065  }
5066 
5067  if (NewType.isNull())
5068  return true;
5069 
5070  if (IsPackExpansion)
5071  NewType = getSema().Context.getPackExpansionType(NewType,
5072  NumExpansions);
5073 
5074  if (ParamInfos)
5075  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5076  OutParamTypes.push_back(NewType);
5077  if (PVars)
5078  PVars->push_back(nullptr);
5079  }
5080 
5081 #ifndef NDEBUG
5082  if (PVars) {
5083  for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5084  if (ParmVarDecl *parm = (*PVars)[i])
5085  assert(parm->getFunctionScopeIndex() == i);
5086  }
5087 #endif
5088 
5089  return false;
5090 }
5091 
5092 template<typename Derived>
5093 QualType
5095  FunctionProtoTypeLoc TL) {
5096  SmallVector<QualType, 4> ExceptionStorage;
5097  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
5098  return getDerived().TransformFunctionProtoType(
5099  TLB, TL, nullptr, 0,
5100  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5101  return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5102  ExceptionStorage, Changed);
5103  });
5104 }
5105 
5106 template<typename Derived> template<typename Fn>
5108  TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5109  unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
5110 
5111  // Transform the parameters and return type.
5112  //
5113  // We are required to instantiate the params and return type in source order.
5114  // When the function has a trailing return type, we instantiate the
5115  // parameters before the return type, since the return type can then refer
5116  // to the parameters themselves (via decltype, sizeof, etc.).
5117  //
5118  SmallVector<QualType, 4> ParamTypes;
5119  SmallVector<ParmVarDecl*, 4> ParamDecls;
5120  Sema::ExtParameterInfoBuilder ExtParamInfos;
5121  const FunctionProtoType *T = TL.getTypePtr();
5122 
5123  QualType ResultType;
5124 
5125  if (T->hasTrailingReturn()) {
5126  if (getDerived().TransformFunctionTypeParams(
5127  TL.getBeginLoc(), TL.getParams(),
5128  TL.getTypePtr()->param_type_begin(),
5130  ParamTypes, &ParamDecls, ExtParamInfos))
5131  return QualType();
5132 
5133  {
5134  // C++11 [expr.prim.general]p3:
5135  // If a declaration declares a member function or member function
5136  // template of a class X, the expression this is a prvalue of type
5137  // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
5138  // and the end of the function-definition, member-declarator, or
5139  // declarator.
5140  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
5141 
5142  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5143  if (ResultType.isNull())
5144  return QualType();
5145  }
5146  }
5147  else {
5148  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5149  if (ResultType.isNull())
5150  return QualType();
5151 
5152  if (getDerived().TransformFunctionTypeParams(
5153  TL.getBeginLoc(), TL.getParams(),
5154  TL.getTypePtr()->param_type_begin(),
5156  ParamTypes, &ParamDecls, ExtParamInfos))
5157  return QualType();
5158  }
5159 
5161 
5162  bool EPIChanged = false;
5163  if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5164  return QualType();
5165 
5166  // Handle extended parameter information.
5167  if (auto NewExtParamInfos =
5168  ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5169  if (!EPI.ExtParameterInfos ||
5170  llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5171  != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5172  EPIChanged = true;
5173  }
5174  EPI.ExtParameterInfos = NewExtParamInfos;
5175  } else if (EPI.ExtParameterInfos) {
5176  EPIChanged = true;
5177  EPI.ExtParameterInfos = nullptr;
5178  }
5179 
5180  QualType Result = TL.getType();
5181  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5182  T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5183  Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5184  if (Result.isNull())
5185  return QualType();
5186  }
5187 
5188  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5190  NewTL.setLParenLoc(TL.getLParenLoc());
5191  NewTL.setRParenLoc(TL.getRParenLoc());
5193  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5194  for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5195  NewTL.setParam(i, ParamDecls[i]);
5196 
5197  return Result;
5198 }
5199 
5200 template<typename Derived>
5203  SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5204  assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5205 
5206  // Instantiate a dynamic noexcept expression, if any.
5207  if (ESI.Type == EST_ComputedNoexcept) {
5210  ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5211  if (NoexceptExpr.isInvalid())
5212  return true;
5213 
5214  // FIXME: This is bogus, a noexcept expression is not a condition.
5215  NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5216  if (NoexceptExpr.isInvalid())
5217  return true;
5218 
5219  if (!NoexceptExpr.get()->isValueDependent()) {
5220  NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5221  NoexceptExpr.get(), nullptr,
5222  diag::err_noexcept_needs_constant_expression,
5223  /*AllowFold*/false);
5224  if (NoexceptExpr.isInvalid())
5225  return true;
5226  }
5227 
5228  if (ESI.NoexceptExpr != NoexceptExpr.get())
5229  Changed = true;
5230  ESI.NoexceptExpr = NoexceptExpr.get();
5231  }
5232 
5233  if (ESI.Type != EST_Dynamic)
5234  return false;
5235 
5236  // Instantiate a dynamic exception specification's type.
5237  for (QualType T : ESI.Exceptions) {
5238  if (const PackExpansionType *PackExpansion =
5239  T->getAs<PackExpansionType>()) {
5240  Changed = true;
5241 
5242  // We have a pack expansion. Instantiate it.
5244  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5245  Unexpanded);
5246  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5247 
5248  // Determine whether the set of unexpanded parameter packs can and
5249  // should
5250  // be expanded.
5251  bool Expand = false;
5252  bool RetainExpansion = false;
5253  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5254  // FIXME: Track the location of the ellipsis (and track source location
5255  // information for the types in the exception specification in general).
5256  if (getDerived().TryExpandParameterPacks(
5257  Loc, SourceRange(), Unexpanded, Expand,
5258  RetainExpansion, NumExpansions))
5259  return true;
5260 
5261  if (!Expand) {
5262  // We can't expand this pack expansion into separate arguments yet;
5263  // just substitute into the pattern and create a new pack expansion
5264  // type.
5265  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5266  QualType U = getDerived().TransformType(PackExpansion->getPattern());
5267  if (U.isNull())
5268  return true;
5269 
5270  U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5271  Exceptions.push_back(U);
5272  continue;
5273  }
5274 
5275  // Substitute into the pack expansion pattern for each slice of the
5276  // pack.
5277  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5278  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5279 
5280  QualType U = getDerived().TransformType(PackExpansion->getPattern());
5281  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5282  return true;
5283 
5284  Exceptions.push_back(U);
5285  }
5286  } else {
5287  QualType U = getDerived().TransformType(T);
5288  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5289  return true;
5290  if (T != U)
5291  Changed = true;
5292 
5293  Exceptions.push_back(U);
5294  }
5295  }
5296 
5297  ESI.Exceptions = Exceptions;
5298  if (ESI.Exceptions.empty())
5299  ESI.Type = EST_DynamicNone;
5300  return false;
5301 }
5302 
5303 template<typename Derived>
5305  TypeLocBuilder &TLB,
5307  const FunctionNoProtoType *T = TL.getTypePtr();
5308  QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5309  if (ResultType.isNull())
5310  return QualType();
5311 
5312  QualType Result = TL.getType();
5313  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5314  Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5315 
5316  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5318  NewTL.setLParenLoc(TL.getLParenLoc());
5319  NewTL.setRParenLoc(TL.getRParenLoc());
5320  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5321 
5322  return Result;
5323 }
5324 
5325 template<typename Derived> QualType
5326 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5327  UnresolvedUsingTypeLoc TL) {
5328  const UnresolvedUsingType *T = TL.getTypePtr();
5329  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5330  if (!D)
5331  return QualType();
5332 
5333  QualType Result = TL.getType();
5334  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5335  Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
5336  if (Result.isNull())
5337  return QualType();
5338  }
5339 
5340  // We might get an arbitrary type spec type back. We should at
5341  // least always get a type spec type, though.
5342  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5343  NewTL.setNameLoc(TL.getNameLoc());
5344 
5345  return Result;
5346 }
5347 
5348 template<typename Derived>
5349 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5350  TypedefTypeLoc TL) {
5351  const TypedefType *T = TL.getTypePtr();
5352  TypedefNameDecl *Typedef
5353  = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5354  T->getDecl()));
5355  if (!Typedef)
5356  return QualType();
5357 
5358  QualType Result = TL.getType();
5359  if (getDerived().AlwaysRebuild() ||
5360  Typedef != T->getDecl()) {
5361  Result = getDerived().RebuildTypedefType(Typedef);
5362  if (Result.isNull())
5363  return QualType();
5364  }
5365 
5366  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5367  NewTL.setNameLoc(TL.getNameLoc());
5368 
5369  return Result;
5370 }
5371 
5372 template<typename Derived>
5373 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5374  TypeOfExprTypeLoc TL) {
5375  // typeof expressions are not potentially evaluated contexts
5376  EnterExpressionEvaluationContext Unevaluated(
5379 
5380  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5381  if (E.isInvalid())
5382  return QualType();
5383 
5384  E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5385  if (E.isInvalid())
5386  return QualType();
5387 
5388  QualType Result = TL.getType();
5389  if (getDerived().AlwaysRebuild() ||
5390  E.get() != TL.getUnderlyingExpr()) {
5391  Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5392  if (Result.isNull())
5393  return QualType();
5394  }
5395  else E.get();
5396 
5397  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5398  NewTL.setTypeofLoc(TL.getTypeofLoc());
5399  NewTL.setLParenLoc(TL.getLParenLoc());
5400  NewTL.setRParenLoc(TL.getRParenLoc());
5401 
5402  return Result;
5403 }
5404 
5405 template<typename Derived>
5406 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5407  TypeOfTypeLoc TL) {
5408  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5409  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5410  if (!New_Under_TI)
5411  return QualType();
5412 
5413  QualType Result = TL.getType();
5414  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5415  Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5416  if (Result.isNull())
5417  return QualType();
5418  }
5419 
5420  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5421  NewTL.setTypeofLoc(TL.getTypeofLoc());
5422  NewTL.setLParenLoc(TL.getLParenLoc());
5423  NewTL.setRParenLoc(TL.getRParenLoc());
5424  NewTL.setUnderlyingTInfo(New_Under_TI);
5425 
5426  return Result;
5427 }
5428 
5429 template<typename Derived>
5430 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5431  DecltypeTypeLoc TL) {
5432  const DecltypeType *T = TL.getTypePtr();
5433 
5434  // decltype expressions are not potentially evaluated contexts
5435  EnterExpressionEvaluationContext Unevaluated(
5437  /*IsDecltype=*/true);
5438 
5439  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5440  if (E.isInvalid())
5441  return QualType();
5442 
5443  E = getSema().ActOnDecltypeExpression(E.get());
5444  if (E.isInvalid())
5445  return QualType();
5446 
5447  QualType Result = TL.getType();
5448  if (getDerived().AlwaysRebuild() ||
5449  E.get() != T->getUnderlyingExpr()) {
5450  Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5451  if (Result.isNull())
5452  return QualType();
5453  }
5454  else E.get();
5455 
5456  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5457  NewTL.setNameLoc(TL.getNameLoc());
5458 
5459  return Result;
5460 }
5461 
5462 template<typename Derived>
5463 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5464  TypeLocBuilder &TLB,
5465  UnaryTransformTypeLoc TL) {
5466  QualType Result = TL.getType();
5467  if (Result->isDependentType()) {
5468  const UnaryTransformType *T = TL.getTypePtr();
5469  QualType NewBase =
5470  getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5471  Result = getDerived().RebuildUnaryTransformType(NewBase,
5472  T->getUTTKind(),
5473  TL.getKWLoc());
5474  if (Result.isNull())
5475  return QualType();
5476  }
5477 
5478  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5479  NewTL.setKWLoc(TL.getKWLoc());
5480  NewTL.setParensRange(TL.getParensRange());
5481  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5482  return Result;
5483 }
5484 
5485 template<typename Derived>
5486 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5487  AutoTypeLoc TL) {
5488  const AutoType *T = TL.getTypePtr();
5489  QualType OldDeduced = T->getDeducedType();
5490  QualType NewDeduced;
5491  if (!OldDeduced.isNull()) {
5492  NewDeduced = getDerived().TransformType(OldDeduced);
5493  if (NewDeduced.isNull())
5494  return QualType();
5495  }
5496 
5497  QualType Result = TL.getType();
5498  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5499  T->isDependentType()) {
5500  Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5501  if (Result.isNull())
5502  return QualType();
5503  }
5504 
5505  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5506  NewTL.setNameLoc(TL.getNameLoc());
5507 
5508  return Result;
5509 }
5510 
5511 template<typename Derived>
5512 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5513  TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5514  const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5515 
5516  CXXScopeSpec SS;
5517  TemplateName TemplateName = getDerived().TransformTemplateName(
5518  SS, T->getTemplateName(), TL.getTemplateNameLoc());
5519  if (TemplateName.isNull())
5520  return QualType();
5521 
5522  QualType OldDeduced = T->getDeducedType();
5523  QualType NewDeduced;
5524  if (!OldDeduced.isNull()) {
5525  NewDeduced = getDerived().TransformType(OldDeduced);
5526  if (NewDeduced.isNull())
5527  return QualType();
5528  }
5529 
5530  QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5531  TemplateName, NewDeduced);
5532  if (Result.isNull())
5533  return QualType();
5534 
5535  DeducedTemplateSpecializationTypeLoc NewTL =
5536  TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5537  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5538 
5539  return Result;
5540 }
5541 
5542 template<typename Derived>
5543 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5544  RecordTypeLoc TL) {
5545  const RecordType *T = TL.getTypePtr();
5546  RecordDecl *Record
5547  = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5548  T->getDecl()));
5549  if (!Record)
5550  return QualType();
5551 
5552  QualType Result = TL.getType();
5553  if (getDerived().AlwaysRebuild() ||
5554  Record != T->getDecl()) {
5555  Result = getDerived().RebuildRecordType(Record);
5556  if (Result.isNull())
5557  return QualType();
5558  }
5559 
5560  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5561  NewTL.setNameLoc(TL.getNameLoc());
5562 
5563  return Result;
5564 }
5565 
5566 template<typename Derived>
5567 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5568  EnumTypeLoc TL) {
5569  const EnumType *T = TL.getTypePtr();
5570  EnumDecl *Enum
5571  = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5572  T->getDecl()));
5573  if (!Enum)
5574  return QualType();
5575 
5576  QualType Result = TL.getType();
5577  if (getDerived().AlwaysRebuild() ||
5578  Enum != T->getDecl()) {
5579  Result = getDerived().RebuildEnumType(Enum);
5580  if (Result.isNull())
5581  return QualType();
5582  }
5583 
5584  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5585  NewTL.setNameLoc(TL.getNameLoc());
5586 
5587  return Result;
5588 }
5589 
5590 template<typename Derived>
5591 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5592  TypeLocBuilder &TLB,
5593  InjectedClassNameTypeLoc TL) {
5594  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5595  TL.getTypePtr()->getDecl());
5596  if (!D) return QualType();
5597 
5598  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5599  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5600  return T;
5601 }
5602 
5603 template<typename Derived>
5604 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5605  TypeLocBuilder &TLB,
5606  TemplateTypeParmTypeLoc TL) {
5607  return TransformTypeSpecType(TLB, TL);
5608 }
5609 
5610 template<typename Derived>
5611 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5612  TypeLocBuilder &TLB,
5613  SubstTemplateTypeParmTypeLoc TL) {
5614  const SubstTemplateTypeParmType *T = TL.getTypePtr();
5615 
5616  // Substitute into the replacement type, which itself might involve something
5617  // that needs to be transformed. This only tends to occur with default
5618  // template arguments of template template parameters.
5619  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5620  QualType Replacement = getDerived().TransformType(T->getReplacementType());
5621  if (Replacement.isNull())
5622  return QualType();
5623 
5624  // Always canonicalize the replacement type.
5625  Replacement = SemaRef.Context.getCanonicalType(Replacement);
5626  QualType Result
5627  = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5628  Replacement);
5629 
5630  // Propagate type-source information.
5631  SubstTemplateTypeParmTypeLoc NewTL
5632  = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5633  NewTL.setNameLoc(TL.getNameLoc());
5634  return Result;
5635 
5636 }
5637 
5638 template<typename Derived>
5639 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5640  TypeLocBuilder &TLB,
5641  SubstTemplateTypeParmPackTypeLoc TL) {
5642  return TransformTypeSpecType(TLB, TL);
5643 }
5644 
5645 template<typename Derived>
5647  TypeLocBuilder &TLB,
5649  const TemplateSpecializationType *T = TL.getTypePtr();
5650 
5651  // The nested-name-specifier never matters in a TemplateSpecializationType,
5652  // because we can't have a dependent nested-name-specifier anyway.
5653  CXXScopeSpec SS;
5654  TemplateName Template
5655  = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5656  TL.getTemplateNameLoc());
5657  if (Template.isNull())
5658  return QualType();
5659 
5660  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5661 }
5662 
5663 template<typename Derived>
5665  AtomicTypeLoc TL) {
5666  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5667  if (ValueType.isNull())
5668  return QualType();
5669 
5670  QualType Result = TL.getType();
5671  if (getDerived().AlwaysRebuild() ||
5672  ValueType != TL.getValueLoc().getType()) {
5673  Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5674  if (Result.isNull())
5675  return QualType();
5676  }
5677 
5678  AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5679  NewTL.setKWLoc(TL.getKWLoc());
5680  NewTL.setLParenLoc(TL.getLParenLoc());
5681  NewTL.setRParenLoc(TL.getRParenLoc());
5682 
5683  return Result;
5684 }
5685 
5686 template <typename Derived>
5687 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5688  PipeTypeLoc TL) {
5689  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5690  if (ValueType.isNull())
5691  return QualType();
5692 
5693  QualType Result = TL.getType();
5694  if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5695  const PipeType *PT = Result->getAs<PipeType>();
5696  bool isReadPipe = PT->isReadOnly();
5697  Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
5698  if (Result.isNull())
5699  return QualType();
5700  }
5701 
5702  PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5703  NewTL.setKWLoc(TL.getKWLoc());
5704 
5705  return Result;
5706 }
5707 
5708  /// \brief Simple iterator that traverses the template arguments in a
5709  /// container that provides a \c getArgLoc() member function.
5710  ///
5711  /// This iterator is intended to be used with the iterator form of
5712  /// \c TreeTransform<Derived>::TransformTemplateArguments().
5713  template<typename ArgLocContainer>
5715  ArgLocContainer *Container;
5716  unsigned Index;
5717 
5718  public:
5721  typedef int difference_type;
5722  typedef std::input_iterator_tag iterator_category;
5723 
5724  class pointer {
5725  TemplateArgumentLoc Arg;
5726 
5727  public:
5728  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5729 
5731  return &Arg;
5732  }
5733  };
5734 
5735 
5737 
5738  TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5739  unsigned Index)
5740  : Container(&Container), Index(Index) { }
5741 
5743  ++Index;
5744  return *this;
5745  }
5746 
5749  ++(*this);
5750  return Old;
5751  }
5752 
5754  return Container->getArgLoc(Index);
5755  }
5756 
5758  return pointer(Container->getArgLoc(Index));
5759  }
5760 
5763  return X.Container == Y.Container && X.Index == Y.Index;
5764  }
5765 
5768  return !(X == Y);
5769  }
5770  };
5771 
5772 
5773 template <typename Derived>
5775  TypeLocBuilder &TLB,
5776  TemplateSpecializationTypeLoc TL,
5777  TemplateName Template) {
5778  TemplateArgumentListInfo NewTemplateArgs;
5779  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5780  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5781  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5782  ArgIterator;
5783  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5784  ArgIterator(TL, TL.getNumArgs()),
5785  NewTemplateArgs))
5786  return QualType();
5787 
5788  // FIXME: maybe don't rebuild if all the template arguments are the same.
5789 
5790  QualType Result =
5791  getDerived().RebuildTemplateSpecializationType(Template,
5792  TL.getTemplateNameLoc(),
5793  NewTemplateArgs);
5794 
5795  if (!Result.isNull()) {
5796  // Specializations of template template parameters are represented as
5797  // TemplateSpecializationTypes, and substitution of type alias templates
5798  // within a dependent context can transform them into
5799  // DependentTemplateSpecializationTypes.
5800  if (isa<DependentTemplateSpecializationType>(Result)) {
5801  DependentTemplateSpecializationTypeLoc NewTL
5802  = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5803  NewTL.setElaboratedKeywordLoc(SourceLocation());
5804  NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5805  NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5806  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5807  NewTL.setLAngleLoc(TL.getLAngleLoc());
5808  NewTL.setRAngleLoc(TL.getRAngleLoc());
5809  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5810  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5811  return Result;
5812  }
5813 
5814  TemplateSpecializationTypeLoc NewTL
5815  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5816  NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5817  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5818  NewTL.setLAngleLoc(TL.getLAngleLoc());
5819  NewTL.setRAngleLoc(TL.getRAngleLoc());
5820  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5821  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5822  }
5823 
5824  return Result;
5825 }
5826 
5827 template <typename Derived>
5829  TypeLocBuilder &TLB,
5831  TemplateName Template,
5832  CXXScopeSpec &SS) {
5833  TemplateArgumentListInfo NewTemplateArgs;
5834  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5835  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5838  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5839  ArgIterator(TL, TL.getNumArgs()),
5840  NewTemplateArgs))
5841  return QualType();
5842 
5843  // FIXME: maybe don't rebuild if all the template arguments are the same.
5844 
5845  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5846  QualType Result
5847  = getSema().Context.getDependentTemplateSpecializationType(
5848  TL.getTypePtr()->getKeyword(),
5849  DTN->getQualifier(),
5850  DTN->getIdentifier(),
5851  NewTemplateArgs);
5852 
5856  NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5859  NewTL.setLAngleLoc(TL.getLAngleLoc());
5860  NewTL.setRAngleLoc(TL.getRAngleLoc());
5861  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5862  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5863  return Result;
5864  }
5865 
5866  QualType Result
5867  = getDerived().RebuildTemplateSpecializationType(Template,
5868  TL.getTemplateNameLoc(),
5869  NewTemplateArgs);
5870 
5871  if (!Result.isNull()) {
5872  /// FIXME: Wrap this in an elaborated-type-specifier?
5874  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5877  NewTL.setLAngleLoc(TL.getLAngleLoc());
5878  NewTL.setRAngleLoc(TL.getRAngleLoc());
5879  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5880  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5881  }
5882 
5883  return Result;
5884 }
5885 
5886 template<typename Derived>
5887 QualType
5889  ElaboratedTypeLoc TL) {
5890  const ElaboratedType *T = TL.getTypePtr();
5891 
5892  NestedNameSpecifierLoc QualifierLoc;
5893  // NOTE: the qualifier in an ElaboratedType is optional.
5894  if (TL.getQualifierLoc()) {
5895  QualifierLoc
5896  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5897  if (!QualifierLoc)
5898  return QualType();
5899  }
5900 
5901  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5902  if (NamedT.isNull())
5903  return QualType();
5904 
5905  // C++0x [dcl.type.elab]p2:
5906  // If the identifier resolves to a typedef-name or the simple-template-id
5907  // resolves to an alias template specialization, the
5908  // elaborated-type-specifier is ill-formed.
5909  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5910  if (const TemplateSpecializationType *TST =
5911  NamedT->getAs<TemplateSpecializationType>()) {
5912  TemplateName Template = TST->getTemplateName();
5913  if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5914  Template.getAsTemplateDecl())) {
5915  SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5916  diag::err_tag_reference_non_tag)
5917  << TAT << Sema::NTK_TypeAliasTemplate
5919  SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5920  }
5921  }
5922  }
5923 
5924  QualType Result = TL.getType();
5925  if (getDerived().AlwaysRebuild() ||
5926  QualifierLoc != TL.getQualifierLoc() ||
5927  NamedT != T->getNamedType()) {
5928  Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5929  T->getKeyword(),
5930  QualifierLoc, NamedT);
5931  if (Result.isNull())
5932  return QualType();
5933  }
5934 
5935  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5936  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5937  NewTL.setQualifierLoc(QualifierLoc);
5938  return Result;
5939 }
5940 
5941 template<typename Derived>
5942 QualType TreeTransform<Derived>::TransformAttributedType(
5943  TypeLocBuilder &TLB,
5944  AttributedTypeLoc TL) {
5945  const AttributedType *oldType = TL.getTypePtr();
5946  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5947  if (modifiedType.isNull())
5948  return QualType();
5949 
5950  QualType result = TL.getType();
5951 
5952  // FIXME: dependent operand expressions?
5953  if (getDerived().AlwaysRebuild() ||
5954  modifiedType != oldType->getModifiedType()) {
5955  // TODO: this is really lame; we should really be rebuilding the
5956  // equivalent type from first principles.
5957  QualType equivalentType
5958  = getDerived().TransformType(oldType->getEquivalentType());
5959  if (equivalentType.isNull())
5960  return QualType();
5961 
5962  // Check whether we can add nullability; it is only represented as
5963  // type sugar, and therefore cannot be diagnosed in any other way.
5964  if (auto nullability = oldType->getImmediateNullability()) {
5965  if (!modifiedType->canHaveNullability()) {
5966  SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5967  << DiagNullabilityKind(*nullability, false) << modifiedType;
5968  return QualType();
5969  }
5970  }
5971 
5972  result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5973  modifiedType,
5974  equivalentType);
5975  }
5976 
5977  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5978  newTL.setAttrNameLoc(TL.getAttrNameLoc());
5979  if (TL.hasAttrOperand())
5980  newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5981  if (TL.hasAttrExprOperand())
5982  newTL.setAttrExprOperand(TL.getAttrExprOperand());
5983  else if (TL.hasAttrEnumOperand())
5984  newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5985 
5986  return result;
5987 }
5988 
5989 template<typename Derived>
5990 QualType
5991 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5992  ParenTypeLoc TL) {
5993  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5994  if (Inner.isNull())
5995  return QualType();
5996 
5997  QualType Result = TL.getType();
5998  if (getDerived().AlwaysRebuild() ||
5999  Inner != TL.getInnerLoc().getType()) {
6000  Result = getDerived().RebuildParenType(Inner);
6001  if (Result.isNull())
6002  return QualType();
6003  }
6004 
6005  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6006  NewTL.setLParenLoc(TL.getLParenLoc());
6007  NewTL.setRParenLoc(TL.getRParenLoc());
6008  return Result;
6009 }
6010 
6011 template<typename Derived>
6012 QualType TreeTransform<Derived>::TransformDependentNameType(
6013  TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6014  return TransformDependentNameType(TLB, TL, false);
6015 }
6016 
6017 template<typename Derived>
6018 QualType TreeTransform<Derived>::TransformDependentNameType(
6019  TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
6020  const DependentNameType *T = TL.getTypePtr();
6021 
6022  NestedNameSpecifierLoc QualifierLoc
6023  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6024  if (!QualifierLoc)
6025  return QualType();
6026 
6027  QualType Result
6028  = getDerived().RebuildDependentNameType(T->getKeyword(),
6029  TL.getElaboratedKeywordLoc(),
6030  QualifierLoc,
6031  T->getIdentifier(),
6032  TL.getNameLoc(),
6033  DeducedTSTContext);
6034  if (Result.isNull())
6035  return QualType();
6036 
6037  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6038  QualType NamedT = ElabT->getNamedType();
6039  TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6040 
6041  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6042  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6043  NewTL.setQualifierLoc(QualifierLoc);
6044  } else {
6045  DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
6046  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
6047  NewTL.setQualifierLoc(QualifierLoc);
6048  NewTL.setNameLoc(TL.getNameLoc());
6049  }
6050  return Result;
6051 }
6052 
6053 template<typename Derived>
6054 QualType TreeTransform<Derived>::
6056  DependentTemplateSpecializationTypeLoc TL) {
6057  NestedNameSpecifierLoc QualifierLoc;
6058  if (TL.getQualifierLoc()) {
6059  QualifierLoc
6060  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6061  if (!QualifierLoc)
6062  return QualType();
6063  }
6064 
6065  return getDerived()
6066  .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
6067 }
6068 
6069 template<typename Derived>
6070 QualType TreeTransform<Derived>::
6073  NestedNameSpecifierLoc QualifierLoc) {
6075 
6076  TemplateArgumentListInfo NewTemplateArgs;
6077  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6078  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6079 
6082  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6083  ArgIterator(TL, TL.getNumArgs()),
6084  NewTemplateArgs))
6085  return QualType();
6086 
6087  QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6088  T->getKeyword(), QualifierLoc, T->getIdentifier(),
6089  TL.getTemplateNameLoc(), NewTemplateArgs,
6090  /*AllowInjectedClassName*/ false);
6091  if (Result.isNull())
6092  return QualType();
6093 
6094  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6095  QualType NamedT = ElabT->getNamedType();
6096 
6097  // Copy information relevant to the template specialization.
6099  = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
6101  NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6102  NamedTL.setLAngleLoc(TL.getLAngleLoc());
6103  NamedTL.setRAngleLoc(TL.getRAngleLoc());
6104  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6105  NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6106 
6107  // Copy information relevant to the elaborated type.
6108  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
6110  NewTL.setQualifierLoc(QualifierLoc);
6111  } else if (isa<DependentTemplateSpecializationType>(Result)) {
6115  SpecTL.setQualifierLoc(QualifierLoc);
6118  SpecTL.setLAngleLoc(TL.getLAngleLoc());
6119  SpecTL.setRAngleLoc(TL.getRAngleLoc());
6120  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6121  SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6122  } else {
6124  = TLB.push<TemplateSpecializationTypeLoc>(Result);
6127  SpecTL.setLAngleLoc(TL.getLAngleLoc());
6128  SpecTL.setRAngleLoc(TL.getRAngleLoc());
6129  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
6130  SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
6131  }
6132  return Result;
6133 }
6134 
6135 template<typename Derived>
6137  PackExpansionTypeLoc TL) {
6138  QualType Pattern
6139  = getDerived().TransformType(TLB, TL.getPatternLoc());
6140  if (Pattern.isNull())
6141  return QualType();
6142 
6143  QualType Result = TL.getType();
6144  if (getDerived().AlwaysRebuild() ||
6145  Pattern != TL.getPatternLoc().getType()) {
6146  Result = getDerived().RebuildPackExpansionType(Pattern,
6148  TL.getEllipsisLoc(),
6149  TL.getTypePtr()->getNumExpansions());
6150  if (Result.isNull())
6151  return QualType();
6152  }
6153 
6154  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6155  NewT.setEllipsisLoc(TL.getEllipsisLoc());
6156  return Result;
6157 }
6158 
6159 template<typename Derived>
6160 QualType
6161 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
6162  ObjCInterfaceTypeLoc TL) {
6163  // ObjCInterfaceType is never dependent.
6164  TLB.pushFullCopy(TL);
6165  return TL.getType();
6166 }
6167 
6168 template<typename Derived>
6169 QualType
6170 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6171  ObjCTypeParamTypeLoc TL) {
6172  const ObjCTypeParamType *T = TL.getTypePtr();
6173  ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6174  getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6175  if (!OTP)
6176  return QualType();
6177 
6178  QualType Result = TL.getType();
6179  if (getDerived().AlwaysRebuild() ||
6180  OTP != T->getDecl()) {
6181  Result = getDerived().RebuildObjCTypeParamType(OTP,
6182  TL.getProtocolLAngleLoc(),
6183  llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6184  TL.getNumProtocols()),
6185  TL.getProtocolLocs(),
6186  TL.getProtocolRAngleLoc());
6187  if (Result.isNull())
6188  return QualType();
6189  }
6190 
6191  ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6192  if (TL.getNumProtocols()) {
6193  NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6194  for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6195  NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6196  NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6197  }
6198  return Result;
6199 }
6200 
6201 template<typename Derived>
6202 QualType
6203 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
6204  ObjCObjectTypeLoc TL) {
6205  // Transform base type.
6206  QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6207  if (BaseType.isNull())
6208  return QualType();
6209 
6210  bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6211 
6212  // Transform type arguments.
6213  SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6214  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6215  TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6216  TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6217  QualType TypeArg = TypeArgInfo->getType();
6218  if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6219  AnyChanged = true;
6220 
6221  // We have a pack expansion. Instantiate it.
6222  const auto *PackExpansion = PackExpansionLoc.getType()
6223  ->castAs<PackExpansionType>();
6224  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6225  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6226  Unexpanded);
6227  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6228 
6229  // Determine whether the set of unexpanded parameter packs can
6230  // and should be expanded.
6231  TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6232  bool Expand = false;
6233  bool RetainExpansion = false;
6234  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6235  if (getDerived().TryExpandParameterPacks(
6236  PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6237  Unexpanded, Expand, RetainExpansion, NumExpansions))
6238  return QualType();
6239 
6240  if (!Expand) {
6241  // We can't expand this pack expansion into separate arguments yet;
6242  // just substitute into the pattern and create a new pack expansion
6243  // type.
6244  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6245 
6246  TypeLocBuilder TypeArgBuilder;
6247  TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6248  QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6249  PatternLoc);
6250  if (NewPatternType.isNull())
6251  return QualType();
6252 
6253  QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6254  NewPatternType, NumExpansions);
6255  auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6256  NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6257  NewTypeArgInfos.push_back(
6258  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6259  continue;
6260  }
6261 
6262  // Substitute into the pack expansion pattern for each slice of the
6263  // pack.
6264  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6265  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6266 
6267  TypeLocBuilder TypeArgBuilder;
6268  TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6269 
6270  QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6271  PatternLoc);
6272  if (NewTypeArg.isNull())
6273  return QualType();
6274 
6275  NewTypeArgInfos.push_back(
6276  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6277  }
6278 
6279  continue;
6280  }
6281 
6282  TypeLocBuilder TypeArgBuilder;
6283  TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6284  QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6285  if (NewTypeArg.isNull())
6286  return QualType();
6287 
6288  // If nothing changed, just keep the old TypeSourceInfo.
6289  if (NewTypeArg == TypeArg) {
6290  NewTypeArgInfos.push_back(TypeArgInfo);
6291  continue;
6292  }
6293 
6294  NewTypeArgInfos.push_back(
6295  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6296  AnyChanged = true;
6297  }
6298 
6299  QualType Result = TL.getType();
6300  if (getDerived().AlwaysRebuild() || AnyChanged) {
6301  // Rebuild the type.
6302  Result = getDerived().RebuildObjCObjectType(
6303  BaseType,
6304  TL.getLocStart(),
6305  TL.getTypeArgsLAngleLoc(),
6306  NewTypeArgInfos,
6307  TL.getTypeArgsRAngleLoc(),
6308  TL.getProtocolLAngleLoc(),
6309  llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6310  TL.getNumProtocols()),
6311  TL.getProtocolLocs(),
6312  TL.getProtocolRAngleLoc());
6313 
6314  if (Result.isNull())
6315  return QualType();
6316  }
6317 
6318  ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6319  NewT.setHasBaseTypeAsWritten(true);
6320  NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6321  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6322  NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6323  NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6324  NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6325  for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6326  NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6327  NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6328  return Result;
6329 }
6330 
6331 template<typename Derived>
6332 QualType
6333 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6334  ObjCObjectPointerTypeLoc TL) {
6335  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6336  if (PointeeType.isNull())
6337  return QualType();
6338 
6339  QualType Result = TL.getType();
6340  if (getDerived().AlwaysRebuild() ||
6341  PointeeType != TL.getPointeeLoc().getType()) {
6342  Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6343  TL.getStarLoc());
6344  if (Result.isNull())
6345  return QualType();
6346  }
6347 
6348  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6349  NewT.setStarLoc(TL.getStarLoc());
6350  return Result;
6351 }
6352 
6353 //===----------------------------------------------------------------------===//
6354 // Statement transformation
6355 //===----------------------------------------------------------------------===//
6356 template<typename Derived>
6357 StmtResult
6358 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6359  return S;
6360 }
6361 
6362 template<typename Derived>
6363 StmtResult
6365  return getDerived().TransformCompoundStmt(S, false);
6366 }
6367 
6368 template<typename Derived>
6369 StmtResult
6371  bool IsStmtExpr) {
6372  Sema::CompoundScopeRAII CompoundScope(getSema());
6373 
6374  bool SubStmtInvalid = false;
6375  bool SubStmtChanged = false;
6376  SmallVector<Stmt*, 8> Statements;
6377  for (auto *B : S->body()) {
6378  StmtResult Result = getDerived().TransformStmt(B);
6379  if (Result.isInvalid()) {
6380  // Immediately fail if this was a DeclStmt, since it's very
6381  // likely that this will cause problems for future statements.
6382  if (isa<DeclStmt>(B))
6383  return StmtError();
6384 
6385  // Otherwise, just keep processing substatements and fail later.
6386  SubStmtInvalid = true;
6387  continue;
6388  }
6389 
6390  SubStmtChanged = SubStmtChanged || Result.get() != B;
6391  Statements.push_back(Result.getAs<Stmt>());
6392  }
6393 
6394  if (SubStmtInvalid)
6395  return StmtError();
6396 
6397  if (!getDerived().AlwaysRebuild() &&
6398  !SubStmtChanged)
6399  return S;
6400 
6401  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6402  Statements,
6403  S->getRBracLoc(),
6404  IsStmtExpr);
6405 }
6406 
6407 template<typename Derived>
6408 StmtResult
6409 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6410  ExprResult LHS, RHS;
6411  {
6412  EnterExpressionEvaluationContext Unevaluated(
6414 
6415  // Transform the left-hand case value.
6416  LHS = getDerived().TransformExpr(S->getLHS());
6417  LHS = SemaRef.ActOnConstantExpression(LHS);
6418  if (LHS.isInvalid())
6419  return StmtError();
6420 
6421  // Transform the right-hand case value (for the GNU case-range extension).
6422  RHS = getDerived().TransformExpr(S->getRHS());
6423  RHS = SemaRef.ActOnConstantExpression(RHS);
6424  if (RHS.isInvalid())
6425  return StmtError();
6426  }
6427 
6428  // Build the case statement.
6429  // Case statements are always rebuilt so that they will attached to their
6430  // transformed switch statement.
6431  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6432  LHS.get(),
6433  S->getEllipsisLoc(),
6434  RHS.get(),
6435  S->getColonLoc());
6436  if (Case.isInvalid())
6437  return StmtError();
6438 
6439  // Transform the statement following the case
6440  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6441  if (SubStmt.isInvalid())
6442  return StmtError();
6443 
6444  // Attach the body to the case statement
6445  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6446 }
6447 
6448 template<typename Derived>
6449 StmtResult
6450 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6451  // Transform the statement following the default case
6452  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6453  if (SubStmt.isInvalid())
6454  return StmtError();
6455 
6456  // Default statements are always rebuilt
6457  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6458  SubStmt.get());
6459 }
6460 
6461 template<typename Derived>
6462 StmtResult
6463 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6464  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6465  if (SubStmt.isInvalid())
6466  return StmtError();
6467 
6468  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6469  S->getDecl());
6470  if (!LD)
6471  return StmtError();
6472 
6473 
6474  // FIXME: Pass the real colon location in.
6475  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6476  cast<LabelDecl>(LD), SourceLocation(),
6477  SubStmt.get());
6478 }
6479 
6480 template <typename Derived>
6482  if (!R)
6483  return R;
6484 
6485  switch (R->getKind()) {
6486 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6487 #define ATTR(X)
6488 #define PRAGMA_SPELLING_ATTR(X) \
6489  case attr::X: \
6490  return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6491 #include "clang/Basic/AttrList.inc"
6492  default:
6493  return R;
6494  }
6495 }
6496 
6497 template <typename Derived>
6499  bool AttrsChanged = false;
6501 
6502  // Visit attributes and keep track if any are transformed.
6503  for (const auto *I : S->getAttrs()) {
6504  const Attr *R = getDerived().TransformAttr(I);
6505  AttrsChanged |= (I != R);
6506  Attrs.push_back(R);
6507  }
6508 
6509  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6510  if (SubStmt.isInvalid())
6511  return StmtError();
6512 
6513  if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6514  return S;
6515 
6516  return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6517  SubStmt.get());
6518 }
6519 
6520 template<typename Derived>
6521 StmtResult
6522 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6523  // Transform the initialization statement
6524  StmtResult Init = getDerived().TransformStmt(S->getInit());
6525  if (Init.isInvalid())
6526  return StmtError();
6527 
6528  // Transform the condition
6529  Sema::ConditionResult Cond = getDerived().TransformCondition(
6530  S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6531  S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6533  if (Cond.isInvalid())
6534  return StmtError();
6535 
6536  // If this is a constexpr if, determine which arm we should instantiate.
6537  llvm::Optional<bool> ConstexprConditionValue;
6538  if (S->isConstexpr())
6539  ConstexprConditionValue = Cond.getKnownValue();
6540 
6541  // Transform the "then" branch.
6542  StmtResult Then;
6543  if (!ConstexprConditionValue || *ConstexprConditionValue) {
6544  Then = getDerived().TransformStmt(S->getThen());
6545  if (Then.isInvalid())
6546  return StmtError();
6547  } else {
6548  Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6549  }
6550 
6551  // Transform the "else" branch.
6552  StmtResult Else;
6553  if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6554  Else = getDerived().TransformStmt(S->getElse());
6555  if (Else.isInvalid())
6556  return StmtError();
6557  }
6558 
6559  if (!getDerived().AlwaysRebuild() &&
6560  Init.get() == S->getInit() &&
6561  Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6562  Then.get() == S->getThen() &&
6563  Else.get() == S->getElse())
6564  return S;
6565 
6566  return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6567  Init.get(), Then.get(), S->getElseLoc(),
6568  Else.get());
6569 }
6570 
6571 template<typename Derived>
6572 StmtResult
6573 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6574  // Transform the initialization statement
6575  StmtResult Init = getDerived().TransformStmt(S->getInit());
6576  if (Init.isInvalid())
6577  return StmtError();
6578 
6579  // Transform the condition.
6580  Sema::ConditionResult Cond = getDerived().TransformCondition(
6581  S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6583  if (Cond.isInvalid())
6584  return StmtError();
6585 
6586  // Rebuild the switch statement.
6587  StmtResult Switch
6588  = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6589  S->getInit(), Cond);
6590  if (Switch.isInvalid())
6591  return StmtError();
6592 
6593  // Transform the body of the switch statement.
6594  StmtResult Body = getDerived().TransformStmt(S->getBody());
6595  if (Body.isInvalid())
6596  return StmtError();
6597 
6598  // Complete the switch statement.
6599  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6600  Body.get());
6601 }
6602 
6603 template<typename Derived>
6604 StmtResult
6605 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6606  // Transform the condition
6607  Sema::ConditionResult Cond = getDerived().TransformCondition(
6608  S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6610  if (Cond.isInvalid())
6611  return StmtError();
6612 
6613  // Transform the body
6614  StmtResult Body = getDerived().TransformStmt(S->getBody());
6615  if (Body.isInvalid())
6616  return StmtError();
6617 
6618  if (!getDerived().AlwaysRebuild() &&
6619  Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6620  Body.get() == S->getBody())
6621  return Owned(S);
6622 
6623  return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6624 }
6625 
6626 template<typename Derived>
6627 StmtResult
6628 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6629  // Transform the body
6630  StmtResult Body = getDerived().TransformStmt(S->getBody());
6631  if (Body.isInvalid())
6632  return StmtError();
6633 
6634  // Transform the condition
6635  ExprResult Cond = getDerived().TransformExpr(S->getCond());
6636  if (Cond.isInvalid())
6637  return StmtError();
6638 
6639  if (!getDerived().AlwaysRebuild() &&
6640  Cond.get() == S->getCond() &&
6641  Body.get() == S->getBody())
6642  return S;
6643 
6644  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6645  /*FIXME:*/S->getWhileLoc(), Cond.get(),
6646  S->getRParenLoc());
6647 }
6648 
6649 template<typename Derived>
6650 StmtResult
6651 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6652  // Transform the initialization statement
6653  StmtResult Init = getDerived().TransformStmt(S->getInit());
6654  if (Init.isInvalid())
6655  return StmtError();
6656 
6657  // In OpenMP loop region loop control variable must be captured and be
6658  // private. Perform analysis of first part (if any).
6659  if (getSema().getLangOpts().OpenMP && Init.isUsable())
6660  getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6661 
6662  // Transform the condition
6663  Sema::ConditionResult Cond = getDerived().TransformCondition(
6664  S->getForLoc(), S->getConditionVariable(), S->getCond(),
6666  if (Cond.isInvalid())
6667  return StmtError();
6668 
6669  // Transform the increment
6670  ExprResult Inc = getDerived().TransformExpr(S->getInc());
6671  if (Inc.isInvalid())
6672  return StmtError();
6673 
6674  Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6675  if (S->getInc() && !FullInc.get())
6676  return StmtError();
6677 
6678  // Transform the body
6679  StmtResult Body = getDerived().TransformStmt(S->getBody());
6680  if (Body.isInvalid())
6681  return StmtError();
6682 
6683  if (!getDerived().AlwaysRebuild() &&
6684  Init.get() == S->getInit() &&
6685  Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6686  Inc.get() == S->getInc() &&
6687  Body.get() == S->getBody())
6688  return S;
6689 
6690  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6691  Init.get(), Cond, FullInc,
6692  S->getRParenLoc(), Body.get());
6693 }
6694 
6695 template<typename Derived>
6696 StmtResult
6697 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6698  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6699  S->getLabel());
6700  if (!LD)
6701  return StmtError();
6702 
6703  // Goto statements must always be rebuilt, to resolve the label.
6704  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6705  cast<LabelDecl>(LD));
6706 }
6707 
6708 template<typename Derived>
6709 StmtResult
6710 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6711  ExprResult Target = getDerived().TransformExpr(S->getTarget());
6712  if (Target.isInvalid())
6713  return StmtError();
6714  Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6715 
6716  if (!getDerived().AlwaysRebuild() &&
6717  Target.get() == S->getTarget())
6718  return S;
6719 
6720  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6721  Target.get());
6722 }
6723 
6724 template<typename Derived>
6725 StmtResult
6726 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6727  return S;
6728 }
6729 
6730 template<typename Derived>
6731 StmtResult
6732 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6733  return S;
6734 }
6735 
6736 template<typename Derived>
6737 StmtResult
6738 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6739  ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6740  /*NotCopyInit*/false);
6741  if (Result.isInvalid())
6742  return StmtError();
6743 
6744  // FIXME: We always rebuild the return statement because there is no way
6745  // to tell whether the return type of the function has changed.
6746  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6747 }
6748 
6749 template<typename Derived>
6750 StmtResult
6751 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6752  bool DeclChanged = false;
6753  SmallVector<Decl *, 4> Decls;
6754  for (auto *D : S->decls()) {
6755  Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6756  if (!Transformed)
6757  return StmtError();
6758 
6759  if (Transformed != D)
6760  DeclChanged = true;
6761 
6762  Decls.push_back(Transformed);
6763  }
6764 
6765  if (!getDerived().AlwaysRebuild() && !DeclChanged)
6766  return S;
6767 
6768  return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6769 }
6770 
6771 template<typename Derived>
6772 StmtResult
6773 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6774 
6775  SmallVector<Expr*, 8> Constraints;
6776  SmallVector<Expr*, 8> Exprs;
6777  SmallVector<IdentifierInfo *, 4> Names;
6778 
6779  ExprResult AsmString;
6780  SmallVector<Expr*, 8> Clobbers;
6781 
6782  bool ExprsChanged = false;
6783 
6784  // Go through the outputs.
6785  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6786  Names.push_back(S->getOutputIdentifier(I));
6787 
6788  // No need to transform the constraint literal.
6789  Constraints.push_back(S->getOutputConstraintLiteral(I));
6790 
6791  // Transform the output expr.
6792  Expr *OutputExpr = S->getOutputExpr(I);
6793  ExprResult Result = getDerived().TransformExpr(OutputExpr);
6794  if (Result.isInvalid())
6795  return StmtError();
6796 
6797  ExprsChanged |= Result.get() != OutputExpr;
6798 
6799  Exprs.push_back(Result.get());
6800  }
6801 
6802  // Go through the inputs.
6803  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6804  Names.push_back(S->getInputIdentifier(I));
6805 
6806  // No need to transform the constraint literal.
6807  Constraints.push_back(S->getInputConstraintLiteral(I));
6808 
6809  // Transform the input expr.
6810  Expr *InputExpr = S->getInputExpr(I);
6811  ExprResult Result = getDerived().TransformExpr(InputExpr);
6812  if (Result.isInvalid())
6813  return StmtError();
6814 
6815  ExprsChanged |= Result.get() != InputExpr;
6816 
6817  Exprs.push_back(Result.get());
6818  }
6819 
6820  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6821  return S;
6822 
6823  // Go through the clobbers.
6824  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6825  Clobbers.push_back(S->getClobberStringLiteral(I));
6826 
6827  // No need to transform the asm string literal.
6828  AsmString = S->getAsmString();
6829  return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6830  S->isVolatile(), S->getNumOutputs(),
6831  S->getNumInputs(), Names.data(),
6832  Constraints, Exprs, AsmString.get(),
6833  Clobbers, S->getRParenLoc());
6834 }
6835 
6836 template<typename Derived>
6837 StmtResult
6838 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6839  ArrayRef<Token> AsmToks =
6840  llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6841 
6842  bool HadError = false, HadChange = false;
6843 
6844  ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6845  SmallVector<Expr*, 8> TransformedExprs;
6846  TransformedExprs.reserve(SrcExprs.size());
6847  for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6848  ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6849  if (!Result.isUsable()) {
6850  HadError = true;
6851  } else {
6852  HadChange |= (Result.get() != SrcExprs[i]);
6853  TransformedExprs.push_back(Result.get());
6854  }
6855  }
6856 
6857  if (HadError) return StmtError();
6858  if (!HadChange && !getDerived().AlwaysRebuild())
6859  return Owned(S);
6860 
6861  return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6862  AsmToks, S->getAsmString(),
6863  S->getNumOutputs(), S->getNumInputs(),
6864  S->getAllConstraints(), S->getClobbers(),
6865  TransformedExprs, S->getEndLoc());
6866 }
6867 
6868 // C++ Coroutines TS
6869 
6870 template<typename Derived>
6871 StmtResult
6872 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6873  auto *ScopeInfo = SemaRef.getCurFunction();
6874  auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
6875  assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
6876  ScopeInfo->NeedsCoroutineSuspends &&
6877  ScopeInfo->CoroutineSuspends.first == nullptr &&
6878  ScopeInfo->CoroutineSuspends.second == nullptr &&
6879  "expected clean scope info");
6880 
6881  // Set that we have (possibly-invalid) suspend points before we do anything
6882  // that may fail.
6883  ScopeInfo->setNeedsCoroutineSuspends(false);
6884 
6885  // The new CoroutinePromise object needs to be built and put into the current
6886  // FunctionScopeInfo before any transformations or rebuilding occurs.
6887  auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6888  if (!Promise)
6889  return StmtError();
6890  getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6891  ScopeInfo->CoroutinePromise = Promise;
6892 
6893  // Transform the implicit coroutine statements we built during the initial
6894  // parse.
6895  StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6896  if (InitSuspend.isInvalid())
6897  return StmtError();
6898  StmtResult FinalSuspend =
6899  getDerived().TransformStmt(S->getFinalSuspendStmt());
6900  if (FinalSuspend.isInvalid())
6901  return StmtError();
6902  ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6903  assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
6904 
6905  StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6906  if (BodyRes.isInvalid())
6907  return StmtError();
6908 
6909  CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6910  if (Builder.isInvalid())
6911  return StmtError();
6912 
6913  Expr *ReturnObject = S->getReturnValueInit();
6914  assert(ReturnObject && "the return object is expected to be valid");
6915  ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6916  /*NoCopyInit*/ false);
6917  if (Res.isInvalid())
6918  return StmtError();
6919  Builder.ReturnValue = Res.get();
6920 
6921  if (S->hasDependentPromiseType()) {
6922  assert(!Promise->getType()->isDependentType() &&
6923  "the promise type must no longer be dependent");
6924  assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6925  !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6926  "these nodes should not have been built yet");
6927  if (!Builder.buildDependentStatements())
6928  return StmtError();
6929  } else {
6930  if (auto *OnFallthrough = S->getFallthroughHandler()) {
6931  StmtResult Res = getDerived().TransformStmt(OnFallthrough);
6932  if (Res.isInvalid())
6933  return StmtError();
6934  Builder.OnFallthrough = Res.get();
6935  }
6936 
6937  if (auto *OnException = S->getExceptionHandler()) {
6938  StmtResult Res = getDerived().TransformStmt(OnException);
6939  if (Res.isInvalid())
6940  return StmtError();
6941  Builder.OnException = Res.get();
6942  }
6943 
6944  if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
6945  StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
6946  if (Res.isInvalid())
6947  return StmtError();
6948  Builder.ReturnStmtOnAllocFailure = Res.get();
6949  }
6950 
6951  // Transform any additional statements we may have already built
6952  assert(S->getAllocate() && S->getDeallocate() &&
6953  "allocation and deallocation calls must already be built");
6954  ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
6955  if (AllocRes.isInvalid())
6956  return StmtError();
6957  Builder.Allocate = AllocRes.get();
6958 
6959  ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
6960  if (DeallocRes.isInvalid())
6961  return StmtError();
6962  Builder.Deallocate = DeallocRes.get();
6963 
6964  assert(S->getResultDecl() && "ResultDecl must already be built");
6965  StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
6966  if (ResultDecl.isInvalid())
6967  return StmtError();
6968  Builder.ResultDecl = ResultDecl.get();
6969 
6970  if (auto *ReturnStmt = S->getReturnStmt()) {
6971  StmtResult Res = getDerived().TransformStmt(ReturnStmt);
6972  if (Res.isInvalid())
6973  return StmtError();
6974  Builder.ReturnStmt = Res.get();
6975  }
6976  }
6977  if (!Builder.buildParameterMoves())
6978  return StmtError();
6979 
6980  return getDerived().RebuildCoroutineBodyStmt(Builder);
6981 }
6982 
6983 template<typename Derived>
6984 StmtResult
6985 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6986  ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6987  /*NotCopyInit*/false);
6988  if (Result.isInvalid())
6989  return StmtError();
6990 
6991  // Always rebuild; we don't know if this needs to be injected into a new
6992  // context or if the promise type has changed.
6993  return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
6994  S->isImplicit());
6995 }
6996 
6997 template<typename Derived>
6998 ExprResult
6999 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7000  ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7001  /*NotCopyInit*/false);
7002  if (Result.isInvalid())
7003  return ExprError();
7004 
7005  // Always rebuild; we don't know if this needs to be injected into a new
7006  // context or if the promise type has changed.
7007  return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7008  E->isImplicit());
7009 }
7010 
7011 template <typename Derived>
7012 ExprResult
7013 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7014  ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7015  /*NotCopyInit*/ false);
7016  if (OperandResult.isInvalid())
7017  return ExprError();
7018 
7019  ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7020  E->getOperatorCoawaitLookup());
7021 
7022  if (LookupResult.isInvalid())
7023  return ExprError();
7024 
7025  // Always rebuild; we don't know if this needs to be injected into a new
7026  // context or if the promise type has changed.
7027  return getDerived().RebuildDependentCoawaitExpr(
7028  E->getKeywordLoc(), OperandResult.get(),
7029  cast<UnresolvedLookupExpr>(LookupResult.get()));
7030 }
7031 
7032 template<typename Derived>
7033 ExprResult
7034 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7035  ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7036  /*NotCopyInit*/false);
7037  if (Result.isInvalid())
7038  return ExprError();
7039 
7040  // Always rebuild; we don't know if this needs to be injected into a new
7041  // context or if the promise type has changed.
7042  return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7043 }
7044 
7045 // Objective-C Statements.
7046 
7047 template<typename Derived>
7048 StmtResult
7049 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
7050  // Transform the body of the @try.
7051  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
7052  if (TryBody.isInvalid())
7053  return StmtError();
7054 
7055  // Transform the @catch statements (if present).
7056  bool AnyCatchChanged = false;
7057  SmallVector<Stmt*, 8> CatchStmts;
7058  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
7059  StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
7060  if (Catch.isInvalid())
7061  return StmtError();
7062  if (Catch.get() != S->getCatchStmt(I))
7063  AnyCatchChanged = true;
7064  CatchStmts.push_back(Catch.get());
7065  }
7066 
7067  // Transform the @finally statement (if present).
7068  StmtResult Finally;
7069  if (S->getFinallyStmt()) {
7070  Finally = getDerived().TransformStmt(S->getFinallyStmt());
7071  if (Finally.isInvalid())
7072  return StmtError();
7073  }
7074 
7075  // If nothing changed, just retain this statement.
7076  if (!getDerived().AlwaysRebuild() &&
7077  TryBody.get() == S->getTryBody() &&
7078  !AnyCatchChanged &&
7079  Finally.get() == S->getFinallyStmt())
7080  return S;
7081 
7082  // Build a new statement.
7083  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
7084  CatchStmts, Finally.get());
7085 }
7086 
7087 template<typename Derived>
7088 StmtResult
7089 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
7090  // Transform the @catch parameter, if there is one.
7091  VarDecl *Var = nullptr;
7092  if (VarDecl *FromVar = S->getCatchParamDecl()) {
7093  TypeSourceInfo *TSInfo = nullptr;
7094  if (FromVar->getTypeSourceInfo()) {
7095  TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7096  if (!TSInfo)
7097  return StmtError();
7098  }
7099 
7100  QualType T;
7101  if (TSInfo)
7102  T = TSInfo->getType();
7103  else {
7104  T = getDerived().TransformType(FromVar->getType());
7105  if (T.isNull())
7106  return StmtError();
7107  }
7108 
7109  Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7110  if (!Var)
7111  return StmtError();
7112  }
7113 
7114  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
7115  if (Body.isInvalid())
7116  return StmtError();
7117 
7118  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
7119  S->getRParenLoc(),
7120  Var, Body.get());
7121 }
7122 
7123 template<typename Derived>
7124 StmtResult
7125 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
7126  // Transform the body.
7127  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
7128  if (Body.isInvalid())
7129  return StmtError();
7130 
7131  // If nothing changed, just retain this statement.
7132  if (!getDerived().AlwaysRebuild() &&
7133  Body.get() == S->getFinallyBody())
7134  return S;
7135 
7136  // Build a new statement.
7137  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
7138  Body.get());
7139 }
7140 
7141 template<typename Derived>
7142 StmtResult
7143 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
7144  ExprResult Operand;
7145  if (S->getThrowExpr()) {
7146  Operand = getDerived().TransformExpr(S->getThrowExpr());
7147  if (Operand.isInvalid())
7148  return StmtError();
7149  }
7150 
7151  if (!getDerived().AlwaysRebuild() &&
7152  Operand.get() == S->getThrowExpr())
7153  return S;
7154 
7155  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
7156 }
7157 
7158 template<typename Derived>
7159 StmtResult
7160 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
7161  ObjCAtSynchronizedStmt *S) {
7162  // Transform the object we are locking.
7163  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
7164  if (Object.isInvalid())
7165  return StmtError();
7166  Object =
7167  getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7168  Object.get());
7169  if (Object.isInvalid())
7170  return StmtError();
7171 
7172  // Transform the body.
7173  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
7174  if (Body.isInvalid())
7175  return StmtError();
7176 
7177  // If nothing change, just retain the current statement.
7178  if (!getDerived().AlwaysRebuild() &&
7179  Object.get() == S->getSynchExpr() &&
7180  Body.get() == S->getSynchBody())
7181  return S;
7182 
7183  // Build a new statement.
7184  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
7185  Object.get(), Body.get());
7186 }
7187 
7188 template<typename Derived>
7189 StmtResult
7190 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7191  ObjCAutoreleasePoolStmt *S) {
7192  // Transform the body.
7193  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7194  if (Body.isInvalid())
7195  return StmtError();
7196 
7197  // If nothing changed, just retain this statement.
7198  if (!getDerived().AlwaysRebuild() &&
7199  Body.get() == S->getSubStmt())
7200  return S;
7201 
7202  // Build a new statement.
7203  return getDerived().RebuildObjCAutoreleasePoolStmt(
7204  S->getAtLoc(), Body.get());
7205 }
7206 
7207 template<typename Derived>
7208 StmtResult
7209 TreeTransform<Derived>::TransformObjCForCollectionStmt(
7210  ObjCForCollectionStmt *S) {
7211  // Transform the element statement.
7212  StmtResult Element = getDerived().TransformStmt(S->getElement());
7213  if (Element.isInvalid())
7214  return StmtError();
7215 
7216  // Transform the collection expression.
7217  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
7218  if (Collection.isInvalid())
7219  return StmtError();
7220 
7221  // Transform the body.
7222  StmtResult Body = getDerived().TransformStmt(S->getBody());
7223  if (Body.isInvalid())
7224  return StmtError();
7225 
7226  // If nothing changed, just retain this statement.
7227  if (!getDerived().AlwaysRebuild() &&
7228  Element.get() == S->getElement() &&
7229  Collection.get() == S->getCollection() &&
7230  Body.get() == S->getBody())
7231  return S;
7232 
7233  // Build a new statement.
7234  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
7235  Element.get(),
7236  Collection.get(),
7237  S->getRParenLoc(),
7238  Body.get());
7239 }
7240 
7241 template <typename Derived>
7242 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
7243  // Transform the exception declaration, if any.
7244  VarDecl *Var = nullptr;
7245  if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7246  TypeSourceInfo *T =
7247  getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
7248  if (!T)
7249  return StmtError();
7250 
7251  Var = getDerived().RebuildExceptionDecl(
7252  ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7253  ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
7254  if (!Var || Var->isInvalidDecl())
7255  return StmtError();
7256  }
7257 
7258  // Transform the actual exception handler.
7259  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
7260  if (Handler.isInvalid())
7261  return StmtError();
7262 
7263  if (!getDerived().AlwaysRebuild() && !Var &&
7264  Handler.get() == S->getHandlerBlock())
7265  return S;
7266 
7267  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
7268 }
7269 
7270 template <typename Derived>
7271 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
7272  // Transform the try block itself.
7273  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7274  if (TryBlock.isInvalid())
7275  return StmtError();
7276 
7277  // Transform the handlers.
7278  bool HandlerChanged = false;
7279  SmallVector<Stmt *, 8> Handlers;
7280  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
7281  StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
7282  if (Handler.isInvalid())
7283  return StmtError();
7284 
7285  HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
7286  Handlers.push_back(Handler.getAs<Stmt>());
7287  }
7288 
7289  if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7290  !HandlerChanged)
7291  return S;
7292 
7293  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
7294  Handlers);
7295 }
7296 
7297 template<typename Derived>
7298 StmtResult
7299 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7300  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7301  if (Range.isInvalid())
7302  return StmtError();
7303 
7304  StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7305  if (Begin.isInvalid())
7306  return StmtError();
7307  StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7308  if (End.isInvalid())
7309  return StmtError();
7310 
7311  ExprResult Cond = getDerived().TransformExpr(S->getCond());
7312  if (Cond.isInvalid())
7313  return StmtError();
7314  if (Cond.get())
7315  Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
7316  if (Cond.isInvalid())
7317  return StmtError();
7318  if (Cond.get())
7319  Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
7320 
7321  ExprResult Inc = getDerived().TransformExpr(S->getInc());
7322  if (Inc.isInvalid())
7323  return StmtError();
7324  if (Inc.get())
7325  Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
7326 
7327  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7328  if (LoopVar.isInvalid())
7329  return StmtError();
7330 
7331  StmtResult NewStmt = S;
7332  if (getDerived().AlwaysRebuild() ||
7333  Range.get() != S->getRangeStmt() ||
7334  Begin.get() != S->getBeginStmt() ||
7335  End.get() != S->getEndStmt() ||
7336  Cond.get() != S->getCond() ||
7337  Inc.get() != S->getInc() ||
7338  LoopVar.get() != S->getLoopVarStmt()) {
7339  NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7340  S->getCoawaitLoc(),
7341  S->getColonLoc(), Range.get(),
7342  Begin.get(), End.get(),
7343  Cond.get(),
7344  Inc.get(), LoopVar.get(),
7345  S->getRParenLoc());
7346  if (NewStmt.isInvalid())
7347  return StmtError();
7348  }
7349 
7350  StmtResult Body = getDerived().TransformStmt(S->getBody());
7351  if (Body.isInvalid())
7352  return StmtError();
7353 
7354  // Body has changed but we didn't rebuild the for-range statement. Rebuild
7355  // it now so we have a new statement to attach the body to.
7356  if (Body.get() != S->getBody() && NewStmt.get() == S) {
7357  NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
7358  S->getCoawaitLoc(),
7359  S->getColonLoc(), Range.get(),
7360  Begin.get(), End.get(),
7361  Cond.get(),
7362  Inc.get(), LoopVar.get(),
7363  S->getRParenLoc());
7364  if (NewStmt.isInvalid())
7365  return StmtError();
7366  }
7367 
7368  if (NewStmt.get() == S)
7369  return S;
7370 
7371  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7372 }
7373 
7374 template<typename Derived>
7375 StmtResult
7376 TreeTransform<Derived>::TransformMSDependentExistsStmt(
7377  MSDependentExistsStmt *S) {
7378  // Transform the nested-name-specifier, if any.
7379  NestedNameSpecifierLoc QualifierLoc;
7380  if (S->getQualifierLoc()) {
7381  QualifierLoc
7382  = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7383  if (!QualifierLoc)
7384  return StmtError();
7385  }
7386 
7387  // Transform the declaration name.
7388  DeclarationNameInfo NameInfo = S->getNameInfo();
7389  if (NameInfo.getName()) {
7390  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7391  if (!NameInfo.getName())
7392  return StmtError();
7393  }
7394 
7395  // Check whether anything changed.
7396  if (!getDerived().AlwaysRebuild() &&
7397  QualifierLoc == S->getQualifierLoc() &&
7398  NameInfo.getName() == S->getNameInfo().getName())
7399  return S;
7400 
7401  // Determine whether this name exists, if we can.
7402  CXXScopeSpec SS;
7403  SS.Adopt(QualifierLoc);
7404  bool Dependent = false;
7405  switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7406  case Sema::IER_Exists:
7407  if (S->isIfExists())
7408  break;
7409 
7410  return new (getSema().Context) NullStmt(S->getKeywordLoc());
7411 
7413  if (S->isIfNotExists())
7414  break;
7415 
7416  return new (getSema().Context) NullStmt(S->getKeywordLoc());
7417 
7418  case Sema::IER_Dependent:
7419  Dependent = true;
7420  break;
7421 
7422  case Sema::IER_Error:
7423  return StmtError();
7424  }
7425 
7426  // We need to continue with the instantiation, so do so now.
7427  StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7428  if (SubStmt.isInvalid())
7429  return StmtError();
7430 
7431  // If we have resolved the name, just transform to the substatement.
7432  if (!Dependent)
7433  return SubStmt;
7434 
7435  // The name is still dependent, so build a dependent expression again.
7436  return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7437  S->isIfExists(),
7438  QualifierLoc,
7439  NameInfo,
7440  SubStmt.get());
7441 }
7442 
7443 template<typename Derived>
7444 ExprResult
7445 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7446  NestedNameSpecifierLoc QualifierLoc;
7447  if (E->getQualifierLoc()) {
7448  QualifierLoc
7449  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7450  if (!QualifierLoc)
7451  return ExprError();
7452  }
7453 
7454  MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7455  getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7456  if (!PD)
7457  return ExprError();
7458 
7459  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7460  if (Base.isInvalid())
7461  return ExprError();
7462 
7463  return new (SemaRef.getASTContext())
7464  MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7465  SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7466  QualifierLoc, E->getMemberLoc());
7467 }
7468 
7469 template <typename Derived>
7470 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7471  MSPropertySubscriptExpr *E) {
7472  auto BaseRes = getDerived().TransformExpr(E->getBase());
7473  if (BaseRes.isInvalid())
7474  return ExprError();
7475  auto IdxRes = getDerived().TransformExpr(E->getIdx());
7476  if (IdxRes.isInvalid())
7477  return ExprError();
7478 
7479  if (!getDerived().AlwaysRebuild() &&
7480  BaseRes.get() == E->getBase() &&
7481  IdxRes.get() == E->getIdx())
7482  return E;
7483 
7484  return getDerived().RebuildArraySubscriptExpr(
7485  BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7486 }
7487 
7488 template <typename Derived>
7489 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7490  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7491  if (TryBlock.isInvalid())
7492  return StmtError();
7493 
7494  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7495  if (Handler.isInvalid())
7496  return StmtError();
7497 
7498  if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7499  Handler.get() == S->getHandler())
7500  return S;
7501 
7502  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7503  TryBlock.get(), Handler.get());
7504 }
7505 
7506 template <typename Derived>
7507 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7508  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7509  if (Block.isInvalid())
7510  return StmtError();
7511 
7512  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7513 }
7514 
7515 template <typename Derived>
7516 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7517  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7518  if (FilterExpr.isInvalid())
7519  return StmtError();
7520 
7521  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7522  if (Block.isInvalid())
7523  return StmtError();
7524 
7525  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7526  Block.get());
7527 }
7528 
7529 template <typename Derived>
7531  if (isa<SEHFinallyStmt>(Handler))
7532  return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7533  else
7534  return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7535 }
7536 
7537 template<typename Derived>
7538 StmtResult
7540  return S;
7541 }
7542 
7543 //===----------------------------------------------------------------------===//
7544 // OpenMP directive transformation
7545 //===----------------------------------------------------------------------===//
7546 template <typename Derived>
7549 
7550  // Transform the clauses
7552  ArrayRef<OMPClause *> Clauses = D->clauses();
7553  TClauses.reserve(Clauses.size());
7554  for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7555  I != E; ++I) {
7556  if (*I) {
7557  getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7558  OMPClause *Clause = getDerived().TransformOMPClause(*I);
7559  getDerived().getSema().EndOpenMPClause();
7560  if (Clause)
7561  TClauses.push_back(Clause);
7562  } else {
7563  TClauses.push_back(nullptr);
7564  }
7565  }
7566  StmtResult AssociatedStmt;
7567  if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7568  getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7569  /*CurScope=*/nullptr);
7570  StmtResult Body;
7571  {
7572  Sema::CompoundScopeRAII CompoundScope(getSema());
7573  int ThisCaptureLevel =
7575  Stmt *CS = D->getAssociatedStmt();
7576  while (--ThisCaptureLevel >= 0)
7577  CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7578  Body = getDerived().TransformStmt(CS);
7579  }
7580  AssociatedStmt =
7581  getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7582  if (AssociatedStmt.isInvalid()) {
7583  return StmtError();
7584  }
7585  }
7586  if (TClauses.size() != Clauses.size()) {
7587  return StmtError();
7588  }
7589 
7590  // Transform directive name for 'omp critical' directive.
7591  DeclarationNameInfo DirName;
7592  if (D->getDirectiveKind() == OMPD_critical) {
7593  DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7594  DirName = getDerived().TransformDeclarationNameInfo(DirName);
7595  }
7596  OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7597  if (D->getDirectiveKind() == OMPD_cancellation_point) {
7598  CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7599  } else if (D->getDirectiveKind() == OMPD_cancel) {
7600  CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7601  }
7602 
7603  return getDerived().RebuildOMPExecutableDirective(
7604  D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7605  AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7606 }
7607 
7608 template <typename Derived>
7609 StmtResult
7611  DeclarationNameInfo DirName;
7612  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7613  D->getLocStart());
7614  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7615  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7616  return Res;
7617 }
7618 
7619 template <typename Derived>
7620 StmtResult
7621 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7622  DeclarationNameInfo DirName;
7623  getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7624  D->getLocStart());
7625  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7626  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7627  return Res;
7628 }
7629 
7630 template <typename Derived>
7631 StmtResult
7632 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7633  DeclarationNameInfo DirName;
7634  getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7635  D->getLocStart());
7636  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7637  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7638  return Res;
7639 }
7640 
7641 template <typename Derived>
7642 StmtResult
7643 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7644  DeclarationNameInfo DirName;
7645  getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7646  D->getLocStart());
7647  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7648  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7649  return Res;
7650 }
7651 
7652 template <typename Derived>
7653 StmtResult
7654 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7655  DeclarationNameInfo DirName;
7656  getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7657  D->getLocStart());
7658  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7659  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7660  return Res;
7661 }
7662 
7663 template <typename Derived>
7664 StmtResult
7665 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7666  DeclarationNameInfo DirName;
7667  getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7668  D->getLocStart());
7669  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7670  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7671  return Res;
7672 }
7673 
7674 template <typename Derived>
7675 StmtResult
7676 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7677  DeclarationNameInfo DirName;
7678  getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7679  D->getLocStart());
7680  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7681  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7682  return Res;
7683 }
7684 
7685 template <typename Derived>
7686 StmtResult
7687 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7688  DeclarationNameInfo DirName;
7689  getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7690  D->getLocStart());
7691  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7692  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7693  return Res;
7694 }
7695 
7696 template <typename Derived>
7697 StmtResult
7698 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7699  getDerived().getSema().StartOpenMPDSABlock(
7700  OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7701  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7702  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7703  return Res;
7704 }
7705 
7706 template <typename Derived>
7707 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7708  OMPParallelForDirective *D) {
7709  DeclarationNameInfo DirName;
7710  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7711  nullptr, D->getLocStart());
7712  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7713  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7714  return Res;
7715 }
7716 
7717 template <typename Derived>
7718 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7719  OMPParallelForSimdDirective *D) {
7720  DeclarationNameInfo DirName;
7721  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7722  nullptr, D->getLocStart());
7723  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7724  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7725  return Res;
7726 }
7727 
7728 template <typename Derived>
7729 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7730  OMPParallelSectionsDirective *D) {
7731  DeclarationNameInfo DirName;
7732  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7733  nullptr, D->getLocStart());
7734  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7735  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7736  return Res;
7737 }
7738 
7739 template <typename Derived>
7740 StmtResult
7741 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7742  DeclarationNameInfo DirName;
7743  getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7744  D->getLocStart());
7745  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7746  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7747  return Res;
7748 }
7749 
7750 template <typename Derived>
7751 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7752  OMPTaskyieldDirective *D) {
7753  DeclarationNameInfo DirName;
7754  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7755  D->getLocStart());
7756  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7757  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7758  return Res;
7759 }
7760 
7761 template <typename Derived>
7762 StmtResult
7763 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7764  DeclarationNameInfo DirName;
7765  getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7766  D->getLocStart());
7767  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7768  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7769  return Res;
7770 }
7771 
7772 template <typename Derived>
7773 StmtResult
7774 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7775  DeclarationNameInfo DirName;
7776  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7777  D->getLocStart());
7778  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7779  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7780  return Res;
7781 }
7782 
7783 template <typename Derived>
7784 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7785  OMPTaskgroupDirective *D) {
7786  DeclarationNameInfo DirName;
7787  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7788  D->getLocStart());
7789  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7790  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7791  return Res;
7792 }
7793 
7794 template <typename Derived>
7795 StmtResult
7796 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7797  DeclarationNameInfo DirName;
7798  getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7799  D->getLocStart());
7800  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7801  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7802  return Res;
7803 }
7804 
7805 template <typename Derived>
7806 StmtResult
7807 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7808  DeclarationNameInfo DirName;
7809  getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7810  D->getLocStart());
7811  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7812  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7813  return Res;
7814 }
7815 
7816 template <typename Derived>
7817 StmtResult
7818 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7819  DeclarationNameInfo DirName;
7820  getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7821  D->getLocStart());
7822  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7823  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7824  return Res;
7825 }
7826 
7827 template <typename Derived>
7828 StmtResult
7829 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7830  DeclarationNameInfo DirName;
7831  getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7832  D->getLocStart());
7833  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7834  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7835  return Res;
7836 }
7837 
7838 template <typename Derived>
7839 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7840  OMPTargetDataDirective *D) {
7841  DeclarationNameInfo DirName;
7842  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7843  D->getLocStart());
7844  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7845  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7846  return Res;
7847 }
7848 
7849 template <typename Derived>
7850 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7851  OMPTargetEnterDataDirective *D) {
7852  DeclarationNameInfo DirName;
7853  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7854  nullptr, D->getLocStart());
7855  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7856  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7857  return Res;
7858 }
7859 
7860 template <typename Derived>
7861 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7862  OMPTargetExitDataDirective *D) {
7863  DeclarationNameInfo DirName;
7864  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7865  nullptr, D->getLocStart());
7866  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7867  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7868  return Res;
7869 }
7870 
7871 template <typename Derived>
7872 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7873  OMPTargetParallelDirective *D) {
7874  DeclarationNameInfo DirName;
7875  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7876  nullptr, D->getLocStart());
7877  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7878  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7879  return Res;
7880 }
7881 
7882 template <typename Derived>
7883 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7884  OMPTargetParallelForDirective *D) {
7885  DeclarationNameInfo DirName;
7886  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7887  nullptr, D->getLocStart());
7888  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7889  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7890  return Res;
7891 }
7892 
7893 template <typename Derived>
7894 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7895  OMPTargetUpdateDirective *D) {
7896  DeclarationNameInfo DirName;
7897  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7898  nullptr, D->getLocStart());
7899  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7900  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7901  return Res;
7902 }
7903 
7904 template <typename Derived>
7905 StmtResult
7906 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7907  DeclarationNameInfo DirName;
7908  getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7909  D->getLocStart());
7910  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7911  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7912  return Res;
7913 }
7914 
7915 template <typename Derived>
7916 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7917  OMPCancellationPointDirective *D) {
7918  DeclarationNameInfo DirName;
7919  getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7920  nullptr, D->getLocStart());
7921  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7922  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7923  return Res;
7924 }
7925 
7926 template <typename Derived>
7927 StmtResult
7928 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7929  DeclarationNameInfo DirName;
7930  getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7931  D->getLocStart());
7932  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7933  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7934  return Res;
7935 }
7936 
7937 template <typename Derived>
7938 StmtResult
7939 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7940  DeclarationNameInfo DirName;
7941  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7942  D->getLocStart());
7943  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7944  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7945  return Res;
7946 }
7947 
7948 template <typename Derived>
7949 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7950  OMPTaskLoopSimdDirective *D) {
7951  DeclarationNameInfo DirName;
7952  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7953  nullptr, D->getLocStart());
7954  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7955  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7956  return Res;
7957 }
7958 
7959 template <typename Derived>
7960 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7961  OMPDistributeDirective *D) {
7962  DeclarationNameInfo DirName;
7963  getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7964  D->getLocStart());
7965  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7966  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7967  return Res;
7968 }
7969 
7970 template <typename Derived>
7971 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7972  OMPDistributeParallelForDirective *D) {
7973  DeclarationNameInfo DirName;
7974  getDerived().getSema().StartOpenMPDSABlock(
7975  OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7976  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7977  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7978  return Res;
7979 }
7980 
7981 template <typename Derived>
7982 StmtResult
7983 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7984  OMPDistributeParallelForSimdDirective *D) {
7985  DeclarationNameInfo DirName;
7986  getDerived().getSema().StartOpenMPDSABlock(
7987  OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7988  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7990  return Res;
7991 }
7992 
7993 template <typename Derived>
7994 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7995  OMPDistributeSimdDirective *D) {
7996  DeclarationNameInfo DirName;
7997  getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7998  nullptr, D->getLocStart());
7999  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8001  return Res;
8002 }
8003 
8004 template <typename Derived>
8005 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8006  OMPTargetParallelForSimdDirective *D) {
8007  DeclarationNameInfo DirName;
8008  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8009  DirName, nullptr,
8010  D->getLocStart());
8011  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8012  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8013  return Res;
8014 }
8015 
8016 template <typename Derived>
8017 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8018  OMPTargetSimdDirective *D) {
8019  DeclarationNameInfo DirName;
8020  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8021  D->getLocStart());
8022  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8023  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8024  return Res;
8025 }
8026 
8027 template <typename Derived>
8028 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8029  OMPTeamsDistributeDirective *D) {
8030  DeclarationNameInfo DirName;
8031  getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8032  nullptr, D->getLocStart());
8033  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8034  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8035  return Res;
8036 }
8037 
8038 template <typename Derived>
8039 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8040  OMPTeamsDistributeSimdDirective *D) {
8041  DeclarationNameInfo DirName;
8042  getDerived().getSema().StartOpenMPDSABlock(
8043  OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8044  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8045  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8046  return Res;
8047 }
8048 
8049 template <typename Derived>
8050 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8051  OMPTeamsDistributeParallelForSimdDirective *D) {
8052  DeclarationNameInfo DirName;
8053  getDerived().getSema().StartOpenMPDSABlock(
8054  OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8055  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8056  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8057  return Res;
8058 }
8059 
8060 template <typename Derived>
8061 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8062  OMPTeamsDistributeParallelForDirective *D) {
8063  DeclarationNameInfo DirName;
8064  getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8065  DirName, nullptr, D->getLocStart());
8066  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8067  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8068  return Res;
8069 }
8070 
8071 template <typename Derived>
8072 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8073  OMPTargetTeamsDirective *D) {
8074  DeclarationNameInfo DirName;
8075  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8076  nullptr, D->getLocStart());
8077  auto Res = getDerived().TransformOMPExecutableDirective(D);
8078  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8079  return Res;
8080 }
8081 
8082 template <typename Derived>
8083 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8084  OMPTargetTeamsDistributeDirective *D) {
8085  DeclarationNameInfo DirName;
8086  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8087  DirName, nullptr, D->getLocStart());
8088  auto Res = getDerived().TransformOMPExecutableDirective(D);
8089  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8090  return Res;
8091 }
8092 
8093 template <typename Derived>
8094 StmtResult
8095 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8096  OMPTargetTeamsDistributeParallelForDirective *D) {
8097  DeclarationNameInfo DirName;
8098  getDerived().getSema().StartOpenMPDSABlock(
8099  OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8100  D->getLocStart());
8101  auto Res = getDerived().TransformOMPExecutableDirective(D);
8102  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8103  return Res;
8104 }
8105 
8106 template <typename Derived>
8107 StmtResult TreeTransform<Derived>::
8108  TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8109  OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8110  DeclarationNameInfo DirName;
8111  getDerived().getSema().StartOpenMPDSABlock(
8112  OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8113  D->getLocStart());
8114  auto Res = getDerived().TransformOMPExecutableDirective(D);
8115  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8116  return Res;
8117 }
8118 
8119 template <typename Derived>
8120 StmtResult
8121 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8122  OMPTargetTeamsDistributeSimdDirective *D) {
8123  DeclarationNameInfo DirName;
8124  getDerived().getSema().StartOpenMPDSABlock(
8125  OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8126  auto Res = getDerived().TransformOMPExecutableDirective(D);
8127  getDerived().getSema().EndOpenMPDSABlock(Res.get());
8128  return Res;
8129 }
8130 
8131 
8132 //===----------------------------------------------------------------------===//
8133 // OpenMP clause transformation
8134 //===----------------------------------------------------------------------===//
8135 template <typename Derived>
8136 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
8137  ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8138  if (Cond.isInvalid())
8139  return nullptr;
8140  return getDerived().RebuildOMPIfClause(
8141  C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8142  C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
8143 }
8144 
8145 template <typename Derived>
8146 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8147  ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8148  if (Cond.isInvalid())
8149  return nullptr;
8150  return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8151  C->getLParenLoc(), C->getLocEnd());
8152 }
8153 
8154 template <typename Derived>
8155 OMPClause *
8156 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8157  ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8158  if (NumThreads.isInvalid())
8159  return nullptr;
8160  return getDerived().RebuildOMPNumThreadsClause(
8161  NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8162 }
8163 
8164 template <typename Derived>
8165 OMPClause *
8166 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8167  ExprResult E = getDerived().TransformExpr(C->getSafelen());
8168  if (E.isInvalid())
8169  return nullptr;
8170  return getDerived().RebuildOMPSafelenClause(
8171  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8172 }
8173 
8174 template <typename Derived>
8175 OMPClause *
8176 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8177  ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8178  if (E.isInvalid())
8179  return nullptr;
8180  return getDerived().RebuildOMPSimdlenClause(
8181  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8182 }
8183 
8184 template <typename Derived>
8185 OMPClause *
8186 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8187  ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8188  if (E.isInvalid())
8189  return nullptr;
8190  return getDerived().RebuildOMPCollapseClause(
8191  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8192 }
8193 
8194 template <typename Derived>
8195 OMPClause *
8196 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
8197  return getDerived().RebuildOMPDefaultClause(
8198  C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8199  C->getLParenLoc(), C->getLocEnd());
8200 }
8201 
8202 template <typename Derived>
8203 OMPClause *
8204 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
8205  return getDerived().RebuildOMPProcBindClause(
8206  C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8207  C->getLParenLoc(), C->getLocEnd());
8208 }
8209 
8210 template <typename Derived>
8211 OMPClause *
8212 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8213  ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8214  if (E.isInvalid())
8215  return nullptr;
8216  return getDerived().RebuildOMPScheduleClause(
8217  C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
8218  C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8219  C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
8220  C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8221 }
8222 
8223 template <typename Derived>
8224 OMPClause *
8225 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
8226  ExprResult E;
8227  if (auto *Num = C->getNumForLoops()) {
8228  E = getDerived().TransformExpr(Num);
8229  if (E.isInvalid())
8230  return nullptr;
8231  }
8232  return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8233  C->getLParenLoc(), E.get());
8234 }
8235 
8236 template <typename Derived>
8237 OMPClause *
8238 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8239  // No need to rebuild this clause, no template-dependent parameters.
8240  return C;
8241 }
8242 
8243 template <typename Derived>
8244 OMPClause *
8245 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8246  // No need to rebuild this clause, no template-dependent parameters.
8247  return C;
8248 }
8249 
8250 template <typename Derived>
8251 OMPClause *
8252 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8253  // No need to rebuild this clause, no template-dependent parameters.
8254  return C;
8255 }
8256 
8257 template <typename Derived>
8258 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8259  // No need to rebuild this clause, no template-dependent parameters.
8260  return C;
8261 }
8262 
8263 template <typename Derived>
8264 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8265  // No need to rebuild this clause, no template-dependent parameters.
8266  return C;
8267 }
8268 
8269 template <typename Derived>
8270 OMPClause *
8271 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8272  // No need to rebuild this clause, no template-dependent parameters.
8273  return C;
8274 }
8275 
8276 template <typename Derived>
8277 OMPClause *
8278 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8279  // No need to rebuild this clause, no template-dependent parameters.
8280  return C;
8281 }
8282 
8283 template <typename Derived>
8284 OMPClause *
8285 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8286  // No need to rebuild this clause, no template-dependent parameters.
8287  return C;
8288 }
8289 
8290 template <typename Derived>
8291 OMPClause *
8292 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8293  // No need to rebuild this clause, no template-dependent parameters.
8294  return C;
8295 }
8296 
8297 template <typename Derived>
8298 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8299  // No need to rebuild this clause, no template-dependent parameters.
8300  return C;
8301 }
8302 
8303 template <typename Derived>
8304 OMPClause *
8305 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8306  // No need to rebuild this clause, no template-dependent parameters.
8307  return C;
8308 }
8309 
8310 template <typename Derived>
8311 OMPClause *
8312 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
8314  Vars.reserve(C->varlist_size());
8315  for (auto *VE : C->varlists()) {
8316  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8317  if (EVar.isInvalid())
8318  return nullptr;
8319  Vars.push_back(EVar.get());
8320  }
8321  return getDerived().RebuildOMPPrivateClause(
8322  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8323 }
8324 
8325 template <typename Derived>
8326 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8327  OMPFirstprivateClause *C) {
8329  Vars.reserve(C->varlist_size());
8330  for (auto *VE : C->varlists()) {
8331  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8332  if (EVar.isInvalid())
8333  return nullptr;
8334  Vars.push_back(EVar.get());
8335  }
8336  return getDerived().RebuildOMPFirstprivateClause(
8337  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8338 }
8339 
8340 template <typename Derived>
8341 OMPClause *
8342 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8344  Vars.reserve(C->varlist_size());
8345  for (auto *VE : C->varlists()) {
8346  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8347  if (EVar.isInvalid())
8348  return nullptr;
8349  Vars.push_back(EVar.get());
8350  }
8351  return getDerived().RebuildOMPLastprivateClause(
8352  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8353 }
8354 
8355 template <typename Derived>
8356 OMPClause *
8357 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8359  Vars.reserve(C->varlist_size());
8360  for (auto *VE : C->varlists()) {
8361  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8362  if (EVar.isInvalid())
8363  return nullptr;
8364  Vars.push_back(EVar.get());
8365  }
8366  return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8367  C->getLParenLoc(), C->getLocEnd());
8368 }
8369 
8370 template <typename Derived>
8371 OMPClause *
8372 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8374  Vars.reserve(C->varlist_size());
8375  for (auto *VE : C->varlists()) {
8376  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8377  if (EVar.isInvalid())
8378  return nullptr;
8379  Vars.push_back(EVar.get());
8380  }
8381  CXXScopeSpec ReductionIdScopeSpec;
8382  ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8383 
8384  DeclarationNameInfo NameInfo = C->getNameInfo();
8385  if (NameInfo.getName()) {
8386  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8387  if (!NameInfo.getName())
8388  return nullptr;
8389  }
8390  // Build a list of all UDR decls with the same names ranged by the Scopes.
8391  // The Scope boundary is a duplication of the previous decl.
8392  llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8393  for (auto *E : C->reduction_ops()) {
8394  // Transform all the decls.
8395  if (E) {
8396  auto *ULE = cast<UnresolvedLookupExpr>(E);
8397  UnresolvedSet<8> Decls;
8398  for (auto *D : ULE->decls()) {
8399  NamedDecl *InstD =
8400  cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8401  Decls.addDecl(InstD, InstD->getAccess());
8402  }
8403  UnresolvedReductions.push_back(
8405  SemaRef.Context, /*NamingClass=*/nullptr,
8406  ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8407  NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8408  Decls.begin(), Decls.end()));
8409  } else
8410  UnresolvedReductions.push_back(nullptr);
8411  }
8412  return getDerived().RebuildOMPReductionClause(
8413  Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8414  C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8415 }
8416 
8417 template <typename Derived>
8418 OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8419  OMPTaskReductionClause *C) {
8421  Vars.reserve(C->varlist_size());
8422  for (auto *VE : C->varlists()) {
8423  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8424  if (EVar.isInvalid())
8425  return nullptr;
8426  Vars.push_back(EVar.get());
8427  }
8428  CXXScopeSpec ReductionIdScopeSpec;
8429  ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8430 
8431  DeclarationNameInfo NameInfo = C->getNameInfo();
8432  if (NameInfo.getName()) {
8433  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8434  if (!NameInfo.getName())
8435  return nullptr;
8436  }
8437  // Build a list of all UDR decls with the same names ranged by the Scopes.
8438  // The Scope boundary is a duplication of the previous decl.
8439  llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8440  for (auto *E : C->reduction_ops()) {
8441  // Transform all the decls.
8442  if (E) {
8443  auto *ULE = cast<UnresolvedLookupExpr>(E);
8444  UnresolvedSet<8> Decls;
8445  for (auto *D : ULE->decls()) {
8446  NamedDecl *InstD =
8447  cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8448  Decls.addDecl(InstD, InstD->getAccess());
8449  }
8450  UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8451  SemaRef.Context, /*NamingClass=*/nullptr,
8452  ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8453  /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8454  } else
8455  UnresolvedReductions.push_back(nullptr);
8456  }
8457  return getDerived().RebuildOMPTaskReductionClause(
8458  Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8459  C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8460 }
8461 
8462 template <typename Derived>
8463 OMPClause *
8464 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8466  Vars.reserve(C->varlist_size());
8467  for (auto *VE : C->varlists()) {
8468  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8469  if (EVar.isInvalid())
8470  return nullptr;
8471  Vars.push_back(EVar.get());
8472  }
8473  ExprResult Step = getDerived().TransformExpr(C->getStep());
8474  if (Step.isInvalid())
8475  return nullptr;
8476  return getDerived().RebuildOMPLinearClause(
8477  Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8478  C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
8479 }
8480 
8481 template <typename Derived>
8482 OMPClause *
8483 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8485  Vars.reserve(C->varlist_size());
8486  for (auto *VE : C->varlists()) {
8487  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8488  if (EVar.isInvalid())
8489  return nullptr;
8490  Vars.push_back(EVar.get());
8491  }
8492  ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8493  if (Alignment.isInvalid())
8494  return nullptr;
8495  return getDerived().RebuildOMPAlignedClause(
8496  Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8497  C->getColonLoc(), C->getLocEnd());
8498 }
8499 
8500 template <typename Derived>
8501 OMPClause *
8502 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8504  Vars.reserve(C->varlist_size());
8505  for (auto *VE : C->varlists()) {
8506  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8507  if (EVar.isInvalid())
8508  return nullptr;
8509  Vars.push_back(EVar.get());
8510  }
8511  return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8512  C->getLParenLoc(), C->getLocEnd());
8513 }
8514 
8515 template <typename Derived>
8516 OMPClause *
8517 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8519  Vars.reserve(C->varlist_size());
8520  for (auto *VE : C->varlists()) {
8521  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8522  if (EVar.isInvalid())
8523  return nullptr;
8524  Vars.push_back(EVar.get());
8525  }
8526  return getDerived().RebuildOMPCopyprivateClause(
8527  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8528 }
8529 
8530 template <typename Derived>
8531 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8533  Vars.reserve(C->varlist_size());
8534  for (auto *VE : C->varlists()) {
8535  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8536  if (EVar.isInvalid())
8537  return nullptr;
8538  Vars.push_back(EVar.get());
8539  }
8540  return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8541  C->getLParenLoc(), C->getLocEnd());
8542 }
8543 
8544 template <typename Derived>
8545 OMPClause *
8546 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8548  Vars.reserve(C->varlist_size());
8549  for (auto *VE : C->varlists()) {
8550  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8551  if (EVar.isInvalid())
8552  return nullptr;
8553  Vars.push_back(EVar.get());
8554  }
8555  return getDerived().RebuildOMPDependClause(
8556  C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8557  C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8558 }
8559 
8560 template <typename Derived>
8561 OMPClause *
8562 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8563  ExprResult E = getDerived().TransformExpr(C->getDevice());
8564  if (E.isInvalid())
8565  return nullptr;
8566  return getDerived().RebuildOMPDeviceClause(
8567  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8568 }
8569 
8570 template <typename Derived>
8571 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8573  Vars.reserve(C->varlist_size());
8574  for (auto *VE : C->varlists()) {
8575  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8576  if (EVar.isInvalid())
8577  return nullptr;
8578  Vars.push_back(EVar.get());
8579  }
8580  return getDerived().RebuildOMPMapClause(
8582  C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8583  C->getLParenLoc(), C->getLocEnd());
8584 }
8585 
8586 template <typename Derived>
8587 OMPClause *
8588 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8589  ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8590  if (E.isInvalid())
8591  return nullptr;
8592  return getDerived().RebuildOMPNumTeamsClause(
8593  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8594 }
8595 
8596 template <typename Derived>
8597 OMPClause *
8598 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8599  ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8600  if (E.isInvalid())
8601  return nullptr;
8602  return getDerived().RebuildOMPThreadLimitClause(
8603  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8604 }
8605 
8606 template <typename Derived>
8607 OMPClause *
8608 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8609  ExprResult E = getDerived().TransformExpr(C->getPriority());
8610  if (E.isInvalid())
8611  return nullptr;
8612  return getDerived().RebuildOMPPriorityClause(
8613  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8614 }
8615 
8616 template <typename Derived>
8617 OMPClause *
8618 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8619  ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8620  if (E.isInvalid())
8621  return nullptr;
8622  return getDerived().RebuildOMPGrainsizeClause(
8623  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8624 }
8625 
8626 template <typename Derived>
8627 OMPClause *
8628 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8629  ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8630  if (E.isInvalid())
8631  return nullptr;
8632  return getDerived().RebuildOMPNumTasksClause(
8633  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8634 }
8635 
8636 template <typename Derived>
8637 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8638  ExprResult E = getDerived().TransformExpr(C->getHint());
8639  if (E.isInvalid())
8640  return nullptr;
8641  return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8642  C->getLParenLoc(), C->getLocEnd());
8643 }
8644 
8645 template <typename Derived>
8646 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8647  OMPDistScheduleClause *C) {
8648  ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8649  if (E.isInvalid())
8650  return nullptr;
8651  return getDerived().RebuildOMPDistScheduleClause(
8652  C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8653  C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8654 }
8655 
8656 template <typename Derived>
8657 OMPClause *
8658 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8659  return C;
8660 }
8661 
8662 template <typename Derived>
8663 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8665  Vars.reserve(C->varlist_size());
8666  for (auto *VE : C->varlists()) {
8667  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8668  if (EVar.isInvalid())
8669  return 0;
8670  Vars.push_back(EVar.get());
8671  }
8672  return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8673  C->getLParenLoc(), C->getLocEnd());
8674 }
8675 
8676 template <typename Derived>
8677 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8679  Vars.reserve(C->varlist_size());
8680  for (auto *VE : C->varlists()) {
8681  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8682  if (EVar.isInvalid())
8683  return 0;
8684  Vars.push_back(EVar.get());
8685  }
8686  return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8687  C->getLParenLoc(), C->getLocEnd());
8688 }
8689 
8690 template <typename Derived>
8691 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8692  OMPUseDevicePtrClause *C) {
8694  Vars.reserve(C->varlist_size());
8695  for (auto *VE : C->varlists()) {
8696  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8697  if (EVar.isInvalid())
8698  return nullptr;
8699  Vars.push_back(EVar.get());
8700  }
8701  return getDerived().RebuildOMPUseDevicePtrClause(
8702  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8703 }
8704 
8705 template <typename Derived>
8706 OMPClause *
8707 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8709  Vars.reserve(C->varlist_size());
8710  for (auto *VE : C->varlists()) {
8711  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8712  if (EVar.isInvalid())
8713  return nullptr;
8714  Vars.push_back(EVar.get());
8715  }
8716  return getDerived().RebuildOMPIsDevicePtrClause(
8717  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8718 }
8719 
8720 //===----------------------------------------------------------------------===//
8721 // Expression transformation
8722 //===----------------------------------------------------------------------===//
8723 template<typename Derived>
8724 ExprResult
8725 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8726  if (!E->isTypeDependent())
8727  return E;
8728 
8729  return getDerived().RebuildPredefinedExpr(E->getLocation(),
8730  E->getIdentType());
8731 }
8732 
8733 template<typename Derived>
8734 ExprResult
8735 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8736  NestedNameSpecifierLoc QualifierLoc;
8737  if (E->getQualifierLoc()) {
8738  QualifierLoc
8739  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8740  if (!QualifierLoc)
8741  return ExprError();
8742  }
8743 
8744  ValueDecl *ND
8745  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8746  E->getDecl()));
8747  if (!ND)
8748  return ExprError();
8749 
8750  DeclarationNameInfo NameInfo = E->getNameInfo();
8751  if (NameInfo.getName()) {
8752  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8753  if (!NameInfo.getName())
8754  return ExprError();
8755  }
8756 
8757  if (!getDerived().AlwaysRebuild() &&
8758  QualifierLoc == E->getQualifierLoc() &&
8759  ND == E->getDecl() &&
8760  NameInfo.getName() == E->getDecl()->getDeclName() &&
8761  !E->hasExplicitTemplateArgs()) {
8762 
8763  // Mark it referenced in the new context regardless.
8764  // FIXME: this is a bit instantiation-specific.
8765  SemaRef.MarkDeclRefReferenced(E);
8766 
8767  return E;
8768  }
8769 
8770  TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8771  if (E->hasExplicitTemplateArgs()) {
8772  TemplateArgs = &TransArgs;
8773  TransArgs.setLAngleLoc(E->getLAngleLoc());
8774  TransArgs.setRAngleLoc(E->getRAngleLoc());
8775  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8776  E->getNumTemplateArgs(),
8777  TransArgs))
8778  return ExprError();
8779  }
8780 
8781  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8782  TemplateArgs);
8783 }
8784 
8785 template<typename Derived>
8786 ExprResult
8787 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8788  return E;
8789 }
8790 
8791 template<typename Derived>
8792 ExprResult
8793 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8794  return E;
8795 }
8796 
8797 template<typename Derived>
8798 ExprResult
8799 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8800  return E;
8801 }
8802 
8803 template<typename Derived>
8804 ExprResult
8805 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8806  return E;
8807 }
8808 
8809 template<typename Derived>
8810 ExprResult
8811 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8812  return E;
8813 }
8814 
8815 template<typename Derived>
8816 ExprResult
8817 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8818  if (FunctionDecl *FD = E->getDirectCallee())
8819  SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8820  return SemaRef.MaybeBindToTemporary(E);
8821 }
8822 
8823 template<typename Derived>
8824 ExprResult
8825 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8826  ExprResult ControllingExpr =
8827  getDerived().TransformExpr(E->getControllingExpr());
8828  if (ControllingExpr.isInvalid())
8829  return ExprError();
8830 
8831  SmallVector<Expr *, 4> AssocExprs;
8832  SmallVector<TypeSourceInfo *, 4> AssocTypes;
8833  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8834  TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8835  if (TS) {
8836  TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8837  if (!AssocType)
8838  return ExprError();
8839  AssocTypes.push_back(AssocType);
8840  } else {
8841  AssocTypes.push_back(nullptr);
8842  }
8843 
8844  ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8845  if (AssocExpr.isInvalid())
8846  return ExprError();
8847  AssocExprs.push_back(AssocExpr.get());
8848  }
8849 
8850  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8851  E->getDefaultLoc(),
8852  E->getRParenLoc(),
8853  ControllingExpr.get(),
8854  AssocTypes,
8855  AssocExprs);
8856 }
8857 
8858 template<typename Derived>
8859 ExprResult
8860 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8861  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8862  if (SubExpr.isInvalid())
8863  return ExprError();
8864 
8865  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8866  return E;
8867 
8868  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8869  E->getRParen());
8870 }
8871 
8872 /// \brief The operand of a unary address-of operator has special rules: it's
8873 /// allowed to refer to a non-static member of a class even if there's no 'this'
8874 /// object available.
8875 template<typename Derived>
8876 ExprResult
8878  if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8879  return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8880  else
8881  return getDerived().TransformExpr(E);
8882 }
8883 
8884 template<typename Derived>
8885 ExprResult
8887  ExprResult SubExpr;
8888  if (E->getOpcode() == UO_AddrOf)
8889  SubExpr = TransformAddressOfOperand(E->getSubExpr());
8890  else
8891  SubExpr = TransformExpr(E->getSubExpr());
8892  if (SubExpr.isInvalid())
8893  return ExprError();
8894 
8895  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8896  return E;
8897 
8898  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8899  E->getOpcode(),
8900  SubExpr.get());
8901 }
8902 
8903 template<typename Derived>
8904 ExprResult
8905 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8906  // Transform the type.
8907  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8908  if (!Type)
8909  return ExprError();
8910 
8911  // Transform all of the components into components similar to what the
8912  // parser uses.
8913  // FIXME: It would be slightly more efficient in the non-dependent case to
8914  // just map FieldDecls, rather than requiring the rebuilder to look for
8915  // the fields again. However, __builtin_offsetof is rare enough in
8916  // template code that we don't care.
8917  bool ExprChanged = false;
8918  typedef Sema::OffsetOfComponent Component;
8919  SmallVector<Component, 4> Components;
8920  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8921  const OffsetOfNode &ON = E->getComponent(I);
8922  Component Comp;
8923  Comp.isBrackets = true;
8924  Comp.LocStart = ON.getSourceRange().getBegin();
8925  Comp.LocEnd = ON.getSourceRange().getEnd();
8926  switch (ON.getKind()) {
8927  case OffsetOfNode::Array: {
8928  Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8929  ExprResult Index = getDerived().TransformExpr(FromIndex);
8930  if (Index.isInvalid())
8931  return ExprError();
8932 
8933  ExprChanged = ExprChanged || Index.get() != FromIndex;
8934  Comp.isBrackets = true;
8935  Comp.U.E = Index.get();
8936  break;
8937  }
8938 
8939  case OffsetOfNode::Field:
8941  Comp.isBrackets = false;
8942  Comp.U.IdentInfo = ON.getFieldName();
8943  if (!Comp.U.IdentInfo)
8944  continue;
8945 
8946  break;
8947 
8948  case OffsetOfNode::Base:
8949  // Will be recomputed during the rebuild.
8950  continue;
8951  }
8952 
8953  Components.push_back(Comp);
8954  }
8955 
8956  // If nothing changed, retain the existing expression.
8957  if (!getDerived().AlwaysRebuild() &&
8958  Type == E->getTypeSourceInfo() &&
8959  !ExprChanged)
8960  return E;
8961 
8962  // Build a new offsetof expression.
8963  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8964  Components, E->getRParenLoc());
8965 }
8966 
8967 template<typename Derived>
8968 ExprResult
8969 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8970  assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8971  "opaque value expression requires transformation");
8972  return E;
8973 }
8974 
8975 template<typename Derived>
8976 ExprResult
8977 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8978  return E;
8979 }
8980 
8981 template<typename Derived>
8982 ExprResult
8983 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8984  // Rebuild the syntactic form. The original syntactic form has
8985  // opaque-value expressions in it, so strip those away and rebuild
8986  // the result. This is a really awful way of doing this, but the
8987  // better solution (rebuilding the semantic expressions and
8988  // rebinding OVEs as necessary) doesn't work; we'd need
8989  // TreeTransform to not strip away implicit conversions.
8990  Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8991  ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8992  if (result.isInvalid()) return ExprError();
8993 
8994  // If that gives us a pseudo-object result back, the pseudo-object
8995  // expression must have been an lvalue-to-rvalue conversion which we
8996  // should reapply.
8997  if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8998  result = SemaRef.checkPseudoObjectRValue(result.get());
8999 
9000  return result;
9001 }
9002 
9003 template<typename Derived>
9004 ExprResult
9005 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9006  UnaryExprOrTypeTraitExpr *E) {
9007  if (E->isArgumentType()) {
9008  TypeSourceInfo *OldT = E->getArgumentTypeInfo();
9009 
9010  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9011  if (!NewT)
9012  return ExprError();
9013 
9014  if (!getDerived().AlwaysRebuild() && OldT == NewT)
9015  return E;
9016 
9017  return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9018  E->getKind(),
9019  E->getSourceRange());
9020  }
9021 
9022  // C++0x [expr.sizeof]p1:
9023  // The operand is either an expression, which is an unevaluated operand
9024  // [...]
9025  EnterExpressionEvaluationContext Unevaluated(
9028 
9029  // Try to recover if we have something like sizeof(T::X) where X is a type.
9030  // Notably, there must be *exactly* one set of parens if X is a type.
9031  TypeSourceInfo *RecoveryTSI = nullptr;
9032  ExprResult SubExpr;
9033  auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9034  if (auto *DRE =
9035  PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9036  SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9037  PE, DRE, false, &RecoveryTSI);
9038  else
9039  SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9040 
9041  if (RecoveryTSI) {
9042  return getDerived().RebuildUnaryExprOrTypeTrait(
9043  RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9044  } else if (SubExpr.isInvalid())
9045  return ExprError();
9046 
9047  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
9048  return E;
9049 
9050  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9051  E->getOperatorLoc(),
9052  E->getKind(),
9053  E->getSourceRange());
9054 }
9055 
9056 template<typename Derived>
9057 ExprResult
9058 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
9059  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9060  if (LHS.isInvalid())
9061  return ExprError();
9062 
9063  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9064  if (RHS.isInvalid())
9065  return ExprError();
9066 
9067 
9068  if (!getDerived().AlwaysRebuild() &&
9069  LHS.get() == E->getLHS() &&
9070  RHS.get() == E->getRHS())
9071  return E;
9072 
9073  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
9074  /*FIXME:*/E->getLHS()->getLocStart(),
9075  RHS.get(),
9076  E->getRBracketLoc());
9077 }
9078 
9079 template <typename Derived>
9080 ExprResult
9081 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9082  ExprResult Base = getDerived().TransformExpr(E->getBase());
9083  if (Base.isInvalid())
9084  return ExprError();
9085 
9086  ExprResult LowerBound;
9087  if (E->getLowerBound()) {
9088  LowerBound = getDerived().TransformExpr(E->getLowerBound());
9089  if (LowerBound.isInvalid())
9090  return ExprError();
9091  }
9092 
9094  if (E->getLength()) {
9095  Length = getDerived().TransformExpr(E->getLength());
9096  if (Length.isInvalid())
9097  return ExprError();
9098  }
9099 
9100  if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9101  LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9102  return E;
9103 
9104  return getDerived().RebuildOMPArraySectionExpr(
9105  Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9106  Length.get(), E->getRBracketLoc());
9107 }
9108 
9109 template<typename Derived>
9110 ExprResult
9111 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
9112  // Transform the callee.
9113  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9114  if (Callee.isInvalid())
9115  return ExprError();
9116 
9117  // Transform arguments.
9118  bool ArgChanged = false;
9119  SmallVector<Expr*, 8> Args;
9120  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9121  &ArgChanged))
9122  return ExprError();
9123 
9124  if (!getDerived().AlwaysRebuild() &&
9125  Callee.get() == E->getCallee() &&
9126  !ArgChanged)
9127  return SemaRef.MaybeBindToTemporary(E);
9128 
9129  // FIXME: Wrong source location information for the '('.
9130  SourceLocation FakeLParenLoc
9131  = ((Expr *)Callee.get())->getSourceRange().getBegin();
9132  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9133  Args,
9134  E->getRParenLoc());
9135 }
9136 
9137 template<typename Derived>
9138 ExprResult
9139 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
9140  ExprResult Base = getDerived().TransformExpr(E->getBase());
9141  if (Base.isInvalid())
9142  return ExprError();
9143 
9144  NestedNameSpecifierLoc QualifierLoc;
9145  if (E->hasQualifier()) {
9146  QualifierLoc
9147  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9148 
9149  if (!QualifierLoc)
9150  return ExprError();
9151  }
9152  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9153 
9154  ValueDecl *Member
9155  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9156  E->getMemberDecl()));
9157  if (!Member)
9158  return ExprError();
9159 
9160  NamedDecl *FoundDecl = E->getFoundDecl();
9161  if (FoundDecl == E->getMemberDecl()) {
9162  FoundDecl = Member;
9163  } else {
9164  FoundDecl = cast_or_null<NamedDecl>(
9165  getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9166  if (!FoundDecl)
9167  return ExprError();
9168  }
9169 
9170  if (!getDerived().AlwaysRebuild() &&
9171  Base.get() == E->getBase() &&
9172  QualifierLoc == E->getQualifierLoc() &&
9173  Member == E->getMemberDecl() &&
9174  FoundDecl == E->getFoundDecl() &&
9175  !E->hasExplicitTemplateArgs()) {
9176 
9177  // Mark it referenced in the new context regardless.
9178  // FIXME: this is a bit instantiation-specific.
9179  SemaRef.MarkMemberReferenced(E);
9180 
9181  return E;
9182  }
9183 
9184  TemplateArgumentListInfo TransArgs;
9185  if (E->hasExplicitTemplateArgs()) {
9186  TransArgs.setLAngleLoc(E->getLAngleLoc());
9187  TransArgs.setRAngleLoc(E->getRAngleLoc());
9188  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9189  E->getNumTemplateArgs(),
9190  TransArgs))
9191  return ExprError();
9192  }
9193 
9194  // FIXME: Bogus source location for the operator
9195  SourceLocation FakeOperatorLoc =
9196  SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
9197 
9198  // FIXME: to do this check properly, we will need to preserve the
9199  // first-qualifier-in-scope here, just in case we had a dependent
9200  // base (and therefore couldn't do the check) and a
9201  // nested-name-qualifier (and therefore could do the lookup).
9202  NamedDecl *FirstQualifierInScope = nullptr;
9203  DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9204  if (MemberNameInfo.getName()) {
9205  MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9206  if (!MemberNameInfo.getName())
9207  return ExprError();
9208  }
9209 
9210  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
9211  E->isArrow(),
9212  QualifierLoc,
9213  TemplateKWLoc,
9214  MemberNameInfo,
9215  Member,
9216  FoundDecl,
9217  (E->hasExplicitTemplateArgs()
9218  ? &TransArgs : nullptr),
9219  FirstQualifierInScope);
9220 }
9221 
9222 template<typename Derived>
9223 ExprResult
9224 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
9225  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9226  if (LHS.isInvalid())
9227  return ExprError();
9228 
9229  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9230  if (RHS.isInvalid())
9231  return ExprError();
9232 
9233  if (!getDerived().AlwaysRebuild() &&
9234  LHS.get() == E->getLHS() &&
9235  RHS.get() == E->getRHS())
9236  return E;
9237 
9238  Sema::FPContractStateRAII FPContractState(getSema());
9239  getSema().FPFeatures = E->getFPFeatures();
9240 
9241  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
9242  LHS.get(), RHS.get());
9243 }
9244 
9245 template<typename Derived>
9246 ExprResult
9247 TreeTransform<Derived>::TransformCompoundAssignOperator(
9248  CompoundAssignOperator *E) {
9249  return getDerived().TransformBinaryOperator(E);
9250 }
9251 
9252 template<typename Derived>
9253 ExprResult TreeTransform<Derived>::
9254 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9255  // Just rebuild the common and RHS expressions and see whether we
9256  // get any changes.
9257 
9258  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9259  if (commonExpr.isInvalid())
9260  return ExprError();
9261 
9262  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9263  if (rhs.isInvalid())
9264  return ExprError();
9265 
9266  if (!getDerived().AlwaysRebuild() &&
9267  commonExpr.get() == e->getCommon() &&
9268  rhs.get() == e->getFalseExpr())
9269  return e;
9270 
9271  return getDerived().RebuildConditionalOperator(commonExpr.get(),
9272  e->getQuestionLoc(),
9273  nullptr,
9274  e->getColonLoc(),
9275  rhs.get());
9276 }
9277 
9278 template<typename Derived>
9279 ExprResult
9280 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
9281  ExprResult Cond = getDerived().TransformExpr(E->getCond());
9282  if (Cond.isInvalid())
9283  return ExprError();
9284 
9285  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9286  if (LHS.isInvalid())
9287  return ExprError();
9288 
9289  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9290  if (RHS.isInvalid())
9291  return ExprError();
9292 
9293  if (!getDerived().AlwaysRebuild() &&
9294  Cond.get() == E->getCond() &&
9295  LHS.get() == E->getLHS() &&
9296  RHS.get() == E->getRHS())
9297  return E;
9298 
9299  return getDerived().RebuildConditionalOperator(Cond.get(),
9300  E->getQuestionLoc(),
9301  LHS.get(),
9302  E->getColonLoc(),
9303  RHS.get());
9304 }
9305 
9306 template<typename Derived>
9307 ExprResult
9308 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
9309  // Implicit casts are eliminated during transformation, since they
9310  // will be recomputed by semantic analysis after transformation.
9311  return getDerived().TransformExpr(E->getSubExprAsWritten());
9312 }
9313 
9314 template<typename Derived>
9315 ExprResult
9316 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
9317  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9318  if (!Type)
9319  return ExprError();
9320 
9321  ExprResult SubExpr
9322  = getDerived().TransformExpr(E->getSubExprAsWritten());
9323  if (SubExpr.isInvalid())
9324  return ExprError();
9325 
9326  if (!getDerived().AlwaysRebuild() &&
9327  Type == E->getTypeInfoAsWritten() &&
9328  SubExpr.get() == E->getSubExpr())
9329  return E;
9330 
9331  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
9332  Type,
9333  E->getRParenLoc(),
9334  SubExpr.get());
9335 }
9336 
9337 template<typename Derived>
9338 ExprResult
9339 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
9340  TypeSourceInfo *OldT = E->getTypeSourceInfo();
9341  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9342  if (!NewT)
9343  return ExprError();
9344 
9345  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
9346  if (Init.isInvalid())
9347  return ExprError();
9348 
9349  if (!getDerived().AlwaysRebuild() &&
9350  OldT == NewT &&
9351  Init.get() == E->getInitializer())
9352  return SemaRef.MaybeBindToTemporary(E);
9353 
9354  // Note: the expression type doesn't necessarily match the
9355  // type-as-written, but that's okay, because it should always be
9356  // derivable from the initializer.
9357 
9358  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
9359  /*FIXME:*/E->getInitializer()->getLocEnd(),
9360  Init.get());
9361 }
9362 
9363 template<typename Derived>
9364 ExprResult
9365 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
9366  ExprResult Base = getDerived().TransformExpr(E->getBase());
9367  if (Base.isInvalid())
9368  return ExprError();
9369 
9370  if (!getDerived().AlwaysRebuild() &&
9371  Base.get() == E->getBase())
9372  return E;
9373 
9374  // FIXME: Bad source location
9375  SourceLocation FakeOperatorLoc =
9376  SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
9377  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
9378  E->getAccessorLoc(),
9379  E->getAccessor());
9380 }
9381 
9382 template<typename Derived>
9383 ExprResult
9384 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
9385  if (InitListExpr *Syntactic = E->getSyntacticForm())
9386  E = Syntactic;
9387 
9388  bool InitChanged = false;
9389 
9390  SmallVector<Expr*, 4> Inits;
9391  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
9392  Inits, &InitChanged))
9393  return ExprError();
9394 
9395  if (!getDerived().AlwaysRebuild() && !InitChanged) {
9396  // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9397  // in some cases. We can't reuse it in general, because the syntactic and
9398  // semantic forms are linked, and we can't know that semantic form will
9399  // match even if the syntactic form does.
9400  }
9401 
9402  return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
9403  E->getRBraceLoc(), E->getType());
9404 }
9405 
9406 template<typename Derived>
9407 ExprResult
9408 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
9409  Designation Desig;
9410 
9411  // transform the initializer value
9412  ExprResult Init = getDerived().TransformExpr(E->getInit());
9413  if (Init.isInvalid())
9414  return ExprError();
9415 
9416  // transform the designators.
9417  SmallVector<Expr*, 4> ArrayExprs;
9418  bool ExprChanged = false;
9419  for (const DesignatedInitExpr::Designator &D : E->designators()) {
9420  if (D.isFieldDesignator()) {
9421  Desig.AddDesignator(Designator::getField(D.getFieldName(),
9422  D.getDotLoc(),
9423  D.getFieldLoc()));
9424  if (D.getField()) {
9425  FieldDecl *Field = cast_or_null<FieldDecl>(
9426  getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9427  if (Field != D.getField())
9428  // Rebuild the expression when the transformed FieldDecl is
9429  // different to the already assigned FieldDecl.
9430  ExprChanged = true;
9431  } else {
9432  // Ensure that the designator expression is rebuilt when there isn't
9433  // a resolved FieldDecl in the designator as we don't want to assign
9434  // a FieldDecl to a pattern designator that will be instantiated again.
9435  ExprChanged = true;
9436  }
9437  continue;
9438  }
9439 
9440  if (D.isArrayDesignator()) {
9441  ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
9442  if (Index.isInvalid())
9443  return ExprError();
9444 
9445  Desig.AddDesignator(
9446  Designator::getArray(Index.get(), D.getLBracketLoc()));
9447 
9448  ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
9449  ArrayExprs.push_back(Index.get());
9450  continue;
9451  }
9452 
9453  assert(D.isArrayRangeDesignator() && "New kind of designator?");
9454  ExprResult Start
9455  = getDerived().TransformExpr(E->getArrayRangeStart(D));
9456  if (Start.isInvalid())
9457  return ExprError();
9458 
9459  ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
9460  if (End.isInvalid())
9461  return ExprError();
9462 
9463  Desig.AddDesignator(Designator::getArrayRange(Start.get(),
9464  End.get(),
9465  D.getLBracketLoc(),
9466  D.getEllipsisLoc()));
9467 
9468  ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9469  End.get() != E->getArrayRangeEnd(D);
9470 
9471  ArrayExprs.push_back(Start.get());
9472  ArrayExprs.push_back(End.get());
9473  }
9474 
9475  if (!getDerived().AlwaysRebuild() &&
9476  Init.get() == E->getInit() &&
9477  !ExprChanged)
9478  return E;
9479 
9480  return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
9481  E->getEqualOrColonLoc(),
9482  E->usesGNUSyntax(), Init.get());
9483 }
9484 
9485 // Seems that if TransformInitListExpr() only works on the syntactic form of an
9486 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9487 template<typename Derived>
9488 ExprResult
9489 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9490  DesignatedInitUpdateExpr *E) {
9491  llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9492  "initializer");
9493  return ExprError();
9494 }
9495 
9496 template<typename Derived>
9497 ExprResult
9498 TreeTransform<Derived>::TransformNoInitExpr(
9499  NoInitExpr *E) {
9500  llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9501  return ExprError();
9502 }
9503 
9504 template<typename Derived>
9505 ExprResult
9506 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9507  llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9508  return ExprError();
9509 }
9510 
9511 template<typename Derived>
9512 ExprResult
9513 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9514  llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9515  return ExprError();
9516 }
9517 
9518 template<typename Derived>
9519 ExprResult
9520 TreeTransform<Derived>::TransformImplicitValueInitExpr(
9521  ImplicitValueInitExpr *E) {
9522  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
9523 
9524  // FIXME: Will we ever have proper type location here? Will we actually
9525  // need to transform the type?
9526  QualType T = getDerived().TransformType(E->getType());
9527  if (T.isNull())
9528  return ExprError();
9529 
9530  if (!getDerived().AlwaysRebuild() &&
9531  T == E->getType())
9532  return E;
9533 
9534  return getDerived().RebuildImplicitValueInitExpr(T);
9535 }
9536 
9537 template<typename Derived>
9538 ExprResult
9539 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
9540  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9541  if (!TInfo)
9542  return ExprError();
9543 
9544  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9545  if (SubExpr.isInvalid())
9546  return ExprError();
9547 
9548  if (!getDerived().AlwaysRebuild() &&
9549  TInfo == E->getWrittenTypeInfo() &&
9550  SubExpr.get() == E->getSubExpr())
9551  return E;
9552 
9553  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
9554  TInfo, E->getRParenLoc());
9555 }
9556 
9557 template<typename Derived>
9558 ExprResult
9559 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
9560  bool ArgumentChanged = false;
9561  SmallVector<Expr*, 4> Inits;
9562  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9563  &ArgumentChanged))
9564  return ExprError();
9565 
9566  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
9567  Inits,
9568  E->getRParenLoc());
9569 }
9570 
9571 /// \brief Transform an address-of-label expression.
9572 ///
9573 /// By default, the transformation of an address-of-label expression always
9574 /// rebuilds the expression, so that the label identifier can be resolved to
9575 /// the corresponding label statement by semantic analysis.
9576 template<typename Derived>
9577 ExprResult
9578 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
9579  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9580  E->getLabel());
9581  if (!LD)
9582  return ExprError();
9583 
9584  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9585  cast<LabelDecl>(LD));
9586 }
9587 
9588 template<typename Derived>
9589 ExprResult
9590 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9591  SemaRef.ActOnStartStmtExpr();
9592  StmtResult SubStmt
9593  = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9594  if (SubStmt.isInvalid()) {
9595  SemaRef.ActOnStmtExprError();
9596  return ExprError();
9597  }
9598 
9599  if (!getDerived().AlwaysRebuild() &&
9600  SubStmt.get() == E->getSubStmt()) {
9601  // Calling this an 'error' is unintuitive, but it does the right thing.
9602  SemaRef.ActOnStmtExprError();
9603  return SemaRef.MaybeBindToTemporary(E);
9604  }
9605 
9606  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9607  SubStmt.get(),
9608  E->getRParenLoc());
9609 }
9610 
9611 template<typename Derived>
9612 ExprResult
9613 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9614  ExprResult Cond = getDerived().TransformExpr(E->getCond());
9615  if (Cond.isInvalid())
9616  return ExprError();
9617 
9618  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9619  if (LHS.isInvalid())
9620  return ExprError();
9621 
9622  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9623  if (RHS.isInvalid())
9624  return ExprError();
9625 
9626  if (!getDerived().AlwaysRebuild() &&
9627  Cond.get() == E->getCond() &&
9628  LHS.get() == E->getLHS() &&
9629  RHS.get() == E->getRHS())
9630  return E;
9631 
9632  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9633  Cond.get(), LHS.get(), RHS.get(),
9634  E->getRParenLoc());
9635 }
9636 
9637 template<typename Derived>
9638 ExprResult
9639 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9640  return E;
9641 }
9642 
9643 template<typename Derived>
9644 ExprResult
9645 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9646  switch (E->getOperator()) {
9647  case OO_New:
9648  case OO_Delete:
9649  case OO_Array_New:
9650  case OO_Array_Delete:
9651  llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9652 
9653  case OO_Call: {
9654  // This is a call to an object's operator().
9655  assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9656 
9657  // Transform the object itself.
9658  ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9659  if (Object.isInvalid())
9660  return ExprError();
9661 
9662  // FIXME: Poor location information
9663  SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9664  static_cast<Expr *>(Object.get())->getLocEnd());
9665 
9666  // Transform the call arguments.
9667  SmallVector<Expr*, 8> Args;
9668  if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9669  Args))
9670  return ExprError();
9671 
9672  return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9673  Args,
9674  E->getLocEnd());
9675  }
9676 
9677 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9678  case OO_##Name:
9679 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9680 #include "clang/Basic/OperatorKinds.def"
9681  case OO_Subscript:
9682  // Handled below.
9683  break;
9684 
9685  case OO_Conditional:
9686  llvm_unreachable("conditional operator is not actually overloadable");
9687 
9688  case OO_None:
9690  llvm_unreachable("not an overloaded operator?");
9691  }
9692 
9693  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9694  if (Callee.isInvalid())
9695  return ExprError();
9696 
9697  ExprResult First;
9698  if (E->getOperator() == OO_Amp)
9699  First = getDerived().TransformAddressOfOperand(E->getArg(0));
9700  else
9701  First = getDerived().TransformExpr(E->getArg(0));
9702  if (First.isInvalid())
9703  return ExprError();
9704 
9705  ExprResult Second;
9706  if (E->getNumArgs() == 2) {
9707  Second = getDerived().TransformExpr(E->getArg(1));
9708  if (Second.isInvalid())
9709  return ExprError();
9710  }
9711 
9712  if (!getDerived().AlwaysRebuild() &&
9713  Callee.get() == E->getCallee() &&
9714  First.get() == E->getArg(0) &&
9715  (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9716  return SemaRef.MaybeBindToTemporary(E);
9717 
9718  Sema::FPContractStateRAII FPContractState(getSema());
9719  getSema().FPFeatures = E->getFPFeatures();
9720 
9721  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9722  E->getOperatorLoc(),
9723  Callee.get(),
9724  First.get(),
9725  Second.get());
9726 }
9727 
9728 template<typename Derived>
9729 ExprResult
9730 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9731  return getDerived().TransformCallExpr(E);
9732 }
9733 
9734 template<typename Derived>
9735 ExprResult
9736 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9737  // Transform the callee.
9738  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9739  if (Callee.isInvalid())
9740  return ExprError();
9741 
9742  // Transform exec config.
9743  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9744  if (EC.isInvalid())
9745  return ExprError();
9746 
9747  // Transform arguments.
9748  bool ArgChanged = false;
9749  SmallVector<Expr*, 8> Args;
9750  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9751  &ArgChanged))
9752  return ExprError();
9753 
9754  if (!getDerived().AlwaysRebuild() &&
9755  Callee.get() == E->getCallee() &&
9756  !ArgChanged)
9757  return SemaRef.MaybeBindToTemporary(E);
9758 
9759  // FIXME: Wrong source location information for the '('.
9760  SourceLocation FakeLParenLoc
9761  = ((Expr *)Callee.get())->getSourceRange().getBegin();
9762  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9763  Args,
9764  E->getRParenLoc(), EC.get());
9765 }
9766 
9767 template<typename Derived>
9768 ExprResult
9770  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9771  if (!Type)
9772  return ExprError();
9773 
9774  ExprResult SubExpr
9775  = getDerived().TransformExpr(E->getSubExprAsWritten());
9776  if (SubExpr.isInvalid())
9777  return ExprError();
9778 
9779  if (!getDerived().AlwaysRebuild() &&
9780  Type == E->getTypeInfoAsWritten() &&
9781  SubExpr.get() == E->getSubExpr())
9782  return E;
9783  return getDerived().RebuildCXXNamedCastExpr(
9785  Type, E->getAngleBrackets().getEnd(),
9786  // FIXME. this should be '(' location
9787  E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9788 }
9789 
9790 template<typename Derived>
9791 ExprResult
9793  return getDerived().TransformCXXNamedCastExpr(E);
9794 }
9795 
9796 template<typename Derived>
9797 ExprResult
9798 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9799  return getDerived().TransformCXXNamedCastExpr(E);
9800 }
9801 
9802 template<typename Derived>
9803 ExprResult
9804 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9805  CXXReinterpretCastExpr *E) {
9806  return getDerived().TransformCXXNamedCastExpr(E);
9807 }
9808 
9809 template<typename Derived>
9810 ExprResult
9811 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9812  return getDerived().TransformCXXNamedCastExpr(E);
9813 }
9814 
9815 template<typename Derived>
9816 ExprResult
9817 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9818  CXXFunctionalCastExpr *E) {
9819  TypeSourceInfo *Type =
9820  getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
9821  if (!Type)
9822  return ExprError();
9823 
9824  ExprResult SubExpr
9825  = getDerived().TransformExpr(E->getSubExprAsWritten());
9826  if (SubExpr.isInvalid())
9827  return ExprError();
9828 
9829  if (!getDerived().AlwaysRebuild() &&
9830  Type == E->getTypeInfoAsWritten() &&
9831  SubExpr.get() == E->getSubExpr())
9832  return E;
9833 
9834  return getDerived().RebuildCXXFunctionalCastExpr(Type,
9835  E->getLParenLoc(),
9836  SubExpr.get(),
9837  E->getRParenLoc());
9838 }
9839 
9840 template<typename Derived>
9841 ExprResult
9842 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9843  if (E->isTypeOperand()) {
9844  TypeSourceInfo *TInfo
9845  = getDerived().TransformType(E->getTypeOperandSourceInfo());
9846  if (!TInfo)
9847  return ExprError();
9848 
9849  if (!getDerived().AlwaysRebuild() &&
9850  TInfo == E->getTypeOperandSourceInfo())
9851  return E;
9852 
9853  return getDerived().RebuildCXXTypeidExpr(E->getType(),
9854  E->getLocStart(),
9855  TInfo,
9856  E->getLocEnd());
9857  }
9858 
9859  // We don't know whether the subexpression is potentially evaluated until
9860  // after we perform semantic analysis. We speculatively assume it is
9861  // unevaluated; it will get fixed later if the subexpression is in fact
9862  // potentially evaluated.
9863  EnterExpressionEvaluationContext Unevaluated(
9866 
9867  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9868  if (SubExpr.isInvalid())
9869  return ExprError();
9870 
9871  if (!getDerived().AlwaysRebuild() &&
9872  SubExpr.get() == E->getExprOperand())
9873  return E;
9874 
9875  return getDerived().RebuildCXXTypeidExpr(E->getType(),
9876  E->getLocStart(),
9877  SubExpr.get(),
9878  E->getLocEnd());
9879 }
9880 
9881 template<typename Derived>
9882 ExprResult
9883 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9884  if (E->isTypeOperand()) {
9885  TypeSourceInfo *TInfo
9886  = getDerived().TransformType(E->getTypeOperandSourceInfo());
9887  if (!TInfo)
9888  return ExprError();
9889 
9890  if (!getDerived().AlwaysRebuild() &&
9891  TInfo == E->getTypeOperandSourceInfo())
9892  return E;
9893 
9894  return getDerived().RebuildCXXUuidofExpr(E->getType(),
9895  E->getLocStart(),
9896  TInfo,
9897  E->getLocEnd());
9898  }
9899 
9900  EnterExpressionEvaluationContext Unevaluated(
9902 
9903  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9904  if (SubExpr.isInvalid())
9905  return ExprError();
9906 
9907  if (!getDerived().AlwaysRebuild() &&
9908  SubExpr.get() == E->getExprOperand())
9909  return E;
9910 
9911  return getDerived().RebuildCXXUuidofExpr(E->getType(),
9912  E->getLocStart(),
9913  SubExpr.get(),
9914  E->getLocEnd());
9915 }
9916 
9917 template<typename Derived>
9918 ExprResult
9919 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9920  return E;
9921 }
9922 
9923 template<typename Derived>
9924 ExprResult
9925 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9926  CXXNullPtrLiteralExpr *E) {
9927  return E;
9928 }
9929 
9930 template<typename Derived>
9931 ExprResult
9932 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9933  QualType T = getSema().getCurrentThisType();
9934 
9935  if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9936  // Make sure that we capture 'this'.
9937  getSema().CheckCXXThisCapture(E->getLocStart());
9938  return E;
9939  }
9940 
9941  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9942 }
9943 
9944 template<typename Derived>
9945 ExprResult
9946 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9947  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9948  if (SubExpr.isInvalid())
9949  return ExprError();
9950 
9951  if (!getDerived().AlwaysRebuild() &&
9952  SubExpr.get() == E->getSubExpr())
9953  return E;
9954 
9955  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9956  E->isThrownVariableInScope());
9957 }
9958 
9959 template<typename Derived>
9960 ExprResult
9961 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9962  ParmVarDecl *Param
9963  = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9964  E->getParam()));
9965  if (!Param)
9966  return ExprError();
9967 
9968  if (!getDerived().AlwaysRebuild() &&
9969  Param == E->getParam())
9970  return E;
9971 
9972  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9973 }
9974 
9975 template<typename Derived>
9976 ExprResult
9977 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9978  FieldDecl *Field
9979  = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9980  E->getField()));
9981  if (!Field)
9982  return ExprError();
9983 
9984  if (!getDerived().AlwaysRebuild() && Field == E->getField())
9985  return E;
9986 
9987  return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9988 }
9989 
9990 template<typename Derived>
9991 ExprResult
9992 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9993  CXXScalarValueInitExpr *E) {
9994  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9995  if (!T)
9996  return ExprError();
9997 
9998  if (!getDerived().AlwaysRebuild() &&
9999  T == E->getTypeSourceInfo())
10000  return E;
10001 
10002  return getDerived().RebuildCXXScalarValueInitExpr(T,
10003  /*FIXME:*/T->getTypeLoc().getEndLoc(),
10004  E->getRParenLoc());
10005 }
10006 
10007 template<typename Derived>
10008 ExprResult
10009 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
10010  // Transform the type that we're allocating
10011  TypeSourceInfo *AllocTypeInfo =
10012  getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
10013  if (!AllocTypeInfo)
10014  return ExprError();
10015 
10016  // Transform the size of the array we're allocating (if any).
10017  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
10018  if (ArraySize.isInvalid())
10019  return ExprError();
10020 
10021  // Transform the placement arguments (if any).
10022  bool ArgumentChanged = false;
10023  SmallVector<Expr*, 8> PlacementArgs;
10024  if (getDerived().TransformExprs(E->getPlacementArgs(),
10025  E->getNumPlacementArgs(), true,
10026  PlacementArgs, &ArgumentChanged))
10027  return ExprError();
10028 
10029  // Transform the initializer (if any).
10030  Expr *OldInit = E->getInitializer();
10031  ExprResult NewInit;
10032  if (OldInit)
10033  NewInit = getDerived().TransformInitializer(OldInit, true);
10034  if (NewInit.isInvalid())
10035  return ExprError();
10036 
10037  // Transform new operator and delete operator.
10038  FunctionDecl *OperatorNew = nullptr;
10039  if (E->getOperatorNew()) {
10040  OperatorNew = cast_or_null<FunctionDecl>(
10041  getDerived().TransformDecl(E->getLocStart(),
10042  E->getOperatorNew()));
10043  if (!OperatorNew)
10044  return ExprError();
10045  }
10046 
10047  FunctionDecl *OperatorDelete = nullptr;
10048  if (E->getOperatorDelete()) {
10049  OperatorDelete = cast_or_null<FunctionDecl>(
10050  getDerived().TransformDecl(E->getLocStart(),
10051  E->getOperatorDelete()));
10052  if (!OperatorDelete)
10053  return ExprError();
10054  }
10055 
10056  if (!getDerived().AlwaysRebuild() &&
10057  AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
10058  ArraySize.get() == E->getArraySize() &&
10059  NewInit.get() == OldInit &&
10060  OperatorNew == E->getOperatorNew() &&
10061  OperatorDelete == E->getOperatorDelete() &&
10062  !ArgumentChanged) {
10063  // Mark any declarations we need as referenced.
10064  // FIXME: instantiation-specific.
10065  if (OperatorNew)
10066  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
10067  if (OperatorDelete)
10068  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10069 
10070  if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
10071  QualType ElementType
10072  = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10073  if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10074  CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10075  if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
10076  SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
10077  }
10078  }
10079  }
10080 
10081  return E;
10082  }
10083 
10084  QualType AllocType = AllocTypeInfo->getType();
10085  if (!ArraySize.get()) {
10086  // If no array size was specified, but the new expression was
10087  // instantiated with an array type (e.g., "new T" where T is
10088  // instantiated with "int[4]"), extract the outer bound from the
10089  // array type as our array size. We do this with constant and
10090  // dependently-sized array types.
10091  const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10092  if (!ArrayT) {
10093  // Do nothing
10094  } else if (const ConstantArrayType *ConsArrayT
10095  = dyn_cast<ConstantArrayType>(ArrayT)) {
10096  ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10097  SemaRef.Context.getSizeType(),
10098  /*FIXME:*/ E->getLocStart());
10099  AllocType = ConsArrayT->getElementType();
10100  } else if (const DependentSizedArrayType *DepArrayT
10101  = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10102  if (DepArrayT->getSizeExpr()) {
10103  ArraySize = DepArrayT->getSizeExpr();
10104  AllocType = DepArrayT->getElementType();
10105  }
10106  }
10107  }
10108 
10109  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10110  E->isGlobalNew(),
10111  /*FIXME:*/E->getLocStart(),
10112  PlacementArgs,
10113  /*FIXME:*/E->getLocStart(),
10114  E->getTypeIdParens(),
10115  AllocType,
10116  AllocTypeInfo,
10117  ArraySize.get(),
10118  E->getDirectInitRange(),
10119  NewInit.get());
10120 }
10121 
10122 template<typename Derived>
10123 ExprResult
10124 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
10125  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
10126  if (Operand.isInvalid())
10127  return ExprError();
10128 
10129  // Transform the delete operator, if known.
10130  FunctionDecl *OperatorDelete = nullptr;
10131  if (E->getOperatorDelete()) {
10132  OperatorDelete = cast_or_null<FunctionDecl>(
10133  getDerived().TransformDecl(E->getLocStart(),
10134  E->getOperatorDelete()));
10135  if (!OperatorDelete)
10136  return ExprError();
10137  }
10138 
10139  if (!getDerived().AlwaysRebuild() &&
10140  Operand.get() == E->getArgument() &&
10141  OperatorDelete == E->getOperatorDelete()) {
10142  // Mark any declarations we need as referenced.
10143  // FIXME: instantiation-specific.
10144  if (OperatorDelete)
10145  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
10146 
10147  if (!E->getArgument()->isTypeDependent()) {
10148  QualType Destroyed = SemaRef.Context.getBaseElementType(
10149  E->getDestroyedType());
10150  if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10151  CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
10152  SemaRef.MarkFunctionReferenced(E->getLocStart(),
10153  SemaRef.LookupDestructor(Record));
10154  }
10155  }
10156 
10157  return E;
10158  }
10159 
10160  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10161  E->isGlobalDelete(),
10162  E->isArrayForm(),
10163  Operand.get());
10164 }
10165 
10166 template<typename Derived>
10167 ExprResult
10168 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
10169  CXXPseudoDestructorExpr *E) {
10170  ExprResult Base = getDerived().TransformExpr(E->getBase());
10171  if (Base.isInvalid())
10172  return ExprError();
10173 
10174  ParsedType ObjectTypePtr;
10175  bool MayBePseudoDestructor = false;
10176  Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10177  E->getOperatorLoc(),
10178  E->isArrow()? tok::arrow : tok::period,
10179  ObjectTypePtr,
10180  MayBePseudoDestructor);
10181  if (Base.isInvalid())
10182  return ExprError();
10183 
10184  QualType ObjectType = ObjectTypePtr.get();
10185  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10186  if (QualifierLoc) {
10187  QualifierLoc
10188  = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10189  if (!QualifierLoc)
10190  return ExprError();
10191  }
10192  CXXScopeSpec SS;
10193  SS.Adopt(QualifierLoc);
10194 
10195  PseudoDestructorTypeStorage Destroyed;
10196  if (E->getDestroyedTypeInfo()) {
10197  TypeSourceInfo *DestroyedTypeInfo
10198  = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
10199  ObjectType, nullptr, SS);
10200  if (!DestroyedTypeInfo)
10201  return ExprError();
10202  Destroyed = DestroyedTypeInfo;
10203  } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
10204  // We aren't likely to be able to resolve the identifier down to a type
10205  // now anyway, so just retain the identifier.
10206  Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10207  E->getDestroyedTypeLoc());
10208  } else {
10209  // Look for a destructor known with the given name.
10210  ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
10211  *E->getDestroyedTypeIdentifier(),
10212  E->getDestroyedTypeLoc(),
10213  /*Scope=*/nullptr,
10214  SS, ObjectTypePtr,
10215  false);
10216  if (!T)
10217  return ExprError();
10218 
10219  Destroyed
10220  = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10221  E->getDestroyedTypeLoc());
10222  }
10223 
10224  TypeSourceInfo *ScopeTypeInfo = nullptr;
10225  if (E->getScopeTypeInfo()) {
10226  CXXScopeSpec EmptySS;
10227  ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
10228  E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
10229  if (!ScopeTypeInfo)
10230  return ExprError();
10231  }
10232 
10233  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
10234  E->getOperatorLoc(),
10235  E->isArrow(),
10236  SS,
10237  ScopeTypeInfo,
10238  E->getColonColonLoc(),
10239  E->getTildeLoc(),
10240  Destroyed);
10241 }
10242 
10243 template <typename Derived>
10245  bool RequiresADL,
10246  LookupResult &R) {
10247  // Transform all the decls.
10248  bool AllEmptyPacks = true;
10249  for (auto *OldD : Old->decls()) {
10250  Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10251  if (!InstD) {
10252  // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10253  // This can happen because of dependent hiding.
10254  if (isa<UsingShadowDecl>(OldD))
10255  continue;
10256  else {
10257  R.clear();
10258  return true;
10259  }
10260  }
10261 
10262  // Expand using pack declarations.
10263  NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10264  ArrayRef<NamedDecl*> Decls = SingleDecl;
10265  if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10266  Decls = UPD->expansions();
10267 
10268  // Expand using declarations.
10269  for (auto *D : Decls) {
10270  if (auto *UD = dyn_cast<UsingDecl>(D)) {
10271  for (auto *SD : UD->shadows())
10272  R.addDecl(SD);
10273  } else {
10274  R.addDecl(D);
10275  }
10276  }
10277 
10278  AllEmptyPacks &= Decls.empty();
10279  };
10280 
10281  // C++ [temp.res]/8.4.2:
10282  // The program is ill-formed, no diagnostic required, if [...] lookup for
10283  // a name in the template definition found a using-declaration, but the
10284  // lookup in the corresponding scope in the instantiation odoes not find
10285  // any declarations because the using-declaration was a pack expansion and
10286  // the corresponding pack is empty
10287  if (AllEmptyPacks && !RequiresADL) {
10288  getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10289  << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10290  return true;
10291  }
10292 
10293  // Resolve a kind, but don't do any further analysis. If it's
10294  // ambiguous, the callee needs to deal with it.
10295  R.resolveKind();
10296  return false;
10297 }
10298 
10299 template<typename Derived>
10300 ExprResult
10302  UnresolvedLookupExpr *Old) {
10303  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10305 
10306  // Transform the declaration set.
10307  if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10308  return ExprError();
10309 
10310  // Rebuild the nested-name qualifier, if present.
10311  CXXScopeSpec SS;
10312  if (Old->getQualifierLoc()) {
10313  NestedNameSpecifierLoc QualifierLoc
10314  = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10315  if (!QualifierLoc)
10316  return ExprError();
10317 
10318  SS.Adopt(QualifierLoc);
10319  }
10320 
10321  if (Old->getNamingClass()) {
10322  CXXRecordDecl *NamingClass
10323  = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10324  Old->getNameLoc(),
10325  Old->getNamingClass()));
10326  if (!NamingClass) {
10327  R.clear();
10328  return ExprError();
10329  }
10330 
10331  R.setNamingClass(NamingClass);
10332  }
10333 
10334  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10335 
10336  // If we have neither explicit template arguments, nor the template keyword,
10337  // it's a normal declaration name or member reference.
10338  if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10339  NamedDecl *D = R.getAsSingle<NamedDecl>();
10340  // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10341  // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10342  // give a good diagnostic.
10343  if (D && D->isCXXInstanceMember()) {
10344  return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10345  /*TemplateArgs=*/nullptr,
10346  /*Scope=*/nullptr);
10347  }
10348 
10349  return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
10350  }
10351 
10352  // If we have template arguments, rebuild them, then rebuild the
10353  // templateid expression.
10354  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
10355  if (Old->hasExplicitTemplateArgs() &&
10356  getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10357  Old->getNumTemplateArgs(),
10358  TransArgs)) {
10359  R.clear();
10360  return ExprError();
10361  }
10362 
10363  return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
10364  Old->requiresADL(), &TransArgs);
10365 }
10366 
10367 template<typename Derived>
10368 ExprResult
10369 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10370  bool ArgChanged = false;
10371  SmallVector<TypeSourceInfo *, 4> Args;
10372  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10373  TypeSourceInfo *From = E->getArg(I);
10374  TypeLoc FromTL = From->getTypeLoc();
10375  if (!FromTL.getAs<PackExpansionTypeLoc>()) {
10376  TypeLocBuilder TLB;
10377  TLB.reserve(FromTL.getFullDataSize());
10378  QualType To = getDerived().TransformType(TLB, FromTL);
10379  if (To.isNull())
10380  return ExprError();
10381 
10382  if (To == From->getType())
10383  Args.push_back(From);
10384  else {
10385  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10386  ArgChanged = true;
10387  }
10388  continue;
10389  }
10390 
10391  ArgChanged = true;
10392 
10393  // We have a pack expansion. Instantiate it.
10394  PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
10395  TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10396  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10397  SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
10398 
10399  // Determine whether the set of unexpanded parameter packs can and should
10400  // be expanded.
10401  bool Expand = true;
10402  bool RetainExpansion = false;
10403  Optional<unsigned> OrigNumExpansions =
10404  ExpansionTL.getTypePtr()->getNumExpansions();
10405  Optional<unsigned> NumExpansions = OrigNumExpansions;
10406  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10407  PatternTL.getSourceRange(),
10408  Unexpanded,
10409  Expand, RetainExpansion,
10410  NumExpansions))
10411  return ExprError();
10412 
10413  if (!Expand) {
10414  // The transform has determined that we should perform a simple
10415  // transformation on the pack expansion, producing another pack
10416  // expansion.
10417  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10418 
10419  TypeLocBuilder TLB;
10420  TLB.reserve(From->getTypeLoc().getFullDataSize());
10421 
10422  QualType To = getDerived().TransformType(TLB, PatternTL);
10423  if (To.isNull())
10424  return ExprError();
10425 
10426  To = getDerived().RebuildPackExpansionType(To,
10427  PatternTL.getSourceRange(),
10428  ExpansionTL.getEllipsisLoc(),
10429  NumExpansions);
10430  if (To.isNull())
10431  return ExprError();
10432 
10433  PackExpansionTypeLoc ToExpansionTL
10434  = TLB.push<PackExpansionTypeLoc>(To);
10435  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10436  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10437  continue;
10438  }
10439 
10440  // Expand the pack expansion by substituting for each argument in the
10441  // pack(s).
10442  for (unsigned I = 0; I != *NumExpansions; ++I) {
10443  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10444  TypeLocBuilder TLB;
10445  TLB.reserve(PatternTL.getFullDataSize());
10446  QualType To = getDerived().TransformType(TLB, PatternTL);
10447  if (To.isNull())
10448  return ExprError();
10449 
10450  if (To->containsUnexpandedParameterPack()) {
10451  To = getDerived().RebuildPackExpansionType(To,
10452  PatternTL.getSourceRange(),
10453  ExpansionTL.getEllipsisLoc(),
10454  NumExpansions);
10455  if (To.isNull())
10456  return ExprError();
10457 
10458  PackExpansionTypeLoc ToExpansionTL
10459  = TLB.push<PackExpansionTypeLoc>(To);
10460  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10461  }
10462 
10463  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10464  }
10465 
10466  if (!RetainExpansion)
10467  continue;
10468 
10469  // If we're supposed to retain a pack expansion, do so by temporarily
10470  // forgetting the partially-substituted parameter pack.
10471  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10472 
10473  TypeLocBuilder TLB;
10474  TLB.reserve(From->getTypeLoc().getFullDataSize());
10475 
10476  QualType To = getDerived().TransformType(TLB, PatternTL);
10477  if (To.isNull())
10478  return ExprError();
10479 
10480  To = getDerived().RebuildPackExpansionType(To,
10481  PatternTL.getSourceRange(),
10482  ExpansionTL.getEllipsisLoc(),
10483  NumExpansions);
10484  if (To.isNull())
10485  return ExprError();
10486 
10487  PackExpansionTypeLoc ToExpansionTL
10488  = TLB.push<PackExpansionTypeLoc>(To);
10489  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10490  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10491  }
10492 
10493  if (!getDerived().AlwaysRebuild() && !ArgChanged)
10494  return E;
10495 
10496  return getDerived().RebuildTypeTrait(E->getTrait(),
10497  E->getLocStart(),
10498  Args,
10499  E->getLocEnd());
10500 }
10501 
10502 template<typename Derived>
10503 ExprResult
10504 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10505  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10506  if (!T)
10507  return ExprError();
10508 
10509  if (!getDerived().AlwaysRebuild() &&
10510  T == E->getQueriedTypeSourceInfo())
10511  return E;
10512 
10513  ExprResult SubExpr;
10514  {
10515  EnterExpressionEvaluationContext Unevaluated(
10517  SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10518  if (SubExpr.isInvalid())
10519  return ExprError();
10520 
10521  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
10522  return E;
10523  }
10524 
10525  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10526  E->getLocStart(),
10527  T,
10528  SubExpr.get(),
10529  E->getLocEnd());
10530 }
10531 
10532 template<typename Derived>
10533 ExprResult
10534 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10535  ExprResult SubExpr;
10536  {
10537  EnterExpressionEvaluationContext Unevaluated(
10539  SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10540  if (SubExpr.isInvalid())
10541  return ExprError();
10542 
10543  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
10544  return E;
10545  }
10546 
10547  return getDerived().RebuildExpressionTrait(
10548  E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10549 }
10550 
10551 template <typename Derived>
10553  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10554  TypeSourceInfo **RecoveryTSI) {
10555  ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10556  DRE, AddrTaken, RecoveryTSI);
10557 
10558  // Propagate both errors and recovered types, which return ExprEmpty.
10559  if (!NewDRE.isUsable())
10560  return NewDRE;
10561 
10562  // We got an expr, wrap it up in parens.
10563  if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10564  return PE;
10565  return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10566  PE->getRParen());
10567 }
10568 
10569 template <typename Derived>
10572  return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10573  nullptr);
10574 }
10575 
10576 template<typename Derived>
10577 ExprResult
10580  bool IsAddressOfOperand,
10581  TypeSourceInfo **RecoveryTSI) {
10582  assert(E->getQualifierLoc());
10583  NestedNameSpecifierLoc QualifierLoc
10584  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10585  if (!QualifierLoc)
10586  return ExprError();
10587  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10588 
10589  // TODO: If this is a conversion-function-id, verify that the
10590  // destination type name (if present) resolves the same way after
10591  // instantiation as it did in the local scope.
10592 
10593  DeclarationNameInfo NameInfo
10594  = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10595  if (!NameInfo.getName())
10596  return ExprError();
10597 
10598  if (!E->hasExplicitTemplateArgs()) {
10599  if (!getDerived().AlwaysRebuild() &&
10600  QualifierLoc == E->getQualifierLoc() &&
10601  // Note: it is sufficient to compare the Name component of NameInfo:
10602  // if name has not changed, DNLoc has not changed either.
10603  NameInfo.getName() == E->getDeclName())
10604  return E;
10605 
10606  return getDerived().RebuildDependentScopeDeclRefExpr(
10607  QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10608  IsAddressOfOperand, RecoveryTSI);
10609  }
10610 
10611  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10612  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10613  E->getNumTemplateArgs(),
10614  TransArgs))
10615  return ExprError();
10616 
10617  return getDerived().RebuildDependentScopeDeclRefExpr(
10618  QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10619  RecoveryTSI);
10620 }
10621 
10622 template<typename Derived>
10623 ExprResult
10624 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10625  // CXXConstructExprs other than for list-initialization and
10626  // CXXTemporaryObjectExpr are always implicit, so when we have
10627  // a 1-argument construction we just transform that argument.
10628  if ((E->getNumArgs() == 1 ||
10629  (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10630  (!getDerived().DropCallArgument(E->getArg(0))) &&
10631  !E->isListInitialization())
10632  return getDerived().TransformExpr(E->getArg(0));
10633 
10634  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10635 
10636  QualType T = getDerived().TransformType(E->getType());
10637  if (T.isNull())
10638  return ExprError();
10639 
10640  CXXConstructorDecl *Constructor
10641  = cast_or_null<CXXConstructorDecl>(
10642  getDerived().TransformDecl(E->getLocStart(),
10643  E->getConstructor()));
10644  if (!Constructor)
10645  return ExprError();
10646 
10647  bool ArgumentChanged = false;
10648  SmallVector<Expr*, 8> Args;
10649  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10650  &ArgumentChanged))
10651  return ExprError();
10652 
10653  if (!getDerived().AlwaysRebuild() &&
10654  T == E->getType() &&
10655  Constructor == E->getConstructor() &&
10656  !ArgumentChanged) {
10657  // Mark the constructor as referenced.
10658  // FIXME: Instantiation-specific
10659  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10660  return E;
10661  }
10662 
10663  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10664  Constructor,
10665  E->isElidable(), Args,
10666  E->hadMultipleCandidates(),
10667  E->isListInitialization(),
10668  E->isStdInitListInitialization(),
10669  E->requiresZeroInitialization(),
10670  E->getConstructionKind(),
10671  E->getParenOrBraceRange());
10672 }
10673 
10674 template<typename Derived>
10675 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10676  CXXInheritedCtorInitExpr *E) {
10677  QualType T = getDerived().TransformType(E->getType());
10678  if (T.isNull())
10679  return ExprError();
10680 
10681  CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10682  getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10683  if (!Constructor)
10684  return ExprError();
10685 
10686  if (!getDerived().AlwaysRebuild() &&
10687  T == E->getType() &&
10688  Constructor == E->getConstructor()) {
10689  // Mark the constructor as referenced.
10690  // FIXME: Instantiation-specific
10691  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10692  return E;
10693  }
10694 
10695  return getDerived().RebuildCXXInheritedCtorInitExpr(
10696  T, E->getLocation(), Constructor,
10697  E->constructsVBase(), E->inheritedFromVBase());
10698 }
10699 
10700 /// \brief Transform a C++ temporary-binding expression.
10701 ///
10702 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10703 /// transform the subexpression and return that.
10704 template<typename Derived>
10705 ExprResult
10706 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10707  return getDerived().TransformExpr(E->getSubExpr());
10708 }
10709 
10710 /// \brief Transform a C++ expression that contains cleanups that should
10711 /// be run after the expression is evaluated.
10712 ///
10713 /// Since ExprWithCleanups nodes are implicitly generated, we
10714 /// just transform the subexpression and return that.
10715 template<typename Derived>
10716 ExprResult
10717 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10718  return getDerived().TransformExpr(E->getSubExpr());
10719 }
10720 
10721 template<typename Derived>
10722 ExprResult
10723 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10724  CXXTemporaryObjectExpr *E) {
10725  TypeSourceInfo *T =
10726  getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
10727  if (!T)
10728  return ExprError();
10729 
10730  CXXConstructorDecl *Constructor
10731  = cast_or_null<CXXConstructorDecl>(
10732  getDerived().TransformDecl(E->getLocStart(),
10733  E->getConstructor()));
10734  if (!Constructor)
10735  return ExprError();
10736 
10737  bool ArgumentChanged = false;
10738  SmallVector<Expr*, 8> Args;
10739  Args.reserve(E->getNumArgs());
10740  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10741  &ArgumentChanged))
10742  return ExprError();
10743 
10744  if (!getDerived().AlwaysRebuild() &&
10745  T == E->getTypeSourceInfo() &&
10746  Constructor == E->getConstructor() &&
10747  !ArgumentChanged) {
10748  // FIXME: Instantiation-specific
10749  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10750  return SemaRef.MaybeBindToTemporary(E);
10751  }
10752 
10753  // FIXME: Pass in E->isListInitialization().
10754  return getDerived().RebuildCXXTemporaryObjectExpr(T,
10755  /*FIXME:*/T->getTypeLoc().getEndLoc(),
10756  Args,
10757  E->getLocEnd());
10758 }
10759 
10760 template<typename Derived>
10761 ExprResult
10762 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10763  // Transform any init-capture expressions before entering the scope of the
10764  // lambda body, because they are not semantically within that scope.
10765  typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10766  SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10767  InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10768  E->explicit_capture_begin());
10769  for (LambdaExpr::capture_iterator C = E->capture_begin(),
10770  CEnd = E->capture_end();
10771  C != CEnd; ++C) {
10772  if (!E->isInitCapture(C))
10773  continue;
10774  EnterExpressionEvaluationContext EEEC(
10776  ExprResult NewExprInitResult = getDerived().TransformInitializer(
10777  C->getCapturedVar()->getInit(),
10778  C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10779 
10780  if (NewExprInitResult.isInvalid())
10781  return ExprError();
10782  Expr *NewExprInit = NewExprInitResult.get();
10783 
10784  VarDecl *OldVD = C->getCapturedVar();
10785  QualType NewInitCaptureType =
10786  getSema().buildLambdaInitCaptureInitialization(
10787  C->getLocation(), OldVD->getType()->isReferenceType(),
10788  OldVD->getIdentifier(),
10789  C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10790  NewExprInitResult = NewExprInit;
10791  InitCaptureExprsAndTypes[C - E->capture_begin()] =
10792  std::make_pair(NewExprInitResult, NewInitCaptureType);
10793  }
10794 
10795  // Transform the template parameters, and add them to the current
10796  // instantiation scope. The null case is handled correctly.
10797  auto TPL = getDerived().TransformTemplateParameterList(
10798  E->getTemplateParameterList());
10799 
10800  // Transform the type of the original lambda's call operator.
10801  // The transformation MUST be done in the CurrentInstantiationScope since
10802  // it introduces a mapping of the original to the newly created
10803  // transformed parameters.
10804  TypeSourceInfo *NewCallOpTSI = nullptr;
10805  {
10806  TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10807  FunctionProtoTypeLoc OldCallOpFPTL =
10808  OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10809 
10810  TypeLocBuilder NewCallOpTLBuilder;
10811  SmallVector<QualType, 4> ExceptionStorage;
10812  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10813  QualType NewCallOpType = TransformFunctionProtoType(
10814  NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10815  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10816  return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10817  ExceptionStorage, Changed);
10818  });
10819  if (NewCallOpType.isNull())
10820  return ExprError();
10821  NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10822  NewCallOpType);
10823  }
10824 
10825  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10826  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10827  LSI->GLTemplateParameterList = TPL;
10828 
10829  // Create the local class that will describe the lambda.
10830  CXXRecordDecl *Class
10831  = getSema().createLambdaClosureType(E->getIntroducerRange(),
10832  NewCallOpTSI,
10833  /*KnownDependent=*/false,
10834  E->getCaptureDefault());
10835  getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10836 
10837  // Build the call operator.
10838  CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10839  Class, E->getIntroducerRange(), NewCallOpTSI,
10840  E->getCallOperator()->getLocEnd(),
10841  NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10842  E->getCallOperator()->isConstexpr());
10843 
10844  LSI->CallOperator = NewCallOperator;
10845 
10846  for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10847  I != NumParams; ++I) {
10848  auto *P = NewCallOperator->getParamDecl(I);
10849  if (P->hasUninstantiatedDefaultArg()) {
10850  EnterExpressionEvaluationContext Eval(
10851  getSema(),
10853  ExprResult R = getDerived().TransformExpr(
10854  E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10855  P->setDefaultArg(R.get());
10856  }
10857  }
10858 
10859  getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10860  getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10861 
10862  // Introduce the context of the call operator.
10863  Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10864  /*NewThisContext*/false);
10865 
10866  // Enter the scope of the lambda.
10867  getSema().buildLambdaScope(LSI, NewCallOperator,
10868  E->getIntroducerRange(),
10869  E->getCaptureDefault(),
10870  E->getCaptureDefaultLoc(),
10871  E->hasExplicitParameters(),
10872  E->hasExplicitResultType(),
10873  E->isMutable());
10874 
10875  bool Invalid = false;
10876 
10877  // Transform captures.
10878  bool FinishedExplicitCaptures = false;
10879  for (LambdaExpr::capture_iterator C = E->capture_begin(),
10880  CEnd = E->capture_end();
10881  C != CEnd; ++C) {
10882  // When we hit the first implicit capture, tell Sema that we've finished
10883  // the list of explicit captures.
10884  if (!FinishedExplicitCaptures && C->isImplicit()) {
10885  getSema().finishLambdaExplicitCaptures(LSI);
10886  FinishedExplicitCaptures = true;
10887  }
10888 
10889  // Capturing 'this' is trivial.
10890  if (C->capturesThis()) {
10891  getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10892  /*BuildAndDiagnose*/ true, nullptr,
10893  C->getCaptureKind() == LCK_StarThis);
10894  continue;
10895  }
10896  // Captured expression will be recaptured during captured variables
10897  // rebuilding.
10898  if (C->capturesVLAType())
10899  continue;
10900 
10901  // Rebuild init-captures, including the implied field declaration.
10902  if (E->isInitCapture(C)) {
10903  InitCaptureInfoTy InitExprTypePair =
10904  InitCaptureExprsAndTypes[C - E->capture_begin()];
10905  ExprResult Init = InitExprTypePair.first;
10906  QualType InitQualType = InitExprTypePair.second;
10907  if (Init.isInvalid() || InitQualType.isNull()) {
10908  Invalid = true;
10909  continue;
10910  }
10911  VarDecl *OldVD = C->getCapturedVar();
10912  VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
10913  OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10914  OldVD->getInitStyle(), Init.get());
10915  if (!NewVD)
10916  Invalid = true;
10917  else {
10918  getDerived().transformedLocalDecl(OldVD, NewVD);
10919  }
10920  getSema().buildInitCaptureField(LSI, NewVD);
10921  continue;
10922  }
10923 
10924  assert(C->capturesVariable() && "unexpected kind of lambda capture");
10925 
10926  // Determine the capture kind for Sema.
10928  = C->isImplicit()? Sema::TryCapture_Implicit
10929  : C->getCaptureKind() == LCK_ByCopy
10932  SourceLocation EllipsisLoc;
10933  if (C->isPackExpansion()) {
10934  UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10935  bool ShouldExpand = false;
10936  bool RetainExpansion = false;
10937  Optional<unsigned> NumExpansions;
10938  if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10939  C->getLocation(),
10940  Unexpanded,
10941  ShouldExpand, RetainExpansion,
10942  NumExpansions)) {
10943  Invalid = true;
10944  continue;
10945  }
10946 
10947  if (ShouldExpand) {
10948  // The transform has determined that we should perform an expansion;
10949  // transform and capture each of the arguments.
10950  // expansion of the pattern. Do so.
10951  VarDecl *Pack = C->getCapturedVar();
10952  for (unsigned I = 0; I != *NumExpansions; ++I) {
10953  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10954  VarDecl *CapturedVar
10955  = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10956  Pack));
10957  if (!CapturedVar) {
10958  Invalid = true;
10959  continue;
10960  }
10961 
10962  // Capture the transformed variable.
10963  getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10964  }
10965 
10966  // FIXME: Retain a pack expansion if RetainExpansion is true.
10967 
10968  continue;
10969  }
10970 
10971  EllipsisLoc = C->getEllipsisLoc();
10972  }
10973 
10974  // Transform the captured variable.
10975  VarDecl *CapturedVar
10976  = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10977  C->getCapturedVar()));
10978  if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10979  Invalid = true;
10980  continue;
10981  }
10982 
10983  // Capture the transformed variable.
10984  getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10985  EllipsisLoc);
10986  }
10987  if (!FinishedExplicitCaptures)
10988  getSema().finishLambdaExplicitCaptures(LSI);
10989 
10990  // Enter a new evaluation context to insulate the lambda from any
10991  // cleanups from the enclosing full-expression.
10992  getSema().PushExpressionEvaluationContext(
10994 
10995  // Instantiate the body of the lambda expression.
10996  StmtResult Body =
10997  Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10998 
10999  // ActOnLambda* will pop the function scope for us.
11000  FuncScopeCleanup.disable();
11001 
11002  if (Body.isInvalid()) {
11003  SavedContext.pop();
11004  getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
11005  /*IsInstantiation=*/true);
11006  return ExprError();
11007  }
11008 
11009  // Copy the LSI before ActOnFinishFunctionBody removes it.
11010  // FIXME: This is dumb. Store the lambda information somewhere that outlives
11011  // the call operator.
11012  auto LSICopy = *LSI;
11013  getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11014  /*IsInstantiation*/ true);
11015  SavedContext.pop();
11016 
11017  return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11018  &LSICopy);
11019 }
11020 
11021 template<typename Derived>
11022 ExprResult
11023 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
11024  CXXUnresolvedConstructExpr *E) {
11025  TypeSourceInfo *T =
11026  getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
11027  if (!T)
11028  return ExprError();
11029 
11030  bool ArgumentChanged = false;
11031  SmallVector<Expr*, 8> Args;
11032  Args.reserve(E->arg_size());
11033  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11034  &ArgumentChanged))
11035  return ExprError();
11036 
11037  if (!getDerived().AlwaysRebuild() &&
11038  T == E->getTypeSourceInfo() &&
11039  !ArgumentChanged)
11040  return E;
11041 
11042  // FIXME: we're faking the locations of the commas
11043  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
11044  E->getLParenLoc(),
11045  Args,
11046  E->getRParenLoc());
11047 }
11048 
11049 template<typename Derived>
11050 ExprResult
11051 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
11052  CXXDependentScopeMemberExpr *E) {
11053  // Transform the base of the expression.
11054  ExprResult Base((Expr*) nullptr);
11055  Expr *OldBase;
11056  QualType BaseType;
11057  QualType ObjectType;
11058  if (!E->isImplicitAccess()) {
11059  OldBase = E->getBase();
11060  Base = getDerived().TransformExpr(OldBase);
11061  if (Base.isInvalid())
11062  return ExprError();
11063 
11064  // Start the member reference and compute the object's type.
11065  ParsedType ObjectTy;
11066  bool MayBePseudoDestructor = false;
11067  Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
11068  E->getOperatorLoc(),
11069  E->isArrow()? tok::arrow : tok::period,
11070  ObjectTy,
11071  MayBePseudoDestructor);
11072  if (Base.isInvalid())
11073  return ExprError();
11074 
11075  ObjectType = ObjectTy.get();
11076  BaseType = ((Expr*) Base.get())->getType();
11077  } else {
11078  OldBase = nullptr;
11079  BaseType = getDerived().TransformType(E->getBaseType());
11080  ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11081  }
11082 
11083  // Transform the first part of the nested-name-specifier that qualifies
11084  // the member name.
11085  NamedDecl *FirstQualifierInScope
11086  = getDerived().TransformFirstQualifierInScope(
11087  E->getFirstQualifierFoundInScope(),
11088  E->getQualifierLoc().getBeginLoc());
11089 
11090  NestedNameSpecifierLoc QualifierLoc;
11091  if (E->getQualifier()) {
11092  QualifierLoc
11093  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11094  ObjectType,
11095  FirstQualifierInScope);
11096  if (!QualifierLoc)
11097  return ExprError();
11098  }
11099 
11100  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11101 
11102  // TODO: If this is a conversion-function-id, verify that the
11103  // destination type name (if present) resolves the same way after
11104  // instantiation as it did in the local scope.
11105 
11106  DeclarationNameInfo NameInfo
11107  = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
11108  if (!NameInfo.getName())
11109  return ExprError();
11110 
11111  if (!E->hasExplicitTemplateArgs()) {
11112  // This is a reference to a member without an explicitly-specified
11113  // template argument list. Optimize for this common case.
11114  if (!getDerived().AlwaysRebuild() &&
11115  Base.get() == OldBase &&
11116  BaseType == E->getBaseType() &&
11117  QualifierLoc == E->getQualifierLoc() &&
11118  NameInfo.getName() == E->getMember() &&
11119  FirstQualifierInScope == E->getFirstQualifierFoundInScope())
11120  return E;
11121 
11122  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11123  BaseType,
11124  E->isArrow(),
11125  E->getOperatorLoc(),
11126  QualifierLoc,
11127  TemplateKWLoc,
11128  FirstQualifierInScope,
11129  NameInfo,
11130  /*TemplateArgs*/nullptr);
11131  }
11132 
11133  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
11134  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11135  E->getNumTemplateArgs(),
11136  TransArgs))
11137  return ExprError();
11138 
11139  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
11140  BaseType,
11141  E->isArrow(),
11142  E->getOperatorLoc(),
11143  QualifierLoc,
11144  TemplateKWLoc,
11145  FirstQualifierInScope,
11146  NameInfo,
11147  &TransArgs);
11148 }
11149 
11150 template<typename Derived>
11151 ExprResult
11152 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
11153  // Transform the base of the expression.
11154  ExprResult Base((Expr*) nullptr);
11155  QualType BaseType;
11156  if (!Old->isImplicitAccess()) {
11157  Base = getDerived().TransformExpr(Old->getBase());
11158  if (Base.isInvalid())
11159  return ExprError();
11160  Base = getSema().PerformMemberExprBaseConversion(Base.get(),
11161  Old->isArrow());
11162  if (Base.isInvalid())
11163  return ExprError();
11164  BaseType = Base.get()->getType();
11165  } else {
11166  BaseType = getDerived().TransformType(Old->getBaseType());
11167  }
11168 
11169  NestedNameSpecifierLoc QualifierLoc;
11170  if (Old->getQualifierLoc()) {
11171  QualifierLoc
11172  = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11173  if (!QualifierLoc)
11174  return ExprError();
11175  }
11176 
11177  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11178 
11179  LookupResult R(SemaRef, Old->getMemberNameInfo(),
11181 
11182  // Transform the declaration set.
11183  if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11184  return ExprError();
11185 
11186  // Determine the naming class.
11187  if (Old->getNamingClass()) {
11188  CXXRecordDecl *NamingClass
11189  = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
11190  Old->getMemberLoc(),
11191  Old->getNamingClass()));
11192  if (!NamingClass)
11193  return ExprError();
11194 
11195  R.setNamingClass(NamingClass);
11196  }
11197 
11198  TemplateArgumentListInfo TransArgs;
11199  if (Old->hasExplicitTemplateArgs()) {
11200  TransArgs.setLAngleLoc(Old->getLAngleLoc());
11201  TransArgs.setRAngleLoc(Old->getRAngleLoc());
11202  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11203  Old->getNumTemplateArgs(),
11204  TransArgs))
11205  return ExprError();
11206  }
11207 
11208  // FIXME: to do this check properly, we will need to preserve the
11209  // first-qualifier-in-scope here, just in case we had a dependent
11210  // base (and therefore couldn't do the check) and a
11211  // nested-name-qualifier (and therefore could do the lookup).
11212  NamedDecl *FirstQualifierInScope = nullptr;
11213 
11214  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
11215  BaseType,
11216  Old->getOperatorLoc(),
11217  Old->isArrow(),
11218  QualifierLoc,
11219  TemplateKWLoc,
11220  FirstQualifierInScope,
11221  R,
11222  (Old->hasExplicitTemplateArgs()
11223  ? &TransArgs : nullptr));
11224 }
11225 
11226 template<typename Derived>
11227 ExprResult
11228 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
11229  EnterExpressionEvaluationContext Unevaluated(
11231  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11232  if (SubExpr.isInvalid())
11233  return ExprError();
11234 
11235  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
11236  return E;
11237 
11238  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11239 }
11240 
11241 template<typename Derived>
11242 ExprResult
11243 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
11244  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11245  if (Pattern.isInvalid())
11246  return ExprError();
11247 
11248  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
11249  return E;
11250 
11251  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11252  E->getNumExpansions());
11253 }
11254 
11255 template<typename Derived>
11256 ExprResult
11257 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11258  // If E is not value-dependent, then nothing will change when we transform it.
11259  // Note: This is an instantiation-centric view.
11260  if (!E->isValueDependent())
11261  return E;
11262 
11263  EnterExpressionEvaluationContext Unevaluated(
11265 
11266  ArrayRef<TemplateArgument> PackArgs;
11267  TemplateArgument ArgStorage;
11268 
11269  // Find the argument list to transform.
11270  if (E->isPartiallySubstituted()) {
11271  PackArgs = E->getPartialArguments();
11272  } else if (E->isValueDependent()) {
11273  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11274  bool ShouldExpand = false;
11275  bool RetainExpansion = false;
11276  Optional<unsigned> NumExpansions;
11277  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11278  Unexpanded,
11279  ShouldExpand, RetainExpansion,
11280  NumExpansions))
11281  return ExprError();
11282 
11283  // If we need to expand the pack, build a template argument from it and
11284  // expand that.
11285  if (ShouldExpand) {
11286  auto *Pack = E->getPack();
11287  if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11288  ArgStorage = getSema().Context.getPackExpansionType(
11289  getSema().Context.getTypeDeclType(TTPD), None);
11290  } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11291  ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11292  } else {
11293  auto *VD = cast<ValueDecl>(Pack);
11294  ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11295  VK_RValue, E->getPackLoc());
11296  if (DRE.isInvalid())
11297  return ExprError();
11298  ArgStorage = new (getSema().Context) PackExpansionExpr(
11299  getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11300  }
11301  PackArgs = ArgStorage;
11302  }
11303  }
11304 
11305  // If we're not expanding the pack, just transform the decl.
11306  if (!PackArgs.size()) {
11307  auto *Pack = cast_or_null<NamedDecl>(
11308  getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
11309  if (!Pack)
11310  return ExprError();
11311  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11312  E->getPackLoc(),
11313  E->getRParenLoc(), None, None);
11314  }
11315 
11316  // Try to compute the result without performing a partial substitution.
11317  Optional<unsigned> Result = 0;
11318  for (const TemplateArgument &Arg : PackArgs) {
11319  if (!Arg.isPackExpansion()) {
11320  Result = *Result + 1;
11321  continue;
11322  }
11323 
11324  TemplateArgumentLoc ArgLoc;
11325  InventTemplateArgumentLoc(Arg, ArgLoc);
11326 
11327  // Find the pattern of the pack expansion.
11328  SourceLocation Ellipsis;
11329  Optional<unsigned> OrigNumExpansions;
11330  TemplateArgumentLoc Pattern =
11331  getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11332  OrigNumExpansions);
11333 
11334  // Substitute under the pack expansion. Do not expand the pack (yet).
11335  TemplateArgumentLoc OutPattern;
11336  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11337  if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11338  /*Uneval*/ true))
11339  return true;
11340 
11341  // See if we can determine the number of arguments from the result.
11342  Optional<unsigned> NumExpansions =
11343  getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11344  if (!NumExpansions) {
11345  // No: we must be in an alias template expansion, and we're going to need
11346  // to actually expand the packs.
11347  Result = None;
11348  break;
11349  }
11350 
11351  Result = *Result + *NumExpansions;
11352  }
11353 
11354  // Common case: we could determine the number of expansions without
11355  // substituting.
11356  if (Result)
11357  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11358  E->getPackLoc(),
11359  E->getRParenLoc(), *Result, None);
11360 
11361  TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11362  E->getPackLoc());
11363  {
11364  TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11365  typedef TemplateArgumentLocInventIterator<
11366  Derived, const TemplateArgument*> PackLocIterator;
11367  if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11368  PackLocIterator(*this, PackArgs.end()),
11369  TransformedPackArgs, /*Uneval*/true))
11370  return ExprError();
11371  }
11372 
11373  // Check whether we managed to fully-expand the pack.
11374  // FIXME: Is it possible for us to do so and not hit the early exit path?
11375  SmallVector<TemplateArgument, 8> Args;
11376  bool PartialSubstitution = false;
11377  for (auto &Loc : TransformedPackArgs.arguments()) {
11378  Args.push_back(Loc.getArgument());
11379  if (Loc.getArgument().isPackExpansion())
11380  PartialSubstitution = true;
11381  }
11382 
11383  if (PartialSubstitution)
11384  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11385  E->getPackLoc(),
11386  E->getRParenLoc(), None, Args);
11387 
11388  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11389  E->getPackLoc(), E->getRParenLoc(),
11390  Args.size(), None);
11391 }
11392 
11393 template<typename Derived>
11394 ExprResult
11395 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11396  SubstNonTypeTemplateParmPackExpr *E) {
11397  // Default behavior is to do nothing with this transformation.
11398  return E;
11399 }
11400 
11401 template<typename Derived>
11402 ExprResult
11403 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11404  SubstNonTypeTemplateParmExpr *E) {
11405  // Default behavior is to do nothing with this transformation.
11406  return E;
11407 }
11408 
11409 template<typename Derived>
11410 ExprResult
11411 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11412  // Default behavior is to do nothing with this transformation.
11413  return E;
11414 }
11415 
11416 template<typename Derived>
11417 ExprResult
11418 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11419  MaterializeTemporaryExpr *E) {
11420  return getDerived().TransformExpr(E->GetTemporaryExpr());
11421 }
11422 
11423 template<typename Derived>
11424 ExprResult
11425 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11426  Expr *Pattern = E->getPattern();
11427 
11428  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11429  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11430  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11431 
11432  // Determine whether the set of unexpanded parameter packs can and should
11433  // be expanded.
11434  bool Expand = true;
11435  bool RetainExpansion = false;
11436  Optional<unsigned> NumExpansions;
11437  if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11438  Pattern->getSourceRange(),
11439  Unexpanded,
11440  Expand, RetainExpansion,
11441  NumExpansions))
11442  return true;
11443 
11444  if (!Expand) {
11445  // Do not expand any packs here, just transform and rebuild a fold
11446  // expression.
11447  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11448 
11449  ExprResult LHS =
11450  E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11451  if (LHS.isInvalid())
11452  return true;
11453 
11454  ExprResult RHS =
11455  E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11456  if (RHS.isInvalid())
11457  return true;
11458 
11459  if (!getDerived().AlwaysRebuild() &&
11460  LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11461  return E;
11462 
11463  return getDerived().RebuildCXXFoldExpr(
11464  E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11465  RHS.get(), E->getLocEnd());
11466  }
11467 
11468  // The transform has determined that we should perform an elementwise
11469  // expansion of the pattern. Do so.
11470  ExprResult Result = getDerived().TransformExpr(E->getInit());
11471  if (Result.isInvalid())
11472  return true;
11473  bool LeftFold = E->isLeftFold();
11474 
11475  // If we're retaining an expansion for a right fold, it is the innermost
11476  // component and takes the init (if any).
11477  if (!LeftFold && RetainExpansion) {
11478  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11479 
11480  ExprResult Out = getDerived().TransformExpr(Pattern);
11481  if (Out.isInvalid())
11482  return true;
11483 
11484  Result = getDerived().RebuildCXXFoldExpr(
11485  E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11486  Result.get(), E->getLocEnd());
11487  if (Result.isInvalid())
11488  return true;
11489  }
11490 
11491  for (unsigned I = 0; I != *NumExpansions; ++I) {
11492  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11493  getSema(), LeftFold ? I : *NumExpansions - I - 1);
11494  ExprResult Out = getDerived().TransformExpr(Pattern);
11495  if (Out.isInvalid())
11496  return true;
11497 
11498  if (Out.get()->containsUnexpandedParameterPack()) {
11499  // We still have a pack; retain a pack expansion for this slice.
11500  Result = getDerived().RebuildCXXFoldExpr(
11501  E->getLocStart(),
11502  LeftFold ? Result.get() : Out.get(),
11503  E->getOperator(), E->getEllipsisLoc(),
11504  LeftFold ? Out.get() : Result.get(),
11505  E->getLocEnd());
11506  } else if (Result.isUsable()) {
11507  // We've got down to a single element; build a binary operator.
11508  Result = getDerived().RebuildBinaryOperator(
11509  E->getEllipsisLoc(), E->getOperator(),
11510  LeftFold ? Result.get() : Out.get(),
11511  LeftFold ? Out.get() : Result.get());
11512  } else
11513  Result = Out;
11514 
11515  if (Result.isInvalid())
11516  return true;
11517  }
11518 
11519  // If we're retaining an expansion for a left fold, it is the outermost
11520  // component and takes the complete expansion so far as its init (if any).
11521  if (LeftFold && RetainExpansion) {
11522  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11523 
11524  ExprResult Out = getDerived().TransformExpr(Pattern);
11525  if (Out.isInvalid())
11526  return true;
11527 
11528  Result = getDerived().RebuildCXXFoldExpr(
11529  E->getLocStart(), Result.get(),
11530  E->getOperator(), E->getEllipsisLoc(),
11531  Out.get(), E->getLocEnd());
11532  if (Result.isInvalid())
11533  return true;
11534  }
11535 
11536  // If we had no init and an empty pack, and we're not retaining an expansion,
11537  // then produce a fallback value or error.
11538  if (Result.isUnset())
11539  return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11540  E->getOperator());
11541 
11542  return Result;
11543 }
11544 
11545 template<typename Derived>
11546 ExprResult
11547 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11548  CXXStdInitializerListExpr *E) {
11549  return getDerived().TransformExpr(E->getSubExpr());
11550 }
11551 
11552 template<typename Derived>
11553 ExprResult
11554 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
11555  return SemaRef.MaybeBindToTemporary(E);
11556 }
11557 
11558 template<typename Derived>
11559 ExprResult
11560 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
11561  return E;
11562 }
11563 
11564 template<typename Derived>
11565 ExprResult
11566 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11567  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11568  if (SubExpr.isInvalid())
11569  return ExprError();
11570 
11571  if (!getDerived().AlwaysRebuild() &&
11572  SubExpr.get() == E->getSubExpr())
11573  return E;
11574 
11575  return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
11576 }
11577 
11578 template<typename Derived>
11579 ExprResult
11580 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11581  // Transform each of the elements.
11582  SmallVector<Expr *, 8> Elements;
11583  bool ArgChanged = false;
11584  if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
11585  /*IsCall=*/false, Elements, &ArgChanged))
11586  return ExprError();
11587 
11588  if (!getDerived().AlwaysRebuild() && !ArgChanged)
11589  return SemaRef.MaybeBindToTemporary(E);
11590 
11591  return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11592  Elements.data(),
11593  Elements.size());
11594 }
11595 
11596 template<typename Derived>
11597 ExprResult
11598 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
11599  ObjCDictionaryLiteral *E) {
11600  // Transform each of the elements.
11601  SmallVector<ObjCDictionaryElement, 8> Elements;
11602  bool ArgChanged = false;
11603  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11604  ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
11605 
11606  if (OrigElement.isPackExpansion()) {
11607  // This key/value element is a pack expansion.
11608  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11609  getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11610  getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11611  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11612 
11613  // Determine whether the set of unexpanded parameter packs can
11614  // and should be expanded.
11615  bool Expand = true;
11616  bool RetainExpansion = false;
11617  Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11618  Optional<unsigned> NumExpansions = OrigNumExpansions;
11619  SourceRange PatternRange(OrigElement.Key->getLocStart(),
11620  OrigElement.Value->getLocEnd());
11621  if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11622  PatternRange,
11623  Unexpanded,
11624  Expand, RetainExpansion,
11625  NumExpansions))
11626  return ExprError();
11627 
11628  if (!Expand) {
11629  // The transform has determined that we should perform a simple
11630  // transformation on the pack expansion, producing another pack
11631  // expansion.
11632  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11633  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11634  if (Key.isInvalid())
11635  return ExprError();
11636 
11637  if (Key.get() != OrigElement.Key)
11638  ArgChanged = true;
11639 
11640  ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11641  if (Value.isInvalid())
11642  return ExprError();
11643 
11644  if (Value.get() != OrigElement.Value)
11645  ArgChanged = true;
11646 
11647  ObjCDictionaryElement Expansion = {
11648  Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11649  };
11650  Elements.push_back(Expansion);
11651  continue;
11652  }
11653 
11654  // Record right away that the argument was changed. This needs
11655  // to happen even if the array expands to nothing.
11656  ArgChanged = true;
11657 
11658  // The transform has determined that we should perform an elementwise
11659  // expansion of the pattern. Do so.
11660  for (unsigned I = 0; I != *NumExpansions; ++I) {
11661  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11662  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11663  if (Key.isInvalid())
11664  return ExprError();
11665 
11666  ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11667  if (Value.isInvalid())
11668  return ExprError();
11669 
11670  ObjCDictionaryElement Element = {
11671  Key.get(), Value.get(), SourceLocation(), NumExpansions
11672  };
11673 
11674  // If any unexpanded parameter packs remain, we still have a
11675  // pack expansion.
11676  // FIXME: Can this really happen?
11677  if (Key.get()->containsUnexpandedParameterPack() ||
11678  Value.get()->containsUnexpandedParameterPack())
11679  Element.EllipsisLoc = OrigElement.EllipsisLoc;
11680 
11681  Elements.push_back(Element);
11682  }
11683 
11684  // FIXME: Retain a pack expansion if RetainExpansion is true.
11685 
11686  // We've finished with this pack expansion.
11687  continue;
11688  }
11689 
11690  // Transform and check key.
11691  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11692  if (Key.isInvalid())
11693  return ExprError();
11694 
11695  if (Key.get() != OrigElement.Key)
11696  ArgChanged = true;
11697 
11698  // Transform and check value.
11699  ExprResult Value
11700  = getDerived().TransformExpr(OrigElement.Value);
11701  if (Value.isInvalid())
11702  return ExprError();
11703 
11704  if (Value.get() != OrigElement.Value)
11705  ArgChanged = true;
11706 
11707  ObjCDictionaryElement Element = {
11708  Key.get(), Value.get(), SourceLocation(), None
11709  };
11710  Elements.push_back(Element);
11711  }
11712 
11713  if (!getDerived().AlwaysRebuild() && !ArgChanged)
11714  return SemaRef.MaybeBindToTemporary(E);
11715 
11716  return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11717  Elements);
11718 }
11719 
11720 template<typename Derived>
11721 ExprResult
11722 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11723  TypeSourceInfo *EncodedTypeInfo
11724  = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11725  if (!EncodedTypeInfo)
11726  return ExprError();
11727 
11728  if (!getDerived().AlwaysRebuild() &&
11729  EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11730  return E;
11731 
11732  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11733  EncodedTypeInfo,
11734  E->getRParenLoc());
11735 }
11736 
11737 template<typename Derived>
11738 ExprResult TreeTransform<Derived>::
11739 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11740  // This is a kind of implicit conversion, and it needs to get dropped
11741  // and recomputed for the same general reasons that ImplicitCastExprs
11742  // do, as well a more specific one: this expression is only valid when
11743  // it appears *immediately* as an argument expression.
11744  return getDerived().TransformExpr(E->getSubExpr());
11745 }
11746 
11747 template<typename Derived>
11748 ExprResult TreeTransform<Derived>::
11749 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11750  TypeSourceInfo *TSInfo
11751  = getDerived().TransformType(E->getTypeInfoAsWritten());
11752  if (!TSInfo)
11753  return ExprError();
11754 
11755  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11756  if (Result.isInvalid())
11757  return ExprError();
11758 
11759  if (!getDerived().AlwaysRebuild() &&
11760  TSInfo == E->getTypeInfoAsWritten() &&
11761  Result.get() == E->getSubExpr())
11762  return E;
11763 
11764  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11765  E->getBridgeKeywordLoc(), TSInfo,
11766  Result.get());
11767 }
11768 
11769 template <typename Derived>
11770 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11771  ObjCAvailabilityCheckExpr *E) {
11772  return E;
11773 }
11774 
11775 template<typename Derived>
11776 ExprResult
11777 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11778  // Transform arguments.
11779  bool ArgChanged = false;
11780  SmallVector<Expr*, 8> Args;
11781  Args.reserve(E->getNumArgs());
11782  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11783  &ArgChanged))
11784  return ExprError();
11785 
11786  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11787  // Class message: transform the receiver type.
11788  TypeSourceInfo *ReceiverTypeInfo
11789  = getDerived().TransformType(E->getClassReceiverTypeInfo());
11790  if (!ReceiverTypeInfo)
11791  return ExprError();
11792 
11793  // If nothing changed, just retain the existing message send.
11794  if (!getDerived().AlwaysRebuild() &&
11795  ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11796  return SemaRef.MaybeBindToTemporary(E);
11797 
11798  // Build a new class message send.
11799  SmallVector<SourceLocation, 16> SelLocs;
11800  E->getSelectorLocs(SelLocs);
11801  return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11802  E->getSelector(),
11803  SelLocs,
11804  E->getMethodDecl(),
11805  E->getLeftLoc(),
11806  Args,
11807  E->getRightLoc());
11808  }
11809  else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11810  E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11811  if (!E->getMethodDecl())
11812  return ExprError();
11813 
11814  // Build a new class message send to 'super'.
11815  SmallVector<SourceLocation, 16> SelLocs;
11816  E->getSelectorLocs(SelLocs);
11817  return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11818  E->getSelector(),
11819  SelLocs,
11820  E->getReceiverType(),
11821  E->getMethodDecl(),
11822  E->getLeftLoc(),
11823  Args,
11824  E->getRightLoc());
11825  }
11826 
11827  // Instance message: transform the receiver
11828  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11829  "Only class and instance messages may be instantiated");
11830  ExprResult Receiver
11831  = getDerived().TransformExpr(E->getInstanceReceiver());
11832  if (Receiver.isInvalid())
11833  return ExprError();
11834 
11835  // If nothing changed, just retain the existing message send.
11836  if (!getDerived().AlwaysRebuild() &&
11837  Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11838  return SemaRef.MaybeBindToTemporary(E);
11839 
11840  // Build a new instance message send.
11841  SmallVector<SourceLocation, 16> SelLocs;
11842  E->getSelectorLocs(SelLocs);
11843  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11844  E->getSelector(),
11845  SelLocs,
11846  E->getMethodDecl(),
11847  E->getLeftLoc(),
11848  Args,
11849  E->getRightLoc());
11850 }
11851 
11852 template<typename Derived>
11853 ExprResult
11854 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11855  return E;
11856 }
11857 
11858 template<typename Derived>
11859 ExprResult
11860 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11861  return E;
11862 }
11863 
11864 template<typename Derived>
11865 ExprResult
11866 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11867  // Transform the base expression.
11868  ExprResult Base = getDerived().TransformExpr(E->getBase());
11869  if (Base.isInvalid())
11870  return ExprError();
11871 
11872  // We don't need to transform the ivar; it will never change.
11873 
11874  // If nothing changed, just retain the existing expression.
11875  if (!getDerived().AlwaysRebuild() &&
11876  Base.get() == E->getBase())
11877  return E;
11878 
11879  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11880  E->getLocation(),
11881  E->isArrow(), E->isFreeIvar());
11882 }
11883 
11884 template<typename Derived>
11885 ExprResult
11886 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
11887  // 'super' and types never change. Property never changes. Just
11888  // retain the existing expression.
11889  if (!E->isObjectReceiver())
11890  return E;
11891 
11892  // Transform the base expression.
11893  ExprResult Base = getDerived().TransformExpr(E->getBase());
11894  if (Base.isInvalid())
11895  return ExprError();
11896 
11897  // We don't need to transform the property; it will never change.
11898 
11899  // If nothing changed, just retain the existing expression.
11900  if (!getDerived().AlwaysRebuild() &&
11901  Base.get() == E->getBase())
11902  return E;
11903 
11904  if (E->isExplicitProperty())
11905  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11906  E->getExplicitProperty(),
11907  E->getLocation());
11908 
11909  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11910  SemaRef.Context.PseudoObjectTy,
11911  E->getImplicitPropertyGetter(),
11912  E->getImplicitPropertySetter(),
11913  E->getLocation());
11914 }
11915 
11916 template<typename Derived>
11917 ExprResult
11918 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11919  // Transform the base expression.
11920  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11921  if (Base.isInvalid())
11922  return ExprError();
11923 
11924  // Transform the key expression.
11925  ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11926  if (Key.isInvalid())
11927  return ExprError();
11928 
11929  // If nothing changed, just retain the existing expression.
11930  if (!getDerived().AlwaysRebuild() &&
11931  Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
11932  return E;
11933 
11934  return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
11935  Base.get(), Key.get(),
11936  E->getAtIndexMethodDecl(),
11937  E->setAtIndexMethodDecl());
11938 }
11939 
11940 template<typename Derived>
11941 ExprResult
11942 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
11943  // Transform the base expression.
11944  ExprResult Base = getDerived().TransformExpr(E->getBase());
11945  if (Base.isInvalid())
11946  return ExprError();
11947 
11948  // If nothing changed, just retain the existing expression.
11949  if (!getDerived().AlwaysRebuild() &&
11950  Base.get() == E->getBase())
11951  return E;
11952 
11953  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
11954  E->getOpLoc(),
11955  E->isArrow());
11956 }
11957 
11958 template<typename Derived>
11959 ExprResult
11960 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
11961  bool ArgumentChanged = false;
11962  SmallVector<Expr*, 8> SubExprs;
11963  SubExprs.reserve(E->getNumSubExprs());
11964  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11965  SubExprs, &ArgumentChanged))
11966  return ExprError();
11967 
11968  if (!getDerived().AlwaysRebuild() &&
11969  !ArgumentChanged)
11970  return E;
11971 
11972  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11973  SubExprs,
11974  E->getRParenLoc());
11975 }
11976 
11977 template<typename Derived>
11978 ExprResult
11979 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11980  ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11981  if (SrcExpr.isInvalid())
11982  return ExprError();
11983 
11984  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11985  if (!Type)
11986  return ExprError();
11987 
11988  if (!getDerived().AlwaysRebuild() &&
11989  Type == E->getTypeSourceInfo() &&
11990  SrcExpr.get() == E->getSrcExpr())
11991  return E;
11992 
11993  return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11994  SrcExpr.get(), Type,
11995  E->getRParenLoc());
11996 }
11997 
11998 template<typename Derived>
11999 ExprResult
12000 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
12001  BlockDecl *oldBlock = E->getBlockDecl();
12002 
12003  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
12004  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12005 
12006  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
12007  blockScope->TheDecl->setBlockMissingReturnType(
12008  oldBlock->blockMissingReturnType());
12009 
12010  SmallVector<ParmVarDecl*, 4> params;
12011  SmallVector<QualType, 4> paramTypes;
12012 
12013  const FunctionProtoType *exprFunctionType = E->getFunctionType();
12014 
12015  // Parameter substitution.
12016  Sema::ExtParameterInfoBuilder extParamInfos;
12017  if (getDerived().TransformFunctionTypeParams(
12018  E->getCaretLocation(), oldBlock->parameters(), nullptr,
12019  exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12020  extParamInfos)) {
12021  getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12022  return ExprError();
12023  }
12024 
12025  QualType exprResultType =
12026  getDerived().TransformType(exprFunctionType->getReturnType());
12027 
12028  auto epi = exprFunctionType->getExtProtoInfo();
12029  epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12030 
12031  QualType functionType =
12032  getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
12033  blockScope->FunctionType = functionType;
12034 
12035  // Set the parameters on the block decl.
12036  if (!params.empty())
12037  blockScope->TheDecl->setParams(params);
12038 
12039  if (!oldBlock->blockMissingReturnType()) {
12040  blockScope->HasImplicitReturnType = false;
12041  blockScope->ReturnType = exprResultType;
12042  }
12043 
12044  // Transform the body
12045  StmtResult body = getDerived().TransformStmt(E->getBody());
12046  if (body.isInvalid()) {
12047  getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
12048  return ExprError();
12049  }
12050 
12051 #ifndef NDEBUG
12052  // In builds with assertions, make sure that we captured everything we
12053  // captured before.
12054  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
12055  for (const auto &I : oldBlock->captures()) {
12056  VarDecl *oldCapture = I.getVariable();
12057 
12058  // Ignore parameter packs.
12059  if (isa<ParmVarDecl>(oldCapture) &&
12060  cast<ParmVarDecl>(oldCapture)->isParameterPack())
12061  continue;
12062 
12063  VarDecl *newCapture =
12064  cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12065  oldCapture));
12066  assert(blockScope->CaptureMap.count(newCapture));
12067  }
12068  assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
12069  }
12070 #endif
12071 
12072  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
12073  /*Scope=*/nullptr);
12074 }
12075 
12076 template<typename Derived>
12077 ExprResult
12078 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
12079  llvm_unreachable("Cannot transform asType expressions yet");
12080 }
12081 
12082 template<typename Derived>
12083 ExprResult
12084 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
12085  QualType RetTy = getDerived().TransformType(E->getType());
12086  bool ArgumentChanged = false;
12087  SmallVector<Expr*, 8> SubExprs;
12088  SubExprs.reserve(E->getNumSubExprs());
12089  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12090  SubExprs, &ArgumentChanged))
12091  return ExprError();
12092 
12093  if (!getDerived().AlwaysRebuild() &&
12094  !ArgumentChanged)
12095  return E;
12096 
12097  return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
12098  RetTy, E->getOp(), E->getRParenLoc());
12099 }
12100 
12101 //===----------------------------------------------------------------------===//
12102 // Type reconstruction
12103 //===----------------------------------------------------------------------===//
12104 
12105 template<typename Derived>
12107  SourceLocation Star) {
12108  return SemaRef.BuildPointerType(PointeeType, Star,
12109  getDerived().getBaseEntity());
12110 }
12111 
12112 template<typename Derived>
12114  SourceLocation Star) {
12115  return SemaRef.BuildBlockPointerType(PointeeType, Star,
12116  getDerived().getBaseEntity());
12117 }
12118 
12119 template<typename Derived>
12120 QualType
12122  bool WrittenAsLValue,
12123  SourceLocation Sigil) {
12124  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
12125  Sigil, getDerived().getBaseEntity());
12126 }
12127 
12128 template<typename Derived>
12129 QualType
12131  QualType ClassType,
12132  SourceLocation Sigil) {
12133  return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12134  getDerived().getBaseEntity());
12135 }
12136 
12137 template<typename Derived>
12139  const ObjCTypeParamDecl *Decl,
12140  SourceLocation ProtocolLAngleLoc,
12141  ArrayRef<ObjCProtocolDecl *> Protocols,
12142  ArrayRef<SourceLocation> ProtocolLocs,
12143  SourceLocation ProtocolRAngleLoc) {
12144  return SemaRef.BuildObjCTypeParamType(Decl,
12145  ProtocolLAngleLoc, Protocols,
12146  ProtocolLocs, ProtocolRAngleLoc,
12147  /*FailOnError=*/true);
12148 }
12149 
12150 template<typename Derived>
12152  QualType BaseType,
12153  SourceLocation Loc,
12154  SourceLocation TypeArgsLAngleLoc,
12155  ArrayRef<TypeSourceInfo *> TypeArgs,
12156  SourceLocation TypeArgsRAngleLoc,
12157  SourceLocation ProtocolLAngleLoc,
12158  ArrayRef<ObjCProtocolDecl *> Protocols,
12159  ArrayRef<SourceLocation> ProtocolLocs,
12160  SourceLocation ProtocolRAngleLoc) {
12161  return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12162  TypeArgs, TypeArgsRAngleLoc,
12163  ProtocolLAngleLoc, Protocols, ProtocolLocs,
12164  ProtocolRAngleLoc,
12165  /*FailOnError=*/true);
12166 }
12167 
12168 template<typename Derived>
12170  QualType PointeeType,
12171  SourceLocation Star) {
12172  return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12173 }
12174 
12175 template<typename Derived>
12176 QualType
12179  const llvm::APInt *Size,
12180  Expr *SizeExpr,
12181  unsigned IndexTypeQuals,
12182  SourceRange BracketsRange) {
12183  if (SizeExpr || !Size)
12184  return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12185  IndexTypeQuals, BracketsRange,
12186  getDerived().getBaseEntity());
12187 
12188  QualType Types[] = {
12189  SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12190  SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12191  SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
12192  };
12193  const unsigned NumTypes = llvm::array_lengthof(Types);
12194  QualType SizeType;
12195  for (unsigned I = 0; I != NumTypes; ++I)
12196  if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12197  SizeType = Types[I];
12198  break;
12199  }
12200 
12201  // Note that we can return a VariableArrayType here in the case where
12202  // the element type was a dependent VariableArrayType.
12203  IntegerLiteral *ArraySize
12204  = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12205  /*FIXME*/BracketsRange.getBegin());
12206  return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
12207  IndexTypeQuals, BracketsRange,
12208  getDerived().getBaseEntity());
12209 }
12210 
12211 template<typename Derived>
12212 QualType
12215  const llvm::APInt &Size,
12216  unsigned IndexTypeQuals,
12217  SourceRange BracketsRange) {
12218  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
12219  IndexTypeQuals, BracketsRange);
12220 }
12221 
12222 template<typename Derived>
12223 QualType
12226  unsigned IndexTypeQuals,
12227  SourceRange BracketsRange) {
12228  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
12229  IndexTypeQuals, BracketsRange);
12230 }
12231 
12232 template<typename Derived>
12233 QualType
12236  Expr *SizeExpr,
12237  unsigned IndexTypeQuals,
12238  SourceRange BracketsRange) {
12239  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12240  SizeExpr,
12241  IndexTypeQuals, BracketsRange);
12242 }
12243 
12244 template<typename Derived>
12245 QualType
12248  Expr *SizeExpr,
12249  unsigned IndexTypeQuals,
12250  SourceRange BracketsRange) {
12251  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
12252  SizeExpr,
12253  IndexTypeQuals, BracketsRange);
12254 }
12255 
12256 template<typename Derived>
12258  unsigned NumElements,
12259  VectorType::VectorKind VecKind) {
12260  // FIXME: semantic checking!
12261  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
12262 }
12263 
12264 template<typename Derived>
12266  unsigned NumElements,
12267  SourceLocation AttributeLoc) {
12268  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12269  NumElements, true);
12270  IntegerLiteral *VectorSize
12271  = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12272  AttributeLoc);
12273  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
12274 }
12275 
12276 template<typename Derived>
12277 QualType
12279  Expr *SizeExpr,
12280  SourceLocation AttributeLoc) {
12281  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
12282 }
12283 
12284 template<typename Derived>
12286  QualType T,
12287  MutableArrayRef<QualType> ParamTypes,
12288  const FunctionProtoType::ExtProtoInfo &EPI) {
12289  return SemaRef.BuildFunctionType(T, ParamTypes,
12290  getDerived().getBaseLocation(),
12291  getDerived().getBaseEntity(),
12292  EPI);
12293 }
12294 
12295 template<typename Derived>
12297  return SemaRef.Context.getFunctionNoProtoType(T);
12298 }
12299 
12300 template<typename Derived>
12302  Decl *D) {
12303  assert(D && "no decl found");
12304  if (D->isInvalidDecl()) return QualType();
12305 
12306  // FIXME: Doesn't account for ObjCInterfaceDecl!
12307  TypeDecl *Ty;
12308  if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12309  // A valid resolved using typename pack expansion decl can have multiple
12310  // UsingDecls, but they must each have exactly one type, and it must be
12311  // the same type in every case. But we must have at least one expansion!
12312  if (UPD->expansions().empty()) {
12313  getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12314  << UPD->isCXXClassMember() << UPD;
12315  return QualType();
12316  }
12317 
12318  // We might still have some unresolved types. Try to pick a resolved type
12319  // if we can. The final instantiation will check that the remaining
12320  // unresolved types instantiate to the type we pick.
12321  QualType FallbackT;
12322  QualType T;
12323  for (auto *E : UPD->expansions()) {
12324  QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12325  if (ThisT.isNull())
12326  continue;
12327  else if (ThisT->getAs<UnresolvedUsingType>())
12328  FallbackT = ThisT;
12329  else if (T.isNull())
12330  T = ThisT;
12331  else
12332  assert(getSema().Context.hasSameType(ThisT, T) &&
12333  "mismatched resolved types in using pack expansion");
12334  }
12335  return T.isNull() ? FallbackT : T;
12336  } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
12337  assert(Using->hasTypename() &&
12338  "UnresolvedUsingTypenameDecl transformed to non-typename using");
12339 
12340  // A valid resolved using typename decl points to exactly one type decl.
12341  assert(++Using->shadow_begin() == Using->shadow_end());
12342  Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
12343  } else {
12344  assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12345  "UnresolvedUsingTypenameDecl transformed to non-using decl");
12346  Ty = cast<UnresolvedUsingTypenameDecl>(D);
12347  }
12348 
12349  return SemaRef.Context.getTypeDeclType(Ty);
12350 }
12351 
12352 template<typename Derived>
12354  SourceLocation Loc) {
12355  return SemaRef.BuildTypeofExprType(E, Loc);
12356 }
12357 
12358 template<typename Derived>
12360  return SemaRef.Context.getTypeOfType(Underlying);
12361 }
12362 
12363 template<typename Derived>
12365  SourceLocation Loc) {
12366  return SemaRef.BuildDecltypeType(E, Loc);
12367 }
12368 
12369 template<typename Derived>
12372  SourceLocation Loc) {
12373  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12374 }
12375 
12376 template<typename Derived>
12378  TemplateName Template,
12379  SourceLocation TemplateNameLoc,
12380  TemplateArgumentListInfo &TemplateArgs) {
12381  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
12382 }
12383 
12384 template<typename Derived>
12386  SourceLocation KWLoc) {
12387  return SemaRef.BuildAtomicType(ValueType, KWLoc);
12388 }
12389 
12390 template<typename Derived>
12392  SourceLocation KWLoc,
12393  bool isReadPipe) {
12394  return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12395  : SemaRef.BuildWritePipeType(ValueType, KWLoc);
12396 }
12397 
12398 template<typename Derived>
12399 TemplateName
12401  bool TemplateKW,
12402  TemplateDecl *Template) {
12403  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
12404  Template);
12405 }
12406 
12407 template<typename Derived>
12408 TemplateName
12410  const IdentifierInfo &Name,
12411  SourceLocation NameLoc,
12412  QualType ObjectType,
12413  NamedDecl *FirstQualifierInScope,
12414  bool AllowInjectedClassName) {
12415  UnqualifiedId TemplateName;
12416  TemplateName.setIdentifier(&Name, NameLoc);
12417  Sema::TemplateTy Template;
12418  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12419  getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12420  SS, TemplateKWLoc, TemplateName,
12421  ParsedType::make(ObjectType),
12422  /*EnteringContext=*/false,
12423  Template, AllowInjectedClassName);
12424  return Template.get();
12425 }
12426 
12427 template<typename Derived>
12428 TemplateName
12430  OverloadedOperatorKind Operator,
12431  SourceLocation NameLoc,
12432  QualType ObjectType,
12433  bool AllowInjectedClassName) {
12435  // FIXME: Bogus location information.
12436  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
12437  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
12438  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12439  Sema::TemplateTy Template;
12440  getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
12441  SS, TemplateKWLoc, Name,
12442  ParsedType::make(ObjectType),
12443  /*EnteringContext=*/false,
12444  Template, AllowInjectedClassName);
12445  return Template.get();
12446 }
12447 
12448 template<typename Derived>
12449 ExprResult
12451  SourceLocation OpLoc,
12452  Expr *OrigCallee,
12453  Expr *First,
12454  Expr *Second) {
12455  Expr *Callee = OrigCallee->IgnoreParenCasts();
12456  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
12457 
12458  if (First->getObjectKind() == OK_ObjCProperty) {
12461  return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12462  First, Second);
12463  ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12464  if (Result.isInvalid())
12465  return ExprError();
12466  First = Result.get();
12467  }
12468 
12469  if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12470  ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12471  if (Result.isInvalid())
12472  return ExprError();
12473  Second = Result.get();
12474  }
12475 
12476  // Determine whether this should be a builtin operation.
12477  if (Op == OO_Subscript) {
12478  if (!First->getType()->isOverloadableType() &&
12479  !Second->getType()->isOverloadableType())
12480  return getSema().CreateBuiltinArraySubscriptExpr(First,
12481  Callee->getLocStart(),
12482  Second, OpLoc);
12483  } else if (Op == OO_Arrow) {
12484  // -> is never a builtin operation.
12485  return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12486  } else if (Second == nullptr || isPostIncDec) {
12487  if (!First->getType()->isOverloadableType()) {
12488  // The argument is not of overloadable type, so try to create a
12489  // built-in unary operation.
12490  UnaryOperatorKind Opc
12491  = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12492 
12493  return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
12494  }
12495  } else {
12496  if (!First->getType()->isOverloadableType() &&
12497  !Second->getType()->isOverloadableType()) {
12498  // Neither of the arguments is an overloadable type, so try to
12499  // create a built-in binary operation.
12501  ExprResult Result
12502  = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
12503  if (Result.isInvalid())
12504  return ExprError();
12505 
12506  return Result;
12507  }
12508  }
12509 
12510  // Compute the transformed set of functions (and function templates) to be
12511  // used during overload resolution.
12512  UnresolvedSet<16> Functions;
12513 
12514  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12515  assert(ULE->requiresADL());
12516  Functions.append(ULE->decls_begin(), ULE->decls_end());
12517  } else {
12518  // If we've resolved this to a particular non-member function, just call
12519  // that function. If we resolved it to a member function,
12520  // CreateOverloaded* will find that function for us.
12521  NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12522  if (!isa<CXXMethodDecl>(ND))
12523  Functions.addDecl(ND);
12524  }
12525 
12526  // Add any functions found via argument-dependent lookup.
12527  Expr *Args[2] = { First, Second };
12528  unsigned NumArgs = 1 + (Second != nullptr);
12529 
12530  // Create the overloaded operator invocation for unary operators.
12531  if (NumArgs == 1 || isPostIncDec) {
12532  UnaryOperatorKind Opc
12533  = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
12534  return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
12535  }
12536 
12537  if (Op == OO_Subscript) {
12538  SourceLocation LBrace;
12539  SourceLocation RBrace;
12540 
12541  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
12542  DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
12546  NameLoc.CXXOperatorName.EndOpNameLoc);
12547  } else {
12548  LBrace = Callee->getLocStart();
12549  RBrace = OpLoc;
12550  }
12551 
12552  return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12553  First, Second);
12554  }
12555 
12556  // Create the overloaded operator invocation for binary operators.
12558  ExprResult Result
12559  = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12560  if (Result.isInvalid())
12561  return ExprError();
12562 
12563  return Result;
12564 }
12565 
12566 template<typename Derived>
12567 ExprResult
12569  SourceLocation OperatorLoc,
12570  bool isArrow,
12571  CXXScopeSpec &SS,
12572  TypeSourceInfo *ScopeType,
12573  SourceLocation CCLoc,
12574  SourceLocation TildeLoc,
12575  PseudoDestructorTypeStorage Destroyed) {
12576  QualType BaseType = Base->getType();
12577  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
12578  (!isArrow && !BaseType->getAs<RecordType>()) ||
12579  (isArrow && BaseType->getAs<PointerType>() &&
12580  !BaseType->getAs<PointerType>()->getPointeeType()
12581  ->template getAs<RecordType>())){
12582  // This pseudo-destructor expression is still a pseudo-destructor.
12583  return SemaRef.BuildPseudoDestructorExpr(
12584  Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12585  CCLoc, TildeLoc, Destroyed);
12586  }
12587 
12588  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
12589  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12590  SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12591  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12592  NameInfo.setNamedTypeInfo(DestroyedType);
12593 
12594  // The scope type is now known to be a valid nested name specifier
12595  // component. Tack it on to the end of the nested name specifier.
12596  if (ScopeType) {
12597  if (!ScopeType->getType()->getAs<TagType>()) {
12598  getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12599  diag::err_expected_class_or_namespace)
12600  << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12601  return ExprError();
12602  }
12603  SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12604  CCLoc);
12605  }
12606 
12607  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
12608  return getSema().BuildMemberReferenceExpr(Base, BaseType,
12609  OperatorLoc, isArrow,
12610  SS, TemplateKWLoc,
12611  /*FIXME: FirstQualifier*/ nullptr,
12612  NameInfo,
12613  /*TemplateArgs*/ nullptr,
12614  /*S*/nullptr);
12615 }
12616 
12617 template<typename Derived>
12618 StmtResult
12620  SourceLocation Loc = S->getLocStart();
12621  CapturedDecl *CD = S->getCapturedDecl();
12622  unsigned NumParams = CD->getNumParams();
12623  unsigned ContextParamPos = CD->getContextParamPosition();
12625  for (unsigned I = 0; I < NumParams; ++I) {
12626  if (I != ContextParamPos) {
12627  Params.push_back(
12628  std::make_pair(
12629  CD->getParam(I)->getName(),
12630  getDerived().TransformType(CD->getParam(I)->getType())));
12631  } else {
12632  Params.push_back(std::make_pair(StringRef(), QualType()));
12633  }
12634  }
12635  getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
12636  S->getCapturedRegionKind(), Params);
12637  StmtResult Body;
12638  {
12639  Sema::CompoundScopeRAII CompoundScope(getSema());
12640  Body = getDerived().TransformStmt(S->getCapturedStmt());
12641  }
12642 
12643  if (Body.isInvalid()) {
12644  getSema().ActOnCapturedRegionError();
12645  return StmtError();
12646  }
12647 
12648  return getSema().ActOnCapturedRegionEnd(Body.get());
12649 }
12650 
12651 } // end namespace clang
12652 
12653 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:539
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1009
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4576
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1467
SourceLocation getEnd() const
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present...
Definition: Type.h:3501
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:64
StmtClass getStmtClass() const
Definition: Stmt.h:361
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:5508
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:409
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:49
This represents 'thread_limit' clause in the '#pragma omp ...' directive.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:222
const TemplateArgumentLoc * operator->() const
The receiver is an object instance.
Definition: ExprObjC.h:1005
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:1986
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:237
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
Smart pointer class that efficiently represents Objective-C method names.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
Expr * getSourceExpression() const
Definition: TemplateBase.h:484
This represents clause 'copyin' in the '#pragma omp ...' directives.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
Build a new object-construction expression.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2224
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:107
unsigned Length
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
Definition: Type.h:3550
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2062
A (possibly-)qualified type.
Definition: Type.h:616
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:5232
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:2610
SourceLocation getColonLoc() const
Get colon location.
ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:213
bool isInvalid() const
Definition: Ownership.h:159
QualType RebuildDependentSizedArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Derived & getDerived()
Retrieves a reference to the derived class.
ArrayRef< OMPClause * > clauses()
Definition: StmtOpenMP.h:235
QualType TransformType(QualType T)
Transforms the given type into another type.
OMPClause * RebuildOMPToClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'to' clause.
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:3698
QualType RebuildTemplateSpecializationType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:2954
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
static ConditionResult ConditionError()
Definition: Sema.h:9639
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
Build a new object-construction expression.
static UnresolvedLookupExpr * Create(const ASTContext &C, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool ADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.h:2703
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1399
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
DeclClass * getAsSingle() const
Definition: Lookup.h:493
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1268
Stmt - This represents one statement.
Definition: Stmt.h:60
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:510
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1588
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1412
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:1905
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
QualType RebuildEnumType(EnumDecl *Enum)
Build a new Enum type.
ActionResult< Expr * > ExprResult
Definition: Ownership.h:252
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1487
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
SourceLocation getLParenLoc() const
Returns the location of '('.
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
bool isRecordType() const
Definition: Type.h:5769
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
This represents 'grainsize' clause in the '#pragma omp ...' directive.
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2118
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
void setType(QualType t)
Definition: Expr.h:128
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2655
Defines the C++ template declaration subclasses.
StringRef P
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4206
Represents an attribute applied to a statement.
Definition: Stmt.h:854
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
bool isEnumeralType() const
Definition: Type.h:5772
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1662
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:316
PtrTy get() const
Definition: Ownership.h:163
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
This represents 'priority' clause in the '#pragma omp ...' directive.
The base class of the type hierarchy.
Definition: Type.h:1303
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1375
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:2842
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc)
Build a new typeof(expr) type.
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2020
QualType RebuildConstantArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array...
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:461
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1177
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:2858
Wrapper for source info for typedefs.
Definition: TypeLoc.h:638
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:392
SourceLocation getColonLoc() const
Returns the location of ':'.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const TemplateArgumentLoc * operator->() const
std::input_iterator_tag iterator_category
A container of type source information.
Definition: Decl.h:62
Wrapper for void* pointer.
Definition: Ownership.h:45
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, TemplateName Template)
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:306
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a function type into the given vectors.
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedExpr::IdentType IT)
Build a new predefined expression.
SourceLocation getColonLoc() const
Get colon location.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2329
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:2618
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:3946
bool isSpelledAsLValue() const
Definition: Type.h:2377
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, Expr *Callee, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
Expr * getAlignment()
Returns alignment.
static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind)
Return the number of captured regions created for an OpenMP directive.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
An identifier, stored as an IdentifierInfo*.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:125
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:544
RAII object that enters a new expression evaluation context.
Definition: Sema.h:10497
OMPClause * RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1733
void removeObjCLifetime()
Definition: Type.h:315
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast. ...
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:254
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:46
Extra information about a function prototype.
Definition: Type.h:3234
This represents 'defaultmap' clause in the '#pragma omp ...' directive.
AutoTypeKeyword getKeyword() const
Definition: Type.h:4220
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
OMPClause * RebuildOMPThreadLimitClause(Expr *ThreadLimit, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:4980
A namespace, stored as a NamespaceDecl*.
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:2849
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:548
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:2601
void transformedLocalDecl(Decl *Old, Decl *New)
Note that a local declaration has been transformed by this transformer.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:50
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1104
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, QualType RetTy, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
This represents implicit clause 'flush' for the '#pragma omp flush' directive.
Defines the Objective-C statement AST node classes.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:2920
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1575
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1434
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4062
TemplateArgumentLocContainerIterator operator++(int)
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1885
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
This represents 'nogroup' clause in the '#pragma omp ...' directive.
The collection of all-type qualifiers we support.
Definition: Type.h:118
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:269
OpenMPDirectiveKind getDirectiveKind() const
Definition: StmtOpenMP.h:221
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3354
A semantic tree transformation that allows one to transform one abstract syntax tree into another...
Definition: TreeTransform.h:96
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc, bool DeducedTSTContext)
Build a new typename type that refers to an identifier.
DeclarationName getName() const
getName - Returns the embedded declaration name.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
One of these records is kept for each identifier that is lexed.
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1385
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Lookup.h:59
SourceLocation getLParenLoc() const
Returns the location of '('.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:233
Step
Definition: OpenMPClause.h:137
This represents '#pragma omp parallel' directive.
Definition: StmtOpenMP.h:251
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1217
A C++ nested-name-specifier augmented with source location information.
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:412
ExprResult ExprEmpty()
Definition: Ownership.h:274
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1146
This represents 'simd' clause in the '#pragma omp ...' directive.
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3343
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:57
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration...
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1602
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
bool isReferenceType() const
Definition: Type.h:5721
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1382
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:84
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2366
The current expression is potentially evaluated at run time, which means that code may be generated t...
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:95
OMPClause * RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'map' clause.
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:1690
Expr * getChunkSize()
Get chunk size.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
This represents clause 'map' in the '#pragma omp ...' directives.
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3150
This represents clause 'to' in the '#pragma omp ...' directives.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition: ExprCXX.h:2568
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
SourceLocation getLBracLoc() const
Definition: Stmt.h:653
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
Expr * getSubExpr()
Definition: Expr.h:2753
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:479
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
SourceRange getSourceRange() const LLVM_READONLY
Fetches the full source range of the argument.
Expr * getNumTeams()
Return NumTeams number.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword...
Definition: Diagnostic.h:1200
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Lookup.h:41
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:947
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:106
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool &ShouldExpand, bool &RetainExpansion, Optional< unsigned > &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
This represents clause 'copyprivate' in the '#pragma omp ...' directives.
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:100
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:169
Describes an C or C++ initializer list.
Definition: Expr.h:3848
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:3767
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
BinaryOperatorKind
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:899
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:468
Represents the results of name lookup.
Definition: Lookup.h:32
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2082
OMPClause * RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2041
< Capturing the *this object by copy
Definition: Lambda.h:37
OMPClause * RebuildOMPFromClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'from' clause.
A convenient class for passing around template argument information.
Definition: TemplateBase.h:524
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:221
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc, QualType ResultTy)
Build a new initializer list expression.
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4382
QualType getReturnType() const
Definition: Type.h:3065
QualType RebuildRecordType(RecordDecl *Record)
Build a new class/struct/union type.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
QualType RebuildArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known)...
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param)
Build a new C++ default-argument expression.
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:1686
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:3770
StmtResult StmtError()
Definition: Ownership.h:269
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:504
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:217
TypeDecl - Represents a declaration of a type.
Definition: Decl.h:2642
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:148
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:2587
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:2731
TemplateArgumentLocContainerIterator & operator++()
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorType::VectorKind VecKind)
Build a new vector type given the element type and number of elements.
OMPClause * RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Build a new pack expansion type.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation...
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Definition: Expr.cpp:2399
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition: Sema.h:2129
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
void append(iterator I, iterator E)
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2078
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1134
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:510
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc)
Build a new C++0x range-based for statement.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:89
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:748
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to...
Definition: Expr.h:2888
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
An ordinary object is located at an address in memory.
Definition: Specifiers.h:122
This represents clause 'is_device_ptr' in the '#pragma omp ...' directives.
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1378
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3726
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:412
Expr * getHint() const
Returns number of threads.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:2962
detail::InMemoryDirectory::const_iterator I
StmtClass
Definition: Stmt.h:62
unsigned getNumParams() const
Definition: TypeLoc.h:1426
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1125
QualType getType() const
Definition: Decl.h:589
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Definition: TypeLoc.h:53
TypedefNameDecl * getTypedefNameDecl() const
Definition: TypeLoc.h:642
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:7165
SourceRange getRange() const
Definition: DeclSpec.h:68
This represents clause 'from' in the '#pragma omp ...' directives.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
Represents the this expression in C++.
Definition: ExprCXX.h:888
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
A helper class for building up ExtParameterInfos.
Definition: Sema.h:7524
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
const Derived & getDerived() const
Retrieves a reference to the derived class.
unsigned getNumParams() const
Definition: Decl.h:3765
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Definition: Type.h:3095
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
Definition: OpenMPClause.h:57
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:2835
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
SourceLocation getLocation() const
Definition: ExprCXX.h:2086
StmtResult TransformSEHHandler(Stmt *Handler)
An error occurred.
Definition: Sema.h:4402
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:269
bool isAssignmentOp() const
Definition: Expr.h:3093
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:575
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3129
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, unsigned NumVars)
Build 'linear' clause with given number of variables NumVars.
Definition: OpenMPClause.h:106
This represents 'threads' clause in the '#pragma omp ...' directive.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructExpr::ConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1028
void TypeWasModifiedSafely(QualType T)
Tell the TypeLocBuilder that the type it is storing has been modified in some safe way that doesn't a...
A RAII object to enter scope of a compound statement.
Definition: Sema.h:3613
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:2560
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
param_type_iterator param_type_begin() const
Definition: Type.h:3468
This represents clause 'aligned' in the '#pragma omp ...' directives.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2503
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
ASTContext * Context
QualType RebuildTypeOfType(QualType Underlying)
Build a new typeof(type) type.
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2049
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param)
Definition: ExprCXX.h:1003
OMPClause * RebuildOMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Definition: Decl.h:305
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:720
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2027
This represents implicit clause 'depend' for the '#pragma omp task' directive.
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:132
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:1873
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1740
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2001
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:580
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
Expr - This represents one expression.
Definition: Expr.h:105
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:103
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:4516
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
std::string Label
SourceLocation getMapLoc() const LLVM_READONLY
Fetches location of clause mapping kind.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, unsigned ThisTypeQuals, Fn TransformExceptionSpec)
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:2583
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:2574
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
StmtResult 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)
Build a new MS style inline asm statement.
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:4503
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:54
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
Inits[]
Definition: OpenMPClause.h:136
TemplateArgumentLoc operator*() const
QualType TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, TemplateName Template, CXXScopeSpec &SS)
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2813
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1210
TemplateArgumentLocInventIterator & operator++()
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:2825
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4606
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:213
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3347
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
OMPClause * RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2149
DeclContext * getDeclContext()
Definition: DeclBase.h:416
QualType RebuildDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Name, SourceLocation NameLoc, TemplateArgumentListInfo &Args, bool AllowInjectedClassName)
Build a new typename type that refers to a template-id.
ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLoc, Expr *Length, SourceLocation RBracketLoc)
Build a new array section expression.
SourceLocation Begin
SourceLocation getLParenLoc() const
Returns the location of '('.
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack)
Build a new template name given a template template parameter pack and the.
unsigned getContextParamPosition() const
Definition: Decl.h:3794
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
A namespace alias, stored as a NamespaceAliasDecl*.
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1407
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult TransformStmt(Stmt *S)
Transform the given statement.
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:250
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1613
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:114
Expr * getSubExpr() const
Definition: Expr.h:1741
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1797
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
bool isInstanceMethod() const
Definition: DeclObjC.h:416
bool hasTrailingReturn() const
Definition: Type.h:3452
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2106
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:266
A boolean condition, from 'if', 'while', 'for', or 'do'.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateDecl *Template)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
ConditionKind
Definition: Sema.h:9641
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:1659
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1714
struct CXXOpName CXXOperatorName
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:258
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
Expr * getDevice()
Return device number.
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
Definition: Sema.h:7543
SourceLocation getLParenLoc() const
Returns the location of '('.
const IdentifierInfo * getField() const
Definition: Designator.h:74
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
SourceLocation getCommaLoc()
Get location of ','.
The symbol exists.
Definition: Sema.h:4392
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
OpenMPProcBindClauseKind
OpenMP attributes for 'proc_bind' clause.
Definition: OpenMPKinds.h:51
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:661
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition: ExprCXX.h:1600
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:480
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:960
bool hasObjCLifetime() const
Definition: Type.h:308
TemplateArgumentLocInventIterator operator++(int)
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
SourceLocation getLocStart() const
Returns starting location of directive kind.
Definition: StmtOpenMP.h:168
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
OMPClause * RebuildOMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'task_reduction' clause.
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:2875
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
const IdentifierInfo * getIdentifier() const
Definition: Type.h:4726
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1751
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
This represents 'num_teams' clause in the '#pragma omp ...' directive.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:222
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
const Decl * FoundDecl
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:2957
Kind
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
Definition: ExprCXX.h:2467
This captures a statement into a function.
Definition: Stmt.h:2032
A field in a dependent type, known only by its name.
Definition: Expr.h:1828
TypeLoc getValueLoc() const
Definition: TypeLoc.h:2134
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1340
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3220
SourceLocation getLParenLoc()
Get location of '('.
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2034
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:3255
Encodes a location in the source.
body_range body()
Definition: Stmt.h:605
This represents 'hint' clause in the '#pragma omp ...' directive.
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:2612
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
Definition: OpenMPKinds.h:76
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5489
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:259
SourceLocation getLParenLoc() const
Returns the location of '('.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:33
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:119
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1389
reference front() const
Definition: DeclBase.h:1188
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2816
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:143
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1295
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
OMPClause * RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:467
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:414
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
QualType RebuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Quals)
Build a new qualified type given its unqualified type and type qualifiers.
Expr * getPriority()
Return Priority number.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
OpenMPLinearClauseKind Modifier
Modifier of 'linear' clause.
Definition: OpenMPClause.h:86
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
C-style initialization with assignment.
Definition: Decl.h:768
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:54
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:33
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
Definition: Expr.h:5070
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:83
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2156
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:243
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
static CXXDefaultInitExpr * Create(const ASTContext &C, SourceLocation Loc, FieldDecl *Field)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.h:1067
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:704
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1989
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2804
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition: Stmt.h:2132
TypeLocClass getTypeLocClass() const
Definition: TypeLoc.h:97
OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY
Fetches the map type modifier for the clause.
QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the class type it refers into...
SourceLocation getLParenLoc() const
Returns the location of '('.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
SourceLocation getBegin() const
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6105
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:166
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1434
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1507
No entity found met the criteria.
Definition: Lookup.h:36
SourceLocation getDependencyLoc() const
Get dependency type location.
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
PtrTy get() const
Definition: Ownership.h:74
The name is a dependent name, so the results will differ from one instantiation to the next...
Definition: Sema.h:4399
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2142
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:7531
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2421
Expr * getGrainsize() const
Return safe iteration space distance.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:543
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:262
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:564
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.cpp:1627
Opcode getOpcode() const
Definition: Expr.h:1738
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
QualType getPointeeType() const
Definition: Type.h:2238
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:1745
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:2775
Represents a pack expansion of types.
Definition: Type.h:4787
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1392
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1581
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2816
attr::Kind getKind() const
Definition: Attr.h:84
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2682
QualType getType() const
Definition: Expr.h:127
Represents a template argument.
Definition: TemplateBase.h:40
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:235
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:355
TagTypeKind
The kind of a tag type.
Definition: Type.h:4488
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition: OpenMPKinds.h:67
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2435
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
This represents 'device' clause in the '#pragma omp ...' directive.
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
not evaluated yet, for special member function
UnaryOperatorKind
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
StringRef Name
Definition: USRFinder.cpp:123
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:378
QualType TransformTypeWithDeducedTST(QualType T)
Transform a type that is permitted to produce a DeducedTemplateSpecializationType.
SourceLocation ModifierLoc
Location of linear modifier if any.
Definition: OpenMPClause.h:88
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:2868
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2102
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:63
SourceRange getSourceRange(const SourceRange &Range)
Returns the SourceRange of a SourceRange.
Definition: FixIt.h:34
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
bool isInvalidDecl() const
Definition: DeclBase.h:532
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ functional-style cast expression.
QualType RebuildElaboratedType(SourceLocation KeywordLoc, ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, QualType Named)
Build a new qualified name type.
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2554
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
A constant boolean condition from 'if constexpr'.
static ExprResult Owned(Expr *E)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2017
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'use_device_ptr' clause.
DeclarationName - The name of a declaration.
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:537
Expr * getNumTasks() const
Return safe iteration space distance.
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3565
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
A set of unresolved declarations.
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:216
EnumDecl - Represents an enum.
Definition: Decl.h:3102
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1481
detail::InMemoryDirectory::const_iterator E
ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Build a new C++1z fold-expression.
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1213
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'is_device_ptr' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
A type that was preceded by the 'template' keyword, stored as a Type*.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
bool isImplicitMapType() const LLVM_READONLY
Is this an implicit map type? We have to capture 'IsMapTypeImplicit' from the parser for more informa...
CXXRecordDecl * getNamingClass() const
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:2739
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
Represents a __leave statement.
Definition: Stmt.h:1998
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new label statement.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:134
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:45
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
QualType RebuildIncompleteArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers...
Not an overloaded operator.
Definition: OperatorKinds.h:23
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3784
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS)
Build a new binary operator expression.
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
This file defines OpenMP AST classes for executable directives and clauses.
OMPClause * RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
An implicit indirection through a C++ base class, when the field found is in a base class...
Definition: Expr.h:1831
UnqualTypeLoc getUnqualifiedLoc() const
Definition: TypeLoc.h:260
bool isNull() const
Determine whether this template name is NULL.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init, Sema::ConditionResult Cond)
Start building a new switch statement.
QualType RebuildVariableArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression...
std::iterator_traits< InputIterator >::difference_type difference_type
bool isFunctionType() const
Definition: Type.h:5709
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
Definition: DeclSpec.cpp:1291
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:59
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2360
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:253
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:2594
The template argument is a type.
Definition: TemplateBase.h:48
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.h:2223
OpenMPDefaultClauseKind
OpenMP attributes for 'default' clause.
Definition: OpenMPKinds.h:43
SourceLocation getDistScheduleKindLoc()
Get kind location.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:386
bool isInvalid() const
The template argument is actually a parameter pack.
Definition: TemplateBase.h:72
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
const Expr * Replacement
Definition: AttributeList.h:59
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
bool isUsable() const
Definition: Ownership.h:160
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3222
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, bool IsImplicit)
Build a new co_await expression.
bool isDeduced() const
Definition: Type.h:4195
bool hasAssociatedStmt() const
Returns true if directive has associated statement.
Definition: StmtOpenMP.h:193
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:886
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13074
SourceLocation getAttrLoc() const
Definition: Stmt.h:885
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3224
An integral condition for a 'switch' statement.
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1090
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:146
Call-style initialization (C++98)
Definition: Decl.h:769
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::ConditionResult Cond, Stmt *Body)
Build a new while statement.
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:47
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2378
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5569
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:246
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
BoundNodesTreeBuilder *const Builder
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Build a new template argument pack expansion.
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4695
This represents 'num_tasks' clause in the '#pragma omp ...' directive.
bool isObjCObjectPointerType() const
Definition: Type.h:5784
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword)
Build a new C++11 auto type.
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:29
An index into an array.
Definition: Expr.h:1824
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2024
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:92
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1866
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1432
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4537
TryCaptureKind
Definition: Sema.h:3950
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1396
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:5982
Location information for a TemplateArgument.
Definition: TemplateBase.h:369
Expr * getThreadLimit()
Return ThreadLimit number.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:97
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
Definition: TemplateBase.h:323
The receiver is a class.
Definition: ExprObjC.h:1003
LookupResultKind getResultKind() const
Definition: Lookup.h:307
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:245
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Build a new expression pack expansion.
const StringRef Input
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2206
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:2571
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1417
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1595
ExprResult ExprError()
Definition: Ownership.h:268
This represents 'dist_schedule' clause in the '#pragma omp ...' directive.
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
Definition: Type.h:4192
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2380
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
SourceLocation getRBracLoc() const
Definition: Stmt.h:654
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:218
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:181
static OpaquePtr make(QualTypeP)
Definition: Ownership.h:54
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:80
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc)
Build a new GNU statement expression.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:953
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:402
SourceLocation getLParenLoc() const
Returns the location of '('.
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4297
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
Iterator adaptor that invents template argument location information for each of the template argumen...
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
Definition: Decl.h:675
ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:110
static Designator getArray(Expr *Index, SourceLocation LBracketLoc)
Definition: Designator.h:136
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
Definition: DeclBase.h:407
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:304
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:1008
TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:1880
Represents a C++ namespace alias.
Definition: DeclCXX.h:2861
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1616
No keyword precedes the qualified type name.
Definition: Type.h:4518
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
SourceLocation getLocEnd() const
Returns ending location of directive.
Definition: StmtOpenMP.h:170
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
static Designator getArrayRange(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Definition: Designator.h:146
The receiver is a superclass.
Definition: ExprObjC.h:1007
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
Stmt * getAssociatedStmt() const
Returns statement associated with the directive.
Definition: StmtOpenMP.h:196
The global specifier '::'. There is no stored value.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.cpp:257
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:471
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:331
SourceLocation ColonLoc
Location of ':'.
Definition: OpenMPClause.h:90
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, Expr *ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:4818
Stmt * getSubStmt()
Definition: Stmt.h:889
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3254
OMPClause * RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type...
QualType RebuildTypedefType(TypedefNameDecl *Typedef)
Build a new typedef type.
The symbol does not exist.
Definition: Sema.h:4395
void clear()
Clears out any current state.
Definition: Lookup.h:540
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:4549
static StmtResult Owned(Stmt *S)
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1876
const NamedDecl * Result
Definition: USRFinder.cpp:70
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
Attr - This represents one attribute.
Definition: Attr.h:43
This represents clause 'use_device_ptr' in the '#pragma omp ...' directives.
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, Sema::ConditionResult Cond, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, SourceLocation RParenLoc)
Build a new inline asm statement.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:5516
bool isPointerType() const
Definition: Type.h:5712
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.