clang  14.0.0git
TreeTransform.h
Go to the documentation of this file.
1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===//
7 //
8 // This file implements a semantic tree transformation that takes a given
9 // AST and rebuilds it, possibly transforming some nodes in the process.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15 
16 #include "CoroutineStmtBuilder.h"
17 #include "TypeLocBuilder.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprConcepts.h"
23 #include "clang/AST/ExprCXX.h"
24 #include "clang/AST/ExprObjC.h"
25 #include "clang/AST/ExprOpenMP.h"
26 #include "clang/AST/OpenMPClause.h"
27 #include "clang/AST/Stmt.h"
28 #include "clang/AST/StmtCXX.h"
29 #include "clang/AST/StmtObjC.h"
30 #include "clang/AST/StmtOpenMP.h"
33 #include "clang/Sema/Designator.h"
34 #include "clang/Sema/Lookup.h"
35 #include "clang/Sema/Ownership.h"
37 #include "clang/Sema/ScopeInfo.h"
40 #include "llvm/ADT/ArrayRef.h"
41 #include "llvm/Support/ErrorHandling.h"
42 #include <algorithm>
43 
44 using namespace llvm::omp;
45 
46 namespace clang {
47 using namespace sema;
48 
49 /// A semantic tree transformation that allows one to transform one
50 /// abstract syntax tree into another.
51 ///
52 /// A new tree transformation is defined by creating a new subclass \c X of
53 /// \c TreeTransform<X> and then overriding certain operations to provide
54 /// behavior specific to that transformation. For example, template
55 /// instantiation is implemented as a tree transformation where the
56 /// transformation of TemplateTypeParmType nodes involves substituting the
57 /// template arguments for their corresponding template parameters; a similar
58 /// transformation is performed for non-type template parameters and
59 /// template template parameters.
60 ///
61 /// This tree-transformation template uses static polymorphism to allow
62 /// subclasses to customize any of its operations. Thus, a subclass can
63 /// override any of the transformation or rebuild operators by providing an
64 /// operation with the same signature as the default implementation. The
65 /// overriding function should not be virtual.
66 ///
67 /// Semantic tree transformations are split into two stages, either of which
68 /// can be replaced by a subclass. The "transform" step transforms an AST node
69 /// or the parts of an AST node using the various transformation functions,
70 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
71 /// node of the appropriate kind from the pieces. The default transformation
72 /// routines recursively transform the operands to composite AST nodes (e.g.,
73 /// the pointee type of a PointerType node) and, if any of those operand nodes
74 /// were changed by the transformation, invokes the rebuild operation to create
75 /// a new AST node.
76 ///
77 /// Subclasses can customize the transformation at various levels. The
78 /// most coarse-grained transformations involve replacing TransformType(),
79 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
80 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
81 /// new implementations.
82 ///
83 /// For more fine-grained transformations, subclasses can replace any of the
84 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
85 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
86 /// replacing TransformTemplateTypeParmType() allows template instantiation
87 /// to substitute template arguments for their corresponding template
88 /// parameters. Additionally, subclasses can override the \c RebuildXXX
89 /// functions to control how AST nodes are rebuilt when their operands change.
90 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
91 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
92 /// be able to use more efficient rebuild steps.
93 ///
94 /// There are a handful of other functions that can be overridden, allowing one
95 /// to avoid traversing nodes that don't need any transformation
96 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
97 /// operands have not changed (\c AlwaysRebuild()), and customize the
98 /// default locations and entity names used for type-checking
99 /// (\c getBaseLocation(), \c getBaseEntity()).
100 template<typename Derived>
102  /// Private RAII object that helps us forget and then re-remember
103  /// the template argument corresponding to a partially-substituted parameter
104  /// pack.
105  class ForgetPartiallySubstitutedPackRAII {
106  Derived &Self;
107  TemplateArgument Old;
108 
109  public:
110  ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
111  Old = Self.ForgetPartiallySubstitutedPack();
112  }
113 
114  ~ForgetPartiallySubstitutedPackRAII() {
115  Self.RememberPartiallySubstitutedPack(Old);
116  }
117  };
118 
119 protected:
121 
122  /// The set of local declarations that have been transformed, for
123  /// cases where we are forced to build new declarations within the transformer
124  /// rather than in the subclass (e.g., lambda closure types).
125  llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
126 
127 public:
128  /// Initializes a new tree transformer.
129  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
130 
131  /// Retrieves a reference to the derived class.
132  Derived &getDerived() { return static_cast<Derived&>(*this); }
133 
134  /// Retrieves a reference to the derived class.
135  const Derived &getDerived() const {
136  return static_cast<const Derived&>(*this);
137  }
138 
139  static inline ExprResult Owned(Expr *E) { return E; }
140  static inline StmtResult Owned(Stmt *S) { return S; }
141 
142  /// Retrieves a reference to the semantic analysis object used for
143  /// this tree transform.
144  Sema &getSema() const { return SemaRef; }
145 
146  /// Whether the transformation should always rebuild AST nodes, even
147  /// if none of the children have changed.
148  ///
149  /// Subclasses may override this function to specify when the transformation
150  /// should rebuild all AST nodes.
151  ///
152  /// We must always rebuild all AST nodes when performing variadic template
153  /// pack expansion, in order to avoid violating the AST invariant that each
154  /// statement node appears at most once in its containing declaration.
155  bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
156 
157  /// Whether the transformation is forming an expression or statement that
158  /// replaces the original. In this case, we'll reuse mangling numbers from
159  /// existing lambdas.
160  bool ReplacingOriginal() { return false; }
161 
162  /// Wether CXXConstructExpr can be skipped when they are implicit.
163  /// They will be reconstructed when used if needed.
164  /// This is useful when the user that cause rebuilding of the
165  /// CXXConstructExpr is outside of the expression at which the TreeTransform
166  /// started.
167  bool AllowSkippingCXXConstructExpr() { return true; }
168 
169  /// Returns the location of the entity being transformed, if that
170  /// information was not available elsewhere in the AST.
171  ///
172  /// By default, returns no source-location information. Subclasses can
173  /// provide an alternative implementation that provides better location
174  /// information.
176 
177  /// Returns the name of the entity being transformed, if that
178  /// information was not available elsewhere in the AST.
179  ///
180  /// By default, returns an empty name. Subclasses can provide an alternative
181  /// implementation with a more precise name.
183 
184  /// Sets the "base" location and entity when that
185  /// information is known based on another transformation.
186  ///
187  /// By default, the source location and entity are ignored. Subclasses can
188  /// override this function to provide a customized implementation.
189  void setBase(SourceLocation Loc, DeclarationName Entity) { }
190 
191  /// RAII object that temporarily sets the base location and entity
192  /// used for reporting diagnostics in types.
194  TreeTransform &Self;
195  SourceLocation OldLocation;
196  DeclarationName OldEntity;
197 
198  public:
200  DeclarationName Entity) : Self(Self) {
201  OldLocation = Self.getDerived().getBaseLocation();
202  OldEntity = Self.getDerived().getBaseEntity();
203 
204  if (Location.isValid())
205  Self.getDerived().setBase(Location, Entity);
206  }
207 
209  Self.getDerived().setBase(OldLocation, OldEntity);
210  }
211  };
212 
213  /// Determine whether the given type \p T has already been
214  /// transformed.
215  ///
216  /// Subclasses can provide an alternative implementation of this routine
217  /// to short-circuit evaluation when it is known that a given type will
218  /// not change. For example, template instantiation need not traverse
219  /// non-dependent types.
221  return T.isNull();
222  }
223 
224  /// Transform a template parameter depth level.
225  ///
226  /// During a transformation that transforms template parameters, this maps
227  /// an old template parameter depth to a new depth.
228  unsigned TransformTemplateDepth(unsigned Depth) {
229  return Depth;
230  }
231 
232  /// Determine whether the given call argument should be dropped, e.g.,
233  /// because it is a default argument.
234  ///
235  /// Subclasses can provide an alternative implementation of this routine to
236  /// determine which kinds of call arguments get dropped. By default,
237  /// CXXDefaultArgument nodes are dropped (prior to transformation).
239  return E->isDefaultArgument();
240  }
241 
242  /// Determine whether we should expand a pack expansion with the
243  /// given set of parameter packs into separate arguments by repeatedly
244  /// transforming the pattern.
245  ///
246  /// By default, the transformer never tries to expand pack expansions.
247  /// Subclasses can override this routine to provide different behavior.
248  ///
249  /// \param EllipsisLoc The location of the ellipsis that identifies the
250  /// pack expansion.
251  ///
252  /// \param PatternRange The source range that covers the entire pattern of
253  /// the pack expansion.
254  ///
255  /// \param Unexpanded The set of unexpanded parameter packs within the
256  /// pattern.
257  ///
258  /// \param ShouldExpand Will be set to \c true if the transformer should
259  /// expand the corresponding pack expansions into separate arguments. When
260  /// set, \c NumExpansions must also be set.
261  ///
262  /// \param RetainExpansion Whether the caller should add an unexpanded
263  /// pack expansion after all of the expanded arguments. This is used
264  /// when extending explicitly-specified template argument packs per
265  /// C++0x [temp.arg.explicit]p9.
266  ///
267  /// \param NumExpansions The number of separate arguments that will be in
268  /// the expanded form of the corresponding pack expansion. This is both an
269  /// input and an output parameter, which can be set by the caller if the
270  /// number of expansions is known a priori (e.g., due to a prior substitution)
271  /// and will be set by the callee when the number of expansions is known.
272  /// The callee must set this value when \c ShouldExpand is \c true; it may
273  /// set this value in other cases.
274  ///
275  /// \returns true if an error occurred (e.g., because the parameter packs
276  /// are to be instantiated with arguments of different lengths), false
277  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
278  /// must be set.
280  SourceRange PatternRange,
282  bool &ShouldExpand,
283  bool &RetainExpansion,
284  Optional<unsigned> &NumExpansions) {
285  ShouldExpand = false;
286  return false;
287  }
288 
289  /// "Forget" about the partially-substituted pack template argument,
290  /// when performing an instantiation that must preserve the parameter pack
291  /// use.
292  ///
293  /// This routine is meant to be overridden by the template instantiator.
295  return TemplateArgument();
296  }
297 
298  /// "Remember" the partially-substituted pack template argument
299  /// after performing an instantiation that must preserve the parameter pack
300  /// use.
301  ///
302  /// This routine is meant to be overridden by the template instantiator.
304 
305  /// Note to the derived class when a function parameter pack is
306  /// being expanded.
308 
309  /// Transforms the given type into another type.
310  ///
311  /// By default, this routine transforms a type by creating a
312  /// TypeSourceInfo for it and delegating to the appropriate
313  /// function. This is expensive, but we don't mind, because
314  /// this method is deprecated anyway; all users should be
315  /// switched to storing TypeSourceInfos.
316  ///
317  /// \returns the transformed type.
318  QualType TransformType(QualType T);
319 
320  /// Transforms the given type-with-location into a new
321  /// type-with-location.
322  ///
323  /// By default, this routine transforms a type by delegating to the
324  /// appropriate TransformXXXType to build a new type. Subclasses
325  /// may override this function (to take over all type
326  /// transformations) or some set of the TransformXXXType functions
327  /// to alter the transformation.
328  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
329 
330  /// Transform the given type-with-location into a new
331  /// type, collecting location information in the given builder
332  /// as necessary.
333  ///
334  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
335 
336  /// Transform a type that is permitted to produce a
337  /// DeducedTemplateSpecializationType.
338  ///
339  /// This is used in the (relatively rare) contexts where it is acceptable
340  /// for transformation to produce a class template type with deduced
341  /// template arguments.
342  /// @{
343  QualType TransformTypeWithDeducedTST(QualType T);
344  TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
345  /// @}
346 
347  /// The reason why the value of a statement is not discarded, if any.
352  };
353 
354  /// Transform the given statement.
355  ///
356  /// By default, this routine transforms a statement by delegating to the
357  /// appropriate TransformXXXStmt function to transform a specific kind of
358  /// statement or the TransformExpr() function to transform an expression.
359  /// Subclasses may override this function to transform statements using some
360  /// other mechanism.
361  ///
362  /// \returns the transformed statement.
363  StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
364 
365  /// Transform the given statement.
366  ///
367  /// By default, this routine transforms a statement by delegating to the
368  /// appropriate TransformOMPXXXClause function to transform a specific kind
369  /// of clause. Subclasses may override this function to transform statements
370  /// using some other mechanism.
371  ///
372  /// \returns the transformed OpenMP clause.
373  OMPClause *TransformOMPClause(OMPClause *S);
374 
375  /// Transform the given attribute.
376  ///
377  /// By default, this routine transforms a statement by delegating to the
378  /// appropriate TransformXXXAttr function to transform a specific kind
379  /// of attribute. Subclasses may override this function to transform
380  /// attributed statements using some other mechanism.
381  ///
382  /// \returns the transformed attribute
383  const Attr *TransformAttr(const Attr *S);
384 
385 /// Transform the specified attribute.
386 ///
387 /// Subclasses should override the transformation of attributes with a pragma
388 /// spelling to transform expressions stored within the attribute.
389 ///
390 /// \returns the transformed attribute.
391 #define ATTR(X)
392 #define PRAGMA_SPELLING_ATTR(X) \
393  const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
394 #include "clang/Basic/AttrList.inc"
395 
396  /// Transform the given expression.
397  ///
398  /// By default, this routine transforms an expression by delegating to the
399  /// appropriate TransformXXXExpr function to build a new expression.
400  /// Subclasses may override this function to transform expressions using some
401  /// other mechanism.
402  ///
403  /// \returns the transformed expression.
404  ExprResult TransformExpr(Expr *E);
405 
406  /// Transform the given initializer.
407  ///
408  /// By default, this routine transforms an initializer by stripping off the
409  /// semantic nodes added by initialization, then passing the result to
410  /// TransformExpr or TransformExprs.
411  ///
412  /// \returns the transformed initializer.
413  ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
414 
415  /// Transform the given list of expressions.
416  ///
417  /// This routine transforms a list of expressions by invoking
418  /// \c TransformExpr() for each subexpression. However, it also provides
419  /// support for variadic templates by expanding any pack expansions (if the
420  /// derived class permits such expansion) along the way. When pack expansions
421  /// are present, the number of outputs may not equal the number of inputs.
422  ///
423  /// \param Inputs The set of expressions to be transformed.
424  ///
425  /// \param NumInputs The number of expressions in \c Inputs.
426  ///
427  /// \param IsCall If \c true, then this transform is being performed on
428  /// function-call arguments, and any arguments that should be dropped, will
429  /// be.
430  ///
431  /// \param Outputs The transformed input expressions will be added to this
432  /// vector.
433  ///
434  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
435  /// due to transformation.
436  ///
437  /// \returns true if an error occurred, false otherwise.
438  bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
439  SmallVectorImpl<Expr *> &Outputs,
440  bool *ArgChanged = nullptr);
441 
442  /// Transform the given declaration, which is referenced from a type
443  /// or expression.
444  ///
445  /// By default, acts as the identity function on declarations, unless the
446  /// transformer has had to transform the declaration itself. Subclasses
447  /// may override this function to provide alternate behavior.
449  llvm::DenseMap<Decl *, Decl *>::iterator Known
450  = TransformedLocalDecls.find(D);
451  if (Known != TransformedLocalDecls.end())
452  return Known->second;
453 
454  return D;
455  }
456 
457  /// Transform the specified condition.
458  ///
459  /// By default, this transforms the variable and expression and rebuilds
460  /// the condition.
461  Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
462  Expr *Expr,
464 
465  /// Transform the attributes associated with the given declaration and
466  /// place them on the new declaration.
467  ///
468  /// By default, this operation does nothing. Subclasses may override this
469  /// behavior to transform attributes.
470  void transformAttrs(Decl *Old, Decl *New) { }
471 
472  /// Note that a local declaration has been transformed by this
473  /// transformer.
474  ///
475  /// Local declarations are typically transformed via a call to
476  /// TransformDefinition. However, in some cases (e.g., lambda expressions),
477  /// the transformer itself has to transform the declarations. This routine
478  /// can be overridden by a subclass that keeps track of such mappings.
480  assert(New.size() == 1 &&
481  "must override transformedLocalDecl if performing pack expansion");
482  TransformedLocalDecls[Old] = New.front();
483  }
484 
485  /// Transform the definition of the given declaration.
486  ///
487  /// By default, invokes TransformDecl() to transform the declaration.
488  /// Subclasses may override this function to provide alternate behavior.
490  return getDerived().TransformDecl(Loc, D);
491  }
492 
493  /// Transform the given declaration, which was the first part of a
494  /// nested-name-specifier in a member access expression.
495  ///
496  /// This specific declaration transformation only applies to the first
497  /// identifier in a nested-name-specifier of a member access expression, e.g.,
498  /// the \c T in \c x->T::member
499  ///
500  /// By default, invokes TransformDecl() to transform the declaration.
501  /// Subclasses may override this function to provide alternate behavior.
503  return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
504  }
505 
506  /// Transform the set of declarations in an OverloadExpr.
507  bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
508  LookupResult &R);
509 
510  /// Transform the given nested-name-specifier with source-location
511  /// information.
512  ///
513  /// By default, transforms all of the types and declarations within the
514  /// nested-name-specifier. Subclasses may override this function to provide
515  /// alternate behavior.
517  TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
518  QualType ObjectType = QualType(),
519  NamedDecl *FirstQualifierInScope = nullptr);
520 
521  /// Transform the given declaration name.
522  ///
523  /// By default, transforms the types of conversion function, constructor,
524  /// and destructor names and then (if needed) rebuilds the declaration name.
525  /// Identifiers and selectors are returned unmodified. Subclasses may
526  /// override this function to provide alternate behavior.
528  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
529 
530  bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs,
533  TransformTypeRequirement(concepts::TypeRequirement *Req);
535  TransformExprRequirement(concepts::ExprRequirement *Req);
537  TransformNestedRequirement(concepts::NestedRequirement *Req);
538 
539  /// Transform the given template name.
540  ///
541  /// \param SS The nested-name-specifier that qualifies the template
542  /// name. This nested-name-specifier must already have been transformed.
543  ///
544  /// \param Name The template name to transform.
545  ///
546  /// \param NameLoc The source location of the template name.
547  ///
548  /// \param ObjectType If we're translating a template name within a member
549  /// access expression, this is the type of the object whose member template
550  /// is being referenced.
551  ///
552  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
553  /// also refers to a name within the current (lexical) scope, this is the
554  /// declaration it refers to.
555  ///
556  /// By default, transforms the template name by transforming the declarations
557  /// and nested-name-specifiers that occur within the template name.
558  /// Subclasses may override this function to provide alternate behavior.
560  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
561  SourceLocation NameLoc,
562  QualType ObjectType = QualType(),
563  NamedDecl *FirstQualifierInScope = nullptr,
564  bool AllowInjectedClassName = false);
565 
566  /// Transform the given template argument.
567  ///
568  /// By default, this operation transforms the type, expression, or
569  /// declaration stored within the template argument and constructs a
570  /// new template argument from the transformed result. Subclasses may
571  /// override this function to provide alternate behavior.
572  ///
573  /// Returns true if there was an error.
574  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
575  TemplateArgumentLoc &Output,
576  bool Uneval = false);
577 
578  /// Transform the given set of template arguments.
579  ///
580  /// By default, this operation transforms all of the template arguments
581  /// in the input set using \c TransformTemplateArgument(), and appends
582  /// the transformed arguments to the output list.
583  ///
584  /// Note that this overload of \c TransformTemplateArguments() is merely
585  /// a convenience function. Subclasses that wish to override this behavior
586  /// should override the iterator-based member template version.
587  ///
588  /// \param Inputs The set of template arguments to be transformed.
589  ///
590  /// \param NumInputs The number of template arguments in \p Inputs.
591  ///
592  /// \param Outputs The set of transformed template arguments output by this
593  /// routine.
594  ///
595  /// Returns true if an error occurred.
597  unsigned NumInputs,
598  TemplateArgumentListInfo &Outputs,
599  bool Uneval = false) {
600  return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
601  Uneval);
602  }
603 
604  /// Transform the given set of template arguments.
605  ///
606  /// By default, this operation transforms all of the template arguments
607  /// in the input set using \c TransformTemplateArgument(), and appends
608  /// the transformed arguments to the output list.
609  ///
610  /// \param First An iterator to the first template argument.
611  ///
612  /// \param Last An iterator one step past the last template argument.
613  ///
614  /// \param Outputs The set of transformed template arguments output by this
615  /// routine.
616  ///
617  /// Returns true if an error occurred.
618  template<typename InputIterator>
619  bool TransformTemplateArguments(InputIterator First,
620  InputIterator Last,
621  TemplateArgumentListInfo &Outputs,
622  bool Uneval = false);
623 
624  /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
625  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
626  TemplateArgumentLoc &ArgLoc);
627 
628  /// Fakes up a TypeSourceInfo for a type.
630  return SemaRef.Context.getTrivialTypeSourceInfo(T,
631  getDerived().getBaseLocation());
632  }
633 
634 #define ABSTRACT_TYPELOC(CLASS, PARENT)
635 #define TYPELOC(CLASS, PARENT) \
636  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
637 #include "clang/AST/TypeLocNodes.def"
638 
639  template<typename Fn>
640  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
641  FunctionProtoTypeLoc TL,
642  CXXRecordDecl *ThisContext,
643  Qualifiers ThisTypeQuals,
644  Fn TransformExceptionSpec);
645 
646  bool TransformExceptionSpec(SourceLocation Loc,
647  FunctionProtoType::ExceptionSpecInfo &ESI,
648  SmallVectorImpl<QualType> &Exceptions,
649  bool &Changed);
650 
651  StmtResult TransformSEHHandler(Stmt *Handler);
652 
653  QualType
654  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
655  TemplateSpecializationTypeLoc TL,
656  TemplateName Template);
657 
658  QualType
659  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
660  DependentTemplateSpecializationTypeLoc TL,
661  TemplateName Template,
662  CXXScopeSpec &SS);
663 
664  QualType TransformDependentTemplateSpecializationType(
665  TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
666  NestedNameSpecifierLoc QualifierLoc);
667 
668  /// Transforms the parameters of a function type into the
669  /// given vectors.
670  ///
671  /// The result vectors should be kept in sync; null entries in the
672  /// variables vector are acceptable.
673  ///
674  /// Return true on error.
675  bool TransformFunctionTypeParams(
676  SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
677  const QualType *ParamTypes,
678  const FunctionProtoType::ExtParameterInfo *ParamInfos,
679  SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
680  Sema::ExtParameterInfoBuilder &PInfos);
681 
682  /// Transforms a single function-type parameter. Return null
683  /// on error.
684  ///
685  /// \param indexAdjustment - A number to add to the parameter's
686  /// scope index; can be negative
687  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
688  int indexAdjustment,
689  Optional<unsigned> NumExpansions,
690  bool ExpectParameterPack);
691 
692  /// Transform the body of a lambda-expression.
693  StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body);
694  /// Alternative implementation of TransformLambdaBody that skips transforming
695  /// the body.
696  StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
697 
698  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
699 
700  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
701  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
702 
704  TemplateParameterList *TPL) {
705  return TPL;
706  }
707 
708  ExprResult TransformAddressOfOperand(Expr *E);
709 
710  ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
711  bool IsAddressOfOperand,
712  TypeSourceInfo **RecoveryTSI);
713 
714  ExprResult TransformParenDependentScopeDeclRefExpr(
715  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
716  TypeSourceInfo **RecoveryTSI);
717 
718  StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
719 
720 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
721 // amount of stack usage with clang.
722 #define STMT(Node, Parent) \
723  LLVM_ATTRIBUTE_NOINLINE \
724  StmtResult Transform##Node(Node *S);
725 #define VALUESTMT(Node, Parent) \
726  LLVM_ATTRIBUTE_NOINLINE \
727  StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
728 #define EXPR(Node, Parent) \
729  LLVM_ATTRIBUTE_NOINLINE \
730  ExprResult Transform##Node(Node *E);
731 #define ABSTRACT_STMT(Stmt)
732 #include "clang/AST/StmtNodes.inc"
733 
734 #define GEN_CLANG_CLAUSE_CLASS
735 #define CLAUSE_CLASS(Enum, Str, Class) \
736  LLVM_ATTRIBUTE_NOINLINE \
737  OMPClause *Transform##Class(Class *S);
738 #include "llvm/Frontend/OpenMP/OMP.inc"
739 
740  /// Build a new qualified type given its unqualified type and type location.
741  ///
742  /// By default, this routine adds type qualifiers only to types that can
743  /// have qualifiers, and silently suppresses those qualifiers that are not
744  /// permitted. Subclasses may override this routine to provide different
745  /// behavior.
746  QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
747 
748  /// Build a new pointer type given its pointee type.
749  ///
750  /// By default, performs semantic analysis when building the pointer type.
751  /// Subclasses may override this routine to provide different behavior.
752  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
753 
754  /// Build a new block pointer type given its pointee type.
755  ///
756  /// By default, performs semantic analysis when building the block pointer
757  /// type. Subclasses may override this routine to provide different behavior.
758  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
759 
760  /// Build a new reference type given the type it references.
761  ///
762  /// By default, performs semantic analysis when building the
763  /// reference type. Subclasses may override this routine to provide
764  /// different behavior.
765  ///
766  /// \param LValue whether the type was written with an lvalue sigil
767  /// or an rvalue sigil.
768  QualType RebuildReferenceType(QualType ReferentType,
769  bool LValue,
770  SourceLocation Sigil);
771 
772  /// Build a new member pointer type given the pointee type and the
773  /// class type it refers into.
774  ///
775  /// By default, performs semantic analysis when building the member pointer
776  /// type. Subclasses may override this routine to provide different behavior.
777  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
778  SourceLocation Sigil);
779 
780  QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
781  SourceLocation ProtocolLAngleLoc,
782  ArrayRef<ObjCProtocolDecl *> Protocols,
783  ArrayRef<SourceLocation> ProtocolLocs,
784  SourceLocation ProtocolRAngleLoc);
785 
786  /// Build an Objective-C object type.
787  ///
788  /// By default, performs semantic analysis when building the object type.
789  /// Subclasses may override this routine to provide different behavior.
790  QualType RebuildObjCObjectType(QualType BaseType,
791  SourceLocation Loc,
792  SourceLocation TypeArgsLAngleLoc,
793  ArrayRef<TypeSourceInfo *> TypeArgs,
794  SourceLocation TypeArgsRAngleLoc,
795  SourceLocation ProtocolLAngleLoc,
796  ArrayRef<ObjCProtocolDecl *> Protocols,
797  ArrayRef<SourceLocation> ProtocolLocs,
798  SourceLocation ProtocolRAngleLoc);
799 
800  /// Build a new Objective-C object pointer type given the pointee type.
801  ///
802  /// By default, directly builds the pointer type, with no additional semantic
803  /// analysis.
804  QualType RebuildObjCObjectPointerType(QualType PointeeType,
805  SourceLocation Star);
806 
807  /// Build a new array type given the element type, size
808  /// modifier, size of the array (if known), size expression, and index type
809  /// qualifiers.
810  ///
811  /// By default, performs semantic analysis when building the array type.
812  /// Subclasses may override this routine to provide different behavior.
813  /// Also by default, all of the other Rebuild*Array
814  QualType RebuildArrayType(QualType ElementType,
815  ArrayType::ArraySizeModifier SizeMod,
816  const llvm::APInt *Size,
817  Expr *SizeExpr,
818  unsigned IndexTypeQuals,
819  SourceRange BracketsRange);
820 
821  /// Build a new constant array type given the element type, size
822  /// modifier, (known) size of the array, and index type qualifiers.
823  ///
824  /// By default, performs semantic analysis when building the array type.
825  /// Subclasses may override this routine to provide different behavior.
826  QualType RebuildConstantArrayType(QualType ElementType,
827  ArrayType::ArraySizeModifier SizeMod,
828  const llvm::APInt &Size,
829  Expr *SizeExpr,
830  unsigned IndexTypeQuals,
831  SourceRange BracketsRange);
832 
833  /// Build a new incomplete array type given the element type, size
834  /// modifier, and index type qualifiers.
835  ///
836  /// By default, performs semantic analysis when building the array type.
837  /// Subclasses may override this routine to provide different behavior.
838  QualType RebuildIncompleteArrayType(QualType ElementType,
839  ArrayType::ArraySizeModifier SizeMod,
840  unsigned IndexTypeQuals,
841  SourceRange BracketsRange);
842 
843  /// Build a new variable-length array type given the element type,
844  /// size modifier, size expression, and index type qualifiers.
845  ///
846  /// By default, performs semantic analysis when building the array type.
847  /// Subclasses may override this routine to provide different behavior.
848  QualType RebuildVariableArrayType(QualType ElementType,
849  ArrayType::ArraySizeModifier SizeMod,
850  Expr *SizeExpr,
851  unsigned IndexTypeQuals,
852  SourceRange BracketsRange);
853 
854  /// Build a new dependent-sized array type given the element type,
855  /// size modifier, size expression, and index type qualifiers.
856  ///
857  /// By default, performs semantic analysis when building the array type.
858  /// Subclasses may override this routine to provide different behavior.
859  QualType RebuildDependentSizedArrayType(QualType ElementType,
860  ArrayType::ArraySizeModifier SizeMod,
861  Expr *SizeExpr,
862  unsigned IndexTypeQuals,
863  SourceRange BracketsRange);
864 
865  /// Build a new vector type given the element type and
866  /// number of elements.
867  ///
868  /// By default, performs semantic analysis when building the vector type.
869  /// Subclasses may override this routine to provide different behavior.
870  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
871  VectorType::VectorKind VecKind);
872 
873  /// Build a new potentially dependently-sized extended vector type
874  /// given the element type and number of elements.
875  ///
876  /// By default, performs semantic analysis when building the vector type.
877  /// Subclasses may override this routine to provide different behavior.
878  QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
879  SourceLocation AttributeLoc,
880  VectorType::VectorKind);
881 
882  /// Build a new extended vector type given the element type and
883  /// number of elements.
884  ///
885  /// By default, performs semantic analysis when building the vector type.
886  /// Subclasses may override this routine to provide different behavior.
887  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
888  SourceLocation AttributeLoc);
889 
890  /// Build a new potentially dependently-sized extended vector type
891  /// given the element type and number of elements.
892  ///
893  /// By default, performs semantic analysis when building the vector type.
894  /// Subclasses may override this routine to provide different behavior.
895  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
896  Expr *SizeExpr,
897  SourceLocation AttributeLoc);
898 
899  /// Build a new matrix type given the element type and dimensions.
900  QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
901  unsigned NumColumns);
902 
903  /// Build a new matrix type given the type and dependently-defined
904  /// dimensions.
905  QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr,
906  Expr *ColumnExpr,
907  SourceLocation AttributeLoc);
908 
909  /// Build a new DependentAddressSpaceType or return the pointee
910  /// type variable with the correct address space (retrieved from
911  /// AddrSpaceExpr) applied to it. The former will be returned in cases
912  /// where the address space remains dependent.
913  ///
914  /// By default, performs semantic analysis when building the type with address
915  /// space applied. Subclasses may override this routine to provide different
916  /// behavior.
917  QualType RebuildDependentAddressSpaceType(QualType PointeeType,
918  Expr *AddrSpaceExpr,
919  SourceLocation AttributeLoc);
920 
921  /// Build a new function type.
922  ///
923  /// By default, performs semantic analysis when building the function type.
924  /// Subclasses may override this routine to provide different behavior.
925  QualType RebuildFunctionProtoType(QualType T,
926  MutableArrayRef<QualType> ParamTypes,
927  const FunctionProtoType::ExtProtoInfo &EPI);
928 
929  /// Build a new unprototyped function type.
930  QualType RebuildFunctionNoProtoType(QualType ResultType);
931 
932  /// Rebuild an unresolved typename type, given the decl that
933  /// the UnresolvedUsingTypenameDecl was transformed to.
934  QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
935 
936  /// Build a new typedef type.
938  return SemaRef.Context.getTypeDeclType(Typedef);
939  }
940 
941  /// Build a new MacroDefined type.
943  const IdentifierInfo *MacroII) {
944  return SemaRef.Context.getMacroQualifiedType(T, MacroII);
945  }
946 
947  /// Build a new class/struct/union type.
949  return SemaRef.Context.getTypeDeclType(Record);
950  }
951 
952  /// Build a new Enum type.
954  return SemaRef.Context.getTypeDeclType(Enum);
955  }
956 
957  /// Build a new typeof(expr) type.
958  ///
959  /// By default, performs semantic analysis when building the typeof type.
960  /// Subclasses may override this routine to provide different behavior.
961  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
962 
963  /// Build a new typeof(type) type.
964  ///
965  /// By default, builds a new TypeOfType with the given underlying type.
966  QualType RebuildTypeOfType(QualType Underlying);
967 
968  /// Build a new unary transform type.
969  QualType RebuildUnaryTransformType(QualType BaseType,
971  SourceLocation Loc);
972 
973  /// Build a new C++11 decltype type.
974  ///
975  /// By default, performs semantic analysis when building the decltype type.
976  /// Subclasses may override this routine to provide different behavior.
977  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
978 
979  /// Build a new C++11 auto type.
980  ///
981  /// By default, builds a new AutoType with the given deduced type.
983  ConceptDecl *TypeConstraintConcept,
984  ArrayRef<TemplateArgument> TypeConstraintArgs) {
985  // Note, IsDependent is always false here: we implicitly convert an 'auto'
986  // which has been deduced to a dependent type into an undeduced 'auto', so
987  // that we'll retry deduction after the transformation.
988  return SemaRef.Context.getAutoType(Deduced, Keyword,
989  /*IsDependent*/ false, /*IsPack=*/false,
990  TypeConstraintConcept,
991  TypeConstraintArgs);
992  }
993 
994  /// By default, builds a new DeducedTemplateSpecializationType with the given
995  /// deduced type.
997  QualType Deduced) {
999  Template, Deduced, /*IsDependent*/ false);
1000  }
1001 
1002  /// Build a new template specialization type.
1003  ///
1004  /// By default, performs semantic analysis when building the template
1005  /// specialization type. Subclasses may override this routine to provide
1006  /// different behavior.
1007  QualType RebuildTemplateSpecializationType(TemplateName Template,
1008  SourceLocation TemplateLoc,
1009  TemplateArgumentListInfo &Args);
1010 
1011  /// Build a new parenthesized type.
1012  ///
1013  /// By default, builds a new ParenType type from the inner type.
1014  /// Subclasses may override this routine to provide different behavior.
1016  return SemaRef.BuildParenType(InnerType);
1017  }
1018 
1019  /// Build a new qualified name type.
1020  ///
1021  /// By default, builds a new ElaboratedType type from the keyword,
1022  /// the nested-name-specifier and the named type.
1023  /// Subclasses may override this routine to provide different behavior.
1025  ElaboratedTypeKeyword Keyword,
1026  NestedNameSpecifierLoc QualifierLoc,
1027  QualType Named) {
1028  return SemaRef.Context.getElaboratedType(Keyword,
1029  QualifierLoc.getNestedNameSpecifier(),
1030  Named);
1031  }
1032 
1033  /// Build a new typename type that refers to a template-id.
1034  ///
1035  /// By default, builds a new DependentNameType type from the
1036  /// nested-name-specifier and the given type. Subclasses may override
1037  /// this routine to provide different behavior.
1039  ElaboratedTypeKeyword Keyword,
1040  NestedNameSpecifierLoc QualifierLoc,
1041  SourceLocation TemplateKWLoc,
1042  const IdentifierInfo *Name,
1043  SourceLocation NameLoc,
1045  bool AllowInjectedClassName) {
1046  // Rebuild the template name.
1047  // TODO: avoid TemplateName abstraction
1048  CXXScopeSpec SS;
1049  SS.Adopt(QualifierLoc);
1050  TemplateName InstName = getDerived().RebuildTemplateName(
1051  SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1052  AllowInjectedClassName);
1053 
1054  if (InstName.isNull())
1055  return QualType();
1056 
1057  // If it's still dependent, make a dependent specialization.
1058  if (InstName.getAsDependentTemplateName())
1059  return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1060  QualifierLoc.getNestedNameSpecifier(),
1061  Name,
1062  Args);
1063 
1064  // Otherwise, make an elaborated type wrapping a non-dependent
1065  // specialization.
1066  QualType T =
1067  getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1068  if (T.isNull()) return QualType();
1069 
1070  if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
1071  return T;
1072 
1073  return SemaRef.Context.getElaboratedType(Keyword,
1074  QualifierLoc.getNestedNameSpecifier(),
1075  T);
1076  }
1077 
1078  /// Build a new typename type that refers to an identifier.
1079  ///
1080  /// By default, performs semantic analysis when building the typename type
1081  /// (or elaborated type). Subclasses may override this routine to provide
1082  /// different behavior.
1084  SourceLocation KeywordLoc,
1085  NestedNameSpecifierLoc QualifierLoc,
1086  const IdentifierInfo *Id,
1087  SourceLocation IdLoc,
1088  bool DeducedTSTContext) {
1089  CXXScopeSpec SS;
1090  SS.Adopt(QualifierLoc);
1091 
1092  if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1093  // If the name is still dependent, just build a new dependent name type.
1094  if (!SemaRef.computeDeclContext(SS))
1095  return SemaRef.Context.getDependentNameType(Keyword,
1096  QualifierLoc.getNestedNameSpecifier(),
1097  Id);
1098  }
1099 
1100  if (Keyword == ETK_None || Keyword == ETK_Typename) {
1101  return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1102  *Id, IdLoc, DeducedTSTContext);
1103  }
1104 
1105  TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1106 
1107  // We had a dependent elaborated-type-specifier that has been transformed
1108  // into a non-dependent elaborated-type-specifier. Find the tag we're
1109  // referring to.
1110  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1111  DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1112  if (!DC)
1113  return QualType();
1114 
1115  if (SemaRef.RequireCompleteDeclContext(SS, DC))
1116  return QualType();
1117 
1118  TagDecl *Tag = nullptr;
1119  SemaRef.LookupQualifiedName(Result, DC);
1120  switch (Result.getResultKind()) {
1121  case LookupResult::NotFound:
1122  case LookupResult::NotFoundInCurrentInstantiation:
1123  break;
1124 
1125  case LookupResult::Found:
1126  Tag = Result.getAsSingle<TagDecl>();
1127  break;
1128 
1129  case LookupResult::FoundOverloaded:
1130  case LookupResult::FoundUnresolvedValue:
1131  llvm_unreachable("Tag lookup cannot find non-tags");
1132 
1133  case LookupResult::Ambiguous:
1134  // Let the LookupResult structure handle ambiguities.
1135  return QualType();
1136  }
1137 
1138  if (!Tag) {
1139  // Check where the name exists but isn't a tag type and use that to emit
1140  // better diagnostics.
1141  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1142  SemaRef.LookupQualifiedName(Result, DC);
1143  switch (Result.getResultKind()) {
1144  case LookupResult::Found:
1145  case LookupResult::FoundOverloaded:
1146  case LookupResult::FoundUnresolvedValue: {
1147  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1148  Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1149  SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1150  << NTK << Kind;
1151  SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1152  break;
1153  }
1154  default:
1155  SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1156  << Kind << Id << DC << QualifierLoc.getSourceRange();
1157  break;
1158  }
1159  return QualType();
1160  }
1161 
1162  if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1163  IdLoc, Id)) {
1164  SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1165  SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1166  return QualType();
1167  }
1168 
1169  // Build the elaborated-type-specifier type.
1170  QualType T = SemaRef.Context.getTypeDeclType(Tag);
1171  return SemaRef.Context.getElaboratedType(Keyword,
1172  QualifierLoc.getNestedNameSpecifier(),
1173  T);
1174  }
1175 
1176  /// Build a new pack expansion type.
1177  ///
1178  /// By default, builds a new PackExpansionType type from the given pattern.
1179  /// Subclasses may override this routine to provide different behavior.
1181  SourceRange PatternRange,
1182  SourceLocation EllipsisLoc,
1183  Optional<unsigned> NumExpansions) {
1184  return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1185  NumExpansions);
1186  }
1187 
1188  /// Build a new atomic type given its value type.
1189  ///
1190  /// By default, performs semantic analysis when building the atomic type.
1191  /// Subclasses may override this routine to provide different behavior.
1192  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1193 
1194  /// Build a new pipe type given its value type.
1195  QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1196  bool isReadPipe);
1197 
1198  /// Build an extended int given its value type.
1199  QualType RebuildExtIntType(bool IsUnsigned, unsigned NumBits,
1200  SourceLocation Loc);
1201 
1202  /// Build a dependent extended int given its value type.
1203  QualType RebuildDependentExtIntType(bool IsUnsigned, Expr *NumBitsExpr,
1204  SourceLocation Loc);
1205 
1206  /// Build a new template name given a nested name specifier, a flag
1207  /// indicating whether the "template" keyword was provided, and the template
1208  /// that the template name refers to.
1209  ///
1210  /// By default, builds the new template name directly. Subclasses may override
1211  /// this routine to provide different behavior.
1212  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1213  bool TemplateKW,
1214  TemplateDecl *Template);
1215 
1216  /// Build a new template name given a nested name specifier and the
1217  /// name that is referred to as a template.
1218  ///
1219  /// By default, performs semantic analysis to determine whether the name can
1220  /// be resolved to a specific template, then builds the appropriate kind of
1221  /// template name. Subclasses may override this routine to provide different
1222  /// behavior.
1223  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1224  SourceLocation TemplateKWLoc,
1225  const IdentifierInfo &Name,
1226  SourceLocation NameLoc, QualType ObjectType,
1227  NamedDecl *FirstQualifierInScope,
1228  bool AllowInjectedClassName);
1229 
1230  /// Build a new template name given a nested name specifier and the
1231  /// overloaded operator name that is referred to as a template.
1232  ///
1233  /// By default, performs semantic analysis to determine whether the name can
1234  /// be resolved to a specific template, then builds the appropriate kind of
1235  /// template name. Subclasses may override this routine to provide different
1236  /// behavior.
1237  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1238  SourceLocation TemplateKWLoc,
1239  OverloadedOperatorKind Operator,
1240  SourceLocation NameLoc, QualType ObjectType,
1241  bool AllowInjectedClassName);
1242 
1243  /// Build a new template name given a template template parameter pack
1244  /// and the
1245  ///
1246  /// By default, performs semantic analysis to determine whether the name can
1247  /// be resolved to a specific template, then builds the appropriate kind of
1248  /// template name. Subclasses may override this routine to provide different
1249  /// behavior.
1251  const TemplateArgument &ArgPack) {
1252  return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1253  }
1254 
1255  /// Build a new compound statement.
1256  ///
1257  /// By default, performs semantic analysis to build the new statement.
1258  /// Subclasses may override this routine to provide different behavior.
1260  MultiStmtArg Statements,
1261  SourceLocation RBraceLoc,
1262  bool IsStmtExpr) {
1263  return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1264  IsStmtExpr);
1265  }
1266 
1267  /// Build a new case statement.
1268  ///
1269  /// By default, performs semantic analysis to build the new statement.
1270  /// Subclasses may override this routine to provide different behavior.
1272  Expr *LHS,
1273  SourceLocation EllipsisLoc,
1274  Expr *RHS,
1275  SourceLocation ColonLoc) {
1276  return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1277  ColonLoc);
1278  }
1279 
1280  /// Attach the body to a new case statement.
1281  ///
1282  /// By default, performs semantic analysis to build the new statement.
1283  /// Subclasses may override this routine to provide different behavior.
1285  getSema().ActOnCaseStmtBody(S, Body);
1286  return S;
1287  }
1288 
1289  /// Build a new default statement.
1290  ///
1291  /// By default, performs semantic analysis to build the new statement.
1292  /// Subclasses may override this routine to provide different behavior.
1294  SourceLocation ColonLoc,
1295  Stmt *SubStmt) {
1296  return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1297  /*CurScope=*/nullptr);
1298  }
1299 
1300  /// Build a new label statement.
1301  ///
1302  /// By default, performs semantic analysis to build the new statement.
1303  /// Subclasses may override this routine to provide different behavior.
1305  SourceLocation ColonLoc, Stmt *SubStmt) {
1306  return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1307  }
1308 
1309  /// Build a new attributed statement.
1310  ///
1311  /// By default, performs semantic analysis to build the new statement.
1312  /// Subclasses may override this routine to provide different behavior.
1314  ArrayRef<const Attr *> Attrs,
1315  Stmt *SubStmt) {
1316  return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1317  }
1318 
1319  /// Build a new "if" statement.
1320  ///
1321  /// By default, performs semantic analysis to build the new statement.
1322  /// Subclasses may override this routine to provide different behavior.
1323  StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1324  SourceLocation LParenLoc, Sema::ConditionResult Cond,
1325  SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1326  SourceLocation ElseLoc, Stmt *Else) {
1327  return getSema().ActOnIfStmt(IfLoc, IsConstexpr, LParenLoc, Init, Cond,
1328  RParenLoc, Then, ElseLoc, Else);
1329  }
1330 
1331  /// Start building a new switch statement.
1332  ///
1333  /// By default, performs semantic analysis to build the new statement.
1334  /// Subclasses may override this routine to provide different behavior.
1336  SourceLocation LParenLoc, Stmt *Init,
1337  Sema::ConditionResult Cond,
1338  SourceLocation RParenLoc) {
1339  return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1340  RParenLoc);
1341  }
1342 
1343  /// Attach the body to the switch statement.
1344  ///
1345  /// By default, performs semantic analysis to build the new statement.
1346  /// Subclasses may override this routine to provide different behavior.
1348  Stmt *Switch, Stmt *Body) {
1349  return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1350  }
1351 
1352  /// Build a new while statement.
1353  ///
1354  /// By default, performs semantic analysis to build the new statement.
1355  /// Subclasses may override this routine to provide different behavior.
1357  Sema::ConditionResult Cond,
1358  SourceLocation RParenLoc, Stmt *Body) {
1359  return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1360  }
1361 
1362  /// Build a new do-while statement.
1363  ///
1364  /// By default, performs semantic analysis to build the new statement.
1365  /// Subclasses may override this routine to provide different behavior.
1367  SourceLocation WhileLoc, SourceLocation LParenLoc,
1368  Expr *Cond, SourceLocation RParenLoc) {
1369  return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1370  Cond, RParenLoc);
1371  }
1372 
1373  /// Build a new for statement.
1374  ///
1375  /// By default, performs semantic analysis to build the new statement.
1376  /// Subclasses may override this routine to provide different behavior.
1378  Stmt *Init, Sema::ConditionResult Cond,
1379  Sema::FullExprArg Inc, SourceLocation RParenLoc,
1380  Stmt *Body) {
1381  return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1382  Inc, RParenLoc, Body);
1383  }
1384 
1385  /// Build a new goto statement.
1386  ///
1387  /// By default, performs semantic analysis to build the new statement.
1388  /// Subclasses may override this routine to provide different behavior.
1390  LabelDecl *Label) {
1391  return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1392  }
1393 
1394  /// Build a new indirect goto statement.
1395  ///
1396  /// By default, performs semantic analysis to build the new statement.
1397  /// Subclasses may override this routine to provide different behavior.
1399  SourceLocation StarLoc,
1400  Expr *Target) {
1401  return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1402  }
1403 
1404  /// Build a new return statement.
1405  ///
1406  /// By default, performs semantic analysis to build the new statement.
1407  /// Subclasses may override this routine to provide different behavior.
1409  return getSema().BuildReturnStmt(ReturnLoc, Result);
1410  }
1411 
1412  /// Build a new declaration statement.
1413  ///
1414  /// By default, performs semantic analysis to build the new statement.
1415  /// Subclasses may override this routine to provide different behavior.
1417  SourceLocation StartLoc, SourceLocation EndLoc) {
1418  Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1419  return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1420  }
1421 
1422  /// Build a new inline asm statement.
1423  ///
1424  /// By default, performs semantic analysis to build the new statement.
1425  /// Subclasses may override this routine to provide different behavior.
1427  bool IsVolatile, unsigned NumOutputs,
1428  unsigned NumInputs, IdentifierInfo **Names,
1429  MultiExprArg Constraints, MultiExprArg Exprs,
1430  Expr *AsmString, MultiExprArg Clobbers,
1431  unsigned NumLabels,
1432  SourceLocation RParenLoc) {
1433  return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1434  NumInputs, Names, Constraints, Exprs,
1435  AsmString, Clobbers, NumLabels, RParenLoc);
1436  }
1437 
1438  /// Build a new MS style inline asm statement.
1439  ///
1440  /// By default, performs semantic analysis to build the new statement.
1441  /// Subclasses may override this routine to provide different behavior.
1443  ArrayRef<Token> AsmToks,
1444  StringRef AsmString,
1445  unsigned NumOutputs, unsigned NumInputs,
1446  ArrayRef<StringRef> Constraints,
1447  ArrayRef<StringRef> Clobbers,
1448  ArrayRef<Expr*> Exprs,
1449  SourceLocation EndLoc) {
1450  return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1451  NumOutputs, NumInputs,
1452  Constraints, Clobbers, Exprs, EndLoc);
1453  }
1454 
1455  /// Build a new co_return statement.
1456  ///
1457  /// By default, performs semantic analysis to build the new statement.
1458  /// Subclasses may override this routine to provide different behavior.
1460  bool IsImplicit) {
1461  return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1462  }
1463 
1464  /// Build a new co_await expression.
1465  ///
1466  /// By default, performs semantic analysis to build the new expression.
1467  /// Subclasses may override this routine to provide different behavior.
1469  bool IsImplicit) {
1470  return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1471  }
1472 
1473  /// Build a new co_await expression.
1474  ///
1475  /// By default, performs semantic analysis to build the new expression.
1476  /// Subclasses may override this routine to provide different behavior.
1478  Expr *Result,
1479  UnresolvedLookupExpr *Lookup) {
1480  return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1481  }
1482 
1483  /// Build a new co_yield expression.
1484  ///
1485  /// By default, performs semantic analysis to build the new expression.
1486  /// Subclasses may override this routine to provide different behavior.
1488  return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1489  }
1490 
1492  return getSema().BuildCoroutineBodyStmt(Args);
1493  }
1494 
1495  /// Build a new Objective-C \@try statement.
1496  ///
1497  /// By default, performs semantic analysis to build the new statement.
1498  /// Subclasses may override this routine to provide different behavior.
1500  Stmt *TryBody,
1501  MultiStmtArg CatchStmts,
1502  Stmt *Finally) {
1503  return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1504  Finally);
1505  }
1506 
1507  /// Rebuild an Objective-C exception declaration.
1508  ///
1509  /// By default, performs semantic analysis to build the new declaration.
1510  /// Subclasses may override this routine to provide different behavior.
1512  TypeSourceInfo *TInfo, QualType T) {
1513  return getSema().BuildObjCExceptionDecl(TInfo, T,
1514  ExceptionDecl->getInnerLocStart(),
1515  ExceptionDecl->getLocation(),
1516  ExceptionDecl->getIdentifier());
1517  }
1518 
1519  /// Build a new Objective-C \@catch statement.
1520  ///
1521  /// By default, performs semantic analysis to build the new statement.
1522  /// Subclasses may override this routine to provide different behavior.
1524  SourceLocation RParenLoc,
1525  VarDecl *Var,
1526  Stmt *Body) {
1527  return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1528  Var, Body);
1529  }
1530 
1531  /// Build a new Objective-C \@finally statement.
1532  ///
1533  /// By default, performs semantic analysis to build the new statement.
1534  /// Subclasses may override this routine to provide different behavior.
1536  Stmt *Body) {
1537  return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1538  }
1539 
1540  /// Build a new Objective-C \@throw statement.
1541  ///
1542  /// By default, performs semantic analysis to build the new statement.
1543  /// Subclasses may override this routine to provide different behavior.
1545  Expr *Operand) {
1546  return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1547  }
1548 
1549  /// Build a new OpenMP Canonical loop.
1550  ///
1551  /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1552  /// OMPCanonicalLoop.
1554  return getSema().ActOnOpenMPCanonicalLoop(LoopStmt);
1555  }
1556 
1557  /// Build a new OpenMP executable directive.
1558  ///
1559  /// By default, performs semantic analysis to build the new statement.
1560  /// Subclasses may override this routine to provide different behavior.
1562  DeclarationNameInfo DirName,
1563  OpenMPDirectiveKind CancelRegion,
1564  ArrayRef<OMPClause *> Clauses,
1565  Stmt *AStmt, SourceLocation StartLoc,
1566  SourceLocation EndLoc) {
1567  return getSema().ActOnOpenMPExecutableDirective(
1568  Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1569  }
1570 
1571  /// Build a new OpenMP 'if' clause.
1572  ///
1573  /// By default, performs semantic analysis to build the new OpenMP clause.
1574  /// Subclasses may override this routine to provide different behavior.
1576  Expr *Condition, SourceLocation StartLoc,
1577  SourceLocation LParenLoc,
1578  SourceLocation NameModifierLoc,
1579  SourceLocation ColonLoc,
1580  SourceLocation EndLoc) {
1581  return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1582  LParenLoc, NameModifierLoc, ColonLoc,
1583  EndLoc);
1584  }
1585 
1586  /// Build a new OpenMP 'final' clause.
1587  ///
1588  /// By default, performs semantic analysis to build the new OpenMP clause.
1589  /// Subclasses may override this routine to provide different behavior.
1591  SourceLocation LParenLoc,
1592  SourceLocation EndLoc) {
1593  return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1594  EndLoc);
1595  }
1596 
1597  /// Build a new OpenMP 'num_threads' clause.
1598  ///
1599  /// By default, performs semantic analysis to build the new OpenMP clause.
1600  /// Subclasses may override this routine to provide different behavior.
1602  SourceLocation StartLoc,
1603  SourceLocation LParenLoc,
1604  SourceLocation EndLoc) {
1605  return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1606  LParenLoc, EndLoc);
1607  }
1608 
1609  /// Build a new OpenMP 'safelen' clause.
1610  ///
1611  /// By default, performs semantic analysis to build the new OpenMP clause.
1612  /// Subclasses may override this routine to provide different behavior.
1614  SourceLocation LParenLoc,
1615  SourceLocation EndLoc) {
1616  return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1617  }
1618 
1619  /// Build a new OpenMP 'simdlen' clause.
1620  ///
1621  /// By default, performs semantic analysis to build the new OpenMP clause.
1622  /// Subclasses may override this routine to provide different behavior.
1624  SourceLocation LParenLoc,
1625  SourceLocation EndLoc) {
1626  return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1627  }
1628 
1630  SourceLocation StartLoc,
1631  SourceLocation LParenLoc,
1632  SourceLocation EndLoc) {
1633  return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc);
1634  }
1635 
1636  /// Build a new OpenMP 'full' clause.
1638  SourceLocation EndLoc) {
1639  return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc);
1640  }
1641 
1642  /// Build a new OpenMP 'partial' clause.
1644  SourceLocation LParenLoc,
1645  SourceLocation EndLoc) {
1646  return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc,
1647  EndLoc);
1648  }
1649 
1650  /// Build a new OpenMP 'allocator' clause.
1651  ///
1652  /// By default, performs semantic analysis to build the new OpenMP clause.
1653  /// Subclasses may override this routine to provide different behavior.
1655  SourceLocation LParenLoc,
1656  SourceLocation EndLoc) {
1657  return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1658  }
1659 
1660  /// Build a new OpenMP 'collapse' clause.
1661  ///
1662  /// By default, performs semantic analysis to build the new OpenMP clause.
1663  /// Subclasses may override this routine to provide different behavior.
1665  SourceLocation LParenLoc,
1666  SourceLocation EndLoc) {
1667  return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1668  EndLoc);
1669  }
1670 
1671  /// Build a new OpenMP 'default' clause.
1672  ///
1673  /// By default, performs semantic analysis to build the new OpenMP clause.
1674  /// Subclasses may override this routine to provide different behavior.
1676  SourceLocation StartLoc,
1677  SourceLocation LParenLoc,
1678  SourceLocation EndLoc) {
1679  return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1680  StartLoc, LParenLoc, EndLoc);
1681  }
1682 
1683  /// Build a new OpenMP 'proc_bind' clause.
1684  ///
1685  /// By default, performs semantic analysis to build the new OpenMP clause.
1686  /// Subclasses may override this routine to provide different behavior.
1688  SourceLocation KindKwLoc,
1689  SourceLocation StartLoc,
1690  SourceLocation LParenLoc,
1691  SourceLocation EndLoc) {
1692  return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1693  StartLoc, LParenLoc, EndLoc);
1694  }
1695 
1696  /// Build a new OpenMP 'schedule' clause.
1697  ///
1698  /// By default, performs semantic analysis to build the new OpenMP clause.
1699  /// Subclasses may override this routine to provide different behavior.
1702  OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1703  SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1704  SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1705  return getSema().ActOnOpenMPScheduleClause(
1706  M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1707  CommaLoc, EndLoc);
1708  }
1709 
1710  /// Build a new OpenMP 'ordered' 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 EndLoc,
1716  SourceLocation LParenLoc, Expr *Num) {
1717  return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1718  }
1719 
1720  /// Build a new OpenMP 'private' clause.
1721  ///
1722  /// By default, performs semantic analysis to build the new OpenMP clause.
1723  /// Subclasses may override this routine to provide different behavior.
1725  SourceLocation StartLoc,
1726  SourceLocation LParenLoc,
1727  SourceLocation EndLoc) {
1728  return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1729  EndLoc);
1730  }
1731 
1732  /// Build a new OpenMP 'firstprivate' clause.
1733  ///
1734  /// By default, performs semantic analysis to build the new OpenMP clause.
1735  /// Subclasses may override this routine to provide different behavior.
1737  SourceLocation StartLoc,
1738  SourceLocation LParenLoc,
1739  SourceLocation EndLoc) {
1740  return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1741  EndLoc);
1742  }
1743 
1744  /// Build a new OpenMP 'lastprivate' clause.
1745  ///
1746  /// By default, performs semantic analysis to build the new OpenMP clause.
1747  /// Subclasses may override this routine to provide different behavior.
1750  SourceLocation LPKindLoc,
1751  SourceLocation ColonLoc,
1752  SourceLocation StartLoc,
1753  SourceLocation LParenLoc,
1754  SourceLocation EndLoc) {
1755  return getSema().ActOnOpenMPLastprivateClause(
1756  VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1757  }
1758 
1759  /// Build a new OpenMP 'shared' clause.
1760  ///
1761  /// By default, performs semantic analysis to build the new OpenMP clause.
1762  /// Subclasses may override this routine to provide different behavior.
1764  SourceLocation StartLoc,
1765  SourceLocation LParenLoc,
1766  SourceLocation EndLoc) {
1767  return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1768  EndLoc);
1769  }
1770 
1771  /// Build a new OpenMP 'reduction' clause.
1772  ///
1773  /// By default, performs semantic analysis to build the new statement.
1774  /// Subclasses may override this routine to provide different behavior.
1777  SourceLocation StartLoc, SourceLocation LParenLoc,
1778  SourceLocation ModifierLoc, SourceLocation ColonLoc,
1779  SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1780  const DeclarationNameInfo &ReductionId,
1781  ArrayRef<Expr *> UnresolvedReductions) {
1782  return getSema().ActOnOpenMPReductionClause(
1783  VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1784  ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1785  }
1786 
1787  /// Build a new OpenMP 'task_reduction' clause.
1788  ///
1789  /// By default, performs semantic analysis to build the new statement.
1790  /// Subclasses may override this routine to provide different behavior.
1792  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1793  SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1794  CXXScopeSpec &ReductionIdScopeSpec,
1795  const DeclarationNameInfo &ReductionId,
1796  ArrayRef<Expr *> UnresolvedReductions) {
1797  return getSema().ActOnOpenMPTaskReductionClause(
1798  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1799  ReductionId, UnresolvedReductions);
1800  }
1801 
1802  /// Build a new OpenMP 'in_reduction' clause.
1803  ///
1804  /// By default, performs semantic analysis to build the new statement.
1805  /// Subclasses may override this routine to provide different behavior.
1806  OMPClause *
1808  SourceLocation LParenLoc, SourceLocation ColonLoc,
1809  SourceLocation EndLoc,
1810  CXXScopeSpec &ReductionIdScopeSpec,
1811  const DeclarationNameInfo &ReductionId,
1812  ArrayRef<Expr *> UnresolvedReductions) {
1813  return getSema().ActOnOpenMPInReductionClause(
1814  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1815  ReductionId, UnresolvedReductions);
1816  }
1817 
1818  /// Build a new OpenMP 'linear' clause.
1819  ///
1820  /// By default, performs semantic analysis to build the new OpenMP clause.
1821  /// Subclasses may override this routine to provide different behavior.
1823  SourceLocation StartLoc,
1824  SourceLocation LParenLoc,
1825  OpenMPLinearClauseKind Modifier,
1826  SourceLocation ModifierLoc,
1827  SourceLocation ColonLoc,
1828  SourceLocation EndLoc) {
1829  return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1830  Modifier, ModifierLoc, ColonLoc,
1831  EndLoc);
1832  }
1833 
1834  /// Build a new OpenMP 'aligned' clause.
1835  ///
1836  /// By default, performs semantic analysis to build the new OpenMP clause.
1837  /// Subclasses may override this routine to provide different behavior.
1839  SourceLocation StartLoc,
1840  SourceLocation LParenLoc,
1841  SourceLocation ColonLoc,
1842  SourceLocation EndLoc) {
1843  return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1844  LParenLoc, ColonLoc, EndLoc);
1845  }
1846 
1847  /// Build a new OpenMP 'copyin' clause.
1848  ///
1849  /// By default, performs semantic analysis to build the new OpenMP clause.
1850  /// Subclasses may override this routine to provide different behavior.
1852  SourceLocation StartLoc,
1853  SourceLocation LParenLoc,
1854  SourceLocation EndLoc) {
1855  return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1856  EndLoc);
1857  }
1858 
1859  /// Build a new OpenMP 'copyprivate' clause.
1860  ///
1861  /// By default, performs semantic analysis to build the new OpenMP clause.
1862  /// Subclasses may override this routine to provide different behavior.
1864  SourceLocation StartLoc,
1865  SourceLocation LParenLoc,
1866  SourceLocation EndLoc) {
1867  return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1868  EndLoc);
1869  }
1870 
1871  /// Build a new OpenMP 'flush' pseudo clause.
1872  ///
1873  /// By default, performs semantic analysis to build the new OpenMP clause.
1874  /// Subclasses may override this routine to provide different behavior.
1876  SourceLocation StartLoc,
1877  SourceLocation LParenLoc,
1878  SourceLocation EndLoc) {
1879  return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1880  EndLoc);
1881  }
1882 
1883  /// Build a new OpenMP 'depobj' pseudo clause.
1884  ///
1885  /// By default, performs semantic analysis to build the new OpenMP clause.
1886  /// Subclasses may override this routine to provide different behavior.
1888  SourceLocation LParenLoc,
1889  SourceLocation EndLoc) {
1890  return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc,
1891  EndLoc);
1892  }
1893 
1894  /// Build a new OpenMP 'depend' pseudo clause.
1895  ///
1896  /// By default, performs semantic analysis to build the new OpenMP clause.
1897  /// Subclasses may override this routine to provide different behavior.
1898  OMPClause *
1900  SourceLocation DepLoc, SourceLocation ColonLoc,
1901  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1902  SourceLocation LParenLoc, SourceLocation EndLoc) {
1903  return getSema().ActOnOpenMPDependClause(DepModifier, DepKind, DepLoc,
1904  ColonLoc, VarList, StartLoc,
1905  LParenLoc, EndLoc);
1906  }
1907 
1908  /// Build a new OpenMP 'device' clause.
1909  ///
1910  /// By default, performs semantic analysis to build the new statement.
1911  /// Subclasses may override this routine to provide different behavior.
1913  Expr *Device, SourceLocation StartLoc,
1914  SourceLocation LParenLoc,
1915  SourceLocation ModifierLoc,
1916  SourceLocation EndLoc) {
1917  return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc,
1918  LParenLoc, ModifierLoc, EndLoc);
1919  }
1920 
1921  /// Build a new OpenMP 'map' clause.
1922  ///
1923  /// By default, performs semantic analysis to build the new OpenMP clause.
1924  /// Subclasses may override this routine to provide different behavior.
1926  ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1927  ArrayRef<SourceLocation> MapTypeModifiersLoc,
1928  CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1929  OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1930  SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1931  const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
1932  return getSema().ActOnOpenMPMapClause(
1933  MapTypeModifiers, MapTypeModifiersLoc, MapperIdScopeSpec, MapperId,
1934  MapType, IsMapTypeImplicit, MapLoc, ColonLoc, VarList, Locs,
1935  /*NoDiagnose=*/false, UnresolvedMappers);
1936  }
1937 
1938  /// Build a new OpenMP 'allocate' clause.
1939  ///
1940  /// By default, performs semantic analysis to build the new OpenMP clause.
1941  /// Subclasses may override this routine to provide different behavior.
1943  SourceLocation StartLoc,
1944  SourceLocation LParenLoc,
1945  SourceLocation ColonLoc,
1946  SourceLocation EndLoc) {
1947  return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1948  LParenLoc, ColonLoc, EndLoc);
1949  }
1950 
1951  /// Build a new OpenMP 'num_teams' clause.
1952  ///
1953  /// By default, performs semantic analysis to build the new statement.
1954  /// Subclasses may override this routine to provide different behavior.
1956  SourceLocation LParenLoc,
1957  SourceLocation EndLoc) {
1958  return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1959  EndLoc);
1960  }
1961 
1962  /// Build a new OpenMP 'thread_limit' clause.
1963  ///
1964  /// By default, performs semantic analysis to build the new statement.
1965  /// Subclasses may override this routine to provide different behavior.
1967  SourceLocation StartLoc,
1968  SourceLocation LParenLoc,
1969  SourceLocation EndLoc) {
1970  return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1971  LParenLoc, EndLoc);
1972  }
1973 
1974  /// Build a new OpenMP 'priority' clause.
1975  ///
1976  /// By default, performs semantic analysis to build the new statement.
1977  /// Subclasses may override this routine to provide different behavior.
1979  SourceLocation LParenLoc,
1980  SourceLocation EndLoc) {
1981  return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1982  EndLoc);
1983  }
1984 
1985  /// Build a new OpenMP 'grainsize' clause.
1986  ///
1987  /// By default, performs semantic analysis to build the new statement.
1988  /// Subclasses may override this routine to provide different behavior.
1990  SourceLocation LParenLoc,
1991  SourceLocation EndLoc) {
1992  return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1993  EndLoc);
1994  }
1995 
1996  /// Build a new OpenMP 'num_tasks' clause.
1997  ///
1998  /// By default, performs semantic analysis to build the new statement.
1999  /// Subclasses may override this routine to provide different behavior.
2001  SourceLocation LParenLoc,
2002  SourceLocation EndLoc) {
2003  return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
2004  EndLoc);
2005  }
2006 
2007  /// Build a new OpenMP 'hint' clause.
2008  ///
2009  /// By default, performs semantic analysis to build the new statement.
2010  /// Subclasses may override this routine to provide different behavior.
2012  SourceLocation LParenLoc,
2013  SourceLocation EndLoc) {
2014  return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
2015  }
2016 
2017  /// Build a new OpenMP 'detach' clause.
2018  ///
2019  /// By default, performs semantic analysis to build the new statement.
2020  /// Subclasses may override this routine to provide different behavior.
2022  SourceLocation LParenLoc,
2023  SourceLocation EndLoc) {
2024  return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);
2025  }
2026 
2027  /// Build a new OpenMP 'dist_schedule' clause.
2028  ///
2029  /// By default, performs semantic analysis to build the new OpenMP clause.
2030  /// Subclasses may override this routine to provide different behavior.
2031  OMPClause *
2033  Expr *ChunkSize, SourceLocation StartLoc,
2034  SourceLocation LParenLoc, SourceLocation KindLoc,
2035  SourceLocation CommaLoc, SourceLocation EndLoc) {
2036  return getSema().ActOnOpenMPDistScheduleClause(
2037  Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2038  }
2039 
2040  /// Build a new OpenMP 'to' clause.
2041  ///
2042  /// By default, performs semantic analysis to build the new statement.
2043  /// Subclasses may override this routine to provide different behavior.
2044  OMPClause *
2046  ArrayRef<SourceLocation> MotionModifiersLoc,
2047  CXXScopeSpec &MapperIdScopeSpec,
2048  DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2049  ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2050  ArrayRef<Expr *> UnresolvedMappers) {
2051  return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc,
2052  MapperIdScopeSpec, MapperId, ColonLoc,
2053  VarList, Locs, UnresolvedMappers);
2054  }
2055 
2056  /// Build a new OpenMP 'from' clause.
2057  ///
2058  /// By default, performs semantic analysis to build the new statement.
2059  /// Subclasses may override this routine to provide different behavior.
2060  OMPClause *
2062  ArrayRef<SourceLocation> MotionModifiersLoc,
2063  CXXScopeSpec &MapperIdScopeSpec,
2064  DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2065  ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2066  ArrayRef<Expr *> UnresolvedMappers) {
2067  return getSema().ActOnOpenMPFromClause(
2068  MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2069  ColonLoc, VarList, Locs, UnresolvedMappers);
2070  }
2071 
2072  /// Build a new OpenMP 'use_device_ptr' clause.
2073  ///
2074  /// By default, performs semantic analysis to build the new OpenMP clause.
2075  /// Subclasses may override this routine to provide different behavior.
2077  const OMPVarListLocTy &Locs) {
2078  return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2079  }
2080 
2081  /// Build a new OpenMP 'use_device_addr' clause.
2082  ///
2083  /// By default, performs semantic analysis to build the new OpenMP clause.
2084  /// Subclasses may override this routine to provide different behavior.
2086  const OMPVarListLocTy &Locs) {
2087  return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2088  }
2089 
2090  /// Build a new OpenMP 'is_device_ptr' clause.
2091  ///
2092  /// By default, performs semantic analysis to build the new OpenMP clause.
2093  /// Subclasses may override this routine to provide different behavior.
2095  const OMPVarListLocTy &Locs) {
2096  return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2097  }
2098 
2099  /// Build a new OpenMP 'defaultmap' clause.
2100  ///
2101  /// By default, performs semantic analysis to build the new OpenMP clause.
2102  /// Subclasses may override this routine to provide different behavior.
2105  SourceLocation StartLoc,
2106  SourceLocation LParenLoc,
2107  SourceLocation MLoc,
2108  SourceLocation KindLoc,
2109  SourceLocation EndLoc) {
2110  return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc,
2111  MLoc, KindLoc, EndLoc);
2112  }
2113 
2114  /// Build a new OpenMP 'nontemporal' clause.
2115  ///
2116  /// By default, performs semantic analysis to build the new OpenMP clause.
2117  /// Subclasses may override this routine to provide different behavior.
2119  SourceLocation StartLoc,
2120  SourceLocation LParenLoc,
2121  SourceLocation EndLoc) {
2122  return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc,
2123  EndLoc);
2124  }
2125 
2126  /// Build a new OpenMP 'inclusive' clause.
2127  ///
2128  /// By default, performs semantic analysis to build the new OpenMP clause.
2129  /// Subclasses may override this routine to provide different behavior.
2131  SourceLocation StartLoc,
2132  SourceLocation LParenLoc,
2133  SourceLocation EndLoc) {
2134  return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc,
2135  EndLoc);
2136  }
2137 
2138  /// Build a new OpenMP 'exclusive' clause.
2139  ///
2140  /// By default, performs semantic analysis to build the new OpenMP clause.
2141  /// Subclasses may override this routine to provide different behavior.
2143  SourceLocation StartLoc,
2144  SourceLocation LParenLoc,
2145  SourceLocation EndLoc) {
2146  return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc,
2147  EndLoc);
2148  }
2149 
2150  /// Build a new OpenMP 'uses_allocators' clause.
2151  ///
2152  /// By default, performs semantic analysis to build the new OpenMP clause.
2153  /// Subclasses may override this routine to provide different behavior.
2156  SourceLocation LParenLoc, SourceLocation EndLoc) {
2157  return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc,
2158  Data);
2159  }
2160 
2161  /// Build a new OpenMP 'affinity' clause.
2162  ///
2163  /// By default, performs semantic analysis to build the new OpenMP clause.
2164  /// Subclasses may override this routine to provide different behavior.
2166  SourceLocation LParenLoc,
2167  SourceLocation ColonLoc,
2168  SourceLocation EndLoc, Expr *Modifier,
2169  ArrayRef<Expr *> Locators) {
2170  return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc,
2171  EndLoc, Modifier, Locators);
2172  }
2173 
2174  /// Build a new OpenMP 'order' clause.
2175  ///
2176  /// By default, performs semantic analysis to build the new OpenMP clause.
2177  /// Subclasses may override this routine to provide different behavior.
2179  SourceLocation KindKwLoc,
2180  SourceLocation StartLoc,
2181  SourceLocation LParenLoc,
2182  SourceLocation EndLoc) {
2183  return getSema().ActOnOpenMPOrderClause(Kind, KindKwLoc, StartLoc,
2184  LParenLoc, EndLoc);
2185  }
2186 
2187  /// Build a new OpenMP 'init' clause.
2188  ///
2189  /// By default, performs semantic analysis to build the new OpenMP clause.
2190  /// Subclasses may override this routine to provide different behavior.
2192  bool IsTarget, bool IsTargetSync,
2193  SourceLocation StartLoc,
2194  SourceLocation LParenLoc,
2195  SourceLocation VarLoc,
2196  SourceLocation EndLoc) {
2197  return getSema().ActOnOpenMPInitClause(InteropVar, PrefExprs, IsTarget,
2198  IsTargetSync, StartLoc, LParenLoc,
2199  VarLoc, EndLoc);
2200  }
2201 
2202  /// Build a new OpenMP 'use' clause.
2203  ///
2204  /// By default, performs semantic analysis to build the new OpenMP clause.
2205  /// Subclasses may override this routine to provide different behavior.
2207  SourceLocation LParenLoc,
2208  SourceLocation VarLoc, SourceLocation EndLoc) {
2209  return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc,
2210  VarLoc, EndLoc);
2211  }
2212 
2213  /// Build a new OpenMP 'destroy' clause.
2214  ///
2215  /// By default, performs semantic analysis to build the new OpenMP clause.
2216  /// Subclasses may override this routine to provide different behavior.
2218  SourceLocation LParenLoc,
2219  SourceLocation VarLoc,
2220  SourceLocation EndLoc) {
2221  return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc,
2222  VarLoc, EndLoc);
2223  }
2224 
2225  /// Build a new OpenMP 'novariants' clause.
2226  ///
2227  /// By default, performs semantic analysis to build the new OpenMP clause.
2228  /// Subclasses may override this routine to provide different behavior.
2230  SourceLocation StartLoc,
2231  SourceLocation LParenLoc,
2232  SourceLocation EndLoc) {
2233  return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc,
2234  EndLoc);
2235  }
2236 
2237  /// Build a new OpenMP 'nocontext' clause.
2238  ///
2239  /// By default, performs semantic analysis to build the new OpenMP clause.
2240  /// Subclasses may override this routine to provide different behavior.
2242  SourceLocation LParenLoc,
2243  SourceLocation EndLoc) {
2244  return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc,
2245  EndLoc);
2246  }
2247 
2248  /// Build a new OpenMP 'filter' clause.
2249  ///
2250  /// By default, performs semantic analysis to build the new OpenMP clause.
2251  /// Subclasses may override this routine to provide different behavior.
2253  SourceLocation LParenLoc,
2254  SourceLocation EndLoc) {
2255  return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc,
2256  EndLoc);
2257  }
2258 
2259  /// Rebuild the operand to an Objective-C \@synchronized statement.
2260  ///
2261  /// By default, performs semantic analysis to build the new statement.
2262  /// Subclasses may override this routine to provide different behavior.
2264  Expr *object) {
2265  return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
2266  }
2267 
2268  /// Build a new Objective-C \@synchronized statement.
2269  ///
2270  /// By default, performs semantic analysis to build the new statement.
2271  /// Subclasses may override this routine to provide different behavior.
2273  Expr *Object, Stmt *Body) {
2274  return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2275  }
2276 
2277  /// Build a new Objective-C \@autoreleasepool statement.
2278  ///
2279  /// By default, performs semantic analysis to build the new statement.
2280  /// Subclasses may override this routine to provide different behavior.
2282  Stmt *Body) {
2283  return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2284  }
2285 
2286  /// Build a new Objective-C fast enumeration statement.
2287  ///
2288  /// By default, performs semantic analysis to build the new statement.
2289  /// Subclasses may override this routine to provide different behavior.
2291  Stmt *Element,
2292  Expr *Collection,
2293  SourceLocation RParenLoc,
2294  Stmt *Body) {
2295  StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
2296  Element,
2297  Collection,
2298  RParenLoc);
2299  if (ForEachStmt.isInvalid())
2300  return StmtError();
2301 
2302  return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
2303  }
2304 
2305  /// Build a new C++ exception declaration.
2306  ///
2307  /// By default, performs semantic analysis to build the new decaration.
2308  /// Subclasses may override this routine to provide different behavior.
2311  SourceLocation StartLoc,
2312  SourceLocation IdLoc,
2313  IdentifierInfo *Id) {
2314  VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
2315  StartLoc, IdLoc, Id);
2316  if (Var)
2317  getSema().CurContext->addDecl(Var);
2318  return Var;
2319  }
2320 
2321  /// Build a new C++ catch statement.
2322  ///
2323  /// By default, performs semantic analysis to build the new statement.
2324  /// Subclasses may override this routine to provide different behavior.
2326  VarDecl *ExceptionDecl,
2327  Stmt *Handler) {
2328  return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2329  Handler));
2330  }
2331 
2332  /// Build a new C++ try statement.
2333  ///
2334  /// By default, performs semantic analysis to build the new statement.
2335  /// Subclasses may override this routine to provide different behavior.
2337  ArrayRef<Stmt *> Handlers) {
2338  return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2339  }
2340 
2341  /// Build a new C++0x range-based for statement.
2342  ///
2343  /// By default, performs semantic analysis to build the new statement.
2344  /// Subclasses may override this routine to provide different behavior.
2346  SourceLocation CoawaitLoc, Stmt *Init,
2347  SourceLocation ColonLoc, Stmt *Range,
2348  Stmt *Begin, Stmt *End, Expr *Cond,
2349  Expr *Inc, Stmt *LoopVar,
2350  SourceLocation RParenLoc) {
2351  // If we've just learned that the range is actually an Objective-C
2352  // collection, treat this as an Objective-C fast enumeration loop.
2353  if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2354  if (RangeStmt->isSingleDecl()) {
2355  if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2356  if (RangeVar->isInvalidDecl())
2357  return StmtError();
2358 
2359  Expr *RangeExpr = RangeVar->getInit();
2360  if (!RangeExpr->isTypeDependent() &&
2361  RangeExpr->getType()->isObjCObjectPointerType()) {
2362  // FIXME: Support init-statements in Objective-C++20 ranged for
2363  // statement.
2364  if (Init) {
2365  return SemaRef.Diag(Init->getBeginLoc(),
2366  diag::err_objc_for_range_init_stmt)
2367  << Init->getSourceRange();
2368  }
2369  return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2370  RangeExpr, RParenLoc);
2371  }
2372  }
2373  }
2374  }
2375 
2376  return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2377  Range, Begin, End, Cond, Inc, LoopVar,
2378  RParenLoc, Sema::BFRK_Rebuild);
2379  }
2380 
2381  /// Build a new C++0x range-based for statement.
2382  ///
2383  /// By default, performs semantic analysis to build the new statement.
2384  /// Subclasses may override this routine to provide different behavior.
2386  bool IsIfExists,
2387  NestedNameSpecifierLoc QualifierLoc,
2388  DeclarationNameInfo NameInfo,
2389  Stmt *Nested) {
2390  return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2391  QualifierLoc, NameInfo, Nested);
2392  }
2393 
2394  /// Attach body to a C++0x range-based for statement.
2395  ///
2396  /// By default, performs semantic analysis to finish the new statement.
2397  /// Subclasses may override this routine to provide different behavior.
2399  return getSema().FinishCXXForRangeStmt(ForRange, Body);
2400  }
2401 
2403  Stmt *TryBlock, Stmt *Handler) {
2404  return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2405  }
2406 
2408  Stmt *Block) {
2409  return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2410  }
2411 
2413  return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2414  }
2415 
2417  SourceLocation LParen,
2418  SourceLocation RParen,
2419  TypeSourceInfo *TSI) {
2420  return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI);
2421  }
2422 
2423  /// Build a new predefined expression.
2424  ///
2425  /// By default, performs semantic analysis to build the new expression.
2426  /// Subclasses may override this routine to provide different behavior.
2429  return getSema().BuildPredefinedExpr(Loc, IK);
2430  }
2431 
2432  /// Build a new expression that references a declaration.
2433  ///
2434  /// By default, performs semantic analysis to build the new expression.
2435  /// Subclasses may override this routine to provide different behavior.
2437  LookupResult &R,
2438  bool RequiresADL) {
2439  return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2440  }
2441 
2442 
2443  /// Build a new expression that references a declaration.
2444  ///
2445  /// By default, performs semantic analysis to build the new expression.
2446  /// Subclasses may override this routine to provide different behavior.
2448  ValueDecl *VD,
2449  const DeclarationNameInfo &NameInfo,
2450  NamedDecl *Found,
2451  TemplateArgumentListInfo *TemplateArgs) {
2452  CXXScopeSpec SS;
2453  SS.Adopt(QualifierLoc);
2454  return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2455  TemplateArgs);
2456  }
2457 
2458  /// Build a new expression in parentheses.
2459  ///
2460  /// By default, performs semantic analysis to build the new expression.
2461  /// Subclasses may override this routine to provide different behavior.
2463  SourceLocation RParen) {
2464  return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2465  }
2466 
2467  /// Build a new pseudo-destructor expression.
2468  ///
2469  /// By default, performs semantic analysis to build the new expression.
2470  /// Subclasses may override this routine to provide different behavior.
2471  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2472  SourceLocation OperatorLoc,
2473  bool isArrow,
2474  CXXScopeSpec &SS,
2475  TypeSourceInfo *ScopeType,
2476  SourceLocation CCLoc,
2477  SourceLocation TildeLoc,
2478  PseudoDestructorTypeStorage Destroyed);
2479 
2480  /// Build a new unary operator expression.
2481  ///
2482  /// By default, performs semantic analysis to build the new expression.
2483  /// Subclasses may override this routine to provide different behavior.
2485  UnaryOperatorKind Opc,
2486  Expr *SubExpr) {
2487  return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2488  }
2489 
2490  /// Build a new builtin offsetof expression.
2491  ///
2492  /// By default, performs semantic analysis to build the new expression.
2493  /// Subclasses may override this routine to provide different behavior.
2497  SourceLocation RParenLoc) {
2498  return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2499  RParenLoc);
2500  }
2501 
2502  /// Build a new sizeof, alignof or vec_step expression with a
2503  /// type argument.
2504  ///
2505  /// By default, performs semantic analysis to build the new expression.
2506  /// Subclasses may override this routine to provide different behavior.
2508  SourceLocation OpLoc,
2509  UnaryExprOrTypeTrait ExprKind,
2510  SourceRange R) {
2511  return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2512  }
2513 
2514  /// Build a new sizeof, alignof or vec step expression with an
2515  /// expression argument.
2516  ///
2517  /// By default, performs semantic analysis to build the new expression.
2518  /// Subclasses may override this routine to provide different behavior.
2520  UnaryExprOrTypeTrait ExprKind,
2521  SourceRange R) {
2522  ExprResult Result
2523  = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2524  if (Result.isInvalid())
2525  return ExprError();
2526 
2527  return Result;
2528  }
2529 
2530  /// Build a new array subscript expression.
2531  ///
2532  /// By default, performs semantic analysis to build the new expression.
2533  /// Subclasses may override this routine to provide different behavior.
2535  SourceLocation LBracketLoc,
2536  Expr *RHS,
2537  SourceLocation RBracketLoc) {
2538  return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2539  LBracketLoc, RHS,
2540  RBracketLoc);
2541  }
2542 
2543  /// Build a new matrix subscript expression.
2544  ///
2545  /// By default, performs semantic analysis to build the new expression.
2546  /// Subclasses may override this routine to provide different behavior.
2548  Expr *ColumnIdx,
2549  SourceLocation RBracketLoc) {
2550  return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2551  RBracketLoc);
2552  }
2553 
2554  /// Build a new array section expression.
2555  ///
2556  /// By default, performs semantic analysis to build the new expression.
2557  /// Subclasses may override this routine to provide different behavior.
2559  Expr *LowerBound,
2560  SourceLocation ColonLocFirst,
2561  SourceLocation ColonLocSecond,
2562  Expr *Length, Expr *Stride,
2563  SourceLocation RBracketLoc) {
2564  return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2565  ColonLocFirst, ColonLocSecond,
2566  Length, Stride, RBracketLoc);
2567  }
2568 
2569  /// Build a new array shaping expression.
2570  ///
2571  /// By default, performs semantic analysis to build the new expression.
2572  /// Subclasses may override this routine to provide different behavior.
2574  SourceLocation RParenLoc,
2575  ArrayRef<Expr *> Dims,
2576  ArrayRef<SourceRange> BracketsRanges) {
2577  return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims,
2578  BracketsRanges);
2579  }
2580 
2581  /// Build a new iterator expression.
2582  ///
2583  /// By default, performs semantic analysis to build the new expression.
2584  /// Subclasses may override this routine to provide different behavior.
2586  SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc,
2588  return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc,
2589  LLoc, RLoc, Data);
2590  }
2591 
2592  /// Build a new call expression.
2593  ///
2594  /// By default, performs semantic analysis to build the new expression.
2595  /// Subclasses may override this routine to provide different behavior.
2597  MultiExprArg Args,
2598  SourceLocation RParenLoc,
2599  Expr *ExecConfig = nullptr) {
2600  return getSema().ActOnCallExpr(
2601  /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2602  }
2603 
2604  /// Build a new member access expression.
2605  ///
2606  /// By default, performs semantic analysis to build the new expression.
2607  /// Subclasses may override this routine to provide different behavior.
2609  bool isArrow,
2610  NestedNameSpecifierLoc QualifierLoc,
2611  SourceLocation TemplateKWLoc,
2612  const DeclarationNameInfo &MemberNameInfo,
2613  ValueDecl *Member,
2614  NamedDecl *FoundDecl,
2615  const TemplateArgumentListInfo *ExplicitTemplateArgs,
2616  NamedDecl *FirstQualifierInScope) {
2617  ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2618  isArrow);
2619  if (!Member->getDeclName()) {
2620  // We have a reference to an unnamed field. This is always the
2621  // base of an anonymous struct/union member access, i.e. the
2622  // field is always of record type.
2623  assert(Member->getType()->isRecordType() &&
2624  "unnamed member not of record type?");
2625 
2626  BaseResult =
2627  getSema().PerformObjectMemberConversion(BaseResult.get(),
2628  QualifierLoc.getNestedNameSpecifier(),
2629  FoundDecl, Member);
2630  if (BaseResult.isInvalid())
2631  return ExprError();
2632  Base = BaseResult.get();
2633 
2634  CXXScopeSpec EmptySS;
2635  return getSema().BuildFieldReferenceExpr(
2636  Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2637  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
2638  }
2639 
2640  CXXScopeSpec SS;
2641  SS.Adopt(QualifierLoc);
2642 
2643  Base = BaseResult.get();
2644  QualType BaseType = Base->getType();
2645 
2646  if (isArrow && !BaseType->isPointerType())
2647  return ExprError();
2648 
2649  // FIXME: this involves duplicating earlier analysis in a lot of
2650  // cases; we should avoid this when possible.
2651  LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2652  R.addDecl(FoundDecl);
2653  R.resolveKind();
2654 
2655  return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2656  SS, TemplateKWLoc,
2657  FirstQualifierInScope,
2658  R, ExplicitTemplateArgs,
2659  /*S*/nullptr);
2660  }
2661 
2662  /// Build a new binary operator expression.
2663  ///
2664  /// By default, performs semantic analysis to build the new expression.
2665  /// Subclasses may override this routine to provide different behavior.
2667  BinaryOperatorKind Opc,
2668  Expr *LHS, Expr *RHS) {
2669  return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2670  }
2671 
2672  /// Build a new rewritten operator expression.
2673  ///
2674  /// By default, performs semantic analysis to build the new expression.
2675  /// Subclasses may override this routine to provide different behavior.
2678  const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2679  return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2680  RHS, /*RequiresADL*/false);
2681  }
2682 
2683  /// Build a new conditional operator expression.
2684  ///
2685  /// By default, performs semantic analysis to build the new expression.
2686  /// Subclasses may override this routine to provide different behavior.
2688  SourceLocation QuestionLoc,
2689  Expr *LHS,
2690  SourceLocation ColonLoc,
2691  Expr *RHS) {
2692  return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2693  LHS, RHS);
2694  }
2695 
2696  /// Build a new C-style cast expression.
2697  ///
2698  /// By default, performs semantic analysis to build the new expression.
2699  /// Subclasses may override this routine to provide different behavior.
2701  TypeSourceInfo *TInfo,
2702  SourceLocation RParenLoc,
2703  Expr *SubExpr) {
2704  return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2705  SubExpr);
2706  }
2707 
2708  /// Build a new compound literal expression.
2709  ///
2710  /// By default, performs semantic analysis to build the new expression.
2711  /// Subclasses may override this routine to provide different behavior.
2713  TypeSourceInfo *TInfo,
2714  SourceLocation RParenLoc,
2715  Expr *Init) {
2716  return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2717  Init);
2718  }
2719 
2720  /// Build a new extended vector element access expression.
2721  ///
2722  /// By default, performs semantic analysis to build the new expression.
2723  /// Subclasses may override this routine to provide different behavior.
2725  SourceLocation OpLoc,
2726  SourceLocation AccessorLoc,
2727  IdentifierInfo &Accessor) {
2728 
2729  CXXScopeSpec SS;
2730  DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2731  return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2732  OpLoc, /*IsArrow*/ false,
2733  SS, SourceLocation(),
2734  /*FirstQualifierInScope*/ nullptr,
2735  NameInfo,
2736  /* TemplateArgs */ nullptr,
2737  /*S*/ nullptr);
2738  }
2739 
2740  /// Build a new initializer list expression.
2741  ///
2742  /// By default, performs semantic analysis to build the new expression.
2743  /// Subclasses may override this routine to provide different behavior.
2745  MultiExprArg Inits,
2746  SourceLocation RBraceLoc) {
2747  return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
2748  }
2749 
2750  /// Build a new designated initializer expression.
2751  ///
2752  /// By default, performs semantic analysis to build the new expression.
2753  /// Subclasses may override this routine to provide different behavior.
2755  MultiExprArg ArrayExprs,
2756  SourceLocation EqualOrColonLoc,
2757  bool GNUSyntax,
2758  Expr *Init) {
2759  ExprResult Result
2760  = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2761  Init);
2762  if (Result.isInvalid())
2763  return ExprError();
2764 
2765  return Result;
2766  }
2767 
2768  /// Build a new value-initialized expression.
2769  ///
2770  /// By default, builds the implicit value initialization without performing
2771  /// any semantic analysis. Subclasses may override this routine to provide
2772  /// different behavior.
2774  return new (SemaRef.Context) ImplicitValueInitExpr(T);
2775  }
2776 
2777  /// Build a new \c va_arg expression.
2778  ///
2779  /// By default, performs semantic analysis to build the new expression.
2780  /// Subclasses may override this routine to provide different behavior.
2782  Expr *SubExpr, TypeSourceInfo *TInfo,
2783  SourceLocation RParenLoc) {
2784  return getSema().BuildVAArgExpr(BuiltinLoc,
2785  SubExpr, TInfo,
2786  RParenLoc);
2787  }
2788 
2789  /// Build a new expression list in parentheses.
2790  ///
2791  /// By default, performs semantic analysis to build the new expression.
2792  /// Subclasses may override this routine to provide different behavior.
2794  MultiExprArg SubExprs,
2795  SourceLocation RParenLoc) {
2796  return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2797  }
2798 
2799  /// Build a new address-of-label expression.
2800  ///
2801  /// By default, performs semantic analysis, using the name of the label
2802  /// rather than attempting to map the label statement itself.
2803  /// Subclasses may override this routine to provide different behavior.
2805  SourceLocation LabelLoc, LabelDecl *Label) {
2806  return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2807  }
2808 
2809  /// Build a new GNU statement expression.
2810  ///
2811  /// By default, performs semantic analysis to build the new expression.
2812  /// Subclasses may override this routine to provide different behavior.
2814  SourceLocation RParenLoc, unsigned TemplateDepth) {
2815  return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
2816  TemplateDepth);
2817  }
2818 
2819  /// Build a new __builtin_choose_expr expression.
2820  ///
2821  /// By default, performs semantic analysis to build the new expression.
2822  /// Subclasses may override this routine to provide different behavior.
2824  Expr *Cond, Expr *LHS, Expr *RHS,
2825  SourceLocation RParenLoc) {
2826  return SemaRef.ActOnChooseExpr(BuiltinLoc,
2827  Cond, LHS, RHS,
2828  RParenLoc);
2829  }
2830 
2831  /// Build a new generic selection expression.
2832  ///
2833  /// By default, performs semantic analysis to build the new expression.
2834  /// Subclasses may override this routine to provide different behavior.
2836  SourceLocation DefaultLoc,
2837  SourceLocation RParenLoc,
2838  Expr *ControllingExpr,
2840  ArrayRef<Expr *> Exprs) {
2841  return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2842  ControllingExpr, Types, Exprs);
2843  }
2844 
2845  /// Build a new overloaded operator call expression.
2846  ///
2847  /// By default, performs semantic analysis to build the new expression.
2848  /// The semantic analysis provides the behavior of template instantiation,
2849  /// copying with transformations that turn what looks like an overloaded
2850  /// operator call into a use of a builtin operator, performing
2851  /// argument-dependent lookup, etc. Subclasses may override this routine to
2852  /// provide different behavior.
2853  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2854  SourceLocation OpLoc,
2855  Expr *Callee,
2856  Expr *First,
2857  Expr *Second);
2858 
2859  /// Build a new C++ "named" cast expression, such as static_cast or
2860  /// reinterpret_cast.
2861  ///
2862  /// By default, this routine dispatches to one of the more-specific routines
2863  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2864  /// Subclasses may override this routine to provide different behavior.
2866  Stmt::StmtClass Class,
2867  SourceLocation LAngleLoc,
2868  TypeSourceInfo *TInfo,
2869  SourceLocation RAngleLoc,
2870  SourceLocation LParenLoc,
2871  Expr *SubExpr,
2872  SourceLocation RParenLoc) {
2873  switch (Class) {
2874  case Stmt::CXXStaticCastExprClass:
2875  return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2876  RAngleLoc, LParenLoc,
2877  SubExpr, RParenLoc);
2878 
2879  case Stmt::CXXDynamicCastExprClass:
2880  return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2881  RAngleLoc, LParenLoc,
2882  SubExpr, RParenLoc);
2883 
2884  case Stmt::CXXReinterpretCastExprClass:
2885  return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2886  RAngleLoc, LParenLoc,
2887  SubExpr,
2888  RParenLoc);
2889 
2890  case Stmt::CXXConstCastExprClass:
2891  return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2892  RAngleLoc, LParenLoc,
2893  SubExpr, RParenLoc);
2894 
2895  case Stmt::CXXAddrspaceCastExprClass:
2896  return getDerived().RebuildCXXAddrspaceCastExpr(
2897  OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
2898 
2899  default:
2900  llvm_unreachable("Invalid C++ named cast");
2901  }
2902  }
2903 
2904  /// Build a new C++ static_cast expression.
2905  ///
2906  /// By default, performs semantic analysis to build the new expression.
2907  /// Subclasses may override this routine to provide different behavior.
2909  SourceLocation LAngleLoc,
2910  TypeSourceInfo *TInfo,
2911  SourceLocation RAngleLoc,
2912  SourceLocation LParenLoc,
2913  Expr *SubExpr,
2914  SourceLocation RParenLoc) {
2915  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2916  TInfo, SubExpr,
2917  SourceRange(LAngleLoc, RAngleLoc),
2918  SourceRange(LParenLoc, RParenLoc));
2919  }
2920 
2921  /// Build a new C++ dynamic_cast expression.
2922  ///
2923  /// By default, performs semantic analysis to build the new expression.
2924  /// Subclasses may override this routine to provide different behavior.
2926  SourceLocation LAngleLoc,
2927  TypeSourceInfo *TInfo,
2928  SourceLocation RAngleLoc,
2929  SourceLocation LParenLoc,
2930  Expr *SubExpr,
2931  SourceLocation RParenLoc) {
2932  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2933  TInfo, SubExpr,
2934  SourceRange(LAngleLoc, RAngleLoc),
2935  SourceRange(LParenLoc, RParenLoc));
2936  }
2937 
2938  /// Build a new C++ reinterpret_cast expression.
2939  ///
2940  /// By default, performs semantic analysis to build the new expression.
2941  /// Subclasses may override this routine to provide different behavior.
2943  SourceLocation LAngleLoc,
2944  TypeSourceInfo *TInfo,
2945  SourceLocation RAngleLoc,
2946  SourceLocation LParenLoc,
2947  Expr *SubExpr,
2948  SourceLocation RParenLoc) {
2949  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2950  TInfo, SubExpr,
2951  SourceRange(LAngleLoc, RAngleLoc),
2952  SourceRange(LParenLoc, RParenLoc));
2953  }
2954 
2955  /// Build a new C++ const_cast expression.
2956  ///
2957  /// By default, performs semantic analysis to build the new expression.
2958  /// Subclasses may override this routine to provide different behavior.
2960  SourceLocation LAngleLoc,
2961  TypeSourceInfo *TInfo,
2962  SourceLocation RAngleLoc,
2963  SourceLocation LParenLoc,
2964  Expr *SubExpr,
2965  SourceLocation RParenLoc) {
2966  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2967  TInfo, SubExpr,
2968  SourceRange(LAngleLoc, RAngleLoc),
2969  SourceRange(LParenLoc, RParenLoc));
2970  }
2971 
2972  ExprResult
2974  TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
2975  SourceLocation LParenLoc, Expr *SubExpr,
2976  SourceLocation RParenLoc) {
2977  return getSema().BuildCXXNamedCast(
2978  OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
2979  SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
2980  }
2981 
2982  /// Build a new C++ functional-style cast expression.
2983  ///
2984  /// By default, performs semantic analysis to build the new expression.
2985  /// Subclasses may override this routine to provide different behavior.
2987  SourceLocation LParenLoc,
2988  Expr *Sub,
2989  SourceLocation RParenLoc,
2990  bool ListInitialization) {
2991  return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2992  MultiExprArg(&Sub, 1), RParenLoc,
2993  ListInitialization);
2994  }
2995 
2996  /// Build a new C++ __builtin_bit_cast expression.
2997  ///
2998  /// By default, performs semantic analysis to build the new expression.
2999  /// Subclasses may override this routine to provide different behavior.
3001  TypeSourceInfo *TSI, Expr *Sub,
3002  SourceLocation RParenLoc) {
3003  return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3004  }
3005 
3006  /// Build a new C++ typeid(type) expression.
3007  ///
3008  /// By default, performs semantic analysis to build the new expression.
3009  /// Subclasses may override this routine to provide different behavior.
3011  SourceLocation TypeidLoc,
3012  TypeSourceInfo *Operand,
3013  SourceLocation RParenLoc) {
3014  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3015  RParenLoc);
3016  }
3017 
3018 
3019  /// Build a new C++ typeid(expr) expression.
3020  ///
3021  /// By default, performs semantic analysis to build the new expression.
3022  /// Subclasses may override this routine to provide different behavior.
3024  SourceLocation TypeidLoc,
3025  Expr *Operand,
3026  SourceLocation RParenLoc) {
3027  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3028  RParenLoc);
3029  }
3030 
3031  /// Build a new C++ __uuidof(type) expression.
3032  ///
3033  /// By default, performs semantic analysis to build the new expression.
3034  /// Subclasses may override this routine to provide different behavior.
3036  TypeSourceInfo *Operand,
3037  SourceLocation RParenLoc) {
3038  return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3039  }
3040 
3041  /// Build a new C++ __uuidof(expr) expression.
3042  ///
3043  /// By default, performs semantic analysis to build the new expression.
3044  /// Subclasses may override this routine to provide different behavior.
3046  Expr *Operand, SourceLocation RParenLoc) {
3047  return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3048  }
3049 
3050  /// Build a new C++ "this" expression.
3051  ///
3052  /// By default, builds a new "this" expression without performing any
3053  /// semantic analysis. Subclasses may override this routine to provide
3054  /// different behavior.
3056  QualType ThisType,
3057  bool isImplicit) {
3058  return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3059  }
3060 
3061  /// Build a new C++ throw expression.
3062  ///
3063  /// By default, performs semantic analysis to build the new expression.
3064  /// Subclasses may override this routine to provide different behavior.
3066  bool IsThrownVariableInScope) {
3067  return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3068  }
3069 
3070  /// Build a new C++ default-argument expression.
3071  ///
3072  /// By default, builds a new default-argument expression, which does not
3073  /// require any semantic analysis. Subclasses may override this routine to
3074  /// provide different behavior.
3076  return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3077  getSema().CurContext);
3078  }
3079 
3080  /// Build a new C++11 default-initialization expression.
3081  ///
3082  /// By default, builds a new default field initialization expression, which
3083  /// does not require any semantic analysis. Subclasses may override this
3084  /// routine to provide different behavior.
3086  FieldDecl *Field) {
3087  return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
3088  getSema().CurContext);
3089  }
3090 
3091  /// Build a new C++ zero-initialization expression.
3092  ///
3093  /// By default, performs semantic analysis to build the new expression.
3094  /// Subclasses may override this routine to provide different behavior.
3096  SourceLocation LParenLoc,
3097  SourceLocation RParenLoc) {
3098  return getSema().BuildCXXTypeConstructExpr(
3099  TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
3100  }
3101 
3102  /// Build a new C++ "new" expression.
3103  ///
3104  /// By default, performs semantic analysis to build the new expression.
3105  /// Subclasses may override this routine to provide different behavior.
3107  bool UseGlobal,
3108  SourceLocation PlacementLParen,
3109  MultiExprArg PlacementArgs,
3110  SourceLocation PlacementRParen,
3111  SourceRange TypeIdParens,
3112  QualType AllocatedType,
3113  TypeSourceInfo *AllocatedTypeInfo,
3114  Optional<Expr *> ArraySize,
3115  SourceRange DirectInitRange,
3116  Expr *Initializer) {
3117  return getSema().BuildCXXNew(StartLoc, UseGlobal,
3118  PlacementLParen,
3119  PlacementArgs,
3120  PlacementRParen,
3121  TypeIdParens,
3122  AllocatedType,
3123  AllocatedTypeInfo,
3124  ArraySize,
3125  DirectInitRange,
3126  Initializer);
3127  }
3128 
3129  /// Build a new C++ "delete" expression.
3130  ///
3131  /// By default, performs semantic analysis to build the new expression.
3132  /// Subclasses may override this routine to provide different behavior.
3134  bool IsGlobalDelete,
3135  bool IsArrayForm,
3136  Expr *Operand) {
3137  return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3138  Operand);
3139  }
3140 
3141  /// Build a new type trait expression.
3142  ///
3143  /// By default, performs semantic analysis to build the new expression.
3144  /// Subclasses may override this routine to provide different behavior.
3146  SourceLocation StartLoc,
3148  SourceLocation RParenLoc) {
3149  return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3150  }
3151 
3152  /// Build a new array type trait expression.
3153  ///
3154  /// By default, performs semantic analysis to build the new expression.
3155  /// Subclasses may override this routine to provide different behavior.
3157  SourceLocation StartLoc,
3158  TypeSourceInfo *TSInfo,
3159  Expr *DimExpr,
3160  SourceLocation RParenLoc) {
3161  return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3162  }
3163 
3164  /// Build a new expression trait expression.
3165  ///
3166  /// By default, performs semantic analysis to build the new expression.
3167  /// Subclasses may override this routine to provide different behavior.
3169  SourceLocation StartLoc,
3170  Expr *Queried,
3171  SourceLocation RParenLoc) {
3172  return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3173  }
3174 
3175  /// Build a new (previously unresolved) declaration reference
3176  /// expression.
3177  ///
3178  /// By default, performs semantic analysis to build the new expression.
3179  /// Subclasses may override this routine to provide different behavior.
3181  NestedNameSpecifierLoc QualifierLoc,
3182  SourceLocation TemplateKWLoc,
3183  const DeclarationNameInfo &NameInfo,
3184  const TemplateArgumentListInfo *TemplateArgs,
3185  bool IsAddressOfOperand,
3186  TypeSourceInfo **RecoveryTSI) {
3187  CXXScopeSpec SS;
3188  SS.Adopt(QualifierLoc);
3189 
3190  if (TemplateArgs || TemplateKWLoc.isValid())
3191  return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
3192  TemplateArgs);
3193 
3194  return getSema().BuildQualifiedDeclarationNameExpr(
3195  SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
3196  }
3197 
3198  /// Build a new template-id expression.
3199  ///
3200  /// By default, performs semantic analysis to build the new expression.
3201  /// Subclasses may override this routine to provide different behavior.
3203  SourceLocation TemplateKWLoc,
3204  LookupResult &R,
3205  bool RequiresADL,
3206  const TemplateArgumentListInfo *TemplateArgs) {
3207  return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3208  TemplateArgs);
3209  }
3210 
3211  /// Build a new object-construction expression.
3212  ///
3213  /// By default, performs semantic analysis to build the new expression.
3214  /// Subclasses may override this routine to provide different behavior.
3216  SourceLocation Loc,
3217  CXXConstructorDecl *Constructor,
3218  bool IsElidable,
3219  MultiExprArg Args,
3220  bool HadMultipleCandidates,
3221  bool ListInitialization,
3222  bool StdInitListInitialization,
3223  bool RequiresZeroInit,
3224  CXXConstructExpr::ConstructionKind ConstructKind,
3225  SourceRange ParenRange) {
3226  // Reconstruct the constructor we originally found, which might be
3227  // different if this is a call to an inherited constructor.
3228  CXXConstructorDecl *FoundCtor = Constructor;
3229  if (Constructor->isInheritingConstructor())
3230  FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3231 
3232  SmallVector<Expr *, 8> ConvertedArgs;
3233  if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3234  ConvertedArgs))
3235  return ExprError();
3236 
3237  return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3238  IsElidable,
3239  ConvertedArgs,
3240  HadMultipleCandidates,
3241  ListInitialization,
3242  StdInitListInitialization,
3243  RequiresZeroInit, ConstructKind,
3244  ParenRange);
3245  }
3246 
3247  /// Build a new implicit construction via inherited constructor
3248  /// expression.
3250  CXXConstructorDecl *Constructor,
3251  bool ConstructsVBase,
3252  bool InheritedFromVBase) {
3253  return new (getSema().Context) CXXInheritedCtorInitExpr(
3254  Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3255  }
3256 
3257  /// Build a new object-construction expression.
3258  ///
3259  /// By default, performs semantic analysis to build the new expression.
3260  /// Subclasses may override this routine to provide different behavior.
3262  SourceLocation LParenOrBraceLoc,
3263  MultiExprArg Args,
3264  SourceLocation RParenOrBraceLoc,
3265  bool ListInitialization) {
3266  return getSema().BuildCXXTypeConstructExpr(
3267  TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3268  }
3269 
3270  /// Build a new object-construction expression.
3271  ///
3272  /// By default, performs semantic analysis to build the new expression.
3273  /// Subclasses may override this routine to provide different behavior.
3275  SourceLocation LParenLoc,
3276  MultiExprArg Args,
3277  SourceLocation RParenLoc,
3278  bool ListInitialization) {
3279  return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3280  RParenLoc, ListInitialization);
3281  }
3282 
3283  /// Build a new member reference expression.
3284  ///
3285  /// By default, performs semantic analysis to build the new expression.
3286  /// Subclasses may override this routine to provide different behavior.
3288  QualType BaseType,
3289  bool IsArrow,
3290  SourceLocation OperatorLoc,
3291  NestedNameSpecifierLoc QualifierLoc,
3292  SourceLocation TemplateKWLoc,
3293  NamedDecl *FirstQualifierInScope,
3294  const DeclarationNameInfo &MemberNameInfo,
3295  const TemplateArgumentListInfo *TemplateArgs) {
3296  CXXScopeSpec SS;
3297  SS.Adopt(QualifierLoc);
3298 
3299  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3300  OperatorLoc, IsArrow,
3301  SS, TemplateKWLoc,
3302  FirstQualifierInScope,
3303  MemberNameInfo,
3304  TemplateArgs, /*S*/nullptr);
3305  }
3306 
3307  /// Build a new member reference expression.
3308  ///
3309  /// By default, performs semantic analysis to build the new expression.
3310  /// Subclasses may override this routine to provide different behavior.
3312  SourceLocation OperatorLoc,
3313  bool IsArrow,
3314  NestedNameSpecifierLoc QualifierLoc,
3315  SourceLocation TemplateKWLoc,
3316  NamedDecl *FirstQualifierInScope,
3317  LookupResult &R,
3318  const TemplateArgumentListInfo *TemplateArgs) {
3319  CXXScopeSpec SS;
3320  SS.Adopt(QualifierLoc);
3321 
3322  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3323  OperatorLoc, IsArrow,
3324  SS, TemplateKWLoc,
3325  FirstQualifierInScope,
3326  R, TemplateArgs, /*S*/nullptr);
3327  }
3328 
3329  /// Build a new noexcept expression.
3330  ///
3331  /// By default, performs semantic analysis to build the new expression.
3332  /// Subclasses may override this routine to provide different behavior.
3334  return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3335  }
3336 
3337  /// Build a new expression to compute the length of a parameter pack.
3339  NamedDecl *Pack,
3340  SourceLocation PackLoc,
3341  SourceLocation RParenLoc,
3342  Optional<unsigned> Length,
3343  ArrayRef<TemplateArgument> PartialArgs) {
3344  return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3345  RParenLoc, Length, PartialArgs);
3346  }
3347 
3348  /// Build a new expression representing a call to a source location
3349  /// builtin.
3350  ///
3351  /// By default, performs semantic analysis to build the new expression.
3352  /// Subclasses may override this routine to provide different behavior.
3354  SourceLocation BuiltinLoc,
3355  SourceLocation RPLoc,
3356  DeclContext *ParentContext) {
3357  return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3358  }
3359 
3360  /// Build a new Objective-C boxed expression.
3361  ///
3362  /// By default, performs semantic analysis to build the new expression.
3363  /// Subclasses may override this routine to provide different behavior.
3365  SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3366  NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3367  TemplateArgumentListInfo *TALI) {
3368  CXXScopeSpec SS;
3369  SS.Adopt(NNS);
3370  ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3371  ConceptNameInfo,
3372  FoundDecl,
3373  NamedConcept, TALI);
3374  if (Result.isInvalid())
3375  return ExprError();
3376  return Result;
3377  }
3378 
3379  /// \brief Build a new requires expression.
3380  ///
3381  /// By default, performs semantic analysis to build the new expression.
3382  /// Subclasses may override this routine to provide different behavior.
3384  RequiresExprBodyDecl *Body,
3385  ArrayRef<ParmVarDecl *> LocalParameters,
3386  ArrayRef<concepts::Requirement *> Requirements,
3387  SourceLocation ClosingBraceLoc) {
3388  return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body,
3389  LocalParameters, Requirements, ClosingBraceLoc);
3390  }
3391 
3395  return SemaRef.BuildTypeRequirement(SubstDiag);
3396  }
3397 
3399  return SemaRef.BuildTypeRequirement(T);
3400  }
3401 
3404  concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3405  SourceLocation NoexceptLoc,
3407  return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3408  std::move(Ret));
3409  }
3410 
3412  RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3414  return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3415  std::move(Ret));
3416  }
3417 
3421  return SemaRef.BuildNestedRequirement(SubstDiag);
3422  }
3423 
3425  return SemaRef.BuildNestedRequirement(Constraint);
3426  }
3427 
3428  /// \brief Build a new Objective-C boxed expression.
3429  ///
3430  /// By default, performs semantic analysis to build the new expression.
3431  /// Subclasses may override this routine to provide different behavior.
3433  return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3434  }
3435 
3436  /// Build a new Objective-C array literal.
3437  ///
3438  /// By default, performs semantic analysis to build the new expression.
3439  /// Subclasses may override this routine to provide different behavior.
3441  Expr **Elements, unsigned NumElements) {
3442  return getSema().BuildObjCArrayLiteral(Range,
3443  MultiExprArg(Elements, NumElements));
3444  }
3445 
3447  Expr *Base, Expr *Key,
3448  ObjCMethodDecl *getterMethod,
3449  ObjCMethodDecl *setterMethod) {
3450  return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3451  getterMethod, setterMethod);
3452  }
3453 
3454  /// Build a new Objective-C dictionary literal.
3455  ///
3456  /// By default, performs semantic analysis to build the new expression.
3457  /// Subclasses may override this routine to provide different behavior.
3460  return getSema().BuildObjCDictionaryLiteral(Range, Elements);
3461  }
3462 
3463  /// Build a new Objective-C \@encode expression.
3464  ///
3465  /// By default, performs semantic analysis to build the new expression.
3466  /// Subclasses may override this routine to provide different behavior.
3468  TypeSourceInfo *EncodeTypeInfo,
3469  SourceLocation RParenLoc) {
3470  return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
3471  }
3472 
3473  /// Build a new Objective-C class message.
3475  Selector Sel,
3476  ArrayRef<SourceLocation> SelectorLocs,
3477  ObjCMethodDecl *Method,
3478  SourceLocation LBracLoc,
3479  MultiExprArg Args,
3480  SourceLocation RBracLoc) {
3481  return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3482  ReceiverTypeInfo->getType(),
3483  /*SuperLoc=*/SourceLocation(),
3484  Sel, Method, LBracLoc, SelectorLocs,
3485  RBracLoc, Args);
3486  }
3487 
3488  /// Build a new Objective-C instance message.
3490  Selector Sel,
3491  ArrayRef<SourceLocation> SelectorLocs,
3492  ObjCMethodDecl *Method,
3493  SourceLocation LBracLoc,
3494  MultiExprArg Args,
3495  SourceLocation RBracLoc) {
3496  return SemaRef.BuildInstanceMessage(Receiver,
3497  Receiver->getType(),
3498  /*SuperLoc=*/SourceLocation(),
3499  Sel, Method, LBracLoc, SelectorLocs,
3500  RBracLoc, Args);
3501  }
3502 
3503  /// Build a new Objective-C instance/class message to 'super'.
3505  Selector Sel,
3506  ArrayRef<SourceLocation> SelectorLocs,
3507  QualType SuperType,
3508  ObjCMethodDecl *Method,
3509  SourceLocation LBracLoc,
3510  MultiExprArg Args,
3511  SourceLocation RBracLoc) {
3512  return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3513  SuperType,
3514  SuperLoc,
3515  Sel, Method, LBracLoc, SelectorLocs,
3516  RBracLoc, Args)
3517  : SemaRef.BuildClassMessage(nullptr,
3518  SuperType,
3519  SuperLoc,
3520  Sel, Method, LBracLoc, SelectorLocs,
3521  RBracLoc, Args);
3522 
3523 
3524  }
3525 
3526  /// Build a new Objective-C ivar reference expression.
3527  ///
3528  /// By default, performs semantic analysis to build the new expression.
3529  /// Subclasses may override this routine to provide different behavior.
3531  SourceLocation IvarLoc,
3532  bool IsArrow, bool IsFreeIvar) {
3533  CXXScopeSpec SS;
3534  DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3535  ExprResult Result = getSema().BuildMemberReferenceExpr(
3536  BaseArg, BaseArg->getType(),
3537  /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3538  /*FirstQualifierInScope=*/nullptr, NameInfo,
3539  /*TemplateArgs=*/nullptr,
3540  /*S=*/nullptr);
3541  if (IsFreeIvar && Result.isUsable())
3542  cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3543  return Result;
3544  }
3545 
3546  /// Build a new Objective-C property reference expression.
3547  ///
3548  /// By default, performs semantic analysis to build the new expression.
3549  /// Subclasses may override this routine to provide different behavior.
3551  ObjCPropertyDecl *Property,
3552  SourceLocation PropertyLoc) {
3553  CXXScopeSpec SS;
3554  DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3555  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3556  /*FIXME:*/PropertyLoc,
3557  /*IsArrow=*/false,
3558  SS, SourceLocation(),
3559  /*FirstQualifierInScope=*/nullptr,
3560  NameInfo,
3561  /*TemplateArgs=*/nullptr,
3562  /*S=*/nullptr);
3563  }
3564 
3565  /// Build a new Objective-C property reference expression.
3566  ///
3567  /// By default, performs semantic analysis to build the new expression.
3568  /// Subclasses may override this routine to provide different behavior.
3570  ObjCMethodDecl *Getter,
3571  ObjCMethodDecl *Setter,
3572  SourceLocation PropertyLoc) {
3573  // Since these expressions can only be value-dependent, we do not
3574  // need to perform semantic analysis again.
3575  return Owned(
3576  new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3578  PropertyLoc, Base));
3579  }
3580 
3581  /// Build a new Objective-C "isa" expression.
3582  ///
3583  /// By default, performs semantic analysis to build the new expression.
3584  /// Subclasses may override this routine to provide different behavior.
3586  SourceLocation OpLoc, bool IsArrow) {
3587  CXXScopeSpec SS;
3588  DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3589  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3590  OpLoc, IsArrow,
3591  SS, SourceLocation(),
3592  /*FirstQualifierInScope=*/nullptr,
3593  NameInfo,
3594  /*TemplateArgs=*/nullptr,
3595  /*S=*/nullptr);
3596  }
3597 
3598  /// Build a new shuffle vector expression.
3599  ///
3600  /// By default, performs semantic analysis to build the new expression.
3601  /// Subclasses may override this routine to provide different behavior.
3603  MultiExprArg SubExprs,
3604  SourceLocation RParenLoc) {
3605  // Find the declaration for __builtin_shufflevector
3606  const IdentifierInfo &Name
3607  = SemaRef.Context.Idents.get("__builtin_shufflevector");
3609  DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3610  assert(!Lookup.empty() && "No __builtin_shufflevector?");
3611 
3612  // Build a reference to the __builtin_shufflevector builtin
3613  FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3614  Expr *Callee = new (SemaRef.Context)
3615  DeclRefExpr(SemaRef.Context, Builtin, false,
3616  SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3617  QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3618  Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3619  CK_BuiltinFnToFnPtr).get();
3620 
3621  // Build the CallExpr
3622  ExprResult TheCall = CallExpr::Create(
3623  SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3624  Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3625  FPOptionsOverride());
3626 
3627  // Type-check the __builtin_shufflevector expression.
3628  return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3629  }
3630 
3631  /// Build a new convert vector expression.
3633  Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3634  SourceLocation RParenLoc) {
3635  return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3636  BuiltinLoc, RParenLoc);
3637  }
3638 
3639  /// Build a new template argument pack expansion.
3640  ///
3641  /// By default, performs semantic analysis to build a new pack expansion
3642  /// for a template argument. Subclasses may override this routine to provide
3643  /// different behavior.
3645  SourceLocation EllipsisLoc,
3646  Optional<unsigned> NumExpansions) {
3647  switch (Pattern.getArgument().getKind()) {
3648  case TemplateArgument::Expression: {
3649  ExprResult Result
3650  = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3651  EllipsisLoc, NumExpansions);
3652  if (Result.isInvalid())
3653  return TemplateArgumentLoc();
3654 
3655  return TemplateArgumentLoc(Result.get(), Result.get());
3656  }
3657 
3658  case TemplateArgument::Template:
3659  return TemplateArgumentLoc(
3660  SemaRef.Context,
3662  NumExpansions),
3663  Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3664  EllipsisLoc);
3665 
3667  case TemplateArgument::Integral:
3668  case TemplateArgument::Declaration:
3669  case TemplateArgument::Pack:
3670  case TemplateArgument::TemplateExpansion:
3671  case TemplateArgument::NullPtr:
3672  llvm_unreachable("Pack expansion pattern has no parameter packs");
3673 
3675  if (TypeSourceInfo *Expansion
3676  = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3677  EllipsisLoc,
3678  NumExpansions))
3679  return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3680  Expansion);
3681  break;
3682  }
3683 
3684  return TemplateArgumentLoc();
3685  }
3686 
3687  /// Build a new expression pack expansion.
3688  ///
3689  /// By default, performs semantic analysis to build a new pack expansion
3690  /// for an expression. Subclasses may override this routine to provide
3691  /// different behavior.
3693  Optional<unsigned> NumExpansions) {
3694  return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3695  }
3696 
3697  /// Build a new C++1z fold-expression.
3698  ///
3699  /// By default, performs semantic analysis in order to build a new fold
3700  /// expression.
3702  SourceLocation LParenLoc, Expr *LHS,
3703  BinaryOperatorKind Operator,
3704  SourceLocation EllipsisLoc, Expr *RHS,
3705  SourceLocation RParenLoc,
3706  Optional<unsigned> NumExpansions) {
3707  return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
3708  EllipsisLoc, RHS, RParenLoc,
3709  NumExpansions);
3710  }
3711 
3712  /// Build an empty C++1z fold-expression with the given operator.
3713  ///
3714  /// By default, produces the fallback value for the fold-expression, or
3715  /// produce an error if there is no fallback value.
3717  BinaryOperatorKind Operator) {
3718  return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3719  }
3720 
3721  /// Build a new atomic operation expression.
3722  ///
3723  /// By default, performs semantic analysis to build the new expression.
3724  /// Subclasses may override this routine to provide different behavior.
3727  SourceLocation RParenLoc) {
3728  // Use this for all of the locations, since we don't know the difference
3729  // between the call and the expr at this point.
3730  SourceRange Range{BuiltinLoc, RParenLoc};
3731  return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
3732  Sema::AtomicArgumentOrder::AST);
3733  }
3734 
3736  ArrayRef<Expr *> SubExprs, QualType Type) {
3737  return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
3738  }
3739 
3740 private:
3741  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3742  QualType ObjectType,
3743  NamedDecl *FirstQualifierInScope,
3744  CXXScopeSpec &SS);
3745 
3746  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3747  QualType ObjectType,
3748  NamedDecl *FirstQualifierInScope,
3749  CXXScopeSpec &SS);
3750 
3751  TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3752  NamedDecl *FirstQualifierInScope,
3753  CXXScopeSpec &SS);
3754 
3755  QualType TransformDependentNameType(TypeLocBuilder &TLB,
3757  bool DeducibleTSTContext);
3758 };
3759 
3760 template <typename Derived>
3762  if (!S)
3763  return S;
3764 
3765  switch (S->getStmtClass()) {
3766  case Stmt::NoStmtClass: break;
3767 
3768  // Transform individual statement nodes
3769  // Pass SDK into statements that can produce a value
3770 #define STMT(Node, Parent) \
3771  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3772 #define VALUESTMT(Node, Parent) \
3773  case Stmt::Node##Class: \
3774  return getDerived().Transform##Node(cast<Node>(S), SDK);
3775 #define ABSTRACT_STMT(Node)
3776 #define EXPR(Node, Parent)
3777 #include "clang/AST/StmtNodes.inc"
3778 
3779  // Transform expressions by calling TransformExpr.
3780 #define STMT(Node, Parent)
3781 #define ABSTRACT_STMT(Stmt)
3782 #define EXPR(Node, Parent) case Stmt::Node##Class:
3783 #include "clang/AST/StmtNodes.inc"
3784  {
3785  ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3786 
3787  if (SDK == SDK_StmtExprResult)
3788  E = getSema().ActOnStmtExprResult(E);
3789  return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
3790  }
3791  }
3792 
3793  return S;
3794 }
3795 
3796 template<typename Derived>
3798  if (!S)
3799  return S;
3800 
3801  switch (S->getClauseKind()) {
3802  default: break;
3803  // Transform individual clause nodes
3804 #define GEN_CLANG_CLAUSE_CLASS
3805 #define CLAUSE_CLASS(Enum, Str, Class) \
3806  case Enum: \
3807  return getDerived().Transform##Class(cast<Class>(S));
3808 #include "llvm/Frontend/OpenMP/OMP.inc"
3809  }
3810 
3811  return S;
3812 }
3813 
3814 
3815 template<typename Derived>
3817  if (!E)
3818  return E;
3819 
3820  switch (E->getStmtClass()) {
3821  case Stmt::NoStmtClass: break;
3822 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3823 #define ABSTRACT_STMT(Stmt)
3824 #define EXPR(Node, Parent) \
3825  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3826 #include "clang/AST/StmtNodes.inc"
3827  }
3828 
3829  return E;
3830 }
3831 
3832 template<typename Derived>
3834  bool NotCopyInit) {
3835  // Initializers are instantiated like expressions, except that various outer
3836  // layers are stripped.
3837  if (!Init)
3838  return Init;
3839 
3840  if (auto *FE = dyn_cast<FullExpr>(Init))
3841  Init = FE->getSubExpr();
3842 
3843  if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3844  Init = AIL->getCommonExpr();
3845 
3846  if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3847  Init = MTE->getSubExpr();
3848 
3849  while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3850  Init = Binder->getSubExpr();
3851 
3852  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3853  Init = ICE->getSubExprAsWritten();
3854 
3855  if (CXXStdInitializerListExpr *ILE =
3856  dyn_cast<CXXStdInitializerListExpr>(Init))
3857  return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3858 
3859  // If this is copy-initialization, we only need to reconstruct
3860  // InitListExprs. Other forms of copy-initialization will be a no-op if
3861  // the initializer is already the right type.
3862  CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3863  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3864  return getDerived().TransformExpr(Init);
3865 
3866  // Revert value-initialization back to empty parens.
3867  if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3868  SourceRange Parens = VIE->getSourceRange();
3869  return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3870  Parens.getEnd());
3871  }
3872 
3873  // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3874  if (isa<ImplicitValueInitExpr>(Init))
3875  return getDerived().RebuildParenListExpr(SourceLocation(), None,
3876  SourceLocation());
3877 
3878  // Revert initialization by constructor back to a parenthesized or braced list
3879  // of expressions. Any other form of initializer can just be reused directly.
3880  if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3881  return getDerived().TransformExpr(Init);
3882 
3883  // If the initialization implicitly converted an initializer list to a
3884  // std::initializer_list object, unwrap the std::initializer_list too.
3885  if (Construct && Construct->isStdInitListInitialization())
3886  return TransformInitializer(Construct->getArg(0), NotCopyInit);
3887 
3888  // Enter a list-init context if this was list initialization.
3890  getSema(), EnterExpressionEvaluationContext::InitList,
3891  Construct->isListInitialization());
3892 
3893  SmallVector<Expr*, 8> NewArgs;
3894  bool ArgChanged = false;
3895  if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3896  /*IsCall*/true, NewArgs, &ArgChanged))
3897  return ExprError();
3898 
3899  // If this was list initialization, revert to syntactic list form.
3900  if (Construct->isListInitialization())
3901  return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
3902  Construct->getEndLoc());
3903 
3904  // Build a ParenListExpr to represent anything else.
3905  SourceRange Parens = Construct->getParenOrBraceRange();
3906  if (Parens.isInvalid()) {
3907  // This was a variable declaration's initialization for which no initializer
3908  // was specified.
3909  assert(NewArgs.empty() &&
3910  "no parens or braces but have direct init with arguments?");
3911  return ExprEmpty();
3912  }
3913  return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3914  Parens.getEnd());
3915 }
3916 
3917 template<typename Derived>
3919  unsigned NumInputs,
3920  bool IsCall,
3921  SmallVectorImpl<Expr *> &Outputs,
3922  bool *ArgChanged) {
3923  for (unsigned I = 0; I != NumInputs; ++I) {
3924  // If requested, drop call arguments that need to be dropped.
3925  if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3926  if (ArgChanged)
3927  *ArgChanged = true;
3928 
3929  break;
3930  }
3931 
3932  if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3933  Expr *Pattern = Expansion->getPattern();
3934 
3936  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3937  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3938 
3939  // Determine whether the set of unexpanded parameter packs can and should
3940  // be expanded.
3941  bool Expand = true;
3942  bool RetainExpansion = false;
3943  Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3944  Optional<unsigned> NumExpansions = OrigNumExpansions;
3945  if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3946  Pattern->getSourceRange(),
3947  Unexpanded,
3948  Expand, RetainExpansion,
3949  NumExpansions))
3950  return true;
3951 
3952  if (!Expand) {
3953  // The transform has determined that we should perform a simple
3954  // transformation on the pack expansion, producing another pack
3955  // expansion.
3956  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3957  ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3958  if (OutPattern.isInvalid())
3959  return true;
3960 
3961  ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3962  Expansion->getEllipsisLoc(),
3963  NumExpansions);
3964  if (Out.isInvalid())
3965  return true;
3966 
3967  if (ArgChanged)
3968  *ArgChanged = true;
3969  Outputs.push_back(Out.get());
3970  continue;
3971  }
3972 
3973  // Record right away that the argument was changed. This needs
3974  // to happen even if the array expands to nothing.
3975  if (ArgChanged) *ArgChanged = true;
3976 
3977  // The transform has determined that we should perform an elementwise
3978  // expansion of the pattern. Do so.
3979  for (unsigned I = 0; I != *NumExpansions; ++I) {
3980  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3981  ExprResult Out = getDerived().TransformExpr(Pattern);
3982  if (Out.isInvalid())
3983  return true;
3984 
3985  if (Out.get()->containsUnexpandedParameterPack()) {
3986  Out = getDerived().RebuildPackExpansion(
3987  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3988  if (Out.isInvalid())
3989  return true;
3990  }
3991 
3992  Outputs.push_back(Out.get());
3993  }
3994 
3995  // If we're supposed to retain a pack expansion, do so by temporarily
3996  // forgetting the partially-substituted parameter pack.
3997  if (RetainExpansion) {
3998  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3999 
4000  ExprResult Out = getDerived().TransformExpr(Pattern);
4001  if (Out.isInvalid())
4002  return true;
4003 
4004  Out = getDerived().RebuildPackExpansion(
4005  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4006  if (Out.isInvalid())
4007  return true;
4008 
4009  Outputs.push_back(Out.get());
4010  }
4011 
4012  continue;
4013  }
4014 
4015  ExprResult Result =
4016  IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4017  : getDerived().TransformExpr(Inputs[I]);
4018  if (Result.isInvalid())
4019  return true;
4020 
4021  if (Result.get() != Inputs[I] && ArgChanged)
4022  *ArgChanged = true;
4023 
4024  Outputs.push_back(Result.get());
4025  }
4026 
4027  return false;
4028 }
4029 
4030 template <typename Derived>
4033  if (Var) {
4034  VarDecl *ConditionVar = cast_or_null<VarDecl>(
4035  getDerived().TransformDefinition(Var->getLocation(), Var));
4036 
4037  if (!ConditionVar)
4038  return Sema::ConditionError();
4039 
4040  return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4041  }
4042 
4043  if (Expr) {
4044  ExprResult CondExpr = getDerived().TransformExpr(Expr);
4045 
4046  if (CondExpr.isInvalid())
4047  return Sema::ConditionError();
4048 
4049  return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
4050  }
4051 
4052  return Sema::ConditionResult();
4053 }
4054 
4055 template <typename Derived>
4057  NestedNameSpecifierLoc NNS, QualType ObjectType,
4058  NamedDecl *FirstQualifierInScope) {
4060  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4061  Qualifier = Qualifier.getPrefix())
4062  Qualifiers.push_back(Qualifier);
4063 
4064  CXXScopeSpec SS;
4065  while (!Qualifiers.empty()) {
4066  NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4068 
4069  switch (QNNS->getKind()) {
4073  ObjectType);
4074  if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4075  SS, FirstQualifierInScope, false))
4076  return NestedNameSpecifierLoc();
4077  break;
4078  }
4079 
4080  case NestedNameSpecifier::Namespace: {
4081  NamespaceDecl *NS =
4082  cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4083  Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4084  SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4085  break;
4086  }
4087 
4088  case NestedNameSpecifier::NamespaceAlias: {
4089  NamespaceAliasDecl *Alias =
4090  cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4091  Q.getLocalBeginLoc(), QNNS->getAsNamespaceAlias()));
4092  SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4093  Q.getLocalEndLoc());
4094  break;
4095  }
4096 
4097  case NestedNameSpecifier::Global:
4098  // There is no meaningful transformation that one could perform on the
4099  // global scope.
4100  SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4101  break;
4102 
4103  case NestedNameSpecifier::Super: {
4104  CXXRecordDecl *RD =
4105  cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4106  SourceLocation(), QNNS->getAsRecordDecl()));
4107  SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4108  break;
4109  }
4110 
4111  case NestedNameSpecifier::TypeSpecWithTemplate:
4112  case NestedNameSpecifier::TypeSpec: {
4113  TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4114  FirstQualifierInScope, SS);
4115 
4116  if (!TL)
4117  return NestedNameSpecifierLoc();
4118 
4119  if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
4120  (SemaRef.getLangOpts().CPlusPlus11 &&
4121  TL.getType()->isEnumeralType())) {
4122  assert(!TL.getType().hasLocalQualifiers() &&
4123  "Can't get cv-qualifiers here");
4124  if (TL.getType()->isEnumeralType())
4125  SemaRef.Diag(TL.getBeginLoc(),
4126  diag::warn_cxx98_compat_enum_nested_name_spec);
4127  SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL,
4128  Q.getLocalEndLoc());
4129  break;
4130  }
4131  // If the nested-name-specifier is an invalid type def, don't emit an
4132  // error because a previous error should have already been emitted.
4133  TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
4134  if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4135  SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4136  << TL.getType() << SS.getRange();
4137  }
4138  return NestedNameSpecifierLoc();
4139  }
4140  }
4141 
4142  // The qualifier-in-scope and object type only apply to the leftmost entity.
4143  FirstQualifierInScope = nullptr;
4144  ObjectType = QualType();
4145  }
4146 
4147  // Don't rebuild the nested-name-specifier if we don't have to.
4148  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4149  !getDerived().AlwaysRebuild())
4150  return NNS;
4151 
4152  // If we can re-use the source-location data from the original
4153  // nested-name-specifier, do so.
4154  if (SS.location_size() == NNS.getDataLength() &&
4155  memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4156  return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
4157 
4158  // Allocate new nested-name-specifier location information.
4159  return SS.getWithLocInContext(SemaRef.Context);
4160 }
4161 
4162 template<typename Derived>
4166  DeclarationName Name = NameInfo.getName();
4167  if (!Name)
4168  return DeclarationNameInfo();
4169 
4170  switch (Name.getNameKind()) {
4172  case DeclarationName::ObjCZeroArgSelector:
4173  case DeclarationName::ObjCOneArgSelector:
4174  case DeclarationName::ObjCMultiArgSelector:
4175  case DeclarationName::CXXOperatorName:
4176  case DeclarationName::CXXLiteralOperatorName:
4177  case DeclarationName::CXXUsingDirective:
4178  return NameInfo;
4179 
4180  case DeclarationName::CXXDeductionGuideName: {
4181  TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4182  TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4183  getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4184  if (!NewTemplate)
4185  return DeclarationNameInfo();
4186 
4187  DeclarationNameInfo NewNameInfo(NameInfo);
4188  NewNameInfo.setName(
4189  SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4190  return NewNameInfo;
4191  }
4192 
4193  case DeclarationName::CXXConstructorName:
4194  case DeclarationName::CXXDestructorName:
4195  case DeclarationName::CXXConversionFunctionName: {
4196  TypeSourceInfo *NewTInfo;
4197  CanQualType NewCanTy;
4198  if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4199  NewTInfo = getDerived().TransformType(OldTInfo);
4200  if (!NewTInfo)
4201  return DeclarationNameInfo();
4202  NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4203  }
4204  else {
4205  NewTInfo = nullptr;
4206  TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4207  QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4208  if (NewT.isNull())
4209  return DeclarationNameInfo();
4210  NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4211  }
4212 
4213  DeclarationName NewName
4214  = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4215  NewCanTy);
4216  DeclarationNameInfo NewNameInfo(NameInfo);
4217  NewNameInfo.setName(NewName);
4218  NewNameInfo.setNamedTypeInfo(NewTInfo);
4219  return NewNameInfo;
4220  }
4221  }
4222 
4223  llvm_unreachable("Unknown name kind.");
4224 }
4225 
4226 template<typename Derived>
4229  TemplateName Name,
4230  SourceLocation NameLoc,
4231  QualType ObjectType,
4232  NamedDecl *FirstQualifierInScope,
4233  bool AllowInjectedClassName) {
4234  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4235  TemplateDecl *Template = QTN->getTemplateDecl();
4236  assert(Template && "qualified template name must refer to a template");
4237 
4238  TemplateDecl *TransTemplate
4239  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4240  Template));
4241  if (!TransTemplate)
4242  return TemplateName();
4243 
4244  if (!getDerived().AlwaysRebuild() &&
4245  SS.getScopeRep() == QTN->getQualifier() &&
4246  TransTemplate == Template)
4247  return Name;
4248 
4249  return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4250  TransTemplate);
4251  }
4252 
4253  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4254  if (SS.getScopeRep()) {
4255  // These apply to the scope specifier, not the template.
4256  ObjectType = QualType();
4257  FirstQualifierInScope = nullptr;
4258  }
4259 
4260  if (!getDerived().AlwaysRebuild() &&
4261  SS.getScopeRep() == DTN->getQualifier() &&
4262  ObjectType.isNull())
4263  return Name;
4264 
4265  // FIXME: Preserve the location of the "template" keyword.
4266  SourceLocation TemplateKWLoc = NameLoc;
4267 
4268  if (DTN->isIdentifier()) {
4269  return getDerived().RebuildTemplateName(SS,
4270  TemplateKWLoc,
4271  *DTN->getIdentifier(),
4272  NameLoc,
4273  ObjectType,
4274  FirstQualifierInScope,
4275  AllowInjectedClassName);
4276  }
4277 
4278  return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4279  DTN->getOperator(), NameLoc,
4280  ObjectType, AllowInjectedClassName);
4281  }
4282 
4283  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4284  TemplateDecl *TransTemplate
4285  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4286  Template));
4287  if (!TransTemplate)
4288  return TemplateName();
4289 
4290  if (!getDerived().AlwaysRebuild() &&
4291  TransTemplate == Template)
4292  return Name;
4293 
4294  return TemplateName(TransTemplate);
4295  }
4296 
4298  = Name.getAsSubstTemplateTemplateParmPack()) {
4299  TemplateTemplateParmDecl *TransParam
4300  = cast_or_null<TemplateTemplateParmDecl>(
4301  getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
4302  if (!TransParam)
4303  return TemplateName();
4304 
4305  if (!getDerived().AlwaysRebuild() &&
4306  TransParam == SubstPack->getParameterPack())
4307  return Name;
4308 
4309  return getDerived().RebuildTemplateName(TransParam,
4310  SubstPack->getArgumentPack());
4311  }
4312 
4313  // These should be getting filtered out before they reach the AST.
4314  llvm_unreachable("overloaded function decl survived to here");
4315 }
4316 
4317 template<typename Derived>
4319  const TemplateArgument &Arg,
4320  TemplateArgumentLoc &Output) {
4321  Output = getSema().getTrivialTemplateArgumentLoc(
4322  Arg, QualType(), getDerived().getBaseLocation());
4323 }
4324 
4325 template <typename Derived>
4327  const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4328  bool Uneval) {
4329  const TemplateArgument &Arg = Input.getArgument();
4330  switch (Arg.getKind()) {
4332  case TemplateArgument::Pack:
4333  llvm_unreachable("Unexpected TemplateArgument");
4334 
4335  case TemplateArgument::Integral:
4336  case TemplateArgument::NullPtr:
4337  case TemplateArgument::Declaration: {
4338  // Transform a resolved template argument straight to a resolved template
4339  // argument. We get here when substituting into an already-substituted
4340  // template type argument during concept satisfaction checking.
4342  QualType NewT = getDerived().TransformType(T);
4343  if (NewT.isNull())
4344  return true;
4345 
4346  ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration
4347  ? Arg.getAsDecl()
4348  : nullptr;
4349  ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4350  getDerived().getBaseLocation(), D))
4351  : nullptr;
4352  if (D && !NewD)
4353  return true;
4354 
4355  if (NewT == T && D == NewD)
4356  Output = Input;
4357  else if (Arg.getKind() == TemplateArgument::Integral)
4358  Output = TemplateArgumentLoc(
4359  TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4361  else if (Arg.getKind() == TemplateArgument::NullPtr)
4362  Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4364  else
4365  Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4367 
4368  return false;
4369  }
4370 
4371  case TemplateArgument::Type: {
4372  TypeSourceInfo *DI = Input.getTypeSourceInfo();
4373  if (!DI)
4374  DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4375 
4376  DI = getDerived().TransformType(DI);
4377  if (!DI)
4378  return true;
4379 
4380  Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4381  return false;
4382  }
4383 
4384  case TemplateArgument::Template: {
4385  NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4386  if (QualifierLoc) {
4387  QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4388  if (!QualifierLoc)
4389  return true;
4390  }
4391 
4392  CXXScopeSpec SS;
4393  SS.Adopt(QualifierLoc);
4394  TemplateName Template = getDerived().TransformTemplateName(
4395  SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4396  if (Template.isNull())
4397  return true;
4398 
4399  Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4400  QualifierLoc, Input.getTemplateNameLoc());
4401  return false;
4402  }
4403 
4404  case TemplateArgument::TemplateExpansion:
4405  llvm_unreachable("Caller should expand pack expansions");
4406 
4407  case TemplateArgument::Expression: {
4408  // Template argument expressions are constant expressions.
4410  getSema(),
4411  Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
4412  : Sema::ExpressionEvaluationContext::ConstantEvaluated,
4413  /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4414  Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
4415 
4416  Expr *InputExpr = Input.getSourceExpression();
4417  if (!InputExpr)
4418  InputExpr = Input.getArgument().getAsExpr();
4419 
4420  ExprResult E = getDerived().TransformExpr(InputExpr);
4421  E = SemaRef.ActOnConstantExpression(E);
4422  if (E.isInvalid())
4423  return true;
4424  Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4425  return false;
4426  }
4427  }
4428 
4429  // Work around bogus GCC warning
4430  return true;
4431 }
4432 
4433 /// Iterator adaptor that invents template argument location information
4434 /// for each of the template arguments in its underlying iterator.
4435 template<typename Derived, typename InputIterator>
4437  TreeTransform<Derived> &Self;
4438  InputIterator Iter;
4439 
4440 public:
4443  typedef typename std::iterator_traits<InputIterator>::difference_type
4445  typedef std::input_iterator_tag iterator_category;
4446 
4447  class pointer {
4448  TemplateArgumentLoc Arg;
4449 
4450  public:
4451  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4452 
4453  const TemplateArgumentLoc *operator->() const { return &Arg; }
4454  };
4455 
4457 
4459  InputIterator Iter)
4460  : Self(Self), Iter(Iter) { }
4461 
4463  ++Iter;
4464  return *this;
4465  }
4466 
4469  ++(*this);
4470  return Old;
4471  }
4472 
4474  TemplateArgumentLoc Result;
4475  Self.InventTemplateArgumentLoc(*Iter, Result);
4476  return Result;
4477  }
4478 
4479  pointer operator->() const { return pointer(**this); }
4480 
4483  return X.Iter == Y.Iter;
4484  }
4485 
4488  return X.Iter != Y.Iter;
4489  }
4490 };
4491 
4492 template<typename Derived>
4493 template<typename InputIterator>
4495  InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4496  bool Uneval) {
4497  for (; First != Last; ++First) {
4498  TemplateArgumentLoc Out;
4499  TemplateArgumentLoc In = *First;
4500 
4501  if (In.getArgument().getKind() == TemplateArgument::Pack) {
4502  // Unpack argument packs, which we translate them into separate
4503  // arguments.
4504  // FIXME: We could do much better if we could guarantee that the
4505  // TemplateArgumentLocInfo for the pack expansion would be usable for
4506  // all of the template arguments in the argument pack.
4507  typedef TemplateArgumentLocInventIterator<Derived,
4509  PackLocIterator;
4510  if (TransformTemplateArguments(PackLocIterator(*this,
4511  In.getArgument().pack_begin()),
4512  PackLocIterator(*this,
4513  In.getArgument().pack_end()),
4514  Outputs, Uneval))
4515  return true;
4516 
4517  continue;
4518  }
4519 
4520  if (In.getArgument().isPackExpansion()) {
4521  // We have a pack expansion, for which we will be substituting into
4522  // the pattern.
4523  SourceLocation Ellipsis;
4524  Optional<unsigned> OrigNumExpansions;
4525  TemplateArgumentLoc Pattern
4526  = getSema().getTemplateArgumentPackExpansionPattern(
4527  In, Ellipsis, OrigNumExpansions);
4528 
4530  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4531  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4532 
4533  // Determine whether the set of unexpanded parameter packs can and should
4534  // be expanded.
4535  bool Expand = true;
4536  bool RetainExpansion = false;
4537  Optional<unsigned> NumExpansions = OrigNumExpansions;
4538  if (getDerived().TryExpandParameterPacks(Ellipsis,
4539  Pattern.getSourceRange(),
4540  Unexpanded,
4541  Expand,
4542  RetainExpansion,
4543  NumExpansions))
4544  return true;
4545 
4546  if (!Expand) {
4547  // The transform has determined that we should perform a simple
4548  // transformation on the pack expansion, producing another pack
4549  // expansion.
4550  TemplateArgumentLoc OutPattern;
4551  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4552  if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4553  return true;
4554 
4555  Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4556  NumExpansions);
4557  if (Out.getArgument().isNull())
4558  return true;
4559 
4560  Outputs.addArgument(Out);
4561  continue;
4562  }
4563 
4564  // The transform has determined that we should perform an elementwise
4565  // expansion of the pattern. Do so.
4566  for (unsigned I = 0; I != *NumExpansions; ++I) {
4567  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4568 
4569  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4570  return true;
4571 
4573  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4574  OrigNumExpansions);
4575  if (Out.getArgument().isNull())
4576  return true;
4577  }
4578 
4579  Outputs.addArgument(Out);
4580  }
4581 
4582  // If we're supposed to retain a pack expansion, do so by temporarily
4583  // forgetting the partially-substituted parameter pack.
4584  if (RetainExpansion) {
4585  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4586 
4587  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4588  return true;
4589 
4590  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4591  OrigNumExpansions);
4592  if (Out.getArgument().isNull())
4593  return true;
4594 
4595  Outputs.addArgument(Out);
4596  }
4597 
4598  continue;
4599  }
4600 
4601  // The simple case:
4602  if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4603  return true;
4604 
4605  Outputs.addArgument(Out);
4606  }
4607 
4608  return false;
4609 
4610 }
4611 
4612 //===----------------------------------------------------------------------===//
4613 // Type transformation
4614 //===----------------------------------------------------------------------===//
4615 
4616 template<typename Derived>
4618  if (getDerived().AlreadyTransformed(T))
4619  return T;
4620 
4621  // Temporary workaround. All of these transformations should
4622  // eventually turn into transformations on TypeLocs.
4623  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4624  getDerived().getBaseLocation());
4625 
4626  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4627 
4628  if (!NewDI)
4629  return QualType();
4630 
4631  return NewDI->getType();
4632 }
4633 
4634 template<typename Derived>
4636  // Refine the base location to the type's location.
4637  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4638  getDerived().getBaseEntity());
4639  if (getDerived().AlreadyTransformed(DI->getType()))
4640  return DI;
4641 
4642  TypeLocBuilder TLB;
4643 
4644  TypeLoc TL = DI->getTypeLoc();
4645  TLB.reserve(TL.getFullDataSize());
4646 
4647  QualType Result = getDerived().TransformType(TLB, TL);
4648  if (Result.isNull())
4649  return nullptr;
4650 
4651  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4652 }
4653 
4654 template<typename Derived>
4655 QualType
4657  switch (T.getTypeLocClass()) {
4658 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4659 #define TYPELOC(CLASS, PARENT) \
4660  case TypeLoc::CLASS: \
4661  return getDerived().Transform##CLASS##Type(TLB, \
4662  T.castAs<CLASS##TypeLoc>());
4663 #include "clang/AST/TypeLocNodes.def"
4664  }
4665 
4666  llvm_unreachable("unhandled type loc!");
4667 }
4668 
4669 template<typename Derived>
4671  if (!isa<DependentNameType>(T))
4672  return TransformType(T);
4673 
4674  if (getDerived().AlreadyTransformed(T))
4675  return T;
4676  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4677  getDerived().getBaseLocation());
4678  TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4679  return NewDI ? NewDI->getType() : QualType();
4680 }
4681 
4682 template<typename Derived>
4685  if (!isa<DependentNameType>(DI->getType()))
4686  return TransformType(DI);
4687 
4688  // Refine the base location to the type's location.
4689  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4690  getDerived().getBaseEntity());
4691  if (getDerived().AlreadyTransformed(DI->getType()))
4692  return DI;
4693 
4694  TypeLocBuilder TLB;
4695 
4696  TypeLoc TL = DI->getTypeLoc();
4697  TLB.reserve(TL.getFullDataSize());
4698 
4699  auto QTL = TL.getAs<QualifiedTypeLoc>();
4700  if (QTL)
4701  TL = QTL.getUnqualifiedLoc();
4702 
4703  auto DNTL = TL.castAs<DependentNameTypeLoc>();
4704 
4705  QualType Result = getDerived().TransformDependentNameType(
4706  TLB, DNTL, /*DeducedTSTContext*/true);
4707  if (Result.isNull())
4708  return nullptr;
4709 
4710  if (QTL) {
4711  Result = getDerived().RebuildQualifiedType(Result, QTL);
4712  if (Result.isNull())
4713  return nullptr;
4714  TLB.TypeWasModifiedSafely(Result);
4715  }
4716 
4717  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4718 }
4719 
4720 template<typename Derived>
4721 QualType
4723  QualifiedTypeLoc T) {
4724  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4725  if (Result.isNull())
4726  return QualType();
4727 
4728  Result = getDerived().RebuildQualifiedType(Result, T);
4729 
4730  if (Result.isNull())
4731  return QualType();
4732 
4733  // RebuildQualifiedType might have updated the type, but not in a way
4734  // that invalidates the TypeLoc. (There's no location information for
4735  // qualifiers.)
4736  TLB.TypeWasModifiedSafely(Result);
4737 
4738  return Result;
4739 }
4740 
4741 template <typename Derived>
4743  QualifiedTypeLoc TL) {
4744 
4745  SourceLocation Loc = TL.getBeginLoc();
4746  Qualifiers Quals = TL.getType().getLocalQualifiers();
4747 
4748  if ((T.getAddressSpace() != LangAS::Default &&
4749  Quals.getAddressSpace() != LangAS::Default) &&
4750  T.getAddressSpace() != Quals.getAddressSpace()) {
4751  SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4752  << TL.getType() << T;
4753  return QualType();
4754  }
4755 
4756  // C++ [dcl.fct]p7:
4757  // [When] adding cv-qualifications on top of the function type [...] the
4758  // cv-qualifiers are ignored.
4759  if (T->isFunctionType()) {
4760  T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4761  Quals.getAddressSpace());
4762  return T;
4763  }
4764 
4765  // C++ [dcl.ref]p1:
4766  // when the cv-qualifiers are introduced through the use of a typedef-name
4767  // or decltype-specifier [...] the cv-qualifiers are ignored.
4768  // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4769  // applied to a reference type.
4770  if (T->isReferenceType()) {
4771  // The only qualifier that applies to a reference type is restrict.
4772  if (!Quals.hasRestrict())
4773  return T;
4774  Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4775  }
4776 
4777  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4778  // resulting type.
4779  if (Quals.hasObjCLifetime()) {
4780  if (!T->isObjCLifetimeType() && !T->isDependentType())
4781  Quals.removeObjCLifetime();
4782  else if (T.getObjCLifetime()) {
4783  // Objective-C ARC:
4784  // A lifetime qualifier applied to a substituted template parameter
4785  // overrides the lifetime qualifier from the template argument.
4786  const AutoType *AutoTy;
4787  if (const SubstTemplateTypeParmType *SubstTypeParam
4788  = dyn_cast<SubstTemplateTypeParmType>(T)) {
4789  QualType Replacement = SubstTypeParam->getReplacementType();
4790  Qualifiers Qs = Replacement.getQualifiers();
4791  Qs.removeObjCLifetime();
4792  Replacement = SemaRef.Context.getQualifiedType(
4793  Replacement.getUnqualifiedType(), Qs);
4795  SubstTypeParam->getReplacedParameter(), Replacement);
4796  } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4797  // 'auto' types behave the same way as template parameters.
4798  QualType Deduced = AutoTy->getDeducedType();
4799  Qualifiers Qs = Deduced.getQualifiers();
4800  Qs.removeObjCLifetime();
4801  Deduced =
4802  SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4803  T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4804  AutoTy->isDependentType(),
4805  /*isPack=*/false,
4806  AutoTy->getTypeConstraintConcept(),
4807  AutoTy->getTypeConstraintArguments());
4808  } else {
4809  // Otherwise, complain about the addition of a qualifier to an
4810  // already-qualified type.
4811  // FIXME: Why is this check not in Sema::BuildQualifiedType?
4812  SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4813  Quals.removeObjCLifetime();
4814  }
4815  }
4816  }
4817 
4818  return SemaRef.BuildQualifiedType(T, Loc, Quals);
4819 }
4820 
4821 template<typename Derived>
4822 TypeLoc
4824  QualType ObjectType,
4825  NamedDecl *UnqualLookup,
4826  CXXScopeSpec &SS) {
4827  if (getDerived().AlreadyTransformed(TL.getType()))
4828  return TL;
4829 
4830  TypeSourceInfo *TSI =
4831  TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4832  if (TSI)
4833  return TSI->getTypeLoc();
4834  return TypeLoc();
4835 }
4836 
4837 template<typename Derived>
4838 TypeSourceInfo *
4839 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4840  QualType ObjectType,
4841  NamedDecl *UnqualLookup,
4842  CXXScopeSpec &SS) {
4843  if (getDerived().AlreadyTransformed(TSInfo->getType()))
4844  return TSInfo;
4845 
4846  return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4847  UnqualLookup, SS);
4848 }
4849 
4850 template <typename Derived>
4851 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4852  TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4853  CXXScopeSpec &SS) {
4854  QualType T = TL.getType();
4855  assert(!getDerived().AlreadyTransformed(T));
4856 
4857  TypeLocBuilder TLB;
4858  QualType Result;
4859 
4860  if (isa<TemplateSpecializationType>(T)) {
4861  TemplateSpecializationTypeLoc SpecTL =
4862  TL.castAs<TemplateSpecializationTypeLoc>();
4863 
4864  TemplateName Template = getDerived().TransformTemplateName(
4865  SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4866  ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4867  if (Template.isNull())
4868  return nullptr;
4869 
4870  Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4871  Template);
4872  } else if (isa<DependentTemplateSpecializationType>(T)) {
4873  DependentTemplateSpecializationTypeLoc SpecTL =
4874  TL.castAs<DependentTemplateSpecializationTypeLoc>();
4875 
4876  TemplateName Template
4877  = getDerived().RebuildTemplateName(SS,
4878  SpecTL.getTemplateKeywordLoc(),
4879  *SpecTL.getTypePtr()->getIdentifier(),
4880  SpecTL.getTemplateNameLoc(),
4881  ObjectType, UnqualLookup,
4882  /*AllowInjectedClassName*/true);
4883  if (Template.isNull())
4884  return nullptr;
4885 
4886  Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4887  SpecTL,
4888  Template,
4889  SS);
4890  } else {
4891  // Nothing special needs to be done for these.
4892  Result = getDerived().TransformType(TLB, TL);
4893  }
4894 
4895  if (Result.isNull())
4896  return nullptr;
4897 
4898  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4899 }
4900 
4901 template <class TyLoc> static inline
4903  TyLoc NewT = TLB.push<TyLoc>(T.getType());
4904  NewT.setNameLoc(T.getNameLoc());
4905  return T.getType();
4906 }
4907 
4908 template<typename Derived>
4909 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4910  BuiltinTypeLoc T) {
4911  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4912  NewT.setBuiltinLoc(T.getBuiltinLoc());
4913  if (T.needsExtraLocalData())
4914  NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4915  return T.getType();
4916 }
4917 
4918 template<typename Derived>
4919 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4920  ComplexTypeLoc T) {
4921  // FIXME: recurse?
4922  return TransformTypeSpecType(TLB, T);
4923 }
4924 
4925 template <typename Derived>
4926 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4927  AdjustedTypeLoc TL) {
4928  // Adjustments applied during transformation are handled elsewhere.
4929  return getDerived().TransformType(TLB, TL.getOriginalLoc());
4930 }
4931 
4932 template<typename Derived>
4933 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4934  DecayedTypeLoc TL) {
4935  QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4936  if (OriginalType.isNull())
4937  return QualType();
4938 
4939  QualType Result = TL.getType();
4940  if (getDerived().AlwaysRebuild() ||
4941  OriginalType != TL.getOriginalLoc().getType())
4942  Result = SemaRef.Context.getDecayedType(OriginalType);
4943  TLB.push<DecayedTypeLoc>(Result);
4944  // Nothing to set for DecayedTypeLoc.
4945  return Result;
4946 }
4947 
4948 template<typename Derived>
4949 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4950  PointerTypeLoc TL) {
4951  QualType PointeeType
4952  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4953  if (PointeeType.isNull())
4954  return QualType();
4955 
4956  QualType Result = TL.getType();
4957  if (PointeeType->getAs<ObjCObjectType>()) {
4958  // A dependent pointer type 'T *' has is being transformed such
4959  // that an Objective-C class type is being replaced for 'T'. The
4960  // resulting pointer type is an ObjCObjectPointerType, not a
4961  // PointerType.
4962  Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4963 
4964  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4965  NewT.setStarLoc(TL.getStarLoc());
4966  return Result;
4967  }
4968 
4969  if (getDerived().AlwaysRebuild() ||
4970  PointeeType != TL.getPointeeLoc().getType()) {
4971  Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4972  if (Result.isNull())
4973  return QualType();
4974  }
4975 
4976  // Objective-C ARC can add lifetime qualifiers to the type that we're
4977  // pointing to.
4978  TLB.TypeWasModifiedSafely(Result->getPointeeType());
4979 
4980  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4981  NewT.setSigilLoc(TL.getSigilLoc());
4982  return Result;
4983 }
4984 
4985 template<typename Derived>
4986 QualType
4987 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4988  BlockPointerTypeLoc TL) {
4989  QualType PointeeType
4990  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4991  if (PointeeType.isNull())
4992  return QualType();
4993 
4994  QualType Result = TL.getType();
4995  if (getDerived().AlwaysRebuild() ||
4996  PointeeType != TL.getPointeeLoc().getType()) {
4997  Result = getDerived().RebuildBlockPointerType(PointeeType,
4998  TL.getSigilLoc());
4999  if (Result.isNull())
5000  return QualType();
5001  }
5002 
5003  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5004  NewT.setSigilLoc(TL.getSigilLoc());
5005  return Result;
5006 }
5007 
5008 /// Transforms a reference type. Note that somewhat paradoxically we
5009 /// don't care whether the type itself is an l-value type or an r-value
5010 /// type; we only care if the type was *written* as an l-value type
5011 /// or an r-value type.
5012 template<typename Derived>
5013 QualType
5015  ReferenceTypeLoc TL) {
5016  const ReferenceType *T = TL.getTypePtr();
5017 
5018  // Note that this works with the pointee-as-written.
5019  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5020  if (PointeeType.isNull())
5021  return QualType();
5022 
5023  QualType Result = TL.getType();
5024  if (getDerived().AlwaysRebuild() ||
5025  PointeeType != T->getPointeeTypeAsWritten()) {
5026  Result = getDerived().RebuildReferenceType(PointeeType,
5027  T->isSpelledAsLValue(),
5028  TL.getSigilLoc());
5029  if (Result.isNull())
5030  return QualType();
5031  }
5032 
5033  // Objective-C ARC can add lifetime qualifiers to the type that we're
5034  // referring to.
5036  Result->castAs<ReferenceType>()->getPointeeTypeAsWritten());
5037 
5038  // r-value references can be rebuilt as l-value references.
5039  ReferenceTypeLoc NewTL;
5040  if (isa<LValueReferenceType>(Result))
5041  NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5042  else
5043  NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5044  NewTL.setSigilLoc(TL.getSigilLoc());
5045 
5046  return Result;
5047 }
5048 
5049 template<typename Derived>
5050 QualType
5053  return TransformReferenceType(TLB, TL);
5054 }
5055 
5056 template<typename Derived>
5057 QualType
5058 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5059  RValueReferenceTypeLoc TL) {
5060  return TransformReferenceType(TLB, TL);
5061 }
5062 
5063 template<typename Derived>
5064 QualType
5065 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5066  MemberPointerTypeLoc TL) {
5067  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5068  if (PointeeType.isNull())
5069  return QualType();
5070 
5071  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5072  TypeSourceInfo *NewClsTInfo = nullptr;
5073  if (OldClsTInfo) {
5074  NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5075  if (!NewClsTInfo)
5076  return QualType();
5077  }
5078 
5079  const MemberPointerType *T = TL.getTypePtr();
5080  QualType OldClsType = QualType(T->getClass(), 0);
5081  QualType NewClsType;
5082  if (NewClsTInfo)
5083  NewClsType = NewClsTInfo->getType();
5084  else {
5085  NewClsType = getDerived().TransformType(OldClsType);
5086  if (NewClsType.isNull())
5087  return QualType();
5088  }
5089 
5090  QualType Result = TL.getType();
5091  if (getDerived().AlwaysRebuild() ||
5092  PointeeType != T->getPointeeType() ||
5093  NewClsType != OldClsType) {
5094  Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5095  TL.getStarLoc());
5096  if (Result.isNull())
5097  return QualType();
5098  }
5099 
5100  // If we had to adjust the pointee type when building a member pointer, make
5101  // sure to push TypeLoc info for it.
5102  const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5103  if (MPT && PointeeType != MPT->getPointeeType()) {
5104  assert(isa<AdjustedType>(MPT->getPointeeType()));
5105  TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5106  }
5107 
5108  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5109  NewTL.setSigilLoc(TL.getSigilLoc());
5110  NewTL.setClassTInfo(NewClsTInfo);
5111 
5112  return Result;
5113 }
5114 
5115 template<typename Derived>
5116 QualType
5117 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5118  ConstantArrayTypeLoc TL) {
5119  const ConstantArrayType *T = TL.getTypePtr();
5120  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5121  if (ElementType.isNull())
5122  return QualType();
5123 
5124  // Prefer the expression from the TypeLoc; the other may have been uniqued.
5125  Expr *OldSize = TL.getSizeExpr();
5126  if (!OldSize)
5127  OldSize = const_cast<Expr*>(T->getSizeExpr());
5128  Expr *NewSize = nullptr;
5129  if (OldSize) {
5130  EnterExpressionEvaluationContext Unevaluated(
5131  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5132  NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5133  NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5134  }
5135 
5136  QualType Result = TL.getType();
5137  if (getDerived().AlwaysRebuild() ||
5138  ElementType != T->getElementType() ||
5139  (T->getSizeExpr() && NewSize != OldSize)) {
5140  Result = getDerived().RebuildConstantArrayType(ElementType,
5141  T->getSizeModifier(),
5142  T->getSize(), NewSize,
5143  T->getIndexTypeCVRQualifiers(),
5144  TL.getBracketsRange());
5145  if (Result.isNull())
5146  return QualType();
5147  }
5148 
5149  // We might have either a ConstantArrayType or a VariableArrayType now:
5150  // a ConstantArrayType is allowed to have an element type which is a
5151  // VariableArrayType if the type is dependent. Fortunately, all array
5152  // types have the same location layout.
5153  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5154  NewTL.setLBracketLoc(TL.getLBracketLoc());
5155  NewTL.setRBracketLoc(TL.getRBracketLoc());
5156  NewTL.setSizeExpr(NewSize);
5157 
5158  return Result;
5159 }
5160 
5161 template<typename Derived>
5162 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5163  TypeLocBuilder &TLB,
5164  IncompleteArrayTypeLoc TL) {
5165  const IncompleteArrayType *T = TL.getTypePtr();
5166  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5167  if (ElementType.isNull())
5168  return QualType();
5169 
5170  QualType Result = TL.getType();
5171  if (getDerived().AlwaysRebuild() ||
5172  ElementType != T->getElementType()) {
5173  Result = getDerived().RebuildIncompleteArrayType(ElementType,
5174  T->getSizeModifier(),
5175  T->getIndexTypeCVRQualifiers(),
5176  TL.getBracketsRange());
5177  if (Result.isNull())
5178  return QualType();
5179  }
5180 
5181  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5182  NewTL.setLBracketLoc(TL.getLBracketLoc());
5183  NewTL.setRBracketLoc(TL.getRBracketLoc());
5184  NewTL.setSizeExpr(nullptr);
5185 
5186  return Result;
5187 }
5188 
5189 template<typename Derived>
5190 QualType
5191 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5192  VariableArrayTypeLoc TL) {
5193  const VariableArrayType *T = TL.getTypePtr();
5194  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5195  if (ElementType.isNull())
5196  return QualType();
5197 
5198  ExprResult SizeResult;
5199  {
5200  EnterExpressionEvaluationContext Context(
5201  SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
5202  SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5203  }
5204  if (SizeResult.isInvalid())
5205  return QualType();
5206  SizeResult =
5207  SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5208  if (SizeResult.isInvalid())
5209  return QualType();
5210 
5211  Expr *Size = SizeResult.get();
5212 
5213  QualType Result = TL.getType();
5214  if (getDerived().AlwaysRebuild() ||
5215  ElementType != T->getElementType() ||
5216  Size != T->getSizeExpr()) {
5217  Result = getDerived().RebuildVariableArrayType(ElementType,
5218  T->getSizeModifier(),
5219  Size,
5220  T->getIndexTypeCVRQualifiers(),
5221  TL.getBracketsRange());
5222  if (Result.isNull())
5223  return QualType();
5224  }
5225 
5226  // We might have constant size array now, but fortunately it has the same
5227  // location layout.
5228  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5229  NewTL.setLBracketLoc(TL.getLBracketLoc());
5230  NewTL.setRBracketLoc(TL.getRBracketLoc());
5231  NewTL.setSizeExpr(Size);
5232 
5233  return Result;
5234 }
5235 
5236 template<typename Derived>
5237 QualType
5238 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5239  DependentSizedArrayTypeLoc TL) {
5240  const DependentSizedArrayType *T = TL.getTypePtr();
5241  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5242  if (ElementType.isNull())
5243  return QualType();
5244 
5245  // Array bounds are constant expressions.
5246  EnterExpressionEvaluationContext Unevaluated(
5247  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5248 
5249  // Prefer the expression from the TypeLoc; the other may have been uniqued.
5250  Expr *origSize = TL.getSizeExpr();
5251  if (!origSize) origSize = T->getSizeExpr();
5252 
5253  ExprResult sizeResult
5254  = getDerived().TransformExpr(origSize);
5255  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5256  if (sizeResult.isInvalid())
5257  return QualType();
5258 
5259  Expr *size = sizeResult.get();
5260 
5261  QualType Result = TL.getType();
5262  if (getDerived().AlwaysRebuild() ||
5263  ElementType != T->getElementType() ||
5264  size != origSize) {
5265  Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5266  T->getSizeModifier(),
5267  size,
5268  T->getIndexTypeCVRQualifiers(),
5269  TL.getBracketsRange());
5270  if (Result.isNull())
5271  return QualType();
5272  }
5273 
5274  // We might have any sort of array type now, but fortunately they
5275  // all have the same location layout.
5276  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5277  NewTL.setLBracketLoc(TL.getLBracketLoc());
5278  NewTL.setRBracketLoc(TL.getRBracketLoc());
5279  NewTL.setSizeExpr(size);
5280 
5281  return Result;
5282 }
5283 
5284 template <typename Derived>
5285 QualType TreeTransform<Derived>::TransformDependentVectorType(
5286  TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5287  const DependentVectorType *T = TL.getTypePtr();
5288  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5289  if (ElementType.isNull())
5290  return QualType();
5291 
5292  EnterExpressionEvaluationContext Unevaluated(
5293  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5294 
5295  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5296  Size = SemaRef.ActOnConstantExpression(Size);
5297  if (Size.isInvalid())
5298  return QualType();
5299 
5300  QualType Result = TL.getType();
5301  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5302  Size.get() != T->getSizeExpr()) {
5303  Result = getDerived().RebuildDependentVectorType(
5304  ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5305  if (Result.isNull())
5306  return QualType();
5307  }
5308 
5309  // Result might be dependent or not.
5310  if (isa<DependentVectorType>(Result)) {
5311  DependentVectorTypeLoc NewTL =
5312  TLB.push<DependentVectorTypeLoc>(Result);
5313  NewTL.setNameLoc(TL.getNameLoc());
5314  } else {
5315  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5316  NewTL.setNameLoc(TL.getNameLoc());
5317  }
5318 
5319  return Result;
5320 }
5321 
5322 template<typename Derived>
5323 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5324  TypeLocBuilder &TLB,
5325  DependentSizedExtVectorTypeLoc TL) {
5326  const DependentSizedExtVectorType *T = TL.getTypePtr();
5327 
5328  // FIXME: ext vector locs should be nested
5329  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5330  if (ElementType.isNull())
5331  return QualType();
5332 
5333  // Vector sizes are constant expressions.
5334  EnterExpressionEvaluationContext Unevaluated(
5335  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5336 
5337  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5338  Size = SemaRef.ActOnConstantExpression(Size);
5339  if (Size.isInvalid())
5340  return QualType();
5341 
5342  QualType Result = TL.getType();
5343  if (getDerived().AlwaysRebuild() ||
5344  ElementType != T->getElementType() ||
5345  Size.get() != T->getSizeExpr()) {
5346  Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5347  Size.get(),
5348  T->getAttributeLoc());
5349  if (Result.isNull())
5350  return QualType();
5351  }
5352 
5353  // Result might be dependent or not.
5354  if (isa<DependentSizedExtVectorType>(Result)) {
5355  DependentSizedExtVectorTypeLoc NewTL
5356  = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5357  NewTL.setNameLoc(TL.getNameLoc());
5358  } else {
5359  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5360  NewTL.setNameLoc(TL.getNameLoc());
5361  }
5362 
5363  return Result;
5364 }
5365 
5366 template <typename Derived>
5367 QualType
5368 TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5369  ConstantMatrixTypeLoc TL) {
5370  const ConstantMatrixType *T = TL.getTypePtr();
5371  QualType ElementType = getDerived().TransformType(T->getElementType());
5372  if (ElementType.isNull())
5373  return QualType();
5374 
5375  QualType Result = TL.getType();
5376  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5377  Result = getDerived().RebuildConstantMatrixType(
5378  ElementType, T->getNumRows(), T->getNumColumns());
5379  if (Result.isNull())
5380  return QualType();
5381  }
5382 
5383  ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5384  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5385  NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5386  NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5387  NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5388 
5389  return Result;
5390 }
5391 
5392 template <typename Derived>
5393 QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5394  TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5395  const DependentSizedMatrixType *T = TL.getTypePtr();
5396 
5397  QualType ElementType = getDerived().TransformType(T->getElementType());
5398  if (ElementType.isNull()) {
5399  return QualType();
5400  }
5401 
5402  // Matrix dimensions are constant expressions.
5403  EnterExpressionEvaluationContext Unevaluated(
5404  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5405 
5406  Expr *origRows = TL.getAttrRowOperand();
5407  if (!origRows)
5408  origRows = T->getRowExpr();
5409  Expr *origColumns = TL.getAttrColumnOperand();
5410  if (!origColumns)
5411  origColumns = T->getColumnExpr();
5412 
5413  ExprResult rowResult = getDerived().TransformExpr(origRows);
5414  rowResult = SemaRef.ActOnConstantExpression(rowResult);
5415  if (rowResult.isInvalid())
5416  return QualType();
5417 
5418  ExprResult columnResult = getDerived().TransformExpr(origColumns);
5419  columnResult = SemaRef.ActOnConstantExpression(columnResult);
5420  if (columnResult.isInvalid())
5421  return QualType();
5422 
5423  Expr *rows = rowResult.get();
5424  Expr *columns = columnResult.get();
5425 
5426  QualType Result = TL.getType();
5427  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5428  rows != origRows || columns != origColumns) {
5429  Result = getDerived().RebuildDependentSizedMatrixType(
5430  ElementType, rows, columns, T->getAttributeLoc());
5431 
5432  if (Result.isNull())
5433  return QualType();
5434  }
5435 
5436  // We might have any sort of matrix type now, but fortunately they
5437  // all have the same location layout.
5438  MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5439  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5440  NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5441  NewTL.setAttrRowOperand(rows);
5442  NewTL.setAttrColumnOperand(columns);
5443  return Result;
5444 }
5445 
5446 template <typename Derived>
5447 QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5448  TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5449  const DependentAddressSpaceType *T = TL.getTypePtr();
5450 
5451  QualType pointeeType = getDerived().TransformType(T->getPointeeType());
5452 
5453  if (pointeeType.isNull())
5454  return QualType();
5455 
5456  // Address spaces are constant expressions.
5457  EnterExpressionEvaluationContext Unevaluated(
5458  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5459 
5460  ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5461  AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5462  if (AddrSpace.isInvalid())
5463  return QualType();
5464 
5465  QualType Result = TL.getType();
5466  if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5467  AddrSpace.get() != T->getAddrSpaceExpr()) {
5468  Result = getDerived().RebuildDependentAddressSpaceType(
5469  pointeeType, AddrSpace.get(), T->getAttributeLoc());
5470  if (Result.isNull())
5471  return QualType();
5472  }
5473 
5474  // Result might be dependent or not.
5475  if (isa<DependentAddressSpaceType>(Result)) {
5476  DependentAddressSpaceTypeLoc NewTL =
5477  TLB.push<DependentAddressSpaceTypeLoc>(Result);
5478 
5479  NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5480  NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5481  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5482 
5483  } else {
5484  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5485  Result, getDerived().getBaseLocation());
5486  TransformType(TLB, DI->getTypeLoc());
5487  }
5488 
5489  return Result;
5490 }
5491 
5492 template <typename Derived>
5493 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5494  VectorTypeLoc TL) {
5495  const VectorType *T = TL.getTypePtr();
5496  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5497  if (ElementType.isNull())
5498  return QualType();
5499 
5500  QualType Result = TL.getType();
5501  if (getDerived().AlwaysRebuild() ||
5502  ElementType != T->getElementType()) {
5503  Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
5504  T->getVectorKind());
5505  if (Result.isNull())
5506  return QualType();
5507  }
5508 
5509  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5510  NewTL.setNameLoc(TL.getNameLoc());
5511 
5512  return Result;
5513 }
5514 
5515 template<typename Derived>
5516 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
5517  ExtVectorTypeLoc TL) {
5518  const VectorType *T = TL.getTypePtr();
5519  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5520  if (ElementType.isNull())
5521  return QualType();
5522 
5523  QualType Result = TL.getType();
5524  if (getDerived().AlwaysRebuild() ||
5525  ElementType != T->getElementType()) {
5526  Result = getDerived().RebuildExtVectorType(ElementType,
5527  T->getNumElements(),
5528  /*FIXME*/ SourceLocation());
5529  if (Result.isNull())
5530  return QualType();
5531  }
5532 
5533  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5534  NewTL.setNameLoc(TL.getNameLoc());
5535 
5536  return Result;
5537 }
5538 
5539 template <typename Derived>
5541  ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5542  bool ExpectParameterPack) {
5543  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
5544  TypeSourceInfo *NewDI = nullptr;
5545 
5546  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
5547  // If we're substituting into a pack expansion type and we know the
5548  // length we want to expand to, just substitute for the pattern.
5549  TypeLoc OldTL = OldDI->getTypeLoc();
5550  PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
5551 
5552  TypeLocBuilder TLB;
5553  TypeLoc NewTL = OldDI->getTypeLoc();
5554  TLB.reserve(NewTL.getFullDataSize());
5555 
5556  QualType Result = getDerived().TransformType(TLB,
5557  OldExpansionTL.getPatternLoc());
5558  if (Result.isNull())
5559  return nullptr;
5560 
5561  Result = RebuildPackExpansionType(Result,
5562  OldExpansionTL.getPatternLoc().getSourceRange(),
5563  OldExpansionTL.getEllipsisLoc(),
5564  NumExpansions);
5565  if (Result.isNull())
5566  return nullptr;
5567 
5568  PackExpansionTypeLoc NewExpansionTL
5569  = TLB.push<PackExpansionTypeLoc>(Result);
5570  NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5571  NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5572  } else
5573  NewDI = getDerived().TransformType(OldDI);
5574  if (!NewDI)
5575  return nullptr;
5576 
5577  if (NewDI == OldDI && indexAdjustment == 0)
5578  return OldParm;
5579 
5580  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5581  OldParm->getDeclContext(),
5582  OldParm->getInnerLocStart(),
5583  OldParm->getLocation(),
5584  OldParm->getIdentifier(),
5585  NewDI->getType(),
5586  NewDI,
5587  OldParm->getStorageClass(),
5588  /* DefArg */ nullptr);
5589  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5590  OldParm->getFunctionScopeIndex() + indexAdjustment);
5591  transformedLocalDecl(OldParm, {newParm});
5592  return newParm;
5593 }
5594 
5595 template <typename Derived>
5598  const QualType *ParamTypes,
5599  const FunctionProtoType::ExtParameterInfo *ParamInfos,
5600  SmallVectorImpl<QualType> &OutParamTypes,
5603  int indexAdjustment = 0;
5604 
5605  unsigned NumParams = Params.size();
5606  for (unsigned i = 0; i != NumParams; ++i) {
5607  if (ParmVarDecl *OldParm = Params[i]) {
5608  assert(OldParm->getFunctionScopeIndex() == i);
5609 
5610  Optional<unsigned> NumExpansions;
5611  ParmVarDecl *NewParm = nullptr;
5612  if (OldParm->isParameterPack()) {
5613  // We have a function parameter pack that may need to be expanded.
5615 
5616  // Find the parameter packs that could be expanded.
5617  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
5618  PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
5619  TypeLoc Pattern = ExpansionTL.getPatternLoc();
5620  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
5621 
5622  // Determine whether we should expand the parameter packs.
5623  bool ShouldExpand = false;
5624  bool RetainExpansion = false;
5625  Optional<unsigned> OrigNumExpansions;
5626  if (Unexpanded.size() > 0) {
5627  OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
5628  NumExpansions = OrigNumExpansions;
5629  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5630  Pattern.getSourceRange(),
5631  Unexpanded,
5632  ShouldExpand,
5633  RetainExpansion,
5634  NumExpansions)) {
5635  return true;
5636  }
5637  } else {
5638 #ifndef NDEBUG
5639  const AutoType *AT =
5640  Pattern.getType().getTypePtr()->getContainedAutoType();
5641  assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
5642  "Could not find parameter packs or undeduced auto type!");
5643 #endif
5644  }
5645 
5646  if (ShouldExpand) {
5647  // Expand the function parameter pack into multiple, separate
5648  // parameters.
5649  getDerived().ExpandingFunctionParameterPack(OldParm);
5650  for (unsigned I = 0; I != *NumExpansions; ++I) {
5651  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5652  ParmVarDecl *NewParm
5653  = getDerived().TransformFunctionTypeParam(OldParm,
5654  indexAdjustment++,
5655  OrigNumExpansions,
5656  /*ExpectParameterPack=*/false);
5657  if (!NewParm)
5658  return true;
5659 
5660  if (ParamInfos)
5661  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5662  OutParamTypes.push_back(NewParm->getType());
5663  if (PVars)
5664  PVars->push_back(NewParm);
5665  }
5666 
5667  // If we're supposed to retain a pack expansion, do so by temporarily
5668  // forgetting the partially-substituted parameter pack.
5669  if (RetainExpansion) {
5670  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5671  ParmVarDecl *NewParm
5672  = getDerived().TransformFunctionTypeParam(OldParm,
5673  indexAdjustment++,
5674  OrigNumExpansions,
5675  /*ExpectParameterPack=*/false);
5676  if (!NewParm)
5677  return true;
5678 
5679  if (ParamInfos)
5680  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5681  OutParamTypes.push_back(NewParm->getType());
5682  if (PVars)
5683  PVars->push_back(NewParm);
5684  }
5685 
5686  // The next parameter should have the same adjustment as the
5687  // last thing we pushed, but we post-incremented indexAdjustment
5688  // on every push. Also, if we push nothing, the adjustment should
5689  // go down by one.
5690  indexAdjustment--;
5691 
5692  // We're done with the pack expansion.
5693  continue;
5694  }
5695 
5696  // We'll substitute the parameter now without expanding the pack
5697  // expansion.
5698  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5699