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