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