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