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 type found via an alias.
938  return SemaRef.Context.getUsingType(Found, Underlying);
939  }
940 
941  /// Build a new typedef type.
943  return SemaRef.Context.getTypeDeclType(Typedef);
944  }
945 
946  /// Build a new MacroDefined type.
948  const IdentifierInfo *MacroII) {
949  return SemaRef.Context.getMacroQualifiedType(T, MacroII);
950  }
951 
952  /// Build a new class/struct/union type.
954  return SemaRef.Context.getTypeDeclType(Record);
955  }
956 
957  /// Build a new Enum type.
959  return SemaRef.Context.getTypeDeclType(Enum);
960  }
961 
962  /// Build a new typeof(expr) type.
963  ///
964  /// By default, performs semantic analysis when building the typeof type.
965  /// Subclasses may override this routine to provide different behavior.
966  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
967 
968  /// Build a new typeof(type) type.
969  ///
970  /// By default, builds a new TypeOfType with the given underlying type.
971  QualType RebuildTypeOfType(QualType Underlying);
972 
973  /// Build a new unary transform type.
974  QualType RebuildUnaryTransformType(QualType BaseType,
976  SourceLocation Loc);
977 
978  /// Build a new C++11 decltype type.
979  ///
980  /// By default, performs semantic analysis when building the decltype type.
981  /// Subclasses may override this routine to provide different behavior.
982  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
983 
984  /// Build a new C++11 auto type.
985  ///
986  /// By default, builds a new AutoType with the given deduced type.
988  ConceptDecl *TypeConstraintConcept,
989  ArrayRef<TemplateArgument> TypeConstraintArgs) {
990  // Note, IsDependent is always false here: we implicitly convert an 'auto'
991  // which has been deduced to a dependent type into an undeduced 'auto', so
992  // that we'll retry deduction after the transformation.
993  return SemaRef.Context.getAutoType(Deduced, Keyword,
994  /*IsDependent*/ false, /*IsPack=*/false,
995  TypeConstraintConcept,
996  TypeConstraintArgs);
997  }
998 
999  /// By default, builds a new DeducedTemplateSpecializationType with the given
1000  /// deduced type.
1002  QualType Deduced) {
1004  Template, Deduced, /*IsDependent*/ false);
1005  }
1006 
1007  /// Build a new template specialization type.
1008  ///
1009  /// By default, performs semantic analysis when building the template
1010  /// specialization type. Subclasses may override this routine to provide
1011  /// different behavior.
1012  QualType RebuildTemplateSpecializationType(TemplateName Template,
1013  SourceLocation TemplateLoc,
1014  TemplateArgumentListInfo &Args);
1015 
1016  /// Build a new parenthesized type.
1017  ///
1018  /// By default, builds a new ParenType type from the inner type.
1019  /// Subclasses may override this routine to provide different behavior.
1021  return SemaRef.BuildParenType(InnerType);
1022  }
1023 
1024  /// Build a new qualified name type.
1025  ///
1026  /// By default, builds a new ElaboratedType type from the keyword,
1027  /// the nested-name-specifier and the named type.
1028  /// Subclasses may override this routine to provide different behavior.
1030  ElaboratedTypeKeyword Keyword,
1031  NestedNameSpecifierLoc QualifierLoc,
1032  QualType Named) {
1033  return SemaRef.Context.getElaboratedType(Keyword,
1034  QualifierLoc.getNestedNameSpecifier(),
1035  Named);
1036  }
1037 
1038  /// Build a new typename type that refers to a template-id.
1039  ///
1040  /// By default, builds a new DependentNameType type from the
1041  /// nested-name-specifier and the given type. Subclasses may override
1042  /// this routine to provide different behavior.
1044  ElaboratedTypeKeyword Keyword,
1045  NestedNameSpecifierLoc QualifierLoc,
1046  SourceLocation TemplateKWLoc,
1047  const IdentifierInfo *Name,
1048  SourceLocation NameLoc,
1050  bool AllowInjectedClassName) {
1051  // Rebuild the template name.
1052  // TODO: avoid TemplateName abstraction
1053  CXXScopeSpec SS;
1054  SS.Adopt(QualifierLoc);
1055  TemplateName InstName = getDerived().RebuildTemplateName(
1056  SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1057  AllowInjectedClassName);
1058 
1059  if (InstName.isNull())
1060  return QualType();
1061 
1062  // If it's still dependent, make a dependent specialization.
1063  if (InstName.getAsDependentTemplateName())
1064  return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1065  QualifierLoc.getNestedNameSpecifier(),
1066  Name,
1067  Args);
1068 
1069  // Otherwise, make an elaborated type wrapping a non-dependent
1070  // specialization.
1071  QualType T =
1072  getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1073  if (T.isNull()) return QualType();
1074 
1075  if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
1076  return T;
1077 
1078  return SemaRef.Context.getElaboratedType(Keyword,
1079  QualifierLoc.getNestedNameSpecifier(),
1080  T);
1081  }
1082 
1083  /// Build a new typename type that refers to an identifier.
1084  ///
1085  /// By default, performs semantic analysis when building the typename type
1086  /// (or elaborated type). Subclasses may override this routine to provide
1087  /// different behavior.
1089  SourceLocation KeywordLoc,
1090  NestedNameSpecifierLoc QualifierLoc,
1091  const IdentifierInfo *Id,
1092  SourceLocation IdLoc,
1093  bool DeducedTSTContext) {
1094  CXXScopeSpec SS;
1095  SS.Adopt(QualifierLoc);
1096 
1097  if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1098  // If the name is still dependent, just build a new dependent name type.
1099  if (!SemaRef.computeDeclContext(SS))
1100  return SemaRef.Context.getDependentNameType(Keyword,
1101  QualifierLoc.getNestedNameSpecifier(),
1102  Id);
1103  }
1104 
1105  if (Keyword == ETK_None || Keyword == ETK_Typename) {
1106  return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1107  *Id, IdLoc, DeducedTSTContext);
1108  }
1109 
1110  TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1111 
1112  // We had a dependent elaborated-type-specifier that has been transformed
1113  // into a non-dependent elaborated-type-specifier. Find the tag we're
1114  // referring to.
1115  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1116  DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1117  if (!DC)
1118  return QualType();
1119 
1120  if (SemaRef.RequireCompleteDeclContext(SS, DC))
1121  return QualType();
1122 
1123  TagDecl *Tag = nullptr;
1124  SemaRef.LookupQualifiedName(Result, DC);
1125  switch (Result.getResultKind()) {
1126  case LookupResult::NotFound:
1127  case LookupResult::NotFoundInCurrentInstantiation:
1128  break;
1129 
1130  case LookupResult::Found:
1131  Tag = Result.getAsSingle<TagDecl>();
1132  break;
1133 
1134  case LookupResult::FoundOverloaded:
1135  case LookupResult::FoundUnresolvedValue:
1136  llvm_unreachable("Tag lookup cannot find non-tags");
1137 
1138  case LookupResult::Ambiguous:
1139  // Let the LookupResult structure handle ambiguities.
1140  return QualType();
1141  }
1142 
1143  if (!Tag) {
1144  // Check where the name exists but isn't a tag type and use that to emit
1145  // better diagnostics.
1146  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1147  SemaRef.LookupQualifiedName(Result, DC);
1148  switch (Result.getResultKind()) {
1149  case LookupResult::Found:
1150  case LookupResult::FoundOverloaded:
1151  case LookupResult::FoundUnresolvedValue: {
1152  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1153  Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1154  SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1155  << NTK << Kind;
1156  SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1157  break;
1158  }
1159  default:
1160  SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1161  << Kind << Id << DC << QualifierLoc.getSourceRange();
1162  break;
1163  }
1164  return QualType();
1165  }
1166 
1167  if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1168  IdLoc, Id)) {
1169  SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1170  SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1171  return QualType();
1172  }
1173 
1174  // Build the elaborated-type-specifier type.
1175  QualType T = SemaRef.Context.getTypeDeclType(Tag);
1176  return SemaRef.Context.getElaboratedType(Keyword,
1177  QualifierLoc.getNestedNameSpecifier(),
1178  T);
1179  }
1180 
1181  /// Build a new pack expansion type.
1182  ///
1183  /// By default, builds a new PackExpansionType type from the given pattern.
1184  /// Subclasses may override this routine to provide different behavior.
1186  SourceRange PatternRange,
1187  SourceLocation EllipsisLoc,
1188  Optional<unsigned> NumExpansions) {
1189  return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1190  NumExpansions);
1191  }
1192 
1193  /// Build a new atomic type given its value type.
1194  ///
1195  /// By default, performs semantic analysis when building the atomic type.
1196  /// Subclasses may override this routine to provide different behavior.
1197  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1198 
1199  /// Build a new pipe type given its value type.
1200  QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1201  bool isReadPipe);
1202 
1203  /// Build a bit-precise int given its value type.
1204  QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1205  SourceLocation Loc);
1206 
1207  /// Build a dependent bit-precise int given its value type.
1208  QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1209  SourceLocation Loc);
1210 
1211  /// Build a new template name given a nested name specifier, a flag
1212  /// indicating whether the "template" keyword was provided, and the template
1213  /// that the template name refers to.
1214  ///
1215  /// By default, builds the new template name directly. Subclasses may override
1216  /// this routine to provide different behavior.
1217  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1218  bool TemplateKW,
1219  TemplateDecl *Template);
1220 
1221  /// Build a new template name given a nested name specifier and the
1222  /// name that is referred to as a template.
1223  ///
1224  /// By default, performs semantic analysis to determine whether the name can
1225  /// be resolved to a specific template, then builds the appropriate kind of
1226  /// template name. Subclasses may override this routine to provide different
1227  /// behavior.
1228  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1229  SourceLocation TemplateKWLoc,
1230  const IdentifierInfo &Name,
1231  SourceLocation NameLoc, QualType ObjectType,
1232  NamedDecl *FirstQualifierInScope,
1233  bool AllowInjectedClassName);
1234 
1235  /// Build a new template name given a nested name specifier and the
1236  /// overloaded operator name that is referred to as a template.
1237  ///
1238  /// By default, performs semantic analysis to determine whether the name can
1239  /// be resolved to a specific template, then builds the appropriate kind of
1240  /// template name. Subclasses may override this routine to provide different
1241  /// behavior.
1242  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1243  SourceLocation TemplateKWLoc,
1244  OverloadedOperatorKind Operator,
1245  SourceLocation NameLoc, QualType ObjectType,
1246  bool AllowInjectedClassName);
1247 
1248  /// Build a new template name given a template template parameter pack
1249  /// and the
1250  ///
1251  /// By default, performs semantic analysis to determine whether the name can
1252  /// be resolved to a specific template, then builds the appropriate kind of
1253  /// template name. Subclasses may override this routine to provide different
1254  /// behavior.
1256  const TemplateArgument &ArgPack) {
1257  return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1258  }
1259 
1260  /// Build a new compound statement.
1261  ///
1262  /// By default, performs semantic analysis to build the new statement.
1263  /// Subclasses may override this routine to provide different behavior.
1265  MultiStmtArg Statements,
1266  SourceLocation RBraceLoc,
1267  bool IsStmtExpr) {
1268  return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1269  IsStmtExpr);
1270  }
1271 
1272  /// Build a new case statement.
1273  ///
1274  /// By default, performs semantic analysis to build the new statement.
1275  /// Subclasses may override this routine to provide different behavior.
1277  Expr *LHS,
1278  SourceLocation EllipsisLoc,
1279  Expr *RHS,
1280  SourceLocation ColonLoc) {
1281  return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1282  ColonLoc);
1283  }
1284 
1285  /// Attach the body to a new case statement.
1286  ///
1287  /// By default, performs semantic analysis to build the new statement.
1288  /// Subclasses may override this routine to provide different behavior.
1290  getSema().ActOnCaseStmtBody(S, Body);
1291  return S;
1292  }
1293 
1294  /// Build a new default statement.
1295  ///
1296  /// By default, performs semantic analysis to build the new statement.
1297  /// Subclasses may override this routine to provide different behavior.
1299  SourceLocation ColonLoc,
1300  Stmt *SubStmt) {
1301  return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1302  /*CurScope=*/nullptr);
1303  }
1304 
1305  /// Build a new label statement.
1306  ///
1307  /// By default, performs semantic analysis to build the new statement.
1308  /// Subclasses may override this routine to provide different behavior.
1310  SourceLocation ColonLoc, Stmt *SubStmt) {
1311  return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1312  }
1313 
1314  /// Build a new attributed statement.
1315  ///
1316  /// By default, performs semantic analysis to build the new statement.
1317  /// Subclasses may override this routine to provide different behavior.
1319  ArrayRef<const Attr *> Attrs,
1320  Stmt *SubStmt) {
1321  return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1322  }
1323 
1324  /// Build a new "if" statement.
1325  ///
1326  /// By default, performs semantic analysis to build the new statement.
1327  /// Subclasses may override this routine to provide different behavior.
1329  SourceLocation LParenLoc, Sema::ConditionResult Cond,
1330  SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1331  SourceLocation ElseLoc, Stmt *Else) {
1332  return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1333  Then, ElseLoc, Else);
1334  }
1335 
1336  /// Start building a new switch statement.
1337  ///
1338  /// By default, performs semantic analysis to build the new statement.
1339  /// Subclasses may override this routine to provide different behavior.
1341  SourceLocation LParenLoc, Stmt *Init,
1342  Sema::ConditionResult Cond,
1343  SourceLocation RParenLoc) {
1344  return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1345  RParenLoc);
1346  }
1347 
1348  /// Attach the body to the switch statement.
1349  ///
1350  /// By default, performs semantic analysis to build the new statement.
1351  /// Subclasses may override this routine to provide different behavior.
1353  Stmt *Switch, Stmt *Body) {
1354  return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1355  }
1356 
1357  /// Build a new while statement.
1358  ///
1359  /// By default, performs semantic analysis to build the new statement.
1360  /// Subclasses may override this routine to provide different behavior.
1362  Sema::ConditionResult Cond,
1363  SourceLocation RParenLoc, Stmt *Body) {
1364  return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1365  }
1366 
1367  /// Build a new do-while statement.
1368  ///
1369  /// By default, performs semantic analysis to build the new statement.
1370  /// Subclasses may override this routine to provide different behavior.
1372  SourceLocation WhileLoc, SourceLocation LParenLoc,
1373  Expr *Cond, SourceLocation RParenLoc) {
1374  return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1375  Cond, RParenLoc);
1376  }
1377 
1378  /// Build a new for statement.
1379  ///
1380  /// By default, performs semantic analysis to build the new statement.
1381  /// Subclasses may override this routine to provide different behavior.
1383  Stmt *Init, Sema::ConditionResult Cond,
1384  Sema::FullExprArg Inc, SourceLocation RParenLoc,
1385  Stmt *Body) {
1386  return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1387  Inc, RParenLoc, Body);
1388  }
1389 
1390  /// Build a new goto statement.
1391  ///
1392  /// By default, performs semantic analysis to build the new statement.
1393  /// Subclasses may override this routine to provide different behavior.
1395  LabelDecl *Label) {
1396  return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1397  }
1398 
1399  /// Build a new indirect goto statement.
1400  ///
1401  /// By default, performs semantic analysis to build the new statement.
1402  /// Subclasses may override this routine to provide different behavior.
1404  SourceLocation StarLoc,
1405  Expr *Target) {
1406  return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1407  }
1408 
1409  /// Build a new return statement.
1410  ///
1411  /// By default, performs semantic analysis to build the new statement.
1412  /// Subclasses may override this routine to provide different behavior.
1414  return getSema().BuildReturnStmt(ReturnLoc, Result);
1415  }
1416 
1417  /// Build a new declaration statement.
1418  ///
1419  /// By default, performs semantic analysis to build the new statement.
1420  /// Subclasses may override this routine to provide different behavior.
1422  SourceLocation StartLoc, SourceLocation EndLoc) {
1423  Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1424  return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1425  }
1426 
1427  /// Build a new inline asm statement.
1428  ///
1429  /// By default, performs semantic analysis to build the new statement.
1430  /// Subclasses may override this routine to provide different behavior.
1432  bool IsVolatile, unsigned NumOutputs,
1433  unsigned NumInputs, IdentifierInfo **Names,
1434  MultiExprArg Constraints, MultiExprArg Exprs,
1435  Expr *AsmString, MultiExprArg Clobbers,
1436  unsigned NumLabels,
1437  SourceLocation RParenLoc) {
1438  return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1439  NumInputs, Names, Constraints, Exprs,
1440  AsmString, Clobbers, NumLabels, RParenLoc);
1441  }
1442 
1443  /// Build a new MS style inline asm statement.
1444  ///
1445  /// By default, performs semantic analysis to build the new statement.
1446  /// Subclasses may override this routine to provide different behavior.
1448  ArrayRef<Token> AsmToks,
1449  StringRef AsmString,
1450  unsigned NumOutputs, unsigned NumInputs,
1451  ArrayRef<StringRef> Constraints,
1452  ArrayRef<StringRef> Clobbers,
1453  ArrayRef<Expr*> Exprs,
1454  SourceLocation EndLoc) {
1455  return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1456  NumOutputs, NumInputs,
1457  Constraints, Clobbers, Exprs, EndLoc);
1458  }
1459 
1460  /// Build a new co_return statement.
1461  ///
1462  /// By default, performs semantic analysis to build the new statement.
1463  /// Subclasses may override this routine to provide different behavior.
1465  bool IsImplicit) {
1466  return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1467  }
1468 
1469  /// Build a new co_await expression.
1470  ///
1471  /// By default, performs semantic analysis to build the new expression.
1472  /// Subclasses may override this routine to provide different behavior.
1474  bool IsImplicit) {
1475  return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1476  }
1477 
1478  /// Build a new co_await expression.
1479  ///
1480  /// By default, performs semantic analysis to build the new expression.
1481  /// Subclasses may override this routine to provide different behavior.
1483  Expr *Result,
1484  UnresolvedLookupExpr *Lookup) {
1485  return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1486  }
1487 
1488  /// Build a new co_yield expression.
1489  ///
1490  /// By default, performs semantic analysis to build the new expression.
1491  /// Subclasses may override this routine to provide different behavior.
1493  return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1494  }
1495 
1497  return getSema().BuildCoroutineBodyStmt(Args);
1498  }
1499 
1500  /// Build a new Objective-C \@try statement.
1501  ///
1502  /// By default, performs semantic analysis to build the new statement.
1503  /// Subclasses may override this routine to provide different behavior.
1505  Stmt *TryBody,
1506  MultiStmtArg CatchStmts,
1507  Stmt *Finally) {
1508  return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1509  Finally);
1510  }
1511 
1512  /// Rebuild an Objective-C exception declaration.
1513  ///
1514  /// By default, performs semantic analysis to build the new declaration.
1515  /// Subclasses may override this routine to provide different behavior.
1517  TypeSourceInfo *TInfo, QualType T) {
1518  return getSema().BuildObjCExceptionDecl(TInfo, T,
1519  ExceptionDecl->getInnerLocStart(),
1520  ExceptionDecl->getLocation(),
1521  ExceptionDecl->getIdentifier());
1522  }
1523 
1524  /// Build a new Objective-C \@catch statement.
1525  ///
1526  /// By default, performs semantic analysis to build the new statement.
1527  /// Subclasses may override this routine to provide different behavior.
1529  SourceLocation RParenLoc,
1530  VarDecl *Var,
1531  Stmt *Body) {
1532  return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1533  Var, Body);
1534  }
1535 
1536  /// Build a new Objective-C \@finally statement.
1537  ///
1538  /// By default, performs semantic analysis to build the new statement.
1539  /// Subclasses may override this routine to provide different behavior.
1541  Stmt *Body) {
1542  return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1543  }
1544 
1545  /// Build a new Objective-C \@throw statement.
1546  ///
1547  /// By default, performs semantic analysis to build the new statement.
1548  /// Subclasses may override this routine to provide different behavior.
1550  Expr *Operand) {
1551  return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1552  }
1553 
1554  /// Build a new OpenMP Canonical loop.
1555  ///
1556  /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1557  /// OMPCanonicalLoop.
1559  return getSema().ActOnOpenMPCanonicalLoop(LoopStmt);
1560  }
1561 
1562  /// Build a new OpenMP executable directive.
1563  ///
1564  /// By default, performs semantic analysis to build the new statement.
1565  /// Subclasses may override this routine to provide different behavior.
1567  DeclarationNameInfo DirName,
1568  OpenMPDirectiveKind CancelRegion,
1569  ArrayRef<OMPClause *> Clauses,
1570  Stmt *AStmt, SourceLocation StartLoc,
1571  SourceLocation EndLoc) {
1572  return getSema().ActOnOpenMPExecutableDirective(
1573  Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1574  }
1575 
1576  /// Build a new OpenMP 'if' clause.
1577  ///
1578  /// By default, performs semantic analysis to build the new OpenMP clause.
1579  /// Subclasses may override this routine to provide different behavior.
1581  Expr *Condition, SourceLocation StartLoc,
1582  SourceLocation LParenLoc,
1583  SourceLocation NameModifierLoc,
1584  SourceLocation ColonLoc,
1585  SourceLocation EndLoc) {
1586  return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1587  LParenLoc, NameModifierLoc, ColonLoc,
1588  EndLoc);
1589  }
1590 
1591  /// Build a new OpenMP 'final' clause.
1592  ///
1593  /// By default, performs semantic analysis to build the new OpenMP clause.
1594  /// Subclasses may override this routine to provide different behavior.
1596  SourceLocation LParenLoc,
1597  SourceLocation EndLoc) {
1598  return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1599  EndLoc);
1600  }
1601 
1602  /// Build a new OpenMP 'num_threads' clause.
1603  ///
1604  /// By default, performs semantic analysis to build the new OpenMP clause.
1605  /// Subclasses may override this routine to provide different behavior.
1607  SourceLocation StartLoc,
1608  SourceLocation LParenLoc,
1609  SourceLocation EndLoc) {
1610  return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1611  LParenLoc, EndLoc);
1612  }
1613 
1614  /// Build a new OpenMP 'safelen' clause.
1615  ///
1616  /// By default, performs semantic analysis to build the new OpenMP clause.
1617  /// Subclasses may override this routine to provide different behavior.
1619  SourceLocation LParenLoc,
1620  SourceLocation EndLoc) {
1621  return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1622  }
1623 
1624  /// Build a new OpenMP 'simdlen' clause.
1625  ///
1626  /// By default, performs semantic analysis to build the new OpenMP clause.
1627  /// Subclasses may override this routine to provide different behavior.
1629  SourceLocation LParenLoc,
1630  SourceLocation EndLoc) {
1631  return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1632  }
1633 
1635  SourceLocation StartLoc,
1636  SourceLocation LParenLoc,
1637  SourceLocation EndLoc) {
1638  return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc);
1639  }
1640 
1641  /// Build a new OpenMP 'full' clause.
1643  SourceLocation EndLoc) {
1644  return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc);
1645  }
1646 
1647  /// Build a new OpenMP 'partial' clause.
1649  SourceLocation LParenLoc,
1650  SourceLocation EndLoc) {
1651  return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc,
1652  EndLoc);
1653  }
1654 
1655  /// Build a new OpenMP 'allocator' clause.
1656  ///
1657  /// By default, performs semantic analysis to build the new OpenMP clause.
1658  /// Subclasses may override this routine to provide different behavior.
1660  SourceLocation LParenLoc,
1661  SourceLocation EndLoc) {
1662  return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1663  }
1664 
1665  /// Build a new OpenMP 'collapse' clause.
1666  ///
1667  /// By default, performs semantic analysis to build the new OpenMP clause.
1668  /// Subclasses may override this routine to provide different behavior.
1670  SourceLocation LParenLoc,
1671  SourceLocation EndLoc) {
1672  return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1673  EndLoc);
1674  }
1675 
1676  /// Build a new OpenMP 'default' clause.
1677  ///
1678  /// By default, performs semantic analysis to build the new OpenMP clause.
1679  /// Subclasses may override this routine to provide different behavior.
1681  SourceLocation StartLoc,
1682  SourceLocation LParenLoc,
1683  SourceLocation EndLoc) {
1684  return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1685  StartLoc, LParenLoc, EndLoc);
1686  }
1687 
1688  /// Build a new OpenMP 'proc_bind' clause.
1689  ///
1690  /// By default, performs semantic analysis to build the new OpenMP clause.
1691  /// Subclasses may override this routine to provide different behavior.
1693  SourceLocation KindKwLoc,
1694  SourceLocation StartLoc,
1695  SourceLocation LParenLoc,
1696  SourceLocation EndLoc) {
1697  return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1698  StartLoc, LParenLoc, EndLoc);
1699  }
1700 
1701  /// Build a new OpenMP 'schedule' clause.
1702  ///
1703  /// By default, performs semantic analysis to build the new OpenMP clause.
1704  /// Subclasses may override this routine to provide different behavior.
1707  OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1708  SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1709  SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1710  return getSema().ActOnOpenMPScheduleClause(
1711  M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1712  CommaLoc, EndLoc);
1713  }
1714 
1715  /// Build a new OpenMP 'ordered' clause.
1716  ///
1717  /// By default, performs semantic analysis to build the new OpenMP clause.
1718  /// Subclasses may override this routine to provide different behavior.
1720  SourceLocation EndLoc,
1721  SourceLocation LParenLoc, Expr *Num) {
1722  return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1723  }
1724 
1725  /// Build a new OpenMP 'private' clause.
1726  ///
1727  /// By default, performs semantic analysis to build the new OpenMP clause.
1728  /// Subclasses may override this routine to provide different behavior.
1730  SourceLocation StartLoc,
1731  SourceLocation LParenLoc,
1732  SourceLocation EndLoc) {
1733  return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1734  EndLoc);
1735  }
1736 
1737  /// Build a new OpenMP 'firstprivate' clause.
1738  ///
1739  /// By default, performs semantic analysis to build the new OpenMP clause.
1740  /// Subclasses may override this routine to provide different behavior.
1742  SourceLocation StartLoc,
1743  SourceLocation LParenLoc,
1744  SourceLocation EndLoc) {
1745  return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1746  EndLoc);
1747  }
1748 
1749  /// Build a new OpenMP 'lastprivate' clause.
1750  ///
1751  /// By default, performs semantic analysis to build the new OpenMP clause.
1752  /// Subclasses may override this routine to provide different behavior.
1755  SourceLocation LPKindLoc,
1756  SourceLocation ColonLoc,
1757  SourceLocation StartLoc,
1758  SourceLocation LParenLoc,
1759  SourceLocation EndLoc) {
1760  return getSema().ActOnOpenMPLastprivateClause(
1761  VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1762  }
1763 
1764  /// Build a new OpenMP 'shared' clause.
1765  ///
1766  /// By default, performs semantic analysis to build the new OpenMP clause.
1767  /// Subclasses may override this routine to provide different behavior.
1769  SourceLocation StartLoc,
1770  SourceLocation LParenLoc,
1771  SourceLocation EndLoc) {
1772  return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1773  EndLoc);
1774  }
1775 
1776  /// Build a new OpenMP 'reduction' clause.
1777  ///
1778  /// By default, performs semantic analysis to build the new statement.
1779  /// Subclasses may override this routine to provide different behavior.
1782  SourceLocation StartLoc, SourceLocation LParenLoc,
1783  SourceLocation ModifierLoc, SourceLocation ColonLoc,
1784  SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1785  const DeclarationNameInfo &ReductionId,
1786  ArrayRef<Expr *> UnresolvedReductions) {
1787  return getSema().ActOnOpenMPReductionClause(
1788  VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1789  ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1790  }
1791 
1792  /// Build a new OpenMP 'task_reduction' clause.
1793  ///
1794  /// By default, performs semantic analysis to build the new statement.
1795  /// Subclasses may override this routine to provide different behavior.
1797  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1798  SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1799  CXXScopeSpec &ReductionIdScopeSpec,
1800  const DeclarationNameInfo &ReductionId,
1801  ArrayRef<Expr *> UnresolvedReductions) {
1802  return getSema().ActOnOpenMPTaskReductionClause(
1803  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1804  ReductionId, UnresolvedReductions);
1805  }
1806 
1807  /// Build a new OpenMP 'in_reduction' clause.
1808  ///
1809  /// By default, performs semantic analysis to build the new statement.
1810  /// Subclasses may override this routine to provide different behavior.
1811  OMPClause *
1813  SourceLocation LParenLoc, SourceLocation ColonLoc,
1814  SourceLocation EndLoc,
1815  CXXScopeSpec &ReductionIdScopeSpec,
1816  const DeclarationNameInfo &ReductionId,
1817  ArrayRef<Expr *> UnresolvedReductions) {
1818  return getSema().ActOnOpenMPInReductionClause(
1819  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1820  ReductionId, UnresolvedReductions);
1821  }
1822 
1823  /// Build a new OpenMP 'linear' clause.
1824  ///
1825  /// By default, performs semantic analysis to build the new OpenMP clause.
1826  /// Subclasses may override this routine to provide different behavior.
1828  SourceLocation StartLoc,
1829  SourceLocation LParenLoc,
1830  OpenMPLinearClauseKind Modifier,
1831  SourceLocation ModifierLoc,
1832  SourceLocation ColonLoc,
1833  SourceLocation EndLoc) {
1834  return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1835  Modifier, ModifierLoc, ColonLoc,
1836  EndLoc);
1837  }
1838 
1839  /// Build a new OpenMP 'aligned' clause.
1840  ///
1841  /// By default, performs semantic analysis to build the new OpenMP clause.
1842  /// Subclasses may override this routine to provide different behavior.
1844  SourceLocation StartLoc,
1845  SourceLocation LParenLoc,
1846  SourceLocation ColonLoc,
1847  SourceLocation EndLoc) {
1848  return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1849  LParenLoc, ColonLoc, EndLoc);
1850  }
1851 
1852  /// Build a new OpenMP 'copyin' clause.
1853  ///
1854  /// By default, performs semantic analysis to build the new OpenMP clause.
1855  /// Subclasses may override this routine to provide different behavior.
1857  SourceLocation StartLoc,
1858  SourceLocation LParenLoc,
1859  SourceLocation EndLoc) {
1860  return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1861  EndLoc);
1862  }
1863 
1864  /// Build a new OpenMP 'copyprivate' clause.
1865  ///
1866  /// By default, performs semantic analysis to build the new OpenMP clause.
1867  /// Subclasses may override this routine to provide different behavior.
1869  SourceLocation StartLoc,
1870  SourceLocation LParenLoc,
1871  SourceLocation EndLoc) {
1872  return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1873  EndLoc);
1874  }
1875 
1876  /// Build a new OpenMP 'flush' pseudo clause.
1877  ///
1878  /// By default, performs semantic analysis to build the new OpenMP clause.
1879  /// Subclasses may override this routine to provide different behavior.
1881  SourceLocation StartLoc,
1882  SourceLocation LParenLoc,
1883  SourceLocation EndLoc) {
1884  return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1885  EndLoc);
1886  }
1887 
1888  /// Build a new OpenMP 'depobj' pseudo clause.
1889  ///
1890  /// By default, performs semantic analysis to build the new OpenMP clause.
1891  /// Subclasses may override this routine to provide different behavior.
1893  SourceLocation LParenLoc,
1894  SourceLocation EndLoc) {
1895  return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc,
1896  EndLoc);
1897  }
1898 
1899  /// Build a new OpenMP 'depend' pseudo clause.
1900  ///
1901  /// By default, performs semantic analysis to build the new OpenMP clause.
1902  /// Subclasses may override this routine to provide different behavior.
1903  OMPClause *
1905  SourceLocation DepLoc, SourceLocation ColonLoc,
1906  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1907  SourceLocation LParenLoc, SourceLocation EndLoc) {
1908  return getSema().ActOnOpenMPDependClause(DepModifier, DepKind, DepLoc,
1909  ColonLoc, VarList, StartLoc,
1910  LParenLoc, EndLoc);
1911  }
1912 
1913  /// Build a new OpenMP 'device' clause.
1914  ///
1915  /// By default, performs semantic analysis to build the new statement.
1916  /// Subclasses may override this routine to provide different behavior.
1918  Expr *Device, SourceLocation StartLoc,
1919  SourceLocation LParenLoc,
1920  SourceLocation ModifierLoc,
1921  SourceLocation EndLoc) {
1922  return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc,
1923  LParenLoc, ModifierLoc, EndLoc);
1924  }
1925 
1926  /// Build a new OpenMP 'map' clause.
1927  ///
1928  /// By default, performs semantic analysis to build the new OpenMP clause.
1929  /// Subclasses may override this routine to provide different behavior.
1931  ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1932  ArrayRef<SourceLocation> MapTypeModifiersLoc,
1933  CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1934  OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1935  SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1936  const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
1937  return getSema().ActOnOpenMPMapClause(
1938  MapTypeModifiers, MapTypeModifiersLoc, MapperIdScopeSpec, MapperId,
1939  MapType, IsMapTypeImplicit, MapLoc, ColonLoc, VarList, Locs,
1940  /*NoDiagnose=*/false, UnresolvedMappers);
1941  }
1942 
1943  /// Build a new OpenMP 'allocate' clause.
1944  ///
1945  /// By default, performs semantic analysis to build the new OpenMP clause.
1946  /// Subclasses may override this routine to provide different behavior.
1948  SourceLocation StartLoc,
1949  SourceLocation LParenLoc,
1950  SourceLocation ColonLoc,
1951  SourceLocation EndLoc) {
1952  return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1953  LParenLoc, ColonLoc, EndLoc);
1954  }
1955 
1956  /// Build a new OpenMP 'num_teams' clause.
1957  ///
1958  /// By default, performs semantic analysis to build the new statement.
1959  /// Subclasses may override this routine to provide different behavior.
1961  SourceLocation LParenLoc,
1962  SourceLocation EndLoc) {
1963  return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1964  EndLoc);
1965  }
1966 
1967  /// Build a new OpenMP 'thread_limit' clause.
1968  ///
1969  /// By default, performs semantic analysis to build the new statement.
1970  /// Subclasses may override this routine to provide different behavior.
1972  SourceLocation StartLoc,
1973  SourceLocation LParenLoc,
1974  SourceLocation EndLoc) {
1975  return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1976  LParenLoc, EndLoc);
1977  }
1978 
1979  /// Build a new OpenMP 'priority' clause.
1980  ///
1981  /// By default, performs semantic analysis to build the new statement.
1982  /// Subclasses may override this routine to provide different behavior.
1984  SourceLocation LParenLoc,
1985  SourceLocation EndLoc) {
1986  return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1987  EndLoc);
1988  }
1989 
1990  /// Build a new OpenMP 'grainsize' clause.
1991  ///
1992  /// By default, performs semantic analysis to build the new statement.
1993  /// Subclasses may override this routine to provide different behavior.
1995  SourceLocation LParenLoc,
1996  SourceLocation EndLoc) {
1997  return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1998  EndLoc);
1999  }
2000 
2001  /// Build a new OpenMP 'num_tasks' clause.
2002  ///
2003  /// By default, performs semantic analysis to build the new statement.
2004  /// Subclasses may override this routine to provide different behavior.
2006  SourceLocation LParenLoc,
2007  SourceLocation EndLoc) {
2008  return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
2009  EndLoc);
2010  }
2011 
2012  /// Build a new OpenMP 'hint' clause.
2013  ///
2014  /// By default, performs semantic analysis to build the new statement.
2015  /// Subclasses may override this routine to provide different behavior.
2017  SourceLocation LParenLoc,
2018  SourceLocation EndLoc) {
2019  return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
2020  }
2021 
2022  /// Build a new OpenMP 'detach' clause.
2023  ///
2024  /// By default, performs semantic analysis to build the new statement.
2025  /// Subclasses may override this routine to provide different behavior.
2027  SourceLocation LParenLoc,
2028  SourceLocation EndLoc) {
2029  return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);
2030  }
2031 
2032  /// Build a new OpenMP 'dist_schedule' clause.
2033  ///
2034  /// By default, performs semantic analysis to build the new OpenMP clause.
2035  /// Subclasses may override this routine to provide different behavior.
2036  OMPClause *
2038  Expr *ChunkSize, SourceLocation StartLoc,
2039  SourceLocation LParenLoc, SourceLocation KindLoc,
2040  SourceLocation CommaLoc, SourceLocation EndLoc) {
2041  return getSema().ActOnOpenMPDistScheduleClause(
2042  Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2043  }
2044 
2045  /// Build a new OpenMP 'to' clause.
2046  ///
2047  /// By default, performs semantic analysis to build the new statement.
2048  /// Subclasses may override this routine to provide different behavior.
2049  OMPClause *
2051  ArrayRef<SourceLocation> MotionModifiersLoc,
2052  CXXScopeSpec &MapperIdScopeSpec,
2053  DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2054  ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2055  ArrayRef<Expr *> UnresolvedMappers) {
2056  return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc,
2057  MapperIdScopeSpec, MapperId, ColonLoc,
2058  VarList, Locs, UnresolvedMappers);
2059  }
2060 
2061  /// Build a new OpenMP 'from' clause.
2062  ///
2063  /// By default, performs semantic analysis to build the new statement.
2064  /// Subclasses may override this routine to provide different behavior.
2065  OMPClause *
2067  ArrayRef<SourceLocation> MotionModifiersLoc,
2068  CXXScopeSpec &MapperIdScopeSpec,
2069  DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2070  ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2071  ArrayRef<Expr *> UnresolvedMappers) {
2072  return getSema().ActOnOpenMPFromClause(
2073  MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2074  ColonLoc, VarList, Locs, UnresolvedMappers);
2075  }
2076 
2077  /// Build a new OpenMP 'use_device_ptr' clause.
2078  ///
2079  /// By default, performs semantic analysis to build the new OpenMP clause.
2080  /// Subclasses may override this routine to provide different behavior.
2082  const OMPVarListLocTy &Locs) {
2083  return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2084  }
2085 
2086  /// Build a new OpenMP 'use_device_addr' clause.
2087  ///
2088  /// By default, performs semantic analysis to build the new OpenMP clause.
2089  /// Subclasses may override this routine to provide different behavior.
2091  const OMPVarListLocTy &Locs) {
2092  return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2093  }
2094 
2095  /// Build a new OpenMP 'is_device_ptr' clause.
2096  ///
2097  /// By default, performs semantic analysis to build the new OpenMP clause.
2098  /// Subclasses may override this routine to provide different behavior.
2100  const OMPVarListLocTy &Locs) {
2101  return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2102  }
2103 
2104  /// Build a new OpenMP 'defaultmap' clause.
2105  ///
2106  /// By default, performs semantic analysis to build the new OpenMP clause.
2107  /// Subclasses may override this routine to provide different behavior.
2110  SourceLocation StartLoc,
2111  SourceLocation LParenLoc,
2112  SourceLocation MLoc,
2113  SourceLocation KindLoc,
2114  SourceLocation EndLoc) {
2115  return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc,
2116  MLoc, KindLoc, EndLoc);
2117  }
2118 
2119  /// Build a new OpenMP 'nontemporal' clause.
2120  ///
2121  /// By default, performs semantic analysis to build the new OpenMP clause.
2122  /// Subclasses may override this routine to provide different behavior.
2124  SourceLocation StartLoc,
2125  SourceLocation LParenLoc,
2126  SourceLocation EndLoc) {
2127  return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc,
2128  EndLoc);
2129  }
2130 
2131  /// Build a new OpenMP 'inclusive' clause.
2132  ///
2133  /// By default, performs semantic analysis to build the new OpenMP clause.
2134  /// Subclasses may override this routine to provide different behavior.
2136  SourceLocation StartLoc,
2137  SourceLocation LParenLoc,
2138  SourceLocation EndLoc) {
2139  return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc,
2140  EndLoc);
2141  }
2142 
2143  /// Build a new OpenMP 'exclusive' clause.
2144  ///
2145  /// By default, performs semantic analysis to build the new OpenMP clause.
2146  /// Subclasses may override this routine to provide different behavior.
2148  SourceLocation StartLoc,
2149  SourceLocation LParenLoc,
2150  SourceLocation EndLoc) {
2151  return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc,
2152  EndLoc);
2153  }
2154 
2155  /// Build a new OpenMP 'uses_allocators' clause.
2156  ///
2157  /// By default, performs semantic analysis to build the new OpenMP clause.
2158  /// Subclasses may override this routine to provide different behavior.
2161  SourceLocation LParenLoc, SourceLocation EndLoc) {
2162  return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc,
2163  Data);
2164  }
2165 
2166  /// Build a new OpenMP 'affinity' clause.
2167  ///
2168  /// By default, performs semantic analysis to build the new OpenMP clause.
2169  /// Subclasses may override this routine to provide different behavior.
2171  SourceLocation LParenLoc,
2172  SourceLocation ColonLoc,
2173  SourceLocation EndLoc, Expr *Modifier,
2174  ArrayRef<Expr *> Locators) {
2175  return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc,
2176  EndLoc, Modifier, Locators);
2177  }
2178 
2179  /// Build a new OpenMP 'order' clause.
2180  ///
2181  /// By default, performs semantic analysis to build the new OpenMP clause.
2182  /// Subclasses may override this routine to provide different behavior.
2184  SourceLocation KindKwLoc,
2185  SourceLocation StartLoc,
2186  SourceLocation LParenLoc,
2187  SourceLocation EndLoc) {
2188  return getSema().ActOnOpenMPOrderClause(Kind, KindKwLoc, StartLoc,
2189  LParenLoc, EndLoc);
2190  }
2191 
2192  /// Build a new OpenMP 'init' clause.
2193  ///
2194  /// By default, performs semantic analysis to build the new OpenMP clause.
2195  /// Subclasses may override this routine to provide different behavior.
2197  bool IsTarget, bool IsTargetSync,
2198  SourceLocation StartLoc,
2199  SourceLocation LParenLoc,
2200  SourceLocation VarLoc,
2201  SourceLocation EndLoc) {
2202  return getSema().ActOnOpenMPInitClause(InteropVar, PrefExprs, IsTarget,
2203  IsTargetSync, StartLoc, LParenLoc,
2204  VarLoc, EndLoc);
2205  }
2206 
2207  /// Build a new OpenMP 'use' clause.
2208  ///
2209  /// By default, performs semantic analysis to build the new OpenMP clause.
2210  /// Subclasses may override this routine to provide different behavior.
2212  SourceLocation LParenLoc,
2213  SourceLocation VarLoc, SourceLocation EndLoc) {
2214  return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc,
2215  VarLoc, EndLoc);
2216  }
2217 
2218  /// Build a new OpenMP 'destroy' clause.
2219  ///
2220  /// By default, performs semantic analysis to build the new OpenMP clause.
2221  /// Subclasses may override this routine to provide different behavior.
2223  SourceLocation LParenLoc,
2224  SourceLocation VarLoc,
2225  SourceLocation EndLoc) {
2226  return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc,
2227  VarLoc, EndLoc);
2228  }
2229 
2230  /// Build a new OpenMP 'novariants' clause.
2231  ///
2232  /// By default, performs semantic analysis to build the new OpenMP clause.
2233  /// Subclasses may override this routine to provide different behavior.
2235  SourceLocation StartLoc,
2236  SourceLocation LParenLoc,
2237  SourceLocation EndLoc) {
2238  return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc,
2239  EndLoc);
2240  }
2241 
2242  /// Build a new OpenMP 'nocontext' clause.
2243  ///
2244  /// By default, performs semantic analysis to build the new OpenMP clause.
2245  /// Subclasses may override this routine to provide different behavior.
2247  SourceLocation LParenLoc,
2248  SourceLocation EndLoc) {
2249  return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc,
2250  EndLoc);
2251  }
2252 
2253  /// Build a new OpenMP 'filter' clause.
2254  ///
2255  /// By default, performs semantic analysis to build the new OpenMP clause.
2256  /// Subclasses may override this routine to provide different behavior.
2258  SourceLocation LParenLoc,
2259  SourceLocation EndLoc) {
2260  return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc,
2261  EndLoc);
2262  }
2263 
2264  /// Build a new OpenMP 'bind' clause.
2265  ///
2266  /// By default, performs semantic analysis to build the new OpenMP clause.
2267  /// Subclasses may override this routine to provide different behavior.
2269  SourceLocation KindLoc,
2270  SourceLocation StartLoc,
2271  SourceLocation LParenLoc,
2272  SourceLocation EndLoc) {
2273  return getSema().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, LParenLoc,
2274  EndLoc);
2275  }
2276 
2277  /// Build a new OpenMP 'align' clause.
2278  ///
2279  /// By default, performs semantic analysis to build the new OpenMP clause.
2280  /// Subclasses may override this routine to provide different behavior.
2282  SourceLocation LParenLoc,
2283  SourceLocation EndLoc) {
2284  return getSema().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
2285  }
2286 
2287  /// Rebuild the operand to an Objective-C \@synchronized statement.
2288  ///
2289  /// By default, performs semantic analysis to build the new statement.
2290  /// Subclasses may override this routine to provide different behavior.
2292  Expr *object) {
2293  return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
2294  }
2295 
2296  /// Build a new Objective-C \@synchronized statement.
2297  ///
2298  /// By default, performs semantic analysis to build the new statement.
2299  /// Subclasses may override this routine to provide different behavior.
2301  Expr *Object, Stmt *Body) {
2302  return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2303  }
2304 
2305  /// Build a new Objective-C \@autoreleasepool statement.
2306  ///
2307  /// By default, performs semantic analysis to build the new statement.
2308  /// Subclasses may override this routine to provide different behavior.
2310  Stmt *Body) {
2311  return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2312  }
2313 
2314  /// Build a new Objective-C fast enumeration statement.
2315  ///
2316  /// By default, performs semantic analysis to build the new statement.
2317  /// Subclasses may override this routine to provide different behavior.
2319  Stmt *Element,
2320  Expr *Collection,
2321  SourceLocation RParenLoc,
2322  Stmt *Body) {
2323  StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
2324  Element,
2325  Collection,
2326  RParenLoc);
2327  if (ForEachStmt.isInvalid())
2328  return StmtError();
2329 
2330  return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
2331  }
2332 
2333  /// Build a new C++ exception declaration.
2334  ///
2335  /// By default, performs semantic analysis to build the new decaration.
2336  /// Subclasses may override this routine to provide different behavior.
2339  SourceLocation StartLoc,
2340  SourceLocation IdLoc,
2341  IdentifierInfo *Id) {
2342  VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
2343  StartLoc, IdLoc, Id);
2344  if (Var)
2345  getSema().CurContext->addDecl(Var);
2346  return Var;
2347  }
2348 
2349  /// Build a new C++ catch statement.
2350  ///
2351  /// By default, performs semantic analysis to build the new statement.
2352  /// Subclasses may override this routine to provide different behavior.
2354  VarDecl *ExceptionDecl,
2355  Stmt *Handler) {
2356  return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2357  Handler));
2358  }
2359 
2360  /// Build a new C++ try statement.
2361  ///
2362  /// By default, performs semantic analysis to build the new statement.
2363  /// Subclasses may override this routine to provide different behavior.
2365  ArrayRef<Stmt *> Handlers) {
2366  return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2367  }
2368 
2369  /// Build a new C++0x range-based for statement.
2370  ///
2371  /// By default, performs semantic analysis to build the new statement.
2372  /// Subclasses may override this routine to provide different behavior.
2374  SourceLocation CoawaitLoc, Stmt *Init,
2375  SourceLocation ColonLoc, Stmt *Range,
2376  Stmt *Begin, Stmt *End, Expr *Cond,
2377  Expr *Inc, Stmt *LoopVar,
2378  SourceLocation RParenLoc) {
2379  // If we've just learned that the range is actually an Objective-C
2380  // collection, treat this as an Objective-C fast enumeration loop.
2381  if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2382  if (RangeStmt->isSingleDecl()) {
2383  if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2384  if (RangeVar->isInvalidDecl())
2385  return StmtError();
2386 
2387  Expr *RangeExpr = RangeVar->getInit();
2388  if (!RangeExpr->isTypeDependent() &&
2389  RangeExpr->getType()->isObjCObjectPointerType()) {
2390  // FIXME: Support init-statements in Objective-C++20 ranged for
2391  // statement.
2392  if (Init) {
2393  return SemaRef.Diag(Init->getBeginLoc(),
2394  diag::err_objc_for_range_init_stmt)
2395  << Init->getSourceRange();
2396  }
2397  return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2398  RangeExpr, RParenLoc);
2399  }
2400  }
2401  }
2402  }
2403 
2404  return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2405  Range, Begin, End, Cond, Inc, LoopVar,
2406  RParenLoc, Sema::BFRK_Rebuild);
2407  }
2408 
2409  /// Build a new C++0x range-based for statement.
2410  ///
2411  /// By default, performs semantic analysis to build the new statement.
2412  /// Subclasses may override this routine to provide different behavior.
2414  bool IsIfExists,
2415  NestedNameSpecifierLoc QualifierLoc,
2416  DeclarationNameInfo NameInfo,
2417  Stmt *Nested) {
2418  return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2419  QualifierLoc, NameInfo, Nested);
2420  }
2421 
2422  /// Attach body to a C++0x range-based for statement.
2423  ///
2424  /// By default, performs semantic analysis to finish the new statement.
2425  /// Subclasses may override this routine to provide different behavior.
2427  return getSema().FinishCXXForRangeStmt(ForRange, Body);
2428  }
2429 
2431  Stmt *TryBlock, Stmt *Handler) {
2432  return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2433  }
2434 
2436  Stmt *Block) {
2437  return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2438  }
2439 
2441  return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2442  }
2443 
2445  SourceLocation LParen,
2446  SourceLocation RParen,
2447  TypeSourceInfo *TSI) {
2448  return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI);
2449  }
2450 
2451  /// Build a new predefined expression.
2452  ///
2453  /// By default, performs semantic analysis to build the new expression.
2454  /// Subclasses may override this routine to provide different behavior.
2457  return getSema().BuildPredefinedExpr(Loc, IK);
2458  }
2459 
2460  /// Build a new expression that references a declaration.
2461  ///
2462  /// By default, performs semantic analysis to build the new expression.
2463  /// Subclasses may override this routine to provide different behavior.
2465  LookupResult &R,
2466  bool RequiresADL) {
2467  return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2468  }
2469 
2470 
2471  /// Build a new expression that references a declaration.
2472  ///
2473  /// By default, performs semantic analysis to build the new expression.
2474  /// Subclasses may override this routine to provide different behavior.
2476  ValueDecl *VD,
2477  const DeclarationNameInfo &NameInfo,
2478  NamedDecl *Found,
2479  TemplateArgumentListInfo *TemplateArgs) {
2480  CXXScopeSpec SS;
2481  SS.Adopt(QualifierLoc);
2482  return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2483  TemplateArgs);
2484  }
2485 
2486  /// Build a new expression in parentheses.
2487  ///
2488  /// By default, performs semantic analysis to build the new expression.
2489  /// Subclasses may override this routine to provide different behavior.
2491  SourceLocation RParen) {
2492  return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2493  }
2494 
2495  /// Build a new pseudo-destructor expression.
2496  ///
2497  /// By default, performs semantic analysis to build the new expression.
2498  /// Subclasses may override this routine to provide different behavior.
2499  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2500  SourceLocation OperatorLoc,
2501  bool isArrow,
2502  CXXScopeSpec &SS,
2503  TypeSourceInfo *ScopeType,
2504  SourceLocation CCLoc,
2505  SourceLocation TildeLoc,
2506  PseudoDestructorTypeStorage Destroyed);
2507 
2508  /// Build a new unary operator expression.
2509  ///
2510  /// By default, performs semantic analysis to build the new expression.
2511  /// Subclasses may override this routine to provide different behavior.
2513  UnaryOperatorKind Opc,
2514  Expr *SubExpr) {
2515  return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2516  }
2517 
2518  /// Build a new builtin offsetof expression.
2519  ///
2520  /// By default, performs semantic analysis to build the new expression.
2521  /// Subclasses may override this routine to provide different behavior.
2525  SourceLocation RParenLoc) {
2526  return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2527  RParenLoc);
2528  }
2529 
2530  /// Build a new sizeof, alignof or vec_step expression with a
2531  /// type argument.
2532  ///
2533  /// By default, performs semantic analysis to build the new expression.
2534  /// Subclasses may override this routine to provide different behavior.
2536  SourceLocation OpLoc,
2537  UnaryExprOrTypeTrait ExprKind,
2538  SourceRange R) {
2539  return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2540  }
2541 
2542  /// Build a new sizeof, alignof or vec step expression with an
2543  /// expression argument.
2544  ///
2545  /// By default, performs semantic analysis to build the new expression.
2546  /// Subclasses may override this routine to provide different behavior.
2548  UnaryExprOrTypeTrait ExprKind,
2549  SourceRange R) {
2550  ExprResult Result
2551  = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2552  if (Result.isInvalid())
2553  return ExprError();
2554 
2555  return Result;
2556  }
2557 
2558  /// Build a new array subscript expression.
2559  ///
2560  /// By default, performs semantic analysis to build the new expression.
2561  /// Subclasses may override this routine to provide different behavior.
2563  SourceLocation LBracketLoc,
2564  Expr *RHS,
2565  SourceLocation RBracketLoc) {
2566  return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2567  LBracketLoc, RHS,
2568  RBracketLoc);
2569  }
2570 
2571  /// Build a new matrix subscript expression.
2572  ///
2573  /// By default, performs semantic analysis to build the new expression.
2574  /// Subclasses may override this routine to provide different behavior.
2576  Expr *ColumnIdx,
2577  SourceLocation RBracketLoc) {
2578  return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2579  RBracketLoc);
2580  }
2581 
2582  /// Build a new array section expression.
2583  ///
2584  /// By default, performs semantic analysis to build the new expression.
2585  /// Subclasses may override this routine to provide different behavior.
2587  Expr *LowerBound,
2588  SourceLocation ColonLocFirst,
2589  SourceLocation ColonLocSecond,
2590  Expr *Length, Expr *Stride,
2591  SourceLocation RBracketLoc) {
2592  return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2593  ColonLocFirst, ColonLocSecond,
2594  Length, Stride, RBracketLoc);
2595  }
2596 
2597  /// Build a new array shaping expression.
2598  ///
2599  /// By default, performs semantic analysis to build the new expression.
2600  /// Subclasses may override this routine to provide different behavior.
2602  SourceLocation RParenLoc,
2603  ArrayRef<Expr *> Dims,
2604  ArrayRef<SourceRange> BracketsRanges) {
2605  return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims,
2606  BracketsRanges);
2607  }
2608 
2609  /// Build a new iterator expression.
2610  ///
2611  /// By default, performs semantic analysis to build the new expression.
2612  /// Subclasses may override this routine to provide different behavior.
2614  SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc,
2616  return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc,
2617  LLoc, RLoc, Data);
2618  }
2619 
2620  /// Build a new call expression.
2621  ///
2622  /// By default, performs semantic analysis to build the new expression.
2623  /// Subclasses may override this routine to provide different behavior.
2625  MultiExprArg Args,
2626  SourceLocation RParenLoc,
2627  Expr *ExecConfig = nullptr) {
2628  return getSema().ActOnCallExpr(
2629  /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2630  }
2631 
2632  /// Build a new member access expression.
2633  ///
2634  /// By default, performs semantic analysis to build the new expression.
2635  /// Subclasses may override this routine to provide different behavior.
2637  bool isArrow,
2638  NestedNameSpecifierLoc QualifierLoc,
2639  SourceLocation TemplateKWLoc,
2640  const DeclarationNameInfo &MemberNameInfo,
2641  ValueDecl *Member,
2642  NamedDecl *FoundDecl,
2643  const TemplateArgumentListInfo *ExplicitTemplateArgs,
2644  NamedDecl *FirstQualifierInScope) {
2645  ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2646  isArrow);
2647  if (!Member->getDeclName()) {
2648  // We have a reference to an unnamed field. This is always the
2649  // base of an anonymous struct/union member access, i.e. the
2650  // field is always of record type.
2651  assert(Member->getType()->isRecordType() &&
2652  "unnamed member not of record type?");
2653 
2654  BaseResult =
2655  getSema().PerformObjectMemberConversion(BaseResult.get(),
2656  QualifierLoc.getNestedNameSpecifier(),
2657  FoundDecl, Member);
2658  if (BaseResult.isInvalid())
2659  return ExprError();
2660  Base = BaseResult.get();
2661 
2662  CXXScopeSpec EmptySS;
2663  return getSema().BuildFieldReferenceExpr(
2664  Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2665  DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
2666  }
2667 
2668  CXXScopeSpec SS;
2669  SS.Adopt(QualifierLoc);
2670 
2671  Base = BaseResult.get();
2672  QualType BaseType = Base->getType();
2673 
2674  if (isArrow && !BaseType->isPointerType())
2675  return ExprError();
2676 
2677  // FIXME: this involves duplicating earlier analysis in a lot of
2678  // cases; we should avoid this when possible.
2679  LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2680  R.addDecl(FoundDecl);
2681  R.resolveKind();
2682 
2683  return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2684  SS, TemplateKWLoc,
2685  FirstQualifierInScope,
2686  R, ExplicitTemplateArgs,
2687  /*S*/nullptr);
2688  }
2689 
2690  /// Build a new binary operator expression.
2691  ///
2692  /// By default, performs semantic analysis to build the new expression.
2693  /// Subclasses may override this routine to provide different behavior.
2695  BinaryOperatorKind Opc,
2696  Expr *LHS, Expr *RHS) {
2697  return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2698  }
2699 
2700  /// Build a new rewritten operator expression.
2701  ///
2702  /// By default, performs semantic analysis to build the new expression.
2703  /// Subclasses may override this routine to provide different behavior.
2706  const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2707  return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2708  RHS, /*RequiresADL*/false);
2709  }
2710 
2711  /// Build a new conditional operator expression.
2712  ///
2713  /// By default, performs semantic analysis to build the new expression.
2714  /// Subclasses may override this routine to provide different behavior.
2716  SourceLocation QuestionLoc,
2717  Expr *LHS,
2718  SourceLocation ColonLoc,
2719  Expr *RHS) {
2720  return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2721  LHS, RHS);
2722  }
2723 
2724  /// Build a new C-style cast expression.
2725  ///
2726  /// By default, performs semantic analysis to build the new expression.
2727  /// Subclasses may override this routine to provide different behavior.
2729  TypeSourceInfo *TInfo,
2730  SourceLocation RParenLoc,
2731  Expr *SubExpr) {
2732  return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2733  SubExpr);
2734  }
2735 
2736  /// Build a new compound literal expression.
2737  ///
2738  /// By default, performs semantic analysis to build the new expression.
2739  /// Subclasses may override this routine to provide different behavior.
2741  TypeSourceInfo *TInfo,
2742  SourceLocation RParenLoc,
2743  Expr *Init) {
2744  return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2745  Init);
2746  }
2747 
2748  /// Build a new extended vector element access expression.
2749  ///
2750  /// By default, performs semantic analysis to build the new expression.
2751  /// Subclasses may override this routine to provide different behavior.
2753  SourceLocation OpLoc,
2754  SourceLocation AccessorLoc,
2755  IdentifierInfo &Accessor) {
2756 
2757  CXXScopeSpec SS;
2758  DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2759  return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2760  OpLoc, /*IsArrow*/ false,
2761  SS, SourceLocation(),
2762  /*FirstQualifierInScope*/ nullptr,
2763  NameInfo,
2764  /* TemplateArgs */ nullptr,
2765  /*S*/ nullptr);
2766  }
2767 
2768  /// Build a new initializer list expression.
2769  ///
2770  /// By default, performs semantic analysis to build the new expression.
2771  /// Subclasses may override this routine to provide different behavior.
2773  MultiExprArg Inits,
2774  SourceLocation RBraceLoc) {
2775  return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
2776  }
2777 
2778  /// Build a new designated initializer expression.
2779  ///
2780  /// By default, performs semantic analysis to build the new expression.
2781  /// Subclasses may override this routine to provide different behavior.
2783  MultiExprArg ArrayExprs,
2784  SourceLocation EqualOrColonLoc,
2785  bool GNUSyntax,
2786  Expr *Init) {
2787  ExprResult Result
2788  = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2789  Init);
2790  if (Result.isInvalid())
2791  return ExprError();
2792 
2793  return Result;
2794  }
2795 
2796  /// Build a new value-initialized expression.
2797  ///
2798  /// By default, builds the implicit value initialization without performing
2799  /// any semantic analysis. Subclasses may override this routine to provide
2800  /// different behavior.
2802  return new (SemaRef.Context) ImplicitValueInitExpr(T);
2803  }
2804 
2805  /// Build a new \c va_arg expression.
2806  ///
2807  /// By default, performs semantic analysis to build the new expression.
2808  /// Subclasses may override this routine to provide different behavior.
2810  Expr *SubExpr, TypeSourceInfo *TInfo,
2811  SourceLocation RParenLoc) {
2812  return getSema().BuildVAArgExpr(BuiltinLoc,
2813  SubExpr, TInfo,
2814  RParenLoc);
2815  }
2816 
2817  /// Build a new expression list in parentheses.
2818  ///
2819  /// By default, performs semantic analysis to build the new expression.
2820  /// Subclasses may override this routine to provide different behavior.
2822  MultiExprArg SubExprs,
2823  SourceLocation RParenLoc) {
2824  return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2825  }
2826 
2827  /// Build a new address-of-label expression.
2828  ///
2829  /// By default, performs semantic analysis, using the name of the label
2830  /// rather than attempting to map the label statement itself.
2831  /// Subclasses may override this routine to provide different behavior.
2833  SourceLocation LabelLoc, LabelDecl *Label) {
2834  return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2835  }
2836 
2837  /// Build a new GNU statement expression.
2838  ///
2839  /// By default, performs semantic analysis to build the new expression.
2840  /// Subclasses may override this routine to provide different behavior.
2842  SourceLocation RParenLoc, unsigned TemplateDepth) {
2843  return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
2844  TemplateDepth);
2845  }
2846 
2847  /// Build a new __builtin_choose_expr expression.
2848  ///
2849  /// By default, performs semantic analysis to build the new expression.
2850  /// Subclasses may override this routine to provide different behavior.
2852  Expr *Cond, Expr *LHS, Expr *RHS,
2853  SourceLocation RParenLoc) {
2854  return SemaRef.ActOnChooseExpr(BuiltinLoc,
2855  Cond, LHS, RHS,
2856  RParenLoc);
2857  }
2858 
2859  /// Build a new generic selection expression.
2860  ///
2861  /// By default, performs semantic analysis to build the new expression.
2862  /// Subclasses may override this routine to provide different behavior.
2864  SourceLocation DefaultLoc,
2865  SourceLocation RParenLoc,
2866  Expr *ControllingExpr,
2868  ArrayRef<Expr *> Exprs) {
2869  return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2870  ControllingExpr, Types, Exprs);
2871  }
2872 
2873  /// Build a new overloaded operator call expression.
2874  ///
2875  /// By default, performs semantic analysis to build the new expression.
2876  /// The semantic analysis provides the behavior of template instantiation,
2877  /// copying with transformations that turn what looks like an overloaded
2878  /// operator call into a use of a builtin operator, performing
2879  /// argument-dependent lookup, etc. Subclasses may override this routine to
2880  /// provide different behavior.
2881  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2882  SourceLocation OpLoc,
2883  Expr *Callee,
2884  Expr *First,
2885  Expr *Second);
2886 
2887  /// Build a new C++ "named" cast expression, such as static_cast or
2888  /// reinterpret_cast.
2889  ///
2890  /// By default, this routine dispatches to one of the more-specific routines
2891  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2892  /// Subclasses may override this routine to provide different behavior.
2894  Stmt::StmtClass Class,
2895  SourceLocation LAngleLoc,
2896  TypeSourceInfo *TInfo,
2897  SourceLocation RAngleLoc,
2898  SourceLocation LParenLoc,
2899  Expr *SubExpr,
2900  SourceLocation RParenLoc) {
2901  switch (Class) {
2902  case Stmt::CXXStaticCastExprClass:
2903  return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2904  RAngleLoc, LParenLoc,
2905  SubExpr, RParenLoc);
2906 
2907  case Stmt::CXXDynamicCastExprClass:
2908  return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2909  RAngleLoc, LParenLoc,
2910  SubExpr, RParenLoc);
2911 
2912  case Stmt::CXXReinterpretCastExprClass:
2913  return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2914  RAngleLoc, LParenLoc,
2915  SubExpr,
2916  RParenLoc);
2917 
2918  case Stmt::CXXConstCastExprClass:
2919  return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2920  RAngleLoc, LParenLoc,
2921  SubExpr, RParenLoc);
2922 
2923  case Stmt::CXXAddrspaceCastExprClass:
2924  return getDerived().RebuildCXXAddrspaceCastExpr(
2925  OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
2926 
2927  default:
2928  llvm_unreachable("Invalid C++ named cast");
2929  }
2930  }
2931 
2932  /// Build a new C++ static_cast expression.
2933  ///
2934  /// By default, performs semantic analysis to build the new expression.
2935  /// Subclasses may override this routine to provide different behavior.
2937  SourceLocation LAngleLoc,
2938  TypeSourceInfo *TInfo,
2939  SourceLocation RAngleLoc,
2940  SourceLocation LParenLoc,
2941  Expr *SubExpr,
2942  SourceLocation RParenLoc) {
2943  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2944  TInfo, SubExpr,
2945  SourceRange(LAngleLoc, RAngleLoc),
2946  SourceRange(LParenLoc, RParenLoc));
2947  }
2948 
2949  /// Build a new C++ dynamic_cast expression.
2950  ///
2951  /// By default, performs semantic analysis to build the new expression.
2952  /// Subclasses may override this routine to provide different behavior.
2954  SourceLocation LAngleLoc,
2955  TypeSourceInfo *TInfo,
2956  SourceLocation RAngleLoc,
2957  SourceLocation LParenLoc,
2958  Expr *SubExpr,
2959  SourceLocation RParenLoc) {
2960  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2961  TInfo, SubExpr,
2962  SourceRange(LAngleLoc, RAngleLoc),
2963  SourceRange(LParenLoc, RParenLoc));
2964  }
2965 
2966  /// Build a new C++ reinterpret_cast expression.
2967  ///
2968  /// By default, performs semantic analysis to build the new expression.
2969  /// Subclasses may override this routine to provide different behavior.
2971  SourceLocation LAngleLoc,
2972  TypeSourceInfo *TInfo,
2973  SourceLocation RAngleLoc,
2974  SourceLocation LParenLoc,
2975  Expr *SubExpr,
2976  SourceLocation RParenLoc) {
2977  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2978  TInfo, SubExpr,
2979  SourceRange(LAngleLoc, RAngleLoc),
2980  SourceRange(LParenLoc, RParenLoc));
2981  }
2982 
2983  /// Build a new C++ const_cast expression.
2984  ///
2985  /// By default, performs semantic analysis to build the new expression.
2986  /// Subclasses may override this routine to provide different behavior.
2988  SourceLocation LAngleLoc,
2989  TypeSourceInfo *TInfo,
2990  SourceLocation RAngleLoc,
2991  SourceLocation LParenLoc,
2992  Expr *SubExpr,
2993  SourceLocation RParenLoc) {
2994  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2995  TInfo, SubExpr,
2996  SourceRange(LAngleLoc, RAngleLoc),
2997  SourceRange(LParenLoc, RParenLoc));
2998  }
2999 
3000  ExprResult
3002  TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3003  SourceLocation LParenLoc, Expr *SubExpr,
3004  SourceLocation RParenLoc) {
3005  return getSema().BuildCXXNamedCast(
3006  OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3007  SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3008  }
3009 
3010  /// Build a new C++ functional-style cast expression.
3011  ///
3012  /// By default, performs semantic analysis to build the new expression.
3013  /// Subclasses may override this routine to provide different behavior.
3015  SourceLocation LParenLoc,
3016  Expr *Sub,
3017  SourceLocation RParenLoc,
3018  bool ListInitialization) {
3019  return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3020  MultiExprArg(&Sub, 1), RParenLoc,
3021  ListInitialization);
3022  }
3023 
3024  /// Build a new C++ __builtin_bit_cast expression.
3025  ///
3026  /// By default, performs semantic analysis to build the new expression.
3027  /// Subclasses may override this routine to provide different behavior.
3029  TypeSourceInfo *TSI, Expr *Sub,
3030  SourceLocation RParenLoc) {
3031  return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3032  }
3033 
3034  /// Build a new C++ typeid(type) expression.
3035  ///
3036  /// By default, performs semantic analysis to build the new expression.
3037  /// Subclasses may override this routine to provide different behavior.
3039  SourceLocation TypeidLoc,
3040  TypeSourceInfo *Operand,
3041  SourceLocation RParenLoc) {
3042  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3043  RParenLoc);
3044  }
3045 
3046 
3047  /// Build a new C++ typeid(expr) expression.
3048  ///
3049  /// By default, performs semantic analysis to build the new expression.
3050  /// Subclasses may override this routine to provide different behavior.
3052  SourceLocation TypeidLoc,
3053  Expr *Operand,
3054  SourceLocation RParenLoc) {
3055  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3056  RParenLoc);
3057  }
3058 
3059  /// Build a new C++ __uuidof(type) expression.
3060  ///
3061  /// By default, performs semantic analysis to build the new expression.
3062  /// Subclasses may override this routine to provide different behavior.
3064  TypeSourceInfo *Operand,
3065  SourceLocation RParenLoc) {
3066  return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3067  }
3068 
3069  /// Build a new C++ __uuidof(expr) expression.
3070  ///
3071  /// By default, performs semantic analysis to build the new expression.
3072  /// Subclasses may override this routine to provide different behavior.
3074  Expr *Operand, SourceLocation RParenLoc) {
3075  return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3076  }
3077 
3078  /// Build a new C++ "this" expression.
3079  ///
3080  /// By default, builds a new "this" expression without performing any
3081  /// semantic analysis. Subclasses may override this routine to provide
3082  /// different behavior.
3084  QualType ThisType,
3085  bool isImplicit) {
3086  return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3087  }
3088 
3089  /// Build a new C++ throw expression.
3090  ///
3091  /// By default, performs semantic analysis to build the new expression.
3092  /// Subclasses may override this routine to provide different behavior.
3094  bool IsThrownVariableInScope) {
3095  return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3096  }
3097 
3098  /// Build a new C++ default-argument expression.
3099  ///
3100  /// By default, builds a new default-argument expression, which does not
3101  /// require any semantic analysis. Subclasses may override this routine to
3102  /// provide different behavior.
3104  return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3105  getSema().CurContext);
3106  }
3107 
3108  /// Build a new C++11 default-initialization expression.
3109  ///
3110  /// By default, builds a new default field initialization expression, which
3111  /// does not require any semantic analysis. Subclasses may override this
3112  /// routine to provide different behavior.
3114  FieldDecl *Field) {
3115  return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
3116  getSema().CurContext);
3117  }
3118 
3119  /// Build a new C++ zero-initialization expression.
3120  ///
3121  /// By default, performs semantic analysis to build the new expression.
3122  /// Subclasses may override this routine to provide different behavior.
3124  SourceLocation LParenLoc,
3125  SourceLocation RParenLoc) {
3126  return getSema().BuildCXXTypeConstructExpr(
3127  TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
3128  }
3129 
3130  /// Build a new C++ "new" expression.
3131  ///
3132  /// By default, performs semantic analysis to build the new expression.
3133  /// Subclasses may override this routine to provide different behavior.
3135  bool UseGlobal,
3136  SourceLocation PlacementLParen,
3137  MultiExprArg PlacementArgs,
3138  SourceLocation PlacementRParen,
3139  SourceRange TypeIdParens,
3140  QualType AllocatedType,
3141  TypeSourceInfo *AllocatedTypeInfo,
3142  Optional<Expr *> ArraySize,
3143  SourceRange DirectInitRange,
3144  Expr *Initializer) {
3145  return getSema().BuildCXXNew(StartLoc, UseGlobal,
3146  PlacementLParen,
3147  PlacementArgs,
3148  PlacementRParen,
3149  TypeIdParens,
3150  AllocatedType,
3151  AllocatedTypeInfo,
3152  ArraySize,
3153  DirectInitRange,
3154  Initializer);
3155  }
3156 
3157  /// Build a new C++ "delete" expression.
3158  ///
3159  /// By default, performs semantic analysis to build the new expression.
3160  /// Subclasses may override this routine to provide different behavior.
3162  bool IsGlobalDelete,
3163  bool IsArrayForm,
3164  Expr *Operand) {
3165  return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3166  Operand);
3167  }
3168 
3169  /// Build a new type trait expression.
3170  ///
3171  /// By default, performs semantic analysis to build the new expression.
3172  /// Subclasses may override this routine to provide different behavior.
3174  SourceLocation StartLoc,
3176  SourceLocation RParenLoc) {
3177  return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3178  }
3179 
3180  /// Build a new array type trait expression.
3181  ///
3182  /// By default, performs semantic analysis to build the new expression.
3183  /// Subclasses may override this routine to provide different behavior.
3185  SourceLocation StartLoc,
3186  TypeSourceInfo *TSInfo,
3187  Expr *DimExpr,
3188  SourceLocation RParenLoc) {
3189  return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3190  }
3191 
3192  /// Build a new expression trait expression.
3193  ///
3194  /// By default, performs semantic analysis to build the new expression.
3195  /// Subclasses may override this routine to provide different behavior.
3197  SourceLocation StartLoc,
3198  Expr *Queried,
3199  SourceLocation RParenLoc) {
3200  return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3201  }
3202 
3203  /// Build a new (previously unresolved) declaration reference
3204  /// expression.
3205  ///
3206  /// By default, performs semantic analysis to build the new expression.
3207  /// Subclasses may override this routine to provide different behavior.
3209  NestedNameSpecifierLoc QualifierLoc,
3210  SourceLocation TemplateKWLoc,
3211  const DeclarationNameInfo &NameInfo,
3212  const TemplateArgumentListInfo *TemplateArgs,
3213  bool IsAddressOfOperand,
3214  TypeSourceInfo **RecoveryTSI) {
3215  CXXScopeSpec SS;
3216  SS.Adopt(QualifierLoc);
3217 
3218  if (TemplateArgs || TemplateKWLoc.isValid())
3219  return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
3220  TemplateArgs);
3221 
3222  return getSema().BuildQualifiedDeclarationNameExpr(
3223  SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
3224  }
3225 
3226  /// Build a new template-id expression.
3227  ///
3228  /// By default, performs semantic analysis to build the new expression.
3229  /// Subclasses may override this routine to provide different behavior.
3231  SourceLocation TemplateKWLoc,
3232  LookupResult &R,
3233  bool RequiresADL,
3234  const TemplateArgumentListInfo *TemplateArgs) {
3235  return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3236  TemplateArgs);
3237  }
3238 
3239  /// Build a new object-construction expression.
3240  ///
3241  /// By default, performs semantic analysis to build the new expression.
3242  /// Subclasses may override this routine to provide different behavior.
3244  SourceLocation Loc,
3245  CXXConstructorDecl *Constructor,
3246  bool IsElidable,
3247  MultiExprArg Args,
3248  bool HadMultipleCandidates,
3249  bool ListInitialization,
3250  bool StdInitListInitialization,
3251  bool RequiresZeroInit,
3252  CXXConstructExpr::ConstructionKind ConstructKind,
3253  SourceRange ParenRange) {
3254  // Reconstruct the constructor we originally found, which might be
3255  // different if this is a call to an inherited constructor.
3256  CXXConstructorDecl *FoundCtor = Constructor;
3257  if (Constructor->isInheritingConstructor())
3258  FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3259 
3260  SmallVector<Expr *, 8> ConvertedArgs;
3261  if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3262  ConvertedArgs))
3263  return ExprError();
3264 
3265  return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3266  IsElidable,
3267  ConvertedArgs,
3268  HadMultipleCandidates,
3269  ListInitialization,
3270  StdInitListInitialization,
3271  RequiresZeroInit, ConstructKind,
3272  ParenRange);
3273  }
3274 
3275  /// Build a new implicit construction via inherited constructor
3276  /// expression.
3278  CXXConstructorDecl *Constructor,
3279  bool ConstructsVBase,
3280  bool InheritedFromVBase) {
3281  return new (getSema().Context) CXXInheritedCtorInitExpr(
3282  Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3283  }
3284 
3285  /// Build a new object-construction expression.
3286  ///
3287  /// By default, performs semantic analysis to build the new expression.
3288  /// Subclasses may override this routine to provide different behavior.
3290  SourceLocation LParenOrBraceLoc,
3291  MultiExprArg Args,
3292  SourceLocation RParenOrBraceLoc,
3293  bool ListInitialization) {
3294  return getSema().BuildCXXTypeConstructExpr(
3295  TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3296  }
3297 
3298  /// Build a new object-construction expression.
3299  ///
3300  /// By default, performs semantic analysis to build the new expression.
3301  /// Subclasses may override this routine to provide different behavior.
3303  SourceLocation LParenLoc,
3304  MultiExprArg Args,
3305  SourceLocation RParenLoc,
3306  bool ListInitialization) {
3307  return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3308  RParenLoc, ListInitialization);
3309  }
3310 
3311  /// Build a new member reference expression.
3312  ///
3313  /// By default, performs semantic analysis to build the new expression.
3314  /// Subclasses may override this routine to provide different behavior.
3316  QualType BaseType,
3317  bool IsArrow,
3318  SourceLocation OperatorLoc,
3319  NestedNameSpecifierLoc QualifierLoc,
3320  SourceLocation TemplateKWLoc,
3321  NamedDecl *FirstQualifierInScope,
3322  const DeclarationNameInfo &MemberNameInfo,
3323  const TemplateArgumentListInfo *TemplateArgs) {
3324  CXXScopeSpec SS;
3325  SS.Adopt(QualifierLoc);
3326 
3327  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3328  OperatorLoc, IsArrow,
3329  SS, TemplateKWLoc,
3330  FirstQualifierInScope,
3331  MemberNameInfo,
3332  TemplateArgs, /*S*/nullptr);
3333  }
3334 
3335  /// Build a new member reference expression.
3336  ///
3337  /// By default, performs semantic analysis to build the new expression.
3338  /// Subclasses may override this routine to provide different behavior.
3340  SourceLocation OperatorLoc,
3341  bool IsArrow,
3342  NestedNameSpecifierLoc QualifierLoc,
3343  SourceLocation TemplateKWLoc,
3344  NamedDecl *FirstQualifierInScope,
3345  LookupResult &R,
3346  const TemplateArgumentListInfo *TemplateArgs) {
3347  CXXScopeSpec SS;
3348  SS.Adopt(QualifierLoc);
3349 
3350  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3351  OperatorLoc, IsArrow,
3352  SS, TemplateKWLoc,
3353  FirstQualifierInScope,
3354  R, TemplateArgs, /*S*/nullptr);
3355  }
3356 
3357  /// Build a new noexcept expression.
3358  ///
3359  /// By default, performs semantic analysis to build the new expression.
3360  /// Subclasses may override this routine to provide different behavior.
3362  return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3363  }
3364 
3365  /// Build a new expression to compute the length of a parameter pack.
3367  NamedDecl *Pack,
3368  SourceLocation PackLoc,
3369  SourceLocation RParenLoc,
3370  Optional<unsigned> Length,
3371  ArrayRef<TemplateArgument> PartialArgs) {
3372  return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3373  RParenLoc, Length, PartialArgs);
3374  }
3375 
3376  /// Build a new expression representing a call to a source location
3377  /// builtin.
3378  ///
3379  /// By default, performs semantic analysis to build the new expression.
3380  /// Subclasses may override this routine to provide different behavior.
3382  SourceLocation BuiltinLoc,
3383  SourceLocation RPLoc,
3384  DeclContext *ParentContext) {
3385  return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3386  }
3387 
3388  /// Build a new Objective-C boxed expression.
3389  ///
3390  /// By default, performs semantic analysis to build the new expression.
3391  /// Subclasses may override this routine to provide different behavior.
3393  SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3394  NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3395  TemplateArgumentListInfo *TALI) {
3396  CXXScopeSpec SS;
3397  SS.Adopt(NNS);
3398  ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3399  ConceptNameInfo,
3400  FoundDecl,
3401  NamedConcept, TALI);
3402  if (Result.isInvalid())
3403  return ExprError();
3404  return Result;
3405  }
3406 
3407  /// \brief Build a new requires expression.
3408  ///
3409  /// By default, performs semantic analysis to build the new expression.
3410  /// Subclasses may override this routine to provide different behavior.
3412  RequiresExprBodyDecl *Body,
3413  ArrayRef<ParmVarDecl *> LocalParameters,
3414  ArrayRef<concepts::Requirement *> Requirements,
3415  SourceLocation ClosingBraceLoc) {
3416  return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body,
3417  LocalParameters, Requirements, ClosingBraceLoc);
3418  }
3419 
3423  return SemaRef.BuildTypeRequirement(SubstDiag);
3424  }
3425 
3427  return SemaRef.BuildTypeRequirement(T);
3428  }
3429 
3432  concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3433  SourceLocation NoexceptLoc,
3435  return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3436  std::move(Ret));
3437  }
3438 
3440  RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3442  return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3443  std::move(Ret));
3444  }
3445 
3449  return SemaRef.BuildNestedRequirement(SubstDiag);
3450  }
3451 
3453  return SemaRef.BuildNestedRequirement(Constraint);
3454  }
3455 
3456  /// \brief Build a new Objective-C boxed expression.
3457  ///
3458  /// By default, performs semantic analysis to build the new expression.
3459  /// Subclasses may override this routine to provide different behavior.
3461  return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3462  }
3463 
3464  /// Build a new Objective-C array literal.
3465  ///
3466  /// By default, performs semantic analysis to build the new expression.
3467  /// Subclasses may override this routine to provide different behavior.
3469  Expr **Elements, unsigned NumElements) {
3470  return getSema().BuildObjCArrayLiteral(Range,
3471  MultiExprArg(Elements, NumElements));
3472  }
3473 
3475  Expr *Base, Expr *Key,
3476  ObjCMethodDecl *getterMethod,
3477  ObjCMethodDecl *setterMethod) {
3478  return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3479  getterMethod, setterMethod);
3480  }
3481 
3482  /// Build a new Objective-C dictionary literal.
3483  ///
3484  /// By default, performs semantic analysis to build the new expression.
3485  /// Subclasses may override this routine to provide different behavior.
3488  return getSema().BuildObjCDictionaryLiteral(Range, Elements);
3489  }
3490 
3491  /// Build a new Objective-C \@encode expression.
3492  ///
3493  /// By default, performs semantic analysis to build the new expression.
3494  /// Subclasses may override this routine to provide different behavior.
3496  TypeSourceInfo *EncodeTypeInfo,
3497  SourceLocation RParenLoc) {
3498  return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
3499  }
3500 
3501  /// Build a new Objective-C class message.
3503  Selector Sel,
3504  ArrayRef<SourceLocation> SelectorLocs,
3505  ObjCMethodDecl *Method,
3506  SourceLocation LBracLoc,
3507  MultiExprArg Args,
3508  SourceLocation RBracLoc) {
3509  return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3510  ReceiverTypeInfo->getType(),
3511  /*SuperLoc=*/SourceLocation(),
3512  Sel, Method, LBracLoc, SelectorLocs,
3513  RBracLoc, Args);
3514  }
3515 
3516  /// Build a new Objective-C instance message.
3518  Selector Sel,
3519  ArrayRef<SourceLocation> SelectorLocs,
3520  ObjCMethodDecl *Method,
3521  SourceLocation LBracLoc,
3522  MultiExprArg Args,
3523  SourceLocation RBracLoc) {
3524  return SemaRef.BuildInstanceMessage(Receiver,
3525  Receiver->getType(),
3526  /*SuperLoc=*/SourceLocation(),
3527  Sel, Method, LBracLoc, SelectorLocs,
3528  RBracLoc, Args);
3529  }
3530 
3531  /// Build a new Objective-C instance/class message to 'super'.
3533  Selector Sel,
3534  ArrayRef<SourceLocation> SelectorLocs,
3535  QualType SuperType,
3536  ObjCMethodDecl *Method,
3537  SourceLocation LBracLoc,
3538  MultiExprArg Args,
3539  SourceLocation RBracLoc) {
3540  return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3541  SuperType,
3542  SuperLoc,
3543  Sel, Method, LBracLoc, SelectorLocs,
3544  RBracLoc, Args)
3545  : SemaRef.BuildClassMessage(nullptr,
3546  SuperType,
3547  SuperLoc,
3548  Sel, Method, LBracLoc, SelectorLocs,
3549  RBracLoc, Args);
3550 
3551 
3552  }
3553 
3554  /// Build a new Objective-C ivar reference expression.
3555  ///
3556  /// By default, performs semantic analysis to build the new expression.
3557  /// Subclasses may override this routine to provide different behavior.
3559  SourceLocation IvarLoc,
3560  bool IsArrow, bool IsFreeIvar) {
3561  CXXScopeSpec SS;
3562  DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3563  ExprResult Result = getSema().BuildMemberReferenceExpr(
3564  BaseArg, BaseArg->getType(),
3565  /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3566  /*FirstQualifierInScope=*/nullptr, NameInfo,
3567  /*TemplateArgs=*/nullptr,
3568  /*S=*/nullptr);
3569  if (IsFreeIvar && Result.isUsable())
3570  cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3571  return Result;
3572  }
3573 
3574  /// Build a new Objective-C property reference expression.
3575  ///
3576  /// By default, performs semantic analysis to build the new expression.
3577  /// Subclasses may override this routine to provide different behavior.
3579  ObjCPropertyDecl *Property,
3580  SourceLocation PropertyLoc) {
3581  CXXScopeSpec SS;
3582  DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3583  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3584  /*FIXME:*/PropertyLoc,
3585  /*IsArrow=*/false,
3586  SS, SourceLocation(),
3587  /*FirstQualifierInScope=*/nullptr,
3588  NameInfo,
3589  /*TemplateArgs=*/nullptr,
3590  /*S=*/nullptr);
3591  }
3592 
3593  /// Build a new Objective-C property reference expression.
3594  ///
3595  /// By default, performs semantic analysis to build the new expression.
3596  /// Subclasses may override this routine to provide different behavior.
3598  ObjCMethodDecl *Getter,
3599  ObjCMethodDecl *Setter,
3600  SourceLocation PropertyLoc) {
3601  // Since these expressions can only be value-dependent, we do not
3602  // need to perform semantic analysis again.
3603  return Owned(
3604  new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3606  PropertyLoc, Base));
3607  }
3608 
3609  /// Build a new Objective-C "isa" expression.
3610  ///
3611  /// By default, performs semantic analysis to build the new expression.
3612  /// Subclasses may override this routine to provide different behavior.
3614  SourceLocation OpLoc, bool IsArrow) {
3615  CXXScopeSpec SS;
3616  DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3617  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3618  OpLoc, IsArrow,
3619  SS, SourceLocation(),
3620  /*FirstQualifierInScope=*/nullptr,
3621  NameInfo,
3622  /*TemplateArgs=*/nullptr,
3623  /*S=*/nullptr);
3624  }
3625 
3626  /// Build a new shuffle vector expression.
3627  ///
3628  /// By default, performs semantic analysis to build the new expression.
3629  /// Subclasses may override this routine to provide different behavior.
3631  MultiExprArg SubExprs,
3632  SourceLocation RParenLoc) {
3633  // Find the declaration for __builtin_shufflevector
3634  const IdentifierInfo &Name
3635  = SemaRef.Context.Idents.get("__builtin_shufflevector");
3637  DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3638  assert(!Lookup.empty() && "No __builtin_shufflevector?");
3639 
3640  // Build a reference to the __builtin_shufflevector builtin
3641  FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3642  Expr *Callee = new (SemaRef.Context)
3643  DeclRefExpr(SemaRef.Context, Builtin, false,
3644  SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3645  QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3646  Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3647  CK_BuiltinFnToFnPtr).get();
3648 
3649  // Build the CallExpr
3650  ExprResult TheCall = CallExpr::Create(
3651  SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3652  Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3653  FPOptionsOverride());
3654 
3655  // Type-check the __builtin_shufflevector expression.
3656  return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3657  }
3658 
3659  /// Build a new convert vector expression.
3661  Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3662  SourceLocation RParenLoc) {
3663  return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3664  BuiltinLoc, RParenLoc);
3665  }
3666 
3667  /// Build a new template argument pack expansion.
3668  ///
3669  /// By default, performs semantic analysis to build a new pack expansion
3670  /// for a template argument. Subclasses may override this routine to provide
3671  /// different behavior.
3673  SourceLocation EllipsisLoc,
3674  Optional<unsigned> NumExpansions) {
3675  switch (Pattern.getArgument().getKind()) {
3676  case TemplateArgument::Expression: {
3677  ExprResult Result
3678  = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3679  EllipsisLoc, NumExpansions);
3680  if (Result.isInvalid())
3681  return TemplateArgumentLoc();
3682 
3683  return TemplateArgumentLoc(Result.get(), Result.get());
3684  }
3685 
3686  case TemplateArgument::Template:
3687  return TemplateArgumentLoc(
3688  SemaRef.Context,
3690  NumExpansions),
3691  Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3692  EllipsisLoc);
3693 
3695  case TemplateArgument::Integral:
3696  case TemplateArgument::Declaration:
3697  case TemplateArgument::Pack:
3698  case TemplateArgument::TemplateExpansion:
3699  case TemplateArgument::NullPtr:
3700  llvm_unreachable("Pack expansion pattern has no parameter packs");
3701 
3703  if (TypeSourceInfo *Expansion
3704  = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3705  EllipsisLoc,
3706  NumExpansions))
3707  return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3708  Expansion);
3709  break;
3710  }
3711 
3712  return TemplateArgumentLoc();
3713  }
3714 
3715  /// Build a new expression pack expansion.
3716  ///
3717  /// By default, performs semantic analysis to build a new pack expansion
3718  /// for an expression. Subclasses may override this routine to provide
3719  /// different behavior.
3721  Optional<unsigned> NumExpansions) {
3722  return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3723  }
3724 
3725  /// Build a new C++1z fold-expression.
3726  ///
3727  /// By default, performs semantic analysis in order to build a new fold
3728  /// expression.
3730  SourceLocation LParenLoc, Expr *LHS,
3731  BinaryOperatorKind Operator,
3732  SourceLocation EllipsisLoc, Expr *RHS,
3733  SourceLocation RParenLoc,
3734  Optional<unsigned> NumExpansions) {
3735  return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
3736  EllipsisLoc, RHS, RParenLoc,
3737  NumExpansions);
3738  }
3739 
3740  /// Build an empty C++1z fold-expression with the given operator.
3741  ///
3742  /// By default, produces the fallback value for the fold-expression, or
3743  /// produce an error if there is no fallback value.
3745  BinaryOperatorKind Operator) {
3746  return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3747  }
3748 
3749  /// Build a new atomic operation expression.
3750  ///
3751  /// By default, performs semantic analysis to build the new expression.
3752  /// Subclasses may override this routine to provide different behavior.
3755  SourceLocation RParenLoc) {
3756  // Use this for all of the locations, since we don't know the difference
3757  // between the call and the expr at this point.
3758  SourceRange Range{BuiltinLoc, RParenLoc};
3759  return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
3760  Sema::AtomicArgumentOrder::AST);
3761  }
3762 
3764  ArrayRef<Expr *> SubExprs, QualType Type) {
3765  return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
3766  }
3767 
3768 private:
3769  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3770  QualType ObjectType,
3771  NamedDecl *FirstQualifierInScope,
3772  CXXScopeSpec &SS);
3773 
3774  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3775  QualType ObjectType,
3776  NamedDecl *FirstQualifierInScope,
3777  CXXScopeSpec &SS);
3778 
3779  TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3780  NamedDecl *FirstQualifierInScope,
3781  CXXScopeSpec &SS);
3782 
3783  QualType TransformDependentNameType(TypeLocBuilder &TLB,
3785  bool DeducibleTSTContext);
3786 };
3787 
3788 template <typename Derived>
3790  if (!S)
3791  return S;
3792 
3793  switch (S->getStmtClass()) {
3794  case Stmt::NoStmtClass: break;
3795 
3796  // Transform individual statement nodes
3797  // Pass SDK into statements that can produce a value
3798 #define STMT(Node, Parent) \
3799  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3800 #define VALUESTMT(Node, Parent) \
3801  case Stmt::Node##Class: \
3802  return getDerived().Transform##Node(cast<Node>(S), SDK);
3803 #define ABSTRACT_STMT(Node)
3804 #define EXPR(Node, Parent)
3805 #include "clang/AST/StmtNodes.inc"
3806 
3807  // Transform expressions by calling TransformExpr.
3808 #define STMT(Node, Parent)
3809 #define ABSTRACT_STMT(Stmt)
3810 #define EXPR(Node, Parent) case Stmt::Node##Class:
3811 #include "clang/AST/StmtNodes.inc"
3812  {
3813  ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3814 
3815  if (SDK == SDK_StmtExprResult)
3816  E = getSema().ActOnStmtExprResult(E);
3817  return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
3818  }
3819  }
3820 
3821  return S;
3822 }
3823 
3824 template<typename Derived>
3826  if (!S)
3827  return S;
3828 
3829  switch (S->getClauseKind()) {
3830  default: break;
3831  // Transform individual clause nodes
3832 #define GEN_CLANG_CLAUSE_CLASS
3833 #define CLAUSE_CLASS(Enum, Str, Class) \
3834  case Enum: \
3835  return getDerived().Transform##Class(cast<Class>(S));
3836 #include "llvm/Frontend/OpenMP/OMP.inc"
3837  }
3838 
3839  return S;
3840 }
3841 
3842 
3843 template<typename Derived>
3845  if (!E)
3846  return E;
3847 
3848  switch (E->getStmtClass()) {
3849  case Stmt::NoStmtClass: break;
3850 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3851 #define ABSTRACT_STMT(Stmt)
3852 #define EXPR(Node, Parent) \
3853  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3854 #include "clang/AST/StmtNodes.inc"
3855  }
3856 
3857  return E;
3858 }
3859 
3860 template<typename Derived>
3862  bool NotCopyInit) {
3863  // Initializers are instantiated like expressions, except that various outer
3864  // layers are stripped.
3865  if (!Init)
3866  return Init;
3867 
3868  if (auto *FE = dyn_cast<FullExpr>(Init))
3869  Init = FE->getSubExpr();
3870 
3871  if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
3872  OpaqueValueExpr *OVE = AIL->getCommonExpr();
3873  Init = OVE->getSourceExpr();
3874  }
3875 
3876  if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3877  Init = MTE->getSubExpr();
3878 
3879  while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3880  Init = Binder->getSubExpr();
3881 
3882  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3883  Init = ICE->getSubExprAsWritten();
3884 
3885  if (CXXStdInitializerListExpr *ILE =
3886  dyn_cast<CXXStdInitializerListExpr>(Init))
3887  return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3888 
3889  // If this is copy-initialization, we only need to reconstruct
3890  // InitListExprs. Other forms of copy-initialization will be a no-op if
3891  // the initializer is already the right type.
3892  CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3893  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3894  return getDerived().TransformExpr(Init);
3895 
3896  // Revert value-initialization back to empty parens.
3897  if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3898  SourceRange Parens = VIE->getSourceRange();
3899  return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3900  Parens.getEnd());
3901  }
3902 
3903  // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3904  if (isa<ImplicitValueInitExpr>(Init))
3905  return getDerived().RebuildParenListExpr(SourceLocation(), None,
3906  SourceLocation());
3907 
3908  // Revert initialization by constructor back to a parenthesized or braced list
3909  // of expressions. Any other form of initializer can just be reused directly.
3910  if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3911  return getDerived().TransformExpr(Init);
3912 
3913  // If the initialization implicitly converted an initializer list to a
3914  // std::initializer_list object, unwrap the std::initializer_list too.
3915  if (Construct && Construct->isStdInitListInitialization())
3916  return TransformInitializer(Construct->getArg(0), NotCopyInit);
3917 
3918  // Enter a list-init context if this was list initialization.
3920  getSema(), EnterExpressionEvaluationContext::InitList,
3921  Construct->isListInitialization());
3922 
3923  SmallVector<Expr*, 8> NewArgs;
3924  bool ArgChanged = false;
3925  if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3926  /*IsCall*/true, NewArgs, &ArgChanged))
3927  return ExprError();
3928 
3929  // If this was list initialization, revert to syntactic list form.
3930  if (Construct->isListInitialization())
3931  return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
3932  Construct->getEndLoc());
3933 
3934  // Build a ParenListExpr to represent anything else.
3935  SourceRange Parens = Construct->getParenOrBraceRange();
3936  if (Parens.isInvalid()) {
3937  // This was a variable declaration's initialization for which no initializer
3938  // was specified.
3939  assert(NewArgs.empty() &&
3940  "no parens or braces but have direct init with arguments?");
3941  return ExprEmpty();
3942  }
3943  return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3944  Parens.getEnd());
3945 }
3946 
3947 template<typename Derived>
3949  unsigned NumInputs,
3950  bool IsCall,
3951  SmallVectorImpl<Expr *> &Outputs,
3952  bool *ArgChanged) {
3953  for (unsigned I = 0; I != NumInputs; ++I) {
3954  // If requested, drop call arguments that need to be dropped.
3955  if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3956  if (ArgChanged)
3957  *ArgChanged = true;
3958 
3959  break;
3960  }
3961 
3962  if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3963  Expr *Pattern = Expansion->getPattern();
3964 
3966  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3967  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3968 
3969  // Determine whether the set of unexpanded parameter packs can and should
3970  // be expanded.
3971  bool Expand = true;
3972  bool RetainExpansion = false;
3973  Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3974  Optional<unsigned> NumExpansions = OrigNumExpansions;
3975  if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3976  Pattern->getSourceRange(),
3977  Unexpanded,
3978  Expand, RetainExpansion,
3979  NumExpansions))
3980  return true;
3981 
3982  if (!Expand) {
3983  // The transform has determined that we should perform a simple
3984  // transformation on the pack expansion, producing another pack
3985  // expansion.
3986  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3987  ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3988  if (OutPattern.isInvalid())
3989  return true;
3990 
3991  ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3992  Expansion->getEllipsisLoc(),
3993  NumExpansions);
3994  if (Out.isInvalid())
3995  return true;
3996 
3997  if (ArgChanged)
3998  *ArgChanged = true;
3999  Outputs.push_back(Out.get());
4000  continue;
4001  }
4002 
4003  // Record right away that the argument was changed. This needs
4004  // to happen even if the array expands to nothing.
4005  if (ArgChanged) *ArgChanged = true;
4006 
4007  // The transform has determined that we should perform an elementwise
4008  // expansion of the pattern. Do so.
4009  for (unsigned I = 0; I != *NumExpansions; ++I) {
4010  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4011  ExprResult Out = getDerived().TransformExpr(Pattern);
4012  if (Out.isInvalid())
4013  return true;
4014 
4015  if (Out.get()->containsUnexpandedParameterPack()) {
4016  Out = getDerived().RebuildPackExpansion(
4017  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4018  if (Out.isInvalid())
4019  return true;
4020  }
4021 
4022  Outputs.push_back(Out.get());
4023  }
4024 
4025  // If we're supposed to retain a pack expansion, do so by temporarily
4026  // forgetting the partially-substituted parameter pack.
4027  if (RetainExpansion) {
4028  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4029 
4030  ExprResult Out = getDerived().TransformExpr(Pattern);
4031  if (Out.isInvalid())
4032  return true;
4033 
4034  Out = getDerived().RebuildPackExpansion(
4035  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4036  if (Out.isInvalid())
4037  return true;
4038 
4039  Outputs.push_back(Out.get());
4040  }
4041 
4042  continue;
4043  }
4044 
4045  ExprResult Result =
4046  IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4047  : getDerived().TransformExpr(Inputs[I]);
4048  if (Result.isInvalid())
4049  return true;
4050 
4051  if (Result.get() != Inputs[I] && ArgChanged)
4052  *ArgChanged = true;
4053 
4054  Outputs.push_back(Result.get());
4055  }
4056 
4057  return false;
4058 }
4059 
4060 template <typename Derived>
4063  if (Var) {
4064  VarDecl *ConditionVar = cast_or_null<VarDecl>(
4065  getDerived().TransformDefinition(Var->getLocation(), Var));
4066 
4067  if (!ConditionVar)
4068  return Sema::ConditionError();
4069 
4070  return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4071  }
4072 
4073  if (Expr) {
4074  ExprResult CondExpr = getDerived().TransformExpr(Expr);
4075 
4076  if (CondExpr.isInvalid())
4077  return Sema::ConditionError();
4078 
4079  return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4080  /*MissingOK=*/true);
4081  }
4082 
4083  return Sema::ConditionResult();
4084 }
4085 
4086 template <typename Derived>
4088  NestedNameSpecifierLoc NNS, QualType ObjectType,
4089  NamedDecl *FirstQualifierInScope) {
4091  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4092  Qualifier = Qualifier.getPrefix())
4093  Qualifiers.push_back(Qualifier);
4094 
4095  CXXScopeSpec SS;
4096  while (!Qualifiers.empty()) {
4097  NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4099 
4100  switch (QNNS->getKind()) {
4104  ObjectType);
4105  if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4106  SS, FirstQualifierInScope, false))
4107  return NestedNameSpecifierLoc();
4108  break;
4109  }
4110 
4111  case NestedNameSpecifier::Namespace: {
4112  NamespaceDecl *NS =
4113  cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4114  Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4115  SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4116  break;
4117  }
4118 
4119  case NestedNameSpecifier::NamespaceAlias: {
4120  NamespaceAliasDecl *Alias =
4121  cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4122  Q.getLocalBeginLoc(), QNNS->getAsNamespaceAlias()));
4123  SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4124  Q.getLocalEndLoc());
4125  break;
4126  }
4127 
4128  case NestedNameSpecifier::Global:
4129  // There is no meaningful transformation that one could perform on the
4130  // global scope.
4131  SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4132  break;
4133 
4134  case NestedNameSpecifier::Super: {
4135  CXXRecordDecl *RD =
4136  cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4137  SourceLocation(), QNNS->getAsRecordDecl()));
4138  SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4139  break;
4140  }
4141 
4142  case NestedNameSpecifier::TypeSpecWithTemplate:
4143  case NestedNameSpecifier::TypeSpec: {
4144  TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4145  FirstQualifierInScope, SS);
4146 
4147  if (!TL)
4148  return NestedNameSpecifierLoc();
4149 
4150  if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
4151  (SemaRef.getLangOpts().CPlusPlus11 &&
4152  TL.getType()->isEnumeralType())) {
4153  assert(!TL.getType().hasLocalQualifiers() &&
4154  "Can't get cv-qualifiers here");
4155  if (TL.getType()->isEnumeralType())
4156  SemaRef.Diag(TL.getBeginLoc(),
4157  diag::warn_cxx98_compat_enum_nested_name_spec);
4158  SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL,
4159  Q.getLocalEndLoc());
4160  break;
4161  }
4162  // If the nested-name-specifier is an invalid type def, don't emit an
4163  // error because a previous error should have already been emitted.
4164  TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
4165  if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4166  SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4167  << TL.getType() << SS.getRange();
4168  }
4169  return NestedNameSpecifierLoc();
4170  }
4171  }
4172 
4173  // The qualifier-in-scope and object type only apply to the leftmost entity.
4174  FirstQualifierInScope = nullptr;
4175  ObjectType = QualType();
4176  }
4177 
4178  // Don't rebuild the nested-name-specifier if we don't have to.
4179  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4180  !getDerived().AlwaysRebuild())
4181  return NNS;
4182 
4183  // If we can re-use the source-location data from the original
4184  // nested-name-specifier, do so.
4185  if (SS.location_size() == NNS.getDataLength() &&
4186  memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4187  return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
4188 
4189  // Allocate new nested-name-specifier location information.
4190  return SS.getWithLocInContext(SemaRef.Context);
4191 }
4192 
4193 template<typename Derived>
4197  DeclarationName Name = NameInfo.getName();
4198  if (!Name)
4199  return DeclarationNameInfo();
4200 
4201  switch (Name.getNameKind()) {
4203  case DeclarationName::ObjCZeroArgSelector:
4204  case DeclarationName::ObjCOneArgSelector:
4205  case DeclarationName::ObjCMultiArgSelector:
4206  case DeclarationName::CXXOperatorName:
4207  case DeclarationName::CXXLiteralOperatorName:
4208  case DeclarationName::CXXUsingDirective:
4209  return NameInfo;
4210 
4211  case DeclarationName::CXXDeductionGuideName: {
4212  TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4213  TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4214  getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4215  if (!NewTemplate)
4216  return DeclarationNameInfo();
4217 
4218  DeclarationNameInfo NewNameInfo(NameInfo);
4219  NewNameInfo.setName(
4220  SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4221  return NewNameInfo;
4222  }
4223 
4224  case DeclarationName::CXXConstructorName:
4225  case DeclarationName::CXXDestructorName:
4226  case DeclarationName::CXXConversionFunctionName: {
4227  TypeSourceInfo *NewTInfo;
4228  CanQualType NewCanTy;
4229  if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4230  NewTInfo = getDerived().TransformType(OldTInfo);
4231  if (!NewTInfo)
4232  return DeclarationNameInfo();
4233  NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4234  }
4235  else {
4236  NewTInfo = nullptr;
4237  TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4238  QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4239  if (NewT.isNull())
4240  return DeclarationNameInfo();
4241  NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4242  }
4243 
4244  DeclarationName NewName
4245  = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4246  NewCanTy);
4247  DeclarationNameInfo NewNameInfo(NameInfo);
4248  NewNameInfo.setName(NewName);
4249  NewNameInfo.setNamedTypeInfo(NewTInfo);
4250  return NewNameInfo;
4251  }
4252  }
4253 
4254  llvm_unreachable("Unknown name kind.");
4255 }
4256 
4257 template<typename Derived>
4260  TemplateName Name,
4261  SourceLocation NameLoc,
4262  QualType ObjectType,
4263  NamedDecl *FirstQualifierInScope,
4264  bool AllowInjectedClassName) {
4265  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4266  TemplateDecl *Template = QTN->getTemplateDecl();
4267  assert(Template && "qualified template name must refer to a template");
4268 
4269  TemplateDecl *TransTemplate
4270  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4271  Template));
4272  if (!TransTemplate)
4273  return TemplateName();
4274 
4275  if (!getDerived().AlwaysRebuild() &&
4276  SS.getScopeRep() == QTN->getQualifier() &&
4277  TransTemplate == Template)
4278  return Name;
4279 
4280  return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4281  TransTemplate);
4282  }
4283 
4284  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4285  if (SS.getScopeRep()) {
4286  // These apply to the scope specifier, not the template.
4287  ObjectType = QualType();
4288  FirstQualifierInScope = nullptr;
4289  }
4290 
4291  if (!getDerived().AlwaysRebuild() &&
4292  SS.getScopeRep() == DTN->getQualifier() &&
4293  ObjectType.isNull())
4294  return Name;
4295 
4296  // FIXME: Preserve the location of the "template" keyword.
4297  SourceLocation TemplateKWLoc = NameLoc;
4298 
4299  if (DTN->isIdentifier()) {
4300  return getDerived().RebuildTemplateName(SS,
4301  TemplateKWLoc,
4302  *DTN->getIdentifier(),
4303  NameLoc,
4304  ObjectType,
4305  FirstQualifierInScope,
4306  AllowInjectedClassName);
4307  }
4308 
4309  return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4310  DTN->getOperator(), NameLoc,
4311  ObjectType, AllowInjectedClassName);
4312  }
4313 
4314  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4315  TemplateDecl *TransTemplate
4316  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4317  Template));
4318  if (!TransTemplate)
4319  return TemplateName();
4320 
4321  if (!getDerived().AlwaysRebuild() &&
4322  TransTemplate == Template)
4323  return Name;
4324 
4325  return TemplateName(TransTemplate);
4326  }
4327 
4329  = Name.getAsSubstTemplateTemplateParmPack()) {
4330  TemplateTemplateParmDecl *TransParam
4331  = cast_or_null<TemplateTemplateParmDecl>(
4332  getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
4333  if (!TransParam)
4334  return TemplateName();
4335 
4336  if (!getDerived().AlwaysRebuild() &&
4337  TransParam == SubstPack->getParameterPack())
4338  return Name;
4339 
4340  return getDerived().RebuildTemplateName(TransParam,
4341  SubstPack->getArgumentPack());
4342  }
4343 
4344  // These should be getting filtered out before they reach the AST.
4345  llvm_unreachable("overloaded function decl survived to here");
4346 }
4347 
4348 template<typename Derived>
4350  const TemplateArgument &Arg,
4351  TemplateArgumentLoc &Output) {
4352  Output = getSema().getTrivialTemplateArgumentLoc(
4353  Arg, QualType(), getDerived().getBaseLocation());
4354 }
4355 
4356 template <typename Derived>
4358  const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4359  bool Uneval) {
4360  const TemplateArgument &Arg = Input.getArgument();
4361  switch (Arg.getKind()) {
4363  case TemplateArgument::Pack:
4364  llvm_unreachable("Unexpected TemplateArgument");
4365 
4366  case TemplateArgument::Integral:
4367  case TemplateArgument::NullPtr:
4368  case TemplateArgument::Declaration: {
4369  // Transform a resolved template argument straight to a resolved template
4370  // argument. We get here when substituting into an already-substituted
4371  // template type argument during concept satisfaction checking.
4373  QualType NewT = getDerived().TransformType(T);
4374  if (NewT.isNull())
4375  return true;
4376 
4377  ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration
4378  ? Arg.getAsDecl()
4379  : nullptr;
4380  ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4381  getDerived().getBaseLocation(), D))
4382  : nullptr;
4383  if (D && !NewD)
4384  return true;
4385 
4386  if (NewT == T && D == NewD)
4387  Output = Input;
4388  else if (Arg.getKind() == TemplateArgument::Integral)
4389  Output = TemplateArgumentLoc(
4390  TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4392  else if (Arg.getKind() == TemplateArgument::NullPtr)
4393  Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4395  else
4396  Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4398 
4399  return false;
4400  }
4401 
4402  case TemplateArgument::Type: {
4403  TypeSourceInfo *DI = Input.getTypeSourceInfo();
4404  if (!DI)
4405  DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4406 
4407  DI = getDerived().TransformType(DI);
4408  if (!DI)
4409  return true;
4410 
4411  Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4412  return false;
4413  }
4414 
4415  case TemplateArgument::Template: {
4416  NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4417  if (QualifierLoc) {
4418  QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4419  if (!QualifierLoc)
4420  return true;
4421  }
4422 
4423  CXXScopeSpec SS;
4424  SS.Adopt(QualifierLoc);
4425  TemplateName Template = getDerived().TransformTemplateName(
4426  SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4427  if (Template.isNull())
4428  return true;
4429 
4430  Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4431  QualifierLoc, Input.getTemplateNameLoc());
4432  return false;
4433  }
4434 
4435  case TemplateArgument::TemplateExpansion:
4436  llvm_unreachable("Caller should expand pack expansions");
4437 
4438  case TemplateArgument::Expression: {
4439  // Template argument expressions are constant expressions.
4441  getSema(),
4442  Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
4443  : Sema::ExpressionEvaluationContext::ConstantEvaluated,
4444  /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4445  Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
4446 
4447  Expr *InputExpr = Input.getSourceExpression();
4448  if (!InputExpr)
4449  InputExpr = Input.getArgument().getAsExpr();
4450 
4451  ExprResult E = getDerived().TransformExpr(InputExpr);
4452  E = SemaRef.ActOnConstantExpression(E);
4453  if (E.isInvalid())
4454  return true;
4455  Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4456  return false;
4457  }
4458  }
4459 
4460  // Work around bogus GCC warning
4461  return true;
4462 }
4463 
4464 /// Iterator adaptor that invents template argument location information
4465 /// for each of the template arguments in its underlying iterator.
4466 template<typename Derived, typename InputIterator>
4468  TreeTransform<Derived> &Self;
4469  InputIterator Iter;
4470 
4471 public:
4474  typedef typename std::iterator_traits<InputIterator>::difference_type
4476  typedef std::input_iterator_tag iterator_category;
4477 
4478  class pointer {
4479  TemplateArgumentLoc Arg;
4480 
4481  public:
4482  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4483 
4484  const TemplateArgumentLoc *operator->() const { return &Arg; }
4485  };
4486 
4488 
4490  InputIterator Iter)
4491  : Self(Self), Iter(Iter) { }
4492 
4494  ++Iter;
4495  return *this;
4496  }
4497 
4500  ++(*this);
4501  return Old;
4502  }
4503 
4505  TemplateArgumentLoc Result;
4506  Self.InventTemplateArgumentLoc(*Iter, Result);
4507  return Result;
4508  }
4509 
4510  pointer operator->() const { return pointer(**this); }
4511 
4514  return X.Iter == Y.Iter;
4515  }
4516 
4519  return X.Iter != Y.Iter;
4520  }
4521 };
4522 
4523 template<typename Derived>
4524 template<typename InputIterator>
4526  InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4527  bool Uneval) {
4528  for (; First != Last; ++First) {
4529  TemplateArgumentLoc Out;
4530  TemplateArgumentLoc In = *First;
4531 
4532  if (In.getArgument().getKind() == TemplateArgument::Pack) {
4533  // Unpack argument packs, which we translate them into separate
4534  // arguments.
4535  // FIXME: We could do much better if we could guarantee that the
4536  // TemplateArgumentLocInfo for the pack expansion would be usable for
4537  // all of the template arguments in the argument pack.
4538  typedef TemplateArgumentLocInventIterator<Derived,
4540  PackLocIterator;
4541  if (TransformTemplateArguments(PackLocIterator(*this,
4542  In.getArgument().pack_begin()),
4543  PackLocIterator(*this,
4544  In.getArgument().pack_end()),
4545  Outputs, Uneval))
4546  return true;
4547 
4548  continue;
4549  }
4550 
4551  if (In.getArgument().isPackExpansion()) {
4552  // We have a pack expansion, for which we will be substituting into
4553  // the pattern.
4554  SourceLocation Ellipsis;
4555  Optional<unsigned> OrigNumExpansions;
4556  TemplateArgumentLoc Pattern
4557  = getSema().getTemplateArgumentPackExpansionPattern(
4558  In, Ellipsis, OrigNumExpansions);
4559 
4561  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4562  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4563 
4564  // Determine whether the set of unexpanded parameter packs can and should
4565  // be expanded.
4566  bool Expand = true;
4567  bool RetainExpansion = false;
4568  Optional<unsigned> NumExpansions = OrigNumExpansions;
4569  if (getDerived().TryExpandParameterPacks(Ellipsis,
4570  Pattern.getSourceRange(),
4571  Unexpanded,
4572  Expand,
4573  RetainExpansion,
4574  NumExpansions))
4575  return true;
4576 
4577  if (!Expand) {
4578  // The transform has determined that we should perform a simple
4579  // transformation on the pack expansion, producing another pack
4580  // expansion.
4581  TemplateArgumentLoc OutPattern;
4582  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4583  if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4584  return true;
4585 
4586  Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4587  NumExpansions);
4588  if (Out.getArgument().isNull())
4589  return true;
4590 
4591  Outputs.addArgument(Out);
4592  continue;
4593  }
4594 
4595  // The transform has determined that we should perform an elementwise
4596  // expansion of the pattern. Do so.
4597  for (unsigned I = 0; I != *NumExpansions; ++I) {
4598  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4599 
4600  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4601  return true;
4602 
4604  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4605  OrigNumExpansions);
4606  if (Out.getArgument().isNull())
4607  return true;
4608  }
4609 
4610  Outputs.addArgument(Out);
4611  }
4612 
4613  // If we're supposed to retain a pack expansion, do so by temporarily
4614  // forgetting the partially-substituted parameter pack.
4615  if (RetainExpansion) {
4616  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4617 
4618  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4619  return true;
4620 
4621  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4622  OrigNumExpansions);
4623  if (Out.getArgument().isNull())
4624  return true;
4625 
4626  Outputs.addArgument(Out);
4627  }
4628 
4629  continue;
4630  }
4631 
4632  // The simple case:
4633  if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4634  return true;
4635 
4636  Outputs.addArgument(Out);
4637  }
4638 
4639  return false;
4640 
4641 }
4642 
4643 //===----------------------------------------------------------------------===//
4644 // Type transformation
4645 //===----------------------------------------------------------------------===//
4646 
4647 template<typename Derived>
4649  if (getDerived().AlreadyTransformed(T))
4650  return T;
4651 
4652  // Temporary workaround. All of these transformations should
4653  // eventually turn into transformations on TypeLocs.
4654  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4655  getDerived().getBaseLocation());
4656 
4657  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4658 
4659  if (!NewDI)
4660  return QualType();
4661 
4662  return NewDI->getType();
4663 }
4664 
4665 template<typename Derived>
4667  // Refine the base location to the type's location.
4668  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4669  getDerived().getBaseEntity());
4670  if (getDerived().AlreadyTransformed(DI->getType()))
4671  return DI;
4672 
4673  TypeLocBuilder TLB;
4674 
4675  TypeLoc TL = DI->getTypeLoc();
4676  TLB.reserve(TL.getFullDataSize());
4677 
4678  QualType Result = getDerived().TransformType(TLB, TL);
4679  if (Result.isNull())
4680  return nullptr;
4681 
4682  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4683 }
4684 
4685 template<typename Derived>
4686 QualType
4688  switch (T.getTypeLocClass()) {
4689 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4690 #define TYPELOC(CLASS, PARENT) \
4691  case TypeLoc::CLASS: \
4692  return getDerived().Transform##CLASS##Type(TLB, \
4693  T.castAs<CLASS##TypeLoc>());
4694 #include "clang/AST/TypeLocNodes.def"
4695  }
4696 
4697  llvm_unreachable("unhandled type loc!");
4698 }
4699 
4700 template<typename Derived>
4702  if (!isa<DependentNameType>(T))
4703  return TransformType(T);
4704 
4705  if (getDerived().AlreadyTransformed(T))
4706  return T;
4707  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4708  getDerived().getBaseLocation());
4709  TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4710  return NewDI ? NewDI->getType() : QualType();
4711 }
4712 
4713 template<typename Derived>
4716  if (!isa<DependentNameType>(DI->getType()))
4717  return TransformType(DI);
4718 
4719  // Refine the base location to the type's location.
4720  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4721  getDerived().getBaseEntity());
4722  if (getDerived().AlreadyTransformed(DI->getType()))
4723  return DI;
4724 
4725  TypeLocBuilder TLB;
4726 
4727  TypeLoc TL = DI->getTypeLoc();
4728  TLB.reserve(TL.getFullDataSize());
4729 
4730  auto QTL = TL.getAs<QualifiedTypeLoc>();
4731  if (QTL)
4732  TL = QTL.getUnqualifiedLoc();
4733 
4734  auto DNTL = TL.castAs<DependentNameTypeLoc>();
4735 
4736  QualType Result = getDerived().TransformDependentNameType(
4737  TLB, DNTL, /*DeducedTSTContext*/true);
4738  if (Result.isNull())
4739  return nullptr;
4740 
4741  if (QTL) {
4742  Result = getDerived().RebuildQualifiedType(Result, QTL);
4743  if (Result.isNull())
4744  return nullptr;
4745  TLB.TypeWasModifiedSafely(Result);
4746  }
4747 
4748  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4749 }
4750 
4751 template<typename Derived>
4752 QualType
4754  QualifiedTypeLoc T) {
4755  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4756  if (Result.isNull())
4757  return QualType();
4758 
4759  Result = getDerived().RebuildQualifiedType(Result, T);
4760 
4761  if (Result.isNull())
4762  return QualType();
4763 
4764  // RebuildQualifiedType might have updated the type, but not in a way
4765  // that invalidates the TypeLoc. (There's no location information for
4766  // qualifiers.)
4767  TLB.TypeWasModifiedSafely(Result);
4768 
4769  return Result;
4770 }
4771 
4772 template <typename Derived>
4774  QualifiedTypeLoc TL) {
4775 
4776  SourceLocation Loc = TL.getBeginLoc();
4777  Qualifiers Quals = TL.getType().getLocalQualifiers();
4778 
4779  if ((T.getAddressSpace() != LangAS::Default &&
4780  Quals.getAddressSpace() != LangAS::Default) &&
4781  T.getAddressSpace() != Quals.getAddressSpace()) {
4782  SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4783  << TL.getType() << T;
4784  return QualType();
4785  }
4786 
4787  // C++ [dcl.fct]p7:
4788  // [When] adding cv-qualifications on top of the function type [...] the
4789  // cv-qualifiers are ignored.
4790  if (T->isFunctionType()) {
4791  T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4792  Quals.getAddressSpace());
4793  return T;
4794  }
4795 
4796  // C++ [dcl.ref]p1:
4797  // when the cv-qualifiers are introduced through the use of a typedef-name
4798  // or decltype-specifier [...] the cv-qualifiers are ignored.
4799  // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4800  // applied to a reference type.
4801  if (T->isReferenceType()) {
4802  // The only qualifier that applies to a reference type is restrict.
4803  if (!Quals.hasRestrict())
4804  return T;
4805  Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4806  }
4807 
4808  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4809  // resulting type.
4810  if (Quals.hasObjCLifetime()) {
4811  if (!T->isObjCLifetimeType() && !T->isDependentType())
4812  Quals.removeObjCLifetime();
4813  else if (T.getObjCLifetime()) {
4814  // Objective-C ARC:
4815  // A lifetime qualifier applied to a substituted template parameter
4816  // overrides the lifetime qualifier from the template argument.
4817  const AutoType *AutoTy;
4818  if (const SubstTemplateTypeParmType *SubstTypeParam
4819  = dyn_cast<SubstTemplateTypeParmType>(T)) {
4820  QualType Replacement = SubstTypeParam->getReplacementType();
4821  Qualifiers Qs = Replacement.getQualifiers();
4822  Qs.removeObjCLifetime();
4823  Replacement = SemaRef.Context.getQualifiedType(
4824  Replacement.getUnqualifiedType(), Qs);
4826  SubstTypeParam->getReplacedParameter(), Replacement);
4827  } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4828  // 'auto' types behave the same way as template parameters.
4829  QualType Deduced = AutoTy->getDeducedType();
4830  Qualifiers Qs = Deduced.getQualifiers();
4831  Qs.removeObjCLifetime();
4832  Deduced =
4833  SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4834  T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4835  AutoTy->isDependentType(),
4836  /*isPack=*/false,
4837  AutoTy->getTypeConstraintConcept(),
4838  AutoTy->getTypeConstraintArguments());
4839  } else {
4840  // Otherwise, complain about the addition of a qualifier to an
4841  // already-qualified type.
4842  // FIXME: Why is this check not in Sema::BuildQualifiedType?
4843  SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4844  Quals.removeObjCLifetime();
4845  }
4846  }
4847  }
4848 
4849  return SemaRef.BuildQualifiedType(T, Loc, Quals);
4850 }
4851 
4852 template<typename Derived>
4853 TypeLoc
4855  QualType ObjectType,
4856  NamedDecl *UnqualLookup,
4857  CXXScopeSpec &SS) {
4858  if (getDerived().AlreadyTransformed(TL.getType()))
4859  return TL;
4860 
4861  TypeSourceInfo *TSI =
4862  TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4863  if (TSI)
4864  return TSI->getTypeLoc();
4865  return TypeLoc();
4866 }
4867 
4868 template<typename Derived>
4869 TypeSourceInfo *
4870 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4871  QualType ObjectType,
4872  NamedDecl *UnqualLookup,
4873  CXXScopeSpec &SS) {
4874  if (getDerived().AlreadyTransformed(TSInfo->getType()))
4875  return TSInfo;
4876 
4877  return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4878  UnqualLookup, SS);
4879 }
4880 
4881 template <typename Derived>
4882 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4883  TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4884  CXXScopeSpec &SS) {
4885  QualType T = TL.getType();
4886  assert(!getDerived().AlreadyTransformed(T));
4887 
4888  TypeLocBuilder TLB;
4889  QualType Result;
4890 
4891  if (isa<TemplateSpecializationType>(T)) {
4892  TemplateSpecializationTypeLoc SpecTL =
4893  TL.castAs<TemplateSpecializationTypeLoc>();
4894 
4895  TemplateName Template = getDerived().TransformTemplateName(
4896  SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4897  ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4898  if (Template.isNull())
4899  return nullptr;
4900 
4901  Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4902  Template);
4903  } else if (isa<DependentTemplateSpecializationType>(T)) {
4904  DependentTemplateSpecializationTypeLoc SpecTL =
4905  TL.castAs<DependentTemplateSpecializationTypeLoc>();
4906 
4907  TemplateName Template
4908  = getDerived().RebuildTemplateName(SS,
4909  SpecTL.getTemplateKeywordLoc(),
4910  *SpecTL.getTypePtr()->getIdentifier(),
4911  SpecTL.getTemplateNameLoc(),
4912  ObjectType, UnqualLookup,
4913  /*AllowInjectedClassName*/true);
4914  if (Template.isNull())
4915  return nullptr;
4916 
4917  Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4918  SpecTL,
4919  Template,
4920  SS);
4921  } else {
4922  // Nothing special needs to be done for these.
4923  Result = getDerived().TransformType(TLB, TL);
4924  }
4925 
4926  if (Result.isNull())
4927  return nullptr;
4928 
4929  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4930 }
4931 
4932 template <class TyLoc> static inline
4934  TyLoc NewT = TLB.push<TyLoc>(T.getType());
4935  NewT.setNameLoc(T.getNameLoc());
4936  return T.getType();
4937 }
4938 
4939 template<typename Derived>
4940 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4941  BuiltinTypeLoc T) {
4942  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4943  NewT.setBuiltinLoc(T.getBuiltinLoc());
4944  if (T.needsExtraLocalData())
4945  NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4946  return T.getType();
4947 }
4948 
4949 template<typename Derived>
4950 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4951  ComplexTypeLoc T) {
4952  // FIXME: recurse?
4953  return TransformTypeSpecType(TLB, T);
4954 }
4955 
4956 template <typename Derived>
4957 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4958  AdjustedTypeLoc TL) {
4959  // Adjustments applied during transformation are handled elsewhere.
4960  return getDerived().TransformType(TLB, TL.getOriginalLoc());
4961 }
4962 
4963 template<typename Derived>
4964 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4965  DecayedTypeLoc TL) {
4966  QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4967  if (OriginalType.isNull())
4968  return QualType();
4969 
4970  QualType Result = TL.getType();
4971  if (getDerived().AlwaysRebuild() ||
4972  OriginalType != TL.getOriginalLoc().getType())
4973  Result = SemaRef.Context.getDecayedType(OriginalType);
4974  TLB.push<DecayedTypeLoc>(Result);
4975  // Nothing to set for DecayedTypeLoc.
4976  return Result;
4977 }
4978 
4979 template<typename Derived>
4980 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4981  PointerTypeLoc TL) {
4982  QualType PointeeType
4983  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4984  if (PointeeType.isNull())
4985  return QualType();
4986 
4987  QualType Result = TL.getType();
4988  if (PointeeType->getAs<ObjCObjectType>()) {
4989  // A dependent pointer type 'T *' has is being transformed such
4990  // that an Objective-C class type is being replaced for 'T'. The
4991  // resulting pointer type is an ObjCObjectPointerType, not a
4992  // PointerType.
4993  Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4994 
4995  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4996  NewT.setStarLoc(TL.getStarLoc());
4997  return Result;
4998  }
4999 
5000  if (getDerived().AlwaysRebuild() ||
5001  PointeeType != TL.getPointeeLoc().getType()) {
5002  Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5003  if (Result.isNull())
5004  return QualType();
5005  }
5006 
5007  // Objective-C ARC can add lifetime qualifiers to the type that we're
5008  // pointing to.
5009  TLB.TypeWasModifiedSafely(Result->getPointeeType());
5010 
5011  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5012  NewT.setSigilLoc(TL.getSigilLoc());
5013  return Result;
5014 }
5015 
5016 template<typename Derived>
5017 QualType
5018 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5019  BlockPointerTypeLoc TL) {
5020  QualType PointeeType
5021  = getDerived().TransformType(TLB, TL.getPointeeLoc());
5022  if (PointeeType.isNull())
5023  return QualType();
5024 
5025  QualType Result = TL.getType();
5026  if (getDerived().AlwaysRebuild() ||
5027  PointeeType != TL.getPointeeLoc().getType()) {
5028  Result = getDerived().RebuildBlockPointerType(PointeeType,
5029  TL.getSigilLoc());
5030  if (Result.isNull())
5031  return QualType();
5032  }
5033 
5034  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5035  NewT.setSigilLoc(TL.getSigilLoc());
5036  return Result;
5037 }
5038 
5039 /// Transforms a reference type. Note that somewhat paradoxically we
5040 /// don't care whether the type itself is an l-value type or an r-value
5041 /// type; we only care if the type was *written* as an l-value type
5042 /// or an r-value type.
5043 template<typename Derived>
5044 QualType
5046  ReferenceTypeLoc TL) {
5047  const ReferenceType *T = TL.getTypePtr();
5048 
5049  // Note that this works with the pointee-as-written.
5050  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5051  if (PointeeType.isNull())
5052  return QualType();
5053 
5054  QualType Result = TL.getType();
5055  if (getDerived().AlwaysRebuild() ||
5056  PointeeType != T->getPointeeTypeAsWritten()) {
5057  Result = getDerived().RebuildReferenceType(PointeeType,
5058  T->isSpelledAsLValue(),
5059  TL.getSigilLoc());
5060  if (Result.isNull())
5061  return QualType();
5062  }
5063 
5064  // Objective-C ARC can add lifetime qualifiers to the type that we're
5065  // referring to.
5067  Result->castAs<ReferenceType>()->getPointeeTypeAsWritten());
5068 
5069  // r-value references can be rebuilt as l-value references.
5070  ReferenceTypeLoc NewTL;
5071  if (isa<LValueReferenceType>(Result))
5072  NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5073  else
5074  NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5075  NewTL.setSigilLoc(TL.getSigilLoc());
5076 
5077  return Result;
5078 }
5079 
5080 template<typename Derived>
5081 QualType
5084  return TransformReferenceType(TLB, TL);
5085 }
5086 
5087 template<typename Derived>
5088 QualType
5089 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5090  RValueReferenceTypeLoc TL) {
5091  return TransformReferenceType(TLB, TL);
5092 }
5093 
5094 template<typename Derived>
5095 QualType
5096 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5097  MemberPointerTypeLoc TL) {
5098  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5099  if (PointeeType.isNull())
5100  return QualType();
5101 
5102  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5103  TypeSourceInfo *NewClsTInfo = nullptr;
5104  if (OldClsTInfo) {
5105  NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5106  if (!NewClsTInfo)
5107  return QualType();
5108  }
5109 
5110  const MemberPointerType *T = TL.getTypePtr();
5111  QualType OldClsType = QualType(T->getClass(), 0);
5112  QualType NewClsType;
5113  if (NewClsTInfo)
5114  NewClsType = NewClsTInfo->getType();
5115  else {
5116  NewClsType = getDerived().TransformType(OldClsType);
5117  if (NewClsType.isNull())
5118  return QualType();
5119  }
5120 
5121  QualType Result = TL.getType();
5122  if (getDerived().AlwaysRebuild() ||
5123  PointeeType != T->getPointeeType() ||
5124  NewClsType != OldClsType) {
5125  Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5126  TL.getStarLoc());
5127  if (Result.isNull())
5128  return QualType();
5129  }
5130 
5131  // If we had to adjust the pointee type when building a member pointer, make
5132  // sure to push TypeLoc info for it.
5133  const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5134  if (MPT && PointeeType != MPT->getPointeeType()) {
5135  assert(isa<AdjustedType>(MPT->getPointeeType()));
5136  TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5137  }
5138 
5139  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5140  NewTL.setSigilLoc(TL.getSigilLoc());
5141  NewTL.setClassTInfo(NewClsTInfo);
5142 
5143  return Result;
5144 }
5145 
5146 template<typename Derived>
5147 QualType
5148 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5149  ConstantArrayTypeLoc TL) {
5150  const ConstantArrayType *T = TL.getTypePtr();
5151  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5152  if (ElementType.isNull())
5153  return QualType();
5154 
5155  // Prefer the expression from the TypeLoc; the other may have been uniqued.
5156  Expr *OldSize = TL.getSizeExpr();
5157  if (!OldSize)
5158  OldSize = const_cast<Expr*>(T->getSizeExpr());
5159  Expr *NewSize = nullptr;
5160  if (OldSize) {
5161  EnterExpressionEvaluationContext Unevaluated(
5162  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5163  NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5164  NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5165  }
5166 
5167  QualType Result = TL.getType();
5168  if (getDerived().AlwaysRebuild() ||
5169  ElementType != T->getElementType() ||
5170  (T->getSizeExpr() && NewSize != OldSize)) {
5171  Result = getDerived().RebuildConstantArrayType(ElementType,
5172  T->getSizeModifier(),
5173  T->getSize(), NewSize,
5174  T->getIndexTypeCVRQualifiers(),
5175  TL.getBracketsRange());
5176  if (Result.isNull())
5177  return QualType();
5178  }
5179 
5180  // We might have either a ConstantArrayType or a VariableArrayType now:
5181  // a ConstantArrayType is allowed to have an element type which is a
5182  // VariableArrayType if the type is dependent. Fortunately, all array
5183  // types have the same location layout.
5184  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5185  NewTL.setLBracketLoc(TL.getLBracketLoc());
5186  NewTL.setRBracketLoc(TL.getRBracketLoc());
5187  NewTL.setSizeExpr(NewSize);
5188 
5189  return Result;
5190 }
5191 
5192 template<typename Derived>
5193 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5194  TypeLocBuilder &TLB,
5195  IncompleteArrayTypeLoc TL) {
5196  const IncompleteArrayType *T = TL.getTypePtr();
5197  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5198  if (ElementType.isNull())
5199  return QualType();
5200 
5201  QualType Result = TL.getType();
5202  if (getDerived().AlwaysRebuild() ||
5203  ElementType != T->getElementType()) {
5204  Result = getDerived().RebuildIncompleteArrayType(ElementType,
5205  T->getSizeModifier(),
5206  T->getIndexTypeCVRQualifiers(),
5207  TL.getBracketsRange());
5208  if (Result.isNull())
5209  return QualType();
5210  }
5211 
5212  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5213  NewTL.setLBracketLoc(TL.getLBracketLoc());
5214  NewTL.setRBracketLoc(TL.getRBracketLoc());
5215  NewTL.setSizeExpr(nullptr);
5216 
5217  return Result;
5218 }
5219 
5220 template<typename Derived>
5221 QualType
5222 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5223  VariableArrayTypeLoc TL) {
5224  const VariableArrayType *T = TL.getTypePtr();
5225  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5226  if (ElementType.isNull())
5227  return QualType();
5228 
5229  ExprResult SizeResult;
5230  {
5231  EnterExpressionEvaluationContext Context(
5232  SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
5233  SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5234  }
5235  if (SizeResult.isInvalid())
5236  return QualType();
5237  SizeResult =
5238  SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5239  if (SizeResult.isInvalid())
5240  return QualType();
5241 
5242  Expr *Size = SizeResult.get();
5243 
5244  QualType Result = TL.getType();
5245  if (getDerived().AlwaysRebuild() ||
5246  ElementType != T->getElementType() ||
5247  Size != T->getSizeExpr()) {
5248  Result = getDerived().RebuildVariableArrayType(ElementType,
5249  T->getSizeModifier(),
5250  Size,
5251  T->getIndexTypeCVRQualifiers(),
5252  TL.getBracketsRange());
5253  if (Result.isNull())
5254  return QualType();
5255  }
5256 
5257  // We might have constant size array now, but fortunately it has the same
5258  // location layout.
5259  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5260  NewTL.setLBracketLoc(TL.getLBracketLoc());
5261  NewTL.setRBracketLoc(TL.getRBracketLoc());
5262  NewTL.setSizeExpr(Size);
5263 
5264  return Result;
5265 }
5266 
5267 template<typename Derived>
5268 QualType
5269 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5270  DependentSizedArrayTypeLoc TL) {
5271  const DependentSizedArrayType *T = TL.getTypePtr();
5272  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5273  if (ElementType.isNull())
5274  return QualType();
5275 
5276  // Array bounds are constant expressions.
5277  EnterExpressionEvaluationContext Unevaluated(
5278  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5279 
5280  // Prefer the expression from the TypeLoc; the other may have been uniqued.
5281  Expr *origSize = TL.getSizeExpr();
5282  if (!origSize) origSize = T->getSizeExpr();
5283 
5284  ExprResult sizeResult
5285  = getDerived().TransformExpr(origSize);
5286  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5287  if (sizeResult.isInvalid())
5288  return QualType();
5289 
5290  Expr *size = sizeResult.get();
5291 
5292  QualType Result = TL.getType();
5293  if (getDerived().AlwaysRebuild() ||
5294  ElementType != T->getElementType() ||
5295  size != origSize) {
5296  Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5297  T->getSizeModifier(),
5298  size,
5299  T->getIndexTypeCVRQualifiers(),
5300  TL.getBracketsRange());
5301  if (Result.isNull())
5302  return QualType();
5303  }
5304 
5305  // We might have any sort of array type now, but fortunately they
5306  // all have the same location layout.
5307  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5308  NewTL.setLBracketLoc(TL.getLBracketLoc());
5309  NewTL.setRBracketLoc(TL.getRBracketLoc());
5310  NewTL.setSizeExpr(size);
5311 
5312  return Result;
5313 }
5314 
5315 template <typename Derived>
5316 QualType TreeTransform<Derived>::TransformDependentVectorType(
5317  TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5318  const DependentVectorType *T = TL.getTypePtr();
5319  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5320  if (ElementType.isNull())
5321  return QualType();
5322 
5323  EnterExpressionEvaluationContext Unevaluated(
5324  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5325 
5326  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5327  Size = SemaRef.ActOnConstantExpression(Size);
5328  if (Size.isInvalid())
5329  return QualType();
5330 
5331  QualType Result = TL.getType();
5332  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5333  Size.get() != T->getSizeExpr()) {
5334  Result = getDerived().RebuildDependentVectorType(
5335  ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5336  if (Result.isNull())
5337  return QualType();
5338  }
5339 
5340  // Result might be dependent or not.
5341  if (isa<DependentVectorType>(Result)) {
5342  DependentVectorTypeLoc NewTL =
5343  TLB.push<DependentVectorTypeLoc>(Result);
5344  NewTL.setNameLoc(TL.getNameLoc());
5345  } else {
5346  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5347  NewTL.setNameLoc(TL.getNameLoc());
5348  }
5349 
5350  return Result;
5351 }
5352 
5353 template<typename Derived>
5354 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5355  TypeLocBuilder &TLB,
5356  DependentSizedExtVectorTypeLoc TL) {
5357  const DependentSizedExtVectorType *T = TL.getTypePtr();
5358 
5359  // FIXME: ext vector locs should be nested
5360  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5361  if (ElementType.isNull())
5362  return QualType();
5363 
5364  // Vector sizes are constant expressions.
5365  EnterExpressionEvaluationContext Unevaluated(
5366  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5367 
5368  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5369  Size = SemaRef.ActOnConstantExpression(Size);
5370  if (Size.isInvalid())
5371  return QualType();
5372 
5373  QualType Result = TL.getType();
5374  if (getDerived().AlwaysRebuild() ||
5375  ElementType != T->getElementType() ||
5376  Size.get() != T->getSizeExpr()) {
5377  Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5378  Size.get(),
5379  T->getAttributeLoc());
5380  if (Result.isNull())
5381  return QualType();
5382  }
5383 
5384  // Result might be dependent or not.
5385  if (isa<DependentSizedExtVectorType>(Result)) {
5386  DependentSizedExtVectorTypeLoc NewTL
5387  = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5388  NewTL.setNameLoc(TL.getNameLoc());
5389  } else {
5390  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5391  NewTL.setNameLoc(TL.getNameLoc());
5392  }
5393 
5394  return Result;
5395 }
5396 
5397 template <typename Derived>
5398 QualType
5399 TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5400  ConstantMatrixTypeLoc TL) {
5401  const ConstantMatrixType *T = TL.getTypePtr();
5402  QualType ElementType = getDerived().TransformType(T->getElementType());
5403  if (ElementType.isNull())
5404  return QualType();
5405 
5406  QualType Result = TL.getType();
5407  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5408  Result = getDerived().RebuildConstantMatrixType(
5409  ElementType, T->getNumRows(), T->getNumColumns());
5410  if (Result.isNull())
5411  return QualType();
5412  }
5413 
5414  ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5415  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5416  NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5417  NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5418  NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5419 
5420  return Result;
5421 }
5422 
5423 template <typename Derived>
5424 QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5425  TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5426  const DependentSizedMatrixType *T = TL.getTypePtr();
5427 
5428  QualType ElementType = getDerived().TransformType(T->getElementType());
5429  if (ElementType.isNull()) {
5430  return QualType();
5431  }
5432 
5433  // Matrix dimensions are constant expressions.
5434  EnterExpressionEvaluationContext Unevaluated(
5435  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5436 
5437  Expr *origRows = TL.getAttrRowOperand();
5438  if (!origRows)
5439  origRows = T->getRowExpr();
5440  Expr *origColumns = TL.getAttrColumnOperand();
5441  if (!origColumns)
5442  origColumns = T->getColumnExpr();
5443 
5444  ExprResult rowResult = getDerived().TransformExpr(origRows);
5445  rowResult = SemaRef.ActOnConstantExpression(rowResult);
5446  if (rowResult.isInvalid())
5447  return QualType();
5448 
5449  ExprResult columnResult = getDerived().TransformExpr(origColumns);
5450  columnResult = SemaRef.ActOnConstantExpression(columnResult);
5451  if (columnResult.isInvalid())
5452  return QualType();
5453 
5454  Expr *rows = rowResult.get();
5455  Expr *columns = columnResult.get();
5456 
5457  QualType Result = TL.getType();
5458  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5459  rows != origRows || columns != origColumns) {
5460  Result = getDerived().RebuildDependentSizedMatrixType(
5461  ElementType, rows, columns, T->getAttributeLoc());
5462 
5463  if (Result.isNull())
5464  return QualType();
5465  }
5466 
5467  // We might have any sort of matrix type now, but fortunately they
5468  // all have the same location layout.
5469  MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5470  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5471  NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5472  NewTL.setAttrRowOperand(rows);
5473  NewTL.setAttrColumnOperand(columns);
5474  return Result;
5475 }
5476 
5477 template <typename Derived>
5478 QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5479  TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5480  const DependentAddressSpaceType *T = TL.getTypePtr();
5481 
5482  QualType pointeeType = getDerived().TransformType(T->getPointeeType());
5483 
5484  if (pointeeType.isNull())
5485  return QualType();
5486 
5487  // Address spaces are constant expressions.
5488  EnterExpressionEvaluationContext Unevaluated(
5489  SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5490 
5491  ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5492  AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5493  if (AddrSpace.isInvalid())
5494  return QualType();
5495 
5496  QualType Result = TL.getType();
5497  if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5498  AddrSpace.get() != T->getAddrSpaceExpr()) {
5499  Result = getDerived().RebuildDependentAddressSpaceType(
5500  pointeeType, AddrSpace.get(), T->getAttributeLoc());
5501  if (Result.isNull())
5502  return QualType();
5503  }
5504 
5505  // Result might be dependent or not.
5506  if (isa<DependentAddressSpaceType>(Result)) {
5507  DependentAddressSpaceTypeLoc NewTL =
5508  TLB.push<DependentAddressSpaceTypeLoc>(Result);
5509 
5510  NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5511  NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5512  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5513 
5514  } else {
5515  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5516  Result, getDerived().getBaseLocation());
5517  TransformType(TLB, DI->getTypeLoc());
5518  }
5519 
5520  return Result;
5521 }
5522 
5523 template <typename Derived>
5524 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5525  VectorTypeLoc TL) {
5526  const VectorType *T = TL.getTypePtr();
5527  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5528  if (ElementType.isNull())
5529  return QualType();
5530 
5531  QualType Result = TL.getType();
5532  if (getDerived().AlwaysRebuild() ||
5533  ElementType != T->getElementType()) {
5534  Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
5535  T->getVectorKind());
5536  if (Result.isNull())
5537  return QualType();
5538  }
5539 
5540  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5541  NewTL.setNameLoc(TL.getNameLoc());
5542 
5543  return Result;
5544 }
5545 
5546 template<typename Derived>
5547 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
5548  ExtVectorTypeLoc TL) {
5549  const VectorType *T = TL.getTypePtr();
5550  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5551  if (ElementType.isNull())
5552  return QualType();
5553 
5554  QualType Result = TL.getType();
5555  if (getDerived().AlwaysRebuild() ||
5556  ElementType != T->getElementType()) {
5557  Result = getDerived().RebuildExtVectorType(ElementType,
5558  T->getNumElements(),
5559  /*FIXME*/ SourceLocation());
5560  if (Result.isNull())
5561  return QualType();
5562  }
5563 
5564  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5565  NewTL.setNameLoc(TL.getNameLoc());
5566 
5567  return Result;
5568 }
5569 
5570 template <typename Derived>
5572  ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5573  bool ExpectParameterPack) {
5574  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
5575  TypeSourceInfo *NewDI = nullptr;
5576 
5577  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
5578  // If we're substituting into a pack expansion type and we know the
5579  // length we want to expand to, just substitute for the pattern.
5580  TypeLoc OldTL = OldDI->getTypeLoc();
5581  PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
5582 
5583  TypeLocBuilder TLB;
5584  TypeLoc NewTL = OldDI->getTypeLoc();
5585  TLB.reserve(NewTL.getFullDataSize());
5586 
5587  QualType Result = getDerived().TransformType(TLB,
5588  OldExpansionTL.getPatternLoc());
5589  if (Result.isNull())
5590  return nullptr;
5591 
5592  Result = RebuildPackExpansionType(Result,
5593  OldExpansionTL.getPatternLoc().getSourceRange(),
5594  OldExpansionTL.getEllipsisLoc(),
5595  NumExpansions);
5596  if (Result.isNull())
5597  return nullptr;
5598 
5599  PackExpansionTypeLoc NewExpansionTL
5600  = TLB.push<PackExpansionTypeLoc>(Result);
5601  NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5602  NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5603  } else
5604  NewDI = getDerived().TransformType(OldDI);
5605  if (!NewDI)
5606  return nullptr;
5607 
5608  if (NewDI == OldDI && indexAdjustment == 0)
5609  return OldParm;
5610 
5611  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5612  OldParm->getDeclContext(),
5613  OldParm->getInnerLocStart(),
5614  OldParm->getLocation(),
5615  OldParm->getIdentifier(),
5616  NewDI->getType(),
5617  NewDI,
5618  OldParm->getStorageClass(),
5619  /* DefArg */ nullptr);
5620  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5621  OldParm->getFunctionScopeIndex() + indexAdjustment);
5622  transformedLocalDecl(OldParm, {newParm});
5623  return newParm;
5624 }
5625 
5626 template <typename Derived>
5629  const QualType *ParamTypes,
5630  const FunctionProtoType::ExtParameterInfo *ParamInfos,
5631  SmallVectorImpl<QualType> &OutParamTypes,
5634  int indexAdjustment = 0;
5635 
5636  unsigned NumParams = Params.size();
5637  for (unsigned i = 0; i != NumParams; ++i) {
5638  if (ParmVarDecl *OldParm = Params[i]) {
5639  assert(OldParm->getFunctionScopeIndex() == i);
5640 
5641  Optional<unsigned> NumExpansions;
5642  ParmVarDecl *NewParm = nullptr;
5643  if (OldParm->isParameterPack()) {
5644  // We have a function parameter pack that may need to be expanded.
5646 
5647  // Find the parameter packs that could be expanded.
5648  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
5649  PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
5650  TypeLoc Pattern = ExpansionTL.getPatternLoc();
5651  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
5652 
5653  // Determine whether we should expand the parameter packs.
5654  bool ShouldExpand = false;
5655  bool RetainExpansion = false;
5656  Optional<unsigned> OrigNumExpansions;
5657  if (Unexpanded.size() > 0) {
5658  OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
5659  NumExpansions = OrigNumExpansions;
5660  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5661  Pattern.getSourceRange(),
5662  Unexpanded,
5663  ShouldExpand,
5664  RetainExpansion,
5665  NumExpansions)) {
5666  return true;
5667  }
5668  } else {
5669 #ifndef NDEBUG
5670  const AutoType *AT =
5671  Pattern.getType().getTypePtr()->getContainedAutoType();
5672  assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
5673  "Could not find parameter packs or undeduced auto type!");
5674 #endif
5675  }
5676 
5677  if (ShouldExpand) {
5678  // Expand the function parameter pack into multiple, separate
5679  // parameters.
5680  getDerived().ExpandingFunctionParameterPack(OldParm);
5681  for (unsigned I = 0; I != *NumExpansions; ++I) {
5682  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5683  ParmVarDecl *NewParm
5684  = getDerived().TransformFunctionTypeParam(OldParm,
5685  indexAdjustment++,
5686