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