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