clang  9.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  unsigned IndexTypeQuals,
799  SourceRange BracketsRange);
800 
801  /// Build a new incomplete array type given the element type, size
802  /// modifier, and index type qualifiers.
803  ///
804  /// By default, performs semantic analysis when building the array type.
805  /// Subclasses may override this routine to provide different behavior.
806  QualType RebuildIncompleteArrayType(QualType ElementType,
808  unsigned IndexTypeQuals,
809  SourceRange BracketsRange);
810 
811  /// Build a new variable-length array type given the element type,
812  /// size modifier, size expression, and index type qualifiers.
813  ///
814  /// By default, performs semantic analysis when building the array type.
815  /// Subclasses may override this routine to provide different behavior.
816  QualType RebuildVariableArrayType(QualType ElementType,
818  Expr *SizeExpr,
819  unsigned IndexTypeQuals,
820  SourceRange BracketsRange);
821 
822  /// Build a new dependent-sized array type given the element type,
823  /// size modifier, size expression, and index type qualifiers.
824  ///
825  /// By default, performs semantic analysis when building the array type.
826  /// Subclasses may override this routine to provide different behavior.
827  QualType RebuildDependentSizedArrayType(QualType ElementType,
829  Expr *SizeExpr,
830  unsigned IndexTypeQuals,
831  SourceRange BracketsRange);
832 
833  /// Build a new vector type given the element type and
834  /// number of elements.
835  ///
836  /// By default, performs semantic analysis when building the vector type.
837  /// Subclasses may override this routine to provide different behavior.
838  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
839  VectorType::VectorKind VecKind);
840 
841  /// Build a new potentially dependently-sized extended vector type
842  /// given the element type and number of elements.
843  ///
844  /// By default, performs semantic analysis when building the vector type.
845  /// Subclasses may override this routine to provide different behavior.
846  QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
847  SourceLocation AttributeLoc,
849 
850  /// Build a new extended vector type given the element type and
851  /// number of elements.
852  ///
853  /// By default, performs semantic analysis when building the vector type.
854  /// Subclasses may override this routine to provide different behavior.
855  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
856  SourceLocation AttributeLoc);
857 
858  /// Build a new potentially dependently-sized extended vector type
859  /// given the element type and number of elements.
860  ///
861  /// By default, performs semantic analysis when building the vector type.
862  /// Subclasses may override this routine to provide different behavior.
863  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
864  Expr *SizeExpr,
865  SourceLocation AttributeLoc);
866 
867  /// Build a new DependentAddressSpaceType or return the pointee
868  /// type variable with the correct address space (retrieved from
869  /// AddrSpaceExpr) applied to it. The former will be returned in cases
870  /// where the address space remains dependent.
871  ///
872  /// By default, performs semantic analysis when building the type with address
873  /// space applied. Subclasses may override this routine to provide different
874  /// behavior.
875  QualType RebuildDependentAddressSpaceType(QualType PointeeType,
876  Expr *AddrSpaceExpr,
877  SourceLocation AttributeLoc);
878 
879  /// Build a new function type.
880  ///
881  /// By default, performs semantic analysis when building the function type.
882  /// Subclasses may override this routine to provide different behavior.
883  QualType RebuildFunctionProtoType(QualType T,
884  MutableArrayRef<QualType> ParamTypes,
885  const FunctionProtoType::ExtProtoInfo &EPI);
886 
887  /// Build a new unprototyped function type.
888  QualType RebuildFunctionNoProtoType(QualType ResultType);
889 
890  /// Rebuild an unresolved typename type, given the decl that
891  /// the UnresolvedUsingTypenameDecl was transformed to.
892  QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
893 
894  /// Build a new typedef type.
896  return SemaRef.Context.getTypeDeclType(Typedef);
897  }
898 
899  /// Build a new MacroDefined type.
901  const IdentifierInfo *MacroII) {
902  return SemaRef.Context.getMacroQualifiedType(T, MacroII);
903  }
904 
905  /// Build a new class/struct/union type.
907  return SemaRef.Context.getTypeDeclType(Record);
908  }
909 
910  /// Build a new Enum type.
912  return SemaRef.Context.getTypeDeclType(Enum);
913  }
914 
915  /// Build a new typeof(expr) type.
916  ///
917  /// By default, performs semantic analysis when building the typeof type.
918  /// Subclasses may override this routine to provide different behavior.
919  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
920 
921  /// Build a new typeof(type) type.
922  ///
923  /// By default, builds a new TypeOfType with the given underlying type.
924  QualType RebuildTypeOfType(QualType Underlying);
925 
926  /// Build a new unary transform type.
927  QualType RebuildUnaryTransformType(QualType BaseType,
929  SourceLocation Loc);
930 
931  /// Build a new C++11 decltype type.
932  ///
933  /// By default, performs semantic analysis when building the decltype type.
934  /// Subclasses may override this routine to provide different behavior.
935  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
936 
937  /// Build a new C++11 auto type.
938  ///
939  /// By default, builds a new AutoType with the given deduced type.
941  // Note, IsDependent is always false here: we implicitly convert an 'auto'
942  // which has been deduced to a dependent type into an undeduced 'auto', so
943  // that we'll retry deduction after the transformation.
944  return SemaRef.Context.getAutoType(Deduced, Keyword,
945  /*IsDependent*/ false);
946  }
947 
948  /// By default, builds a new DeducedTemplateSpecializationType with the given
949  /// deduced type.
951  QualType Deduced) {
953  Template, Deduced, /*IsDependent*/ false);
954  }
955 
956  /// Build a new template specialization type.
957  ///
958  /// By default, performs semantic analysis when building the template
959  /// specialization type. Subclasses may override this routine to provide
960  /// different behavior.
961  QualType RebuildTemplateSpecializationType(TemplateName Template,
962  SourceLocation TemplateLoc,
964 
965  /// Build a new parenthesized type.
966  ///
967  /// By default, builds a new ParenType type from the inner type.
968  /// Subclasses may override this routine to provide different behavior.
970  return SemaRef.BuildParenType(InnerType);
971  }
972 
973  /// Build a new qualified name type.
974  ///
975  /// By default, builds a new ElaboratedType type from the keyword,
976  /// the nested-name-specifier and the named type.
977  /// Subclasses may override this routine to provide different behavior.
979  ElaboratedTypeKeyword Keyword,
980  NestedNameSpecifierLoc QualifierLoc,
981  QualType Named) {
982  return SemaRef.Context.getElaboratedType(Keyword,
983  QualifierLoc.getNestedNameSpecifier(),
984  Named);
985  }
986 
987  /// Build a new typename type that refers to a template-id.
988  ///
989  /// By default, builds a new DependentNameType type from the
990  /// nested-name-specifier and the given type. Subclasses may override
991  /// this routine to provide different behavior.
993  ElaboratedTypeKeyword Keyword,
994  NestedNameSpecifierLoc QualifierLoc,
995  SourceLocation TemplateKWLoc,
996  const IdentifierInfo *Name,
997  SourceLocation NameLoc,
999  bool AllowInjectedClassName) {
1000  // Rebuild the template name.
1001  // TODO: avoid TemplateName abstraction
1002  CXXScopeSpec SS;
1003  SS.Adopt(QualifierLoc);
1004  TemplateName InstName = getDerived().RebuildTemplateName(
1005  SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1006  AllowInjectedClassName);
1007 
1008  if (InstName.isNull())
1009  return QualType();
1010 
1011  // If it's still dependent, make a dependent specialization.
1012  if (InstName.getAsDependentTemplateName())
1013  return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1014  QualifierLoc.getNestedNameSpecifier(),
1015  Name,
1016  Args);
1017 
1018  // Otherwise, make an elaborated type wrapping a non-dependent
1019  // specialization.
1020  QualType T =
1021  getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1022  if (T.isNull()) return QualType();
1023 
1024  if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
1025  return T;
1026 
1027  return SemaRef.Context.getElaboratedType(Keyword,
1028  QualifierLoc.getNestedNameSpecifier(),
1029  T);
1030  }
1031 
1032  /// Build a new typename type that refers to an identifier.
1033  ///
1034  /// By default, performs semantic analysis when building the typename type
1035  /// (or elaborated type). Subclasses may override this routine to provide
1036  /// different behavior.
1038  SourceLocation KeywordLoc,
1039  NestedNameSpecifierLoc QualifierLoc,
1040  const IdentifierInfo *Id,
1041  SourceLocation IdLoc,
1042  bool DeducedTSTContext) {
1043  CXXScopeSpec SS;
1044  SS.Adopt(QualifierLoc);
1045 
1046  if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1047  // If the name is still dependent, just build a new dependent name type.
1048  if (!SemaRef.computeDeclContext(SS))
1049  return SemaRef.Context.getDependentNameType(Keyword,
1050  QualifierLoc.getNestedNameSpecifier(),
1051  Id);
1052  }
1053 
1054  if (Keyword == ETK_None || Keyword == ETK_Typename) {
1055  QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1056  *Id, IdLoc);
1057  // If a dependent name resolves to a deduced template specialization type,
1058  // check that we're in one of the syntactic contexts permitting it.
1059  if (!DeducedTSTContext) {
1060  if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1061  T.isNull() ? nullptr : T->getContainedDeducedType())) {
1062  SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1063  << (int)SemaRef.getTemplateNameKindForDiagnostics(
1064  Deduced->getTemplateName())
1065  << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1066  if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1067  SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1068  return QualType();
1069  }
1070  }
1071  return T;
1072  }
1073 
1075 
1076  // We had a dependent elaborated-type-specifier that has been transformed
1077  // into a non-dependent elaborated-type-specifier. Find the tag we're
1078  // referring to.
1079  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1080  DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1081  if (!DC)
1082  return QualType();
1083 
1084  if (SemaRef.RequireCompleteDeclContext(SS, DC))
1085  return QualType();
1086 
1087  TagDecl *Tag = nullptr;
1088  SemaRef.LookupQualifiedName(Result, DC);
1089  switch (Result.getResultKind()) {
1092  break;
1093 
1094  case LookupResult::Found:
1095  Tag = Result.getAsSingle<TagDecl>();
1096  break;
1097 
1100  llvm_unreachable("Tag lookup cannot find non-tags");
1101 
1103  // Let the LookupResult structure handle ambiguities.
1104  return QualType();
1105  }
1106 
1107  if (!Tag) {
1108  // Check where the name exists but isn't a tag type and use that to emit
1109  // better diagnostics.
1110  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1111  SemaRef.LookupQualifiedName(Result, DC);
1112  switch (Result.getResultKind()) {
1113  case LookupResult::Found:
1116  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1117  Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1118  SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1119  << NTK << Kind;
1120  SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1121  break;
1122  }
1123  default:
1124  SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1125  << Kind << Id << DC << QualifierLoc.getSourceRange();
1126  break;
1127  }
1128  return QualType();
1129  }
1130 
1131  if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1132  IdLoc, Id)) {
1133  SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1134  SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1135  return QualType();
1136  }
1137 
1138  // Build the elaborated-type-specifier type.
1139  QualType T = SemaRef.Context.getTypeDeclType(Tag);
1140  return SemaRef.Context.getElaboratedType(Keyword,
1141  QualifierLoc.getNestedNameSpecifier(),
1142  T);
1143  }
1144 
1145  /// Build a new pack expansion type.
1146  ///
1147  /// By default, builds a new PackExpansionType type from the given pattern.
1148  /// Subclasses may override this routine to provide different behavior.
1150  SourceRange PatternRange,
1151  SourceLocation EllipsisLoc,
1152  Optional<unsigned> NumExpansions) {
1153  return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1154  NumExpansions);
1155  }
1156 
1157  /// Build a new atomic type given its value type.
1158  ///
1159  /// By default, performs semantic analysis when building the atomic type.
1160  /// Subclasses may override this routine to provide different behavior.
1161  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1162 
1163  /// Build a new pipe type given its value type.
1164  QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1165  bool isReadPipe);
1166 
1167  /// Build a new template name given a nested name specifier, a flag
1168  /// indicating whether the "template" keyword was provided, and the template
1169  /// that the template name refers to.
1170  ///
1171  /// By default, builds the new template name directly. Subclasses may override
1172  /// this routine to provide different behavior.
1173  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1174  bool TemplateKW,
1175  TemplateDecl *Template);
1176 
1177  /// Build a new template name given a nested name specifier and the
1178  /// name that is referred to as a template.
1179  ///
1180  /// By default, performs semantic analysis to determine whether the name can
1181  /// be resolved to a specific template, then builds the appropriate kind of
1182  /// template name. Subclasses may override this routine to provide different
1183  /// behavior.
1184  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1185  SourceLocation TemplateKWLoc,
1186  const IdentifierInfo &Name,
1187  SourceLocation NameLoc, QualType ObjectType,
1188  NamedDecl *FirstQualifierInScope,
1189  bool AllowInjectedClassName);
1190 
1191  /// Build a new template name given a nested name specifier and the
1192  /// overloaded operator name that is referred to as a template.
1193  ///
1194  /// By default, performs semantic analysis to determine whether the name can
1195  /// be resolved to a specific template, then builds the appropriate kind of
1196  /// template name. Subclasses may override this routine to provide different
1197  /// behavior.
1198  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1199  SourceLocation TemplateKWLoc,
1200  OverloadedOperatorKind Operator,
1201  SourceLocation NameLoc, QualType ObjectType,
1202  bool AllowInjectedClassName);
1203 
1204  /// Build a new template name given a template template parameter pack
1205  /// and the
1206  ///
1207  /// By default, performs semantic analysis to determine whether the name can
1208  /// be resolved to a specific template, then builds the appropriate kind of
1209  /// template name. Subclasses may override this routine to provide different
1210  /// behavior.
1212  const TemplateArgument &ArgPack) {
1213  return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1214  }
1215 
1216  /// Build a new compound statement.
1217  ///
1218  /// By default, performs semantic analysis to build the new statement.
1219  /// Subclasses may override this routine to provide different behavior.
1221  MultiStmtArg Statements,
1222  SourceLocation RBraceLoc,
1223  bool IsStmtExpr) {
1224  return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1225  IsStmtExpr);
1226  }
1227 
1228  /// Build a new case statement.
1229  ///
1230  /// By default, performs semantic analysis to build the new statement.
1231  /// Subclasses may override this routine to provide different behavior.
1233  Expr *LHS,
1234  SourceLocation EllipsisLoc,
1235  Expr *RHS,
1237  return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1238  ColonLoc);
1239  }
1240 
1241  /// Attach the body to a new case statement.
1242  ///
1243  /// By default, performs semantic analysis to build the new statement.
1244  /// Subclasses may override this routine to provide different behavior.
1246  getSema().ActOnCaseStmtBody(S, Body);
1247  return S;
1248  }
1249 
1250  /// Build a new default statement.
1251  ///
1252  /// By default, performs semantic analysis to build the new statement.
1253  /// Subclasses may override this routine to provide different behavior.
1256  Stmt *SubStmt) {
1257  return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1258  /*CurScope=*/nullptr);
1259  }
1260 
1261  /// Build a new label statement.
1262  ///
1263  /// By default, performs semantic analysis to build the new statement.
1264  /// Subclasses may override this routine to provide different behavior.
1266  SourceLocation ColonLoc, Stmt *SubStmt) {
1267  return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1268  }
1269 
1270  /// Build a new label statement.
1271  ///
1272  /// By default, performs semantic analysis to build the new statement.
1273  /// Subclasses may override this routine to provide different behavior.
1275  ArrayRef<const Attr*> Attrs,
1276  Stmt *SubStmt) {
1277  return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1278  }
1279 
1280  /// Build a new "if" statement.
1281  ///
1282  /// By default, performs semantic analysis to build the new statement.
1283  /// Subclasses may override this routine to provide different behavior.
1284  StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1285  Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1286  SourceLocation ElseLoc, Stmt *Else) {
1287  return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1288  ElseLoc, Else);
1289  }
1290 
1291  /// Start building a new switch statement.
1292  ///
1293  /// By default, performs semantic analysis to build the new statement.
1294  /// Subclasses may override this routine to provide different behavior.
1296  Sema::ConditionResult Cond) {
1297  return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1298  }
1299 
1300  /// Attach the body to the switch statement.
1301  ///
1302  /// By default, performs semantic analysis to build the new statement.
1303  /// Subclasses may override this routine to provide different behavior.
1305  Stmt *Switch, Stmt *Body) {
1306  return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1307  }
1308 
1309  /// Build a new while statement.
1310  ///
1311  /// By default, performs semantic analysis to build the new statement.
1312  /// Subclasses may override this routine to provide different behavior.
1314  Sema::ConditionResult Cond, Stmt *Body) {
1315  return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1316  }
1317 
1318  /// Build a new do-while statement.
1319  ///
1320  /// By default, performs semantic analysis to build the new statement.
1321  /// Subclasses may override this routine to provide different behavior.
1323  SourceLocation WhileLoc, SourceLocation LParenLoc,
1324  Expr *Cond, SourceLocation RParenLoc) {
1325  return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1326  Cond, RParenLoc);
1327  }
1328 
1329  /// Build a new for statement.
1330  ///
1331  /// By default, performs semantic analysis to build the new statement.
1332  /// Subclasses may override this routine to provide different behavior.
1334  Stmt *Init, Sema::ConditionResult Cond,
1335  Sema::FullExprArg Inc, SourceLocation RParenLoc,
1336  Stmt *Body) {
1337  return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1338  Inc, RParenLoc, Body);
1339  }
1340 
1341  /// Build a new goto statement.
1342  ///
1343  /// By default, performs semantic analysis to build the new statement.
1344  /// Subclasses may override this routine to provide different behavior.
1346  LabelDecl *Label) {
1347  return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1348  }
1349 
1350  /// Build a new indirect goto statement.
1351  ///
1352  /// By default, performs semantic analysis to build the new statement.
1353  /// Subclasses may override this routine to provide different behavior.
1355  SourceLocation StarLoc,
1356  Expr *Target) {
1357  return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1358  }
1359 
1360  /// Build a new return statement.
1361  ///
1362  /// By default, performs semantic analysis to build the new statement.
1363  /// Subclasses may override this routine to provide different behavior.
1365  return getSema().BuildReturnStmt(ReturnLoc, Result);
1366  }
1367 
1368  /// Build a new declaration statement.
1369  ///
1370  /// By default, performs semantic analysis to build the new statement.
1371  /// Subclasses may override this routine to provide different behavior.
1373  SourceLocation StartLoc, SourceLocation EndLoc) {
1374  Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1375  return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1376  }
1377 
1378  /// Build a new inline asm statement.
1379  ///
1380  /// By default, performs semantic analysis to build the new statement.
1381  /// Subclasses may override this routine to provide different behavior.
1383  bool IsVolatile, unsigned NumOutputs,
1384  unsigned NumInputs, IdentifierInfo **Names,
1385  MultiExprArg Constraints, MultiExprArg Exprs,
1386  Expr *AsmString, MultiExprArg Clobbers,
1387  unsigned NumLabels,
1388  SourceLocation RParenLoc) {
1389  return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1390  NumInputs, Names, Constraints, Exprs,
1391  AsmString, Clobbers, NumLabels, RParenLoc);
1392  }
1393 
1394  /// Build a new MS style inline asm statement.
1395  ///
1396  /// By default, performs semantic analysis to build the new statement.
1397  /// Subclasses may override this routine to provide different behavior.
1399  ArrayRef<Token> AsmToks,
1400  StringRef AsmString,
1401  unsigned NumOutputs, unsigned NumInputs,
1402  ArrayRef<StringRef> Constraints,
1403  ArrayRef<StringRef> Clobbers,
1404  ArrayRef<Expr*> Exprs,
1405  SourceLocation EndLoc) {
1406  return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1407  NumOutputs, NumInputs,
1408  Constraints, Clobbers, Exprs, EndLoc);
1409  }
1410 
1411  /// Build a new co_return statement.
1412  ///
1413  /// By default, performs semantic analysis to build the new statement.
1414  /// Subclasses may override this routine to provide different behavior.
1416  bool IsImplicit) {
1417  return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1418  }
1419 
1420  /// Build a new co_await expression.
1421  ///
1422  /// By default, performs semantic analysis to build the new expression.
1423  /// Subclasses may override this routine to provide different behavior.
1425  bool IsImplicit) {
1426  return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1427  }
1428 
1429  /// Build a new co_await expression.
1430  ///
1431  /// By default, performs semantic analysis to build the new expression.
1432  /// Subclasses may override this routine to provide different behavior.
1434  Expr *Result,
1435  UnresolvedLookupExpr *Lookup) {
1436  return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1437  }
1438 
1439  /// Build a new co_yield expression.
1440  ///
1441  /// By default, performs semantic analysis to build the new expression.
1442  /// Subclasses may override this routine to provide different behavior.
1444  return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1445  }
1446 
1448  return getSema().BuildCoroutineBodyStmt(Args);
1449  }
1450 
1451  /// Build a new Objective-C \@try statement.
1452  ///
1453  /// By default, performs semantic analysis to build the new statement.
1454  /// Subclasses may override this routine to provide different behavior.
1456  Stmt *TryBody,
1457  MultiStmtArg CatchStmts,
1458  Stmt *Finally) {
1459  return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1460  Finally);
1461  }
1462 
1463  /// Rebuild an Objective-C exception declaration.
1464  ///
1465  /// By default, performs semantic analysis to build the new declaration.
1466  /// Subclasses may override this routine to provide different behavior.
1468  TypeSourceInfo *TInfo, QualType T) {
1469  return getSema().BuildObjCExceptionDecl(TInfo, T,
1470  ExceptionDecl->getInnerLocStart(),
1471  ExceptionDecl->getLocation(),
1472  ExceptionDecl->getIdentifier());
1473  }
1474 
1475  /// Build a new Objective-C \@catch statement.
1476  ///
1477  /// By default, performs semantic analysis to build the new statement.
1478  /// Subclasses may override this routine to provide different behavior.
1480  SourceLocation RParenLoc,
1481  VarDecl *Var,
1482  Stmt *Body) {
1483  return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1484  Var, Body);
1485  }
1486 
1487  /// Build a new Objective-C \@finally statement.
1488  ///
1489  /// By default, performs semantic analysis to build the new statement.
1490  /// Subclasses may override this routine to provide different behavior.
1492  Stmt *Body) {
1493  return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1494  }
1495 
1496  /// Build a new Objective-C \@throw statement.
1497  ///
1498  /// By default, performs semantic analysis to build the new statement.
1499  /// Subclasses may override this routine to provide different behavior.
1501  Expr *Operand) {
1502  return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1503  }
1504 
1505  /// Build a new OpenMP executable directive.
1506  ///
1507  /// By default, performs semantic analysis to build the new statement.
1508  /// Subclasses may override this routine to provide different behavior.
1510  DeclarationNameInfo DirName,
1511  OpenMPDirectiveKind CancelRegion,
1512  ArrayRef<OMPClause *> Clauses,
1513  Stmt *AStmt, SourceLocation StartLoc,
1514  SourceLocation EndLoc) {
1515  return getSema().ActOnOpenMPExecutableDirective(
1516  Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1517  }
1518 
1519  /// Build a new OpenMP 'if' clause.
1520  ///
1521  /// By default, performs semantic analysis to build the new OpenMP clause.
1522  /// Subclasses may override this routine to provide different behavior.
1524  Expr *Condition, SourceLocation StartLoc,
1525  SourceLocation LParenLoc,
1526  SourceLocation NameModifierLoc,
1528  SourceLocation EndLoc) {
1529  return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1530  LParenLoc, NameModifierLoc, ColonLoc,
1531  EndLoc);
1532  }
1533 
1534  /// Build a new OpenMP 'final' clause.
1535  ///
1536  /// By default, performs semantic analysis to build the new OpenMP clause.
1537  /// Subclasses may override this routine to provide different behavior.
1539  SourceLocation LParenLoc,
1540  SourceLocation EndLoc) {
1541  return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1542  EndLoc);
1543  }
1544 
1545  /// Build a new OpenMP 'num_threads' clause.
1546  ///
1547  /// By default, performs semantic analysis to build the new OpenMP clause.
1548  /// Subclasses may override this routine to provide different behavior.
1550  SourceLocation StartLoc,
1551  SourceLocation LParenLoc,
1552  SourceLocation EndLoc) {
1553  return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1554  LParenLoc, EndLoc);
1555  }
1556 
1557  /// Build a new OpenMP 'safelen' clause.
1558  ///
1559  /// By default, performs semantic analysis to build the new OpenMP clause.
1560  /// Subclasses may override this routine to provide different behavior.
1562  SourceLocation LParenLoc,
1563  SourceLocation EndLoc) {
1564  return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1565  }
1566 
1567  /// Build a new OpenMP 'simdlen' clause.
1568  ///
1569  /// By default, performs semantic analysis to build the new OpenMP clause.
1570  /// Subclasses may override this routine to provide different behavior.
1572  SourceLocation LParenLoc,
1573  SourceLocation EndLoc) {
1574  return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1575  }
1576 
1577  /// Build a new OpenMP 'allocator' clause.
1578  ///
1579  /// By default, performs semantic analysis to build the new OpenMP clause.
1580  /// Subclasses may override this routine to provide different behavior.
1582  SourceLocation LParenLoc,
1583  SourceLocation EndLoc) {
1584  return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1585  }
1586 
1587  /// Build a new OpenMP 'collapse' clause.
1588  ///
1589  /// By default, performs semantic analysis to build the new OpenMP clause.
1590  /// Subclasses may override this routine to provide different behavior.
1592  SourceLocation LParenLoc,
1593  SourceLocation EndLoc) {
1594  return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1595  EndLoc);
1596  }
1597 
1598  /// Build a new OpenMP 'default' clause.
1599  ///
1600  /// By default, performs semantic analysis to build the new OpenMP clause.
1601  /// Subclasses may override this routine to provide different behavior.
1603  SourceLocation KindKwLoc,
1604  SourceLocation StartLoc,
1605  SourceLocation LParenLoc,
1606  SourceLocation EndLoc) {
1607  return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1608  StartLoc, LParenLoc, EndLoc);
1609  }
1610 
1611  /// Build a new OpenMP 'proc_bind' clause.
1612  ///
1613  /// By default, performs semantic analysis to build the new OpenMP clause.
1614  /// Subclasses may override this routine to provide different behavior.
1616  SourceLocation KindKwLoc,
1617  SourceLocation StartLoc,
1618  SourceLocation LParenLoc,
1619  SourceLocation EndLoc) {
1620  return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1621  StartLoc, LParenLoc, EndLoc);
1622  }
1623 
1624  /// Build a new OpenMP 'schedule' clause.
1625  ///
1626  /// By default, performs semantic analysis to build the new OpenMP clause.
1627  /// Subclasses may override this routine to provide different behavior.
1630  OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1631  SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1632  SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1633  return getSema().ActOnOpenMPScheduleClause(
1634  M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1635  CommaLoc, EndLoc);
1636  }
1637 
1638  /// Build a new OpenMP 'ordered' clause.
1639  ///
1640  /// By default, performs semantic analysis to build the new OpenMP clause.
1641  /// Subclasses may override this routine to provide different behavior.
1643  SourceLocation EndLoc,
1644  SourceLocation LParenLoc, Expr *Num) {
1645  return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1646  }
1647 
1648  /// Build a new OpenMP 'private' clause.
1649  ///
1650  /// By default, performs semantic analysis to build the new OpenMP clause.
1651  /// Subclasses may override this routine to provide different behavior.
1653  SourceLocation StartLoc,
1654  SourceLocation LParenLoc,
1655  SourceLocation EndLoc) {
1656  return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1657  EndLoc);
1658  }
1659 
1660  /// Build a new OpenMP 'firstprivate' clause.
1661  ///
1662  /// By default, performs semantic analysis to build the new OpenMP clause.
1663  /// Subclasses may override this routine to provide different behavior.
1665  SourceLocation StartLoc,
1666  SourceLocation LParenLoc,
1667  SourceLocation EndLoc) {
1668  return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1669  EndLoc);
1670  }
1671 
1672  /// Build a new OpenMP 'lastprivate' clause.
1673  ///
1674  /// By default, performs semantic analysis to build the new OpenMP clause.
1675  /// Subclasses may override this routine to provide different behavior.
1677  SourceLocation StartLoc,
1678  SourceLocation LParenLoc,
1679  SourceLocation EndLoc) {
1680  return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1681  EndLoc);
1682  }
1683 
1684  /// Build a new OpenMP 'shared' clause.
1685  ///
1686  /// By default, performs semantic analysis to build the new OpenMP clause.
1687  /// Subclasses may override this routine to provide different behavior.
1689  SourceLocation StartLoc,
1690  SourceLocation LParenLoc,
1691  SourceLocation EndLoc) {
1692  return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1693  EndLoc);
1694  }
1695 
1696  /// Build a new OpenMP 'reduction' clause.
1697  ///
1698  /// By default, performs semantic analysis to build the new statement.
1699  /// Subclasses may override this routine to provide different behavior.
1701  SourceLocation StartLoc,
1702  SourceLocation LParenLoc,
1704  SourceLocation EndLoc,
1705  CXXScopeSpec &ReductionIdScopeSpec,
1706  const DeclarationNameInfo &ReductionId,
1707  ArrayRef<Expr *> UnresolvedReductions) {
1708  return getSema().ActOnOpenMPReductionClause(
1709  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1710  ReductionId, UnresolvedReductions);
1711  }
1712 
1713  /// Build a new OpenMP 'task_reduction' clause.
1714  ///
1715  /// By default, performs semantic analysis to build the new statement.
1716  /// Subclasses may override this routine to provide different behavior.
1718  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1720  CXXScopeSpec &ReductionIdScopeSpec,
1721  const DeclarationNameInfo &ReductionId,
1722  ArrayRef<Expr *> UnresolvedReductions) {
1723  return getSema().ActOnOpenMPTaskReductionClause(
1724  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1725  ReductionId, UnresolvedReductions);
1726  }
1727 
1728  /// Build a new OpenMP 'in_reduction' clause.
1729  ///
1730  /// By default, performs semantic analysis to build the new statement.
1731  /// Subclasses may override this routine to provide different behavior.
1732  OMPClause *
1735  SourceLocation EndLoc,
1736  CXXScopeSpec &ReductionIdScopeSpec,
1737  const DeclarationNameInfo &ReductionId,
1738  ArrayRef<Expr *> UnresolvedReductions) {
1739  return getSema().ActOnOpenMPInReductionClause(
1740  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1741  ReductionId, UnresolvedReductions);
1742  }
1743 
1744  /// Build a new OpenMP 'linear' clause.
1745  ///
1746  /// By default, performs semantic analysis to build the new OpenMP clause.
1747  /// Subclasses may override this routine to provide different behavior.
1749  SourceLocation StartLoc,
1750  SourceLocation LParenLoc,
1754  SourceLocation EndLoc) {
1755  return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1756  Modifier, ModifierLoc, ColonLoc,
1757  EndLoc);
1758  }
1759 
1760  /// Build a new OpenMP 'aligned' clause.
1761  ///
1762  /// By default, performs semantic analysis to build the new OpenMP clause.
1763  /// Subclasses may override this routine to provide different behavior.
1765  SourceLocation StartLoc,
1766  SourceLocation LParenLoc,
1768  SourceLocation EndLoc) {
1769  return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1770  LParenLoc, ColonLoc, EndLoc);
1771  }
1772 
1773  /// Build a new OpenMP 'copyin' clause.
1774  ///
1775  /// By default, performs semantic analysis to build the new OpenMP clause.
1776  /// Subclasses may override this routine to provide different behavior.
1778  SourceLocation StartLoc,
1779  SourceLocation LParenLoc,
1780  SourceLocation EndLoc) {
1781  return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1782  EndLoc);
1783  }
1784 
1785  /// Build a new OpenMP 'copyprivate' clause.
1786  ///
1787  /// By default, performs semantic analysis to build the new OpenMP clause.
1788  /// Subclasses may override this routine to provide different behavior.
1790  SourceLocation StartLoc,
1791  SourceLocation LParenLoc,
1792  SourceLocation EndLoc) {
1793  return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1794  EndLoc);
1795  }
1796 
1797  /// Build a new OpenMP 'flush' pseudo clause.
1798  ///
1799  /// By default, performs semantic analysis to build the new OpenMP clause.
1800  /// Subclasses may override this routine to provide different behavior.
1802  SourceLocation StartLoc,
1803  SourceLocation LParenLoc,
1804  SourceLocation EndLoc) {
1805  return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1806  EndLoc);
1807  }
1808 
1809  /// Build a new OpenMP 'depend' pseudo clause.
1810  ///
1811  /// By default, performs semantic analysis to build the new OpenMP clause.
1812  /// Subclasses may override this routine to provide different behavior.
1813  OMPClause *
1816  SourceLocation StartLoc, SourceLocation LParenLoc,
1817  SourceLocation EndLoc) {
1818  return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1819  StartLoc, LParenLoc, EndLoc);
1820  }
1821 
1822  /// Build a new OpenMP 'device' clause.
1823  ///
1824  /// By default, performs semantic analysis to build the new statement.
1825  /// Subclasses may override this routine to provide different behavior.
1827  SourceLocation LParenLoc,
1828  SourceLocation EndLoc) {
1829  return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1830  EndLoc);
1831  }
1832 
1833  /// Build a new OpenMP 'map' clause.
1834  ///
1835  /// By default, performs semantic analysis to build the new OpenMP clause.
1836  /// Subclasses may override this routine to provide different behavior.
1838  ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1839  ArrayRef<SourceLocation> MapTypeModifiersLoc,
1840  CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1841  OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1843  const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
1844  return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
1845  MapperIdScopeSpec, MapperId, MapType,
1846  IsMapTypeImplicit, MapLoc, ColonLoc,
1847  VarList, Locs, UnresolvedMappers);
1848  }
1849 
1850  /// Build a new OpenMP 'allocate' clause.
1851  ///
1852  /// By default, performs semantic analysis to build the new OpenMP clause.
1853  /// Subclasses may override this routine to provide different behavior.
1855  SourceLocation StartLoc,
1856  SourceLocation LParenLoc,
1858  SourceLocation EndLoc) {
1859  return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1860  LParenLoc, ColonLoc, EndLoc);
1861  }
1862 
1863  /// Build a new OpenMP 'num_teams' clause.
1864  ///
1865  /// By default, performs semantic analysis to build the new statement.
1866  /// Subclasses may override this routine to provide different behavior.
1868  SourceLocation LParenLoc,
1869  SourceLocation EndLoc) {
1870  return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1871  EndLoc);
1872  }
1873 
1874  /// Build a new OpenMP 'thread_limit' clause.
1875  ///
1876  /// By default, performs semantic analysis to build the new statement.
1877  /// Subclasses may override this routine to provide different behavior.
1879  SourceLocation StartLoc,
1880  SourceLocation LParenLoc,
1881  SourceLocation EndLoc) {
1882  return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1883  LParenLoc, EndLoc);
1884  }
1885 
1886  /// Build a new OpenMP 'priority' clause.
1887  ///
1888  /// By default, performs semantic analysis to build the new statement.
1889  /// Subclasses may override this routine to provide different behavior.
1891  SourceLocation LParenLoc,
1892  SourceLocation EndLoc) {
1893  return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1894  EndLoc);
1895  }
1896 
1897  /// Build a new OpenMP 'grainsize' clause.
1898  ///
1899  /// By default, performs semantic analysis to build the new statement.
1900  /// Subclasses may override this routine to provide different behavior.
1902  SourceLocation LParenLoc,
1903  SourceLocation EndLoc) {
1904  return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1905  EndLoc);
1906  }
1907 
1908  /// Build a new OpenMP 'num_tasks' clause.
1909  ///
1910  /// By default, performs semantic analysis to build the new statement.
1911  /// Subclasses may override this routine to provide different behavior.
1913  SourceLocation LParenLoc,
1914  SourceLocation EndLoc) {
1915  return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1916  EndLoc);
1917  }
1918 
1919  /// Build a new OpenMP 'hint' clause.
1920  ///
1921  /// By default, performs semantic analysis to build the new statement.
1922  /// Subclasses may override this routine to provide different behavior.
1924  SourceLocation LParenLoc,
1925  SourceLocation EndLoc) {
1926  return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1927  }
1928 
1929  /// Build a new OpenMP 'dist_schedule' clause.
1930  ///
1931  /// By default, performs semantic analysis to build the new OpenMP clause.
1932  /// Subclasses may override this routine to provide different behavior.
1933  OMPClause *
1935  Expr *ChunkSize, SourceLocation StartLoc,
1936  SourceLocation LParenLoc, SourceLocation KindLoc,
1937  SourceLocation CommaLoc, SourceLocation EndLoc) {
1938  return getSema().ActOnOpenMPDistScheduleClause(
1939  Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1940  }
1941 
1942  /// Build a new OpenMP 'to' clause.
1943  ///
1944  /// By default, performs semantic analysis to build the new statement.
1945  /// Subclasses may override this routine to provide different behavior.
1947  CXXScopeSpec &MapperIdScopeSpec,
1948  DeclarationNameInfo &MapperId,
1949  const OMPVarListLocTy &Locs,
1950  ArrayRef<Expr *> UnresolvedMappers) {
1951  return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId,
1952  Locs, UnresolvedMappers);
1953  }
1954 
1955  /// Build a new OpenMP 'from' clause.
1956  ///
1957  /// By default, performs semantic analysis to build the new statement.
1958  /// Subclasses may override this routine to provide different behavior.
1960  CXXScopeSpec &MapperIdScopeSpec,
1961  DeclarationNameInfo &MapperId,
1962  const OMPVarListLocTy &Locs,
1963  ArrayRef<Expr *> UnresolvedMappers) {
1964  return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId,
1965  Locs, UnresolvedMappers);
1966  }
1967 
1968  /// Build a new OpenMP 'use_device_ptr' clause.
1969  ///
1970  /// By default, performs semantic analysis to build the new OpenMP clause.
1971  /// Subclasses may override this routine to provide different behavior.
1973  const OMPVarListLocTy &Locs) {
1974  return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
1975  }
1976 
1977  /// Build a new OpenMP 'is_device_ptr' clause.
1978  ///
1979  /// By default, performs semantic analysis to build the new OpenMP clause.
1980  /// Subclasses may override this routine to provide different behavior.
1982  const OMPVarListLocTy &Locs) {
1983  return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
1984  }
1985 
1986  /// Rebuild the operand to an Objective-C \@synchronized statement.
1987  ///
1988  /// By default, performs semantic analysis to build the new statement.
1989  /// Subclasses may override this routine to provide different behavior.
1991  Expr *object) {
1992  return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1993  }
1994 
1995  /// Build a new Objective-C \@synchronized statement.
1996  ///
1997  /// By default, performs semantic analysis to build the new statement.
1998  /// Subclasses may override this routine to provide different behavior.
2000  Expr *Object, Stmt *Body) {
2001  return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2002  }
2003 
2004  /// Build a new Objective-C \@autoreleasepool statement.
2005  ///
2006  /// By default, performs semantic analysis to build the new statement.
2007  /// Subclasses may override this routine to provide different behavior.
2009  Stmt *Body) {
2010  return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2011  }
2012 
2013  /// Build a new Objective-C fast enumeration statement.
2014  ///
2015  /// By default, performs semantic analysis to build the new statement.
2016  /// Subclasses may override this routine to provide different behavior.
2018  Stmt *Element,
2019  Expr *Collection,
2020  SourceLocation RParenLoc,
2021  Stmt *Body) {
2022  StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
2023  Element,
2024  Collection,
2025  RParenLoc);
2026  if (ForEachStmt.isInvalid())
2027  return StmtError();
2028 
2029  return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
2030  }
2031 
2032  /// Build a new C++ exception declaration.
2033  ///
2034  /// By default, performs semantic analysis to build the new decaration.
2035  /// Subclasses may override this routine to provide different behavior.
2038  SourceLocation StartLoc,
2039  SourceLocation IdLoc,
2040  IdentifierInfo *Id) {
2041  VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
2042  StartLoc, IdLoc, Id);
2043  if (Var)
2044  getSema().CurContext->addDecl(Var);
2045  return Var;
2046  }
2047 
2048  /// Build a new C++ catch statement.
2049  ///
2050  /// By default, performs semantic analysis to build the new statement.
2051  /// Subclasses may override this routine to provide different behavior.
2053  VarDecl *ExceptionDecl,
2054  Stmt *Handler) {
2055  return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2056  Handler));
2057  }
2058 
2059  /// Build a new C++ try statement.
2060  ///
2061  /// By default, performs semantic analysis to build the new statement.
2062  /// Subclasses may override this routine to provide different behavior.
2064  ArrayRef<Stmt *> Handlers) {
2065  return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2066  }
2067 
2068  /// Build a new C++0x range-based for statement.
2069  ///
2070  /// By default, performs semantic analysis to build the new statement.
2071  /// Subclasses may override this routine to provide different behavior.
2073  SourceLocation CoawaitLoc, Stmt *Init,
2074  SourceLocation ColonLoc, Stmt *Range,
2075  Stmt *Begin, Stmt *End, Expr *Cond,
2076  Expr *Inc, Stmt *LoopVar,
2077  SourceLocation RParenLoc) {
2078  // If we've just learned that the range is actually an Objective-C
2079  // collection, treat this as an Objective-C fast enumeration loop.
2080  if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2081  if (RangeStmt->isSingleDecl()) {
2082  if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2083  if (RangeVar->isInvalidDecl())
2084  return StmtError();
2085 
2086  Expr *RangeExpr = RangeVar->getInit();
2087  if (!RangeExpr->isTypeDependent() &&
2088  RangeExpr->getType()->isObjCObjectPointerType()) {
2089  // FIXME: Support init-statements in Objective-C++20 ranged for
2090  // statement.
2091  if (Init) {
2092  return SemaRef.Diag(Init->getBeginLoc(),
2093  diag::err_objc_for_range_init_stmt)
2094  << Init->getSourceRange();
2095  }
2096  return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2097  RangeExpr, RParenLoc);
2098  }
2099  }
2100  }
2101  }
2102 
2103  return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2104  Range, Begin, End, Cond, Inc, LoopVar,
2105  RParenLoc, Sema::BFRK_Rebuild);
2106  }
2107 
2108  /// Build a new C++0x range-based for statement.
2109  ///
2110  /// By default, performs semantic analysis to build the new statement.
2111  /// Subclasses may override this routine to provide different behavior.
2113  bool IsIfExists,
2114  NestedNameSpecifierLoc QualifierLoc,
2115  DeclarationNameInfo NameInfo,
2116  Stmt *Nested) {
2117  return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2118  QualifierLoc, NameInfo, Nested);
2119  }
2120 
2121  /// Attach body to a C++0x range-based for statement.
2122  ///
2123  /// By default, performs semantic analysis to finish the new statement.
2124  /// Subclasses may override this routine to provide different behavior.
2126  return getSema().FinishCXXForRangeStmt(ForRange, Body);
2127  }
2128 
2130  Stmt *TryBlock, Stmt *Handler) {
2131  return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2132  }
2133 
2135  Stmt *Block) {
2136  return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2137  }
2138 
2140  return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2141  }
2142 
2143  /// Build a new predefined expression.
2144  ///
2145  /// By default, performs semantic analysis to build the new expression.
2146  /// Subclasses may override this routine to provide different behavior.
2149  return getSema().BuildPredefinedExpr(Loc, IK);
2150  }
2151 
2152  /// Build a new expression that references a declaration.
2153  ///
2154  /// By default, performs semantic analysis to build the new expression.
2155  /// Subclasses may override this routine to provide different behavior.
2157  LookupResult &R,
2158  bool RequiresADL) {
2159  return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2160  }
2161 
2162 
2163  /// Build a new expression that references a declaration.
2164  ///
2165  /// By default, performs semantic analysis to build the new expression.
2166  /// Subclasses may override this routine to provide different behavior.
2168  ValueDecl *VD,
2169  const DeclarationNameInfo &NameInfo,
2170  TemplateArgumentListInfo *TemplateArgs) {
2171  CXXScopeSpec SS;
2172  SS.Adopt(QualifierLoc);
2173 
2174  // FIXME: loses template args.
2175 
2176  return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
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 conditional operator expression.
2357  ///
2358  /// By default, performs semantic analysis to build the new expression.
2359  /// Subclasses may override this routine to provide different behavior.
2361  SourceLocation QuestionLoc,
2362  Expr *LHS,
2364  Expr *RHS) {
2365  return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2366  LHS, RHS);
2367  }
2368 
2369  /// Build a new C-style cast expression.
2370  ///
2371  /// By default, performs semantic analysis to build the new expression.
2372  /// Subclasses may override this routine to provide different behavior.
2374  TypeSourceInfo *TInfo,
2375  SourceLocation RParenLoc,
2376  Expr *SubExpr) {
2377  return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2378  SubExpr);
2379  }
2380 
2381  /// Build a new compound literal expression.
2382  ///
2383  /// By default, performs semantic analysis to build the new expression.
2384  /// Subclasses may override this routine to provide different behavior.
2386  TypeSourceInfo *TInfo,
2387  SourceLocation RParenLoc,
2388  Expr *Init) {
2389  return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2390  Init);
2391  }
2392 
2393  /// Build a new extended vector element access expression.
2394  ///
2395  /// By default, performs semantic analysis to build the new expression.
2396  /// Subclasses may override this routine to provide different behavior.
2398  SourceLocation OpLoc,
2399  SourceLocation AccessorLoc,
2400  IdentifierInfo &Accessor) {
2401 
2402  CXXScopeSpec SS;
2403  DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2404  return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2405  OpLoc, /*IsArrow*/ false,
2406  SS, SourceLocation(),
2407  /*FirstQualifierInScope*/ nullptr,
2408  NameInfo,
2409  /* TemplateArgs */ nullptr,
2410  /*S*/ nullptr);
2411  }
2412 
2413  /// Build a new initializer list expression.
2414  ///
2415  /// By default, performs semantic analysis to build the new expression.
2416  /// Subclasses may override this routine to provide different behavior.
2419  SourceLocation RBraceLoc) {
2420  return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2421  }
2422 
2423  /// Build a new designated initializer expression.
2424  ///
2425  /// By default, performs semantic analysis to build the new expression.
2426  /// Subclasses may override this routine to provide different behavior.
2428  MultiExprArg ArrayExprs,
2429  SourceLocation EqualOrColonLoc,
2430  bool GNUSyntax,
2431  Expr *Init) {
2432  ExprResult Result
2433  = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2434  Init);
2435  if (Result.isInvalid())
2436  return ExprError();
2437 
2438  return Result;
2439  }
2440 
2441  /// Build a new value-initialized expression.
2442  ///
2443  /// By default, builds the implicit value initialization without performing
2444  /// any semantic analysis. Subclasses may override this routine to provide
2445  /// different behavior.
2447  return new (SemaRef.Context) ImplicitValueInitExpr(T);
2448  }
2449 
2450  /// Build a new \c va_arg expression.
2451  ///
2452  /// By default, performs semantic analysis to build the new expression.
2453  /// Subclasses may override this routine to provide different behavior.
2455  Expr *SubExpr, TypeSourceInfo *TInfo,
2456  SourceLocation RParenLoc) {
2457  return getSema().BuildVAArgExpr(BuiltinLoc,
2458  SubExpr, TInfo,
2459  RParenLoc);
2460  }
2461 
2462  /// Build a new expression list in parentheses.
2463  ///
2464  /// By default, performs semantic analysis to build the new expression.
2465  /// Subclasses may override this routine to provide different behavior.
2467  MultiExprArg SubExprs,
2468  SourceLocation RParenLoc) {
2469  return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2470  }
2471 
2472  /// Build a new address-of-label expression.
2473  ///
2474  /// By default, performs semantic analysis, using the name of the label
2475  /// rather than attempting to map the label statement itself.
2476  /// Subclasses may override this routine to provide different behavior.
2478  SourceLocation LabelLoc, LabelDecl *Label) {
2479  return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2480  }
2481 
2482  /// Build a new GNU statement expression.
2483  ///
2484  /// By default, performs semantic analysis to build the new expression.
2485  /// Subclasses may override this routine to provide different behavior.
2487  Stmt *SubStmt,
2488  SourceLocation RParenLoc) {
2489  return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2490  }
2491 
2492  /// Build a new __builtin_choose_expr expression.
2493  ///
2494  /// By default, performs semantic analysis to build the new expression.
2495  /// Subclasses may override this routine to provide different behavior.
2497  Expr *Cond, Expr *LHS, Expr *RHS,
2498  SourceLocation RParenLoc) {
2499  return SemaRef.ActOnChooseExpr(BuiltinLoc,
2500  Cond, LHS, RHS,
2501  RParenLoc);
2502  }
2503 
2504  /// Build a new generic selection expression.
2505  ///
2506  /// By default, performs semantic analysis to build the new expression.
2507  /// Subclasses may override this routine to provide different behavior.
2509  SourceLocation DefaultLoc,
2510  SourceLocation RParenLoc,
2511  Expr *ControllingExpr,
2513  ArrayRef<Expr *> Exprs) {
2514  return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2515  ControllingExpr, Types, Exprs);
2516  }
2517 
2518  /// Build a new overloaded operator call expression.
2519  ///
2520  /// By default, performs semantic analysis to build the new expression.
2521  /// The semantic analysis provides the behavior of template instantiation,
2522  /// copying with transformations that turn what looks like an overloaded
2523  /// operator call into a use of a builtin operator, performing
2524  /// argument-dependent lookup, etc. Subclasses may override this routine to
2525  /// provide different behavior.
2526  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2527  SourceLocation OpLoc,
2528  Expr *Callee,
2529  Expr *First,
2530  Expr *Second);
2531 
2532  /// Build a new C++ "named" cast expression, such as static_cast or
2533  /// reinterpret_cast.
2534  ///
2535  /// By default, this routine dispatches to one of the more-specific routines
2536  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2537  /// Subclasses may override this routine to provide different behavior.
2539  Stmt::StmtClass Class,
2540  SourceLocation LAngleLoc,
2541  TypeSourceInfo *TInfo,
2542  SourceLocation RAngleLoc,
2543  SourceLocation LParenLoc,
2544  Expr *SubExpr,
2545  SourceLocation RParenLoc) {
2546  switch (Class) {
2547  case Stmt::CXXStaticCastExprClass:
2548  return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2549  RAngleLoc, LParenLoc,
2550  SubExpr, RParenLoc);
2551 
2552  case Stmt::CXXDynamicCastExprClass:
2553  return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2554  RAngleLoc, LParenLoc,
2555  SubExpr, RParenLoc);
2556 
2557  case Stmt::CXXReinterpretCastExprClass:
2558  return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2559  RAngleLoc, LParenLoc,
2560  SubExpr,
2561  RParenLoc);
2562 
2563  case Stmt::CXXConstCastExprClass:
2564  return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2565  RAngleLoc, LParenLoc,
2566  SubExpr, RParenLoc);
2567 
2568  default:
2569  llvm_unreachable("Invalid C++ named cast");
2570  }
2571  }
2572 
2573  /// Build a new C++ static_cast expression.
2574  ///
2575  /// By default, performs semantic analysis to build the new expression.
2576  /// Subclasses may override this routine to provide different behavior.
2578  SourceLocation LAngleLoc,
2579  TypeSourceInfo *TInfo,
2580  SourceLocation RAngleLoc,
2581  SourceLocation LParenLoc,
2582  Expr *SubExpr,
2583  SourceLocation RParenLoc) {
2584  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2585  TInfo, SubExpr,
2586  SourceRange(LAngleLoc, RAngleLoc),
2587  SourceRange(LParenLoc, RParenLoc));
2588  }
2589 
2590  /// Build a new C++ dynamic_cast expression.
2591  ///
2592  /// By default, performs semantic analysis to build the new expression.
2593  /// Subclasses may override this routine to provide different behavior.
2595  SourceLocation LAngleLoc,
2596  TypeSourceInfo *TInfo,
2597  SourceLocation RAngleLoc,
2598  SourceLocation LParenLoc,
2599  Expr *SubExpr,
2600  SourceLocation RParenLoc) {
2601  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2602  TInfo, SubExpr,
2603  SourceRange(LAngleLoc, RAngleLoc),
2604  SourceRange(LParenLoc, RParenLoc));
2605  }
2606 
2607  /// Build a new C++ reinterpret_cast expression.
2608  ///
2609  /// By default, performs semantic analysis to build the new expression.
2610  /// Subclasses may override this routine to provide different behavior.
2612  SourceLocation LAngleLoc,
2613  TypeSourceInfo *TInfo,
2614  SourceLocation RAngleLoc,
2615  SourceLocation LParenLoc,
2616  Expr *SubExpr,
2617  SourceLocation RParenLoc) {
2618  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2619  TInfo, SubExpr,
2620  SourceRange(LAngleLoc, RAngleLoc),
2621  SourceRange(LParenLoc, RParenLoc));
2622  }
2623 
2624  /// Build a new C++ const_cast expression.
2625  ///
2626  /// By default, performs semantic analysis to build the new expression.
2627  /// Subclasses may override this routine to provide different behavior.
2629  SourceLocation LAngleLoc,
2630  TypeSourceInfo *TInfo,
2631  SourceLocation RAngleLoc,
2632  SourceLocation LParenLoc,
2633  Expr *SubExpr,
2634  SourceLocation RParenLoc) {
2635  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2636  TInfo, SubExpr,
2637  SourceRange(LAngleLoc, RAngleLoc),
2638  SourceRange(LParenLoc, RParenLoc));
2639  }
2640 
2641  /// Build a new C++ functional-style cast expression.
2642  ///
2643  /// By default, performs semantic analysis to build the new expression.
2644  /// Subclasses may override this routine to provide different behavior.
2646  SourceLocation LParenLoc,
2647  Expr *Sub,
2648  SourceLocation RParenLoc,
2649  bool ListInitialization) {
2650  return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2651  MultiExprArg(&Sub, 1), RParenLoc,
2652  ListInitialization);
2653  }
2654 
2655  /// Build a new C++ typeid(type) expression.
2656  ///
2657  /// By default, performs semantic analysis to build the new expression.
2658  /// Subclasses may override this routine to provide different behavior.
2660  SourceLocation TypeidLoc,
2661  TypeSourceInfo *Operand,
2662  SourceLocation RParenLoc) {
2663  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2664  RParenLoc);
2665  }
2666 
2667 
2668  /// Build a new C++ typeid(expr) expression.
2669  ///
2670  /// By default, performs semantic analysis to build the new expression.
2671  /// Subclasses may override this routine to provide different behavior.
2673  SourceLocation TypeidLoc,
2674  Expr *Operand,
2675  SourceLocation RParenLoc) {
2676  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2677  RParenLoc);
2678  }
2679 
2680  /// Build a new C++ __uuidof(type) expression.
2681  ///
2682  /// By default, performs semantic analysis to build the new expression.
2683  /// Subclasses may override this routine to provide different behavior.
2685  SourceLocation TypeidLoc,
2686  TypeSourceInfo *Operand,
2687  SourceLocation RParenLoc) {
2688  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2689  RParenLoc);
2690  }
2691 
2692  /// Build a new C++ __uuidof(expr) expression.
2693  ///
2694  /// By default, performs semantic analysis to build the new expression.
2695  /// Subclasses may override this routine to provide different behavior.
2697  SourceLocation TypeidLoc,
2698  Expr *Operand,
2699  SourceLocation RParenLoc) {
2700  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2701  RParenLoc);
2702  }
2703 
2704  /// Build a new C++ "this" expression.
2705  ///
2706  /// By default, builds a new "this" expression without performing any
2707  /// semantic analysis. Subclasses may override this routine to provide
2708  /// different behavior.
2710  QualType ThisType,
2711  bool isImplicit) {
2712  return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
2713  }
2714 
2715  /// Build a new C++ throw expression.
2716  ///
2717  /// By default, performs semantic analysis to build the new expression.
2718  /// Subclasses may override this routine to provide different behavior.
2720  bool IsThrownVariableInScope) {
2721  return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2722  }
2723 
2724  /// Build a new C++ default-argument expression.
2725  ///
2726  /// By default, builds a new default-argument expression, which does not
2727  /// require any semantic analysis. Subclasses may override this routine to
2728  /// provide different behavior.
2730  return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
2731  getSema().CurContext);
2732  }
2733 
2734  /// Build a new C++11 default-initialization expression.
2735  ///
2736  /// By default, builds a new default field initialization expression, which
2737  /// does not require any semantic analysis. Subclasses may override this
2738  /// routine to provide different behavior.
2740  FieldDecl *Field) {
2741  return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
2742  getSema().CurContext);
2743  }
2744 
2745  /// Build a new C++ zero-initialization expression.
2746  ///
2747  /// By default, performs semantic analysis to build the new expression.
2748  /// Subclasses may override this routine to provide different behavior.
2750  SourceLocation LParenLoc,
2751  SourceLocation RParenLoc) {
2752  return getSema().BuildCXXTypeConstructExpr(
2753  TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
2754  }
2755 
2756  /// Build a new C++ "new" expression.
2757  ///
2758  /// By default, performs semantic analysis to build the new expression.
2759  /// Subclasses may override this routine to provide different behavior.
2761  bool UseGlobal,
2762  SourceLocation PlacementLParen,
2763  MultiExprArg PlacementArgs,
2764  SourceLocation PlacementRParen,
2765  SourceRange TypeIdParens,
2766  QualType AllocatedType,
2767  TypeSourceInfo *AllocatedTypeInfo,
2768  Optional<Expr *> ArraySize,
2769  SourceRange DirectInitRange,
2770  Expr *Initializer) {
2771  return getSema().BuildCXXNew(StartLoc, UseGlobal,
2772  PlacementLParen,
2773  PlacementArgs,
2774  PlacementRParen,
2775  TypeIdParens,
2776  AllocatedType,
2777  AllocatedTypeInfo,
2778  ArraySize,
2779  DirectInitRange,
2780  Initializer);
2781  }
2782 
2783  /// Build a new C++ "delete" expression.
2784  ///
2785  /// By default, performs semantic analysis to build the new expression.
2786  /// Subclasses may override this routine to provide different behavior.
2788  bool IsGlobalDelete,
2789  bool IsArrayForm,
2790  Expr *Operand) {
2791  return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2792  Operand);
2793  }
2794 
2795  /// Build a new type trait expression.
2796  ///
2797  /// By default, performs semantic analysis to build the new expression.
2798  /// Subclasses may override this routine to provide different behavior.
2800  SourceLocation StartLoc,
2802  SourceLocation RParenLoc) {
2803  return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2804  }
2805 
2806  /// Build a new array type trait expression.
2807  ///
2808  /// By default, performs semantic analysis to build the new expression.
2809  /// Subclasses may override this routine to provide different behavior.
2811  SourceLocation StartLoc,
2812  TypeSourceInfo *TSInfo,
2813  Expr *DimExpr,
2814  SourceLocation RParenLoc) {
2815  return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2816  }
2817 
2818  /// Build a new expression trait expression.
2819  ///
2820  /// By default, performs semantic analysis to build the new expression.
2821  /// Subclasses may override this routine to provide different behavior.
2823  SourceLocation StartLoc,
2824  Expr *Queried,
2825  SourceLocation RParenLoc) {
2826  return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2827  }
2828 
2829  /// Build a new (previously unresolved) declaration reference
2830  /// expression.
2831  ///
2832  /// By default, performs semantic analysis to build the new expression.
2833  /// Subclasses may override this routine to provide different behavior.
2835  NestedNameSpecifierLoc QualifierLoc,
2836  SourceLocation TemplateKWLoc,
2837  const DeclarationNameInfo &NameInfo,
2838  const TemplateArgumentListInfo *TemplateArgs,
2839  bool IsAddressOfOperand,
2840  TypeSourceInfo **RecoveryTSI) {
2841  CXXScopeSpec SS;
2842  SS.Adopt(QualifierLoc);
2843 
2844  if (TemplateArgs || TemplateKWLoc.isValid())
2845  return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2846  TemplateArgs);
2847 
2848  return getSema().BuildQualifiedDeclarationNameExpr(
2849  SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2850  }
2851 
2852  /// Build a new template-id expression.
2853  ///
2854  /// By default, performs semantic analysis to build the new expression.
2855  /// Subclasses may override this routine to provide different behavior.
2857  SourceLocation TemplateKWLoc,
2858  LookupResult &R,
2859  bool RequiresADL,
2860  const TemplateArgumentListInfo *TemplateArgs) {
2861  return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2862  TemplateArgs);
2863  }
2864 
2865  /// Build a new object-construction expression.
2866  ///
2867  /// By default, performs semantic analysis to build the new expression.
2868  /// Subclasses may override this routine to provide different behavior.
2870  SourceLocation Loc,
2871  CXXConstructorDecl *Constructor,
2872  bool IsElidable,
2873  MultiExprArg Args,
2874  bool HadMultipleCandidates,
2875  bool ListInitialization,
2876  bool StdInitListInitialization,
2877  bool RequiresZeroInit,
2878  CXXConstructExpr::ConstructionKind ConstructKind,
2879  SourceRange ParenRange) {
2880  SmallVector<Expr*, 8> ConvertedArgs;
2881  if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2882  ConvertedArgs))
2883  return ExprError();
2884 
2885  return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2886  IsElidable,
2887  ConvertedArgs,
2888  HadMultipleCandidates,
2889  ListInitialization,
2890  StdInitListInitialization,
2891  RequiresZeroInit, ConstructKind,
2892  ParenRange);
2893  }
2894 
2895  /// Build a new implicit construction via inherited constructor
2896  /// expression.
2898  CXXConstructorDecl *Constructor,
2899  bool ConstructsVBase,
2900  bool InheritedFromVBase) {
2901  return new (getSema().Context) CXXInheritedCtorInitExpr(
2902  Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2903  }
2904 
2905  /// Build a new object-construction expression.
2906  ///
2907  /// By default, performs semantic analysis to build the new expression.
2908  /// Subclasses may override this routine to provide different behavior.
2910  SourceLocation LParenOrBraceLoc,
2911  MultiExprArg Args,
2912  SourceLocation RParenOrBraceLoc,
2913  bool ListInitialization) {
2914  return getSema().BuildCXXTypeConstructExpr(
2915  TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
2916  }
2917 
2918  /// Build a new object-construction expression.
2919  ///
2920  /// By default, performs semantic analysis to build the new expression.
2921  /// Subclasses may override this routine to provide different behavior.
2923  SourceLocation LParenLoc,
2924  MultiExprArg Args,
2925  SourceLocation RParenLoc,
2926  bool ListInitialization) {
2927  return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2928  RParenLoc, ListInitialization);
2929  }
2930 
2931  /// Build a new member reference expression.
2932  ///
2933  /// By default, performs semantic analysis to build the new expression.
2934  /// Subclasses may override this routine to provide different behavior.
2936  QualType BaseType,
2937  bool IsArrow,
2938  SourceLocation OperatorLoc,
2939  NestedNameSpecifierLoc QualifierLoc,
2940  SourceLocation TemplateKWLoc,
2941  NamedDecl *FirstQualifierInScope,
2942  const DeclarationNameInfo &MemberNameInfo,
2943  const TemplateArgumentListInfo *TemplateArgs) {
2944  CXXScopeSpec SS;
2945  SS.Adopt(QualifierLoc);
2946 
2947  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2948  OperatorLoc, IsArrow,
2949  SS, TemplateKWLoc,
2950  FirstQualifierInScope,
2951  MemberNameInfo,
2952  TemplateArgs, /*S*/nullptr);
2953  }
2954 
2955  /// Build a new member reference expression.
2956  ///
2957  /// By default, performs semantic analysis to build the new expression.
2958  /// Subclasses may override this routine to provide different behavior.
2960  SourceLocation OperatorLoc,
2961  bool IsArrow,
2962  NestedNameSpecifierLoc QualifierLoc,
2963  SourceLocation TemplateKWLoc,
2964  NamedDecl *FirstQualifierInScope,
2965  LookupResult &R,
2966  const TemplateArgumentListInfo *TemplateArgs) {
2967  CXXScopeSpec SS;
2968  SS.Adopt(QualifierLoc);
2969 
2970  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2971  OperatorLoc, IsArrow,
2972  SS, TemplateKWLoc,
2973  FirstQualifierInScope,
2974  R, TemplateArgs, /*S*/nullptr);
2975  }
2976 
2977  /// Build a new noexcept expression.
2978  ///
2979  /// By default, performs semantic analysis to build the new expression.
2980  /// Subclasses may override this routine to provide different behavior.
2982  return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2983  }
2984 
2985  /// Build a new expression to compute the length of a parameter pack.
2987  NamedDecl *Pack,
2988  SourceLocation PackLoc,
2989  SourceLocation RParenLoc,
2990  Optional<unsigned> Length,
2991  ArrayRef<TemplateArgument> PartialArgs) {
2992  return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2993  RParenLoc, Length, PartialArgs);
2994  }
2995 
2996  /// Build a new expression representing a call to a source location
2997  /// builtin.
2998  ///
2999  /// By default, performs semantic analysis to build the new expression.
3000  /// Subclasses may override this routine to provide different behavior.
3002  SourceLocation BuiltinLoc,
3003  SourceLocation RPLoc,
3004  DeclContext *ParentContext) {
3005  return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3006  }
3007 
3008  /// Build a new Objective-C boxed expression.
3009  ///
3010  /// By default, performs semantic analysis to build the new expression.
3011  /// Subclasses may override this routine to provide different behavior.
3013  return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3014  }
3015 
3016  /// Build a new Objective-C array literal.
3017  ///
3018  /// By default, performs semantic analysis to build the new expression.
3019  /// Subclasses may override this routine to provide different behavior.
3021  Expr **Elements, unsigned NumElements) {
3022  return getSema().BuildObjCArrayLiteral(Range,
3023  MultiExprArg(Elements, NumElements));
3024  }
3025 
3027  Expr *Base, Expr *Key,
3028  ObjCMethodDecl *getterMethod,
3029  ObjCMethodDecl *setterMethod) {
3030  return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3031  getterMethod, setterMethod);
3032  }
3033 
3034  /// Build a new Objective-C dictionary literal.
3035  ///
3036  /// By default, performs semantic analysis to build the new expression.
3037  /// Subclasses may override this routine to provide different behavior.
3040  return getSema().BuildObjCDictionaryLiteral(Range, Elements);
3041  }
3042 
3043  /// Build a new Objective-C \@encode expression.
3044  ///
3045  /// By default, performs semantic analysis to build the new expression.
3046  /// Subclasses may override this routine to provide different behavior.
3048  TypeSourceInfo *EncodeTypeInfo,
3049  SourceLocation RParenLoc) {
3050  return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
3051  }
3052 
3053  /// Build a new Objective-C class message.
3055  Selector Sel,
3056  ArrayRef<SourceLocation> SelectorLocs,
3057  ObjCMethodDecl *Method,
3058  SourceLocation LBracLoc,
3059  MultiExprArg Args,
3060  SourceLocation RBracLoc) {
3061  return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3062  ReceiverTypeInfo->getType(),
3063  /*SuperLoc=*/SourceLocation(),
3064  Sel, Method, LBracLoc, SelectorLocs,
3065  RBracLoc, Args);
3066  }
3067 
3068  /// Build a new Objective-C instance message.
3070  Selector Sel,
3071  ArrayRef<SourceLocation> SelectorLocs,
3072  ObjCMethodDecl *Method,
3073  SourceLocation LBracLoc,
3074  MultiExprArg Args,
3075  SourceLocation RBracLoc) {
3076  return SemaRef.BuildInstanceMessage(Receiver,
3077  Receiver->getType(),
3078  /*SuperLoc=*/SourceLocation(),
3079  Sel, Method, LBracLoc, SelectorLocs,
3080  RBracLoc, Args);
3081  }
3082 
3083  /// Build a new Objective-C instance/class message to 'super'.
3085  Selector Sel,
3086  ArrayRef<SourceLocation> SelectorLocs,
3087  QualType SuperType,
3088  ObjCMethodDecl *Method,
3089  SourceLocation LBracLoc,
3090  MultiExprArg Args,
3091  SourceLocation RBracLoc) {
3092  return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3093  SuperType,
3094  SuperLoc,
3095  Sel, Method, LBracLoc, SelectorLocs,
3096  RBracLoc, Args)
3097  : SemaRef.BuildClassMessage(nullptr,
3098  SuperType,
3099  SuperLoc,
3100  Sel, Method, LBracLoc, SelectorLocs,
3101  RBracLoc, Args);
3102 
3103 
3104  }
3105 
3106  /// Build a new Objective-C ivar reference expression.
3107  ///
3108  /// By default, performs semantic analysis to build the new expression.
3109  /// Subclasses may override this routine to provide different behavior.
3111  SourceLocation IvarLoc,
3112  bool IsArrow, bool IsFreeIvar) {
3113  CXXScopeSpec SS;
3114  DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3115  ExprResult Result = getSema().BuildMemberReferenceExpr(
3116  BaseArg, BaseArg->getType(),
3117  /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3118  /*FirstQualifierInScope=*/nullptr, NameInfo,
3119  /*TemplateArgs=*/nullptr,
3120  /*S=*/nullptr);
3121  if (IsFreeIvar && Result.isUsable())
3122  cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3123  return Result;
3124  }
3125 
3126  /// Build a new Objective-C property reference expression.
3127  ///
3128  /// By default, performs semantic analysis to build the new expression.
3129  /// Subclasses may override this routine to provide different behavior.
3131  ObjCPropertyDecl *Property,
3132  SourceLocation PropertyLoc) {
3133  CXXScopeSpec SS;
3134  DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3135  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3136  /*FIXME:*/PropertyLoc,
3137  /*IsArrow=*/false,
3138  SS, SourceLocation(),
3139  /*FirstQualifierInScope=*/nullptr,
3140  NameInfo,
3141  /*TemplateArgs=*/nullptr,
3142  /*S=*/nullptr);
3143  }
3144 
3145  /// Build a new Objective-C property reference expression.
3146  ///
3147  /// By default, performs semantic analysis to build the new expression.
3148  /// Subclasses may override this routine to provide different behavior.
3150  ObjCMethodDecl *Getter,
3151  ObjCMethodDecl *Setter,
3152  SourceLocation PropertyLoc) {
3153  // Since these expressions can only be value-dependent, we do not
3154  // need to perform semantic analysis again.
3155  return Owned(
3156  new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3158  PropertyLoc, Base));
3159  }
3160 
3161  /// Build a new Objective-C "isa" expression.
3162  ///
3163  /// By default, performs semantic analysis to build the new expression.
3164  /// Subclasses may override this routine to provide different behavior.
3166  SourceLocation OpLoc, bool IsArrow) {
3167  CXXScopeSpec SS;
3168  DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3169  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3170  OpLoc, IsArrow,
3171  SS, SourceLocation(),
3172  /*FirstQualifierInScope=*/nullptr,
3173  NameInfo,
3174  /*TemplateArgs=*/nullptr,
3175  /*S=*/nullptr);
3176  }
3177 
3178  /// Build a new shuffle vector expression.
3179  ///
3180  /// By default, performs semantic analysis to build the new expression.
3181  /// Subclasses may override this routine to provide different behavior.
3183  MultiExprArg SubExprs,
3184  SourceLocation RParenLoc) {
3185  // Find the declaration for __builtin_shufflevector
3186  const IdentifierInfo &Name
3187  = SemaRef.Context.Idents.get("__builtin_shufflevector");
3189  DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3190  assert(!Lookup.empty() && "No __builtin_shufflevector?");
3191 
3192  // Build a reference to the __builtin_shufflevector builtin
3193  FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3194  Expr *Callee = new (SemaRef.Context)
3195  DeclRefExpr(SemaRef.Context, Builtin, false,
3196  SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
3197  QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3198  Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3199  CK_BuiltinFnToFnPtr).get();
3200 
3201  // Build the CallExpr
3202  ExprResult TheCall = CallExpr::Create(
3203  SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3204  Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3205 
3206  // Type-check the __builtin_shufflevector expression.
3207  return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3208  }
3209 
3210  /// Build a new convert vector expression.
3212  Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3213  SourceLocation RParenLoc) {
3214  return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3215  BuiltinLoc, RParenLoc);
3216  }
3217 
3218  /// Build a new template argument pack expansion.
3219  ///
3220  /// By default, performs semantic analysis to build a new pack expansion
3221  /// for a template argument. Subclasses may override this routine to provide
3222  /// different behavior.
3224  SourceLocation EllipsisLoc,
3225  Optional<unsigned> NumExpansions) {
3226  switch (Pattern.getArgument().getKind()) {
3228  ExprResult Result
3229  = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3230  EllipsisLoc, NumExpansions);
3231  if (Result.isInvalid())
3232  return TemplateArgumentLoc();
3233 
3234  return TemplateArgumentLoc(Result.get(), Result.get());
3235  }
3236 
3239  Pattern.getArgument().getAsTemplate(),
3240  NumExpansions),
3241  Pattern.getTemplateQualifierLoc(),
3242  Pattern.getTemplateNameLoc(),
3243  EllipsisLoc);
3244 
3251  llvm_unreachable("Pack expansion pattern has no parameter packs");
3252 
3254  if (TypeSourceInfo *Expansion
3255  = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3256  EllipsisLoc,
3257  NumExpansions))
3258  return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3259  Expansion);
3260  break;
3261  }
3262 
3263  return TemplateArgumentLoc();
3264  }
3265 
3266  /// Build a new expression pack expansion.
3267  ///
3268  /// By default, performs semantic analysis to build a new pack expansion
3269  /// for an expression. Subclasses may override this routine to provide
3270  /// different behavior.
3272  Optional<unsigned> NumExpansions) {
3273  return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3274  }
3275 
3276  /// Build a new C++1z fold-expression.
3277  ///
3278  /// By default, performs semantic analysis in order to build a new fold
3279  /// expression.
3281  BinaryOperatorKind Operator,
3282  SourceLocation EllipsisLoc, Expr *RHS,
3283  SourceLocation RParenLoc,
3284  Optional<unsigned> NumExpansions) {
3285  return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3286  RHS, RParenLoc, NumExpansions);
3287  }
3288 
3289  /// Build an empty C++1z fold-expression with the given operator.
3290  ///
3291  /// By default, produces the fallback value for the fold-expression, or
3292  /// produce an error if there is no fallback value.
3294  BinaryOperatorKind Operator) {
3295  return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3296  }
3297 
3298  /// Build a new atomic operation expression.
3299  ///
3300  /// By default, performs semantic analysis to build the new expression.
3301  /// Subclasses may override this routine to provide different behavior.
3303  MultiExprArg SubExprs,
3304  QualType RetTy,
3306  SourceLocation RParenLoc) {
3307  // Just create the expression; there is not any interesting semantic
3308  // analysis here because we can't actually build an AtomicExpr until
3309  // we are sure it is semantically sound.
3310  return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3311  RParenLoc);
3312  }
3313 
3314 private:
3315  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3316  QualType ObjectType,
3317  NamedDecl *FirstQualifierInScope,
3318  CXXScopeSpec &SS);
3319 
3320  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3321  QualType ObjectType,
3322  NamedDecl *FirstQualifierInScope,
3323  CXXScopeSpec &SS);
3324 
3325  TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3326  NamedDecl *FirstQualifierInScope,
3327  CXXScopeSpec &SS);
3328 
3329  QualType TransformDependentNameType(TypeLocBuilder &TLB,
3331  bool DeducibleTSTContext);
3332 };
3333 
3334 template <typename Derived>
3336  if (!S)
3337  return S;
3338 
3339  switch (S->getStmtClass()) {
3340  case Stmt::NoStmtClass: break;
3341 
3342  // Transform individual statement nodes
3343  // Pass SDK into statements that can produce a value
3344 #define STMT(Node, Parent) \
3345  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3346 #define VALUESTMT(Node, Parent) \
3347  case Stmt::Node##Class: \
3348  return getDerived().Transform##Node(cast<Node>(S), SDK);
3349 #define ABSTRACT_STMT(Node)
3350 #define EXPR(Node, Parent)
3351 #include "clang/AST/StmtNodes.inc"
3352 
3353  // Transform expressions by calling TransformExpr.
3354 #define STMT(Node, Parent)
3355 #define ABSTRACT_STMT(Stmt)
3356 #define EXPR(Node, Parent) case Stmt::Node##Class:
3357 #include "clang/AST/StmtNodes.inc"
3358  {
3359  ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3360 
3361  if (SDK == SDK_StmtExprResult)
3362  E = getSema().ActOnStmtExprResult(E);
3363  return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
3364  }
3365  }
3366 
3367  return S;
3368 }
3369 
3370 template<typename Derived>
3372  if (!S)
3373  return S;
3374 
3375  switch (S->getClauseKind()) {
3376  default: break;
3377  // Transform individual clause nodes
3378 #define OPENMP_CLAUSE(Name, Class) \
3379  case OMPC_ ## Name : \
3380  return getDerived().Transform ## Class(cast<Class>(S));
3381 #include "clang/Basic/OpenMPKinds.def"
3382  }
3383 
3384  return S;
3385 }
3386 
3387 
3388 template<typename Derived>
3390  if (!E)
3391  return E;
3392 
3393  switch (E->getStmtClass()) {
3394  case Stmt::NoStmtClass: break;
3395 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3396 #define ABSTRACT_STMT(Stmt)
3397 #define EXPR(Node, Parent) \
3398  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3399 #include "clang/AST/StmtNodes.inc"
3400  }
3401 
3402  return E;
3403 }
3404 
3405 template<typename Derived>
3407  bool NotCopyInit) {
3408  // Initializers are instantiated like expressions, except that various outer
3409  // layers are stripped.
3410  if (!Init)
3411  return Init;
3412 
3413  if (auto *FE = dyn_cast<FullExpr>(Init))
3414  Init = FE->getSubExpr();
3415 
3416  if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3417  Init = AIL->getCommonExpr();
3418 
3419  if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3420  Init = MTE->GetTemporaryExpr();
3421 
3422  while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3423  Init = Binder->getSubExpr();
3424 
3425  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3426  Init = ICE->getSubExprAsWritten();
3427 
3428  if (CXXStdInitializerListExpr *ILE =
3429  dyn_cast<CXXStdInitializerListExpr>(Init))
3430  return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3431 
3432  // If this is copy-initialization, we only need to reconstruct
3433  // InitListExprs. Other forms of copy-initialization will be a no-op if
3434  // the initializer is already the right type.
3435  CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3436  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3437  return getDerived().TransformExpr(Init);
3438 
3439  // Revert value-initialization back to empty parens.
3440  if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3441  SourceRange Parens = VIE->getSourceRange();
3442  return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3443  Parens.getEnd());
3444  }
3445 
3446  // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3447  if (isa<ImplicitValueInitExpr>(Init))
3448  return getDerived().RebuildParenListExpr(SourceLocation(), None,
3449  SourceLocation());
3450 
3451  // Revert initialization by constructor back to a parenthesized or braced list
3452  // of expressions. Any other form of initializer can just be reused directly.
3453  if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3454  return getDerived().TransformExpr(Init);
3455 
3456  // If the initialization implicitly converted an initializer list to a
3457  // std::initializer_list object, unwrap the std::initializer_list too.
3458  if (Construct && Construct->isStdInitListInitialization())
3459  return TransformInitializer(Construct->getArg(0), NotCopyInit);
3460 
3461  // Enter a list-init context if this was list initialization.
3464  Construct->isListInitialization());
3465 
3466  SmallVector<Expr*, 8> NewArgs;
3467  bool ArgChanged = false;
3468  if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3469  /*IsCall*/true, NewArgs, &ArgChanged))
3470  return ExprError();
3471 
3472  // If this was list initialization, revert to syntactic list form.
3473  if (Construct->isListInitialization())
3474  return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
3475  Construct->getEndLoc());
3476 
3477  // Build a ParenListExpr to represent anything else.
3478  SourceRange Parens = Construct->getParenOrBraceRange();
3479  if (Parens.isInvalid()) {
3480  // This was a variable declaration's initialization for which no initializer
3481  // was specified.
3482  assert(NewArgs.empty() &&
3483  "no parens or braces but have direct init with arguments?");
3484  return ExprEmpty();
3485  }
3486  return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3487  Parens.getEnd());
3488 }
3489 
3490 template<typename Derived>
3492  unsigned NumInputs,
3493  bool IsCall,
3494  SmallVectorImpl<Expr *> &Outputs,
3495  bool *ArgChanged) {
3496  for (unsigned I = 0; I != NumInputs; ++I) {
3497  // If requested, drop call arguments that need to be dropped.
3498  if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3499  if (ArgChanged)
3500  *ArgChanged = true;
3501 
3502  break;
3503  }
3504 
3505  if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3506  Expr *Pattern = Expansion->getPattern();
3507 
3509  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3510  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3511 
3512  // Determine whether the set of unexpanded parameter packs can and should
3513  // be expanded.
3514  bool Expand = true;
3515  bool RetainExpansion = false;
3516  Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3517  Optional<unsigned> NumExpansions = OrigNumExpansions;
3518  if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3519  Pattern->getSourceRange(),
3520  Unexpanded,
3521  Expand, RetainExpansion,
3522  NumExpansions))
3523  return true;
3524 
3525  if (!Expand) {
3526  // The transform has determined that we should perform a simple
3527  // transformation on the pack expansion, producing another pack
3528  // expansion.
3529  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3530  ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3531  if (OutPattern.isInvalid())
3532  return true;
3533 
3534  ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3535  Expansion->getEllipsisLoc(),
3536  NumExpansions);
3537  if (Out.isInvalid())
3538  return true;
3539 
3540  if (ArgChanged)
3541  *ArgChanged = true;
3542  Outputs.push_back(Out.get());
3543  continue;
3544  }
3545 
3546  // Record right away that the argument was changed. This needs
3547  // to happen even if the array expands to nothing.
3548  if (ArgChanged) *ArgChanged = true;
3549 
3550  // The transform has determined that we should perform an elementwise
3551  // expansion of the pattern. Do so.
3552  for (unsigned I = 0; I != *NumExpansions; ++I) {
3553  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3554  ExprResult Out = getDerived().TransformExpr(Pattern);
3555  if (Out.isInvalid())
3556  return true;
3557 
3558  if (Out.get()->containsUnexpandedParameterPack()) {
3559  Out = getDerived().RebuildPackExpansion(
3560  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3561  if (Out.isInvalid())
3562  return true;
3563  }
3564 
3565  Outputs.push_back(Out.get());
3566  }
3567 
3568  // If we're supposed to retain a pack expansion, do so by temporarily
3569  // forgetting the partially-substituted parameter pack.
3570  if (RetainExpansion) {
3571  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3572 
3573  ExprResult Out = getDerived().TransformExpr(Pattern);
3574  if (Out.isInvalid())
3575  return true;
3576 
3577  Out = getDerived().RebuildPackExpansion(
3578  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3579  if (Out.isInvalid())
3580  return true;
3581 
3582  Outputs.push_back(Out.get());
3583  }
3584 
3585  continue;
3586  }
3587 
3588  ExprResult Result =
3589  IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3590  : getDerived().TransformExpr(Inputs[I]);
3591  if (Result.isInvalid())
3592  return true;
3593 
3594  if (Result.get() != Inputs[I] && ArgChanged)
3595  *ArgChanged = true;
3596 
3597  Outputs.push_back(Result.get());
3598  }
3599 
3600  return false;
3601 }
3602 
3603 template <typename Derived>
3606  if (Var) {
3607  VarDecl *ConditionVar = cast_or_null<VarDecl>(
3608  getDerived().TransformDefinition(Var->getLocation(), Var));
3609 
3610  if (!ConditionVar)
3611  return Sema::ConditionError();
3612 
3613  return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3614  }
3615 
3616  if (Expr) {
3617  ExprResult CondExpr = getDerived().TransformExpr(Expr);
3618 
3619  if (CondExpr.isInvalid())
3620  return Sema::ConditionError();
3621 
3622  return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3623  }
3624 
3625  return Sema::ConditionResult();
3626 }
3627 
3628 template<typename Derived>
3632  QualType ObjectType,
3633  NamedDecl *FirstQualifierInScope) {
3635  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3636  Qualifier = Qualifier.getPrefix())
3637  Qualifiers.push_back(Qualifier);
3638 
3639  CXXScopeSpec SS;
3640  while (!Qualifiers.empty()) {
3641  NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3643 
3644  switch (QNNS->getKind()) {
3647  Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3648  if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3649  SS, FirstQualifierInScope, false))
3650  return NestedNameSpecifierLoc();
3651  }
3652  break;
3653 
3655  NamespaceDecl *NS
3656  = cast_or_null<NamespaceDecl>(
3657  getDerived().TransformDecl(
3658  Q.getLocalBeginLoc(),
3659  QNNS->getAsNamespace()));
3660  SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3661  break;
3662  }
3663 
3665  NamespaceAliasDecl *Alias
3666  = cast_or_null<NamespaceAliasDecl>(
3667  getDerived().TransformDecl(Q.getLocalBeginLoc(),
3668  QNNS->getAsNamespaceAlias()));
3669  SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3670  Q.getLocalEndLoc());
3671  break;
3672  }
3673 
3675  // There is no meaningful transformation that one could perform on the
3676  // global scope.
3677  SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3678  break;
3679 
3681  CXXRecordDecl *RD =
3682  cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3683  SourceLocation(), QNNS->getAsRecordDecl()));
3684  SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3685  break;
3686  }
3687 
3690  TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3691  FirstQualifierInScope, SS);
3692 
3693  if (!TL)
3694  return NestedNameSpecifierLoc();
3695 
3696  if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3697  (SemaRef.getLangOpts().CPlusPlus11 &&
3698  TL.getType()->isEnumeralType())) {
3699  assert(!TL.getType().hasLocalQualifiers() &&
3700  "Can't get cv-qualifiers here");
3701  if (TL.getType()->isEnumeralType())
3702  SemaRef.Diag(TL.getBeginLoc(),
3703  diag::warn_cxx98_compat_enum_nested_name_spec);
3704  SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3705  Q.getLocalEndLoc());
3706  break;
3707  }
3708  // If the nested-name-specifier is an invalid type def, don't emit an
3709  // error because a previous error should have already been emitted.
3710  TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3711  if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3712  SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3713  << TL.getType() << SS.getRange();
3714  }
3715  return NestedNameSpecifierLoc();
3716  }
3717  }
3718 
3719  // The qualifier-in-scope and object type only apply to the leftmost entity.
3720  FirstQualifierInScope = nullptr;
3721  ObjectType = QualType();
3722  }
3723 
3724  // Don't rebuild the nested-name-specifier if we don't have to.
3725  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3726  !getDerived().AlwaysRebuild())
3727  return NNS;
3728 
3729  // If we can re-use the source-location data from the original
3730  // nested-name-specifier, do so.
3731  if (SS.location_size() == NNS.getDataLength() &&
3732  memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3733  return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3734 
3735  // Allocate new nested-name-specifier location information.
3736  return SS.getWithLocInContext(SemaRef.Context);
3737 }
3738 
3739 template<typename Derived>
3743  DeclarationName Name = NameInfo.getName();
3744  if (!Name)
3745  return DeclarationNameInfo();
3746 
3747  switch (Name.getNameKind()) {
3755  return NameInfo;
3756 
3758  TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3759  TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3760  getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3761  if (!NewTemplate)
3762  return DeclarationNameInfo();
3763 
3764  DeclarationNameInfo NewNameInfo(NameInfo);
3765  NewNameInfo.setName(
3766  SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3767  return NewNameInfo;
3768  }
3769 
3773  TypeSourceInfo *NewTInfo;
3774  CanQualType NewCanTy;
3775  if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3776  NewTInfo = getDerived().TransformType(OldTInfo);
3777  if (!NewTInfo)
3778  return DeclarationNameInfo();
3779  NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3780  }
3781  else {
3782  NewTInfo = nullptr;
3783  TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3784  QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3785  if (NewT.isNull())
3786  return DeclarationNameInfo();
3787  NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3788  }
3789 
3790  DeclarationName NewName
3791  = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3792  NewCanTy);
3793  DeclarationNameInfo NewNameInfo(NameInfo);
3794  NewNameInfo.setName(NewName);
3795  NewNameInfo.setNamedTypeInfo(NewTInfo);
3796  return NewNameInfo;
3797  }
3798  }
3799 
3800  llvm_unreachable("Unknown name kind.");
3801 }
3802 
3803 template<typename Derived>
3806  TemplateName Name,
3807  SourceLocation NameLoc,
3808  QualType ObjectType,
3809  NamedDecl *FirstQualifierInScope,
3810  bool AllowInjectedClassName) {
3812  TemplateDecl *Template = QTN->getTemplateDecl();
3813  assert(Template && "qualified template name must refer to a template");
3814 
3815  TemplateDecl *TransTemplate
3816  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3817  Template));
3818  if (!TransTemplate)
3819  return TemplateName();
3820 
3821  if (!getDerived().AlwaysRebuild() &&
3822  SS.getScopeRep() == QTN->getQualifier() &&
3823  TransTemplate == Template)
3824  return Name;
3825 
3826  return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3827  TransTemplate);
3828  }
3829 
3831  if (SS.getScopeRep()) {
3832  // These apply to the scope specifier, not the template.
3833  ObjectType = QualType();
3834  FirstQualifierInScope = nullptr;
3835  }
3836 
3837  if (!getDerived().AlwaysRebuild() &&
3838  SS.getScopeRep() == DTN->getQualifier() &&
3839  ObjectType.isNull())
3840  return Name;
3841 
3842  // FIXME: Preserve the location of the "template" keyword.
3843  SourceLocation TemplateKWLoc = NameLoc;
3844 
3845  if (DTN->isIdentifier()) {
3846  return getDerived().RebuildTemplateName(SS,
3847  TemplateKWLoc,
3848  *DTN->getIdentifier(),
3849  NameLoc,
3850  ObjectType,
3851  FirstQualifierInScope,
3852  AllowInjectedClassName);
3853  }
3854 
3855  return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3856  DTN->getOperator(), NameLoc,
3857  ObjectType, AllowInjectedClassName);
3858  }
3859 
3860  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3861  TemplateDecl *TransTemplate
3862  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3863  Template));
3864  if (!TransTemplate)
3865  return TemplateName();
3866 
3867  if (!getDerived().AlwaysRebuild() &&
3868  TransTemplate == Template)
3869  return Name;
3870 
3871  return TemplateName(TransTemplate);
3872  }
3873 
3876  TemplateTemplateParmDecl *TransParam
3877  = cast_or_null<TemplateTemplateParmDecl>(
3878  getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3879  if (!TransParam)
3880  return TemplateName();
3881 
3882  if (!getDerived().AlwaysRebuild() &&
3883  TransParam == SubstPack->getParameterPack())
3884  return Name;
3885 
3886  return getDerived().RebuildTemplateName(TransParam,
3887  SubstPack->getArgumentPack());
3888  }
3889 
3890  // These should be getting filtered out before they reach the AST.
3891  llvm_unreachable("overloaded function decl survived to here");
3892 }
3893 
3894 template<typename Derived>
3896  const TemplateArgument &Arg,
3897  TemplateArgumentLoc &Output) {
3898  SourceLocation Loc = getDerived().getBaseLocation();
3899  switch (Arg.getKind()) {
3901  llvm_unreachable("null template argument in TreeTransform");
3902  break;
3903 
3905  Output = TemplateArgumentLoc(Arg,
3906  SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3907 
3908  break;
3909 
3914  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3915  Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3916  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3917  Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3918 
3919  if (Arg.getKind() == TemplateArgument::Template)
3920  Output = TemplateArgumentLoc(Arg,
3921  Builder.getWithLocInContext(SemaRef.Context),
3922  Loc);
3923  else
3924  Output = TemplateArgumentLoc(Arg,
3925  Builder.getWithLocInContext(SemaRef.Context),
3926  Loc, Loc);
3927 
3928  break;
3929  }
3930 
3932  Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3933  break;
3934 
3940  break;
3941  }
3942 }
3943 
3944 template<typename Derived>
3946  const TemplateArgumentLoc &Input,
3947  TemplateArgumentLoc &Output, bool Uneval) {
3950  /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3952  const TemplateArgument &Arg = Input.getArgument();
3953  switch (Arg.getKind()) {
3959  llvm_unreachable("Unexpected TemplateArgument");
3960 
3961  case TemplateArgument::Type: {
3962  TypeSourceInfo *DI = Input.getTypeSourceInfo();
3963  if (!DI)
3964  DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3965 
3966  DI = getDerived().TransformType(DI);
3967  if (!DI) return true;
3968 
3969  Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3970  return false;
3971  }
3972 
3974  NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3975  if (QualifierLoc) {
3976  QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3977  if (!QualifierLoc)
3978  return true;
3979  }
3980 
3981  CXXScopeSpec SS;
3982  SS.Adopt(QualifierLoc);
3983  TemplateName Template
3984  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3985  Input.getTemplateNameLoc());
3986  if (Template.isNull())
3987  return true;
3988 
3989  Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3990  Input.getTemplateNameLoc());
3991  return false;
3992  }
3993 
3995  llvm_unreachable("Caller should expand pack expansions");
3996 
3998  // Template argument expressions are constant expressions.
4000  getSema(), Uneval
4003 
4004  Expr *InputExpr = Input.getSourceExpression();
4005  if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
4006 
4007  ExprResult E = getDerived().TransformExpr(InputExpr);
4008  E = SemaRef.ActOnConstantExpression(E);
4009  if (E.isInvalid()) return true;
4010  Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4011  return false;
4012  }
4013  }
4014 
4015  // Work around bogus GCC warning
4016  return true;
4017 }
4018 
4019 /// Iterator adaptor that invents template argument location information
4020 /// for each of the template arguments in its underlying iterator.
4021 template<typename Derived, typename InputIterator>
4023  TreeTransform<Derived> &Self;
4024  InputIterator Iter;
4025 
4026 public:
4029  typedef typename std::iterator_traits<InputIterator>::difference_type
4031  typedef std::input_iterator_tag iterator_category;
4032 
4033  class pointer {
4034  TemplateArgumentLoc Arg;
4035 
4036  public:
4037  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4038 
4039  const TemplateArgumentLoc *operator->() const { return &Arg; }
4040  };
4041 
4043 
4045  InputIterator Iter)
4046  : Self(Self), Iter(Iter) { }
4047 
4049  ++Iter;
4050  return *this;
4051  }
4052 
4055  ++(*this);
4056  return Old;
4057  }
4058 
4059  reference operator*() const {
4060  TemplateArgumentLoc Result;
4061  Self.InventTemplateArgumentLoc(*Iter, Result);
4062  return Result;
4063  }
4064 
4065  pointer operator->() const { return pointer(**this); }
4066 
4069  return X.Iter == Y.Iter;
4070  }
4071 
4074  return X.Iter != Y.Iter;
4075  }
4076 };
4077 
4078 template<typename Derived>
4079 template<typename InputIterator>
4081  InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4082  bool Uneval) {
4083  for (; First != Last; ++First) {
4084  TemplateArgumentLoc Out;
4085  TemplateArgumentLoc In = *First;
4086 
4087  if (In.getArgument().getKind() == TemplateArgument::Pack) {
4088  // Unpack argument packs, which we translate them into separate
4089  // arguments.
4090  // FIXME: We could do much better if we could guarantee that the
4091  // TemplateArgumentLocInfo for the pack expansion would be usable for
4092  // all of the template arguments in the argument pack.
4093  typedef TemplateArgumentLocInventIterator<Derived,
4095  PackLocIterator;
4096  if (TransformTemplateArguments(PackLocIterator(*this,
4097  In.getArgument().pack_begin()),
4098  PackLocIterator(*this,
4099  In.getArgument().pack_end()),
4100  Outputs, Uneval))
4101  return true;
4102 
4103  continue;
4104  }
4105 
4106  if (In.getArgument().isPackExpansion()) {
4107  // We have a pack expansion, for which we will be substituting into
4108  // the pattern.
4109  SourceLocation Ellipsis;
4110  Optional<unsigned> OrigNumExpansions;
4111  TemplateArgumentLoc Pattern
4112  = getSema().getTemplateArgumentPackExpansionPattern(
4113  In, Ellipsis, OrigNumExpansions);
4114 
4116  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4117  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4118 
4119  // Determine whether the set of unexpanded parameter packs can and should
4120  // be expanded.
4121  bool Expand = true;
4122  bool RetainExpansion = false;
4123  Optional<unsigned> NumExpansions = OrigNumExpansions;
4124  if (getDerived().TryExpandParameterPacks(Ellipsis,
4125  Pattern.getSourceRange(),
4126  Unexpanded,
4127  Expand,
4128  RetainExpansion,
4129  NumExpansions))
4130  return true;
4131 
4132  if (!Expand) {
4133  // The transform has determined that we should perform a simple
4134  // transformation on the pack expansion, producing another pack
4135  // expansion.
4136  TemplateArgumentLoc OutPattern;
4137  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4138  if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4139  return true;
4140 
4141  Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4142  NumExpansions);
4143  if (Out.getArgument().isNull())
4144  return true;
4145 
4146  Outputs.addArgument(Out);
4147  continue;
4148  }
4149 
4150  // The transform has determined that we should perform an elementwise
4151  // expansion of the pattern. Do so.
4152  for (unsigned I = 0; I != *NumExpansions; ++I) {
4153  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4154 
4155  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4156  return true;
4157 
4159  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4160  OrigNumExpansions);
4161  if (Out.getArgument().isNull())
4162  return true;
4163  }
4164 
4165  Outputs.addArgument(Out);
4166  }
4167 
4168  // If we're supposed to retain a pack expansion, do so by temporarily
4169  // forgetting the partially-substituted parameter pack.
4170  if (RetainExpansion) {
4171  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4172 
4173  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4174  return true;
4175 
4176  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4177  OrigNumExpansions);
4178  if (Out.getArgument().isNull())
4179  return true;
4180 
4181  Outputs.addArgument(Out);
4182  }
4183 
4184  continue;
4185  }
4186 
4187  // The simple case:
4188  if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4189  return true;
4190 
4191  Outputs.addArgument(Out);
4192  }
4193 
4194  return false;
4195 
4196 }
4197 
4198 //===----------------------------------------------------------------------===//
4199 // Type transformation
4200 //===----------------------------------------------------------------------===//
4201 
4202 template<typename Derived>
4204  if (getDerived().AlreadyTransformed(T))
4205  return T;
4206 
4207  // Temporary workaround. All of these transformations should
4208  // eventually turn into transformations on TypeLocs.
4209  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4210  getDerived().getBaseLocation());
4211 
4212  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4213 
4214  if (!NewDI)
4215  return QualType();
4216 
4217  return NewDI->getType();
4218 }
4219 
4220 template<typename Derived>
4222  // Refine the base location to the type's location.
4223  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4224  getDerived().getBaseEntity());
4225  if (getDerived().AlreadyTransformed(DI->getType()))
4226  return DI;
4227 
4228  TypeLocBuilder TLB;
4229 
4230  TypeLoc TL = DI->getTypeLoc();
4231  TLB.reserve(TL.getFullDataSize());
4232 
4233  QualType Result = getDerived().TransformType(TLB, TL);
4234  if (Result.isNull())
4235  return nullptr;
4236 
4237  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4238 }
4239 
4240 template<typename Derived>
4241 QualType
4243  switch (T.getTypeLocClass()) {
4244 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4245 #define TYPELOC(CLASS, PARENT) \
4246  case TypeLoc::CLASS: \
4247  return getDerived().Transform##CLASS##Type(TLB, \
4248  T.castAs<CLASS##TypeLoc>());
4249 #include "clang/AST/TypeLocNodes.def"
4250  }
4251 
4252  llvm_unreachable("unhandled type loc!");
4253 }
4254 
4255 template<typename Derived>
4257  if (!isa<DependentNameType>(T))
4258  return TransformType(T);
4259 
4260  if (getDerived().AlreadyTransformed(T))
4261  return T;
4262  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4263  getDerived().getBaseLocation());
4264  TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4265  return NewDI ? NewDI->getType() : QualType();
4266 }
4267 
4268 template<typename Derived>
4271  if (!isa<DependentNameType>(DI->getType()))
4272  return TransformType(DI);
4273 
4274  // Refine the base location to the type's location.
4275  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4276  getDerived().getBaseEntity());
4277  if (getDerived().AlreadyTransformed(DI->getType()))
4278  return DI;
4279 
4280  TypeLocBuilder TLB;
4281 
4282  TypeLoc TL = DI->getTypeLoc();
4283  TLB.reserve(TL.getFullDataSize());
4284 
4285  auto QTL = TL.getAs<QualifiedTypeLoc>();
4286  if (QTL)
4287  TL = QTL.getUnqualifiedLoc();
4288 
4289  auto DNTL = TL.castAs<DependentNameTypeLoc>();
4290 
4291  QualType Result = getDerived().TransformDependentNameType(
4292  TLB, DNTL, /*DeducedTSTContext*/true);
4293  if (Result.isNull())
4294  return nullptr;
4295 
4296  if (QTL) {
4297  Result = getDerived().RebuildQualifiedType(Result, QTL);
4298  if (Result.isNull())
4299  return nullptr;
4300  TLB.TypeWasModifiedSafely(Result);
4301  }
4302 
4303  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4304 }
4305 
4306 template<typename Derived>
4307 QualType
4309  QualifiedTypeLoc T) {
4310  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4311  if (Result.isNull())
4312  return QualType();
4313 
4314  Result = getDerived().RebuildQualifiedType(Result, T);
4315 
4316  if (Result.isNull())
4317  return QualType();
4318 
4319  // RebuildQualifiedType might have updated the type, but not in a way
4320  // that invalidates the TypeLoc. (There's no location information for
4321  // qualifiers.)
4322  TLB.TypeWasModifiedSafely(Result);
4323 
4324  return Result;
4325 }
4326 
4327 template <typename Derived>
4329  QualifiedTypeLoc TL) {
4330 
4331  SourceLocation Loc = TL.getBeginLoc();
4332  Qualifiers Quals = TL.getType().getLocalQualifiers();
4333 
4334  if (((T.getAddressSpace() != LangAS::Default &&
4335  Quals.getAddressSpace() != LangAS::Default)) &&
4336  T.getAddressSpace() != Quals.getAddressSpace()) {
4337  SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4338  << TL.getType() << T;
4339  return QualType();
4340  }
4341 
4342  // C++ [dcl.fct]p7:
4343  // [When] adding cv-qualifications on top of the function type [...] the
4344  // cv-qualifiers are ignored.
4345  if (T->isFunctionType()) {
4346  T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4347  Quals.getAddressSpace());
4348  return T;
4349  }
4350 
4351  // C++ [dcl.ref]p1:
4352  // when the cv-qualifiers are introduced through the use of a typedef-name
4353  // or decltype-specifier [...] the cv-qualifiers are ignored.
4354  // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4355  // applied to a reference type.
4356  if (T->isReferenceType()) {
4357  // The only qualifier that applies to a reference type is restrict.
4358  if (!Quals.hasRestrict())
4359  return T;
4361  }
4362 
4363  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4364  // resulting type.
4365  if (Quals.hasObjCLifetime()) {
4366  if (!T->isObjCLifetimeType() && !T->isDependentType())
4367  Quals.removeObjCLifetime();
4368  else if (T.getObjCLifetime()) {
4369  // Objective-C ARC:
4370  // A lifetime qualifier applied to a substituted template parameter
4371  // overrides the lifetime qualifier from the template argument.
4372  const AutoType *AutoTy;
4373  if (const SubstTemplateTypeParmType *SubstTypeParam
4374  = dyn_cast<SubstTemplateTypeParmType>(T)) {
4375  QualType Replacement = SubstTypeParam->getReplacementType();
4376  Qualifiers Qs = Replacement.getQualifiers();
4377  Qs.removeObjCLifetime();
4378  Replacement = SemaRef.Context.getQualifiedType(
4379  Replacement.getUnqualifiedType(), Qs);
4380  T = SemaRef.Context.getSubstTemplateTypeParmType(
4381  SubstTypeParam->getReplacedParameter(), Replacement);
4382  } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
4383  // 'auto' types behave the same way as template parameters.
4384  QualType Deduced = AutoTy->getDeducedType();
4385  Qualifiers Qs = Deduced.getQualifiers();
4386  Qs.removeObjCLifetime();
4387  Deduced =
4388  SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4389  T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4390  AutoTy->isDependentType());
4391  } else {
4392  // Otherwise, complain about the addition of a qualifier to an
4393  // already-qualified type.
4394  // FIXME: Why is this check not in Sema::BuildQualifiedType?
4395  SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
4396  Quals.removeObjCLifetime();
4397  }
4398  }
4399  }
4400 
4401  return SemaRef.BuildQualifiedType(T, Loc, Quals);
4402 }
4403 
4404 template<typename Derived>
4405 TypeLoc
4407  QualType ObjectType,
4408  NamedDecl *UnqualLookup,
4409  CXXScopeSpec &SS) {
4410  if (getDerived().AlreadyTransformed(TL.getType()))
4411  return TL;
4412 
4413  TypeSourceInfo *TSI =
4414  TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4415  if (TSI)
4416  return TSI->getTypeLoc();
4417  return TypeLoc();
4418 }
4419 
4420 template<typename Derived>
4423  QualType ObjectType,
4424  NamedDecl *UnqualLookup,
4425  CXXScopeSpec &SS) {
4426  if (getDerived().AlreadyTransformed(TSInfo->getType()))
4427  return TSInfo;
4428 
4429  return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4430  UnqualLookup, SS);
4431 }
4432 
4433 template <typename Derived>
4435  TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4436  CXXScopeSpec &SS) {
4437  QualType T = TL.getType();
4438  assert(!getDerived().AlreadyTransformed(T));
4439 
4440  TypeLocBuilder TLB;
4441  QualType Result;
4442 
4443  if (isa<TemplateSpecializationType>(T)) {
4446 
4447  TemplateName Template = getDerived().TransformTemplateName(
4448  SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4449  ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
4450  if (Template.isNull())
4451  return nullptr;
4452 
4453  Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4454  Template);
4455  } else if (isa<DependentTemplateSpecializationType>(T)) {
4458 
4459  TemplateName Template
4460  = getDerived().RebuildTemplateName(SS,
4461  SpecTL.getTemplateKeywordLoc(),
4462  *SpecTL.getTypePtr()->getIdentifier(),
4463  SpecTL.getTemplateNameLoc(),
4464  ObjectType, UnqualLookup,
4465  /*AllowInjectedClassName*/true);
4466  if (Template.isNull())
4467  return nullptr;
4468 
4469  Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4470  SpecTL,
4471  Template,
4472  SS);
4473  } else {
4474  // Nothing special needs to be done for these.
4475  Result = getDerived().TransformType(TLB, TL);
4476  }
4477 
4478  if (Result.isNull())
4479  return nullptr;
4480 
4481  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4482 }
4483 
4484 template <class TyLoc> static inline
4486  TyLoc NewT = TLB.push<TyLoc>(T.getType());
4487  NewT.setNameLoc(T.getNameLoc());
4488  return T.getType();
4489 }
4490 
4491 template<typename Derived>
4493  BuiltinTypeLoc T) {
4494  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4495  NewT.setBuiltinLoc(T.getBuiltinLoc());
4496  if (T.needsExtraLocalData())
4498  return T.getType();
4499 }
4500 
4501 template<typename Derived>
4503  ComplexTypeLoc T) {
4504  // FIXME: recurse?
4505  return TransformTypeSpecType(TLB, T);
4506 }
4507 
4508 template <typename Derived>
4510  AdjustedTypeLoc TL) {
4511  // Adjustments applied during transformation are handled elsewhere.
4512  return getDerived().TransformType(TLB, TL.getOriginalLoc());
4513 }
4514 
4515 template<typename Derived>
4517  DecayedTypeLoc TL) {
4518  QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4519  if (OriginalType.isNull())
4520  return QualType();
4521 
4522  QualType Result = TL.getType();
4523  if (getDerived().AlwaysRebuild() ||
4524  OriginalType != TL.getOriginalLoc().getType())
4525  Result = SemaRef.Context.getDecayedType(OriginalType);
4526  TLB.push<DecayedTypeLoc>(Result);
4527  // Nothing to set for DecayedTypeLoc.
4528  return Result;
4529 }
4530 
4531 template<typename Derived>
4533  PointerTypeLoc TL) {
4534  QualType PointeeType
4535  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4536  if (PointeeType.isNull())
4537  return QualType();
4538 
4539  QualType Result = TL.getType();
4540  if (PointeeType->getAs<ObjCObjectType>()) {
4541  // A dependent pointer type 'T *' has is being transformed such
4542  // that an Objective-C class type is being replaced for 'T'. The
4543  // resulting pointer type is an ObjCObjectPointerType, not a
4544  // PointerType.
4545  Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4546 
4548  NewT.setStarLoc(TL.getStarLoc());
4549  return Result;
4550  }
4551 
4552  if (getDerived().AlwaysRebuild() ||
4553  PointeeType != TL.getPointeeLoc().getType()) {
4554  Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4555  if (Result.isNull())
4556  return QualType();
4557  }
4558 
4559  // Objective-C ARC can add lifetime qualifiers to the type that we're
4560  // pointing to.
4561  TLB.TypeWasModifiedSafely(Result->getPointeeType());
4562 
4563  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4564  NewT.setSigilLoc(TL.getSigilLoc());
4565  return Result;
4566 }
4567 
4568 template<typename Derived>
4569 QualType
4571  BlockPointerTypeLoc TL) {
4572  QualType PointeeType
4573  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4574  if (PointeeType.isNull())
4575  return QualType();
4576 
4577  QualType Result = TL.getType();
4578  if (getDerived().AlwaysRebuild() ||
4579  PointeeType != TL.getPointeeLoc().getType()) {
4580  Result = getDerived().RebuildBlockPointerType(PointeeType,
4581  TL.getSigilLoc());
4582  if (Result.isNull())
4583  return QualType();
4584  }
4585 
4586  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4587  NewT.setSigilLoc(TL.getSigilLoc());
4588  return Result;
4589 }
4590 
4591 /// Transforms a reference type. Note that somewhat paradoxically we
4592 /// don't care whether the type itself is an l-value type or an r-value
4593 /// type; we only care if the type was *written* as an l-value type
4594 /// or an r-value type.
4595 template<typename Derived>
4596 QualType
4598  ReferenceTypeLoc TL) {
4599  const ReferenceType *T = TL.getTypePtr();
4600 
4601  // Note that this works with the pointee-as-written.
4602  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4603  if (PointeeType.isNull())
4604  return QualType();
4605 
4606  QualType Result = TL.getType();
4607  if (getDerived().AlwaysRebuild() ||
4608  PointeeType != T->getPointeeTypeAsWritten()) {
4609  Result = getDerived().RebuildReferenceType(PointeeType,
4610  T->isSpelledAsLValue(),
4611  TL.getSigilLoc());
4612  if (Result.isNull())
4613  return QualType();
4614  }
4615 
4616  // Objective-C ARC can add lifetime qualifiers to the type that we're
4617  // referring to.
4620 
4621  // r-value references can be rebuilt as l-value references.
4622  ReferenceTypeLoc NewTL;
4623  if (isa<LValueReferenceType>(Result))
4624  NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4625  else
4626  NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4627  NewTL.setSigilLoc(TL.getSigilLoc());
4628 
4629  return Result;
4630 }
4631 
4632 template<typename Derived>
4633 QualType
4636  return TransformReferenceType(TLB, TL);
4637 }
4638 
4639 template<typename Derived>
4640 QualType
4643  return TransformReferenceType(TLB, TL);
4644 }
4645 
4646 template<typename Derived>
4647 QualType
4649  MemberPointerTypeLoc TL) {
4650  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4651  if (PointeeType.isNull())
4652  return QualType();
4653 
4654  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4655  TypeSourceInfo *NewClsTInfo = nullptr;
4656  if (OldClsTInfo) {
4657  NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4658  if (!NewClsTInfo)
4659  return QualType();
4660  }
4661 
4662  const MemberPointerType *T = TL.getTypePtr();
4663  QualType OldClsType = QualType(T->getClass(), 0);
4664  QualType NewClsType;
4665  if (NewClsTInfo)
4666  NewClsType = NewClsTInfo->getType();
4667  else {
4668  NewClsType = getDerived().TransformType(OldClsType);
4669  if (NewClsType.isNull())
4670  return QualType();
4671  }
4672 
4673  QualType Result = TL.getType();
4674  if (getDerived().AlwaysRebuild() ||
4675  PointeeType != T->getPointeeType() ||
4676  NewClsType != OldClsType) {
4677  Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4678  TL.getStarLoc());
4679  if (Result.isNull())
4680  return QualType();
4681  }
4682 
4683  // If we had to adjust the pointee type when building a member pointer, make
4684  // sure to push TypeLoc info for it.
4685  const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4686  if (MPT && PointeeType != MPT->getPointeeType()) {
4687  assert(isa<AdjustedType>(MPT->getPointeeType()));
4688  TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4689  }
4690 
4691  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4692  NewTL.setSigilLoc(TL.getSigilLoc());
4693  NewTL.setClassTInfo(NewClsTInfo);
4694 
4695  return Result;
4696 }
4697 
4698 template<typename Derived>
4699 QualType
4701  ConstantArrayTypeLoc TL) {
4702  const ConstantArrayType *T = TL.getTypePtr();
4703  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4704  if (ElementType.isNull())
4705  return QualType();
4706 
4707  QualType Result = TL.getType();
4708  if (getDerived().AlwaysRebuild() ||
4709  ElementType != T->getElementType()) {
4710  Result = getDerived().RebuildConstantArrayType(ElementType,
4711  T->getSizeModifier(),
4712  T->getSize(),
4714  TL.getBracketsRange());
4715  if (Result.isNull())
4716  return QualType();
4717  }
4718 
4719  // We might have either a ConstantArrayType or a VariableArrayType now:
4720  // a ConstantArrayType is allowed to have an element type which is a
4721  // VariableArrayType if the type is dependent. Fortunately, all array
4722  // types have the same location layout.
4723  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4724  NewTL.setLBracketLoc(TL.getLBracketLoc());
4725  NewTL.setRBracketLoc(TL.getRBracketLoc());
4726 
4727  Expr *Size = TL.getSizeExpr();
4728  if (Size) {
4731  Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4732  Size = SemaRef.ActOnConstantExpression(Size).get();
4733  }
4734  NewTL.setSizeExpr(Size);
4735 
4736  return Result;
4737 }
4738 
4739 template<typename Derived>
4741  TypeLocBuilder &TLB,
4743  const IncompleteArrayType *T = TL.getTypePtr();
4744  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4745  if (ElementType.isNull())
4746  return QualType();
4747 
4748  QualType Result = TL.getType();
4749  if (getDerived().AlwaysRebuild() ||
4750  ElementType != T->getElementType()) {
4751  Result = getDerived().RebuildIncompleteArrayType(ElementType,
4752  T->getSizeModifier(),
4754  TL.getBracketsRange());
4755  if (Result.isNull())
4756  return QualType();
4757  }
4758 
4759  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4760  NewTL.setLBracketLoc(TL.getLBracketLoc());
4761  NewTL.setRBracketLoc(TL.getRBracketLoc());
4762  NewTL.setSizeExpr(nullptr);
4763 
4764  return Result;
4765 }
4766 
4767 template<typename Derived>
4768 QualType
4770  VariableArrayTypeLoc TL) {
4771  const VariableArrayType *T = TL.getTypePtr();
4772  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4773  if (ElementType.isNull())
4774  return QualType();
4775 
4776  ExprResult SizeResult;
4777  {
4780  SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4781  }
4782  if (SizeResult.isInvalid())
4783  return QualType();
4784  SizeResult =
4785  SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
4786  if (SizeResult.isInvalid())
4787  return QualType();
4788 
4789  Expr *Size = SizeResult.get();
4790 
4791  QualType Result = TL.getType();
4792  if (getDerived().AlwaysRebuild() ||
4793  ElementType != T->getElementType() ||
4794  Size != T->getSizeExpr()) {
4795  Result = getDerived().RebuildVariableArrayType(ElementType,
4796  T->getSizeModifier(),
4797  Size,
4799  TL.getBracketsRange());
4800  if (Result.isNull())
4801  return QualType();
4802  }
4803 
4804  // We might have constant size array now, but fortunately it has the same
4805  // location layout.
4806  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4807  NewTL.setLBracketLoc(TL.getLBracketLoc());
4808  NewTL.setRBracketLoc(TL.getRBracketLoc());
4809  NewTL.setSizeExpr(Size);
4810 
4811  return Result;
4812 }
4813 
4814 template<typename Derived>
4815 QualType
4818  const DependentSizedArrayType *T = TL.getTypePtr();
4819  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4820  if (ElementType.isNull())
4821  return QualType();
4822 
4823  // Array bounds are constant expressions.
4826 
4827  // Prefer the expression from the TypeLoc; the other may have been uniqued.
4828  Expr *origSize = TL.getSizeExpr();
4829  if (!origSize) origSize = T->getSizeExpr();
4830 
4831  ExprResult sizeResult
4832  = getDerived().TransformExpr(origSize);
4833  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4834  if (sizeResult.isInvalid())
4835  return QualType();
4836 
4837  Expr *size = sizeResult.get();
4838 
4839  QualType Result = TL.getType();
4840  if (getDerived().AlwaysRebuild() ||
4841  ElementType != T->getElementType() ||
4842  size != origSize) {
4843  Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4844  T->getSizeModifier(),
4845  size,
4847  TL.getBracketsRange());
4848  if (Result.isNull())
4849  return QualType();
4850  }
4851 
4852  // We might have any sort of array type now, but fortunately they
4853  // all have the same location layout.
4854  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4855  NewTL.setLBracketLoc(TL.getLBracketLoc());
4856  NewTL.setRBracketLoc(TL.getRBracketLoc());
4857  NewTL.setSizeExpr(size);
4858 
4859  return Result;
4860 }
4861 
4862 template <typename Derived>
4865  const DependentVectorType *T = TL.getTypePtr();
4866  QualType ElementType = getDerived().TransformType(T->getElementType());
4867  if (ElementType.isNull())
4868  return QualType();
4869 
4872 
4873  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4874  Size = SemaRef.ActOnConstantExpression(Size);
4875  if (Size.isInvalid())
4876  return QualType();
4877 
4878  QualType Result = TL.getType();
4879  if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4880  Size.get() != T->getSizeExpr()) {
4881  Result = getDerived().RebuildDependentVectorType(
4882  ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4883  if (Result.isNull())
4884  return QualType();
4885  }
4886 
4887  // Result might be dependent or not.
4888  if (isa<DependentVectorType>(Result)) {
4889  DependentVectorTypeLoc NewTL =
4890  TLB.push<DependentVectorTypeLoc>(Result);
4891  NewTL.setNameLoc(TL.getNameLoc());
4892  } else {
4893  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4894  NewTL.setNameLoc(TL.getNameLoc());
4895  }
4896 
4897  return Result;
4898 }
4899 
4900 template<typename Derived>
4902  TypeLocBuilder &TLB,
4904  const DependentSizedExtVectorType *T = TL.getTypePtr();
4905 
4906  // FIXME: ext vector locs should be nested
4907  QualType ElementType = getDerived().TransformType(T->getElementType());
4908  if (ElementType.isNull())
4909  return QualType();
4910 
4911  // Vector sizes are constant expressions.
4914 
4915  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4916  Size = SemaRef.ActOnConstantExpression(Size);
4917  if (Size.isInvalid())
4918  return QualType();
4919 
4920  QualType Result = TL.getType();
4921  if (getDerived().AlwaysRebuild() ||
4922  ElementType != T->getElementType() ||
4923  Size.get() != T->getSizeExpr()) {
4924  Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4925  Size.get(),
4926  T->getAttributeLoc());
4927  if (Result.isNull())
4928  return QualType();
4929  }
4930 
4931  // Result might be dependent or not.
4932  if (isa<DependentSizedExtVectorType>(Result)) {
4934  = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4935  NewTL.setNameLoc(TL.getNameLoc());
4936  } else {
4937  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4938  NewTL.setNameLoc(TL.getNameLoc());
4939  }
4940 
4941  return Result;
4942 }
4943 
4944 template <typename Derived>
4947  const DependentAddressSpaceType *T = TL.getTypePtr();
4948 
4949  QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4950 
4951  if (pointeeType.isNull())
4952  return QualType();
4953 
4954  // Address spaces are constant expressions.
4957 
4958  ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4959  AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4960  if (AddrSpace.isInvalid())
4961  return QualType();
4962 
4963  QualType Result = TL.getType();
4964  if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4965  AddrSpace.get() != T->getAddrSpaceExpr()) {
4966  Result = getDerived().RebuildDependentAddressSpaceType(
4967  pointeeType, AddrSpace.get(), T->getAttributeLoc());
4968  if (Result.isNull())
4969  return QualType();
4970  }
4971 
4972  // Result might be dependent or not.
4973  if (isa<DependentAddressSpaceType>(Result)) {
4975  TLB.push<DependentAddressSpaceTypeLoc>(Result);
4976 
4979  NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4980 
4981  } else {
4982  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4983  Result, getDerived().getBaseLocation());
4984  TransformType(TLB, DI->getTypeLoc());
4985  }
4986 
4987  return Result;
4988 }
4989 
4990 template <typename Derived>
4992  VectorTypeLoc TL) {
4993  const VectorType *T = TL.getTypePtr();
4994  QualType ElementType = getDerived().TransformType(T->getElementType());
4995  if (ElementType.isNull())
4996  return QualType();
4997 
4998  QualType Result = TL.getType();
4999  if (getDerived().AlwaysRebuild() ||
5000  ElementType != T->getElementType()) {
5001  Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
5002  T->getVectorKind());
5003  if (Result.isNull())
5004  return QualType();
5005  }
5006 
5007  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5008  NewTL.setNameLoc(TL.getNameLoc());
5009 
5010  return Result;
5011 }
5012 
5013 template<typename Derived>
5015  ExtVectorTypeLoc TL) {
5016  const VectorType *T = TL.getTypePtr();
5017  QualType ElementType = getDerived().TransformType(T->getElementType());
5018  if (ElementType.isNull())
5019  return QualType();
5020 
5021  QualType Result = TL.getType();
5022  if (getDerived().AlwaysRebuild() ||
5023  ElementType != T->getElementType()) {
5024  Result = getDerived().RebuildExtVectorType(ElementType,
5025  T->getNumElements(),
5026  /*FIXME*/ SourceLocation());
5027  if (Result.isNull())
5028  return QualType();
5029  }
5030 
5031  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5032  NewTL.setNameLoc(TL.getNameLoc());
5033 
5034  return Result;
5035 }
5036 
5037 template <typename Derived>
5039  ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5040  bool ExpectParameterPack) {
5041  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
5042  TypeSourceInfo *NewDI = nullptr;
5043 
5044  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
5045  // If we're substituting into a pack expansion type and we know the
5046  // length we want to expand to, just substitute for the pattern.
5047  TypeLoc OldTL = OldDI->getTypeLoc();
5048  PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
5049 
5050  TypeLocBuilder TLB;
5051  TypeLoc NewTL = OldDI->getTypeLoc();
5052  TLB.reserve(NewTL.getFullDataSize());
5053 
5054  QualType Result = getDerived().TransformType(TLB,
5055  OldExpansionTL.getPatternLoc());
5056  if (Result.isNull())
5057  return nullptr;
5058 
5059  Result = RebuildPackExpansionType(Result,
5060  OldExpansionTL.getPatternLoc().getSourceRange(),
5061  OldExpansionTL.getEllipsisLoc(),
5062  NumExpansions);
5063  if (Result.isNull())
5064  return nullptr;
5065 
5066  PackExpansionTypeLoc NewExpansionTL
5067  = TLB.push<PackExpansionTypeLoc>(Result);
5068  NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5069  NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5070  } else
5071  NewDI = getDerived().TransformType(OldDI);
5072  if (!NewDI)
5073  return nullptr;
5074 
5075  if (NewDI == OldDI && indexAdjustment == 0)
5076  return OldParm;
5077 
5078  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5079  OldParm->getDeclContext(),
5080  OldParm->getInnerLocStart(),
5081  OldParm->getLocation(),
5082  OldParm->getIdentifier(),
5083  NewDI->getType(),
5084  NewDI,
5085  OldParm->getStorageClass(),
5086  /* DefArg */ nullptr);
5087  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5088  OldParm->getFunctionScopeIndex() + indexAdjustment);
5089  return newParm;
5090 }
5091 
5092 template <typename Derived>
5095  const QualType *ParamTypes,
5096  const FunctionProtoType::ExtParameterInfo *ParamInfos,
5097  SmallVectorImpl<QualType> &OutParamTypes,
5100  int indexAdjustment = 0;
5101 
5102  unsigned NumParams = Params.size();
5103  for (unsigned i = 0; i != NumParams; ++i) {
5104  if (ParmVarDecl *OldParm = Params[i]) {
5105  assert(OldParm->getFunctionScopeIndex() == i);
5106 
5107  Optional<unsigned> NumExpansions;
5108  ParmVarDecl *NewParm = nullptr;
5109  if (OldParm->isParameterPack()) {
5110  // We have a function parameter pack that may need to be expanded.
5112 
5113  // Find the parameter packs that could be expanded.
5114  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
5115  PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
5116  TypeLoc Pattern = ExpansionTL.getPatternLoc();
5117  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
5118  assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5119 
5120  // Determine whether we should expand the parameter packs.
5121  bool ShouldExpand = false;
5122  bool RetainExpansion = false;
5123  Optional<unsigned> OrigNumExpansions =
5124  ExpansionTL.getTypePtr()->getNumExpansions();
5125  NumExpansions = OrigNumExpansions;
5126  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5127  Pattern.getSourceRange(),
5128  Unexpanded,
5129  ShouldExpand,
5130  RetainExpansion,
5131  NumExpansions)) {
5132  return true;
5133  }
5134 
5135  if (ShouldExpand) {
5136  // Expand the function parameter pack into multiple, separate
5137  // parameters.
5138  getDerived().ExpandingFunctionParameterPack(OldParm);
5139  for (unsigned I = 0; I != *NumExpansions; ++I) {
5140  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5141  ParmVarDecl *NewParm
5142  = getDerived().TransformFunctionTypeParam(OldParm,
5143  indexAdjustment++,
5144  OrigNumExpansions,
5145  /*ExpectParameterPack=*/false);
5146  if (!NewParm)
5147  return true;
5148 
5149  if (ParamInfos)
5150  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5151  OutParamTypes.push_back(NewParm->getType());
5152  if (PVars)
5153  PVars->push_back(NewParm);
5154  }
5155 
5156  // If we're supposed to retain a pack expansion, do so by temporarily
5157  // forgetting the partially-substituted parameter pack.
5158  if (RetainExpansion) {
5159  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5160  ParmVarDecl *NewParm
5161  = getDerived().TransformFunctionTypeParam(OldParm,
5162  indexAdjustment++,
5163  OrigNumExpansions,
5164  /*ExpectParameterPack=*/false);
5165  if (!NewParm)
5166  return true;
5167 
5168  if (ParamInfos)
5169  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5170  OutParamTypes.push_back(NewParm->getType());
5171  if (PVars)
5172  PVars->push_back(NewParm);
5173  }
5174 
5175  // The next parameter should have the same adjustment as the
5176  // last thing we pushed, but we post-incremented indexAdjustment
5177  // on every push. Also, if we push nothing, the adjustment should
5178  // go down by one.
5179  indexAdjustment--;
5180 
5181  // We're done with the pack expansion.
5182  continue;
5183  }
5184 
5185  // We'll substitute the parameter now without expanding the pack
5186  // expansion.
5187  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5188  NewParm = getDerived().TransformFunctionTypeParam(OldParm,
5189  indexAdjustment,
5190  NumExpansions,
5191  /*ExpectParameterPack=*/true);
5192  } else {
5193  NewParm = getDerived().TransformFunctionTypeParam(
5194  OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
5195  }
5196 
5197  if (!NewParm)
5198  return true;
5199 
5200  if (ParamInfos)
5201  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5202  OutParamTypes.push_back(NewParm->getType());
5203  if (PVars)
5204  PVars->push_back(NewParm);
5205  continue;
5206  }
5207 
5208  // Deal with the possibility that we don't have a parameter
5209  // declaration for this parameter.
5210  QualType OldType = ParamTypes[i];
5211  bool IsPackExpansion = false;
5212  Optional<unsigned> NumExpansions;
5213  QualType NewType;
5214  if (const PackExpansionType *Expansion
5215  = dyn_cast<PackExpansionType>(OldType)) {
5216  // We have a function parameter pack that may need to be expanded.
5217  QualType Pattern = Expansion->getPattern();
5219  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5220 
5221  // Determine whether we should expand the parameter packs.
5222  bool ShouldExpand = false;
5223  bool RetainExpansion = false;
5224  if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
5225  Unexpanded,
5226  ShouldExpand,
5227  RetainExpansion,
5228  NumExpansions)) {
5229  return true;
5230  }
5231 
5232  if (ShouldExpand) {
5233  // Expand the function parameter pack into multiple, separate
5234  // parameters.
5235  for (unsigned I = 0; I != *NumExpansions; ++I) {
5236  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5237  QualType NewType = getDerived().TransformType(Pattern);
5238  if (NewType.isNull())
5239  return true;
5240 
5241  if (NewType->containsUnexpandedParameterPack()) {
5242  NewType =
5243  getSema().getASTContext().getPackExpansionType(NewType, None);
5244 
5245  if (NewType.isNull())
5246  return true;
5247  }
5248 
5249  if (ParamInfos)
5250  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5251  OutParamTypes.push_back(NewType);
5252  if (PVars)
5253  PVars->push_back(nullptr);
5254  }
5255 
5256  // We're done with the pack expansion.
5257  continue;
5258  }
5259 
5260  // If we're supposed to retain a pack expansion, do so by temporarily
5261  // forgetting the partially-substituted parameter pack.
5262  if (RetainExpansion) {
5263  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5264  QualType NewType = getDerived().TransformType(Pattern);
5265  if (NewType.isNull())
5266  return true;
5267 
5268  if (ParamInfos)
5269  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5270  OutParamTypes.push_back(NewType);
5271  if (PVars)
5272  PVars->push_back(nullptr);
5273  }
5274 
5275  // We'll substitute the parameter now without expanding the pack
5276  // expansion.
5277  OldType = Expansion->getPattern();
5278  IsPackExpansion = true;
5279  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5280  NewType = getDerived().TransformType(OldType);
5281  } else {
5282  NewType = getDerived().TransformType(OldType);
5283  }
5284 
5285  if (NewType.isNull())
5286  return true;
5287 
5288  if (IsPackExpansion)
5289  NewType = getSema().Context.getPackExpansionType(NewType,
5290  NumExpansions);
5291 
5292  if (ParamInfos)
5293  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5294  OutParamTypes.push_back(NewType);
5295  if (PVars)
5296  PVars->push_back(nullptr);
5297  }
5298 
5299 #ifndef NDEBUG
5300  if (PVars) {
5301  for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5302  if (ParmVarDecl *parm = (*PVars)[i])
5303  assert(parm->getFunctionScopeIndex() == i);
5304  }
5305 #endif
5306 
5307  return false;
5308 }
5309 
5310 template<typename Derived>
5311 QualType
5313  FunctionProtoTypeLoc TL) {
5314  SmallVector<QualType, 4> ExceptionStorage;
5315  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
5316  return getDerived().TransformFunctionProtoType(
5317  TLB, TL, nullptr, Qualifiers(),
5318  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5319  return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5320  ExceptionStorage, Changed);
5321  });
5322 }
5323 
5324 template<typename Derived> template<typename Fn>
5326  TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5327  Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
5328 
5329  // Transform the parameters and return type.
5330  //
5331  // We are required to instantiate the params and return type in source order.
5332  // When the function has a trailing return type, we instantiate the
5333  // parameters before the return type, since the return type can then refer
5334  // to the parameters themselves (via decltype, sizeof, etc.).
5335  //
5336  SmallVector<QualType, 4> ParamTypes;
5337  SmallVector<ParmVarDecl*, 4> ParamDecls;
5338  Sema::ExtParameterInfoBuilder ExtParamInfos;
5339  const FunctionProtoType *T = TL.getTypePtr();
5340 
5341  QualType ResultType;
5342 
5343  if (T->hasTrailingReturn()) {
5344  if (getDerived().TransformFunctionTypeParams(
5345  TL.getBeginLoc(), TL.getParams(),
5346  TL.getTypePtr()->param_type_begin(),
5348  ParamTypes, &ParamDecls, ExtParamInfos))
5349  return QualType();
5350 
5351  {
5352  // C++11 [expr.prim.general]p3:
5353  // If a declaration declares a member function or member function
5354  // template of a class X, the expression this is a prvalue of type
5355  // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
5356  // and the end of the function-definition, member-declarator, or
5357  // declarator.
5358  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
5359 
5360  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5361  if (ResultType.isNull())
5362  return QualType();
5363  }
5364  }
5365  else {
5366  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5367  if (ResultType.isNull())
5368  return QualType();
5369 
5370  // Return type can not be qualified with an address space.
5371  if (ResultType.getAddressSpace() != LangAS::Default) {
5372  SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
5373  diag::err_attribute_address_function_type);
5374  return QualType();
5375  }
5376 
5377  if (getDerived().TransformFunctionTypeParams(
5378  TL.getBeginLoc(), TL.getParams(),
5379  TL.getTypePtr()->param_type_begin(),
5381  ParamTypes, &ParamDecls, ExtParamInfos))
5382  return QualType();
5383  }
5384 
5386 
5387  bool EPIChanged = false;
5388  if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5389  return QualType();
5390 
5391  // Handle extended parameter information.
5392  if (auto NewExtParamInfos =
5393  ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5394  if (!EPI.ExtParameterInfos ||
5395  llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5396  != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5397  EPIChanged = true;
5398  }
5399  EPI.ExtParameterInfos = NewExtParamInfos;
5400  } else if (EPI.ExtParameterInfos) {
5401  EPIChanged = true;
5402  EPI.ExtParameterInfos = nullptr;
5403  }
5404 
5405  QualType Result = TL.getType();
5406  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5407  T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5408  Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5409  if (Result.isNull())
5410  return QualType();
5411  }
5412 
5413  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5415  NewTL.setLParenLoc(TL.getLParenLoc());
5416  NewTL.setRParenLoc(TL.getRParenLoc());
5418  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5419  for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5420  NewTL.setParam(i, ParamDecls[i]);
5421 
5422  return Result;
5423 }
5424 
5425 template<typename Derived>
5428  SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5429  assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5430 
5431  // Instantiate a dynamic noexcept expression, if any.
5432  if (isComputedNoexcept(ESI.Type)) {
5435  ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5436  if (NoexceptExpr.isInvalid())
5437  return true;
5438 
5439  ExceptionSpecificationType EST = ESI.Type;
5440  NoexceptExpr =
5441  getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
5442  if (NoexceptExpr.isInvalid())
5443  return true;
5444 
5445  if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
5446  Changed = true;
5447  ESI.NoexceptExpr = NoexceptExpr.get();
5448  ESI.Type = EST;
5449  }
5450 
5451  if (ESI.Type != EST_Dynamic)
5452  return false;
5453 
5454  // Instantiate a dynamic exception specification's type.
5455  for (QualType T : ESI.Exceptions) {
5456  if (const PackExpansionType *PackExpansion =
5457  T->getAs<PackExpansionType>()) {
5458  Changed = true;
5459 
5460  // We have a pack expansion. Instantiate it.
5462  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5463  Unexpanded);
5464  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5465 
5466  // Determine whether the set of unexpanded parameter packs can and
5467  // should
5468  // be expanded.
5469  bool Expand = false;
5470  bool RetainExpansion = false;
5471  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5472  // FIXME: Track the location of the ellipsis (and track source location
5473  // information for the types in the exception specification in general).
5474  if (getDerived().TryExpandParameterPacks(
5475  Loc, SourceRange(), Unexpanded, Expand,
5476  RetainExpansion, NumExpansions))
5477  return true;
5478 
5479  if (!Expand) {
5480  // We can't expand this pack expansion into separate arguments yet;
5481  // just substitute into the pattern and create a new pack expansion
5482  // type.
5483  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5484  QualType U = getDerived().TransformType(PackExpansion->getPattern());
5485  if (U.isNull())
5486  return true;
5487 
5488  U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5489  Exceptions.push_back(U);
5490  continue;
5491  }
5492 
5493  // Substitute into the pack expansion pattern for each slice of the
5494  // pack.
5495  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5496  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5497 
5498  QualType U = getDerived().TransformType(PackExpansion->getPattern());
5499  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5500  return true;
5501 
5502  Exceptions.push_back(U);
5503  }
5504  } else {
5505  QualType U = getDerived().TransformType(T);
5506  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5507  return true;
5508  if (T != U)
5509  Changed = true;
5510 
5511  Exceptions.push_back(U);
5512  }
5513  }
5514 
5515  ESI.Exceptions = Exceptions;
5516  if (ESI.Exceptions.empty())
5517  ESI.Type = EST_DynamicNone;
5518  return false;
5519 }
5520 
5521 template<typename Derived>
5523  TypeLocBuilder &TLB,
5525  const FunctionNoProtoType *T = TL.getTypePtr();
5526  QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5527  if (ResultType.isNull())
5528  return QualType();
5529 
5530  QualType Result = TL.getType();
5531  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5532  Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5533 
5534  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5536  NewTL.setLParenLoc(TL.getLParenLoc());
5537  NewTL.setRParenLoc(TL.getRParenLoc());
5538  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5539 
5540  return Result;
5541 }
5542 
5543 template<typename Derived> QualType
5546  const UnresolvedUsingType *T = TL.