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