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