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