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