clang  3.9.0
TreeTransform.h
Go to the documentation of this file.
1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a semantic tree transformation that takes a given
10 // AST and rebuilds it, possibly transforming some nodes in the process.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
16 
17 #include "TypeLocBuilder.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/ExprObjC.h"
24 #include "clang/AST/ExprOpenMP.h"
25 #include "clang/AST/Stmt.h"
26 #include "clang/AST/StmtCXX.h"
27 #include "clang/AST/StmtObjC.h"
28 #include "clang/AST/StmtOpenMP.h"
29 #include "clang/Sema/Designator.h"
30 #include "clang/Sema/Lookup.h"
31 #include "clang/Sema/Ownership.h"
33 #include "clang/Sema/ScopeInfo.h"
36 #include "llvm/ADT/ArrayRef.h"
37 #include "llvm/Support/ErrorHandling.h"
38 #include <algorithm>
39 
40 namespace clang {
41 using namespace sema;
42 
43 /// \brief A semantic tree transformation that allows one to transform one
44 /// abstract syntax tree into another.
45 ///
46 /// A new tree transformation is defined by creating a new subclass \c X of
47 /// \c TreeTransform<X> and then overriding certain operations to provide
48 /// behavior specific to that transformation. For example, template
49 /// instantiation is implemented as a tree transformation where the
50 /// transformation of TemplateTypeParmType nodes involves substituting the
51 /// template arguments for their corresponding template parameters; a similar
52 /// transformation is performed for non-type template parameters and
53 /// template template parameters.
54 ///
55 /// This tree-transformation template uses static polymorphism to allow
56 /// subclasses to customize any of its operations. Thus, a subclass can
57 /// override any of the transformation or rebuild operators by providing an
58 /// operation with the same signature as the default implementation. The
59 /// overridding function should not be virtual.
60 ///
61 /// Semantic tree transformations are split into two stages, either of which
62 /// can be replaced by a subclass. The "transform" step transforms an AST node
63 /// or the parts of an AST node using the various transformation functions,
64 /// then passes the pieces on to the "rebuild" step, which constructs a new AST
65 /// node of the appropriate kind from the pieces. The default transformation
66 /// routines recursively transform the operands to composite AST nodes (e.g.,
67 /// the pointee type of a PointerType node) and, if any of those operand nodes
68 /// were changed by the transformation, invokes the rebuild operation to create
69 /// a new AST node.
70 ///
71 /// Subclasses can customize the transformation at various levels. The
72 /// most coarse-grained transformations involve replacing TransformType(),
73 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
74 /// TransformTemplateName(), or TransformTemplateArgument() with entirely
75 /// new implementations.
76 ///
77 /// For more fine-grained transformations, subclasses can replace any of the
78 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
79 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
80 /// replacing TransformTemplateTypeParmType() allows template instantiation
81 /// to substitute template arguments for their corresponding template
82 /// parameters. Additionally, subclasses can override the \c RebuildXXX
83 /// functions to control how AST nodes are rebuilt when their operands change.
84 /// By default, \c TreeTransform will invoke semantic analysis to rebuild
85 /// AST nodes. However, certain other tree transformations (e.g, cloning) may
86 /// be able to use more efficient rebuild steps.
87 ///
88 /// There are a handful of other functions that can be overridden, allowing one
89 /// to avoid traversing nodes that don't need any transformation
90 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91 /// operands have not changed (\c AlwaysRebuild()), and customize the
92 /// default locations and entity names used for type-checking
93 /// (\c getBaseLocation(), \c getBaseEntity()).
94 template<typename Derived>
96  /// \brief Private RAII object that helps us forget and then re-remember
97  /// the template argument corresponding to a partially-substituted parameter
98  /// pack.
99  class ForgetPartiallySubstitutedPackRAII {
100  Derived &Self;
101  TemplateArgument Old;
102 
103  public:
104  ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105  Old = Self.ForgetPartiallySubstitutedPack();
106  }
107 
108  ~ForgetPartiallySubstitutedPackRAII() {
109  Self.RememberPartiallySubstitutedPack(Old);
110  }
111  };
112 
113 protected:
115 
116  /// \brief The set of local declarations that have been transformed, for
117  /// cases where we are forced to build new declarations within the transformer
118  /// rather than in the subclass (e.g., lambda closure types).
119  llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
120 
121 public:
122  /// \brief Initializes a new tree transformer.
123  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
124 
125  /// \brief Retrieves a reference to the derived class.
126  Derived &getDerived() { return static_cast<Derived&>(*this); }
127 
128  /// \brief Retrieves a reference to the derived class.
129  const Derived &getDerived() const {
130  return static_cast<const Derived&>(*this);
131  }
132 
133  static inline ExprResult Owned(Expr *E) { return E; }
134  static inline StmtResult Owned(Stmt *S) { return S; }
135 
136  /// \brief Retrieves a reference to the semantic analysis object used for
137  /// this tree transform.
138  Sema &getSema() const { return SemaRef; }
139 
140  /// \brief Whether the transformation should always rebuild AST nodes, even
141  /// if none of the children have changed.
142  ///
143  /// Subclasses may override this function to specify when the transformation
144  /// should rebuild all AST nodes.
145  ///
146  /// We must always rebuild all AST nodes when performing variadic template
147  /// pack expansion, in order to avoid violating the AST invariant that each
148  /// statement node appears at most once in its containing declaration.
149  bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
150 
151  /// \brief Returns the location of the entity being transformed, if that
152  /// information was not available elsewhere in the AST.
153  ///
154  /// By default, returns no source-location information. Subclasses can
155  /// provide an alternative implementation that provides better location
156  /// information.
158 
159  /// \brief Returns the name of the entity being transformed, if that
160  /// information was not available elsewhere in the AST.
161  ///
162  /// By default, returns an empty name. Subclasses can provide an alternative
163  /// implementation with a more precise name.
165 
166  /// \brief Sets the "base" location and entity when that
167  /// information is known based on another transformation.
168  ///
169  /// By default, the source location and entity are ignored. Subclasses can
170  /// override this function to provide a customized implementation.
171  void setBase(SourceLocation Loc, DeclarationName Entity) { }
172 
173  /// \brief RAII object that temporarily sets the base location and entity
174  /// used for reporting diagnostics in types.
176  TreeTransform &Self;
177  SourceLocation OldLocation;
178  DeclarationName OldEntity;
179 
180  public:
182  DeclarationName Entity) : Self(Self) {
183  OldLocation = Self.getDerived().getBaseLocation();
184  OldEntity = Self.getDerived().getBaseEntity();
185 
186  if (Location.isValid())
187  Self.getDerived().setBase(Location, Entity);
188  }
189 
191  Self.getDerived().setBase(OldLocation, OldEntity);
192  }
193  };
194 
195  /// \brief Determine whether the given type \p T has already been
196  /// transformed.
197  ///
198  /// Subclasses can provide an alternative implementation of this routine
199  /// to short-circuit evaluation when it is known that a given type will
200  /// not change. For example, template instantiation need not traverse
201  /// non-dependent types.
203  return T.isNull();
204  }
205 
206  /// \brief Determine whether the given call argument should be dropped, e.g.,
207  /// because it is a default argument.
208  ///
209  /// Subclasses can provide an alternative implementation of this routine to
210  /// determine which kinds of call arguments get dropped. By default,
211  /// CXXDefaultArgument nodes are dropped (prior to transformation).
213  return E->isDefaultArgument();
214  }
215 
216  /// \brief Determine whether we should expand a pack expansion with the
217  /// given set of parameter packs into separate arguments by repeatedly
218  /// transforming the pattern.
219  ///
220  /// By default, the transformer never tries to expand pack expansions.
221  /// Subclasses can override this routine to provide different behavior.
222  ///
223  /// \param EllipsisLoc The location of the ellipsis that identifies the
224  /// pack expansion.
225  ///
226  /// \param PatternRange The source range that covers the entire pattern of
227  /// the pack expansion.
228  ///
229  /// \param Unexpanded The set of unexpanded parameter packs within the
230  /// pattern.
231  ///
232  /// \param ShouldExpand Will be set to \c true if the transformer should
233  /// expand the corresponding pack expansions into separate arguments. When
234  /// set, \c NumExpansions must also be set.
235  ///
236  /// \param RetainExpansion Whether the caller should add an unexpanded
237  /// pack expansion after all of the expanded arguments. This is used
238  /// when extending explicitly-specified template argument packs per
239  /// C++0x [temp.arg.explicit]p9.
240  ///
241  /// \param NumExpansions The number of separate arguments that will be in
242  /// the expanded form of the corresponding pack expansion. This is both an
243  /// input and an output parameter, which can be set by the caller if the
244  /// number of expansions is known a priori (e.g., due to a prior substitution)
245  /// and will be set by the callee when the number of expansions is known.
246  /// The callee must set this value when \c ShouldExpand is \c true; it may
247  /// set this value in other cases.
248  ///
249  /// \returns true if an error occurred (e.g., because the parameter packs
250  /// are to be instantiated with arguments of different lengths), false
251  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
252  /// must be set.
254  SourceRange PatternRange,
256  bool &ShouldExpand,
257  bool &RetainExpansion,
258  Optional<unsigned> &NumExpansions) {
259  ShouldExpand = false;
260  return false;
261  }
262 
263  /// \brief "Forget" about the partially-substituted pack template argument,
264  /// when performing an instantiation that must preserve the parameter pack
265  /// use.
266  ///
267  /// This routine is meant to be overridden by the template instantiator.
269  return TemplateArgument();
270  }
271 
272  /// \brief "Remember" the partially-substituted pack template argument
273  /// after performing an instantiation that must preserve the parameter pack
274  /// use.
275  ///
276  /// This routine is meant to be overridden by the template instantiator.
278 
279  /// \brief Note to the derived class when a function parameter pack is
280  /// being expanded.
282 
283  /// \brief Transforms the given type into another type.
284  ///
285  /// By default, this routine transforms a type by creating a
286  /// TypeSourceInfo for it and delegating to the appropriate
287  /// function. This is expensive, but we don't mind, because
288  /// this method is deprecated anyway; all users should be
289  /// switched to storing TypeSourceInfos.
290  ///
291  /// \returns the transformed type.
292  QualType TransformType(QualType T);
293 
294  /// \brief Transforms the given type-with-location into a new
295  /// type-with-location.
296  ///
297  /// By default, this routine transforms a type by delegating to the
298  /// appropriate TransformXXXType to build a new type. Subclasses
299  /// may override this function (to take over all type
300  /// transformations) or some set of the TransformXXXType functions
301  /// to alter the transformation.
302  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
303 
304  /// \brief Transform the given type-with-location into a new
305  /// type, collecting location information in the given builder
306  /// as necessary.
307  ///
308  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
309 
310  /// \brief Transform the given statement.
311  ///
312  /// By default, this routine transforms a statement by delegating to the
313  /// appropriate TransformXXXStmt function to transform a specific kind of
314  /// statement or the TransformExpr() function to transform an expression.
315  /// Subclasses may override this function to transform statements using some
316  /// other mechanism.
317  ///
318  /// \returns the transformed statement.
319  StmtResult TransformStmt(Stmt *S);
320 
321  /// \brief Transform the given statement.
322  ///
323  /// By default, this routine transforms a statement by delegating to the
324  /// appropriate TransformOMPXXXClause function to transform a specific kind
325  /// of clause. Subclasses may override this function to transform statements
326  /// using some other mechanism.
327  ///
328  /// \returns the transformed OpenMP clause.
329  OMPClause *TransformOMPClause(OMPClause *S);
330 
331  /// \brief Transform the given attribute.
332  ///
333  /// By default, this routine transforms a statement by delegating to the
334  /// appropriate TransformXXXAttr function to transform a specific kind
335  /// of attribute. Subclasses may override this function to transform
336  /// attributed statements using some other mechanism.
337  ///
338  /// \returns the transformed attribute
339  const Attr *TransformAttr(const Attr *S);
340 
341 /// \brief Transform the specified attribute.
342 ///
343 /// Subclasses should override the transformation of attributes with a pragma
344 /// spelling to transform expressions stored within the attribute.
345 ///
346 /// \returns the transformed attribute.
347 #define ATTR(X)
348 #define PRAGMA_SPELLING_ATTR(X) \
349  const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350 #include "clang/Basic/AttrList.inc"
351 
352  /// \brief Transform the given expression.
353  ///
354  /// By default, this routine transforms an expression by delegating to the
355  /// appropriate TransformXXXExpr function to build a new expression.
356  /// Subclasses may override this function to transform expressions using some
357  /// other mechanism.
358  ///
359  /// \returns the transformed expression.
360  ExprResult TransformExpr(Expr *E);
361 
362  /// \brief Transform the given initializer.
363  ///
364  /// By default, this routine transforms an initializer by stripping off the
365  /// semantic nodes added by initialization, then passing the result to
366  /// TransformExpr or TransformExprs.
367  ///
368  /// \returns the transformed initializer.
369  ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
370 
371  /// \brief Transform the given list of expressions.
372  ///
373  /// This routine transforms a list of expressions by invoking
374  /// \c TransformExpr() for each subexpression. However, it also provides
375  /// support for variadic templates by expanding any pack expansions (if the
376  /// derived class permits such expansion) along the way. When pack expansions
377  /// are present, the number of outputs may not equal the number of inputs.
378  ///
379  /// \param Inputs The set of expressions to be transformed.
380  ///
381  /// \param NumInputs The number of expressions in \c Inputs.
382  ///
383  /// \param IsCall If \c true, then this transform is being performed on
384  /// function-call arguments, and any arguments that should be dropped, will
385  /// be.
386  ///
387  /// \param Outputs The transformed input expressions will be added to this
388  /// vector.
389  ///
390  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391  /// due to transformation.
392  ///
393  /// \returns true if an error occurred, false otherwise.
394  bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
395  SmallVectorImpl<Expr *> &Outputs,
396  bool *ArgChanged = nullptr);
397 
398  /// \brief Transform the given declaration, which is referenced from a type
399  /// or expression.
400  ///
401  /// By default, acts as the identity function on declarations, unless the
402  /// transformer has had to transform the declaration itself. Subclasses
403  /// may override this function to provide alternate behavior.
406  = TransformedLocalDecls.find(D);
407  if (Known != TransformedLocalDecls.end())
408  return Known->second;
409 
410  return D;
411  }
412 
413  /// \brief Transform the specified condition.
414  ///
415  /// By default, this transforms the variable and expression and rebuilds
416  /// the condition.
417  Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418  Expr *Expr,
420 
421  /// \brief Transform the attributes associated with the given declaration and
422  /// place them on the new declaration.
423  ///
424  /// By default, this operation does nothing. Subclasses may override this
425  /// behavior to transform attributes.
426  void transformAttrs(Decl *Old, Decl *New) { }
427 
428  /// \brief Note that a local declaration has been transformed by this
429  /// transformer.
430  ///
431  /// Local declarations are typically transformed via a call to
432  /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433  /// the transformer itself has to transform the declarations. This routine
434  /// can be overridden by a subclass that keeps track of such mappings.
435  void transformedLocalDecl(Decl *Old, Decl *New) {
436  TransformedLocalDecls[Old] = New;
437  }
438 
439  /// \brief Transform the definition of the given declaration.
440  ///
441  /// By default, invokes TransformDecl() to transform the declaration.
442  /// Subclasses may override this function to provide alternate behavior.
444  return getDerived().TransformDecl(Loc, D);
445  }
446 
447  /// \brief Transform the given declaration, which was the first part of a
448  /// nested-name-specifier in a member access expression.
449  ///
450  /// This specific declaration transformation only applies to the first
451  /// identifier in a nested-name-specifier of a member access expression, e.g.,
452  /// the \c T in \c x->T::member
453  ///
454  /// By default, invokes TransformDecl() to transform the declaration.
455  /// Subclasses may override this function to provide alternate behavior.
457  return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
458  }
459 
460  /// \brief Transform the given nested-name-specifier with source-location
461  /// information.
462  ///
463  /// By default, transforms all of the types and declarations within the
464  /// nested-name-specifier. Subclasses may override this function to provide
465  /// alternate behavior.
467  TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468  QualType ObjectType = QualType(),
469  NamedDecl *FirstQualifierInScope = nullptr);
470 
471  /// \brief Transform the given declaration name.
472  ///
473  /// By default, transforms the types of conversion function, constructor,
474  /// and destructor names and then (if needed) rebuilds the declaration name.
475  /// Identifiers and selectors are returned unmodified. Sublcasses may
476  /// override this function to provide alternate behavior.
478  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
479 
480  /// \brief Transform the given template name.
481  ///
482  /// \param SS The nested-name-specifier that qualifies the template
483  /// name. This nested-name-specifier must already have been transformed.
484  ///
485  /// \param Name The template name to transform.
486  ///
487  /// \param NameLoc The source location of the template name.
488  ///
489  /// \param ObjectType If we're translating a template name within a member
490  /// access expression, this is the type of the object whose member template
491  /// is being referenced.
492  ///
493  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494  /// also refers to a name within the current (lexical) scope, this is the
495  /// declaration it refers to.
496  ///
497  /// By default, transforms the template name by transforming the declarations
498  /// and nested-name-specifiers that occur within the template name.
499  /// Subclasses may override this function to provide alternate behavior.
501  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502  SourceLocation NameLoc,
503  QualType ObjectType = QualType(),
504  NamedDecl *FirstQualifierInScope = nullptr);
505 
506  /// \brief Transform the given template argument.
507  ///
508  /// By default, this operation transforms the type, expression, or
509  /// declaration stored within the template argument and constructs a
510  /// new template argument from the transformed result. Subclasses may
511  /// override this function to provide alternate behavior.
512  ///
513  /// Returns true if there was an error.
514  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
515  TemplateArgumentLoc &Output,
516  bool Uneval = false);
517 
518  /// \brief Transform the given set of template arguments.
519  ///
520  /// By default, this operation transforms all of the template arguments
521  /// in the input set using \c TransformTemplateArgument(), and appends
522  /// the transformed arguments to the output list.
523  ///
524  /// Note that this overload of \c TransformTemplateArguments() is merely
525  /// a convenience function. Subclasses that wish to override this behavior
526  /// should override the iterator-based member template version.
527  ///
528  /// \param Inputs The set of template arguments to be transformed.
529  ///
530  /// \param NumInputs The number of template arguments in \p Inputs.
531  ///
532  /// \param Outputs The set of transformed template arguments output by this
533  /// routine.
534  ///
535  /// Returns true if an error occurred.
537  unsigned NumInputs,
538  TemplateArgumentListInfo &Outputs,
539  bool Uneval = false) {
540  return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541  Uneval);
542  }
543 
544  /// \brief Transform the given set of template arguments.
545  ///
546  /// By default, this operation transforms all of the template arguments
547  /// in the input set using \c TransformTemplateArgument(), and appends
548  /// the transformed arguments to the output list.
549  ///
550  /// \param First An iterator to the first template argument.
551  ///
552  /// \param Last An iterator one step past the last template argument.
553  ///
554  /// \param Outputs The set of transformed template arguments output by this
555  /// routine.
556  ///
557  /// Returns true if an error occurred.
558  template<typename InputIterator>
559  bool TransformTemplateArguments(InputIterator First,
560  InputIterator Last,
561  TemplateArgumentListInfo &Outputs,
562  bool Uneval = false);
563 
564  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566  TemplateArgumentLoc &ArgLoc);
567 
568  /// \brief Fakes up a TypeSourceInfo for a type.
570  return SemaRef.Context.getTrivialTypeSourceInfo(T,
571  getDerived().getBaseLocation());
572  }
573 
574 #define ABSTRACT_TYPELOC(CLASS, PARENT)
575 #define TYPELOC(CLASS, PARENT) \
576  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
577 #include "clang/AST/TypeLocNodes.def"
578 
579  template<typename Fn>
580  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581  FunctionProtoTypeLoc TL,
582  CXXRecordDecl *ThisContext,
583  unsigned ThisTypeQuals,
584  Fn TransformExceptionSpec);
585 
586  bool TransformExceptionSpec(SourceLocation Loc,
587  FunctionProtoType::ExceptionSpecInfo &ESI,
588  SmallVectorImpl<QualType> &Exceptions,
589  bool &Changed);
590 
591  StmtResult TransformSEHHandler(Stmt *Handler);
592 
593  QualType
594  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595  TemplateSpecializationTypeLoc TL,
596  TemplateName Template);
597 
598  QualType
599  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600  DependentTemplateSpecializationTypeLoc TL,
601  TemplateName Template,
602  CXXScopeSpec &SS);
603 
604  QualType TransformDependentTemplateSpecializationType(
605  TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606  NestedNameSpecifierLoc QualifierLoc);
607 
608  /// \brief Transforms the parameters of a function type into the
609  /// given vectors.
610  ///
611  /// The result vectors should be kept in sync; null entries in the
612  /// variables vector are acceptable.
613  ///
614  /// Return true on error.
615  bool TransformFunctionTypeParams(
616  SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617  const QualType *ParamTypes,
618  const FunctionProtoType::ExtParameterInfo *ParamInfos,
619  SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620  Sema::ExtParameterInfoBuilder &PInfos);
621 
622  /// \brief Transforms a single function-type parameter. Return null
623  /// on error.
624  ///
625  /// \param indexAdjustment - A number to add to the parameter's
626  /// scope index; can be negative
627  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
628  int indexAdjustment,
629  Optional<unsigned> NumExpansions,
630  bool ExpectParameterPack);
631 
632  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
633 
634  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
636 
638  TemplateParameterList *TPL) {
639  return TPL;
640  }
641 
642  ExprResult TransformAddressOfOperand(Expr *E);
643 
644  ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
645  bool IsAddressOfOperand,
646  TypeSourceInfo **RecoveryTSI);
647 
648  ExprResult TransformParenDependentScopeDeclRefExpr(
649  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650  TypeSourceInfo **RecoveryTSI);
651 
652  StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
653 
654 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655 // amount of stack usage with clang.
656 #define STMT(Node, Parent) \
657  LLVM_ATTRIBUTE_NOINLINE \
658  StmtResult Transform##Node(Node *S);
659 #define EXPR(Node, Parent) \
660  LLVM_ATTRIBUTE_NOINLINE \
661  ExprResult Transform##Node(Node *E);
662 #define ABSTRACT_STMT(Stmt)
663 #include "clang/AST/StmtNodes.inc"
664 
665 #define OPENMP_CLAUSE(Name, Class) \
666  LLVM_ATTRIBUTE_NOINLINE \
667  OMPClause *Transform ## Class(Class *S);
668 #include "clang/Basic/OpenMPKinds.def"
669 
670  /// \brief Build a new pointer type given its pointee type.
671  ///
672  /// By default, performs semantic analysis when building the pointer type.
673  /// Subclasses may override this routine to provide different behavior.
674  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
675 
676  /// \brief Build a new block pointer type given its pointee type.
677  ///
678  /// By default, performs semantic analysis when building the block pointer
679  /// type. Subclasses may override this routine to provide different behavior.
680  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
681 
682  /// \brief Build a new reference type given the type it references.
683  ///
684  /// By default, performs semantic analysis when building the
685  /// reference type. Subclasses may override this routine to provide
686  /// different behavior.
687  ///
688  /// \param LValue whether the type was written with an lvalue sigil
689  /// or an rvalue sigil.
690  QualType RebuildReferenceType(QualType ReferentType,
691  bool LValue,
692  SourceLocation Sigil);
693 
694  /// \brief Build a new member pointer type given the pointee type and the
695  /// class type it refers into.
696  ///
697  /// By default, performs semantic analysis when building the member pointer
698  /// type. Subclasses may override this routine to provide different behavior.
699  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700  SourceLocation Sigil);
701 
702  /// \brief Build an Objective-C object type.
703  ///
704  /// By default, performs semantic analysis when building the object type.
705  /// Subclasses may override this routine to provide different behavior.
706  QualType RebuildObjCObjectType(QualType BaseType,
707  SourceLocation Loc,
708  SourceLocation TypeArgsLAngleLoc,
709  ArrayRef<TypeSourceInfo *> TypeArgs,
710  SourceLocation TypeArgsRAngleLoc,
711  SourceLocation ProtocolLAngleLoc,
712  ArrayRef<ObjCProtocolDecl *> Protocols,
713  ArrayRef<SourceLocation> ProtocolLocs,
714  SourceLocation ProtocolRAngleLoc);
715 
716  /// \brief Build a new Objective-C object pointer type given the pointee type.
717  ///
718  /// By default, directly builds the pointer type, with no additional semantic
719  /// analysis.
720  QualType RebuildObjCObjectPointerType(QualType PointeeType,
721  SourceLocation Star);
722 
723  /// \brief Build a new array type given the element type, size
724  /// modifier, size of the array (if known), size expression, and index type
725  /// qualifiers.
726  ///
727  /// By default, performs semantic analysis when building the array type.
728  /// Subclasses may override this routine to provide different behavior.
729  /// Also by default, all of the other Rebuild*Array
730  QualType RebuildArrayType(QualType ElementType,
732  const llvm::APInt *Size,
733  Expr *SizeExpr,
734  unsigned IndexTypeQuals,
735  SourceRange BracketsRange);
736 
737  /// \brief Build a new constant array type given the element type, size
738  /// modifier, (known) size of the array, and index type qualifiers.
739  ///
740  /// By default, performs semantic analysis when building the array type.
741  /// Subclasses may override this routine to provide different behavior.
742  QualType RebuildConstantArrayType(QualType ElementType,
744  const llvm::APInt &Size,
745  unsigned IndexTypeQuals,
746  SourceRange BracketsRange);
747 
748  /// \brief Build a new incomplete array type given the element type, size
749  /// modifier, and index type qualifiers.
750  ///
751  /// By default, performs semantic analysis when building the array type.
752  /// Subclasses may override this routine to provide different behavior.
753  QualType RebuildIncompleteArrayType(QualType ElementType,
755  unsigned IndexTypeQuals,
756  SourceRange BracketsRange);
757 
758  /// \brief Build a new variable-length array type given the element type,
759  /// size modifier, size expression, and index type qualifiers.
760  ///
761  /// By default, performs semantic analysis when building the array type.
762  /// Subclasses may override this routine to provide different behavior.
763  QualType RebuildVariableArrayType(QualType ElementType,
765  Expr *SizeExpr,
766  unsigned IndexTypeQuals,
767  SourceRange BracketsRange);
768 
769  /// \brief Build a new dependent-sized array type given the element type,
770  /// size modifier, size expression, and index type qualifiers.
771  ///
772  /// By default, performs semantic analysis when building the array type.
773  /// Subclasses may override this routine to provide different behavior.
774  QualType RebuildDependentSizedArrayType(QualType ElementType,
776  Expr *SizeExpr,
777  unsigned IndexTypeQuals,
778  SourceRange BracketsRange);
779 
780  /// \brief Build a new vector type given the element type and
781  /// number of elements.
782  ///
783  /// By default, performs semantic analysis when building the vector type.
784  /// Subclasses may override this routine to provide different behavior.
785  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
786  VectorType::VectorKind VecKind);
787 
788  /// \brief Build a new extended vector type given the element type and
789  /// number of elements.
790  ///
791  /// By default, performs semantic analysis when building the vector type.
792  /// Subclasses may override this routine to provide different behavior.
793  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
794  SourceLocation AttributeLoc);
795 
796  /// \brief Build a new potentially dependently-sized extended vector type
797  /// given the element type and number of elements.
798  ///
799  /// By default, performs semantic analysis when building the vector type.
800  /// Subclasses may override this routine to provide different behavior.
801  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
802  Expr *SizeExpr,
803  SourceLocation AttributeLoc);
804 
805  /// \brief Build a new function type.
806  ///
807  /// By default, performs semantic analysis when building the function type.
808  /// Subclasses may override this routine to provide different behavior.
809  QualType RebuildFunctionProtoType(QualType T,
810  MutableArrayRef<QualType> ParamTypes,
811  const FunctionProtoType::ExtProtoInfo &EPI);
812 
813  /// \brief Build a new unprototyped function type.
814  QualType RebuildFunctionNoProtoType(QualType ResultType);
815 
816  /// \brief Rebuild an unresolved typename type, given the decl that
817  /// the UnresolvedUsingTypenameDecl was transformed to.
818  QualType RebuildUnresolvedUsingType(Decl *D);
819 
820  /// \brief Build a new typedef type.
822  return SemaRef.Context.getTypeDeclType(Typedef);
823  }
824 
825  /// \brief Build a new class/struct/union type.
827  return SemaRef.Context.getTypeDeclType(Record);
828  }
829 
830  /// \brief Build a new Enum type.
832  return SemaRef.Context.getTypeDeclType(Enum);
833  }
834 
835  /// \brief Build a new typeof(expr) type.
836  ///
837  /// By default, performs semantic analysis when building the typeof type.
838  /// Subclasses may override this routine to provide different behavior.
839  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
840 
841  /// \brief Build a new typeof(type) type.
842  ///
843  /// By default, builds a new TypeOfType with the given underlying type.
844  QualType RebuildTypeOfType(QualType Underlying);
845 
846  /// \brief Build a new unary transform type.
847  QualType RebuildUnaryTransformType(QualType BaseType,
849  SourceLocation Loc);
850 
851  /// \brief Build a new C++11 decltype type.
852  ///
853  /// By default, performs semantic analysis when building the decltype type.
854  /// Subclasses may override this routine to provide different behavior.
855  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
856 
857  /// \brief Build a new C++11 auto type.
858  ///
859  /// By default, builds a new AutoType with the given deduced type.
861  // Note, IsDependent is always false here: we implicitly convert an 'auto'
862  // which has been deduced to a dependent type into an undeduced 'auto', so
863  // that we'll retry deduction after the transformation.
864  return SemaRef.Context.getAutoType(Deduced, Keyword,
865  /*IsDependent*/ false);
866  }
867 
868  /// \brief Build a new template specialization type.
869  ///
870  /// By default, performs semantic analysis when building the template
871  /// specialization type. Subclasses may override this routine to provide
872  /// different behavior.
873  QualType RebuildTemplateSpecializationType(TemplateName Template,
874  SourceLocation TemplateLoc,
876 
877  /// \brief Build a new parenthesized type.
878  ///
879  /// By default, builds a new ParenType type from the inner type.
880  /// Subclasses may override this routine to provide different behavior.
882  return SemaRef.Context.getParenType(InnerType);
883  }
884 
885  /// \brief Build a new qualified name type.
886  ///
887  /// By default, builds a new ElaboratedType type from the keyword,
888  /// the nested-name-specifier and the named type.
889  /// Subclasses may override this routine to provide different behavior.
891  ElaboratedTypeKeyword Keyword,
892  NestedNameSpecifierLoc QualifierLoc,
893  QualType Named) {
894  return SemaRef.Context.getElaboratedType(Keyword,
895  QualifierLoc.getNestedNameSpecifier(),
896  Named);
897  }
898 
899  /// \brief Build a new typename type that refers to a template-id.
900  ///
901  /// By default, builds a new DependentNameType type from the
902  /// nested-name-specifier and the given type. Subclasses may override
903  /// this routine to provide different behavior.
905  ElaboratedTypeKeyword Keyword,
906  NestedNameSpecifierLoc QualifierLoc,
907  const IdentifierInfo *Name,
908  SourceLocation NameLoc,
909  TemplateArgumentListInfo &Args) {
910  // Rebuild the template name.
911  // TODO: avoid TemplateName abstraction
912  CXXScopeSpec SS;
913  SS.Adopt(QualifierLoc);
914  TemplateName InstName
915  = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
916  nullptr);
917 
918  if (InstName.isNull())
919  return QualType();
920 
921  // If it's still dependent, make a dependent specialization.
922  if (InstName.getAsDependentTemplateName())
923  return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
924  QualifierLoc.getNestedNameSpecifier(),
925  Name,
926  Args);
927 
928  // Otherwise, make an elaborated type wrapping a non-dependent
929  // specialization.
930  QualType T =
931  getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
932  if (T.isNull()) return QualType();
933 
934  if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
935  return T;
936 
937  return SemaRef.Context.getElaboratedType(Keyword,
938  QualifierLoc.getNestedNameSpecifier(),
939  T);
940  }
941 
942  /// \brief Build a new typename type that refers to an identifier.
943  ///
944  /// By default, performs semantic analysis when building the typename type
945  /// (or elaborated type). Subclasses may override this routine to provide
946  /// different behavior.
948  SourceLocation KeywordLoc,
949  NestedNameSpecifierLoc QualifierLoc,
950  const IdentifierInfo *Id,
951  SourceLocation IdLoc) {
952  CXXScopeSpec SS;
953  SS.Adopt(QualifierLoc);
954 
955  if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
956  // If the name is still dependent, just build a new dependent name type.
957  if (!SemaRef.computeDeclContext(SS))
958  return SemaRef.Context.getDependentNameType(Keyword,
959  QualifierLoc.getNestedNameSpecifier(),
960  Id);
961  }
962 
963  if (Keyword == ETK_None || Keyword == ETK_Typename)
964  return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
965  *Id, IdLoc);
966 
968 
969  // We had a dependent elaborated-type-specifier that has been transformed
970  // into a non-dependent elaborated-type-specifier. Find the tag we're
971  // referring to.
972  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
973  DeclContext *DC = SemaRef.computeDeclContext(SS, false);
974  if (!DC)
975  return QualType();
976 
977  if (SemaRef.RequireCompleteDeclContext(SS, DC))
978  return QualType();
979 
980  TagDecl *Tag = nullptr;
981  SemaRef.LookupQualifiedName(Result, DC);
982  switch (Result.getResultKind()) {
985  break;
986 
987  case LookupResult::Found:
988  Tag = Result.getAsSingle<TagDecl>();
989  break;
990 
993  llvm_unreachable("Tag lookup cannot find non-tags");
994 
996  // Let the LookupResult structure handle ambiguities.
997  return QualType();
998  }
999 
1000  if (!Tag) {
1001  // Check where the name exists but isn't a tag type and use that to emit
1002  // better diagnostics.
1003  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1004  SemaRef.LookupQualifiedName(Result, DC);
1005  switch (Result.getResultKind()) {
1006  case LookupResult::Found:
1009  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1010  unsigned Kind = 0;
1011  if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
1012  else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1013  else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
1014  SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1015  SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1016  break;
1017  }
1018  default:
1019  SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1020  << Kind << Id << DC << QualifierLoc.getSourceRange();
1021  break;
1022  }
1023  return QualType();
1024  }
1025 
1026  if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1027  IdLoc, Id)) {
1028  SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1029  SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1030  return QualType();
1031  }
1032 
1033  // Build the elaborated-type-specifier type.
1034  QualType T = SemaRef.Context.getTypeDeclType(Tag);
1035  return SemaRef.Context.getElaboratedType(Keyword,
1036  QualifierLoc.getNestedNameSpecifier(),
1037  T);
1038  }
1039 
1040  /// \brief Build a new pack expansion type.
1041  ///
1042  /// By default, builds a new PackExpansionType type from the given pattern.
1043  /// Subclasses may override this routine to provide different behavior.
1045  SourceRange PatternRange,
1046  SourceLocation EllipsisLoc,
1047  Optional<unsigned> NumExpansions) {
1048  return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1049  NumExpansions);
1050  }
1051 
1052  /// \brief Build a new atomic type given its value type.
1053  ///
1054  /// By default, performs semantic analysis when building the atomic type.
1055  /// Subclasses may override this routine to provide different behavior.
1056  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1057 
1058  /// \brief Build a new pipe type given its value type.
1059  QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1060 
1061  /// \brief Build a new template name given a nested name specifier, a flag
1062  /// indicating whether the "template" keyword was provided, and the template
1063  /// that the template name refers to.
1064  ///
1065  /// By default, builds the new template name directly. Subclasses may override
1066  /// this routine to provide different behavior.
1067  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1068  bool TemplateKW,
1069  TemplateDecl *Template);
1070 
1071  /// \brief Build a new template name given a nested name specifier and the
1072  /// name that is referred to as a template.
1073  ///
1074  /// By default, performs semantic analysis to determine whether the name can
1075  /// be resolved to a specific template, then builds the appropriate kind of
1076  /// template name. Subclasses may override this routine to provide different
1077  /// behavior.
1078  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1079  const IdentifierInfo &Name,
1080  SourceLocation NameLoc,
1081  QualType ObjectType,
1082  NamedDecl *FirstQualifierInScope);
1083 
1084  /// \brief Build a new template name given a nested name specifier and the
1085  /// overloaded operator name that is referred to as a template.
1086  ///
1087  /// By default, performs semantic analysis to determine whether the name can
1088  /// be resolved to a specific template, then builds the appropriate kind of
1089  /// template name. Subclasses may override this routine to provide different
1090  /// behavior.
1091  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1092  OverloadedOperatorKind Operator,
1093  SourceLocation NameLoc,
1094  QualType ObjectType);
1095 
1096  /// \brief Build a new template name given a template template parameter pack
1097  /// and the
1098  ///
1099  /// By default, performs semantic analysis to determine whether the name can
1100  /// be resolved to a specific template, then builds the appropriate kind of
1101  /// template name. Subclasses may override this routine to provide different
1102  /// behavior.
1104  const TemplateArgument &ArgPack) {
1105  return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1106  }
1107 
1108  /// \brief Build a new compound statement.
1109  ///
1110  /// By default, performs semantic analysis to build the new statement.
1111  /// Subclasses may override this routine to provide different behavior.
1113  MultiStmtArg Statements,
1114  SourceLocation RBraceLoc,
1115  bool IsStmtExpr) {
1116  return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1117  IsStmtExpr);
1118  }
1119 
1120  /// \brief Build a new case statement.
1121  ///
1122  /// By default, performs semantic analysis to build the new statement.
1123  /// Subclasses may override this routine to provide different behavior.
1125  Expr *LHS,
1126  SourceLocation EllipsisLoc,
1127  Expr *RHS,
1129  return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1130  ColonLoc);
1131  }
1132 
1133  /// \brief Attach the body to a new case statement.
1134  ///
1135  /// By default, performs semantic analysis to build the new statement.
1136  /// Subclasses may override this routine to provide different behavior.
1138  getSema().ActOnCaseStmtBody(S, Body);
1139  return S;
1140  }
1141 
1142  /// \brief Build a new default statement.
1143  ///
1144  /// By default, performs semantic analysis to build the new statement.
1145  /// Subclasses may override this routine to provide different behavior.
1148  Stmt *SubStmt) {
1149  return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1150  /*CurScope=*/nullptr);
1151  }
1152 
1153  /// \brief Build a new label statement.
1154  ///
1155  /// By default, performs semantic analysis to build the new statement.
1156  /// Subclasses may override this routine to provide different behavior.
1158  SourceLocation ColonLoc, Stmt *SubStmt) {
1159  return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1160  }
1161 
1162  /// \brief Build a new label statement.
1163  ///
1164  /// By default, performs semantic analysis to build the new statement.
1165  /// Subclasses may override this routine to provide different behavior.
1167  ArrayRef<const Attr*> Attrs,
1168  Stmt *SubStmt) {
1169  return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1170  }
1171 
1172  /// \brief Build a new "if" statement.
1173  ///
1174  /// By default, performs semantic analysis to build the new statement.
1175  /// Subclasses may override this routine to provide different behavior.
1176  StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
1177  Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
1178  SourceLocation ElseLoc, Stmt *Else) {
1179  return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
1180  ElseLoc, Else);
1181  }
1182 
1183  /// \brief Start building a new switch statement.
1184  ///
1185  /// By default, performs semantic analysis to build the new statement.
1186  /// Subclasses may override this routine to provide different behavior.
1188  Sema::ConditionResult Cond) {
1189  return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
1190  }
1191 
1192  /// \brief Attach the body to the switch statement.
1193  ///
1194  /// By default, performs semantic analysis to build the new statement.
1195  /// Subclasses may override this routine to provide different behavior.
1197  Stmt *Switch, Stmt *Body) {
1198  return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1199  }
1200 
1201  /// \brief Build a new while statement.
1202  ///
1203  /// By default, performs semantic analysis to build the new statement.
1204  /// Subclasses may override this routine to provide different behavior.
1206  Sema::ConditionResult Cond, Stmt *Body) {
1207  return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
1208  }
1209 
1210  /// \brief Build a new do-while statement.
1211  ///
1212  /// By default, performs semantic analysis to build the new statement.
1213  /// Subclasses may override this routine to provide different behavior.
1215  SourceLocation WhileLoc, SourceLocation LParenLoc,
1216  Expr *Cond, SourceLocation RParenLoc) {
1217  return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1218  Cond, RParenLoc);
1219  }
1220 
1221  /// \brief Build a new for statement.
1222  ///
1223  /// By default, performs semantic analysis to build the new statement.
1224  /// Subclasses may override this routine to provide different behavior.
1226  Stmt *Init, Sema::ConditionResult Cond,
1227  Sema::FullExprArg Inc, SourceLocation RParenLoc,
1228  Stmt *Body) {
1229  return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1230  Inc, RParenLoc, Body);
1231  }
1232 
1233  /// \brief Build a new goto statement.
1234  ///
1235  /// By default, performs semantic analysis to build the new statement.
1236  /// Subclasses may override this routine to provide different behavior.
1238  LabelDecl *Label) {
1239  return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1240  }
1241 
1242  /// \brief Build a new indirect goto statement.
1243  ///
1244  /// By default, performs semantic analysis to build the new statement.
1245  /// Subclasses may override this routine to provide different behavior.
1247  SourceLocation StarLoc,
1248  Expr *Target) {
1249  return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1250  }
1251 
1252  /// \brief Build a new return statement.
1253  ///
1254  /// By default, performs semantic analysis to build the new statement.
1255  /// Subclasses may override this routine to provide different behavior.
1257  return getSema().BuildReturnStmt(ReturnLoc, Result);
1258  }
1259 
1260  /// \brief Build a new declaration statement.
1261  ///
1262  /// By default, performs semantic analysis to build the new statement.
1263  /// Subclasses may override this routine to provide different behavior.
1265  SourceLocation StartLoc, SourceLocation EndLoc) {
1266  Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1267  return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1268  }
1269 
1270  /// \brief Build a new inline asm statement.
1271  ///
1272  /// By default, performs semantic analysis to build the new statement.
1273  /// Subclasses may override this routine to provide different behavior.
1275  bool IsVolatile, unsigned NumOutputs,
1276  unsigned NumInputs, IdentifierInfo **Names,
1277  MultiExprArg Constraints, MultiExprArg Exprs,
1278  Expr *AsmString, MultiExprArg Clobbers,
1279  SourceLocation RParenLoc) {
1280  return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1281  NumInputs, Names, Constraints, Exprs,
1282  AsmString, Clobbers, RParenLoc);
1283  }
1284 
1285  /// \brief Build a new MS style inline asm statement.
1286  ///
1287  /// By default, performs semantic analysis to build the new statement.
1288  /// Subclasses may override this routine to provide different behavior.
1290  ArrayRef<Token> AsmToks,
1291  StringRef AsmString,
1292  unsigned NumOutputs, unsigned NumInputs,
1293  ArrayRef<StringRef> Constraints,
1294  ArrayRef<StringRef> Clobbers,
1295  ArrayRef<Expr*> Exprs,
1296  SourceLocation EndLoc) {
1297  return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1298  NumOutputs, NumInputs,
1299  Constraints, Clobbers, Exprs, EndLoc);
1300  }
1301 
1302  /// \brief Build a new co_return statement.
1303  ///
1304  /// By default, performs semantic analysis to build the new statement.
1305  /// Subclasses may override this routine to provide different behavior.
1307  return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1308  }
1309 
1310  /// \brief Build a new co_await expression.
1311  ///
1312  /// By default, performs semantic analysis to build the new expression.
1313  /// Subclasses may override this routine to provide different behavior.
1315  return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1316  }
1317 
1318  /// \brief Build a new co_yield expression.
1319  ///
1320  /// By default, performs semantic analysis to build the new expression.
1321  /// Subclasses may override this routine to provide different behavior.
1323  return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1324  }
1325 
1326  /// \brief Build a new Objective-C \@try statement.
1327  ///
1328  /// By default, performs semantic analysis to build the new statement.
1329  /// Subclasses may override this routine to provide different behavior.
1331  Stmt *TryBody,
1332  MultiStmtArg CatchStmts,
1333  Stmt *Finally) {
1334  return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1335  Finally);
1336  }
1337 
1338  /// \brief Rebuild an Objective-C exception declaration.
1339  ///
1340  /// By default, performs semantic analysis to build the new declaration.
1341  /// Subclasses may override this routine to provide different behavior.
1343  TypeSourceInfo *TInfo, QualType T) {
1344  return getSema().BuildObjCExceptionDecl(TInfo, T,
1345  ExceptionDecl->getInnerLocStart(),
1346  ExceptionDecl->getLocation(),
1347  ExceptionDecl->getIdentifier());
1348  }
1349 
1350  /// \brief Build a new Objective-C \@catch statement.
1351  ///
1352  /// By default, performs semantic analysis to build the new statement.
1353  /// Subclasses may override this routine to provide different behavior.
1355  SourceLocation RParenLoc,
1356  VarDecl *Var,
1357  Stmt *Body) {
1358  return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1359  Var, Body);
1360  }
1361 
1362  /// \brief Build a new Objective-C \@finally statement.
1363  ///
1364  /// By default, performs semantic analysis to build the new statement.
1365  /// Subclasses may override this routine to provide different behavior.
1367  Stmt *Body) {
1368  return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1369  }
1370 
1371  /// \brief Build a new Objective-C \@throw statement.
1372  ///
1373  /// By default, performs semantic analysis to build the new statement.
1374  /// Subclasses may override this routine to provide different behavior.
1376  Expr *Operand) {
1377  return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1378  }
1379 
1380  /// \brief Build a new OpenMP executable directive.
1381  ///
1382  /// By default, performs semantic analysis to build the new statement.
1383  /// Subclasses may override this routine to provide different behavior.
1385  DeclarationNameInfo DirName,
1386  OpenMPDirectiveKind CancelRegion,
1387  ArrayRef<OMPClause *> Clauses,
1388  Stmt *AStmt, SourceLocation StartLoc,
1389  SourceLocation EndLoc) {
1390  return getSema().ActOnOpenMPExecutableDirective(
1391  Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1392  }
1393 
1394  /// \brief Build a new OpenMP 'if' clause.
1395  ///
1396  /// By default, performs semantic analysis to build the new OpenMP clause.
1397  /// Subclasses may override this routine to provide different behavior.
1399  Expr *Condition, SourceLocation StartLoc,
1400  SourceLocation LParenLoc,
1401  SourceLocation NameModifierLoc,
1403  SourceLocation EndLoc) {
1404  return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1405  LParenLoc, NameModifierLoc, ColonLoc,
1406  EndLoc);
1407  }
1408 
1409  /// \brief Build a new OpenMP 'final' clause.
1410  ///
1411  /// By default, performs semantic analysis to build the new OpenMP clause.
1412  /// Subclasses may override this routine to provide different behavior.
1414  SourceLocation LParenLoc,
1415  SourceLocation EndLoc) {
1416  return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1417  EndLoc);
1418  }
1419 
1420  /// \brief Build a new OpenMP 'num_threads' clause.
1421  ///
1422  /// By default, performs semantic analysis to build the new OpenMP clause.
1423  /// Subclasses may override this routine to provide different behavior.
1425  SourceLocation StartLoc,
1426  SourceLocation LParenLoc,
1427  SourceLocation EndLoc) {
1428  return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1429  LParenLoc, EndLoc);
1430  }
1431 
1432  /// \brief Build a new OpenMP 'safelen' clause.
1433  ///
1434  /// By default, performs semantic analysis to build the new OpenMP clause.
1435  /// Subclasses may override this routine to provide different behavior.
1437  SourceLocation LParenLoc,
1438  SourceLocation EndLoc) {
1439  return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1440  }
1441 
1442  /// \brief Build a new OpenMP 'simdlen' clause.
1443  ///
1444  /// By default, performs semantic analysis to build the new OpenMP clause.
1445  /// Subclasses may override this routine to provide different behavior.
1447  SourceLocation LParenLoc,
1448  SourceLocation EndLoc) {
1449  return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1450  }
1451 
1452  /// \brief Build a new OpenMP 'collapse' clause.
1453  ///
1454  /// By default, performs semantic analysis to build the new OpenMP clause.
1455  /// Subclasses may override this routine to provide different behavior.
1457  SourceLocation LParenLoc,
1458  SourceLocation EndLoc) {
1459  return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1460  EndLoc);
1461  }
1462 
1463  /// \brief Build a new OpenMP 'default' clause.
1464  ///
1465  /// By default, performs semantic analysis to build the new OpenMP clause.
1466  /// Subclasses may override this routine to provide different behavior.
1468  SourceLocation KindKwLoc,
1469  SourceLocation StartLoc,
1470  SourceLocation LParenLoc,
1471  SourceLocation EndLoc) {
1472  return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1473  StartLoc, LParenLoc, EndLoc);
1474  }
1475 
1476  /// \brief Build a new OpenMP 'proc_bind' clause.
1477  ///
1478  /// By default, performs semantic analysis to build the new OpenMP clause.
1479  /// Subclasses may override this routine to provide different behavior.
1481  SourceLocation KindKwLoc,
1482  SourceLocation StartLoc,
1483  SourceLocation LParenLoc,
1484  SourceLocation EndLoc) {
1485  return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1486  StartLoc, LParenLoc, EndLoc);
1487  }
1488 
1489  /// \brief Build a new OpenMP 'schedule' clause.
1490  ///
1491  /// By default, performs semantic analysis to build the new OpenMP clause.
1492  /// Subclasses may override this routine to provide different behavior.
1495  OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1496  SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1497  SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1498  return getSema().ActOnOpenMPScheduleClause(
1499  M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1500  CommaLoc, EndLoc);
1501  }
1502 
1503  /// \brief Build a new OpenMP 'ordered' clause.
1504  ///
1505  /// By default, performs semantic analysis to build the new OpenMP clause.
1506  /// Subclasses may override this routine to provide different behavior.
1508  SourceLocation EndLoc,
1509  SourceLocation LParenLoc, Expr *Num) {
1510  return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1511  }
1512 
1513  /// \brief Build a new OpenMP 'private' clause.
1514  ///
1515  /// By default, performs semantic analysis to build the new OpenMP clause.
1516  /// Subclasses may override this routine to provide different behavior.
1518  SourceLocation StartLoc,
1519  SourceLocation LParenLoc,
1520  SourceLocation EndLoc) {
1521  return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1522  EndLoc);
1523  }
1524 
1525  /// \brief Build a new OpenMP 'firstprivate' clause.
1526  ///
1527  /// By default, performs semantic analysis to build the new OpenMP clause.
1528  /// Subclasses may override this routine to provide different behavior.
1530  SourceLocation StartLoc,
1531  SourceLocation LParenLoc,
1532  SourceLocation EndLoc) {
1533  return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1534  EndLoc);
1535  }
1536 
1537  /// \brief Build a new OpenMP 'lastprivate' clause.
1538  ///
1539  /// By default, performs semantic analysis to build the new OpenMP clause.
1540  /// Subclasses may override this routine to provide different behavior.
1542  SourceLocation StartLoc,
1543  SourceLocation LParenLoc,
1544  SourceLocation EndLoc) {
1545  return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1546  EndLoc);
1547  }
1548 
1549  /// \brief Build a new OpenMP 'shared' clause.
1550  ///
1551  /// By default, performs semantic analysis to build the new OpenMP clause.
1552  /// Subclasses may override this routine to provide different behavior.
1554  SourceLocation StartLoc,
1555  SourceLocation LParenLoc,
1556  SourceLocation EndLoc) {
1557  return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1558  EndLoc);
1559  }
1560 
1561  /// \brief Build a new OpenMP 'reduction' clause.
1562  ///
1563  /// By default, performs semantic analysis to build the new statement.
1564  /// Subclasses may override this routine to provide different behavior.
1566  SourceLocation StartLoc,
1567  SourceLocation LParenLoc,
1569  SourceLocation EndLoc,
1570  CXXScopeSpec &ReductionIdScopeSpec,
1571  const DeclarationNameInfo &ReductionId,
1572  ArrayRef<Expr *> UnresolvedReductions) {
1573  return getSema().ActOnOpenMPReductionClause(
1574  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1575  ReductionId, UnresolvedReductions);
1576  }
1577 
1578  /// \brief Build a new OpenMP 'linear' clause.
1579  ///
1580  /// By default, performs semantic analysis to build the new OpenMP clause.
1581  /// Subclasses may override this routine to provide different behavior.
1583  SourceLocation StartLoc,
1584  SourceLocation LParenLoc,
1588  SourceLocation EndLoc) {
1589  return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1590  Modifier, ModifierLoc, ColonLoc,
1591  EndLoc);
1592  }
1593 
1594  /// \brief Build a new OpenMP 'aligned' clause.
1595  ///
1596  /// By default, performs semantic analysis to build the new OpenMP clause.
1597  /// Subclasses may override this routine to provide different behavior.
1599  SourceLocation StartLoc,
1600  SourceLocation LParenLoc,
1602  SourceLocation EndLoc) {
1603  return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1604  LParenLoc, ColonLoc, EndLoc);
1605  }
1606 
1607  /// \brief Build a new OpenMP 'copyin' clause.
1608  ///
1609  /// By default, performs semantic analysis to build the new OpenMP clause.
1610  /// Subclasses may override this routine to provide different behavior.
1612  SourceLocation StartLoc,
1613  SourceLocation LParenLoc,
1614  SourceLocation EndLoc) {
1615  return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1616  EndLoc);
1617  }
1618 
1619  /// \brief Build a new OpenMP 'copyprivate' clause.
1620  ///
1621  /// By default, performs semantic analysis to build the new OpenMP clause.
1622  /// Subclasses may override this routine to provide different behavior.
1624  SourceLocation StartLoc,
1625  SourceLocation LParenLoc,
1626  SourceLocation EndLoc) {
1627  return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1628  EndLoc);
1629  }
1630 
1631  /// \brief Build a new OpenMP 'flush' pseudo clause.
1632  ///
1633  /// By default, performs semantic analysis to build the new OpenMP clause.
1634  /// Subclasses may override this routine to provide different behavior.
1636  SourceLocation StartLoc,
1637  SourceLocation LParenLoc,
1638  SourceLocation EndLoc) {
1639  return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1640  EndLoc);
1641  }
1642 
1643  /// \brief Build a new OpenMP 'depend' pseudo clause.
1644  ///
1645  /// By default, performs semantic analysis to build the new OpenMP clause.
1646  /// Subclasses may override this routine to provide different behavior.
1647  OMPClause *
1650  SourceLocation StartLoc, SourceLocation LParenLoc,
1651  SourceLocation EndLoc) {
1652  return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1653  StartLoc, LParenLoc, EndLoc);
1654  }
1655 
1656  /// \brief Build a new OpenMP 'device' clause.
1657  ///
1658  /// By default, performs semantic analysis to build the new statement.
1659  /// Subclasses may override this routine to provide different behavior.
1661  SourceLocation LParenLoc,
1662  SourceLocation EndLoc) {
1663  return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1664  EndLoc);
1665  }
1666 
1667  /// \brief Build a new OpenMP 'map' clause.
1668  ///
1669  /// By default, performs semantic analysis to build the new OpenMP clause.
1670  /// Subclasses may override this routine to provide different behavior.
1671  OMPClause *
1673  OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1675  ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1676  SourceLocation LParenLoc, SourceLocation EndLoc) {
1677  return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1678  IsMapTypeImplicit, MapLoc, ColonLoc,
1679  VarList, StartLoc, LParenLoc, EndLoc);
1680  }
1681 
1682  /// \brief Build a new OpenMP 'num_teams' clause.
1683  ///
1684  /// By default, performs semantic analysis to build the new statement.
1685  /// Subclasses may override this routine to provide different behavior.
1687  SourceLocation LParenLoc,
1688  SourceLocation EndLoc) {
1689  return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1690  EndLoc);
1691  }
1692 
1693  /// \brief Build a new OpenMP 'thread_limit' clause.
1694  ///
1695  /// By default, performs semantic analysis to build the new statement.
1696  /// Subclasses may override this routine to provide different behavior.
1698  SourceLocation StartLoc,
1699  SourceLocation LParenLoc,
1700  SourceLocation EndLoc) {
1701  return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1702  LParenLoc, EndLoc);
1703  }
1704 
1705  /// \brief Build a new OpenMP 'priority' clause.
1706  ///
1707  /// By default, performs semantic analysis to build the new statement.
1708  /// Subclasses may override this routine to provide different behavior.
1710  SourceLocation LParenLoc,
1711  SourceLocation EndLoc) {
1712  return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1713  EndLoc);
1714  }
1715 
1716  /// \brief Build a new OpenMP 'grainsize' clause.
1717  ///
1718  /// By default, performs semantic analysis to build the new statement.
1719  /// Subclasses may override this routine to provide different behavior.
1721  SourceLocation LParenLoc,
1722  SourceLocation EndLoc) {
1723  return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1724  EndLoc);
1725  }
1726 
1727  /// \brief Build a new OpenMP 'num_tasks' clause.
1728  ///
1729  /// By default, performs semantic analysis to build the new statement.
1730  /// Subclasses may override this routine to provide different behavior.
1732  SourceLocation LParenLoc,
1733  SourceLocation EndLoc) {
1734  return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1735  EndLoc);
1736  }
1737 
1738  /// \brief Build a new OpenMP 'hint' clause.
1739  ///
1740  /// By default, performs semantic analysis to build the new statement.
1741  /// Subclasses may override this routine to provide different behavior.
1743  SourceLocation LParenLoc,
1744  SourceLocation EndLoc) {
1745  return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1746  }
1747 
1748  /// \brief Build a new OpenMP 'dist_schedule' clause.
1749  ///
1750  /// By default, performs semantic analysis to build the new OpenMP clause.
1751  /// Subclasses may override this routine to provide different behavior.
1752  OMPClause *
1754  Expr *ChunkSize, SourceLocation StartLoc,
1755  SourceLocation LParenLoc, SourceLocation KindLoc,
1756  SourceLocation CommaLoc, SourceLocation EndLoc) {
1757  return getSema().ActOnOpenMPDistScheduleClause(
1758  Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1759  }
1760 
1761  /// \brief Build a new OpenMP 'to' clause.
1762  ///
1763  /// By default, performs semantic analysis to build the new statement.
1764  /// Subclasses may override this routine to provide different behavior.
1766  SourceLocation StartLoc,
1767  SourceLocation LParenLoc,
1768  SourceLocation EndLoc) {
1769  return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1770  }
1771 
1772  /// \brief Build a new OpenMP 'from' clause.
1773  ///
1774  /// By default, performs semantic analysis to build the new statement.
1775  /// Subclasses may override this routine to provide different behavior.
1777  SourceLocation StartLoc,
1778  SourceLocation LParenLoc,
1779  SourceLocation EndLoc) {
1780  return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1781  EndLoc);
1782  }
1783 
1784  /// Build a new OpenMP 'use_device_ptr' clause.
1785  ///
1786  /// By default, performs semantic analysis to build the new OpenMP clause.
1787  /// Subclasses may override this routine to provide different behavior.
1789  SourceLocation StartLoc,
1790  SourceLocation LParenLoc,
1791  SourceLocation EndLoc) {
1792  return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1793  EndLoc);
1794  }
1795 
1796  /// Build a new OpenMP 'is_device_ptr' clause.
1797  ///
1798  /// By default, performs semantic analysis to build the new OpenMP clause.
1799  /// Subclasses may override this routine to provide different behavior.
1801  SourceLocation StartLoc,
1802  SourceLocation LParenLoc,
1803  SourceLocation EndLoc) {
1804  return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1805  EndLoc);
1806  }
1807 
1808  /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1809  ///
1810  /// By default, performs semantic analysis to build the new statement.
1811  /// Subclasses may override this routine to provide different behavior.
1813  Expr *object) {
1814  return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1815  }
1816 
1817  /// \brief Build a new Objective-C \@synchronized statement.
1818  ///
1819  /// By default, performs semantic analysis to build the new statement.
1820  /// Subclasses may override this routine to provide different behavior.
1822  Expr *Object, Stmt *Body) {
1823  return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1824  }
1825 
1826  /// \brief Build a new Objective-C \@autoreleasepool statement.
1827  ///
1828  /// By default, performs semantic analysis to build the new statement.
1829  /// Subclasses may override this routine to provide different behavior.
1831  Stmt *Body) {
1832  return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1833  }
1834 
1835  /// \brief Build a new Objective-C fast enumeration statement.
1836  ///
1837  /// By default, performs semantic analysis to build the new statement.
1838  /// Subclasses may override this routine to provide different behavior.
1840  Stmt *Element,
1841  Expr *Collection,
1842  SourceLocation RParenLoc,
1843  Stmt *Body) {
1844  StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1845  Element,
1846  Collection,
1847  RParenLoc);
1848  if (ForEachStmt.isInvalid())
1849  return StmtError();
1850 
1851  return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1852  }
1853 
1854  /// \brief Build a new C++ exception declaration.
1855  ///
1856  /// By default, performs semantic analysis to build the new decaration.
1857  /// Subclasses may override this routine to provide different behavior.
1860  SourceLocation StartLoc,
1861  SourceLocation IdLoc,
1862  IdentifierInfo *Id) {
1863  VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1864  StartLoc, IdLoc, Id);
1865  if (Var)
1866  getSema().CurContext->addDecl(Var);
1867  return Var;
1868  }
1869 
1870  /// \brief Build a new C++ catch statement.
1871  ///
1872  /// By default, performs semantic analysis to build the new statement.
1873  /// Subclasses may override this routine to provide different behavior.
1875  VarDecl *ExceptionDecl,
1876  Stmt *Handler) {
1877  return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1878  Handler));
1879  }
1880 
1881  /// \brief Build a new C++ try statement.
1882  ///
1883  /// By default, performs semantic analysis to build the new statement.
1884  /// Subclasses may override this routine to provide different behavior.
1886  ArrayRef<Stmt *> Handlers) {
1887  return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1888  }
1889 
1890  /// \brief Build a new C++0x range-based for statement.
1891  ///
1892  /// By default, performs semantic analysis to build the new statement.
1893  /// Subclasses may override this routine to provide different behavior.
1895  SourceLocation CoawaitLoc,
1897  Stmt *Range, Stmt *Begin, Stmt *End,
1898  Expr *Cond, Expr *Inc,
1899  Stmt *LoopVar,
1900  SourceLocation RParenLoc) {
1901  // If we've just learned that the range is actually an Objective-C
1902  // collection, treat this as an Objective-C fast enumeration loop.
1903  if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1904  if (RangeStmt->isSingleDecl()) {
1905  if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1906  if (RangeVar->isInvalidDecl())
1907  return StmtError();
1908 
1909  Expr *RangeExpr = RangeVar->getInit();
1910  if (!RangeExpr->isTypeDependent() &&
1911  RangeExpr->getType()->isObjCObjectPointerType())
1912  return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1913  RParenLoc);
1914  }
1915  }
1916  }
1917 
1918  return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1919  Range, Begin, End,
1920  Cond, Inc, LoopVar, RParenLoc,
1922  }
1923 
1924  /// \brief Build a new C++0x range-based for statement.
1925  ///
1926  /// By default, performs semantic analysis to build the new statement.
1927  /// Subclasses may override this routine to provide different behavior.
1929  bool IsIfExists,
1930  NestedNameSpecifierLoc QualifierLoc,
1931  DeclarationNameInfo NameInfo,
1932  Stmt *Nested) {
1933  return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1934  QualifierLoc, NameInfo, Nested);
1935  }
1936 
1937  /// \brief Attach body to a C++0x range-based for statement.
1938  ///
1939  /// By default, performs semantic analysis to finish the new statement.
1940  /// Subclasses may override this routine to provide different behavior.
1942  return getSema().FinishCXXForRangeStmt(ForRange, Body);
1943  }
1944 
1946  Stmt *TryBlock, Stmt *Handler) {
1947  return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
1948  }
1949 
1951  Stmt *Block) {
1952  return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1953  }
1954 
1956  return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
1957  }
1958 
1959  /// \brief Build a new predefined expression.
1960  ///
1961  /// By default, performs semantic analysis to build the new expression.
1962  /// Subclasses may override this routine to provide different behavior.
1965  return getSema().BuildPredefinedExpr(Loc, IT);
1966  }
1967 
1968  /// \brief Build a new expression that references a declaration.
1969  ///
1970  /// By default, performs semantic analysis to build the new expression.
1971  /// Subclasses may override this routine to provide different behavior.
1973  LookupResult &R,
1974  bool RequiresADL) {
1975  return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1976  }
1977 
1978 
1979  /// \brief Build a new expression that references a declaration.
1980  ///
1981  /// By default, performs semantic analysis to build the new expression.
1982  /// Subclasses may override this routine to provide different behavior.
1984  ValueDecl *VD,
1985  const DeclarationNameInfo &NameInfo,
1986  TemplateArgumentListInfo *TemplateArgs) {
1987  CXXScopeSpec SS;
1988  SS.Adopt(QualifierLoc);
1989 
1990  // FIXME: loses template args.
1991 
1992  return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1993  }
1994 
1995  /// \brief Build a new expression in parentheses.
1996  ///
1997  /// By default, performs semantic analysis to build the new expression.
1998  /// Subclasses may override this routine to provide different behavior.
2000  SourceLocation RParen) {
2001  return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2002  }
2003 
2004  /// \brief Build a new pseudo-destructor expression.
2005  ///
2006  /// By default, performs semantic analysis to build the new expression.
2007  /// Subclasses may override this routine to provide different behavior.
2008  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
2009  SourceLocation OperatorLoc,
2010  bool isArrow,
2011  CXXScopeSpec &SS,
2012  TypeSourceInfo *ScopeType,
2013  SourceLocation CCLoc,
2014  SourceLocation TildeLoc,
2015  PseudoDestructorTypeStorage Destroyed);
2016 
2017  /// \brief Build a new unary operator expression.
2018  ///
2019  /// By default, performs semantic analysis to build the new expression.
2020  /// Subclasses may override this routine to provide different behavior.
2022  UnaryOperatorKind Opc,
2023  Expr *SubExpr) {
2024  return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2025  }
2026 
2027  /// \brief Build a new builtin offsetof expression.
2028  ///
2029  /// By default, performs semantic analysis to build the new expression.
2030  /// Subclasses may override this routine to provide different behavior.
2034  SourceLocation RParenLoc) {
2035  return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2036  RParenLoc);
2037  }
2038 
2039  /// \brief Build a new sizeof, alignof or vec_step expression with a
2040  /// type argument.
2041  ///
2042  /// By default, performs semantic analysis to build the new expression.
2043  /// Subclasses may override this routine to provide different behavior.
2045  SourceLocation OpLoc,
2046  UnaryExprOrTypeTrait ExprKind,
2047  SourceRange R) {
2048  return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2049  }
2050 
2051  /// \brief Build a new sizeof, alignof or vec step expression with an
2052  /// expression argument.
2053  ///
2054  /// By default, performs semantic analysis to build the new expression.
2055  /// Subclasses may override this routine to provide different behavior.
2057  UnaryExprOrTypeTrait ExprKind,
2058  SourceRange R) {
2060  = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2061  if (Result.isInvalid())
2062  return ExprError();
2063 
2064  return Result;
2065  }
2066 
2067  /// \brief Build a new array subscript expression.
2068  ///
2069  /// By default, performs semantic analysis to build the new expression.
2070  /// Subclasses may override this routine to provide different behavior.
2072  SourceLocation LBracketLoc,
2073  Expr *RHS,
2074  SourceLocation RBracketLoc) {
2075  return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2076  LBracketLoc, RHS,
2077  RBracketLoc);
2078  }
2079 
2080  /// \brief Build a new array section expression.
2081  ///
2082  /// By default, performs semantic analysis to build the new expression.
2083  /// Subclasses may override this routine to provide different behavior.
2085  Expr *LowerBound,
2087  SourceLocation RBracketLoc) {
2088  return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2089  ColonLoc, Length, RBracketLoc);
2090  }
2091 
2092  /// \brief Build a new call expression.
2093  ///
2094  /// By default, performs semantic analysis to build the new expression.
2095  /// Subclasses may override this routine to provide different behavior.
2097  MultiExprArg Args,
2098  SourceLocation RParenLoc,
2099  Expr *ExecConfig = nullptr) {
2100  return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2101  Args, RParenLoc, ExecConfig);
2102  }
2103 
2104  /// \brief Build a new member access expression.
2105  ///
2106  /// By default, performs semantic analysis to build the new expression.
2107  /// Subclasses may override this routine to provide different behavior.
2109  bool isArrow,
2110  NestedNameSpecifierLoc QualifierLoc,
2111  SourceLocation TemplateKWLoc,
2112  const DeclarationNameInfo &MemberNameInfo,
2113  ValueDecl *Member,
2114  NamedDecl *FoundDecl,
2115  const TemplateArgumentListInfo *ExplicitTemplateArgs,
2116  NamedDecl *FirstQualifierInScope) {
2117  ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2118  isArrow);
2119  if (!Member->getDeclName()) {
2120  // We have a reference to an unnamed field. This is always the
2121  // base of an anonymous struct/union member access, i.e. the
2122  // field is always of record type.
2123  assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2124  assert(Member->getType()->isRecordType() &&
2125  "unnamed member not of record type?");
2126 
2127  BaseResult =
2128  getSema().PerformObjectMemberConversion(BaseResult.get(),
2129  QualifierLoc.getNestedNameSpecifier(),
2130  FoundDecl, Member);
2131  if (BaseResult.isInvalid())
2132  return ExprError();
2133  Base = BaseResult.get();
2134  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2135  MemberExpr *ME = new (getSema().Context)
2136  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2137  cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2138  return ME;
2139  }
2140 
2141  CXXScopeSpec SS;
2142  SS.Adopt(QualifierLoc);
2143 
2144  Base = BaseResult.get();
2145  QualType BaseType = Base->getType();
2146 
2147  // FIXME: this involves duplicating earlier analysis in a lot of
2148  // cases; we should avoid this when possible.
2149  LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2150  R.addDecl(FoundDecl);
2151  R.resolveKind();
2152 
2153  return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2154  SS, TemplateKWLoc,
2155  FirstQualifierInScope,
2156  R, ExplicitTemplateArgs,
2157  /*S*/nullptr);
2158  }
2159 
2160  /// \brief Build a new binary operator expression.
2161  ///
2162  /// By default, performs semantic analysis to build the new expression.
2163  /// Subclasses may override this routine to provide different behavior.
2165  BinaryOperatorKind Opc,
2166  Expr *LHS, Expr *RHS) {
2167  return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2168  }
2169 
2170  /// \brief Build a new conditional operator expression.
2171  ///
2172  /// By default, performs semantic analysis to build the new expression.
2173  /// Subclasses may override this routine to provide different behavior.
2175  SourceLocation QuestionLoc,
2176  Expr *LHS,
2178  Expr *RHS) {
2179  return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2180  LHS, RHS);
2181  }
2182 
2183  /// \brief Build a new C-style cast expression.
2184  ///
2185  /// By default, performs semantic analysis to build the new expression.
2186  /// Subclasses may override this routine to provide different behavior.
2188  TypeSourceInfo *TInfo,
2189  SourceLocation RParenLoc,
2190  Expr *SubExpr) {
2191  return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2192  SubExpr);
2193  }
2194 
2195  /// \brief Build a new compound literal expression.
2196  ///
2197  /// By default, performs semantic analysis to build the new expression.
2198  /// Subclasses may override this routine to provide different behavior.
2200  TypeSourceInfo *TInfo,
2201  SourceLocation RParenLoc,
2202  Expr *Init) {
2203  return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2204  Init);
2205  }
2206 
2207  /// \brief Build a new extended vector element access expression.
2208  ///
2209  /// By default, performs semantic analysis to build the new expression.
2210  /// Subclasses may override this routine to provide different behavior.
2212  SourceLocation OpLoc,
2213  SourceLocation AccessorLoc,
2214  IdentifierInfo &Accessor) {
2215 
2216  CXXScopeSpec SS;
2217  DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2218  return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2219  OpLoc, /*IsArrow*/ false,
2220  SS, SourceLocation(),
2221  /*FirstQualifierInScope*/ nullptr,
2222  NameInfo,
2223  /* TemplateArgs */ nullptr,
2224  /*S*/ nullptr);
2225  }
2226 
2227  /// \brief Build a new initializer list expression.
2228  ///
2229  /// By default, performs semantic analysis to build the new expression.
2230  /// Subclasses may override this routine to provide different behavior.
2233  SourceLocation RBraceLoc,
2234  QualType ResultTy) {
2236  = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2237  if (Result.isInvalid() || ResultTy->isDependentType())
2238  return Result;
2239 
2240  // Patch in the result type we were given, which may have been computed
2241  // when the initial InitListExpr was built.
2242  InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2243  ILE->setType(ResultTy);
2244  return Result;
2245  }
2246 
2247  /// \brief Build a new designated initializer expression.
2248  ///
2249  /// By default, performs semantic analysis to build the new expression.
2250  /// Subclasses may override this routine to provide different behavior.
2252  MultiExprArg ArrayExprs,
2253  SourceLocation EqualOrColonLoc,
2254  bool GNUSyntax,
2255  Expr *Init) {
2257  = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2258  Init);
2259  if (Result.isInvalid())
2260  return ExprError();
2261 
2262  return Result;
2263  }
2264 
2265  /// \brief Build a new value-initialized expression.
2266  ///
2267  /// By default, builds the implicit value initialization without performing
2268  /// any semantic analysis. Subclasses may override this routine to provide
2269  /// different behavior.
2271  return new (SemaRef.Context) ImplicitValueInitExpr(T);
2272  }
2273 
2274  /// \brief Build a new \c va_arg expression.
2275  ///
2276  /// By default, performs semantic analysis to build the new expression.
2277  /// Subclasses may override this routine to provide different behavior.
2279  Expr *SubExpr, TypeSourceInfo *TInfo,
2280  SourceLocation RParenLoc) {
2281  return getSema().BuildVAArgExpr(BuiltinLoc,
2282  SubExpr, TInfo,
2283  RParenLoc);
2284  }
2285 
2286  /// \brief Build a new expression list in parentheses.
2287  ///
2288  /// By default, performs semantic analysis to build the new expression.
2289  /// Subclasses may override this routine to provide different behavior.
2291  MultiExprArg SubExprs,
2292  SourceLocation RParenLoc) {
2293  return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2294  }
2295 
2296  /// \brief Build a new address-of-label expression.
2297  ///
2298  /// By default, performs semantic analysis, using the name of the label
2299  /// rather than attempting to map the label statement itself.
2300  /// Subclasses may override this routine to provide different behavior.
2302  SourceLocation LabelLoc, LabelDecl *Label) {
2303  return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2304  }
2305 
2306  /// \brief Build a new GNU statement expression.
2307  ///
2308  /// By default, performs semantic analysis to build the new expression.
2309  /// Subclasses may override this routine to provide different behavior.
2311  Stmt *SubStmt,
2312  SourceLocation RParenLoc) {
2313  return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2314  }
2315 
2316  /// \brief Build a new __builtin_choose_expr expression.
2317  ///
2318  /// By default, performs semantic analysis to build the new expression.
2319  /// Subclasses may override this routine to provide different behavior.
2321  Expr *Cond, Expr *LHS, Expr *RHS,
2322  SourceLocation RParenLoc) {
2323  return SemaRef.ActOnChooseExpr(BuiltinLoc,
2324  Cond, LHS, RHS,
2325  RParenLoc);
2326  }
2327 
2328  /// \brief Build a new generic selection expression.
2329  ///
2330  /// By default, performs semantic analysis to build the new expression.
2331  /// Subclasses may override this routine to provide different behavior.
2333  SourceLocation DefaultLoc,
2334  SourceLocation RParenLoc,
2335  Expr *ControllingExpr,
2337  ArrayRef<Expr *> Exprs) {
2338  return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2339  ControllingExpr, Types, Exprs);
2340  }
2341 
2342  /// \brief Build a new overloaded operator call expression.
2343  ///
2344  /// By default, performs semantic analysis to build the new expression.
2345  /// The semantic analysis provides the behavior of template instantiation,
2346  /// copying with transformations that turn what looks like an overloaded
2347  /// operator call into a use of a builtin operator, performing
2348  /// argument-dependent lookup, etc. Subclasses may override this routine to
2349  /// provide different behavior.
2350  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2351  SourceLocation OpLoc,
2352  Expr *Callee,
2353  Expr *First,
2354  Expr *Second);
2355 
2356  /// \brief Build a new C++ "named" cast expression, such as static_cast or
2357  /// reinterpret_cast.
2358  ///
2359  /// By default, this routine dispatches to one of the more-specific routines
2360  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2361  /// Subclasses may override this routine to provide different behavior.
2363  Stmt::StmtClass Class,
2364  SourceLocation LAngleLoc,
2365  TypeSourceInfo *TInfo,
2366  SourceLocation RAngleLoc,
2367  SourceLocation LParenLoc,
2368  Expr *SubExpr,
2369  SourceLocation RParenLoc) {
2370  switch (Class) {
2371  case Stmt::CXXStaticCastExprClass:
2372  return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2373  RAngleLoc, LParenLoc,
2374  SubExpr, RParenLoc);
2375 
2376  case Stmt::CXXDynamicCastExprClass:
2377  return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2378  RAngleLoc, LParenLoc,
2379  SubExpr, RParenLoc);
2380 
2381  case Stmt::CXXReinterpretCastExprClass:
2382  return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2383  RAngleLoc, LParenLoc,
2384  SubExpr,
2385  RParenLoc);
2386 
2387  case Stmt::CXXConstCastExprClass:
2388  return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2389  RAngleLoc, LParenLoc,
2390  SubExpr, RParenLoc);
2391 
2392  default:
2393  llvm_unreachable("Invalid C++ named cast");
2394  }
2395  }
2396 
2397  /// \brief Build a new C++ static_cast expression.
2398  ///
2399  /// By default, performs semantic analysis to build the new expression.
2400  /// Subclasses may override this routine to provide different behavior.
2402  SourceLocation LAngleLoc,
2403  TypeSourceInfo *TInfo,
2404  SourceLocation RAngleLoc,
2405  SourceLocation LParenLoc,
2406  Expr *SubExpr,
2407  SourceLocation RParenLoc) {
2408  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2409  TInfo, SubExpr,
2410  SourceRange(LAngleLoc, RAngleLoc),
2411  SourceRange(LParenLoc, RParenLoc));
2412  }
2413 
2414  /// \brief Build a new C++ dynamic_cast expression.
2415  ///
2416  /// By default, performs semantic analysis to build the new expression.
2417  /// Subclasses may override this routine to provide different behavior.
2419  SourceLocation LAngleLoc,
2420  TypeSourceInfo *TInfo,
2421  SourceLocation RAngleLoc,
2422  SourceLocation LParenLoc,
2423  Expr *SubExpr,
2424  SourceLocation RParenLoc) {
2425  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2426  TInfo, SubExpr,
2427  SourceRange(LAngleLoc, RAngleLoc),
2428  SourceRange(LParenLoc, RParenLoc));
2429  }
2430 
2431  /// \brief Build a new C++ reinterpret_cast expression.
2432  ///
2433  /// By default, performs semantic analysis to build the new expression.
2434  /// Subclasses may override this routine to provide different behavior.
2436  SourceLocation LAngleLoc,
2437  TypeSourceInfo *TInfo,
2438  SourceLocation RAngleLoc,
2439  SourceLocation LParenLoc,
2440  Expr *SubExpr,
2441  SourceLocation RParenLoc) {
2442  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2443  TInfo, SubExpr,
2444  SourceRange(LAngleLoc, RAngleLoc),
2445  SourceRange(LParenLoc, RParenLoc));
2446  }
2447 
2448  /// \brief Build a new C++ const_cast expression.
2449  ///
2450  /// By default, performs semantic analysis to build the new expression.
2451  /// Subclasses may override this routine to provide different behavior.
2453  SourceLocation LAngleLoc,
2454  TypeSourceInfo *TInfo,
2455  SourceLocation RAngleLoc,
2456  SourceLocation LParenLoc,
2457  Expr *SubExpr,
2458  SourceLocation RParenLoc) {
2459  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2460  TInfo, SubExpr,
2461  SourceRange(LAngleLoc, RAngleLoc),
2462  SourceRange(LParenLoc, RParenLoc));
2463  }
2464 
2465  /// \brief Build a new C++ functional-style cast expression.
2466  ///
2467  /// By default, performs semantic analysis to build the new expression.
2468  /// Subclasses may override this routine to provide different behavior.
2470  SourceLocation LParenLoc,
2471  Expr *Sub,
2472  SourceLocation RParenLoc) {
2473  return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2474  MultiExprArg(&Sub, 1),
2475  RParenLoc);
2476  }
2477 
2478  /// \brief Build a new C++ typeid(type) expression.
2479  ///
2480  /// By default, performs semantic analysis to build the new expression.
2481  /// Subclasses may override this routine to provide different behavior.
2483  SourceLocation TypeidLoc,
2484  TypeSourceInfo *Operand,
2485  SourceLocation RParenLoc) {
2486  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2487  RParenLoc);
2488  }
2489 
2490 
2491  /// \brief Build a new C++ typeid(expr) expression.
2492  ///
2493  /// By default, performs semantic analysis to build the new expression.
2494  /// Subclasses may override this routine to provide different behavior.
2496  SourceLocation TypeidLoc,
2497  Expr *Operand,
2498  SourceLocation RParenLoc) {
2499  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2500  RParenLoc);
2501  }
2502 
2503  /// \brief Build a new C++ __uuidof(type) expression.
2504  ///
2505  /// By default, performs semantic analysis to build the new expression.
2506  /// Subclasses may override this routine to provide different behavior.
2508  SourceLocation TypeidLoc,
2509  TypeSourceInfo *Operand,
2510  SourceLocation RParenLoc) {
2511  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2512  RParenLoc);
2513  }
2514 
2515  /// \brief Build a new C++ __uuidof(expr) expression.
2516  ///
2517  /// By default, performs semantic analysis to build the new expression.
2518  /// Subclasses may override this routine to provide different behavior.
2520  SourceLocation TypeidLoc,
2521  Expr *Operand,
2522  SourceLocation RParenLoc) {
2523  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2524  RParenLoc);
2525  }
2526 
2527  /// \brief Build a new C++ "this" expression.
2528  ///
2529  /// By default, builds a new "this" expression without performing any
2530  /// semantic analysis. Subclasses may override this routine to provide
2531  /// different behavior.
2533  QualType ThisType,
2534  bool isImplicit) {
2535  getSema().CheckCXXThisCapture(ThisLoc);
2536  return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2537  }
2538 
2539  /// \brief Build a new C++ throw expression.
2540  ///
2541  /// By default, performs semantic analysis to build the new expression.
2542  /// Subclasses may override this routine to provide different behavior.
2544  bool IsThrownVariableInScope) {
2545  return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2546  }
2547 
2548  /// \brief Build a new C++ default-argument expression.
2549  ///
2550  /// By default, builds a new default-argument expression, which does not
2551  /// require any semantic analysis. Subclasses may override this routine to
2552  /// provide different behavior.
2554  ParmVarDecl *Param) {
2555  return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2556  }
2557 
2558  /// \brief Build a new C++11 default-initialization expression.
2559  ///
2560  /// By default, builds a new default field initialization expression, which
2561  /// does not require any semantic analysis. Subclasses may override this
2562  /// routine to provide different behavior.
2564  FieldDecl *Field) {
2565  return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2566  }
2567 
2568  /// \brief Build a new C++ zero-initialization expression.
2569  ///
2570  /// By default, performs semantic analysis to build the new expression.
2571  /// Subclasses may override this routine to provide different behavior.
2573  SourceLocation LParenLoc,
2574  SourceLocation RParenLoc) {
2575  return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2576  None, RParenLoc);
2577  }
2578 
2579  /// \brief Build a new C++ "new" expression.
2580  ///
2581  /// By default, performs semantic analysis to build the new expression.
2582  /// Subclasses may override this routine to provide different behavior.
2584  bool UseGlobal,
2585  SourceLocation PlacementLParen,
2586  MultiExprArg PlacementArgs,
2587  SourceLocation PlacementRParen,
2588  SourceRange TypeIdParens,
2589  QualType AllocatedType,
2590  TypeSourceInfo *AllocatedTypeInfo,
2591  Expr *ArraySize,
2592  SourceRange DirectInitRange,
2593  Expr *Initializer) {
2594  return getSema().BuildCXXNew(StartLoc, UseGlobal,
2595  PlacementLParen,
2596  PlacementArgs,
2597  PlacementRParen,
2598  TypeIdParens,
2599  AllocatedType,
2600  AllocatedTypeInfo,
2601  ArraySize,
2602  DirectInitRange,
2603  Initializer);
2604  }
2605 
2606  /// \brief Build a new C++ "delete" expression.
2607  ///
2608  /// By default, performs semantic analysis to build the new expression.
2609  /// Subclasses may override this routine to provide different behavior.
2611  bool IsGlobalDelete,
2612  bool IsArrayForm,
2613  Expr *Operand) {
2614  return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2615  Operand);
2616  }
2617 
2618  /// \brief Build a new type trait expression.
2619  ///
2620  /// By default, performs semantic analysis to build the new expression.
2621  /// Subclasses may override this routine to provide different behavior.
2623  SourceLocation StartLoc,
2625  SourceLocation RParenLoc) {
2626  return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2627  }
2628 
2629  /// \brief Build a new array type trait expression.
2630  ///
2631  /// By default, performs semantic analysis to build the new expression.
2632  /// Subclasses may override this routine to provide different behavior.
2634  SourceLocation StartLoc,
2635  TypeSourceInfo *TSInfo,
2636  Expr *DimExpr,
2637  SourceLocation RParenLoc) {
2638  return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2639  }
2640 
2641  /// \brief Build a new expression trait expression.
2642  ///
2643  /// By default, performs semantic analysis to build the new expression.
2644  /// Subclasses may override this routine to provide different behavior.
2646  SourceLocation StartLoc,
2647  Expr *Queried,
2648  SourceLocation RParenLoc) {
2649  return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2650  }
2651 
2652  /// \brief Build a new (previously unresolved) declaration reference
2653  /// expression.
2654  ///
2655  /// By default, performs semantic analysis to build the new expression.
2656  /// Subclasses may override this routine to provide different behavior.
2658  NestedNameSpecifierLoc QualifierLoc,
2659  SourceLocation TemplateKWLoc,
2660  const DeclarationNameInfo &NameInfo,
2661  const TemplateArgumentListInfo *TemplateArgs,
2662  bool IsAddressOfOperand,
2663  TypeSourceInfo **RecoveryTSI) {
2664  CXXScopeSpec SS;
2665  SS.Adopt(QualifierLoc);
2666 
2667  if (TemplateArgs || TemplateKWLoc.isValid())
2668  return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2669  TemplateArgs);
2670 
2671  return getSema().BuildQualifiedDeclarationNameExpr(
2672  SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2673  }
2674 
2675  /// \brief Build a new template-id expression.
2676  ///
2677  /// By default, performs semantic analysis to build the new expression.
2678  /// Subclasses may override this routine to provide different behavior.
2680  SourceLocation TemplateKWLoc,
2681  LookupResult &R,
2682  bool RequiresADL,
2683  const TemplateArgumentListInfo *TemplateArgs) {
2684  return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2685  TemplateArgs);
2686  }
2687 
2688  /// \brief Build a new object-construction expression.
2689  ///
2690  /// By default, performs semantic analysis to build the new expression.
2691  /// Subclasses may override this routine to provide different behavior.
2693  SourceLocation Loc,
2694  CXXConstructorDecl *Constructor,
2695  bool IsElidable,
2696  MultiExprArg Args,
2697  bool HadMultipleCandidates,
2698  bool ListInitialization,
2699  bool StdInitListInitialization,
2700  bool RequiresZeroInit,
2701  CXXConstructExpr::ConstructionKind ConstructKind,
2702  SourceRange ParenRange) {
2703  SmallVector<Expr*, 8> ConvertedArgs;
2704  if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2705  ConvertedArgs))
2706  return ExprError();
2707 
2708  return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
2709  IsElidable,
2710  ConvertedArgs,
2711  HadMultipleCandidates,
2712  ListInitialization,
2713  StdInitListInitialization,
2714  RequiresZeroInit, ConstructKind,
2715  ParenRange);
2716  }
2717 
2718  /// \brief Build a new implicit construction via inherited constructor
2719  /// expression.
2721  CXXConstructorDecl *Constructor,
2722  bool ConstructsVBase,
2723  bool InheritedFromVBase) {
2724  return new (getSema().Context) CXXInheritedCtorInitExpr(
2725  Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2726  }
2727 
2728  /// \brief Build a new object-construction expression.
2729  ///
2730  /// By default, performs semantic analysis to build the new expression.
2731  /// Subclasses may override this routine to provide different behavior.
2733  SourceLocation LParenLoc,
2734  MultiExprArg Args,
2735  SourceLocation RParenLoc) {
2736  return getSema().BuildCXXTypeConstructExpr(TSInfo,
2737  LParenLoc,
2738  Args,
2739  RParenLoc);
2740  }
2741 
2742  /// \brief Build a new object-construction expression.
2743  ///
2744  /// By default, performs semantic analysis to build the new expression.
2745  /// Subclasses may override this routine to provide different behavior.
2747  SourceLocation LParenLoc,
2748  MultiExprArg Args,
2749  SourceLocation RParenLoc) {
2750  return getSema().BuildCXXTypeConstructExpr(TSInfo,
2751  LParenLoc,
2752  Args,
2753  RParenLoc);
2754  }
2755 
2756  /// \brief Build a new member reference expression.
2757  ///
2758  /// By default, performs semantic analysis to build the new expression.
2759  /// Subclasses may override this routine to provide different behavior.
2761  QualType BaseType,
2762  bool IsArrow,
2763  SourceLocation OperatorLoc,
2764  NestedNameSpecifierLoc QualifierLoc,
2765  SourceLocation TemplateKWLoc,
2766  NamedDecl *FirstQualifierInScope,
2767  const DeclarationNameInfo &MemberNameInfo,
2768  const TemplateArgumentListInfo *TemplateArgs) {
2769  CXXScopeSpec SS;
2770  SS.Adopt(QualifierLoc);
2771 
2772  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2773  OperatorLoc, IsArrow,
2774  SS, TemplateKWLoc,
2775  FirstQualifierInScope,
2776  MemberNameInfo,
2777  TemplateArgs, /*S*/nullptr);
2778  }
2779 
2780  /// \brief Build a new member reference expression.
2781  ///
2782  /// By default, performs semantic analysis to build the new expression.
2783  /// Subclasses may override this routine to provide different behavior.
2785  SourceLocation OperatorLoc,
2786  bool IsArrow,
2787  NestedNameSpecifierLoc QualifierLoc,
2788  SourceLocation TemplateKWLoc,
2789  NamedDecl *FirstQualifierInScope,
2790  LookupResult &R,
2791  const TemplateArgumentListInfo *TemplateArgs) {
2792  CXXScopeSpec SS;
2793  SS.Adopt(QualifierLoc);
2794 
2795  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2796  OperatorLoc, IsArrow,
2797  SS, TemplateKWLoc,
2798  FirstQualifierInScope,
2799  R, TemplateArgs, /*S*/nullptr);
2800  }
2801 
2802  /// \brief Build a new noexcept expression.
2803  ///
2804  /// By default, performs semantic analysis to build the new expression.
2805  /// Subclasses may override this routine to provide different behavior.
2807  return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2808  }
2809 
2810  /// \brief Build a new expression to compute the length of a parameter pack.
2812  NamedDecl *Pack,
2813  SourceLocation PackLoc,
2814  SourceLocation RParenLoc,
2816  ArrayRef<TemplateArgument> PartialArgs) {
2817  return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2818  RParenLoc, Length, PartialArgs);
2819  }
2820 
2821  /// \brief Build a new Objective-C boxed expression.
2822  ///
2823  /// By default, performs semantic analysis to build the new expression.
2824  /// Subclasses may override this routine to provide different behavior.
2826  return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2827  }
2828 
2829  /// \brief Build a new Objective-C array literal.
2830  ///
2831  /// By default, performs semantic analysis to build the new expression.
2832  /// Subclasses may override this routine to provide different behavior.
2834  Expr **Elements, unsigned NumElements) {
2835  return getSema().BuildObjCArrayLiteral(Range,
2836  MultiExprArg(Elements, NumElements));
2837  }
2838 
2840  Expr *Base, Expr *Key,
2841  ObjCMethodDecl *getterMethod,
2842  ObjCMethodDecl *setterMethod) {
2843  return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2844  getterMethod, setterMethod);
2845  }
2846 
2847  /// \brief Build a new Objective-C dictionary literal.
2848  ///
2849  /// By default, performs semantic analysis to build the new expression.
2850  /// Subclasses may override this routine to provide different behavior.
2853  return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2854  }
2855 
2856  /// \brief Build a new Objective-C \@encode expression.
2857  ///
2858  /// By default, performs semantic analysis to build the new expression.
2859  /// Subclasses may override this routine to provide different behavior.
2861  TypeSourceInfo *EncodeTypeInfo,
2862  SourceLocation RParenLoc) {
2863  return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2864  }
2865 
2866  /// \brief Build a new Objective-C class message.
2868  Selector Sel,
2869  ArrayRef<SourceLocation> SelectorLocs,
2870  ObjCMethodDecl *Method,
2871  SourceLocation LBracLoc,
2872  MultiExprArg Args,
2873  SourceLocation RBracLoc) {
2874  return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2875  ReceiverTypeInfo->getType(),
2876  /*SuperLoc=*/SourceLocation(),
2877  Sel, Method, LBracLoc, SelectorLocs,
2878  RBracLoc, Args);
2879  }
2880 
2881  /// \brief Build a new Objective-C instance message.
2883  Selector Sel,
2884  ArrayRef<SourceLocation> SelectorLocs,
2885  ObjCMethodDecl *Method,
2886  SourceLocation LBracLoc,
2887  MultiExprArg Args,
2888  SourceLocation RBracLoc) {
2889  return SemaRef.BuildInstanceMessage(Receiver,
2890  Receiver->getType(),
2891  /*SuperLoc=*/SourceLocation(),
2892  Sel, Method, LBracLoc, SelectorLocs,
2893  RBracLoc, Args);
2894  }
2895 
2896  /// \brief Build a new Objective-C instance/class message to 'super'.
2898  Selector Sel,
2899  ArrayRef<SourceLocation> SelectorLocs,
2900  QualType SuperType,
2901  ObjCMethodDecl *Method,
2902  SourceLocation LBracLoc,
2903  MultiExprArg Args,
2904  SourceLocation RBracLoc) {
2905  return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2906  SuperType,
2907  SuperLoc,
2908  Sel, Method, LBracLoc, SelectorLocs,
2909  RBracLoc, Args)
2910  : SemaRef.BuildClassMessage(nullptr,
2911  SuperType,
2912  SuperLoc,
2913  Sel, Method, LBracLoc, SelectorLocs,
2914  RBracLoc, Args);
2915 
2916 
2917  }
2918 
2919  /// \brief Build a new Objective-C ivar reference expression.
2920  ///
2921  /// By default, performs semantic analysis to build the new expression.
2922  /// Subclasses may override this routine to provide different behavior.
2924  SourceLocation IvarLoc,
2925  bool IsArrow, bool IsFreeIvar) {
2926  // FIXME: We lose track of the IsFreeIvar bit.
2927  CXXScopeSpec SS;
2928  DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2929  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2930  /*FIXME:*/IvarLoc, IsArrow,
2931  SS, SourceLocation(),
2932  /*FirstQualifierInScope=*/nullptr,
2933  NameInfo,
2934  /*TemplateArgs=*/nullptr,
2935  /*S=*/nullptr);
2936  }
2937 
2938  /// \brief Build a new Objective-C property reference expression.
2939  ///
2940  /// By default, performs semantic analysis to build the new expression.
2941  /// Subclasses may override this routine to provide different behavior.
2943  ObjCPropertyDecl *Property,
2944  SourceLocation PropertyLoc) {
2945  CXXScopeSpec SS;
2946  DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2947  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2948  /*FIXME:*/PropertyLoc,
2949  /*IsArrow=*/false,
2950  SS, SourceLocation(),
2951  /*FirstQualifierInScope=*/nullptr,
2952  NameInfo,
2953  /*TemplateArgs=*/nullptr,
2954  /*S=*/nullptr);
2955  }
2956 
2957  /// \brief Build a new Objective-C property reference expression.
2958  ///
2959  /// By default, performs semantic analysis to build the new expression.
2960  /// Subclasses may override this routine to provide different behavior.
2962  ObjCMethodDecl *Getter,
2963  ObjCMethodDecl *Setter,
2964  SourceLocation PropertyLoc) {
2965  // Since these expressions can only be value-dependent, we do not
2966  // need to perform semantic analysis again.
2967  return Owned(
2968  new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2970  PropertyLoc, Base));
2971  }
2972 
2973  /// \brief Build a new Objective-C "isa" expression.
2974  ///
2975  /// By default, performs semantic analysis to build the new expression.
2976  /// Subclasses may override this routine to provide different behavior.
2978  SourceLocation OpLoc, bool IsArrow) {
2979  CXXScopeSpec SS;
2980  DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2981  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2982  OpLoc, IsArrow,
2983  SS, SourceLocation(),
2984  /*FirstQualifierInScope=*/nullptr,
2985  NameInfo,
2986  /*TemplateArgs=*/nullptr,
2987  /*S=*/nullptr);
2988  }
2989 
2990  /// \brief Build a new shuffle vector expression.
2991  ///
2992  /// By default, performs semantic analysis to build the new expression.
2993  /// Subclasses may override this routine to provide different behavior.
2995  MultiExprArg SubExprs,
2996  SourceLocation RParenLoc) {
2997  // Find the declaration for __builtin_shufflevector
2998  const IdentifierInfo &Name
2999  = SemaRef.Context.Idents.get("__builtin_shufflevector");
3000  TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3001  DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3002  assert(!Lookup.empty() && "No __builtin_shufflevector?");
3003 
3004  // Build a reference to the __builtin_shufflevector builtin
3005  FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3006  Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3007  SemaRef.Context.BuiltinFnTy,
3008  VK_RValue, BuiltinLoc);
3009  QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3010  Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3011  CK_BuiltinFnToFnPtr).get();
3012 
3013  // Build the CallExpr
3014  ExprResult TheCall = new (SemaRef.Context) CallExpr(
3015  SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3016  Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
3017 
3018  // Type-check the __builtin_shufflevector expression.
3019  return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3020  }
3021 
3022  /// \brief Build a new convert vector expression.
3024  Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3025  SourceLocation RParenLoc) {
3026  return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3027  BuiltinLoc, RParenLoc);
3028  }
3029 
3030  /// \brief Build a new template argument pack expansion.
3031  ///
3032  /// By default, performs semantic analysis to build a new pack expansion
3033  /// for a template argument. Subclasses may override this routine to provide
3034  /// different behavior.
3036  SourceLocation EllipsisLoc,
3037  Optional<unsigned> NumExpansions) {
3038  switch (Pattern.getArgument().getKind()) {
3041  = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3042  EllipsisLoc, NumExpansions);
3043  if (Result.isInvalid())
3044  return TemplateArgumentLoc();
3045 
3046  return TemplateArgumentLoc(Result.get(), Result.get());
3047  }
3048 
3051  Pattern.getArgument().getAsTemplate(),
3052  NumExpansions),
3053  Pattern.getTemplateQualifierLoc(),
3054  Pattern.getTemplateNameLoc(),
3055  EllipsisLoc);
3056 
3063  llvm_unreachable("Pack expansion pattern has no parameter packs");
3064 
3066  if (TypeSourceInfo *Expansion
3067  = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3068  EllipsisLoc,
3069  NumExpansions))
3070  return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3071  Expansion);
3072  break;
3073  }
3074 
3075  return TemplateArgumentLoc();
3076  }
3077 
3078  /// \brief Build a new expression pack expansion.
3079  ///
3080  /// By default, performs semantic analysis to build a new pack expansion
3081  /// for an expression. Subclasses may override this routine to provide
3082  /// different behavior.
3084  Optional<unsigned> NumExpansions) {
3085  return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3086  }
3087 
3088  /// \brief Build a new C++1z fold-expression.
3089  ///
3090  /// By default, performs semantic analysis in order to build a new fold
3091  /// expression.
3093  BinaryOperatorKind Operator,
3094  SourceLocation EllipsisLoc, Expr *RHS,
3095  SourceLocation RParenLoc) {
3096  return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3097  RHS, RParenLoc);
3098  }
3099 
3100  /// \brief Build an empty C++1z fold-expression with the given operator.
3101  ///
3102  /// By default, produces the fallback value for the fold-expression, or
3103  /// produce an error if there is no fallback value.
3105  BinaryOperatorKind Operator) {
3106  return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3107  }
3108 
3109  /// \brief Build a new atomic operation expression.
3110  ///
3111  /// By default, performs semantic analysis to build the new expression.
3112  /// Subclasses may override this routine to provide different behavior.
3114  MultiExprArg SubExprs,
3115  QualType RetTy,
3117  SourceLocation RParenLoc) {
3118  // Just create the expression; there is not any interesting semantic
3119  // analysis here because we can't actually build an AtomicExpr until
3120  // we are sure it is semantically sound.
3121  return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3122  RParenLoc);
3123  }
3124 
3125 private:
3126  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3127  QualType ObjectType,
3128  NamedDecl *FirstQualifierInScope,
3129  CXXScopeSpec &SS);
3130 
3131  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3132  QualType ObjectType,
3133  NamedDecl *FirstQualifierInScope,
3134  CXXScopeSpec &SS);
3135 
3136  TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3137  NamedDecl *FirstQualifierInScope,
3138  CXXScopeSpec &SS);
3139 };
3140 
3141 template<typename Derived>
3143  if (!S)
3144  return S;
3145 
3146  switch (S->getStmtClass()) {
3147  case Stmt::NoStmtClass: break;
3148 
3149  // Transform individual statement nodes
3150 #define STMT(Node, Parent) \
3151  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3152 #define ABSTRACT_STMT(Node)
3153 #define EXPR(Node, Parent)
3154 #include "clang/AST/StmtNodes.inc"
3155 
3156  // Transform expressions by calling TransformExpr.
3157 #define STMT(Node, Parent)
3158 #define ABSTRACT_STMT(Stmt)
3159 #define EXPR(Node, Parent) case Stmt::Node##Class:
3160 #include "clang/AST/StmtNodes.inc"
3161  {
3162  ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3163  if (E.isInvalid())
3164  return StmtError();
3165 
3166  return getSema().ActOnExprStmt(E);
3167  }
3168  }
3169 
3170  return S;
3171 }
3172 
3173 template<typename Derived>
3175  if (!S)
3176  return S;
3177 
3178  switch (S->getClauseKind()) {
3179  default: break;
3180  // Transform individual clause nodes
3181 #define OPENMP_CLAUSE(Name, Class) \
3182  case OMPC_ ## Name : \
3183  return getDerived().Transform ## Class(cast<Class>(S));
3184 #include "clang/Basic/OpenMPKinds.def"
3185  }
3186 
3187  return S;
3188 }
3189 
3190 
3191 template<typename Derived>
3193  if (!E)
3194  return E;
3195 
3196  switch (E->getStmtClass()) {
3197  case Stmt::NoStmtClass: break;
3198 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3199 #define ABSTRACT_STMT(Stmt)
3200 #define EXPR(Node, Parent) \
3201  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3202 #include "clang/AST/StmtNodes.inc"
3203  }
3204 
3205  return E;
3206 }
3207 
3208 template<typename Derived>
3210  bool NotCopyInit) {
3211  // Initializers are instantiated like expressions, except that various outer
3212  // layers are stripped.
3213  if (!Init)
3214  return Init;
3215 
3216  if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3217  Init = ExprTemp->getSubExpr();
3218 
3219  if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3220  Init = MTE->GetTemporaryExpr();
3221 
3222  while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3223  Init = Binder->getSubExpr();
3224 
3225  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3226  Init = ICE->getSubExprAsWritten();
3227 
3228  if (CXXStdInitializerListExpr *ILE =
3229  dyn_cast<CXXStdInitializerListExpr>(Init))
3230  return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3231 
3232  // If this is copy-initialization, we only need to reconstruct
3233  // InitListExprs. Other forms of copy-initialization will be a no-op if
3234  // the initializer is already the right type.
3235  CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3236  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3237  return getDerived().TransformExpr(Init);
3238 
3239  // Revert value-initialization back to empty parens.
3240  if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3241  SourceRange Parens = VIE->getSourceRange();
3242  return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3243  Parens.getEnd());
3244  }
3245 
3246  // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3247  if (isa<ImplicitValueInitExpr>(Init))
3248  return getDerived().RebuildParenListExpr(SourceLocation(), None,
3249  SourceLocation());
3250 
3251  // Revert initialization by constructor back to a parenthesized or braced list
3252  // of expressions. Any other form of initializer can just be reused directly.
3253  if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3254  return getDerived().TransformExpr(Init);
3255 
3256  // If the initialization implicitly converted an initializer list to a
3257  // std::initializer_list object, unwrap the std::initializer_list too.
3258  if (Construct && Construct->isStdInitListInitialization())
3259  return TransformInitializer(Construct->getArg(0), NotCopyInit);
3260 
3261  SmallVector<Expr*, 8> NewArgs;
3262  bool ArgChanged = false;
3263  if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3264  /*IsCall*/true, NewArgs, &ArgChanged))
3265  return ExprError();
3266 
3267  // If this was list initialization, revert to list form.
3268  if (Construct->isListInitialization())
3269  return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3270  Construct->getLocEnd(),
3271  Construct->getType());
3272 
3273  // Build a ParenListExpr to represent anything else.
3274  SourceRange Parens = Construct->getParenOrBraceRange();
3275  if (Parens.isInvalid()) {
3276  // This was a variable declaration's initialization for which no initializer
3277  // was specified.
3278  assert(NewArgs.empty() &&
3279  "no parens or braces but have direct init with arguments?");
3280  return ExprEmpty();
3281  }
3282  return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3283  Parens.getEnd());
3284 }
3285 
3286 template<typename Derived>
3288  unsigned NumInputs,
3289  bool IsCall,
3290  SmallVectorImpl<Expr *> &Outputs,
3291  bool *ArgChanged) {
3292  for (unsigned I = 0; I != NumInputs; ++I) {
3293  // If requested, drop call arguments that need to be dropped.
3294  if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3295  if (ArgChanged)
3296  *ArgChanged = true;
3297 
3298  break;
3299  }
3300 
3301  if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3302  Expr *Pattern = Expansion->getPattern();
3303 
3305  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3306  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3307 
3308  // Determine whether the set of unexpanded parameter packs can and should
3309  // be expanded.
3310  bool Expand = true;
3311  bool RetainExpansion = false;
3312  Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3313  Optional<unsigned> NumExpansions = OrigNumExpansions;
3314  if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3315  Pattern->getSourceRange(),
3316  Unexpanded,
3317  Expand, RetainExpansion,
3318  NumExpansions))
3319  return true;
3320 
3321  if (!Expand) {
3322  // The transform has determined that we should perform a simple
3323  // transformation on the pack expansion, producing another pack
3324  // expansion.
3325  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3326  ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3327  if (OutPattern.isInvalid())
3328  return true;
3329 
3330  ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3331  Expansion->getEllipsisLoc(),
3332  NumExpansions);
3333  if (Out.isInvalid())
3334  return true;
3335 
3336  if (ArgChanged)
3337  *ArgChanged = true;
3338  Outputs.push_back(Out.get());
3339  continue;
3340  }
3341 
3342  // Record right away that the argument was changed. This needs
3343  // to happen even if the array expands to nothing.
3344  if (ArgChanged) *ArgChanged = true;
3345 
3346  // The transform has determined that we should perform an elementwise
3347  // expansion of the pattern. Do so.
3348  for (unsigned I = 0; I != *NumExpansions; ++I) {
3349  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3350  ExprResult Out = getDerived().TransformExpr(Pattern);
3351  if (Out.isInvalid())
3352  return true;
3353 
3354  if (Out.get()->containsUnexpandedParameterPack()) {
3355  Out = getDerived().RebuildPackExpansion(
3356  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3357  if (Out.isInvalid())
3358  return true;
3359  }
3360 
3361  Outputs.push_back(Out.get());
3362  }
3363 
3364  // If we're supposed to retain a pack expansion, do so by temporarily
3365  // forgetting the partially-substituted parameter pack.
3366  if (RetainExpansion) {
3367  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3368 
3369  ExprResult Out = getDerived().TransformExpr(Pattern);
3370  if (Out.isInvalid())
3371  return true;
3372 
3373  Out = getDerived().RebuildPackExpansion(
3374  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3375  if (Out.isInvalid())
3376  return true;
3377 
3378  Outputs.push_back(Out.get());
3379  }
3380 
3381  continue;
3382  }
3383 
3384  ExprResult Result =
3385  IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3386  : getDerived().TransformExpr(Inputs[I]);
3387  if (Result.isInvalid())
3388  return true;
3389 
3390  if (Result.get() != Inputs[I] && ArgChanged)
3391  *ArgChanged = true;
3392 
3393  Outputs.push_back(Result.get());
3394  }
3395 
3396  return false;
3397 }
3398 
3399 template <typename Derived>
3402  if (Var) {
3403  VarDecl *ConditionVar = cast_or_null<VarDecl>(
3404  getDerived().TransformDefinition(Var->getLocation(), Var));
3405 
3406  if (!ConditionVar)
3407  return Sema::ConditionError();
3408 
3409  return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3410  }
3411 
3412  if (Expr) {
3413  ExprResult CondExpr = getDerived().TransformExpr(Expr);
3414 
3415  if (CondExpr.isInvalid())
3416  return Sema::ConditionError();
3417 
3418  return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3419  }
3420 
3421  return Sema::ConditionResult();
3422 }
3423 
3424 template<typename Derived>
3428  QualType ObjectType,
3429  NamedDecl *FirstQualifierInScope) {
3431  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3432  Qualifier = Qualifier.getPrefix())
3433  Qualifiers.push_back(Qualifier);
3434 
3435  CXXScopeSpec SS;
3436  while (!Qualifiers.empty()) {
3437  NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3439 
3440  switch (QNNS->getKind()) {
3442  if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
3443  *QNNS->getAsIdentifier(),
3444  Q.getLocalBeginLoc(),
3445  Q.getLocalEndLoc(),
3446  ObjectType, false, SS,
3447  FirstQualifierInScope, false))
3448  return NestedNameSpecifierLoc();
3449 
3450  break;
3451 
3453  NamespaceDecl *NS
3454  = cast_or_null<NamespaceDecl>(
3455  getDerived().TransformDecl(
3456  Q.getLocalBeginLoc(),
3457  QNNS->getAsNamespace()));
3458  SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3459  break;
3460  }
3461 
3463  NamespaceAliasDecl *Alias
3464  = cast_or_null<NamespaceAliasDecl>(
3465  getDerived().TransformDecl(Q.getLocalBeginLoc(),
3466  QNNS->getAsNamespaceAlias()));
3467  SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3468  Q.getLocalEndLoc());
3469  break;
3470  }
3471 
3473  // There is no meaningful transformation that one could perform on the
3474  // global scope.
3475  SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3476  break;
3477 
3479  CXXRecordDecl *RD =
3480  cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3481  SourceLocation(), QNNS->getAsRecordDecl()));
3482  SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3483  break;
3484  }
3485 
3488  TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3489  FirstQualifierInScope, SS);
3490 
3491  if (!TL)
3492  return NestedNameSpecifierLoc();
3493 
3494  if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3495  (SemaRef.getLangOpts().CPlusPlus11 &&
3496  TL.getType()->isEnumeralType())) {
3497  assert(!TL.getType().hasLocalQualifiers() &&
3498  "Can't get cv-qualifiers here");
3499  if (TL.getType()->isEnumeralType())
3500  SemaRef.Diag(TL.getBeginLoc(),
3501  diag::warn_cxx98_compat_enum_nested_name_spec);
3502  SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3503  Q.getLocalEndLoc());
3504  break;
3505  }
3506  // If the nested-name-specifier is an invalid type def, don't emit an
3507  // error because a previous error should have already been emitted.
3508  TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3509  if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3510  SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3511  << TL.getType() << SS.getRange();
3512  }
3513  return NestedNameSpecifierLoc();
3514  }
3515  }
3516 
3517  // The qualifier-in-scope and object type only apply to the leftmost entity.
3518  FirstQualifierInScope = nullptr;
3519  ObjectType = QualType();
3520  }
3521 
3522  // Don't rebuild the nested-name-specifier if we don't have to.
3523  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3524  !getDerived().AlwaysRebuild())
3525  return NNS;
3526 
3527  // If we can re-use the source-location data from the original
3528  // nested-name-specifier, do so.
3529  if (SS.location_size() == NNS.getDataLength() &&
3530  memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3531  return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3532 
3533  // Allocate new nested-name-specifier location information.
3534  return SS.getWithLocInContext(SemaRef.Context);
3535 }
3536 
3537 template<typename Derived>
3541  DeclarationName Name = NameInfo.getName();
3542  if (!Name)
3543  return DeclarationNameInfo();
3544 
3545  switch (Name.getNameKind()) {
3553  return NameInfo;
3554 
3558  TypeSourceInfo *NewTInfo;
3559  CanQualType NewCanTy;
3560  if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3561  NewTInfo = getDerived().TransformType(OldTInfo);
3562  if (!NewTInfo)
3563  return DeclarationNameInfo();
3564  NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3565  }
3566  else {
3567  NewTInfo = nullptr;
3568  TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3569  QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3570  if (NewT.isNull())
3571  return DeclarationNameInfo();
3572  NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3573  }
3574 
3575  DeclarationName NewName
3576  = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3577  NewCanTy);
3578  DeclarationNameInfo NewNameInfo(NameInfo);
3579  NewNameInfo.setName(NewName);
3580  NewNameInfo.setNamedTypeInfo(NewTInfo);
3581  return NewNameInfo;
3582  }
3583  }
3584 
3585  llvm_unreachable("Unknown name kind.");
3586 }
3587 
3588 template<typename Derived>
3592  SourceLocation NameLoc,
3593  QualType ObjectType,
3594  NamedDecl *FirstQualifierInScope) {
3596  TemplateDecl *Template = QTN->getTemplateDecl();
3597  assert(Template && "qualified template name must refer to a template");
3598 
3599  TemplateDecl *TransTemplate
3600  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3601  Template));
3602  if (!TransTemplate)
3603  return TemplateName();
3604 
3605  if (!getDerived().AlwaysRebuild() &&
3606  SS.getScopeRep() == QTN->getQualifier() &&
3607  TransTemplate == Template)
3608  return Name;
3609 
3610  return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3611  TransTemplate);
3612  }
3613 
3615  if (SS.getScopeRep()) {
3616  // These apply to the scope specifier, not the template.
3617  ObjectType = QualType();
3618  FirstQualifierInScope = nullptr;
3619  }
3620 
3621  if (!getDerived().AlwaysRebuild() &&
3622  SS.getScopeRep() == DTN->getQualifier() &&
3623  ObjectType.isNull())
3624  return Name;
3625 
3626  if (DTN->isIdentifier()) {
3627  return getDerived().RebuildTemplateName(SS,
3628  *DTN->getIdentifier(),
3629  NameLoc,
3630  ObjectType,
3631  FirstQualifierInScope);
3632  }
3633 
3634  return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3635  ObjectType);
3636  }
3637 
3638  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3639  TemplateDecl *TransTemplate
3640  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3641  Template));
3642  if (!TransTemplate)
3643  return TemplateName();
3644 
3645  if (!getDerived().AlwaysRebuild() &&
3646  TransTemplate == Template)
3647  return Name;
3648 
3649  return TemplateName(TransTemplate);
3650  }
3651 
3654  TemplateTemplateParmDecl *TransParam
3655  = cast_or_null<TemplateTemplateParmDecl>(
3656  getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3657  if (!TransParam)
3658  return TemplateName();
3659 
3660  if (!getDerived().AlwaysRebuild() &&
3661  TransParam == SubstPack->getParameterPack())
3662  return Name;
3663 
3664  return getDerived().RebuildTemplateName(TransParam,
3665  SubstPack->getArgumentPack());
3666  }
3667 
3668  // These should be getting filtered out before they reach the AST.
3669  llvm_unreachable("overloaded function decl survived to here");
3670 }
3671 
3672 template<typename Derived>
3674  const TemplateArgument &Arg,
3675  TemplateArgumentLoc &Output) {
3676  SourceLocation Loc = getDerived().getBaseLocation();
3677  switch (Arg.getKind()) {
3679  llvm_unreachable("null template argument in TreeTransform");
3680  break;
3681 
3683  Output = TemplateArgumentLoc(Arg,
3684  SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3685 
3686  break;
3687 
3692  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3693  Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3694  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3695  Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3696 
3697  if (Arg.getKind() == TemplateArgument::Template)
3698  Output = TemplateArgumentLoc(Arg,
3699  Builder.getWithLocInContext(SemaRef.Context),
3700  Loc);
3701  else
3702  Output = TemplateArgumentLoc(Arg,
3703  Builder.getWithLocInContext(SemaRef.Context),
3704  Loc, Loc);
3705 
3706  break;
3707  }
3708 
3710  Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3711  break;
3712 
3718  break;
3719  }
3720 }
3721 
3722 template<typename Derived>
3724  const TemplateArgumentLoc &Input,
3725  TemplateArgumentLoc &Output, bool Uneval) {
3726  const TemplateArgument &Arg = Input.getArgument();
3727  switch (Arg.getKind()) {
3733  llvm_unreachable("Unexpected TemplateArgument");
3734 
3735  case TemplateArgument::Type: {
3736  TypeSourceInfo *DI = Input.getTypeSourceInfo();
3737  if (!DI)
3738  DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3739 
3740  DI = getDerived().TransformType(DI);
3741  if (!DI) return true;
3742 
3743  Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3744  return false;
3745  }
3746 
3748  NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3749  if (QualifierLoc) {
3750  QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3751  if (!QualifierLoc)
3752  return true;
3753  }
3754 
3755  CXXScopeSpec SS;
3756  SS.Adopt(QualifierLoc);
3757  TemplateName Template
3758  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3759  Input.getTemplateNameLoc());
3760  if (Template.isNull())
3761  return true;
3762 
3763  Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3764  Input.getTemplateNameLoc());
3765  return false;
3766  }
3767 
3769  llvm_unreachable("Caller should expand pack expansions");
3770 
3772  // Template argument expressions are constant expressions.
3774  getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
3775 
3776  Expr *InputExpr = Input.getSourceExpression();
3777  if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3778 
3779  ExprResult E = getDerived().TransformExpr(InputExpr);
3780  E = SemaRef.ActOnConstantExpression(E);
3781  if (E.isInvalid()) return true;
3782  Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3783  return false;
3784  }
3785  }
3786 
3787  // Work around bogus GCC warning
3788  return true;
3789 }
3790 
3791 /// \brief Iterator adaptor that invents template argument location information
3792 /// for each of the template arguments in its underlying iterator.
3793 template<typename Derived, typename InputIterator>
3795  TreeTransform<Derived> &Self;
3796  InputIterator Iter;
3797 
3798 public:
3801  typedef typename std::iterator_traits<InputIterator>::difference_type
3803  typedef std::input_iterator_tag iterator_category;
3804 
3805  class pointer {
3806  TemplateArgumentLoc Arg;
3807 
3808  public:
3809  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3810 
3811  const TemplateArgumentLoc *operator->() const { return &Arg; }
3812  };
3813 
3815 
3817  InputIterator Iter)
3818  : Self(Self), Iter(Iter) { }
3819 
3821  ++Iter;
3822  return *this;
3823  }
3824 
3827  ++(*this);
3828  return Old;
3829  }
3830 
3833  Self.InventTemplateArgumentLoc(*Iter, Result);
3834  return Result;
3835  }
3836 
3837  pointer operator->() const { return pointer(**this); }
3838 
3841  return X.Iter == Y.Iter;
3842  }
3843 
3846  return X.Iter != Y.Iter;
3847  }
3848 };
3849 
3850 template<typename Derived>
3851 template<typename InputIterator>
3853  InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3854  bool Uneval) {
3855  for (; First != Last; ++First) {
3856  TemplateArgumentLoc Out;
3857  TemplateArgumentLoc In = *First;
3858 
3859  if (In.getArgument().getKind() == TemplateArgument::Pack) {
3860  // Unpack argument packs, which we translate them into separate
3861  // arguments.
3862  // FIXME: We could do much better if we could guarantee that the
3863  // TemplateArgumentLocInfo for the pack expansion would be usable for
3864  // all of the template arguments in the argument pack.
3865  typedef TemplateArgumentLocInventIterator<Derived,
3867  PackLocIterator;
3868  if (TransformTemplateArguments(PackLocIterator(*this,
3869  In.getArgument().pack_begin()),
3870  PackLocIterator(*this,
3871  In.getArgument().pack_end()),
3872  Outputs, Uneval))
3873  return true;
3874 
3875  continue;
3876  }
3877 
3878  if (In.getArgument().isPackExpansion()) {
3879  // We have a pack expansion, for which we will be substituting into
3880  // the pattern.
3881  SourceLocation Ellipsis;
3882  Optional<unsigned> OrigNumExpansions;
3883  TemplateArgumentLoc Pattern
3884  = getSema().getTemplateArgumentPackExpansionPattern(
3885  In, Ellipsis, OrigNumExpansions);
3886 
3888  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3889  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3890 
3891  // Determine whether the set of unexpanded parameter packs can and should
3892  // be expanded.
3893  bool Expand = true;
3894  bool RetainExpansion = false;
3895  Optional<unsigned> NumExpansions = OrigNumExpansions;
3896  if (getDerived().TryExpandParameterPacks(Ellipsis,
3897  Pattern.getSourceRange(),
3898  Unexpanded,
3899  Expand,
3900  RetainExpansion,
3901  NumExpansions))
3902  return true;
3903 
3904  if (!Expand) {
3905  // The transform has determined that we should perform a simple
3906  // transformation on the pack expansion, producing another pack
3907  // expansion.
3908  TemplateArgumentLoc OutPattern;
3909  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3910  if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
3911  return true;
3912 
3913  Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3914  NumExpansions);
3915  if (Out.getArgument().isNull())
3916  return true;
3917 
3918  Outputs.addArgument(Out);
3919  continue;
3920  }
3921 
3922  // The transform has determined that we should perform an elementwise
3923  // expansion of the pattern. Do so.
3924  for (unsigned I = 0; I != *NumExpansions; ++I) {
3925  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3926 
3927  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3928  return true;
3929 
3931  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3932  OrigNumExpansions);
3933  if (Out.getArgument().isNull())
3934  return true;
3935  }
3936 
3937  Outputs.addArgument(Out);
3938  }
3939 
3940  // If we're supposed to retain a pack expansion, do so by temporarily
3941  // forgetting the partially-substituted parameter pack.
3942  if (RetainExpansion) {
3943  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3944 
3945  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3946  return true;
3947 
3948  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3949  OrigNumExpansions);
3950  if (Out.getArgument().isNull())
3951  return true;
3952 
3953  Outputs.addArgument(Out);
3954  }
3955 
3956  continue;
3957  }
3958 
3959  // The simple case:
3960  if (getDerived().TransformTemplateArgument(In, Out, Uneval))
3961  return true;
3962 
3963  Outputs.addArgument(Out);
3964  }
3965 
3966  return false;
3967 
3968 }
3969 
3970 //===----------------------------------------------------------------------===//
3971 // Type transformation
3972 //===----------------------------------------------------------------------===//
3973 
3974 template<typename Derived>
3976  if (getDerived().AlreadyTransformed(T))
3977  return T;
3978 
3979  // Temporary workaround. All of these transformations should
3980  // eventually turn into transformations on TypeLocs.
3981  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3982  getDerived().getBaseLocation());
3983 
3984  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3985 
3986  if (!NewDI)
3987  return QualType();
3988 
3989  return NewDI->getType();
3990 }
3991 
3992 template<typename Derived>
3994  // Refine the base location to the type's location.
3995  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3996  getDerived().getBaseEntity());
3997  if (getDerived().AlreadyTransformed(DI->getType()))
3998  return DI;
3999 
4000  TypeLocBuilder TLB;
4001 
4002  TypeLoc TL = DI->getTypeLoc();
4003  TLB.reserve(TL.getFullDataSize());
4004 
4005  QualType Result = getDerived().TransformType(TLB, TL);
4006  if (Result.isNull())
4007  return nullptr;
4008 
4009  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4010 }
4011 
4012 template<typename Derived>
4013 QualType
4015  switch (T.getTypeLocClass()) {
4016 #define ABSTRACT_TYPELOC(CLASS, PARENT)
4017 #define TYPELOC(CLASS, PARENT) \
4018  case TypeLoc::CLASS: \
4019  return getDerived().Transform##CLASS##Type(TLB, \
4020  T.castAs<CLASS##TypeLoc>());
4021 #include "clang/AST/TypeLocNodes.def"
4022  }
4023 
4024  llvm_unreachable("unhandled type loc!");
4025 }
4026 
4027 /// FIXME: By default, this routine adds type qualifiers only to types
4028 /// that can have qualifiers, and silently suppresses those qualifiers
4029 /// that are not permitted (e.g., qualifiers on reference or function
4030 /// types). This is the right thing for template instantiation, but
4031 /// probably not for other clients.
4032 template<typename Derived>
4033 QualType
4035  QualifiedTypeLoc T) {
4036  Qualifiers Quals = T.getType().getLocalQualifiers();
4037 
4038  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
4039  if (Result.isNull())
4040  return QualType();
4041 
4042  // Silently suppress qualifiers if the result type can't be qualified.
4043  // FIXME: this is the right thing for template instantiation, but
4044  // probably not for other clients.
4045  if (Result->isFunctionType() || Result->isReferenceType())
4046  return Result;
4047 
4048  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
4049  // resulting type.
4050  if (Quals.hasObjCLifetime()) {
4051  if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4052  Quals.removeObjCLifetime();
4053  else if (Result.getObjCLifetime()) {
4054  // Objective-C ARC:
4055  // A lifetime qualifier applied to a substituted template parameter
4056  // overrides the lifetime qualifier from the template argument.
4057  const AutoType *AutoTy;
4058  if (const SubstTemplateTypeParmType *SubstTypeParam
4059  = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4060  QualType Replacement = SubstTypeParam->getReplacementType();
4061  Qualifiers Qs = Replacement.getQualifiers();
4062  Qs.removeObjCLifetime();
4063  Replacement
4064  = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4065  Qs);
4066  Result = SemaRef.Context.getSubstTemplateTypeParmType(
4067  SubstTypeParam->getReplacedParameter(),
4068  Replacement);
4069  TLB.TypeWasModifiedSafely(Result);
4070  } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4071  // 'auto' types behave the same way as template parameters.
4072  QualType Deduced = AutoTy->getDeducedType();
4073  Qualifiers Qs = Deduced.getQualifiers();
4074  Qs.removeObjCLifetime();
4075  Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4076  Qs);
4077  Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4078  AutoTy->isDependentType());
4079  TLB.TypeWasModifiedSafely(Result);
4080  } else {
4081  // Otherwise, complain about the addition of a qualifier to an
4082  // already-qualified type.
4083  SourceRange R = T.getUnqualifiedLoc().getSourceRange();
4084  SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
4085  << Result << R;
4086 
4087  Quals.removeObjCLifetime();
4088  }
4089  }
4090  }
4091  if (!Quals.empty()) {
4092  Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
4093  // BuildQualifiedType might not add qualifiers if they are invalid.
4094  if (Result.hasLocalQualifiers())
4095  TLB.push<QualifiedTypeLoc>(Result);
4096  // No location information to preserve.
4097  }
4098 
4099  return Result;
4100 }
4101 
4102 template<typename Derived>
4103 TypeLoc
4104 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4105  QualType ObjectType,
4106  NamedDecl *UnqualLookup,
4107  CXXScopeSpec &SS) {
4108  if (getDerived().AlreadyTransformed(TL.getType()))
4109  return TL;
4110 
4111  TypeSourceInfo *TSI =
4112  TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4113  if (TSI)
4114  return TSI->getTypeLoc();
4115  return TypeLoc();
4116 }
4117 
4118 template<typename Derived>
4119 TypeSourceInfo *
4120 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4121  QualType ObjectType,
4122  NamedDecl *UnqualLookup,
4123  CXXScopeSpec &SS) {
4124  if (getDerived().AlreadyTransformed(TSInfo->getType()))
4125  return TSInfo;
4126 
4127  return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4128  UnqualLookup, SS);
4129 }
4130 
4131 template <typename Derived>
4132 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4133  TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4134  CXXScopeSpec &SS) {
4135  QualType T = TL.getType();
4136  assert(!getDerived().AlreadyTransformed(T));
4137 
4138  TypeLocBuilder TLB;
4139  QualType Result;
4140 
4141  if (isa<TemplateSpecializationType>(T)) {
4142  TemplateSpecializationTypeLoc SpecTL =
4143  TL.castAs<TemplateSpecializationTypeLoc>();
4144 
4145  TemplateName Template
4146  = getDerived().TransformTemplateName(SS,
4147  SpecTL.getTypePtr()->getTemplateName(),
4148  SpecTL.getTemplateNameLoc(),
4149  ObjectType, UnqualLookup);
4150  if (Template.isNull())
4151  return nullptr;
4152 
4153  Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4154  Template);
4155  } else if (isa<DependentTemplateSpecializationType>(T)) {
4156  DependentTemplateSpecializationTypeLoc SpecTL =
4157  TL.castAs<DependentTemplateSpecializationTypeLoc>();
4158 
4159  TemplateName Template
4160  = getDerived().RebuildTemplateName(SS,
4161  *SpecTL.getTypePtr()->getIdentifier(),
4162  SpecTL.getTemplateNameLoc(),
4163  ObjectType, UnqualLookup);
4164  if (Template.isNull())
4165  return nullptr;
4166 
4167  Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4168  SpecTL,
4169  Template,
4170  SS);
4171  } else {
4172  // Nothing special needs to be done for these.
4173  Result = getDerived().TransformType(TLB, TL);
4174  }
4175 
4176  if (Result.isNull())
4177  return nullptr;
4178 
4179  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4180 }
4181 
4182 template <class TyLoc> static inline
4184  TyLoc NewT = TLB.push<TyLoc>(T.getType());
4185  NewT.setNameLoc(T.getNameLoc());
4186  return T.getType();
4187 }
4188 
4189 template<typename Derived>
4190 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4191  BuiltinTypeLoc T) {
4192  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4193  NewT.setBuiltinLoc(T.getBuiltinLoc());
4194  if (T.needsExtraLocalData())
4195  NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4196  return T.getType();
4197 }
4198 
4199 template<typename Derived>
4200 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4201  ComplexTypeLoc T) {
4202  // FIXME: recurse?
4203  return TransformTypeSpecType(TLB, T);
4204 }
4205 
4206 template <typename Derived>
4207 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4208  AdjustedTypeLoc TL) {
4209  // Adjustments applied during transformation are handled elsewhere.
4210  return getDerived().TransformType(TLB, TL.getOriginalLoc());
4211 }
4212 
4213 template<typename Derived>
4214 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4215  DecayedTypeLoc TL) {
4216  QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4217  if (OriginalType.isNull())
4218  return QualType();
4219 
4220  QualType Result = TL.getType();
4221  if (getDerived().AlwaysRebuild() ||
4222  OriginalType != TL.getOriginalLoc().getType())
4223  Result = SemaRef.Context.getDecayedType(OriginalType);
4224  TLB.push<DecayedTypeLoc>(Result);
4225  // Nothing to set for DecayedTypeLoc.
4226  return Result;
4227 }
4228 
4229 template<typename Derived>
4230 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4231  PointerTypeLoc TL) {
4232  QualType PointeeType
4233  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4234  if (PointeeType.isNull())
4235  return QualType();
4236 
4237  QualType Result = TL.getType();
4238  if (PointeeType->getAs<ObjCObjectType>()) {
4239  // A dependent pointer type 'T *' has is being transformed such
4240  // that an Objective-C class type is being replaced for 'T'. The
4241  // resulting pointer type is an ObjCObjectPointerType, not a
4242  // PointerType.
4243  Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4244 
4245  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4246  NewT.setStarLoc(TL.getStarLoc());
4247  return Result;
4248  }
4249 
4250  if (getDerived().AlwaysRebuild() ||
4251  PointeeType != TL.getPointeeLoc().getType()) {
4252  Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4253  if (Result.isNull())
4254  return QualType();
4255  }
4256 
4257  // Objective-C ARC can add lifetime qualifiers to the type that we're
4258  // pointing to.
4259  TLB.TypeWasModifiedSafely(Result->getPointeeType());
4260 
4261  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4262  NewT.setSigilLoc(TL.getSigilLoc());
4263  return Result;
4264 }
4265 
4266 template<typename Derived>
4267 QualType
4268 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4269  BlockPointerTypeLoc TL) {
4270  QualType PointeeType
4271  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4272  if (PointeeType.isNull())
4273  return QualType();
4274 
4275  QualType Result = TL.getType();
4276  if (getDerived().AlwaysRebuild() ||
4277  PointeeType != TL.getPointeeLoc().getType()) {
4278  Result = getDerived().RebuildBlockPointerType(PointeeType,
4279  TL.getSigilLoc());
4280  if (Result.isNull())
4281  return QualType();
4282  }
4283 
4284  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4285  NewT.setSigilLoc(TL.getSigilLoc());
4286  return Result;
4287 }
4288 
4289 /// Transforms a reference type. Note that somewhat paradoxically we
4290 /// don't care whether the type itself is an l-value type or an r-value
4291 /// type; we only care if the type was *written* as an l-value type
4292 /// or an r-value type.
4293 template<typename Derived>
4294 QualType
4296  ReferenceTypeLoc TL) {
4297  const ReferenceType *T = TL.getTypePtr();
4298 
4299  // Note that this works with the pointee-as-written.
4300  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4301  if (PointeeType.isNull())
4302  return QualType();
4303 
4304  QualType Result = TL.getType();
4305  if (getDerived().AlwaysRebuild() ||
4306  PointeeType != T->getPointeeTypeAsWritten()) {
4307  Result = getDerived().RebuildReferenceType(PointeeType,
4308  T->isSpelledAsLValue(),
4309  TL.getSigilLoc());
4310  if (Result.isNull())
4311  return QualType();
4312  }
4313 
4314  // Objective-C ARC can add lifetime qualifiers to the type that we're
4315  // referring to.
4318 
4319  // r-value references can be rebuilt as l-value references.
4320  ReferenceTypeLoc NewTL;
4321  if (isa<LValueReferenceType>(Result))
4322  NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4323  else
4324  NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4325  NewTL.setSigilLoc(TL.getSigilLoc());
4326 
4327  return Result;
4328 }
4329 
4330 template<typename Derived>
4331 QualType
4334  return TransformReferenceType(TLB, TL);
4335 }
4336 
4337 template<typename Derived>
4338 QualType
4339 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4340  RValueReferenceTypeLoc TL) {
4341  return TransformReferenceType(TLB, TL);
4342 }
4343 
4344 template<typename Derived>
4345 QualType
4346 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4347  MemberPointerTypeLoc TL) {
4348  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4349  if (PointeeType.isNull())
4350  return QualType();
4351 
4352  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4353  TypeSourceInfo *NewClsTInfo = nullptr;
4354  if (OldClsTInfo) {
4355  NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4356  if (!NewClsTInfo)
4357  return QualType();
4358  }
4359 
4360  const MemberPointerType *T = TL.getTypePtr();
4361  QualType OldClsType = QualType(T->getClass(), 0);
4362  QualType NewClsType;
4363  if (NewClsTInfo)
4364  NewClsType = NewClsTInfo->getType();
4365  else {
4366  NewClsType = getDerived().TransformType(OldClsType);
4367  if (NewClsType.isNull())
4368  return QualType();
4369  }
4370 
4371  QualType Result = TL.getType();
4372  if (getDerived().AlwaysRebuild() ||
4373  PointeeType != T->getPointeeType() ||
4374  NewClsType != OldClsType) {
4375  Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4376  TL.getStarLoc());
4377  if (Result.isNull())
4378  return QualType();
4379  }
4380 
4381  // If we had to adjust the pointee type when building a member pointer, make
4382  // sure to push TypeLoc info for it.
4383  const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4384  if (MPT && PointeeType != MPT->getPointeeType()) {
4385  assert(isa<AdjustedType>(MPT->getPointeeType()));
4386  TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4387  }
4388 
4389  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4390  NewTL.setSigilLoc(TL.getSigilLoc());
4391  NewTL.setClassTInfo(NewClsTInfo);
4392 
4393  return Result;
4394 }
4395 
4396 template<typename Derived>
4397 QualType
4398 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4399  ConstantArrayTypeLoc TL) {
4400  const ConstantArrayType *T = TL.getTypePtr();
4401  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4402  if (ElementType.isNull())
4403  return QualType();
4404 
4405  QualType Result = TL.getType();
4406  if (getDerived().AlwaysRebuild() ||
4407  ElementType != T->getElementType()) {
4408  Result = getDerived().RebuildConstantArrayType(ElementType,
4409  T->getSizeModifier(),
4410  T->getSize(),
4411  T->getIndexTypeCVRQualifiers(),
4412  TL.getBracketsRange());
4413  if (Result.isNull())
4414  return QualType();
4415  }
4416 
4417  // We might have either a ConstantArrayType or a VariableArrayType now:
4418  // a ConstantArrayType is allowed to have an element type which is a
4419  // VariableArrayType if the type is dependent. Fortunately, all array
4420  // types have the same location layout.
4421  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4422  NewTL.setLBracketLoc(TL.getLBracketLoc());
4423  NewTL.setRBracketLoc(TL.getRBracketLoc());
4424 
4425  Expr *Size = TL.getSizeExpr();
4426  if (Size) {
4427  EnterExpressionEvaluationContext Unevaluated(SemaRef,
4429  Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4430  Size = SemaRef.ActOnConstantExpression(Size).get();
4431  }
4432  NewTL.setSizeExpr(Size);
4433 
4434  return Result;
4435 }
4436 
4437 template<typename Derived>
4438 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4439  TypeLocBuilder &TLB,
4440  IncompleteArrayTypeLoc TL) {
4441  const IncompleteArrayType *T = TL.getTypePtr();
4442  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4443  if (ElementType.isNull())
4444  return QualType();
4445 
4446  QualType Result = TL.getType();
4447  if (getDerived().AlwaysRebuild() ||
4448  ElementType != T->getElementType()) {
4449  Result = getDerived().RebuildIncompleteArrayType(ElementType,
4450  T->getSizeModifier(),
4451  T->getIndexTypeCVRQualifiers(),
4452  TL.getBracketsRange());
4453  if (Result.isNull())
4454  return QualType();
4455  }
4456 
4457  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4458  NewTL.setLBracketLoc(TL.getLBracketLoc());
4459  NewTL.setRBracketLoc(TL.getRBracketLoc());
4460  NewTL.setSizeExpr(nullptr);
4461 
4462  return Result;
4463 }
4464 
4465 template<typename Derived>
4466 QualType
4467 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4468  VariableArrayTypeLoc TL) {
4469  const VariableArrayType *T = TL.getTypePtr();
4470  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4471  if (ElementType.isNull())
4472  return QualType();
4473 
4474  ExprResult SizeResult
4475  = getDerived().TransformExpr(T->getSizeExpr());
4476  if (SizeResult.isInvalid())
4477  return QualType();
4478 
4479  Expr *Size = SizeResult.get();
4480 
4481  QualType Result = TL.getType();
4482  if (getDerived().AlwaysRebuild() ||
4483  ElementType != T->getElementType() ||
4484  Size != T->getSizeExpr()) {
4485  Result = getDerived().RebuildVariableArrayType(ElementType,
4486  T->getSizeModifier(),
4487  Size,
4488  T->getIndexTypeCVRQualifiers(),
4489  TL.getBracketsRange());
4490  if (Result.isNull())
4491  return QualType();
4492  }
4493 
4494  // We might have constant size array now, but fortunately it has the same
4495  // location layout.
4496  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4497  NewTL.setLBracketLoc(TL.getLBracketLoc());
4498  NewTL.setRBracketLoc(TL.getRBracketLoc());
4499  NewTL.setSizeExpr(Size);
4500 
4501  return Result;
4502 }
4503 
4504 template<typename Derived>
4505 QualType
4506 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4507  DependentSizedArrayTypeLoc TL) {
4508  const DependentSizedArrayType *T = TL.getTypePtr();
4509  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4510  if (ElementType.isNull())
4511  return QualType();
4512 
4513  // Array bounds are constant expressions.
4514  EnterExpressionEvaluationContext Unevaluated(SemaRef,
4516 
4517  // Prefer the expression from the TypeLoc; the other may have been uniqued.
4518  Expr *origSize = TL.getSizeExpr();
4519  if (!origSize) origSize = T->getSizeExpr();
4520 
4521  ExprResult sizeResult
4522  = getDerived().TransformExpr(origSize);
4523  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4524  if (sizeResult.isInvalid())
4525  return QualType();
4526 
4527  Expr *size = sizeResult.get();
4528 
4529  QualType Result = TL.getType();
4530  if (getDerived().AlwaysRebuild() ||
4531  ElementType != T->getElementType() ||
4532  size != origSize) {
4533  Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4534  T->getSizeModifier(),
4535  size,
4536  T->getIndexTypeCVRQualifiers(),
4537  TL.getBracketsRange());
4538  if (Result.isNull())
4539  return QualType();
4540  }
4541 
4542  // We might have any sort of array type now, but fortunately they
4543  // all have the same location layout.
4544  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4545  NewTL.setLBracketLoc(TL.getLBracketLoc());
4546  NewTL.setRBracketLoc(TL.getRBracketLoc());
4547  NewTL.setSizeExpr(size);
4548 
4549  return Result;
4550 }
4551 
4552 template<typename Derived>
4553 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4554  TypeLocBuilder &TLB,
4555  DependentSizedExtVectorTypeLoc TL) {
4556  const DependentSizedExtVectorType *T = TL.getTypePtr();
4557 
4558  // FIXME: ext vector locs should be nested
4559  QualType ElementType = getDerived().TransformType(T->getElementType());
4560  if (ElementType.isNull())
4561  return QualType();
4562 
4563  // Vector sizes are constant expressions.
4564  EnterExpressionEvaluationContext Unevaluated(SemaRef,
4566 
4567  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4568  Size = SemaRef.ActOnConstantExpression(Size);
4569  if (Size.isInvalid())
4570  return QualType();
4571 
4572  QualType Result = TL.getType();
4573  if (getDerived().AlwaysRebuild() ||
4574  ElementType != T->getElementType() ||
4575  Size.get() != T->getSizeExpr()) {
4576  Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4577  Size.get(),
4578  T->getAttributeLoc());
4579  if (Result.isNull())
4580  return QualType();
4581  }
4582 
4583  // Result might be dependent or not.
4584  if (isa<DependentSizedExtVectorType>(Result)) {
4585  DependentSizedExtVectorTypeLoc NewTL
4586  = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4587  NewTL.setNameLoc(TL.getNameLoc());
4588  } else {
4589  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4590  NewTL.setNameLoc(TL.getNameLoc());
4591  }
4592 
4593  return Result;
4594 }
4595 
4596 template<typename Derived>
4597 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4598  VectorTypeLoc TL) {
4599  const VectorType *T = TL.getTypePtr();
4600  QualType ElementType = getDerived().TransformType(T->getElementType());
4601  if (ElementType.isNull())
4602  return QualType();
4603 
4604  QualType Result = TL.getType();
4605  if (getDerived().AlwaysRebuild() ||
4606  ElementType != T->getElementType()) {
4607  Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4608  T->getVectorKind());
4609  if (Result.isNull())
4610  return QualType();
4611  }
4612 
4613  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4614  NewTL.setNameLoc(TL.getNameLoc());
4615 
4616  return Result;
4617 }
4618 
4619 template<typename Derived>
4620 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4621  ExtVectorTypeLoc TL) {
4622  const VectorType *T = TL.getTypePtr();
4623  QualType ElementType = getDerived().TransformType(T->getElementType());
4624  if (ElementType.isNull())
4625  return QualType();
4626 
4627  QualType Result = TL.getType();
4628  if (getDerived().AlwaysRebuild() ||
4629  ElementType != T->getElementType()) {
4630  Result = getDerived().RebuildExtVectorType(ElementType,
4631  T->getNumElements(),
4632  /*FIXME*/ SourceLocation());
4633  if (Result.isNull())
4634  return QualType();
4635  }
4636 
4637  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4638  NewTL.setNameLoc(TL.getNameLoc());
4639 
4640  return Result;
4641 }
4642 
4643 template <typename Derived>
4645  ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4646  bool ExpectParameterPack) {
4647  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4648  TypeSourceInfo *NewDI = nullptr;
4649 
4650  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4651  // If we're substituting into a pack expansion type and we know the
4652  // length we want to expand to, just substitute for the pattern.
4653  TypeLoc OldTL = OldDI->getTypeLoc();
4654  PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4655 
4656  TypeLocBuilder TLB;
4657  TypeLoc NewTL = OldDI->getTypeLoc();
4658  TLB.reserve(NewTL.getFullDataSize());
4659 
4660  QualType Result = getDerived().TransformType(TLB,
4661  OldExpansionTL.getPatternLoc());
4662  if (Result.isNull())
4663  return nullptr;
4664 
4665  Result = RebuildPackExpansionType(Result,
4666  OldExpansionTL.getPatternLoc().getSourceRange(),
4667  OldExpansionTL.getEllipsisLoc(),
4668  NumExpansions);
4669  if (Result.isNull())
4670  return nullptr;
4671 
4672  PackExpansionTypeLoc NewExpansionTL
4673  = TLB.push<PackExpansionTypeLoc>(Result);
4674  NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4675  NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4676  } else
4677  NewDI = getDerived().TransformType(OldDI);
4678  if (!NewDI)
4679  return nullptr;
4680 
4681  if (NewDI == OldDI && indexAdjustment == 0)
4682  return OldParm;
4683 
4684  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4685  OldParm->getDeclContext(),
4686  OldParm->getInnerLocStart(),
4687  OldParm->getLocation(),
4688  OldParm->getIdentifier(),
4689  NewDI->getType(),
4690  NewDI,
4691  OldParm->getStorageClass(),
4692  /* DefArg */ nullptr);
4693  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4694  OldParm->getFunctionScopeIndex() + indexAdjustment);
4695  return newParm;
4696 }
4697 
4698 template <typename Derived>
4701  const QualType *ParamTypes,
4702  const FunctionProtoType::ExtParameterInfo *ParamInfos,
4703  SmallVectorImpl<QualType> &OutParamTypes,
4706  int indexAdjustment = 0;
4707 
4708  unsigned NumParams = Params.size();
4709  for (unsigned i = 0; i != NumParams; ++i) {
4710  if (ParmVarDecl *OldParm = Params[i]) {
4711  assert(OldParm->getFunctionScopeIndex() == i);
4712 
4713  Optional<unsigned> NumExpansions;
4714  ParmVarDecl *NewParm = nullptr;
4715  if (OldParm->isParameterPack()) {
4716  // We have a function parameter pack that may need to be expanded.
4718 
4719  // Find the parameter packs that could be expanded.
4720  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4721  PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4722  TypeLoc Pattern = ExpansionTL.getPatternLoc();
4723  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4724  assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4725 
4726  // Determine whether we should expand the parameter packs.
4727  bool ShouldExpand = false;
4728  bool RetainExpansion = false;
4729  Optional<unsigned> OrigNumExpansions =
4730  ExpansionTL.getTypePtr()->getNumExpansions();
4731  NumExpansions = OrigNumExpansions;
4732  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4733  Pattern.getSourceRange(),
4734  Unexpanded,
4735  ShouldExpand,
4736  RetainExpansion,
4737  NumExpansions)) {
4738  return true;
4739  }
4740 
4741  if (ShouldExpand) {
4742  // Expand the function parameter pack into multiple, separate
4743  // parameters.
4744  getDerived().ExpandingFunctionParameterPack(OldParm);
4745  for (unsigned I = 0; I != *NumExpansions; ++I) {
4746  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4747  ParmVarDecl *NewParm
4748  = getDerived().TransformFunctionTypeParam(OldParm,
4749  indexAdjustment++,
4750  OrigNumExpansions,
4751  /*ExpectParameterPack=*/false);
4752  if (!NewParm)
4753  return true;
4754 
4755  if (ParamInfos)
4756  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4757  OutParamTypes.push_back(NewParm->getType());
4758  if (PVars)
4759  PVars->push_back(NewParm);
4760  }
4761 
4762  // If we're supposed to retain a pack expansion, do so by temporarily
4763  // forgetting the partially-substituted parameter pack.
4764  if (RetainExpansion) {
4765  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4766  ParmVarDecl *NewParm
4767  = getDerived().TransformFunctionTypeParam(OldParm,
4768  indexAdjustment++,
4769  OrigNumExpansions,
4770  /*ExpectParameterPack=*/false);
4771  if (!NewParm)
4772  return true;
4773 
4774  if (ParamInfos)
4775  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4776  OutParamTypes.push_back(NewParm->getType());
4777  if (PVars)
4778  PVars->push_back(NewParm);
4779  }
4780 
4781  // The next parameter should have the same adjustment as the
4782  // last thing we pushed, but we post-incremented indexAdjustment
4783  // on every push. Also, if we push nothing, the adjustment should
4784  // go down by one.
4785  indexAdjustment--;
4786 
4787  // We're done with the pack expansion.
4788  continue;
4789  }
4790 
4791  // We'll substitute the parameter now without expanding the pack
4792  // expansion.
4793  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4794  NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4795  indexAdjustment,
4796  NumExpansions,
4797  /*ExpectParameterPack=*/true);
4798  } else {
4799  NewParm = getDerived().TransformFunctionTypeParam(
4800  OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4801  }
4802 
4803  if (!NewParm)
4804  return true;
4805 
4806  if (ParamInfos)
4807  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4808  OutParamTypes.push_back(NewParm->getType());
4809  if (PVars)
4810  PVars->push_back(NewParm);
4811  continue;
4812  }
4813 
4814  // Deal with the possibility that we don't have a parameter
4815  // declaration for this parameter.
4816  QualType OldType = ParamTypes[i];
4817  bool IsPackExpansion = false;
4818  Optional<unsigned> NumExpansions;
4819  QualType NewType;
4820  if (const PackExpansionType *Expansion
4821  = dyn_cast<PackExpansionType>(OldType)) {
4822  // We have a function parameter pack that may need to be expanded.
4823  QualType Pattern = Expansion->getPattern();
4825  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4826 
4827  // Determine whether we should expand the parameter packs.
4828  bool ShouldExpand = false;
4829  bool RetainExpansion = false;
4830  if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4831  Unexpanded,
4832  ShouldExpand,
4833  RetainExpansion,
4834  NumExpansions)) {
4835  return true;
4836  }
4837 
4838  if (ShouldExpand) {
4839  // Expand the function parameter pack into multiple, separate
4840  // parameters.
4841  for (unsigned I = 0; I != *NumExpansions; ++I) {
4842  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4843  QualType NewType = getDerived().TransformType(Pattern);
4844  if (NewType.isNull())
4845  return true;
4846 
4847  if (NewType->containsUnexpandedParameterPack()) {
4848  NewType =
4849  getSema().getASTContext().getPackExpansionType(NewType, None);
4850 
4851  if (NewType.isNull())
4852  return true;
4853  }
4854 
4855  if (ParamInfos)
4856  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4857  OutParamTypes.push_back(NewType);
4858  if (PVars)
4859  PVars->push_back(nullptr);
4860  }
4861 
4862  // We're done with the pack expansion.
4863  continue;
4864  }
4865 
4866  // If we're supposed to retain a pack expansion, do so by temporarily
4867  // forgetting the partially-substituted parameter pack.
4868  if (RetainExpansion) {
4869  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4870  QualType NewType = getDerived().TransformType(Pattern);
4871  if (NewType.isNull())
4872  return true;
4873 
4874  if (ParamInfos)
4875  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4876  OutParamTypes.push_back(NewType);
4877  if (PVars)
4878  PVars->push_back(nullptr);
4879  }
4880 
4881  // We'll substitute the parameter now without expanding the pack
4882  // expansion.
4883  OldType = Expansion->getPattern();
4884  IsPackExpansion = true;
4885  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4886  NewType = getDerived().TransformType(OldType);
4887  } else {
4888  NewType = getDerived().TransformType(OldType);
4889  }
4890 
4891  if (NewType.isNull())
4892  return true;
4893 
4894  if (IsPackExpansion)
4895  NewType = getSema().Context.getPackExpansionType(NewType,
4896  NumExpansions);
4897 
4898  if (ParamInfos)
4899  PInfos.set(OutParamTypes.size(), ParamInfos[i]);
4900  OutParamTypes.push_back(NewType);
4901  if (PVars)
4902  PVars->push_back(nullptr);
4903  }
4904 
4905 #ifndef NDEBUG
4906  if (PVars) {
4907  for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4908  if (ParmVarDecl *parm = (*PVars)[i])
4909  assert(parm->getFunctionScopeIndex() == i);
4910  }
4911 #endif
4912 
4913  return false;
4914 }
4915 
4916 template<typename Derived>
4917 QualType
4919  FunctionProtoTypeLoc TL) {
4920  SmallVector<QualType, 4> ExceptionStorage;
4921  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
4922  return getDerived().TransformFunctionProtoType(
4923  TLB, TL, nullptr, 0,
4924  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4925  return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4926  ExceptionStorage, Changed);
4927  });
4928 }
4929 
4930 template<typename Derived> template<typename Fn>
4932  TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4933  unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
4934 
4935  // Transform the parameters and return type.
4936  //
4937  // We are required to instantiate the params and return type in source order.
4938  // When the function has a trailing return type, we instantiate the
4939  // parameters before the return type, since the return type can then refer
4940  // to the parameters themselves (via decltype, sizeof, etc.).
4941  //
4942  SmallVector<QualType, 4> ParamTypes;
4943  SmallVector<ParmVarDecl*, 4> ParamDecls;
4944  Sema::ExtParameterInfoBuilder ExtParamInfos;
4945  const FunctionProtoType *T = TL.getTypePtr();
4946 
4947  QualType ResultType;
4948 
4949  if (T->hasTrailingReturn()) {
4950  if (getDerived().TransformFunctionTypeParams(
4951  TL.getBeginLoc(), TL.getParams(),
4952  TL.getTypePtr()->param_type_begin(),
4954  ParamTypes, &ParamDecls, ExtParamInfos))
4955  return QualType();
4956 
4957  {
4958  // C++11 [expr.prim.general]p3:
4959  // If a declaration declares a member function or member function
4960  // template of a class X, the expression this is a prvalue of type
4961  // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4962  // and the end of the function-definition, member-declarator, or
4963  // declarator.
4964  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4965 
4966  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4967  if (ResultType.isNull())
4968  return QualType();
4969  }
4970  }
4971  else {
4972  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4973  if (ResultType.isNull())
4974  return QualType();
4975 
4976  if (getDerived().TransformFunctionTypeParams(
4977  TL.getBeginLoc(), TL.getParams(),
4978  TL.getTypePtr()->param_type_begin(),
4980  ParamTypes, &ParamDecls, ExtParamInfos))
4981  return QualType();
4982  }
4983 
4985 
4986  bool EPIChanged = false;
4987  if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4988  return QualType();
4989 
4990  // Handle extended parameter information.
4991  if (auto NewExtParamInfos =
4992  ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4993  if (!EPI.ExtParameterInfos ||
4994  llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
4995  != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
4996  EPIChanged = true;
4997  }
4998  EPI.ExtParameterInfos = NewExtParamInfos;
4999  } else if (EPI.ExtParameterInfos) {
5000  EPIChanged = true;
5001  EPI.ExtParameterInfos = nullptr;
5002  }
5003 
5004  QualType Result = TL.getType();
5005  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
5006  T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
5007  Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
5008  if (Result.isNull())
5009  return QualType();
5010  }
5011 
5012  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
5014  NewTL.setLParenLoc(TL.getLParenLoc());
5015  NewTL.setRParenLoc(TL.getRParenLoc());
5016  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5017  for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5018  NewTL.setParam(i, ParamDecls[i]);
5019 
5020  return Result;
5021 }
5022 
5023 template<typename Derived>
5026  SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5027  assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5028 
5029  // Instantiate a dynamic noexcept expression, if any.
5030  if (ESI.Type == EST_ComputedNoexcept) {
5031  EnterExpressionEvaluationContext Unevaluated(getSema(),
5033  ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5034  if (NoexceptExpr.isInvalid())
5035  return true;
5036 
5037  // FIXME: This is bogus, a noexcept expression is not a condition.
5038  NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
5039  if (NoexceptExpr.isInvalid())
5040  return true;
5041 
5042  if (!NoexceptExpr.get()->isValueDependent()) {
5043  NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5044  NoexceptExpr.get(), nullptr,
5045  diag::err_noexcept_needs_constant_expression,
5046  /*AllowFold*/false);
5047  if (NoexceptExpr.isInvalid())
5048  return true;
5049  }
5050 
5051  if (ESI.NoexceptExpr != NoexceptExpr.get())
5052  Changed = true;
5053  ESI.NoexceptExpr = NoexceptExpr.get();
5054  }
5055 
5056  if (ESI.Type != EST_Dynamic)
5057  return false;
5058 
5059  // Instantiate a dynamic exception specification's type.
5060  for (QualType T : ESI.Exceptions) {
5061  if (const PackExpansionType *PackExpansion =
5062  T->getAs<PackExpansionType>()) {
5063  Changed = true;
5064 
5065  // We have a pack expansion. Instantiate it.
5067  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5068  Unexpanded);
5069  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5070 
5071  // Determine whether the set of unexpanded parameter packs can and
5072  // should
5073  // be expanded.
5074  bool Expand = false;
5075  bool RetainExpansion = false;
5076  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5077  // FIXME: Track the location of the ellipsis (and track source location
5078  // information for the types in the exception specification in general).
5079  if (getDerived().TryExpandParameterPacks(
5080  Loc, SourceRange(), Unexpanded, Expand,
5081  RetainExpansion, NumExpansions))
5082  return true;
5083 
5084  if (!Expand) {
5085  // We can't expand this pack expansion into separate arguments yet;
5086  // just substitute into the pattern and create a new pack expansion
5087  // type.
5088  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5089  QualType U = getDerived().TransformType(PackExpansion->getPattern());
5090  if (U.isNull())
5091  return true;
5092 
5093  U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5094  Exceptions.push_back(U);
5095  continue;
5096  }
5097 
5098  // Substitute into the pack expansion pattern for each slice of the
5099  // pack.
5100  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5101  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5102 
5103  QualType U = getDerived().TransformType(PackExpansion->getPattern());
5104  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5105  return true;
5106 
5107  Exceptions.push_back(U);
5108  }
5109  } else {
5110  QualType U = getDerived().TransformType(T);
5111  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5112  return true;
5113  if (T != U)
5114  Changed = true;
5115 
5116  Exceptions.push_back(U);
5117  }
5118  }
5119 
5120  ESI.Exceptions = Exceptions;
5121  return false;
5122 }
5123 
5124 template<typename Derived>
5126  TypeLocBuilder &TLB,
5128  const FunctionNoProtoType *T = TL.getTypePtr();
5129  QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
5130  if (ResultType.isNull())
5131  return QualType();
5132 
5133  QualType Result = TL.getType();
5134  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
5135  Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5136 
5137  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
5139  NewTL.setLParenLoc(TL.getLParenLoc());
5140  NewTL.setRParenLoc(TL.getRParenLoc());
5141  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
5142 
5143  return Result;
5144 }
5145 
5146 template<typename Derived> QualType
5147 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5148  UnresolvedUsingTypeLoc TL) {
5149  const UnresolvedUsingType *T = TL.getTypePtr();
5150  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5151  if (!D)
5152  return QualType();
5153 
5154  QualType Result = TL.getType();
5155  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5156  Result = getDerived().RebuildUnresolvedUsingType(D);
5157  if (Result.isNull())
5158  return QualType();
5159  }
5160 
5161  // We might get an arbitrary type spec type back. We should at
5162  // least always get a type spec type, though.
5163  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5164  NewTL.setNameLoc(TL.getNameLoc());
5165 
5166  return Result;
5167 }
5168 
5169 template<typename Derived>
5170 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5171  TypedefTypeLoc TL) {
5172  const TypedefType *T = TL.getTypePtr();
5173  TypedefNameDecl *Typedef
5174  = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5175  T->getDecl()));
5176  if (!Typedef)
5177  return QualType();
5178 
5179  QualType Result = TL.getType();
5180  if (getDerived().AlwaysRebuild() ||
5181  Typedef != T->getDecl()) {
5182  Result = getDerived().RebuildTypedefType(Typedef);
5183  if (Result.isNull())
5184  return QualType();
5185  }
5186 
5187  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5188  NewTL.setNameLoc(TL.getNameLoc());
5189 
5190  return Result;
5191 }
5192 
5193 template<typename Derived>
5194 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5195  TypeOfExprTypeLoc TL) {
5196  // typeof expressions are not potentially evaluated contexts
5197  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5199 
5200  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5201  if (E.isInvalid())
5202  return QualType();
5203 
5204  E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5205  if (E.isInvalid())
5206  return QualType();
5207 
5208  QualType Result = TL.getType();
5209  if (getDerived().AlwaysRebuild() ||
5210  E.get() != TL.getUnderlyingExpr()) {
5211  Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5212  if (Result.isNull())
5213  return QualType();
5214  }
5215  else E.get();
5216 
5217  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5218  NewTL.setTypeofLoc(TL.getTypeofLoc());
5219  NewTL.setLParenLoc(TL.getLParenLoc());
5220  NewTL.setRParenLoc(TL.getRParenLoc());
5221 
5222  return Result;
5223 }
5224 
5225 template<typename Derived>
5226 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5227  TypeOfTypeLoc TL) {
5228  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5229  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5230  if (!New_Under_TI)
5231  return QualType();
5232 
5233  QualType Result = TL.getType();
5234  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5235  Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5236  if (Result.isNull())
5237  return QualType();
5238  }
5239 
5240  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5241  NewTL.setTypeofLoc(TL.getTypeofLoc());
5242  NewTL.setLParenLoc(TL.getLParenLoc());
5243  NewTL.setRParenLoc(TL.getRParenLoc());
5244  NewTL.setUnderlyingTInfo(New_Under_TI);
5245 
5246  return Result;
5247 }
5248 
5249 template<typename Derived>
5250 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5251  DecltypeTypeLoc TL) {
5252  const DecltypeType *T = TL.getTypePtr();
5253 
5254  // decltype expressions are not potentially evaluated contexts
5255  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5256  nullptr, /*IsDecltype=*/ true);
5257 
5258  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5259  if (E.isInvalid())
5260  return QualType();
5261 
5262  E = getSema().ActOnDecltypeExpression(E.get());
5263  if (E.isInvalid())
5264  return QualType();
5265 
5266  QualType Result = TL.getType();
5267  if (getDerived().AlwaysRebuild() ||
5268  E.get() != T->getUnderlyingExpr()) {
5269  Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5270  if (Result.isNull())
5271  return QualType();
5272  }
5273  else E.get();
5274 
5275  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5276  NewTL.setNameLoc(TL.getNameLoc());
5277 
5278  return Result;
5279 }
5280 
5281 template<typename Derived>
5282 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5283  TypeLocBuilder &TLB,
5284  UnaryTransformTypeLoc TL) {
5285  QualType Result = TL.getType();
5286  if (Result->isDependentType()) {
5287  const UnaryTransformType *T = TL.getTypePtr();
5288  QualType NewBase =
5289  getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5290  Result = getDerived().RebuildUnaryTransformType(NewBase,
5291  T->getUTTKind(),
5292  TL.getKWLoc());
5293  if (Result.isNull())
5294  return QualType();
5295  }
5296 
5297  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5298  NewTL.setKWLoc(TL.getKWLoc());
5299  NewTL.setParensRange(TL.getParensRange());
5300  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5301  return Result;
5302 }
5303 
5304 template<typename Derived>
5305 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5306  AutoTypeLoc TL) {
5307  const AutoType *T = TL.getTypePtr();
5308  QualType OldDeduced = T->getDeducedType();
5309  QualType NewDeduced;
5310  if (!OldDeduced.isNull()) {
5311  NewDeduced = getDerived().TransformType(OldDeduced);
5312  if (NewDeduced.isNull())
5313  return QualType();
5314  }
5315 
5316  QualType Result = TL.getType();
5317  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5318  T->isDependentType()) {
5319  Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5320  if (Result.isNull())
5321  return QualType();
5322  }
5323 
5324  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5325  NewTL.setNameLoc(TL.getNameLoc());
5326 
5327  return Result;
5328 }
5329 
5330 template<typename Derived>
5331 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5332  RecordTypeLoc TL) {
5333  const RecordType *T = TL.getTypePtr();
5334  RecordDecl *Record
5335  = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5336  T->getDecl()));
5337  if (!Record)
5338  return QualType();
5339 
5340  QualType Result = TL.getType();
5341  if (getDerived().AlwaysRebuild() ||
5342  Record != T->getDecl()) {
5343  Result = getDerived().RebuildRecordType(Record);
5344  if (Result.isNull())
5345  return QualType();
5346  }
5347 
5348  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5349  NewTL.setNameLoc(TL.getNameLoc());
5350 
5351  return Result;
5352 }
5353 
5354 template<typename Derived>
5355 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5356  EnumTypeLoc TL) {
5357  const EnumType *T = TL.getTypePtr();
5358  EnumDecl *Enum
5359  = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5360  T->getDecl()));
5361  if (!Enum)
5362  return QualType();
5363 
5364  QualType Result = TL.getType();
5365  if (getDerived().AlwaysRebuild() ||
5366  Enum != T->getDecl()) {
5367  Result = getDerived().RebuildEnumType(Enum);
5368  if (Result.isNull())
5369  return QualType();
5370  }
5371 
5372  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5373  NewTL.setNameLoc(TL.getNameLoc());
5374 
5375  return Result;
5376 }
5377 
5378 template<typename Derived>
5379 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5380  TypeLocBuilder &TLB,
5381  InjectedClassNameTypeLoc TL) {
5382  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5383  TL.getTypePtr()->getDecl());
5384  if (!D) return QualType();
5385 
5386  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5387  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5388  return T;
5389 }
5390 
5391 template<typename Derived>
5392 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5393  TypeLocBuilder &TLB,
5394  TemplateTypeParmTypeLoc TL) {
5395  return TransformTypeSpecType(TLB, TL);
5396 }
5397 
5398 template<typename Derived>
5399 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5400  TypeLocBuilder &TLB,
5401  SubstTemplateTypeParmTypeLoc TL) {
5402  const SubstTemplateTypeParmType *T = TL.getTypePtr();
5403 
5404  // Substitute into the replacement type, which itself might involve something
5405  // that needs to be transformed. This only tends to occur with default
5406  // template arguments of template template parameters.
5407  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5408  QualType Replacement = getDerived().TransformType(T->getReplacementType());
5409  if (Replacement.isNull())
5410  return QualType();
5411 
5412  // Always canonicalize the replacement type.
5413  Replacement = SemaRef.Context.getCanonicalType(Replacement);
5414  QualType Result
5415  = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5416  Replacement);
5417 
5418  // Propagate type-source information.
5419  SubstTemplateTypeParmTypeLoc NewTL
5420  = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5421  NewTL.setNameLoc(TL.getNameLoc());
5422  return Result;
5423 
5424 }
5425 
5426 template<typename Derived>
5427 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5428  TypeLocBuilder &TLB,
5429  SubstTemplateTypeParmPackTypeLoc TL) {
5430  return TransformTypeSpecType(TLB, TL);
5431 }
5432 
5433 template<typename Derived>
5435  TypeLocBuilder &TLB,
5437  const TemplateSpecializationType *T = TL.getTypePtr();
5438 
5439  // The nested-name-specifier never matters in a TemplateSpecializationType,
5440  // because we can't have a dependent nested-name-specifier anyway.
5441  CXXScopeSpec SS;
5442  TemplateName Template
5443  = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5444  TL.getTemplateNameLoc());
5445  if (Template.isNull())
5446  return QualType();
5447 
5448  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5449 }
5450 
5451 template<typename Derived>
5453  AtomicTypeLoc TL) {
5454  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5455  if (ValueType.isNull())
5456  return QualType();
5457 
5458  QualType Result = TL.getType();
5459  if (getDerived().AlwaysRebuild() ||
5460  ValueType != TL.getValueLoc().getType()) {
5461  Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5462  if (Result.isNull())
5463  return QualType();
5464  }
5465 
5466  AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5467  NewTL.setKWLoc(TL.getKWLoc());
5468  NewTL.setLParenLoc(TL.getLParenLoc());
5469  NewTL.setRParenLoc(TL.getRParenLoc());
5470 
5471  return Result;
5472 }
5473 
5474 template <typename Derived>
5475 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5476  PipeTypeLoc TL) {
5477  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5478  if (ValueType.isNull())
5479  return QualType();
5480 
5481  QualType Result = TL.getType();
5482  if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5483  Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5484  if (Result.isNull())
5485  return QualType();
5486  }
5487 
5488  PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5489  NewTL.setKWLoc(TL.getKWLoc());
5490 
5491  return Result;
5492 }
5493 
5494  /// \brief Simple iterator that traverses the template arguments in a
5495  /// container that provides a \c getArgLoc() member function.
5496  ///
5497  /// This iterator is intended to be used with the iterator form of
5498  /// \c TreeTransform<Derived>::TransformTemplateArguments().
5499  template<typename ArgLocContainer>
5501  ArgLocContainer *Container;
5502  unsigned Index;
5503 
5504  public:
5507  typedef int difference_type;
5508  typedef std::input_iterator_tag iterator_category;
5509 
5510  class pointer {
5511  TemplateArgumentLoc Arg;
5512 
5513  public:
5514  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5515 
5517  return &Arg;
5518  }
5519  };
5520 
5521 
5523 
5524  TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5525  unsigned Index)
5526  : Container(&Container), Index(Index) { }
5527 
5529  ++Index;
5530  return *this;
5531  }
5532 
5535  ++(*this);
5536  return Old;
5537  }
5538 
5540  return Container->getArgLoc(Index);
5541  }
5542 
5544  return pointer(Container->getArgLoc(Index));
5545  }
5546 
5549  return X.Container == Y.Container && X.Index == Y.Index;
5550  }
5551 
5554  return !(X == Y);
5555  }
5556  };
5557 
5558 
5559 template <typename Derived>
5561  TypeLocBuilder &TLB,
5562  TemplateSpecializationTypeLoc TL,
5563  TemplateName Template) {
5564  TemplateArgumentListInfo NewTemplateArgs;
5565  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5566  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5567  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5568  ArgIterator;
5569  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5570  ArgIterator(TL, TL.getNumArgs()),
5571  NewTemplateArgs))
5572  return QualType();
5573 
5574  // FIXME: maybe don't rebuild if all the template arguments are the same.
5575 
5576  QualType Result =
5577  getDerived().RebuildTemplateSpecializationType(Template,
5578  TL.getTemplateNameLoc(),
5579  NewTemplateArgs);
5580 
5581  if (!Result.isNull()) {
5582  // Specializations of template template parameters are represented as
5583  // TemplateSpecializationTypes, and substitution of type alias templates
5584  // within a dependent context can transform them into
5585  // DependentTemplateSpecializationTypes.
5586  if (isa<DependentTemplateSpecializationType>(Result)) {
5587  DependentTemplateSpecializationTypeLoc NewTL
5588  = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5589  NewTL.setElaboratedKeywordLoc(SourceLocation());
5590  NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5591  NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5592  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5593  NewTL.setLAngleLoc(TL.getLAngleLoc());
5594  NewTL.setRAngleLoc(TL.getRAngleLoc());
5595  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5596  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5597  return Result;
5598  }
5599 
5600  TemplateSpecializationTypeLoc NewTL
5601  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5602  NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5603  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5604  NewTL.setLAngleLoc(TL.getLAngleLoc());
5605  NewTL.setRAngleLoc(TL.getRAngleLoc());
5606  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5607  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5608  }
5609 
5610  return Result;
5611 }
5612 
5613 template <typename Derived>
5615  TypeLocBuilder &TLB,
5617  TemplateName Template,
5618  CXXScopeSpec &SS) {
5619  TemplateArgumentListInfo NewTemplateArgs;
5620  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5621  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5624  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5625  ArgIterator(TL, TL.getNumArgs()),
5626  NewTemplateArgs))
5627  return QualType();
5628 
5629  // FIXME: maybe don't rebuild if all the template arguments are the same.
5630 
5631  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5632  QualType Result
5633  = getSema().Context.getDependentTemplateSpecializationType(
5634  TL.getTypePtr()->getKeyword(),
5635  DTN->getQualifier(),
5636  DTN->getIdentifier(),
5637  NewTemplateArgs);
5638 
5642  NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5645  NewTL.setLAngleLoc(TL.getLAngleLoc());
5646  NewTL.setRAngleLoc(TL.getRAngleLoc());
5647  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5648  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5649  return Result;
5650  }
5651 
5652  QualType Result
5653  = getDerived().RebuildTemplateSpecializationType(Template,
5654  TL.getTemplateNameLoc(),
5655  NewTemplateArgs);
5656 
5657  if (!Result.isNull()) {
5658  /// FIXME: Wrap this in an elaborated-type-specifier?
5660  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5663  NewTL.setLAngleLoc(TL.getLAngleLoc());
5664  NewTL.setRAngleLoc(TL.getRAngleLoc());
5665  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5666  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5667  }
5668 
5669  return Result;
5670 }
5671 
5672 template<typename Derived>
5673 QualType
5675  ElaboratedTypeLoc TL) {
5676  const ElaboratedType *T = TL.getTypePtr();
5677 
5678  NestedNameSpecifierLoc QualifierLoc;
5679  // NOTE: the qualifier in an ElaboratedType is optional.
5680  if (TL.getQualifierLoc()) {
5681  QualifierLoc
5682  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5683  if (!QualifierLoc)
5684  return QualType();
5685  }
5686 
5687  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5688  if (NamedT.isNull())
5689  return QualType();
5690 
5691  // C++0x [dcl.type.elab]p2:
5692  // If the identifier resolves to a typedef-name or the simple-template-id
5693  // resolves to an alias template specialization, the
5694  // elaborated-type-specifier is ill-formed.
5695  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5696  if (const TemplateSpecializationType *TST =
5697  NamedT->getAs<TemplateSpecializationType>()) {
5698  TemplateName Template = TST->getTemplateName();
5699  if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5700  Template.getAsTemplateDecl())) {
5701  SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5702  diag::err_tag_reference_non_tag) << 4;
5703  SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5704  }
5705  }
5706  }
5707 
5708  QualType Result = TL.getType();
5709  if (getDerived().AlwaysRebuild() ||
5710  QualifierLoc != TL.getQualifierLoc() ||
5711  NamedT != T->getNamedType()) {
5712  Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5713  T->getKeyword(),
5714  QualifierLoc, NamedT);
5715  if (Result.isNull())
5716  return QualType();
5717  }
5718 
5719  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5720  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5721  NewTL.setQualifierLoc(QualifierLoc);
5722  return Result;
5723 }
5724 
5725 template<typename Derived>
5726 QualType TreeTransform<Derived>::TransformAttributedType(
5727  TypeLocBuilder &TLB,
5728  AttributedTypeLoc TL) {
5729  const AttributedType *oldType = TL.getTypePtr();
5730  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5731  if (modifiedType.isNull())
5732  return QualType();
5733 
5734  QualType result = TL.getType();
5735 
5736  // FIXME: dependent operand expressions?
5737  if (getDerived().AlwaysRebuild() ||
5738  modifiedType != oldType->getModifiedType()) {
5739  // TODO: this is really lame; we should really be rebuilding the
5740  // equivalent type from first principles.
5741  QualType equivalentType
5742  = getDerived().TransformType(oldType->getEquivalentType());
5743  if (equivalentType.isNull())
5744  return QualType();
5745 
5746  // Check whether we can add nullability; it is only represented as
5747  // type sugar, and therefore cannot be diagnosed in any other way.
5748  if (auto nullability = oldType->getImmediateNullability()) {
5749  if (!modifiedType->canHaveNullability()) {
5750  SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5751  << DiagNullabilityKind(*nullability, false) << modifiedType;
5752  return QualType();
5753  }
5754  }
5755 
5756  result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5757  modifiedType,
5758  equivalentType);
5759  }
5760 
5761  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5762  newTL.setAttrNameLoc(TL.getAttrNameLoc());
5763  if (TL.hasAttrOperand())
5764  newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5765  if (TL.hasAttrExprOperand())
5766  newTL.setAttrExprOperand(TL.getAttrExprOperand());
5767  else if (TL.hasAttrEnumOperand())
5768  newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5769 
5770  return result;
5771 }
5772 
5773 template<typename Derived>
5774 QualType
5775 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5776  ParenTypeLoc TL) {
5777  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5778  if (Inner.isNull())
5779  return QualType();
5780 
5781  QualType Result = TL.getType();
5782  if (getDerived().AlwaysRebuild() ||
5783  Inner != TL.getInnerLoc().getType()) {
5784  Result = getDerived().RebuildParenType(Inner);
5785  if (Result.isNull())
5786  return QualType();
5787  }
5788 
5789  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5790  NewTL.setLParenLoc(TL.getLParenLoc());
5791  NewTL.setRParenLoc(TL.getRParenLoc());
5792  return Result;
5793 }
5794 
5795 template<typename Derived>
5796 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5797  DependentNameTypeLoc TL) {
5798  const DependentNameType *T = TL.getTypePtr();
5799 
5800  NestedNameSpecifierLoc QualifierLoc
5801  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5802  if (!QualifierLoc)
5803  return QualType();
5804 
5805  QualType Result
5806  = getDerived().RebuildDependentNameType(T->getKeyword(),
5807  TL.getElaboratedKeywordLoc(),
5808  QualifierLoc,
5809  T->getIdentifier(),
5810  TL.getNameLoc());
5811  if (Result.isNull())
5812  return QualType();
5813 
5814  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5815  QualType NamedT = ElabT->getNamedType();
5816  TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5817 
5818  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5819  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5820  NewTL.setQualifierLoc(QualifierLoc);
5821  } else {
5822  DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5823  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5824  NewTL.setQualifierLoc(QualifierLoc);
5825  NewTL.setNameLoc(TL.getNameLoc());
5826  }
5827  return Result;
5828 }
5829 
5830 template<typename Derived>
5831 QualType TreeTransform<Derived>::
5833  DependentTemplateSpecializationTypeLoc TL) {
5834  NestedNameSpecifierLoc QualifierLoc;
5835  if (TL.getQualifierLoc()) {
5836  QualifierLoc
5837  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5838  if (!QualifierLoc)
5839  return QualType();
5840  }
5841 
5842  return getDerived()
5843  .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5844 }
5845 
5846 template<typename Derived>
5847 QualType TreeTransform<Derived>::
5850  NestedNameSpecifierLoc QualifierLoc) {
5852 
5853  TemplateArgumentListInfo NewTemplateArgs;
5854  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5855  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5856 
5859  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5860  ArgIterator(TL, TL.getNumArgs()),
5861  NewTemplateArgs))
5862  return QualType();
5863 
5864  QualType Result
5865  = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5866  QualifierLoc,
5867  T->getIdentifier(),
5868  TL.getTemplateNameLoc(),
5869  NewTemplateArgs);
5870  if (Result.isNull())
5871  return QualType();
5872 
5873  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5874  QualType NamedT = ElabT->getNamedType();
5875 
5876  // Copy information relevant to the template specialization.
5878  = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5880  NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5881  NamedTL.setLAngleLoc(TL.getLAngleLoc());
5882  NamedTL.setRAngleLoc(TL.getRAngleLoc());
5883  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5884  NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5885 
5886  // Copy information relevant to the elaborated type.
5887  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5889  NewTL.setQualifierLoc(QualifierLoc);
5890  } else if (isa<DependentTemplateSpecializationType>(Result)) {
5894  SpecTL.setQualifierLoc(QualifierLoc);
5897  SpecTL.setLAngleLoc(TL.getLAngleLoc());
5898  SpecTL.setRAngleLoc(TL.getRAngleLoc());
5899  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5900  SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5901  } else {
5903  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5906  SpecTL.setLAngleLoc(TL.getLAngleLoc());
5907  SpecTL.setRAngleLoc(TL.getRAngleLoc());
5908  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5909  SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5910  }
5911  return Result;
5912 }
5913 
5914 template<typename Derived>
5916  PackExpansionTypeLoc TL) {
5917  QualType Pattern
5918  = getDerived().TransformType(TLB, TL.getPatternLoc());
5919  if (Pattern.isNull())
5920  return QualType();
5921 
5922  QualType Result = TL.getType();
5923  if (getDerived().AlwaysRebuild() ||
5924  Pattern != TL.getPatternLoc().getType()) {
5925  Result = getDerived().RebuildPackExpansionType(Pattern,
5927  TL.getEllipsisLoc(),
5928  TL.getTypePtr()->getNumExpansions());
5929  if (Result.isNull())
5930  return QualType();
5931  }
5932 
5933  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5934  NewT.setEllipsisLoc(TL.getEllipsisLoc());
5935  return Result;
5936 }
5937 
5938 template<typename Derived>
5939 QualType
5940 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5941  ObjCInterfaceTypeLoc TL) {
5942  // ObjCInterfaceType is never dependent.
5943  TLB.pushFullCopy(TL);
5944  return TL.getType();
5945 }
5946 
5947 template<typename Derived>
5948 QualType
5949 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5950  ObjCObjectTypeLoc TL) {
5951  // Transform base type.
5952  QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5953  if (BaseType.isNull())
5954  return QualType();
5955 
5956  bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5957 
5958  // Transform type arguments.
5959  SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5960  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5961  TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5962  TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5963  QualType TypeArg = TypeArgInfo->getType();
5964  if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5965  AnyChanged = true;
5966 
5967  // We have a pack expansion. Instantiate it.
5968  const auto *PackExpansion = PackExpansionLoc.getType()
5969  ->castAs<PackExpansionType>();
5970  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5971  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5972  Unexpanded);
5973  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5974 
5975  // Determine whether the set of unexpanded parameter packs can
5976  // and should be expanded.
5977  TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5978  bool Expand = false;
5979  bool RetainExpansion = false;
5980  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5981  if (getDerived().TryExpandParameterPacks(
5982  PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5983  Unexpanded, Expand, RetainExpansion, NumExpansions))
5984  return QualType();
5985 
5986  if (!Expand) {
5987  // We can't expand this pack expansion into separate arguments yet;
5988  // just substitute into the pattern and create a new pack expansion
5989  // type.
5990  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5991 
5992  TypeLocBuilder TypeArgBuilder;
5993  TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5994  QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5995  PatternLoc);
5996  if (NewPatternType.isNull())
5997  return QualType();
5998 
5999  QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6000  NewPatternType, NumExpansions);
6001  auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6002  NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6003  NewTypeArgInfos.push_back(
6004  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6005  continue;
6006  }
6007 
6008  // Substitute into the pack expansion pattern for each slice of the
6009  // pack.
6010  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6011  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6012 
6013  TypeLocBuilder TypeArgBuilder;
6014  TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6015 
6016  QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6017  PatternLoc);
6018  if (NewTypeArg.isNull())
6019  return QualType();
6020 
6021  NewTypeArgInfos.push_back(
6022  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6023  }
6024 
6025  continue;
6026  }
6027 
6028  TypeLocBuilder TypeArgBuilder;
6029  TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6030  QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6031  if (NewTypeArg.isNull())
6032  return QualType();
6033 
6034  // If nothing changed, just keep the old TypeSourceInfo.
6035  if (NewTypeArg == TypeArg) {
6036  NewTypeArgInfos.push_back(TypeArgInfo);
6037  continue;
6038  }
6039 
6040  NewTypeArgInfos.push_back(
6041  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6042  AnyChanged = true;
6043  }
6044 
6045  QualType Result = TL.getType();
6046  if (getDerived().AlwaysRebuild() || AnyChanged) {
6047  // Rebuild the type.
6048  Result = getDerived().RebuildObjCObjectType(
6049  BaseType,
6050  TL.getLocStart(),
6051  TL.getTypeArgsLAngleLoc(),
6052  NewTypeArgInfos,
6053  TL.getTypeArgsRAngleLoc(),
6054  TL.getProtocolLAngleLoc(),
6055  llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6056  TL.getNumProtocols()),
6057  TL.getProtocolLocs(),
6058  TL.getProtocolRAngleLoc());
6059 
6060  if (Result.isNull())
6061  return QualType();
6062  }
6063 
6064  ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
6065  NewT.setHasBaseTypeAsWritten(true);
6066  NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6067  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6068  NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6069  NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6070  NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6071  for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6072  NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6073  NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6074  return Result;
6075 }
6076 
6077 template<typename Derived>
6078 QualType
6079 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
6080  ObjCObjectPointerTypeLoc TL) {
6081  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6082  if (PointeeType.isNull())
6083  return QualType();
6084 
6085  QualType Result = TL.getType();
6086  if (getDerived().AlwaysRebuild() ||
6087  PointeeType != TL.getPointeeLoc().getType()) {
6088  Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6089  TL.getStarLoc());
6090  if (Result.isNull())
6091  return QualType();
6092  }
6093 
6094  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6095  NewT.setStarLoc(TL.getStarLoc());
6096  return Result;
6097 }
6098 
6099 //===----------------------------------------------------------------------===//
6100 // Statement transformation
6101 //===----------------------------------------------------------------------===//
6102 template<typename Derived>
6103 StmtResult
6104 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
6105  return S;
6106 }
6107 
6108 template<typename Derived>
6109 StmtResult
6111  return getDerived().TransformCompoundStmt(S, false);
6112 }
6113 
6114 template<typename Derived>
6115 StmtResult
6117  bool IsStmtExpr) {
6118  Sema::CompoundScopeRAII CompoundScope(getSema());
6119 
6120  bool SubStmtInvalid = false;
6121  bool SubStmtChanged = false;
6122  SmallVector<Stmt*, 8> Statements;
6123  for (auto *B : S->body()) {
6124  StmtResult Result = getDerived().TransformStmt(B);
6125  if (Result.isInvalid()) {
6126  // Immediately fail if this was a DeclStmt, since it's very
6127  // likely that this will cause problems for future statements.
6128  if (isa<DeclStmt>(B))
6129  return StmtError();
6130 
6131  // Otherwise, just keep processing substatements and fail later.
6132  SubStmtInvalid = true;
6133  continue;
6134  }
6135 
6136  SubStmtChanged = SubStmtChanged || Result.get() != B;
6137  Statements.push_back(Result.getAs<Stmt>());
6138  }
6139 
6140  if (SubStmtInvalid)
6141  return StmtError();
6142 
6143  if (!getDerived().AlwaysRebuild() &&
6144  !SubStmtChanged)
6145  return S;
6146 
6147  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6148  Statements,
6149  S->getRBracLoc(),
6150  IsStmtExpr);
6151 }
6152 
6153 template<typename Derived>
6154 StmtResult
6155 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6156  ExprResult LHS, RHS;
6157  {
6158  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6160 
6161  // Transform the left-hand case value.
6162  LHS = getDerived().TransformExpr(S->getLHS());
6163  LHS = SemaRef.ActOnConstantExpression(LHS);
6164  if (LHS.isInvalid())
6165  return StmtError();
6166 
6167  // Transform the right-hand case value (for the GNU case-range extension).
6168  RHS = getDerived().TransformExpr(S->getRHS());
6169  RHS = SemaRef.ActOnConstantExpression(RHS);
6170  if (RHS.isInvalid())
6171  return StmtError();
6172  }
6173 
6174  // Build the case statement.
6175  // Case statements are always rebuilt so that they will attached to their
6176  // transformed switch statement.
6177  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6178  LHS.get(),
6179  S->getEllipsisLoc(),
6180  RHS.get(),
6181  S->getColonLoc());
6182  if (Case.isInvalid())
6183  return StmtError();
6184 
6185  // Transform the statement following the case
6186  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6187  if (SubStmt.isInvalid())
6188  return StmtError();
6189 
6190  // Attach the body to the case statement
6191  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6192 }
6193 
6194 template<typename Derived>
6195 StmtResult
6196 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6197  // Transform the statement following the default case
6198  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6199  if (SubStmt.isInvalid())
6200  return StmtError();
6201 
6202  // Default statements are always rebuilt
6203  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6204  SubStmt.get());
6205 }
6206 
6207 template<typename Derived>
6208 StmtResult
6209 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6210  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6211  if (SubStmt.isInvalid())
6212  return StmtError();
6213 
6214  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6215  S->getDecl());
6216  if (!LD)
6217  return StmtError();
6218 
6219 
6220  // FIXME: Pass the real colon location in.
6221  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6222  cast<LabelDecl>(LD), SourceLocation(),
6223  SubStmt.get());
6224 }
6225 
6226 template <typename Derived>
6228  if (!R)
6229  return R;
6230 
6231  switch (R->getKind()) {
6232 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6233 #define ATTR(X)
6234 #define PRAGMA_SPELLING_ATTR(X) \
6235  case attr::X: \
6236  return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6237 #include "clang/Basic/AttrList.inc"
6238  default:
6239  return R;
6240  }
6241 }
6242 
6243 template <typename Derived>
6245  bool AttrsChanged = false;
6247 
6248  // Visit attributes and keep track if any are transformed.
6249  for (const auto *I : S->getAttrs()) {
6250  const Attr *R = getDerived().TransformAttr(I);
6251  AttrsChanged |= (I != R);
6252  Attrs.push_back(R);
6253  }
6254 
6255  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6256  if (SubStmt.isInvalid())
6257  return StmtError();
6258 
6259  if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6260  return S;
6261 
6262  return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6263  SubStmt.get());
6264 }
6265 
6266 template<typename Derived>
6267 StmtResult
6268 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6269  // Transform the initialization statement
6270  StmtResult Init = getDerived().TransformStmt(S->getInit());
6271  if (Init.isInvalid())
6272  return StmtError();
6273 
6274  // Transform the condition
6275  Sema::ConditionResult Cond = getDerived().TransformCondition(
6276  S->getIfLoc(), S->getConditionVariable(), S->getCond(),
6277  S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6279  if (Cond.isInvalid())
6280  return StmtError();
6281 
6282  // If this is a constexpr if, determine which arm we should instantiate.
6283  llvm::Optional<bool> ConstexprConditionValue;
6284  if (S->isConstexpr())
6285  ConstexprConditionValue = Cond.getKnownValue();
6286 
6287  // Transform the "then" branch.
6288  StmtResult Then;
6289  if (!ConstexprConditionValue || *ConstexprConditionValue) {
6290  Then = getDerived().TransformStmt(S->getThen());
6291  if (Then.isInvalid())
6292  return StmtError();
6293  } else {
6294  Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6295  }
6296 
6297  // Transform the "else" branch.
6298  StmtResult Else;
6299  if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6300  Else = getDerived().TransformStmt(S->getElse());
6301  if (Else.isInvalid())
6302  return StmtError();
6303  }
6304 
6305  if (!getDerived().AlwaysRebuild() &&
6306  Init.get() == S->getInit() &&
6307  Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6308  Then.get() == S->getThen() &&
6309  Else.get() == S->getElse())
6310  return S;
6311 
6312  return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
6313  Init.get(), Then.get(), S->getElseLoc(),
6314  Else.get());
6315 }
6316 
6317 template<typename Derived>
6318 StmtResult
6319 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6320  // Transform the initialization statement
6321  StmtResult Init = getDerived().TransformStmt(S->getInit());
6322  if (Init.isInvalid())
6323  return StmtError();
6324 
6325  // Transform the condition.
6326  Sema::ConditionResult Cond = getDerived().TransformCondition(
6327  S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6329  if (Cond.isInvalid())
6330  return StmtError();
6331 
6332  // Rebuild the switch statement.
6333  StmtResult Switch
6334  = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6335  S->getInit(), Cond);
6336  if (Switch.isInvalid())
6337  return StmtError();
6338 
6339  // Transform the body of the switch statement.
6340  StmtResult Body = getDerived().TransformStmt(S->getBody());
6341  if (Body.isInvalid())
6342  return StmtError();
6343 
6344  // Complete the switch statement.
6345  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6346  Body.get());
6347 }
6348 
6349 template<typename Derived>
6350 StmtResult
6351 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6352  // Transform the condition
6353  Sema::ConditionResult Cond = getDerived().TransformCondition(
6354  S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6356  if (Cond.isInvalid())
6357  return StmtError();
6358 
6359  // Transform the body
6360  StmtResult Body = getDerived().TransformStmt(S->getBody());
6361  if (Body.isInvalid())
6362  return StmtError();
6363 
6364  if (!getDerived().AlwaysRebuild() &&
6365  Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6366  Body.get() == S->getBody())
6367  return Owned(S);
6368 
6369  return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
6370 }
6371 
6372 template<typename Derived>
6373 StmtResult
6374 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6375  // Transform the body
6376  StmtResult Body = getDerived().TransformStmt(S->getBody());
6377  if (Body.isInvalid())
6378  return StmtError();
6379 
6380  // Transform the condition
6381  ExprResult Cond = getDerived().TransformExpr(S->getCond());
6382  if (Cond.isInvalid())
6383  return StmtError();
6384 
6385  if (!getDerived().AlwaysRebuild() &&
6386  Cond.get() == S->getCond() &&
6387  Body.get() == S->getBody())
6388  return S;
6389 
6390  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6391  /*FIXME:*/S->getWhileLoc(), Cond.get(),
6392  S->getRParenLoc());
6393 }
6394 
6395 template<typename Derived>
6396 StmtResult
6397 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6398  // Transform the initialization statement
6399  StmtResult Init = getDerived().TransformStmt(S->getInit());
6400  if (Init.isInvalid())
6401  return StmtError();
6402 
6403  // In OpenMP loop region loop control variable must be captured and be
6404  // private. Perform analysis of first part (if any).
6405  if (getSema().getLangOpts().OpenMP && Init.isUsable())
6406  getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6407 
6408  // Transform the condition
6409  Sema::ConditionResult Cond = getDerived().TransformCondition(
6410  S->getForLoc(), S->getConditionVariable(), S->getCond(),
6412  if (Cond.isInvalid())
6413  return StmtError();
6414 
6415  // Transform the increment
6416  ExprResult Inc = getDerived().TransformExpr(S->getInc());
6417  if (Inc.isInvalid())
6418  return StmtError();
6419 
6420  Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6421  if (S->getInc() && !FullInc.get())
6422  return StmtError();
6423 
6424  // Transform the body
6425  StmtResult Body = getDerived().TransformStmt(S->getBody());
6426  if (Body.isInvalid())
6427  return StmtError();
6428 
6429  if (!getDerived().AlwaysRebuild() &&
6430  Init.get() == S->getInit() &&
6431  Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
6432  Inc.get() == S->getInc() &&
6433  Body.get() == S->getBody())
6434  return S;
6435 
6436  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6437  Init.get(), Cond, FullInc,
6438  S->getRParenLoc(), Body.get());
6439 }
6440 
6441 template<typename Derived>
6442 StmtResult
6443 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6444  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6445  S->getLabel());
6446  if (!LD)
6447  return StmtError();
6448 
6449  // Goto statements must always be rebuilt, to resolve the label.
6450  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6451  cast<LabelDecl>(LD));
6452 }
6453 
6454 template<typename Derived>
6455 StmtResult
6456 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6457  ExprResult Target = getDerived().TransformExpr(S->getTarget());
6458  if (Target.isInvalid())
6459  return StmtError();
6460  Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6461 
6462  if (!getDerived().AlwaysRebuild() &&
6463  Target.get() == S->getTarget())
6464  return S;
6465 
6466  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6467  Target.get());
6468 }
6469 
6470 template<typename Derived>
6471 StmtResult
6472 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6473  return S;
6474 }
6475 
6476 template<typename Derived>
6477 StmtResult
6478 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6479  return S;
6480 }
6481 
6482 template<typename Derived>
6483 StmtResult
6484 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6485  ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6486  /*NotCopyInit*/false);
6487  if (Result.isInvalid())
6488  return StmtError();
6489 
6490  // FIXME: We always rebuild the return statement because there is no way
6491  // to tell whether the return type of the function has changed.
6492  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6493 }
6494 
6495 template<typename Derived>
6496 StmtResult
6497 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6498  bool DeclChanged = false;
6499  SmallVector<Decl *, 4> Decls;
6500  for (auto *D : S->decls()) {
6501  Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6502  if (!Transformed)
6503  return StmtError();
6504 
6505  if (Transformed != D)
6506  DeclChanged = true;
6507 
6508  Decls.push_back(Transformed);
6509  }
6510 
6511  if (!getDerived().AlwaysRebuild() && !DeclChanged)
6512  return S;
6513 
6514  return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6515 }
6516 
6517 template<typename Derived>
6518 StmtResult
6519 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6520 
6521  SmallVector<Expr*, 8> Constraints;
6522  SmallVector<Expr*, 8> Exprs;
6523  SmallVector<IdentifierInfo *, 4> Names;
6524 
6525  ExprResult AsmString;
6526  SmallVector<Expr*, 8> Clobbers;
6527 
6528  bool ExprsChanged = false;
6529 
6530  // Go through the outputs.
6531  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6532  Names.push_back(S->getOutputIdentifier(I));
6533 
6534  // No need to transform the constraint literal.
6535  Constraints.push_back(S->getOutputConstraintLiteral(I));
6536 
6537  // Transform the output expr.
6538  Expr *OutputExpr = S->getOutputExpr(I);
6539  ExprResult Result = getDerived().TransformExpr(OutputExpr);
6540  if (Result.isInvalid())
6541  return StmtError();
6542 
6543  ExprsChanged |= Result.get() != OutputExpr;
6544 
6545  Exprs.push_back(Result.get());
6546  }
6547 
6548  // Go through the inputs.
6549  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6550  Names.push_back(S->getInputIdentifier(I));
6551 
6552  // No need to transform the constraint literal.
6553  Constraints.push_back(S->getInputConstraintLiteral(I));
6554 
6555  // Transform the input expr.
6556  Expr *InputExpr = S->getInputExpr(I);
6557  ExprResult Result = getDerived().TransformExpr(InputExpr);
6558  if (Result.isInvalid())
6559  return StmtError();
6560 
6561  ExprsChanged |= Result.get() != InputExpr;
6562 
6563  Exprs.push_back(Result.get());
6564  }
6565 
6566  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6567  return S;
6568 
6569  // Go through the clobbers.
6570  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6571  Clobbers.push_back(S->getClobberStringLiteral(I));
6572 
6573  // No need to transform the asm string literal.
6574  AsmString = S->getAsmString();
6575  return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6576  S->isVolatile(), S->getNumOutputs(),
6577  S->getNumInputs(), Names.data(),
6578  Constraints, Exprs, AsmString.get(),
6579  Clobbers, S->getRParenLoc());
6580 }
6581 
6582 template<typename Derived>
6583 StmtResult
6584 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6585  ArrayRef<Token> AsmToks =
6586  llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6587 
6588  bool HadError = false, HadChange = false;
6589 
6590  ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6591  SmallVector<Expr*, 8> TransformedExprs;
6592  TransformedExprs.reserve(SrcExprs.size());
6593  for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6594  ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6595  if (!Result.isUsable()) {
6596  HadError = true;
6597  } else {
6598  HadChange |= (Result.get() != SrcExprs[i]);
6599  TransformedExprs.push_back(Result.get());
6600  }
6601  }
6602 
6603  if (HadError) return StmtError();
6604  if (!HadChange && !getDerived().AlwaysRebuild())
6605  return Owned(S);
6606 
6607  return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6608  AsmToks, S->getAsmString(),
6609  S->getNumOutputs(), S->getNumInputs(),
6610  S->getAllConstraints(), S->getClobbers(),
6611  TransformedExprs, S->getEndLoc());
6612 }
6613 
6614 // C++ Coroutines TS
6615 
6616 template<typename Derived>
6617 StmtResult
6618 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6619  // The coroutine body should be re-formed by the caller if necessary.
6620  return getDerived().TransformStmt(S->getBody());
6621 }
6622 
6623 template<typename Derived>
6624 StmtResult
6625 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6626  ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6627  /*NotCopyInit*/false);
6628  if (Result.isInvalid())
6629  return StmtError();
6630 
6631  // Always rebuild; we don't know if this needs to be injected into a new
6632  // context or if the promise type has changed.
6633  return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6634 }
6635 
6636 template<typename Derived>
6637 ExprResult
6638 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6639  ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6640  /*NotCopyInit*/false);
6641  if (Result.isInvalid())
6642  return ExprError();
6643 
6644  // Always rebuild; we don't know if this needs to be injected into a new
6645  // context or if the promise type has changed.
6646  return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6647 }
6648 
6649 template<typename Derived>
6650 ExprResult
6651 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6652  ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6653  /*NotCopyInit*/false);
6654  if (Result.isInvalid())
6655  return ExprError();
6656 
6657  // Always rebuild; we don't know if this needs to be injected into a new
6658  // context or if the promise type has changed.
6659  return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6660 }
6661 
6662 // Objective-C Statements.
6663 
6664 template<typename Derived>
6665 StmtResult
6666 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
6667  // Transform the body of the @try.
6668  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
6669  if (TryBody.isInvalid())
6670  return StmtError();
6671 
6672  // Transform the @catch statements (if present).
6673  bool AnyCatchChanged = false;
6674  SmallVector<Stmt*, 8> CatchStmts;
6675  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
6676  StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
6677  if (Catch.isInvalid())
6678  return StmtError();
6679  if (Catch.get() != S->getCatchStmt(I))
6680  AnyCatchChanged = true;
6681  CatchStmts.push_back(Catch.get());
6682  }
6683 
6684  // Transform the @finally statement (if present).
6685  StmtResult Finally;
6686  if (S->getFinallyStmt()) {
6687  Finally = getDerived().TransformStmt(S->getFinallyStmt());
6688  if (Finally.isInvalid())
6689  return StmtError();
6690  }
6691 
6692  // If nothing changed, just retain this statement.
6693  if (!getDerived().AlwaysRebuild() &&
6694  TryBody.get() == S->getTryBody() &&
6695  !AnyCatchChanged &&
6696  Finally.get() == S->getFinallyStmt())
6697  return S;
6698 
6699  // Build a new statement.
6700  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
6701  CatchStmts, Finally.get());
6702 }
6703 
6704 template<typename Derived>
6705 StmtResult
6706 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
6707  // Transform the @catch parameter, if there is one.
6708  VarDecl *Var = nullptr;
6709  if (VarDecl *FromVar = S->getCatchParamDecl()) {
6710  TypeSourceInfo *TSInfo = nullptr;
6711  if (FromVar->getTypeSourceInfo()) {
6712  TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6713  if (!TSInfo)
6714  return StmtError();
6715  }
6716 
6717  QualType T;
6718  if (TSInfo)
6719  T = TSInfo->getType();
6720  else {
6721  T = getDerived().TransformType(FromVar->getType());
6722  if (T.isNull())
6723  return StmtError();
6724  }
6725 
6726  Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6727  if (!Var)
6728  return StmtError();
6729  }
6730 
6731  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6732  if (Body.isInvalid())
6733  return StmtError();
6734 
6735  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6736  S->getRParenLoc(),
6737  Var, Body.get());
6738 }
6739 
6740 template<typename Derived>
6741 StmtResult
6742 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6743  // Transform the body.
6744  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6745  if (Body.isInvalid())
6746  return StmtError();
6747 
6748  // If nothing changed, just retain this statement.
6749  if (!getDerived().AlwaysRebuild() &&
6750  Body.get() == S->getFinallyBody())
6751  return S;
6752 
6753  // Build a new statement.
6754  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6755  Body.get());
6756 }
6757 
6758 template<typename Derived>
6759 StmtResult
6760 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6761  ExprResult Operand;
6762  if (S->getThrowExpr()) {
6763  Operand = getDerived().TransformExpr(S->getThrowExpr());
6764  if (Operand.isInvalid())
6765  return StmtError();
6766  }
6767 
6768  if (!getDerived().AlwaysRebuild() &&
6769  Operand.get() == S->getThrowExpr())
6770  return S;
6771 
6772  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6773 }
6774 
6775 template<typename Derived>
6776 StmtResult
6777 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6778  ObjCAtSynchronizedStmt *S) {
6779  // Transform the object we are locking.
6780  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6781  if (Object.isInvalid())
6782  return StmtError();
6783  Object =
6784  getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6785  Object.get());
6786  if (Object.isInvalid())
6787  return StmtError();
6788 
6789  // Transform the body.
6790  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6791  if (Body.isInvalid())
6792  return StmtError();
6793 
6794  // If nothing change, just retain the current statement.
6795  if (!getDerived().AlwaysRebuild() &&
6796  Object.get() == S->getSynchExpr() &&
6797  Body.get() == S->getSynchBody())
6798  return S;
6799 
6800  // Build a new statement.
6801  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6802  Object.get(), Body.get());
6803 }
6804 
6805 template<typename Derived>
6806 StmtResult
6807 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6808  ObjCAutoreleasePoolStmt *S) {
6809  // Transform the body.
6810  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6811  if (Body.isInvalid())
6812  return StmtError();
6813 
6814  // If nothing changed, just retain this statement.
6815  if (!getDerived().AlwaysRebuild() &&
6816  Body.get() == S->getSubStmt())
6817  return S;
6818 
6819  // Build a new statement.
6820  return getDerived().RebuildObjCAutoreleasePoolStmt(
6821  S->getAtLoc(), Body.get());
6822 }
6823 
6824 template<typename Derived>
6825 StmtResult
6826 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6827  ObjCForCollectionStmt *S) {
6828  // Transform the element statement.
6829  StmtResult Element = getDerived().TransformStmt(S->getElement());
6830  if (Element.isInvalid())
6831  return StmtError();
6832 
6833  // Transform the collection expression.
6834  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6835  if (Collection.isInvalid())
6836  return StmtError();
6837 
6838  // Transform the body.
6839  StmtResult Body = getDerived().TransformStmt(S->getBody());
6840  if (Body.isInvalid())
6841  return StmtError();
6842 
6843  // If nothing changed, just retain this statement.
6844  if (!getDerived().AlwaysRebuild() &&
6845  Element.get() == S->getElement() &&
6846  Collection.get() == S->getCollection() &&
6847  Body.get() == S->getBody())
6848  return S;
6849 
6850  // Build a new statement.
6851  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6852  Element.get(),
6853  Collection.get(),
6854  S->getRParenLoc(),
6855  Body.get());
6856 }
6857 
6858 template <typename Derived>
6859 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6860  // Transform the exception declaration, if any.
6861  VarDecl *Var = nullptr;
6862  if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6863  TypeSourceInfo *T =
6864  getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6865  if (!T)
6866  return StmtError();
6867 
6868  Var = getDerived().RebuildExceptionDecl(
6869  ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6870  ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6871  if (!Var || Var->isInvalidDecl())
6872  return StmtError();
6873  }
6874 
6875  // Transform the actual exception handler.
6876  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6877  if (Handler.isInvalid())
6878  return StmtError();
6879 
6880  if (!getDerived().AlwaysRebuild() && !Var &&
6881  Handler.get() == S->getHandlerBlock())
6882  return S;
6883 
6884  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6885 }
6886 
6887 template <typename Derived>
6888 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6889  // Transform the try block itself.
6890  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6891  if (TryBlock.isInvalid())
6892  return StmtError();
6893 
6894  // Transform the handlers.
6895  bool HandlerChanged = false;
6896  SmallVector<Stmt *, 8> Handlers;
6897  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6898  StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6899  if (Handler.isInvalid())
6900  return StmtError();
6901 
6902  HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6903  Handlers.push_back(Handler.getAs<Stmt>());
6904  }
6905 
6906  if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6907  !HandlerChanged)
6908  return S;
6909 
6910  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6911  Handlers);
6912 }
6913 
6914 template<typename Derived>
6915 StmtResult
6916 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6917  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6918  if (Range.isInvalid())
6919  return StmtError();
6920 
6921  StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6922  if (Begin.isInvalid())
6923  return StmtError();
6924  StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6925  if (End.isInvalid())
6926  return StmtError();
6927 
6928  ExprResult Cond = getDerived().TransformExpr(S->getCond());
6929  if (Cond.isInvalid())
6930  return StmtError();
6931  if (Cond.get())
6932  Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
6933  if (Cond.isInvalid())
6934  return StmtError();
6935  if (Cond.get())
6936  Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6937 
6938  ExprResult Inc = getDerived().TransformExpr(S->getInc());
6939  if (Inc.isInvalid())
6940  return StmtError();
6941  if (Inc.get())
6942  Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6943 
6944  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6945  if (LoopVar.isInvalid())
6946  return StmtError();
6947 
6948  StmtResult NewStmt = S;
6949  if (getDerived().AlwaysRebuild() ||
6950  Range.get() != S->getRangeStmt() ||
6951  Begin.get() != S->getBeginStmt() ||
6952  End.get() != S->getEndStmt() ||
6953  Cond.get() != S->getCond() ||
6954  Inc.get() != S->getInc() ||
6955  LoopVar.get() != S->getLoopVarStmt()) {
6956  NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6957  S->getCoawaitLoc(),
6958  S->getColonLoc(), Range.get(),
6959  Begin.get(), End.get(),
6960  Cond.get(),
6961  Inc.get(), LoopVar.get(),
6962  S->getRParenLoc());
6963  if (NewStmt.isInvalid())
6964  return StmtError();
6965  }
6966 
6967  StmtResult Body = getDerived().TransformStmt(S->getBody());
6968  if (Body.isInvalid())
6969  return StmtError();
6970 
6971  // Body has changed but we didn't rebuild the for-range statement. Rebuild
6972  // it now so we have a new statement to attach the body to.
6973  if (Body.get() != S->getBody() && NewStmt.get() == S) {
6974  NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6975  S->getCoawaitLoc(),
6976  S->getColonLoc(), Range.get(),
6977  Begin.get(), End.get(),
6978  Cond.get(),
6979  Inc.get(), LoopVar.get(),
6980  S->getRParenLoc());
6981  if (NewStmt.isInvalid())
6982  return StmtError();
6983  }
6984 
6985  if (NewStmt.get() == S)
6986  return S;
6987 
6988  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6989 }
6990 
6991 template<typename Derived>
6992 StmtResult
6993 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6994  MSDependentExistsStmt *S) {
6995  // Transform the nested-name-specifier, if any.
6996  NestedNameSpecifierLoc QualifierLoc;
6997  if (S->getQualifierLoc()) {
6998  QualifierLoc
6999  = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7000  if (!QualifierLoc)
7001  return StmtError();
7002  }
7003 
7004  // Transform the declaration name.
7005  DeclarationNameInfo NameInfo = S->getNameInfo();
7006  if (NameInfo.getName()) {
7007  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7008  if (!NameInfo.getName())
7009  return StmtError();
7010  }
7011 
7012  // Check whether anything changed.
7013  if (!getDerived().AlwaysRebuild() &&
7014  QualifierLoc == S->getQualifierLoc() &&
7015  NameInfo.getName() == S->getNameInfo().getName())
7016  return S;
7017 
7018  // Determine whether this name exists, if we can.
7019  CXXScopeSpec SS;
7020  SS.Adopt(QualifierLoc);
7021  bool Dependent = false;
7022  switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
7023  case Sema::IER_Exists:
7024  if (S->isIfExists())
7025  break;
7026 
7027  return new (getSema().Context) NullStmt(S->getKeywordLoc());
7028 
7030  if (S->isIfNotExists())
7031  break;
7032 
7033  return new (getSema().Context) NullStmt(S->getKeywordLoc());
7034 
7035  case Sema::IER_Dependent:
7036  Dependent = true;
7037  break;
7038 
7039  case Sema::IER_Error:
7040  return StmtError();
7041  }
7042 
7043  // We need to continue with the instantiation, so do so now.
7044  StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7045  if (SubStmt.isInvalid())
7046  return StmtError();
7047 
7048  // If we have resolved the name, just transform to the substatement.
7049  if (!Dependent)
7050  return SubStmt;
7051 
7052  // The name is still dependent, so build a dependent expression again.
7053  return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7054  S->isIfExists(),
7055  QualifierLoc,
7056  NameInfo,
7057  SubStmt.get());
7058 }
7059 
7060 template<typename Derived>
7061 ExprResult
7062 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7063  NestedNameSpecifierLoc QualifierLoc;
7064  if (E->getQualifierLoc()) {
7065  QualifierLoc
7066  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7067  if (!QualifierLoc)
7068  return ExprError();
7069  }
7070 
7071  MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7072  getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7073  if (!PD)
7074  return ExprError();
7075 
7076  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7077  if (Base.isInvalid())
7078  return ExprError();
7079 
7080  return new (SemaRef.getASTContext())
7081  MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7082  SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7083  QualifierLoc, E->getMemberLoc());
7084 }
7085 
7086 template <typename Derived>
7087 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7088  MSPropertySubscriptExpr *E) {
7089  auto BaseRes = getDerived().TransformExpr(E->getBase());
7090  if (BaseRes.isInvalid())
7091  return ExprError();
7092  auto IdxRes = getDerived().TransformExpr(E->getIdx());
7093  if (IdxRes.isInvalid())
7094  return ExprError();
7095 
7096  if (!getDerived().AlwaysRebuild() &&
7097  BaseRes.get() == E->getBase() &&
7098  IdxRes.get() == E->getIdx())
7099  return E;
7100 
7101  return getDerived().RebuildArraySubscriptExpr(
7102  BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7103 }
7104 
7105 template <typename Derived>
7106 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7107  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7108  if (TryBlock.isInvalid())
7109  return StmtError();
7110 
7111  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7112  if (Handler.isInvalid())
7113  return StmtError();
7114 
7115  if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7116  Handler.get() == S->getHandler())
7117  return S;
7118 
7119  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7120  TryBlock.get(), Handler.get());
7121 }
7122 
7123 template <typename Derived>
7124 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7125  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7126  if (Block.isInvalid())
7127  return StmtError();
7128 
7129  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7130 }
7131 
7132 template <typename Derived>
7133 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7134  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7135  if (FilterExpr.isInvalid())
7136  return StmtError();
7137 
7138  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7139  if (Block.isInvalid())
7140  return StmtError();
7141 
7142  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7143  Block.get());
7144 }
7145 
7146 template <typename Derived>
7148  if (isa<SEHFinallyStmt>(Handler))
7149  return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7150  else
7151  return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7152 }
7153 
7154 template<typename Derived>
7155 StmtResult
7157  return S;
7158 }
7159 
7160 //===----------------------------------------------------------------------===//
7161 // OpenMP directive transformation
7162 //===----------------------------------------------------------------------===//
7163 template <typename Derived>
7166 
7167  // Transform the clauses
7169  ArrayRef<OMPClause *> Clauses = D->clauses();
7170  TClauses.reserve(Clauses.size());
7171  for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7172  I != E; ++I) {
7173  if (*I) {
7174  getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7175  OMPClause *Clause = getDerived().TransformOMPClause(*I);
7176  getDerived().getSema().EndOpenMPClause();
7177  if (Clause)
7178  TClauses.push_back(Clause);
7179  } else {
7180  TClauses.push_back(nullptr);
7181  }
7182  }
7183  StmtResult AssociatedStmt;
7184  if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7185  getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7186  /*CurScope=*/nullptr);
7187  StmtResult Body;
7188  {
7189  Sema::CompoundScopeRAII CompoundScope(getSema());
7190  Body = getDerived().TransformStmt(
7191  cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7192  }
7193  AssociatedStmt =
7194  getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7195  if (AssociatedStmt.isInvalid()) {
7196  return StmtError();
7197  }
7198  }
7199  if (TClauses.size() != Clauses.size()) {
7200  return StmtError();
7201  }
7202 
7203  // Transform directive name for 'omp critical' directive.
7204  DeclarationNameInfo DirName;
7205  if (D->getDirectiveKind() == OMPD_critical) {
7206  DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7207  DirName = getDerived().TransformDeclarationNameInfo(DirName);
7208  }
7209  OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7210  if (D->getDirectiveKind() == OMPD_cancellation_point) {
7211  CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7212  } else if (D->getDirectiveKind() == OMPD_cancel) {
7213  CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7214  }
7215 
7216  return getDerived().RebuildOMPExecutableDirective(
7217  D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7218  AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7219 }
7220 
7221 template <typename Derived>
7222 StmtResult
7224  DeclarationNameInfo DirName;
7225  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7226  D->getLocStart());
7227  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7228  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7229  return Res;
7230 }
7231 
7232 template <typename Derived>
7233 StmtResult
7234 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7235  DeclarationNameInfo DirName;
7236  getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7237  D->getLocStart());
7238  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7239  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7240  return Res;
7241 }
7242 
7243 template <typename Derived>
7244 StmtResult
7245 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7246  DeclarationNameInfo DirName;
7247  getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7248  D->getLocStart());
7249  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7250  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7251  return Res;
7252 }
7253 
7254 template <typename Derived>
7255 StmtResult
7256 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7257  DeclarationNameInfo DirName;
7258  getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7259  D->getLocStart());
7260  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7261  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7262  return Res;
7263 }
7264 
7265 template <typename Derived>
7266 StmtResult
7267 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7268  DeclarationNameInfo DirName;
7269  getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7270  D->getLocStart());
7271  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7272  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7273  return Res;
7274 }
7275 
7276 template <typename Derived>
7277 StmtResult
7278 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7279  DeclarationNameInfo DirName;
7280  getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7281  D->getLocStart());
7282  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7283  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7284  return Res;
7285 }
7286 
7287 template <typename Derived>
7288 StmtResult
7289 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7290  DeclarationNameInfo DirName;
7291  getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7292  D->getLocStart());
7293  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7294  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7295  return Res;
7296 }
7297 
7298 template <typename Derived>
7299 StmtResult
7300 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7301  DeclarationNameInfo DirName;
7302  getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7303  D->getLocStart());
7304  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7305  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7306  return Res;
7307 }
7308 
7309 template <typename Derived>
7310 StmtResult
7311 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7312  getDerived().getSema().StartOpenMPDSABlock(
7313  OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7314  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7315  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7316  return Res;
7317 }
7318 
7319 template <typename Derived>
7320 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7321  OMPParallelForDirective *D) {
7322  DeclarationNameInfo DirName;
7323  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7324  nullptr, D->getLocStart());
7325  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7326  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7327  return Res;
7328 }
7329 
7330 template <typename Derived>
7331 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7332  OMPParallelForSimdDirective *D) {
7333  DeclarationNameInfo DirName;
7334  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7335  nullptr, D->getLocStart());
7336  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7337  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7338  return Res;
7339 }
7340 
7341 template <typename Derived>
7342 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7343  OMPParallelSectionsDirective *D) {
7344  DeclarationNameInfo DirName;
7345  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7346  nullptr, D->getLocStart());
7347  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7348  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7349  return Res;
7350 }
7351 
7352 template <typename Derived>
7353 StmtResult
7354 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7355  DeclarationNameInfo DirName;
7356  getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7357  D->getLocStart());
7358  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7359  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7360  return Res;
7361 }
7362 
7363 template <typename Derived>
7364 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7365  OMPTaskyieldDirective *D) {
7366  DeclarationNameInfo DirName;
7367  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7368  D->getLocStart());
7369  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7370  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7371  return Res;
7372 }
7373 
7374 template <typename Derived>
7375 StmtResult
7376 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7377  DeclarationNameInfo DirName;
7378  getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7379  D->getLocStart());
7380  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7381  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7382  return Res;
7383 }
7384 
7385 template <typename Derived>
7386 StmtResult
7387 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7388  DeclarationNameInfo DirName;
7389  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7390  D->getLocStart());
7391  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7392  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7393  return Res;
7394 }
7395 
7396 template <typename Derived>
7397 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7398  OMPTaskgroupDirective *D) {
7399  DeclarationNameInfo DirName;
7400  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7401  D->getLocStart());
7402  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7403  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7404  return Res;
7405 }
7406 
7407 template <typename Derived>
7408 StmtResult
7409 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7410  DeclarationNameInfo DirName;
7411  getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7412  D->getLocStart());
7413  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7414  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7415  return Res;
7416 }
7417 
7418 template <typename Derived>
7419 StmtResult
7420 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7421  DeclarationNameInfo DirName;
7422  getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7423  D->getLocStart());
7424  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7425  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7426  return Res;
7427 }
7428 
7429 template <typename Derived>
7430 StmtResult
7431 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7432  DeclarationNameInfo DirName;
7433  getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7434  D->getLocStart());
7435  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7436  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7437  return Res;
7438 }
7439 
7440 template <typename Derived>
7441 StmtResult
7442 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7443  DeclarationNameInfo DirName;
7444  getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7445  D->getLocStart());
7446  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7447  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7448  return Res;
7449 }
7450 
7451 template <typename Derived>
7452 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7453  OMPTargetDataDirective *D) {
7454  DeclarationNameInfo DirName;
7455  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7456  D->getLocStart());
7457  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7458  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7459  return Res;
7460 }
7461 
7462 template <typename Derived>
7463 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7464  OMPTargetEnterDataDirective *D) {
7465  DeclarationNameInfo DirName;
7466  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7467  nullptr, D->getLocStart());
7468  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7469  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7470  return Res;
7471 }
7472 
7473 template <typename Derived>
7474 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7475  OMPTargetExitDataDirective *D) {
7476  DeclarationNameInfo DirName;
7477  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7478  nullptr, D->getLocStart());
7479  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7480  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7481  return Res;
7482 }
7483 
7484 template <typename Derived>
7485 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7486  OMPTargetParallelDirective *D) {
7487  DeclarationNameInfo DirName;
7488  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7489  nullptr, D->getLocStart());
7490  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7491  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7492  return Res;
7493 }
7494 
7495 template <typename Derived>
7496 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7497  OMPTargetParallelForDirective *D) {
7498  DeclarationNameInfo DirName;
7499  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7500  nullptr, D->getLocStart());
7501  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7502  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7503  return Res;
7504 }
7505 
7506 template <typename Derived>
7507 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7508  OMPTargetUpdateDirective *D) {
7509  DeclarationNameInfo DirName;
7510  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7511  nullptr, D->getLocStart());
7512  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7513  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7514  return Res;
7515 }
7516 
7517 template <typename Derived>
7518 StmtResult
7519 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7520  DeclarationNameInfo DirName;
7521  getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7522  D->getLocStart());
7523  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7524  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7525  return Res;
7526 }
7527 
7528 template <typename Derived>
7529 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7530  OMPCancellationPointDirective *D) {
7531  DeclarationNameInfo DirName;
7532  getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7533  nullptr, D->getLocStart());
7534  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7535  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7536  return Res;
7537 }
7538 
7539 template <typename Derived>
7540 StmtResult
7541 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7542  DeclarationNameInfo DirName;
7543  getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7544  D->getLocStart());
7545  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7546  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7547  return Res;
7548 }
7549 
7550 template <typename Derived>
7551 StmtResult
7552 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7553  DeclarationNameInfo DirName;
7554  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7555  D->getLocStart());
7556  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7557  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7558  return Res;
7559 }
7560 
7561 template <typename Derived>
7562 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7563  OMPTaskLoopSimdDirective *D) {
7564  DeclarationNameInfo DirName;
7565  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7566  nullptr, D->getLocStart());
7567  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7568  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7569  return Res;
7570 }
7571 
7572 template <typename Derived>
7573 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7574  OMPDistributeDirective *D) {
7575  DeclarationNameInfo DirName;
7576  getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7577  D->getLocStart());
7578  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7579  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7580  return Res;
7581 }
7582 
7583 template <typename Derived>
7584 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7585  OMPDistributeParallelForDirective *D) {
7586  DeclarationNameInfo DirName;
7587  getDerived().getSema().StartOpenMPDSABlock(
7588  OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7589  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7590  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7591  return Res;
7592 }
7593 
7594 template <typename Derived>
7595 StmtResult
7596 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7597  OMPDistributeParallelForSimdDirective *D) {
7598  DeclarationNameInfo DirName;
7599  getDerived().getSema().StartOpenMPDSABlock(
7600  OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7601  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7602  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7603  return Res;
7604 }
7605 
7606 template <typename Derived>
7607 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7608  OMPDistributeSimdDirective *D) {
7609  DeclarationNameInfo DirName;
7610  getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7611  nullptr, D->getLocStart());
7612  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7613  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7614  return Res;
7615 }
7616 
7617 template <typename Derived>
7618 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7619  OMPTargetParallelForSimdDirective *D) {
7620  DeclarationNameInfo DirName;
7621  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7622  DirName, nullptr,
7623  D->getLocStart());
7624  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7625  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7626  return Res;
7627 }
7628 
7629 //===----------------------------------------------------------------------===//
7630 // OpenMP clause transformation
7631 //===----------------------------------------------------------------------===//
7632 template <typename Derived>
7633 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
7634  ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7635  if (Cond.isInvalid())
7636  return nullptr;
7637  return getDerived().RebuildOMPIfClause(
7638  C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7639  C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
7640 }
7641 
7642 template <typename Derived>
7643 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7644  ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7645  if (Cond.isInvalid())
7646  return nullptr;
7647  return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7648  C->getLParenLoc(), C->getLocEnd());
7649 }
7650 
7651 template <typename Derived>
7652 OMPClause *
7653 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7654  ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7655  if (NumThreads.isInvalid())
7656  return nullptr;
7657  return getDerived().RebuildOMPNumThreadsClause(
7658  NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7659 }
7660 
7661 template <typename Derived>
7662 OMPClause *
7663 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7664  ExprResult E = getDerived().TransformExpr(C->getSafelen());
7665  if (E.isInvalid())
7666  return nullptr;
7667  return getDerived().RebuildOMPSafelenClause(
7668  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7669 }
7670 
7671 template <typename Derived>
7672 OMPClause *
7673 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7674  ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7675  if (E.isInvalid())
7676  return nullptr;
7677  return getDerived().RebuildOMPSimdlenClause(
7678  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7679 }
7680 
7681 template <typename Derived>
7682 OMPClause *
7683 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7684  ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7685  if (E.isInvalid())
7686  return nullptr;
7687  return getDerived().RebuildOMPCollapseClause(
7688  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7689 }
7690 
7691 template <typename Derived>
7692 OMPClause *
7693 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
7694  return getDerived().RebuildOMPDefaultClause(
7695  C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7696  C->getLParenLoc(), C->getLocEnd());
7697 }
7698 
7699 template <typename Derived>
7700 OMPClause *
7701 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
7702  return getDerived().RebuildOMPProcBindClause(
7703  C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7704  C->getLParenLoc(), C->getLocEnd());
7705 }
7706 
7707 template <typename Derived>
7708 OMPClause *
7709 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7710  ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7711  if (E.isInvalid())
7712  return nullptr;
7713  return getDerived().RebuildOMPScheduleClause(
7714  C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
7715  C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7716  C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
7717  C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7718 }
7719 
7720 template <typename Derived>
7721 OMPClause *
7722 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7723  ExprResult E;
7724  if (auto *Num = C->getNumForLoops()) {
7725  E = getDerived().TransformExpr(Num);
7726  if (E.isInvalid())
7727  return nullptr;
7728  }
7729  return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7730  C->getLParenLoc(), E.get());
7731 }
7732 
7733 template <typename Derived>
7734 OMPClause *
7735 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7736  // No need to rebuild this clause, no template-dependent parameters.
7737  return C;
7738 }
7739 
7740 template <typename Derived>
7741 OMPClause *
7742 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7743  // No need to rebuild this clause, no template-dependent parameters.
7744  return C;
7745 }
7746 
7747 template <typename Derived>
7748 OMPClause *
7749 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7750  // No need to rebuild this clause, no template-dependent parameters.
7751  return C;
7752 }
7753 
7754 template <typename Derived>
7755 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7756  // No need to rebuild this clause, no template-dependent parameters.
7757  return C;
7758 }
7759 
7760 template <typename Derived>
7761 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7762  // No need to rebuild this clause, no template-dependent parameters.
7763  return C;
7764 }
7765 
7766 template <typename Derived>
7767 OMPClause *
7768 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7769  // No need to rebuild this clause, no template-dependent parameters.
7770  return C;
7771 }
7772 
7773 template <typename Derived>
7774 OMPClause *
7775 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7776  // No need to rebuild this clause, no template-dependent parameters.
7777  return C;
7778 }
7779 
7780 template <typename Derived>
7781 OMPClause *
7782 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7783  // No need to rebuild this clause, no template-dependent parameters.
7784  return C;
7785 }
7786 
7787 template <typename Derived>
7788 OMPClause *
7789 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7790  // No need to rebuild this clause, no template-dependent parameters.
7791  return C;
7792 }
7793 
7794 template <typename Derived>
7795 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7796  // No need to rebuild this clause, no template-dependent parameters.
7797  return C;
7798 }
7799 
7800 template <typename Derived>
7801 OMPClause *
7802 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7803  // No need to rebuild this clause, no template-dependent parameters.
7804  return C;
7805 }
7806 
7807 template <typename Derived>
7808 OMPClause *
7809 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
7811  Vars.reserve(C->varlist_size());
7812  for (auto *VE : C->varlists()) {
7813  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7814  if (EVar.isInvalid())
7815  return nullptr;
7816  Vars.push_back(EVar.get());
7817  }
7818  return getDerived().RebuildOMPPrivateClause(
7819  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7820 }
7821 
7822 template <typename Derived>
7823 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7824  OMPFirstprivateClause *C) {
7826  Vars.reserve(C->varlist_size());
7827  for (auto *VE : C->varlists()) {
7828  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7829  if (EVar.isInvalid())
7830  return nullptr;
7831  Vars.push_back(EVar.get());
7832  }
7833  return getDerived().RebuildOMPFirstprivateClause(
7834  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7835 }
7836 
7837 template <typename Derived>
7838 OMPClause *
7839 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7841  Vars.reserve(C->varlist_size());
7842  for (auto *VE : C->varlists()) {
7843  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7844  if (EVar.isInvalid())
7845  return nullptr;
7846  Vars.push_back(EVar.get());
7847  }
7848  return getDerived().RebuildOMPLastprivateClause(
7849  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7850 }
7851 
7852 template <typename Derived>
7853 OMPClause *
7854 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7856  Vars.reserve(C->varlist_size());
7857  for (auto *VE : C->varlists()) {
7858  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7859  if (EVar.isInvalid())
7860  return nullptr;
7861  Vars.push_back(EVar.get());
7862  }
7863  return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7864  C->getLParenLoc(), C->getLocEnd());
7865 }
7866 
7867 template <typename Derived>
7868 OMPClause *
7869 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7871  Vars.reserve(C->varlist_size());
7872  for (auto *VE : C->varlists()) {
7873  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7874  if (EVar.isInvalid())
7875  return nullptr;
7876  Vars.push_back(EVar.get());
7877  }
7878  CXXScopeSpec ReductionIdScopeSpec;
7879  ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7880 
7881  DeclarationNameInfo NameInfo = C->getNameInfo();
7882  if (NameInfo.getName()) {
7883  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7884  if (!NameInfo.getName())
7885  return nullptr;
7886  }
7887  // Build a list of all UDR decls with the same names ranged by the Scopes.
7888  // The Scope boundary is a duplication of the previous decl.
7889  llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7890  for (auto *E : C->reduction_ops()) {
7891  // Transform all the decls.
7892  if (E) {
7893  auto *ULE = cast<UnresolvedLookupExpr>(E);
7894  UnresolvedSet<8> Decls;
7895  for (auto *D : ULE->decls()) {
7896  NamedDecl *InstD =
7897  cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
7898  Decls.addDecl(InstD, InstD->getAccess());
7899  }
7900  UnresolvedReductions.push_back(
7902  SemaRef.Context, /*NamingClass=*/nullptr,
7903  ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
7904  NameInfo, /*ADL=*/true, ULE->isOverloaded(),
7905  Decls.begin(), Decls.end()));
7906  } else
7907  UnresolvedReductions.push_back(nullptr);
7908  }
7909  return getDerived().RebuildOMPReductionClause(
7910  Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7911  C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
7912 }
7913 
7914 template <typename Derived>
7915 OMPClause *
7916 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7918  Vars.reserve(C->varlist_size());
7919  for (auto *VE : C->varlists()) {
7920  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7921  if (EVar.isInvalid())
7922  return nullptr;
7923  Vars.push_back(EVar.get());
7924  }
7925  ExprResult Step = getDerived().TransformExpr(C->getStep());
7926  if (Step.isInvalid())
7927  return nullptr;
7928  return getDerived().RebuildOMPLinearClause(
7929  Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7930  C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
7931 }
7932 
7933 template <typename Derived>
7934 OMPClause *
7935 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7937  Vars.reserve(C->varlist_size());
7938  for (auto *VE : C->varlists()) {
7939  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7940  if (EVar.isInvalid())
7941  return nullptr;
7942  Vars.push_back(EVar.get());
7943  }
7944  ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7945  if (Alignment.isInvalid())
7946  return nullptr;
7947  return getDerived().RebuildOMPAlignedClause(
7948  Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7949  C->getColonLoc(), C->getLocEnd());
7950 }
7951 
7952 template <typename Derived>
7953 OMPClause *
7954 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7956  Vars.reserve(C->varlist_size());
7957  for (auto *VE : C->varlists()) {
7958  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7959  if (EVar.isInvalid())
7960  return nullptr;
7961  Vars.push_back(EVar.get());
7962  }
7963  return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7964  C->getLParenLoc(), C->getLocEnd());
7965 }
7966 
7967 template <typename Derived>
7968 OMPClause *
7969 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7971  Vars.reserve(C->varlist_size());
7972  for (auto *VE : C->varlists()) {
7973  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7974  if (EVar.isInvalid())
7975  return nullptr;
7976  Vars.push_back(EVar.get());
7977  }
7978  return getDerived().RebuildOMPCopyprivateClause(
7979  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7980 }
7981 
7982 template <typename Derived>
7983 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7985  Vars.reserve(C->varlist_size());
7986  for (auto *VE : C->varlists()) {
7987  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7988  if (EVar.isInvalid())
7989  return nullptr;
7990  Vars.push_back(EVar.get());
7991  }
7992  return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7993  C->getLParenLoc(), C->getLocEnd());
7994 }
7995 
7996 template <typename Derived>
7997 OMPClause *
7998 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8000  Vars.reserve(C->varlist_size());
8001  for (auto *VE : C->varlists()) {
8002  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8003  if (EVar.isInvalid())
8004  return nullptr;
8005  Vars.push_back(EVar.get());
8006  }
8007  return getDerived().RebuildOMPDependClause(
8008  C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8009  C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8010 }
8011 
8012 template <typename Derived>
8013 OMPClause *
8014 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8015  ExprResult E = getDerived().TransformExpr(C->getDevice());
8016  if (E.isInvalid())
8017  return nullptr;
8018  return getDerived().RebuildOMPDeviceClause(
8019  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8020 }
8021 
8022 template <typename Derived>
8023 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8025  Vars.reserve(C->varlist_size());
8026  for (auto *VE : C->varlists()) {
8027  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8028  if (EVar.isInvalid())
8029  return nullptr;
8030  Vars.push_back(EVar.get());
8031  }
8032  return getDerived().RebuildOMPMapClause(
8034  C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8035  C->getLParenLoc(), C->getLocEnd());
8036 }
8037 
8038 template <typename Derived>
8039 OMPClause *
8040 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8041  ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8042  if (E.isInvalid())
8043  return nullptr;
8044  return getDerived().RebuildOMPNumTeamsClause(
8045  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8046 }
8047 
8048 template <typename Derived>
8049 OMPClause *
8050 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8051  ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8052  if (E.isInvalid())
8053  return nullptr;
8054  return getDerived().RebuildOMPThreadLimitClause(
8055  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8056 }
8057 
8058 template <typename Derived>
8059 OMPClause *
8060 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8061  ExprResult E = getDerived().TransformExpr(C->getPriority());
8062  if (E.isInvalid())
8063  return nullptr;
8064  return getDerived().RebuildOMPPriorityClause(
8065  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8066 }
8067 
8068 template <typename Derived>
8069 OMPClause *
8070 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8071  ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8072  if (E.isInvalid())
8073  return nullptr;
8074  return getDerived().RebuildOMPGrainsizeClause(
8075  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8076 }
8077 
8078 template <typename Derived>
8079 OMPClause *
8080 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8081  ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8082  if (E.isInvalid())
8083  return nullptr;
8084  return getDerived().RebuildOMPNumTasksClause(
8085  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8086 }
8087 
8088 template <typename Derived>
8089 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8090  ExprResult E = getDerived().TransformExpr(C->getHint());
8091  if (E.isInvalid())
8092  return nullptr;
8093  return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8094  C->getLParenLoc(), C->getLocEnd());
8095 }
8096 
8097 template <typename Derived>
8098 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8099  OMPDistScheduleClause *C) {
8100  ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8101  if (E.isInvalid())
8102  return nullptr;
8103  return getDerived().RebuildOMPDistScheduleClause(
8104  C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8105  C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8106 }
8107 
8108 template <typename Derived>
8109 OMPClause *
8110 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8111  return C;
8112 }
8113 
8114 template <typename Derived>
8115 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8117  Vars.reserve(C->varlist_size());
8118  for (auto *VE : C->varlists()) {
8119  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8120  if (EVar.isInvalid())
8121  return 0;
8122  Vars.push_back(EVar.get());
8123  }
8124  return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8125  C->getLParenLoc(), C->getLocEnd());
8126 }
8127 
8128 template <typename Derived>
8129 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8131  Vars.reserve(C->varlist_size());
8132  for (auto *VE : C->varlists()) {
8133  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8134  if (EVar.isInvalid())
8135  return 0;
8136  Vars.push_back(EVar.get());
8137  }
8138  return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8139  C->getLParenLoc(), C->getLocEnd());
8140 }
8141 
8142 template <typename Derived>
8143 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8144  OMPUseDevicePtrClause *C) {
8146  Vars.reserve(C->varlist_size());
8147  for (auto *VE : C->varlists()) {
8148  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8149  if (EVar.isInvalid())
8150  return nullptr;
8151  Vars.push_back(EVar.get());
8152  }
8153  return getDerived().RebuildOMPUseDevicePtrClause(
8154  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8155 }
8156 
8157 template <typename Derived>
8158 OMPClause *
8159 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8161  Vars.reserve(C->varlist_size());
8162  for (auto *VE : C->varlists()) {
8163  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8164  if (EVar.isInvalid())
8165  return nullptr;
8166  Vars.push_back(EVar.get());
8167  }
8168  return getDerived().RebuildOMPIsDevicePtrClause(
8169  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8170 }
8171 
8172 //===----------------------------------------------------------------------===//
8173 // Expression transformation
8174 //===----------------------------------------------------------------------===//
8175 template<typename Derived>
8176 ExprResult
8177 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
8178  if (!E->isTypeDependent())
8179  return E;
8180 
8181  return getDerived().RebuildPredefinedExpr(E->getLocation(),
8182  E->getIdentType());
8183 }
8184 
8185 template<typename Derived>
8186 ExprResult
8187 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
8188  NestedNameSpecifierLoc QualifierLoc;
8189  if (E->getQualifierLoc()) {
8190  QualifierLoc
8191  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8192  if (!QualifierLoc)
8193  return ExprError();
8194  }
8195 
8196  ValueDecl *ND
8197  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8198  E->getDecl()));
8199  if (!ND)
8200  return ExprError();
8201 
8202  DeclarationNameInfo NameInfo = E->getNameInfo();
8203  if (NameInfo.getName()) {
8204  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8205  if (!NameInfo.getName())
8206  return ExprError();
8207  }
8208 
8209  if (!getDerived().AlwaysRebuild() &&
8210  QualifierLoc == E->getQualifierLoc() &&
8211  ND == E->getDecl() &&
8212  NameInfo.getName() == E->getDecl()->getDeclName() &&
8213  !E->hasExplicitTemplateArgs()) {
8214 
8215  // Mark it referenced in the new context regardless.
8216  // FIXME: this is a bit instantiation-specific.
8217  SemaRef.MarkDeclRefReferenced(E);
8218 
8219  return E;
8220  }
8221 
8222  TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
8223  if (E->hasExplicitTemplateArgs()) {
8224  TemplateArgs = &TransArgs;
8225  TransArgs.setLAngleLoc(E->getLAngleLoc());
8226  TransArgs.setRAngleLoc(E->getRAngleLoc());
8227  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8228  E->getNumTemplateArgs(),
8229  TransArgs))
8230  return ExprError();
8231  }
8232 
8233  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
8234  TemplateArgs);
8235 }
8236 
8237 template<typename Derived>
8238 ExprResult
8239 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
8240  return E;
8241 }
8242 
8243 template<typename Derived>
8244 ExprResult
8245 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
8246  return E;
8247 }
8248 
8249 template<typename Derived>
8250 ExprResult
8251 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
8252  return E;
8253 }
8254 
8255 template<typename Derived>
8256 ExprResult
8257 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
8258  return E;
8259 }
8260 
8261 template<typename Derived>
8262 ExprResult
8263 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
8264  return E;
8265 }
8266 
8267 template<typename Derived>
8268 ExprResult
8269 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
8270  if (FunctionDecl *FD = E->getDirectCallee())
8271  SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
8272  return SemaRef.MaybeBindToTemporary(E);
8273 }
8274 
8275 template<typename Derived>
8276 ExprResult
8277 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8278  ExprResult ControllingExpr =
8279  getDerived().TransformExpr(E->getControllingExpr());
8280  if (ControllingExpr.isInvalid())
8281  return ExprError();
8282 
8283  SmallVector<Expr *, 4> AssocExprs;
8284  SmallVector<TypeSourceInfo *, 4> AssocTypes;
8285  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8286  TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8287  if (TS) {
8288  TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8289  if (!AssocType)
8290  return ExprError();
8291  AssocTypes.push_back(AssocType);
8292  } else {
8293  AssocTypes.push_back(nullptr);
8294  }
8295 
8296  ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8297  if (AssocExpr.isInvalid())
8298  return ExprError();
8299  AssocExprs.push_back(AssocExpr.get());
8300  }
8301 
8302  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8303  E->getDefaultLoc(),
8304  E->getRParenLoc(),
8305  ControllingExpr.get(),
8306  AssocTypes,
8307  AssocExprs);
8308 }
8309 
8310 template<typename Derived>
8311 ExprResult
8312 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8313  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8314  if (SubExpr.isInvalid())
8315  return ExprError();
8316 
8317  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8318  return E;
8319 
8320  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8321  E->getRParen());
8322 }
8323 
8324 /// \brief The operand of a unary address-of operator has special rules: it's
8325 /// allowed to refer to a non-static member of a class even if there's no 'this'
8326 /// object available.
8327 template<typename Derived>
8328 ExprResult
8330  if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8331  return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8332  else
8333  return getDerived().TransformExpr(E);
8334 }
8335 
8336 template<typename Derived>
8337 ExprResult
8339  ExprResult SubExpr;
8340  if (E->getOpcode() == UO_AddrOf)
8341  SubExpr = TransformAddressOfOperand(E->getSubExpr());
8342  else
8343  SubExpr = TransformExpr(E->getSubExpr());
8344  if (SubExpr.isInvalid())
8345  return ExprError();
8346 
8347  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8348  return E;
8349 
8350  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8351  E->getOpcode(),
8352  SubExpr.get());
8353 }
8354 
8355 template<typename Derived>
8356 ExprResult
8357 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8358  // Transform the type.
8359  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8360  if (!Type)
8361  return ExprError();
8362 
8363  // Transform all of the components into components similar to what the
8364  // parser uses.
8365  // FIXME: It would be slightly more efficient in the non-dependent case to
8366  // just map FieldDecls, rather than requiring the rebuilder to look for
8367  // the fields again. However, __builtin_offsetof is rare enough in
8368  // template code that we don't care.
8369  bool ExprChanged = false;
8370  typedef Sema::OffsetOfComponent Component;
8371  SmallVector<Component, 4> Components;
8372  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8373  const OffsetOfNode &ON = E->getComponent(I);
8374  Component Comp;
8375  Comp.isBrackets = true;
8376  Comp.LocStart = ON.getSourceRange().getBegin();
8377  Comp.LocEnd = ON.getSourceRange().getEnd();
8378  switch (ON.getKind()) {
8379  case OffsetOfNode::Array: {
8380  Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8381  ExprResult Index = getDerived().TransformExpr(FromIndex);
8382  if (Index.isInvalid())
8383  return ExprError();
8384 
8385  ExprChanged = ExprChanged || Index.get() != FromIndex;
8386  Comp.isBrackets = true;
8387  Comp.U.E = Index.get();
8388  break;
8389  }
8390 
8391  case OffsetOfNode::Field:
8393  Comp.isBrackets = false;
8394  Comp.U.IdentInfo = ON.getFieldName();
8395  if (!Comp.U.IdentInfo)
8396  continue;
8397 
8398  break;
8399 
8400  case OffsetOfNode::Base:
8401  // Will be recomputed during the rebuild.
8402  continue;
8403  }
8404 
8405  Components.push_back(Comp);
8406  }
8407 
8408  // If nothing changed, retain the existing expression.
8409  if (!getDerived().AlwaysRebuild() &&
8410  Type == E->getTypeSourceInfo() &&
8411  !ExprChanged)
8412  return E;
8413 
8414  // Build a new offsetof expression.
8415  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8416  Components, E->getRParenLoc());
8417 }
8418 
8419 template<typename Derived>
8420 ExprResult
8421 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8422  assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8423  "opaque value expression requires transformation");
8424  return E;
8425 }
8426 
8427 template<typename Derived>
8428 ExprResult
8429 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8430  return E;
8431 }
8432 
8433 template<typename Derived>
8434 ExprResult
8435 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8436  // Rebuild the syntactic form. The original syntactic form has
8437  // opaque-value expressions in it, so strip those away and rebuild
8438  // the result. This is a really awful way of doing this, but the
8439  // better solution (rebuilding the semantic expressions and
8440  // rebinding OVEs as necessary) doesn't work; we'd need
8441  // TreeTransform to not strip away implicit conversions.
8442  Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8443  ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8444  if (result.isInvalid()) return ExprError();
8445 
8446  // If that gives us a pseudo-object result back, the pseudo-object
8447  // expression must have been an lvalue-to-rvalue conversion which we
8448  // should reapply.
8449  if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8450  result = SemaRef.checkPseudoObjectRValue(result.get());
8451 
8452  return result;
8453 }
8454 
8455 template<typename Derived>
8456 ExprResult
8457 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8458  UnaryExprOrTypeTraitExpr *E) {
8459  if (E->isArgumentType()) {
8460  TypeSourceInfo *OldT = E->getArgumentTypeInfo();
8461 
8462  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8463  if (!NewT)
8464  return ExprError();
8465 
8466  if (!getDerived().AlwaysRebuild() && OldT == NewT)
8467  return E;
8468 
8469  return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8470  E->getKind(),
8471  E->getSourceRange());
8472  }
8473 
8474  // C++0x [expr.sizeof]p1:
8475  // The operand is either an expression, which is an unevaluated operand
8476  // [...]
8477  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8479 
8480  // Try to recover if we have something like sizeof(T::X) where X is a type.
8481  // Notably, there must be *exactly* one set of parens if X is a type.
8482  TypeSourceInfo *RecoveryTSI = nullptr;
8483  ExprResult SubExpr;
8484  auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8485  if (auto *DRE =
8486  PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8487  SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8488  PE, DRE, false, &RecoveryTSI);
8489  else
8490  SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8491 
8492  if (RecoveryTSI) {
8493  return getDerived().RebuildUnaryExprOrTypeTrait(
8494  RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8495  } else if (SubExpr.isInvalid())
8496  return ExprError();
8497 
8498  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
8499  return E;
8500 
8501  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8502  E->getOperatorLoc(),
8503  E->getKind(),
8504  E->getSourceRange());
8505 }
8506 
8507 template<typename Derived>
8508 ExprResult
8509 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
8510  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8511  if (LHS.isInvalid())
8512  return ExprError();
8513 
8514  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8515  if (RHS.isInvalid())
8516  return ExprError();
8517 
8518 
8519  if (!getDerived().AlwaysRebuild() &&
8520  LHS.get() == E->getLHS() &&
8521  RHS.get() == E->getRHS())
8522  return E;
8523 
8524  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
8525  /*FIXME:*/E->getLHS()->getLocStart(),
8526  RHS.get(),
8527  E->getRBracketLoc());
8528 }
8529 
8530 template <typename Derived>
8531 ExprResult
8532 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8533  ExprResult Base = getDerived().TransformExpr(E->getBase());
8534  if (Base.isInvalid())
8535  return ExprError();
8536 
8537  ExprResult LowerBound;
8538  if (E->getLowerBound()) {
8539  LowerBound = getDerived().TransformExpr(E->getLowerBound());
8540  if (LowerBound.isInvalid())
8541  return ExprError();
8542  }
8543 
8545  if (E->getLength()) {
8546  Length = getDerived().TransformExpr(E->getLength());
8547  if (Length.isInvalid())
8548  return ExprError();
8549  }
8550 
8551  if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8552  LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8553  return E;
8554 
8555  return getDerived().RebuildOMPArraySectionExpr(
8556  Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8557  Length.get(), E->getRBracketLoc());
8558 }
8559 
8560 template<typename Derived>
8561 ExprResult
8562 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
8563  // Transform the callee.
8564  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8565  if (Callee.isInvalid())
8566  return ExprError();
8567 
8568  // Transform arguments.
8569  bool ArgChanged = false;
8570  SmallVector<Expr*, 8> Args;
8571  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8572  &ArgChanged))
8573  return ExprError();
8574 
8575  if (!getDerived().AlwaysRebuild() &&
8576  Callee.get() == E->getCallee() &&
8577  !ArgChanged)
8578  return SemaRef.MaybeBindToTemporary(E);
8579 
8580  // FIXME: Wrong source location information for the '('.
8581  SourceLocation FakeLParenLoc
8582  = ((Expr *)Callee.get())->getSourceRange().getBegin();
8583  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
8584  Args,
8585  E->getRParenLoc());
8586 }
8587 
8588 template<typename Derived>
8589 ExprResult
8590 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
8591  ExprResult Base = getDerived().TransformExpr(E->getBase());
8592  if (Base.isInvalid())
8593  return ExprError();
8594 
8595  NestedNameSpecifierLoc QualifierLoc;
8596  if (E->hasQualifier()) {
8597  QualifierLoc
8598  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8599 
8600  if (!QualifierLoc)
8601  return ExprError();
8602  }
8603  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8604 
8605  ValueDecl *Member
8606  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8607  E->getMemberDecl()));
8608  if (!Member)
8609  return ExprError();
8610 
8611  NamedDecl *FoundDecl = E->getFoundDecl();
8612  if (FoundDecl == E->getMemberDecl()) {
8613  FoundDecl = Member;
8614  } else {
8615  FoundDecl = cast_or_null<NamedDecl>(
8616  getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8617  if (!FoundDecl)
8618  return ExprError();
8619  }
8620 
8621  if (!getDerived().AlwaysRebuild() &&
8622  Base.get() == E->getBase() &&
8623  QualifierLoc == E->getQualifierLoc() &&
8624  Member == E->getMemberDecl() &&
8625  FoundDecl == E->getFoundDecl() &&
8626  !E->hasExplicitTemplateArgs()) {
8627 
8628  // Mark it referenced in the new context regardless.
8629  // FIXME: this is a bit instantiation-specific.
8630  SemaRef.MarkMemberReferenced(E);
8631 
8632  return E;
8633  }
8634 
8635  TemplateArgumentListInfo TransArgs;
8636  if (E->hasExplicitTemplateArgs()) {
8637  TransArgs.setLAngleLoc(E->getLAngleLoc());
8638  TransArgs.setRAngleLoc(E->getRAngleLoc());
8639  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8640  E->getNumTemplateArgs(),
8641  TransArgs))
8642  return ExprError();
8643  }
8644 
8645  // FIXME: Bogus source location for the operator
8646  SourceLocation FakeOperatorLoc =
8647  SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
8648 
8649  // FIXME: to do this check properly, we will need to preserve the
8650  // first-qualifier-in-scope here, just in case we had a dependent
8651  // base (and therefore couldn't do the check) and a
8652  // nested-name-qualifier (and therefore could do the lookup).
8653  NamedDecl *FirstQualifierInScope = nullptr;
8654 
8655  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
8656  E->isArrow(),
8657  QualifierLoc,
8658  TemplateKWLoc,
8659  E->getMemberNameInfo(),
8660  Member,
8661  FoundDecl,
8662  (E->hasExplicitTemplateArgs()
8663  ? &TransArgs : nullptr),
8664  FirstQualifierInScope);
8665 }
8666 
8667 template<typename Derived>
8668 ExprResult
8669 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
8670  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8671  if (LHS.isInvalid())
8672  return ExprError();
8673 
8674  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8675  if (RHS.isInvalid())
8676  return ExprError();
8677 
8678  if (!getDerived().AlwaysRebuild() &&
8679  LHS.get() == E->getLHS() &&
8680  RHS.get() == E->getRHS())
8681  return E;
8682 
8683  Sema::FPContractStateRAII FPContractState(getSema());
8684  getSema().FPFeatures.fp_contract = E->isFPContractable();
8685 
8686  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
8687  LHS.get(), RHS.get());
8688 }
8689 
8690 template<typename Derived>
8691 ExprResult
8692 TreeTransform<Derived>::TransformCompoundAssignOperator(
8693  CompoundAssignOperator *E) {
8694  return getDerived().TransformBinaryOperator(E);
8695 }
8696 
8697 template<typename Derived>
8698 ExprResult TreeTransform<Derived>::
8699 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8700  // Just rebuild the common and RHS expressions and see whether we
8701  // get any changes.
8702 
8703  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8704  if (commonExpr.isInvalid())
8705  return ExprError();
8706 
8707  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8708  if (rhs.isInvalid())
8709  return ExprError();
8710 
8711  if (!getDerived().AlwaysRebuild() &&
8712  commonExpr.get() == e->getCommon() &&
8713  rhs.get() == e->getFalseExpr())
8714  return e;
8715 
8716  return getDerived().RebuildConditionalOperator(commonExpr.get(),
8717  e->getQuestionLoc(),
8718  nullptr,
8719  e->getColonLoc(),
8720  rhs.get());
8721 }
8722 
8723 template<typename Derived>
8724 ExprResult
8725 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
8726  ExprResult Cond = getDerived().TransformExpr(E->getCond());
8727  if (Cond.isInvalid())
8728  return ExprError();
8729 
8730  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8731  if (LHS.isInvalid())
8732  return ExprError();
8733 
8734  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8735  if (RHS.isInvalid())
8736  return ExprError();
8737 
8738  if (!getDerived().AlwaysRebuild() &&
8739  Cond.get() == E->getCond() &&
8740  LHS.get() == E->getLHS() &&
8741  RHS.get() == E->getRHS())
8742  return E;
8743 
8744  return getDerived().RebuildConditionalOperator(Cond.get(),
8745  E->getQuestionLoc(),
8746  LHS.get(),
8747  E->getColonLoc(),
8748  RHS.get());
8749 }
8750 
8751 template<typename Derived>
8752 ExprResult
8753 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
8754  // Implicit casts are eliminated during transformation, since they
8755  // will be recomputed by semantic analysis after transformation.
8756  return getDerived().TransformExpr(E->getSubExprAsWritten());
8757 }
8758 
8759 template<typename Derived>
8760 ExprResult
8761 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
8762  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8763  if (!Type)
8764  return ExprError();
8765 
8766  ExprResult SubExpr
8767  = getDerived().TransformExpr(E->getSubExprAsWritten());
8768  if (SubExpr.isInvalid())
8769  return ExprError();
8770 
8771  if (!getDerived().AlwaysRebuild() &&
8772  Type == E->getTypeInfoAsWritten() &&
8773  SubExpr.get() == E->getSubExpr())
8774  return E;
8775 
8776  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
8777  Type,
8778  E->getRParenLoc(),
8779  SubExpr.get());
8780 }
8781 
8782 template<typename Derived>
8783 ExprResult
8784 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
8785  TypeSourceInfo *OldT = E->getTypeSourceInfo();
8786  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8787  if (!NewT)
8788  return ExprError();
8789 
8790  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
8791  if (Init.isInvalid())
8792  return ExprError();
8793 
8794  if (!getDerived().AlwaysRebuild() &&
8795  OldT == NewT &&
8796  Init.get() == E->getInitializer())
8797  return SemaRef.MaybeBindToTemporary(E);
8798 
8799  // Note: the expression type doesn't necessarily match the
8800  // type-as-written, but that's okay, because it should always be
8801  // derivable from the initializer.
8802 
8803  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
8804  /*FIXME:*/E->getInitializer()->getLocEnd(),
8805  Init.get());
8806 }
8807 
8808 template<typename Derived>
8809 ExprResult
8810 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
8811  ExprResult Base = getDerived().TransformExpr(E->getBase());
8812  if (Base.isInvalid())
8813  return ExprError();
8814 
8815  if (!getDerived().AlwaysRebuild() &&
8816  Base.get() == E->getBase())
8817  return E;
8818 
8819  // FIXME: Bad source location
8820  SourceLocation FakeOperatorLoc =
8821  SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
8822  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
8823  E->getAccessorLoc(),
8824  E->getAccessor());
8825 }
8826 
8827 template<typename Derived>
8828 ExprResult
8829 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
8830  if (InitListExpr *Syntactic = E->getSyntacticForm())
8831  E = Syntactic;
8832 
8833  bool InitChanged = false;
8834 
8835  SmallVector<Expr*, 4> Inits;
8836  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
8837  Inits, &InitChanged))
8838  return ExprError();
8839 
8840  if (!getDerived().AlwaysRebuild() && !InitChanged) {
8841  // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8842  // in some cases. We can't reuse it in general, because the syntactic and
8843  // semantic forms are linked, and we can't know that semantic form will
8844  // match even if the syntactic form does.
8845  }
8846 
8847  return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
8848  E->getRBraceLoc(), E->getType());
8849 }
8850 
8851 template<typename Derived>
8852 ExprResult
8853 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
8854  Designation Desig;
8855 
8856  // transform the initializer value
8857  ExprResult Init = getDerived().TransformExpr(E->getInit());
8858  if (Init.isInvalid())
8859  return ExprError();
8860 
8861  // transform the designators.
8862  SmallVector<Expr*, 4> ArrayExprs;
8863  bool ExprChanged = false;
8864  for (const DesignatedInitExpr::Designator &D : E->designators()) {
8865  if (D.isFieldDesignator()) {
8866  Desig.AddDesignator(Designator::getField(D.getFieldName(),
8867  D.getDotLoc(),
8868  D.getFieldLoc()));
8869  continue;
8870  }
8871 
8872  if (D.isArrayDesignator()) {
8873  ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
8874  if (Index.isInvalid())
8875  return ExprError();
8876 
8877  Desig.AddDesignator(
8878  Designator::getArray(Index.get(), D.getLBracketLoc()));
8879 
8880  ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
8881  ArrayExprs.push_back(Index.get());
8882  continue;
8883  }
8884 
8885  assert(D.isArrayRangeDesignator() && "New kind of designator?");
8886  ExprResult Start
8887  = getDerived().TransformExpr(E->getArrayRangeStart(D));
8888  if (Start.isInvalid())
8889  return ExprError();
8890 
8891  ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
8892  if (End.isInvalid())
8893  return ExprError();
8894 
8895  Desig.AddDesignator(Designator::getArrayRange(Start.get(),
8896  End.get(),
8897  D.getLBracketLoc(),
8898  D.getEllipsisLoc()));
8899 
8900  ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
8901  End.get() != E->getArrayRangeEnd(D);
8902 
8903  ArrayExprs.push_back(Start.get());
8904  ArrayExprs.push_back(End.get());
8905  }
8906 
8907  if (!getDerived().AlwaysRebuild() &&
8908  Init.get() == E->getInit() &&
8909  !ExprChanged)
8910  return E;
8911 
8912  return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
8913  E->getEqualOrColonLoc(),
8914  E->usesGNUSyntax(), Init.get());
8915 }
8916 
8917 // Seems that if TransformInitListExpr() only works on the syntactic form of an
8918 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8919 template<typename Derived>
8920 ExprResult
8921 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8922  DesignatedInitUpdateExpr *E) {
8923  llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8924  "initializer");
8925  return ExprError();
8926 }
8927 
8928 template<typename Derived>
8929 ExprResult
8930 TreeTransform<Derived>::TransformNoInitExpr(
8931  NoInitExpr *E) {
8932  llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8933  return ExprError();
8934 }
8935 
8936 template<typename Derived>
8937 ExprResult
8938 TreeTransform<Derived>::TransformImplicitValueInitExpr(
8939  ImplicitValueInitExpr *E) {
8940  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
8941 
8942  // FIXME: Will we ever have proper type location here? Will we actually
8943  // need to transform the type?
8944  QualType T = getDerived().TransformType(E->getType());
8945  if (T.isNull())
8946  return ExprError();
8947 
8948  if (!getDerived().AlwaysRebuild() &&
8949  T == E->getType())
8950  return E;
8951 
8952  return getDerived().RebuildImplicitValueInitExpr(T);
8953 }
8954 
8955 template<typename Derived>
8956 ExprResult
8957 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
8958  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8959  if (!TInfo)
8960  return ExprError();
8961 
8962  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8963  if (SubExpr.isInvalid())
8964  return ExprError();
8965 
8966  if (!getDerived().AlwaysRebuild() &&
8967  TInfo == E->getWrittenTypeInfo() &&
8968  SubExpr.get() == E->getSubExpr())
8969  return E;
8970 
8971  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
8972  TInfo, E->getRParenLoc());
8973 }
8974 
8975 template<typename Derived>
8976 ExprResult
8977 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
8978  bool ArgumentChanged = false;
8979  SmallVector<Expr*, 4> Inits;
8980  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8981  &ArgumentChanged))
8982  return ExprError();
8983 
8984  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
8985  Inits,
8986  E->getRParenLoc());
8987 }
8988 
8989 /// \brief Transform an address-of-label expression.
8990 ///
8991 /// By default, the transformation of an address-of-label expression always
8992 /// rebuilds the expression, so that the label identifier can be resolved to
8993 /// the corresponding label statement by semantic analysis.
8994 template<typename Derived>
8995 ExprResult
8996 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
8997  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8998  E->getLabel());
8999  if (!LD)
9000  return ExprError();
9001 
9002  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
9003  cast<LabelDecl>(LD));
9004 }
9005 
9006 template<typename Derived>
9007 ExprResult
9008 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
9009  SemaRef.ActOnStartStmtExpr();
9010  StmtResult SubStmt
9011  = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
9012  if (SubStmt.isInvalid()) {
9013  SemaRef.ActOnStmtExprError();
9014  return ExprError();
9015  }
9016 
9017  if (!getDerived().AlwaysRebuild() &&
9018  SubStmt.get() == E->getSubStmt()) {
9019  // Calling this an 'error' is unintuitive, but it does the right thing.
9020  SemaRef.ActOnStmtExprError();
9021  return SemaRef.MaybeBindToTemporary(E);
9022  }
9023 
9024  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
9025  SubStmt.get(),
9026  E->getRParenLoc());
9027 }
9028 
9029 template<typename Derived>
9030 ExprResult
9031 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
9032  ExprResult Cond = getDerived().TransformExpr(E->getCond());
9033  if (Cond.isInvalid())
9034  return ExprError();
9035 
9036  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
9037  if (LHS.isInvalid())
9038  return ExprError();
9039 
9040  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
9041  if (RHS.isInvalid())
9042  return ExprError();
9043 
9044  if (!getDerived().AlwaysRebuild() &&
9045  Cond.get() == E->getCond() &&
9046  LHS.get() == E->getLHS() &&
9047  RHS.get() == E->getRHS())
9048  return E;
9049 
9050  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
9051  Cond.get(), LHS.get(), RHS.get(),
9052  E->getRParenLoc());
9053 }
9054 
9055 template<typename Derived>
9056 ExprResult
9057 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
9058  return E;
9059 }
9060 
9061 template<typename Derived>
9062 ExprResult
9063 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
9064  switch (E->getOperator()) {
9065  case OO_New:
9066  case OO_Delete:
9067  case OO_Array_New:
9068  case OO_Array_Delete:
9069  llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
9070 
9071  case OO_Call: {
9072  // This is a call to an object's operator().
9073  assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9074 
9075  // Transform the object itself.
9076  ExprResult Object = getDerived().TransformExpr(E->getArg(0));
9077  if (Object.isInvalid())
9078  return ExprError();
9079 
9080  // FIXME: Poor location information
9081  SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9082  static_cast<Expr *>(Object.get())->getLocEnd());
9083 
9084  // Transform the call arguments.
9085  SmallVector<Expr*, 8> Args;
9086  if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
9087  Args))
9088  return ExprError();
9089 
9090  return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
9091  Args,
9092  E->getLocEnd());
9093  }
9094 
9095 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9096  case OO_##Name:
9097 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9098 #include "clang/Basic/OperatorKinds.def"
9099  case OO_Subscript:
9100  // Handled below.
9101  break;
9102 
9103  case OO_Conditional:
9104  llvm_unreachable("conditional operator is not actually overloadable");
9105 
9106  case OO_None:
9108  llvm_unreachable("not an overloaded operator?");
9109  }
9110 
9111  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9112  if (Callee.isInvalid())
9113  return ExprError();
9114 
9115  ExprResult First;
9116  if (E->getOperator() == OO_Amp)
9117  First = getDerived().TransformAddressOfOperand(E->getArg(0));
9118  else
9119  First = getDerived().TransformExpr(E->getArg(0));
9120  if (First.isInvalid())
9121  return ExprError();
9122 
9123  ExprResult Second;
9124  if (E->getNumArgs() == 2) {
9125  Second = getDerived().TransformExpr(E->getArg(1));
9126  if (Second.isInvalid())
9127  return ExprError();
9128  }
9129 
9130  if (!getDerived().AlwaysRebuild() &&
9131  Callee.get() == E->getCallee() &&
9132  First.get() == E->getArg(0) &&
9133  (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
9134  return SemaRef.MaybeBindToTemporary(E);
9135 
9136  Sema::FPContractStateRAII FPContractState(getSema());
9137  getSema().FPFeatures.fp_contract = E->isFPContractable();
9138 
9139  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9140  E->getOperatorLoc(),
9141  Callee.get(),
9142  First.get(),
9143  Second.get());
9144 }
9145 
9146 template<typename Derived>
9147 ExprResult
9148 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9149  return getDerived().TransformCallExpr(E);
9150 }
9151 
9152 template<typename Derived>
9153 ExprResult
9154 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9155  // Transform the callee.
9156  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9157  if (Callee.isInvalid())
9158  return ExprError();
9159 
9160  // Transform exec config.
9161  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9162  if (EC.isInvalid())
9163  return ExprError();
9164 
9165  // Transform arguments.
9166  bool ArgChanged = false;
9167  SmallVector<Expr*, 8> Args;
9168  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9169  &ArgChanged))
9170  return ExprError();
9171 
9172  if (!getDerived().AlwaysRebuild() &&
9173  Callee.get() == E->getCallee() &&
9174  !ArgChanged)
9175  return SemaRef.MaybeBindToTemporary(E);
9176 
9177  // FIXME: Wrong source location information for the '('.
9178  SourceLocation FakeLParenLoc
9179  = ((Expr *)Callee.get())->getSourceRange().getBegin();
9180  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
9181  Args,
9182  E->getRParenLoc(), EC.get());
9183 }
9184 
9185 template<typename Derived>
9186 ExprResult
9188  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9189  if (!Type)
9190  return ExprError();
9191 
9192  ExprResult SubExpr
9193  = getDerived().TransformExpr(E->getSubExprAsWritten());
9194  if (SubExpr.isInvalid())
9195  return ExprError();
9196 
9197  if (!getDerived().AlwaysRebuild() &&
9198  Type == E->getTypeInfoAsWritten() &&
9199  SubExpr.get() == E->getSubExpr())
9200  return E;
9201  return getDerived().RebuildCXXNamedCastExpr(
9202  E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9203  Type, E->getAngleBrackets().getEnd(),
9204  // FIXME. this should be '(' location
9205  E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
9206 }
9207 
9208 template<typename Derived>
9209 ExprResult
9211  return getDerived().TransformCXXNamedCastExpr(E);
9212 }
9213 
9214 template<typename Derived>
9215 ExprResult
9216 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9217  return getDerived().TransformCXXNamedCastExpr(E);
9218 }
9219 
9220 template<typename Derived>
9221 ExprResult
9222 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
9223  CXXReinterpretCastExpr *E) {
9224  return getDerived().TransformCXXNamedCastExpr(E);
9225 }
9226 
9227 template<typename Derived>
9228 ExprResult
9229 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9230  return getDerived().TransformCXXNamedCastExpr(E);
9231 }
9232 
9233 template<typename Derived>
9234 ExprResult
9235 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
9236  CXXFunctionalCastExpr *E) {
9237  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9238  if (!Type)
9239  return ExprError();
9240 
9241  ExprResult SubExpr
9242  = getDerived().TransformExpr(E->getSubExprAsWritten());
9243  if (SubExpr.isInvalid())
9244  return ExprError();
9245 
9246  if (!getDerived().AlwaysRebuild() &&
9247  Type == E->getTypeInfoAsWritten() &&
9248  SubExpr.get() == E->getSubExpr())
9249  return E;
9250 
9251  return getDerived().RebuildCXXFunctionalCastExpr(Type,
9252  E->getLParenLoc(),
9253  SubExpr.get(),
9254  E->getRParenLoc());
9255 }
9256 
9257 template<typename Derived>
9258 ExprResult
9259 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
9260  if (E->isTypeOperand()) {
9261  TypeSourceInfo *TInfo
9262  = getDerived().TransformType(E->getTypeOperandSourceInfo());
9263  if (!TInfo)
9264  return ExprError();
9265 
9266  if (!getDerived().AlwaysRebuild() &&
9267  TInfo == E->getTypeOperandSourceInfo())
9268  return E;
9269 
9270  return getDerived().RebuildCXXTypeidExpr(E->getType(),
9271  E->getLocStart(),
9272  TInfo,
9273  E->getLocEnd());
9274  }
9275 
9276  // We don't know whether the subexpression is potentially evaluated until
9277  // after we perform semantic analysis. We speculatively assume it is
9278  // unevaluated; it will get fixed later if the subexpression is in fact
9279  // potentially evaluated.
9280  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9282 
9283  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9284  if (SubExpr.isInvalid())
9285  return ExprError();
9286 
9287  if (!getDerived().AlwaysRebuild() &&
9288  SubExpr.get() == E->getExprOperand())
9289  return E;
9290 
9291  return getDerived().RebuildCXXTypeidExpr(E->getType(),
9292  E->getLocStart(),
9293  SubExpr.get(),
9294  E->getLocEnd());
9295 }
9296 
9297 template<typename Derived>
9298 ExprResult
9299 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9300  if (E->isTypeOperand()) {
9301  TypeSourceInfo *TInfo
9302  = getDerived().TransformType(E->getTypeOperandSourceInfo());
9303  if (!TInfo)
9304  return ExprError();
9305 
9306  if (!getDerived().AlwaysRebuild() &&
9307  TInfo == E->getTypeOperandSourceInfo())
9308  return E;
9309 
9310  return getDerived().RebuildCXXUuidofExpr(E->getType(),
9311  E->getLocStart(),
9312  TInfo,
9313  E->getLocEnd());
9314  }
9315 
9316  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9317 
9318  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9319  if (SubExpr.isInvalid())
9320  return ExprError();
9321 
9322  if (!getDerived().AlwaysRebuild() &&
9323  SubExpr.get() == E->getExprOperand())
9324  return E;
9325 
9326  return getDerived().RebuildCXXUuidofExpr(E->getType(),
9327  E->getLocStart(),
9328  SubExpr.get(),
9329  E->getLocEnd());
9330 }
9331 
9332 template<typename Derived>
9333 ExprResult
9334 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9335  return E;
9336 }
9337 
9338 template<typename Derived>
9339 ExprResult
9340 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9341  CXXNullPtrLiteralExpr *E) {
9342  return E;
9343 }
9344 
9345 template<typename Derived>
9346 ExprResult
9347 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9348  QualType T = getSema().getCurrentThisType();
9349 
9350  if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9351  // Make sure that we capture 'this'.
9352  getSema().CheckCXXThisCapture(E->getLocStart());
9353  return E;
9354  }
9355 
9356  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9357 }
9358 
9359 template<typename Derived>
9360 ExprResult
9361 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9362  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9363  if (SubExpr.isInvalid())
9364  return ExprError();
9365 
9366  if (!getDerived().AlwaysRebuild() &&
9367  SubExpr.get() == E->getSubExpr())
9368  return E;
9369 
9370  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9371  E->isThrownVariableInScope());
9372 }
9373 
9374 template<typename Derived>
9375 ExprResult
9376 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9377  ParmVarDecl *Param
9378  = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9379  E->getParam()));
9380  if (!Param)
9381  return ExprError();
9382 
9383  if (!getDerived().AlwaysRebuild() &&
9384  Param == E->getParam())
9385  return E;
9386 
9387  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9388 }
9389 
9390 template<typename Derived>
9391 ExprResult
9392 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9393  FieldDecl *Field
9394  = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9395  E->getField()));
9396  if (!Field)
9397  return ExprError();
9398 
9399  if (!getDerived().AlwaysRebuild() && Field == E->getField())
9400  return E;
9401 
9402  return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9403 }
9404 
9405 template<typename Derived>
9406 ExprResult
9407 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9408  CXXScalarValueInitExpr *E) {
9409  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9410  if (!T)
9411  return ExprError();
9412 
9413  if (!getDerived().AlwaysRebuild() &&
9414  T == E->getTypeSourceInfo())
9415  return E;
9416 
9417  return getDerived().RebuildCXXScalarValueInitExpr(T,
9418  /*FIXME:*/T->getTypeLoc().getEndLoc(),
9419  E->getRParenLoc());
9420 }
9421 
9422 template<typename Derived>
9423 ExprResult
9424 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
9425  // Transform the type that we're allocating
9426  TypeSourceInfo *AllocTypeInfo
9427  = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9428  if (!AllocTypeInfo)
9429  return ExprError();
9430 
9431  // Transform the size of the array we're allocating (if any).
9432  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
9433  if (ArraySize.isInvalid())
9434  return ExprError();
9435 
9436  // Transform the placement arguments (if any).
9437  bool ArgumentChanged = false;
9438  SmallVector<Expr*, 8> PlacementArgs;
9439  if (getDerived().TransformExprs(E->getPlacementArgs(),
9440  E->getNumPlacementArgs(), true,
9441  PlacementArgs, &ArgumentChanged))
9442  return ExprError();
9443 
9444  // Transform the initializer (if any).
9445  Expr *OldInit = E->getInitializer();
9446  ExprResult NewInit;
9447  if (OldInit)
9448  NewInit = getDerived().TransformInitializer(OldInit, true);
9449  if (NewInit.isInvalid())
9450  return ExprError();
9451 
9452  // Transform new operator and delete operator.
9453  FunctionDecl *OperatorNew = nullptr;
9454  if (E->getOperatorNew()) {
9455  OperatorNew = cast_or_null<FunctionDecl>(
9456  getDerived().TransformDecl(E->getLocStart(),
9457  E->getOperatorNew()));
9458  if (!OperatorNew)
9459  return ExprError();
9460  }
9461 
9462  FunctionDecl *OperatorDelete = nullptr;
9463  if (E->getOperatorDelete()) {
9464  OperatorDelete = cast_or_null<FunctionDecl>(
9465  getDerived().TransformDecl(E->getLocStart(),
9466  E->getOperatorDelete()));
9467  if (!OperatorDelete)
9468  return ExprError();
9469  }
9470 
9471  if (!getDerived().AlwaysRebuild() &&
9472  AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
9473  ArraySize.get() == E->getArraySize() &&
9474  NewInit.get() == OldInit &&
9475  OperatorNew == E->getOperatorNew() &&
9476  OperatorDelete == E->getOperatorDelete() &&
9477  !ArgumentChanged) {
9478  // Mark any declarations we need as referenced.
9479  // FIXME: instantiation-specific.
9480  if (OperatorNew)
9481  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
9482  if (OperatorDelete)
9483  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9484 
9485  if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
9486  QualType ElementType
9487  = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9488  if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9489  CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9490  if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
9491  SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
9492  }
9493  }
9494  }
9495 
9496  return E;
9497  }
9498 
9499  QualType AllocType = AllocTypeInfo->getType();
9500  if (!ArraySize.get()) {
9501  // If no array size was specified, but the new expression was
9502  // instantiated with an array type (e.g., "new T" where T is
9503  // instantiated with "int[4]"), extract the outer bound from the
9504  // array type as our array size. We do this with constant and
9505  // dependently-sized array types.
9506  const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9507  if (!ArrayT) {
9508  // Do nothing
9509  } else if (const ConstantArrayType *ConsArrayT
9510  = dyn_cast<ConstantArrayType>(ArrayT)) {
9511  ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9512  SemaRef.Context.getSizeType(),
9513  /*FIXME:*/ E->getLocStart());
9514  AllocType = ConsArrayT->getElementType();
9515  } else if (const DependentSizedArrayType *DepArrayT
9516  = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9517  if (DepArrayT->getSizeExpr()) {
9518  ArraySize = DepArrayT->getSizeExpr();
9519  AllocType = DepArrayT->getElementType();
9520  }
9521  }
9522  }
9523 
9524  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9525  E->isGlobalNew(),
9526  /*FIXME:*/E->getLocStart(),
9527  PlacementArgs,
9528  /*FIXME:*/E->getLocStart(),
9529  E->getTypeIdParens(),
9530  AllocType,
9531  AllocTypeInfo,
9532  ArraySize.get(),
9533  E->getDirectInitRange(),
9534  NewInit.get());
9535 }
9536 
9537 template<typename Derived>
9538 ExprResult
9539 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
9540  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
9541  if (Operand.isInvalid())
9542  return ExprError();
9543 
9544  // Transform the delete operator, if known.
9545  FunctionDecl *OperatorDelete = nullptr;
9546  if (E->getOperatorDelete()) {
9547  OperatorDelete = cast_or_null<FunctionDecl>(
9548  getDerived().TransformDecl(E->getLocStart(),
9549  E->getOperatorDelete()));
9550  if (!OperatorDelete)
9551  return ExprError();
9552  }
9553 
9554  if (!getDerived().AlwaysRebuild() &&
9555  Operand.get() == E->getArgument() &&
9556  OperatorDelete == E->getOperatorDelete()) {
9557  // Mark any declarations we need as referenced.
9558  // FIXME: instantiation-specific.
9559  if (OperatorDelete)
9560  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9561 
9562  if (!E->getArgument()->isTypeDependent()) {
9563  QualType Destroyed = SemaRef.Context.getBaseElementType(
9564  E->getDestroyedType());
9565  if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9566  CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
9567  SemaRef.MarkFunctionReferenced(E->getLocStart(),
9568  SemaRef.LookupDestructor(Record));
9569  }
9570  }
9571 
9572  return E;
9573  }
9574 
9575  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9576  E->isGlobalDelete(),
9577  E->isArrayForm(),
9578  Operand.get());
9579 }
9580 
9581 template<typename Derived>
9582 ExprResult
9583 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
9584  CXXPseudoDestructorExpr *E) {
9585  ExprResult Base = getDerived().TransformExpr(E->getBase());
9586  if (Base.isInvalid())
9587  return ExprError();
9588 
9589  ParsedType ObjectTypePtr;
9590  bool MayBePseudoDestructor = false;
9591  Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9592  E->getOperatorLoc(),
9593  E->isArrow()? tok::arrow : tok::period,
9594  ObjectTypePtr,
9595  MayBePseudoDestructor);
9596  if (Base.isInvalid())
9597  return ExprError();
9598 
9599  QualType ObjectType = ObjectTypePtr.get();
9600  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9601  if (QualifierLoc) {
9602  QualifierLoc
9603  = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9604  if (!QualifierLoc)
9605  return ExprError();
9606  }
9607  CXXScopeSpec SS;
9608  SS.Adopt(QualifierLoc);
9609 
9610  PseudoDestructorTypeStorage Destroyed;
9611  if (E->getDestroyedTypeInfo()) {
9612  TypeSourceInfo *DestroyedTypeInfo
9613  = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
9614  ObjectType, nullptr, SS);
9615  if (!DestroyedTypeInfo)
9616  return ExprError();
9617  Destroyed = DestroyedTypeInfo;
9618  } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
9619  // We aren't likely to be able to resolve the identifier down to a type
9620  // now anyway, so just retain the identifier.
9621  Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9622  E->getDestroyedTypeLoc());
9623  } else {
9624  // Look for a destructor known with the given name.
9625  ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
9626  *E->getDestroyedTypeIdentifier(),
9627  E->getDestroyedTypeLoc(),
9628  /*Scope=*/nullptr,
9629  SS, ObjectTypePtr,
9630  false);
9631  if (!T)
9632  return ExprError();
9633 
9634  Destroyed
9635  = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9636  E->getDestroyedTypeLoc());
9637  }
9638 
9639  TypeSourceInfo *ScopeTypeInfo = nullptr;
9640  if (E->getScopeTypeInfo()) {
9641  CXXScopeSpec EmptySS;
9642  ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
9643  E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
9644  if (!ScopeTypeInfo)
9645  return ExprError();
9646  }
9647 
9648  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
9649  E->getOperatorLoc(),
9650  E->isArrow(),
9651  SS,
9652  ScopeTypeInfo,
9653  E->getColonColonLoc(),
9654  E->getTildeLoc(),
9655  Destroyed);
9656 }
9657 
9658 template<typename Derived>
9659 ExprResult
9660 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
9661  UnresolvedLookupExpr *Old) {
9662  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9664 
9665  // Transform all the decls.
9666  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9667  E = Old->decls_end(); I != E; ++I) {
9668  NamedDecl *InstD = static_cast<NamedDecl*>(
9669  getDerived().TransformDecl(Old->getNameLoc(),
9670  *I));
9671  if (!InstD) {
9672  // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9673  // This can happen because of dependent hiding.
9674  if (isa<UsingShadowDecl>(*I))
9675  continue;
9676  else {
9677  R.clear();
9678  return ExprError();
9679  }
9680  }
9681 
9682  // Expand using declarations.
9683  if (isa<UsingDecl>(InstD)) {
9684  UsingDecl *UD = cast<UsingDecl>(InstD);
9685  for (auto *I : UD->shadows())
9686  R.addDecl(I);
9687  continue;
9688  }
9689 
9690  R.addDecl(InstD);
9691  }
9692 
9693  // Resolve a kind, but don't do any further analysis. If it's
9694  // ambiguous, the callee needs to deal with it.
9695  R.resolveKind();
9696 
9697  // Rebuild the nested-name qualifier, if present.
9698  CXXScopeSpec SS;
9699  if (Old->getQualifierLoc()) {
9700  NestedNameSpecifierLoc QualifierLoc
9701  = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9702  if (!QualifierLoc)
9703  return ExprError();
9704 
9705  SS.Adopt(QualifierLoc);
9706  }
9707 
9708  if (Old->getNamingClass()) {
9709  CXXRecordDecl *NamingClass
9710  = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9711  Old->getNameLoc(),
9712  Old->getNamingClass()));
9713  if (!NamingClass) {
9714  R.clear();
9715  return ExprError();
9716  }
9717 
9718  R.setNamingClass(NamingClass);
9719  }
9720 
9721  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9722 
9723  // If we have neither explicit template arguments, nor the template keyword,
9724  // it's a normal declaration name or member reference.
9725  if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9726  NamedDecl *D = R.getAsSingle<NamedDecl>();
9727  // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9728  // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9729  // give a good diagnostic.
9730  if (D && D->isCXXInstanceMember()) {
9731  return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9732  /*TemplateArgs=*/nullptr,
9733  /*Scope=*/nullptr);
9734  }
9735 
9736  return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9737  }
9738 
9739  // If we have template arguments, rebuild them, then rebuild the
9740  // templateid expression.
9741  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
9742  if (Old->hasExplicitTemplateArgs() &&
9743  getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9744  Old->getNumTemplateArgs(),
9745  TransArgs)) {
9746  R.clear();
9747  return ExprError();
9748  }
9749 
9750  return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
9751  Old->requiresADL(), &TransArgs);
9752 }
9753 
9754 template<typename Derived>
9755 ExprResult
9756 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9757  bool ArgChanged = false;
9758  SmallVector<TypeSourceInfo *, 4> Args;
9759  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9760  TypeSourceInfo *From = E->getArg(I);
9761  TypeLoc FromTL = From->getTypeLoc();
9762  if (!FromTL.getAs<PackExpansionTypeLoc>()) {
9763  TypeLocBuilder TLB;
9764  TLB.reserve(FromTL.getFullDataSize());
9765  QualType To = getDerived().TransformType(TLB, FromTL);
9766  if (To.isNull())
9767  return ExprError();
9768 
9769  if (To == From->getType())
9770  Args.push_back(From);
9771  else {
9772  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9773  ArgChanged = true;
9774  }
9775  continue;
9776  }
9777 
9778  ArgChanged = true;
9779 
9780  // We have a pack expansion. Instantiate it.
9781  PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
9782  TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9783  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9784  SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
9785 
9786  // Determine whether the set of unexpanded parameter packs can and should
9787  // be expanded.
9788  bool Expand = true;
9789  bool RetainExpansion = false;
9790  Optional<unsigned> OrigNumExpansions =
9791  ExpansionTL.getTypePtr()->getNumExpansions();
9792  Optional<unsigned> NumExpansions = OrigNumExpansions;
9793  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9794  PatternTL.getSourceRange(),
9795  Unexpanded,
9796  Expand, RetainExpansion,
9797  NumExpansions))
9798  return ExprError();
9799 
9800  if (!Expand) {
9801  // The transform has determined that we should perform a simple
9802  // transformation on the pack expansion, producing another pack
9803  // expansion.
9804  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9805 
9806  TypeLocBuilder TLB;
9807  TLB.reserve(From->getTypeLoc().getFullDataSize());
9808 
9809  QualType To = getDerived().TransformType(TLB, PatternTL);
9810  if (To.isNull())
9811  return ExprError();
9812 
9813  To = getDerived().RebuildPackExpansionType(To,
9814  PatternTL.getSourceRange(),
9815  ExpansionTL.getEllipsisLoc(),
9816  NumExpansions);
9817  if (To.isNull())
9818  return ExprError();
9819 
9820  PackExpansionTypeLoc ToExpansionTL
9821  = TLB.push<PackExpansionTypeLoc>(To);
9822  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9823  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9824  continue;
9825  }
9826 
9827  // Expand the pack expansion by substituting for each argument in the
9828  // pack(s).
9829  for (unsigned I = 0; I != *NumExpansions; ++I) {
9830  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9831  TypeLocBuilder TLB;
9832  TLB.reserve(PatternTL.getFullDataSize());
9833  QualType To = getDerived().TransformType(TLB, PatternTL);
9834  if (To.isNull())
9835  return ExprError();
9836 
9837  if (To->containsUnexpandedParameterPack()) {
9838  To = getDerived().RebuildPackExpansionType(To,
9839  PatternTL.getSourceRange(),
9840  ExpansionTL.getEllipsisLoc(),
9841  NumExpansions);
9842  if (To.isNull())
9843  return ExprError();
9844 
9845  PackExpansionTypeLoc ToExpansionTL
9846  = TLB.push<PackExpansionTypeLoc>(To);
9847  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9848  }
9849 
9850  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9851  }
9852 
9853  if (!RetainExpansion)
9854  continue;
9855 
9856  // If we're supposed to retain a pack expansion, do so by temporarily
9857  // forgetting the partially-substituted parameter pack.
9858  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9859 
9860  TypeLocBuilder TLB;
9861  TLB.reserve(From->getTypeLoc().getFullDataSize());
9862 
9863  QualType To = getDerived().TransformType(TLB, PatternTL);
9864  if (To.isNull())
9865  return ExprError();
9866 
9867  To = getDerived().RebuildPackExpansionType(To,
9868  PatternTL.getSourceRange(),
9869  ExpansionTL.getEllipsisLoc(),
9870  NumExpansions);
9871  if (To.isNull())
9872  return ExprError();
9873 
9874  PackExpansionTypeLoc ToExpansionTL
9875  = TLB.push<PackExpansionTypeLoc>(To);
9876  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9877  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9878  }
9879 
9880  if (!getDerived().AlwaysRebuild() && !ArgChanged)
9881  return E;
9882 
9883  return getDerived().RebuildTypeTrait(E->getTrait(),
9884  E->getLocStart(),
9885  Args,
9886  E->getLocEnd());
9887 }
9888 
9889 template<typename Derived>
9890 ExprResult
9891 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9892  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9893  if (!T)
9894  return ExprError();
9895 
9896  if (!getDerived().AlwaysRebuild() &&
9897  T == E->getQueriedTypeSourceInfo())
9898  return E;
9899 
9900  ExprResult SubExpr;
9901  {
9902  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9903  SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9904  if (SubExpr.isInvalid())
9905  return ExprError();
9906 
9907  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
9908  return E;
9909  }
9910 
9911  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9912  E->getLocStart(),
9913  T,
9914  SubExpr.get(),
9915  E->getLocEnd());
9916 }
9917 
9918 template<typename Derived>
9919 ExprResult
9920 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9921  ExprResult SubExpr;
9922  {
9923  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9924  SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9925  if (SubExpr.isInvalid())
9926  return ExprError();
9927 
9928  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
9929  return E;
9930  }
9931 
9932  return getDerived().RebuildExpressionTrait(
9933  E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9934 }
9935 
9936 template <typename Derived>
9938  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9939  TypeSourceInfo **RecoveryTSI) {
9940  ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9941  DRE, AddrTaken, RecoveryTSI);
9942 
9943  // Propagate both errors and recovered types, which return ExprEmpty.
9944  if (!NewDRE.isUsable())
9945  return NewDRE;
9946 
9947  // We got an expr, wrap it up in parens.
9948  if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9949  return PE;
9950  return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9951  PE->getRParen());
9952 }
9953 
9954 template <typename Derived>
9957  return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9958  nullptr);
9959 }
9960 
9961 template<typename Derived>
9962 ExprResult
9965  bool IsAddressOfOperand,
9966  TypeSourceInfo **RecoveryTSI) {
9967  assert(E->getQualifierLoc());
9968  NestedNameSpecifierLoc QualifierLoc
9969  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9970  if (!QualifierLoc)
9971  return ExprError();
9972  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9973 
9974  // TODO: If this is a conversion-function-id, verify that the
9975  // destination type name (if present) resolves the same way after
9976  // instantiation as it did in the local scope.
9977 
9978  DeclarationNameInfo NameInfo
9979  = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9980  if (!NameInfo.getName())
9981  return ExprError();
9982 
9983  if (!E->hasExplicitTemplateArgs()) {
9984  if (!getDerived().AlwaysRebuild() &&
9985  QualifierLoc == E->getQualifierLoc() &&
9986  // Note: it is sufficient to compare the Name component of NameInfo:
9987  // if name has not changed, DNLoc has not changed either.
9988  NameInfo.getName() == E->getDeclName())
9989  return E;
9990 
9991  return getDerived().RebuildDependentScopeDeclRefExpr(
9992  QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9993  IsAddressOfOperand, RecoveryTSI);
9994  }
9995 
9996  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
9997  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9998  E->getNumTemplateArgs(),
9999  TransArgs))
10000  return ExprError();
10001 
10002  return getDerived().RebuildDependentScopeDeclRefExpr(
10003  QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10004  RecoveryTSI);
10005 }
10006 
10007 template<typename Derived>
10008 ExprResult
10009 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
10010  // CXXConstructExprs other than for list-initialization and
10011  // CXXTemporaryObjectExpr are always implicit, so when we have
10012  // a 1-argument construction we just transform that argument.
10013  if ((E->getNumArgs() == 1 ||
10014  (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
10015  (!getDerived().DropCallArgument(E->getArg(0))) &&
10016  !E->isListInitialization())
10017  return getDerived().TransformExpr(E->getArg(0));
10018 
10019  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10020 
10021  QualType T = getDerived().TransformType(E->getType());
10022  if (T.isNull())
10023  return ExprError();
10024 
10025  CXXConstructorDecl *Constructor
10026  = cast_or_null<CXXConstructorDecl>(
10027  getDerived().TransformDecl(E->getLocStart(),
10028  E->getConstructor()));
10029  if (!Constructor)
10030  return ExprError();
10031 
10032  bool ArgumentChanged = false;
10033  SmallVector<Expr*, 8> Args;
10034  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10035  &ArgumentChanged))
10036  return ExprError();
10037 
10038  if (!getDerived().AlwaysRebuild() &&
10039  T == E->getType() &&
10040  Constructor == E->getConstructor() &&
10041  !ArgumentChanged) {
10042  // Mark the constructor as referenced.
10043  // FIXME: Instantiation-specific
10044  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10045  return E;
10046  }
10047 
10048  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
10049  Constructor,
10050  E->isElidable(), Args,
10051  E->hadMultipleCandidates(),
10052  E->isListInitialization(),
10053  E->isStdInitListInitialization(),
10054  E->requiresZeroInitialization(),
10055  E->getConstructionKind(),
10056  E->getParenOrBraceRange());
10057 }
10058 
10059 template<typename Derived>
10060 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10061  CXXInheritedCtorInitExpr *E) {
10062  QualType T = getDerived().TransformType(E->getType());
10063  if (T.isNull())
10064  return ExprError();
10065 
10066  CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10067  getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10068  if (!Constructor)
10069  return ExprError();
10070 
10071  if (!getDerived().AlwaysRebuild() &&
10072  T == E->getType() &&
10073  Constructor == E->getConstructor()) {
10074  // Mark the constructor as referenced.
10075  // FIXME: Instantiation-specific
10076  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10077  return E;
10078  }
10079 
10080  return getDerived().RebuildCXXInheritedCtorInitExpr(
10081  T, E->getLocation(), Constructor,
10082  E->constructsVBase(), E->inheritedFromVBase());
10083 }
10084 
10085 /// \brief Transform a C++ temporary-binding expression.
10086 ///
10087 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10088 /// transform the subexpression and return that.
10089 template<typename Derived>
10090 ExprResult
10091 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
10092  return getDerived().TransformExpr(E->getSubExpr());
10093 }
10094 
10095 /// \brief Transform a C++ expression that contains cleanups that should
10096 /// be run after the expression is evaluated.
10097 ///
10098 /// Since ExprWithCleanups nodes are implicitly generated, we
10099 /// just transform the subexpression and return that.
10100 template<typename Derived>
10101 ExprResult
10102 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
10103  return getDerived().TransformExpr(E->getSubExpr());
10104 }
10105 
10106 template<typename Derived>
10107 ExprResult
10108 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
10109  CXXTemporaryObjectExpr *E) {
10110  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10111  if (!T)
10112  return ExprError();
10113 
10114  CXXConstructorDecl *Constructor
10115  = cast_or_null<CXXConstructorDecl>(
10116  getDerived().TransformDecl(E->getLocStart(),
10117  E->getConstructor()));
10118  if (!Constructor)
10119  return ExprError();
10120 
10121  bool ArgumentChanged = false;
10122  SmallVector<Expr*, 8> Args;
10123  Args.reserve(E->getNumArgs());
10124  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10125  &ArgumentChanged))
10126  return ExprError();
10127 
10128  if (!getDerived().AlwaysRebuild() &&
10129  T == E->getTypeSourceInfo() &&
10130  Constructor == E->getConstructor() &&
10131  !ArgumentChanged) {
10132  // FIXME: Instantiation-specific
10133  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10134  return SemaRef.MaybeBindToTemporary(E);
10135  }
10136 
10137  // FIXME: Pass in E->isListInitialization().
10138  return getDerived().RebuildCXXTemporaryObjectExpr(T,
10139  /*FIXME:*/T->getTypeLoc().getEndLoc(),
10140  Args,
10141  E->getLocEnd());
10142 }
10143 
10144 template<typename Derived>
10145 ExprResult
10146 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
10147  // Transform any init-capture expressions before entering the scope of the
10148  // lambda body, because they are not semantically within that scope.
10149  typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
10150  SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10151  InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
10152  E->explicit_capture_begin());
10153  for (LambdaExpr::capture_iterator C = E->capture_begin(),
10154  CEnd = E->capture_end();
10155  C != CEnd; ++C) {
10156  if (!E->isInitCapture(C))
10157  continue;
10158  EnterExpressionEvaluationContext EEEC(getSema(),
10160  ExprResult NewExprInitResult = getDerived().TransformInitializer(
10161  C->getCapturedVar()->getInit(),
10162  C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
10163 
10164  if (NewExprInitResult.isInvalid())
10165  return ExprError();
10166  Expr *NewExprInit = NewExprInitResult.get();
10167 
10168  VarDecl *OldVD = C->getCapturedVar();
10169  QualType NewInitCaptureType =
10170  getSema().buildLambdaInitCaptureInitialization(
10171  C->getLocation(), OldVD->getType()->isReferenceType(),
10172  OldVD->getIdentifier(),
10173  C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
10174  NewExprInitResult = NewExprInit;
10175  InitCaptureExprsAndTypes[C - E->capture_begin()] =
10176  std::make_pair(NewExprInitResult, NewInitCaptureType);
10177  }
10178 
10179  // Transform the template parameters, and add them to the current
10180  // instantiation scope. The null case is handled correctly.
10181  auto TPL = getDerived().TransformTemplateParameterList(
10182  E->getTemplateParameterList());
10183 
10184  // Transform the type of the original lambda's call operator.
10185  // The transformation MUST be done in the CurrentInstantiationScope since
10186  // it introduces a mapping of the original to the newly created
10187  // transformed parameters.
10188  TypeSourceInfo *NewCallOpTSI = nullptr;
10189  {
10190  TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10191  FunctionProtoTypeLoc OldCallOpFPTL =
10192  OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
10193 
10194  TypeLocBuilder NewCallOpTLBuilder;
10195  SmallVector<QualType, 4> ExceptionStorage;
10196  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
10197  QualType NewCallOpType = TransformFunctionProtoType(
10198  NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
10199  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10200  return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10201  ExceptionStorage, Changed);
10202  });
10203  if (NewCallOpType.isNull())
10204  return ExprError();
10205  NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10206  NewCallOpType);
10207  }
10208 
10209  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10210  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10211  LSI->GLTemplateParameterList = TPL;
10212 
10213  // Create the local class that will describe the lambda.
10214  CXXRecordDecl *Class
10215  = getSema().createLambdaClosureType(E->getIntroducerRange(),
10216  NewCallOpTSI,
10217  /*KnownDependent=*/false,
10218  E->getCaptureDefault());
10219  getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10220 
10221  // Build the call operator.
10222  CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10223  Class, E->getIntroducerRange(), NewCallOpTSI,
10224  E->getCallOperator()->getLocEnd(),
10225  NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
10226  LSI->CallOperator = NewCallOperator;
10227 
10228  getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
10229  getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
10230 
10231  // Introduce the context of the call operator.
10232  Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
10233  /*NewThisContext*/false);
10234 
10235  // Enter the scope of the lambda.
10236  getSema().buildLambdaScope(LSI, NewCallOperator,
10237  E->getIntroducerRange(),
10238  E->getCaptureDefault(),
10239  E->getCaptureDefaultLoc(),
10240  E->hasExplicitParameters(),
10241  E->hasExplicitResultType(),
10242  E->isMutable());
10243 
10244  bool Invalid = false;
10245 
10246  // Transform captures.
10247  bool FinishedExplicitCaptures = false;
10248  for (LambdaExpr::capture_iterator C = E->capture_begin(),
10249  CEnd = E->capture_end();
10250  C != CEnd; ++C) {
10251  // When we hit the first implicit capture, tell Sema that we've finished
10252  // the list of explicit captures.
10253  if (!FinishedExplicitCaptures && C->isImplicit()) {
10254  getSema().finishLambdaExplicitCaptures(LSI);
10255  FinishedExplicitCaptures = true;
10256  }
10257 
10258  // Capturing 'this' is trivial.
10259  if (C->capturesThis()) {
10260  getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10261  /*BuildAndDiagnose*/ true, nullptr,
10262  C->getCaptureKind() == LCK_StarThis);
10263  continue;
10264  }
10265  // Captured expression will be recaptured during captured variables
10266  // rebuilding.
10267  if (C->capturesVLAType())
10268  continue;
10269 
10270  // Rebuild init-captures, including the implied field declaration.
10271  if (E->isInitCapture(C)) {
10272  InitCaptureInfoTy InitExprTypePair =
10273  InitCaptureExprsAndTypes[C - E->capture_begin()];
10274  ExprResult Init = InitExprTypePair.first;
10275  QualType InitQualType = InitExprTypePair.second;
10276  if (Init.isInvalid() || InitQualType.isNull()) {
10277  Invalid = true;
10278  continue;
10279  }
10280  VarDecl *OldVD = C->getCapturedVar();
10281  VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
10282  OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10283  OldVD->getInitStyle(), Init.get());
10284  if (!NewVD)
10285  Invalid = true;
10286  else {
10287  getDerived().transformedLocalDecl(OldVD, NewVD);
10288  }
10289  getSema().buildInitCaptureField(LSI, NewVD);
10290  continue;
10291  }
10292 
10293  assert(C->capturesVariable() && "unexpected kind of lambda capture");
10294 
10295  // Determine the capture kind for Sema.
10297  = C->isImplicit()? Sema::TryCapture_Implicit
10298  : C->getCaptureKind() == LCK_ByCopy
10301  SourceLocation EllipsisLoc;
10302  if (C->isPackExpansion()) {
10303  UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10304  bool ShouldExpand = false;
10305  bool RetainExpansion = false;
10306  Optional<unsigned> NumExpansions;
10307  if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10308  C->getLocation(),
10309  Unexpanded,
10310  ShouldExpand, RetainExpansion,
10311  NumExpansions)) {
10312  Invalid = true;
10313  continue;
10314  }
10315 
10316  if (ShouldExpand) {
10317  // The transform has determined that we should perform an expansion;
10318  // transform and capture each of the arguments.
10319  // expansion of the pattern. Do so.
10320  VarDecl *Pack = C->getCapturedVar();
10321  for (unsigned I = 0; I != *NumExpansions; ++I) {
10322  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10323  VarDecl *CapturedVar
10324  = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10325  Pack));
10326  if (!CapturedVar) {
10327  Invalid = true;
10328  continue;
10329  }
10330 
10331  // Capture the transformed variable.
10332  getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10333  }
10334 
10335  // FIXME: Retain a pack expansion if RetainExpansion is true.
10336 
10337  continue;
10338  }
10339 
10340  EllipsisLoc = C->getEllipsisLoc();
10341  }
10342 
10343  // Transform the captured variable.
10344  VarDecl *CapturedVar
10345  = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10346  C->getCapturedVar()));
10347  if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10348  Invalid = true;
10349  continue;
10350  }
10351 
10352  // Capture the transformed variable.
10353  getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10354  EllipsisLoc);
10355  }
10356  if (!FinishedExplicitCaptures)
10357  getSema().finishLambdaExplicitCaptures(LSI);
10358 
10359  // Enter a new evaluation context to insulate the lambda from any
10360  // cleanups from the enclosing full-expression.
10361  getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
10362 
10363  // Instantiate the body of the lambda expression.
10364  StmtResult Body =
10365  Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10366 
10367  // ActOnLambda* will pop the function scope for us.
10368  FuncScopeCleanup.disable();
10369 
10370  if (Body.isInvalid()) {
10371  SavedContext.pop();
10372  getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
10373  /*IsInstantiation=*/true);
10374  return ExprError();
10375  }
10376 
10377  // Copy the LSI before ActOnFinishFunctionBody removes it.
10378  // FIXME: This is dumb. Store the lambda information somewhere that outlives
10379  // the call operator.
10380  auto LSICopy = *LSI;
10381  getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10382  /*IsInstantiation*/ true);
10383  SavedContext.pop();
10384 
10385  return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10386  &LSICopy);
10387 }
10388 
10389 template<typename Derived>
10390 ExprResult
10391 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
10392  CXXUnresolvedConstructExpr *E) {
10393  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10394  if (!T)
10395  return ExprError();
10396 
10397  bool ArgumentChanged = false;
10398  SmallVector<Expr*, 8> Args;
10399  Args.reserve(E->arg_size());
10400  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
10401  &ArgumentChanged))
10402  return ExprError();
10403 
10404  if (!getDerived().AlwaysRebuild() &&
10405  T == E->getTypeSourceInfo() &&
10406  !ArgumentChanged)
10407  return E;
10408 
10409  // FIXME: we're faking the locations of the commas
10410  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
10411  E->getLParenLoc(),
10412  Args,
10413  E->getRParenLoc());
10414 }
10415 
10416 template<typename Derived>
10417 ExprResult
10418 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
10419  CXXDependentScopeMemberExpr *E) {
10420  // Transform the base of the expression.
10421  ExprResult Base((Expr*) nullptr);
10422  Expr *OldBase;
10423  QualType BaseType;
10424  QualType ObjectType;
10425  if (!E->isImplicitAccess()) {
10426  OldBase = E->getBase();
10427  Base = getDerived().TransformExpr(OldBase);
10428  if (Base.isInvalid())
10429  return ExprError();
10430 
10431  // Start the member reference and compute the object's type.
10432  ParsedType ObjectTy;
10433  bool MayBePseudoDestructor = false;
10434  Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10435  E->getOperatorLoc(),
10436  E->isArrow()? tok::arrow : tok::period,
10437  ObjectTy,
10438  MayBePseudoDestructor);
10439  if (Base.isInvalid())
10440  return ExprError();
10441 
10442  ObjectType = ObjectTy.get();
10443  BaseType = ((Expr*) Base.get())->getType();
10444  } else {
10445  OldBase = nullptr;
10446  BaseType = getDerived().TransformType(E->getBaseType());
10447  ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10448  }
10449 
10450  // Transform the first part of the nested-name-specifier that qualifies
10451  // the member name.
10452  NamedDecl *FirstQualifierInScope
10453  = getDerived().TransformFirstQualifierInScope(
10454  E->getFirstQualifierFoundInScope(),
10455  E->getQualifierLoc().getBeginLoc());
10456 
10457  NestedNameSpecifierLoc QualifierLoc;
10458  if (E->getQualifier()) {
10459  QualifierLoc
10460  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10461  ObjectType,
10462  FirstQualifierInScope);
10463  if (!QualifierLoc)
10464  return ExprError();
10465  }
10466 
10467  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10468 
10469  // TODO: If this is a conversion-function-id, verify that the
10470  // destination type name (if present) resolves the same way after
10471  // instantiation as it did in the local scope.
10472 
10473  DeclarationNameInfo NameInfo
10474  = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
10475  if (!NameInfo.getName())
10476  return ExprError();
10477 
10478  if (!E->hasExplicitTemplateArgs()) {
10479  // This is a reference to a member without an explicitly-specified
10480  // template argument list. Optimize for this common case.
10481  if (!getDerived().AlwaysRebuild() &&
10482  Base.get() == OldBase &&
10483  BaseType == E->getBaseType() &&
10484  QualifierLoc == E->getQualifierLoc() &&
10485  NameInfo.getName() == E->getMember() &&
10486  FirstQualifierInScope == E->getFirstQualifierFoundInScope())
10487  return E;
10488 
10489  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10490  BaseType,
10491  E->isArrow(),
10492  E->getOperatorLoc(),
10493  QualifierLoc,
10494  TemplateKWLoc,
10495  FirstQualifierInScope,
10496  NameInfo,
10497  /*TemplateArgs*/nullptr);
10498  }
10499 
10500  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10501  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10502  E->getNumTemplateArgs(),
10503  TransArgs))
10504  return ExprError();
10505 
10506  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10507  BaseType,
10508  E->isArrow(),
10509  E->getOperatorLoc(),
10510  QualifierLoc,
10511  TemplateKWLoc,
10512  FirstQualifierInScope,
10513  NameInfo,
10514  &TransArgs);
10515 }
10516 
10517 template<typename Derived>
10518 ExprResult
10519 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
10520  // Transform the base of the expression.
10521  ExprResult Base((Expr*) nullptr);
10522  QualType BaseType;
10523  if (!Old->isImplicitAccess()) {
10524  Base = getDerived().TransformExpr(Old->getBase());
10525  if (Base.isInvalid())
10526  return ExprError();
10527  Base = getSema().PerformMemberExprBaseConversion(Base.get(),
10528  Old->isArrow());
10529  if (Base.isInvalid())
10530  return ExprError();
10531  BaseType = Base.get()->getType();
10532  } else {
10533  BaseType = getDerived().TransformType(Old->getBaseType());
10534  }
10535 
10536  NestedNameSpecifierLoc QualifierLoc;
10537  if (Old->getQualifierLoc()) {
10538  QualifierLoc
10539  = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10540  if (!QualifierLoc)
10541  return ExprError();
10542  }
10543 
10544  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10545 
10546  LookupResult R(SemaRef, Old->getMemberNameInfo(),
10548 
10549  // Transform all the decls.
10550  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10551  E = Old->decls_end(); I != E; ++I) {
10552  NamedDecl *InstD = static_cast<NamedDecl*>(
10553  getDerived().TransformDecl(Old->getMemberLoc(),
10554  *I));
10555  if (!InstD) {
10556  // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10557  // This can happen because of dependent hiding.
10558  if (isa<UsingShadowDecl>(*I))
10559  continue;
10560  else {
10561  R.clear();
10562  return ExprError();
10563  }
10564  }
10565 
10566  // Expand using declarations.
10567  if (isa<UsingDecl>(InstD)) {
10568  UsingDecl *UD = cast<UsingDecl>(InstD);
10569  for (auto *I : UD->shadows())
10570  R.addDecl(I);
10571  continue;
10572  }
10573 
10574  R.addDecl(InstD);
10575  }
10576 
10577  R.resolveKind();
10578 
10579  // Determine the naming class.
10580  if (Old->getNamingClass()) {
10581  CXXRecordDecl *NamingClass
10582  = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10583  Old->getMemberLoc(),
10584  Old->getNamingClass()));
10585  if (!NamingClass)
10586  return ExprError();
10587 
10588  R.setNamingClass(NamingClass);
10589  }
10590 
10591  TemplateArgumentListInfo TransArgs;
10592  if (Old->hasExplicitTemplateArgs()) {
10593  TransArgs.setLAngleLoc(Old->getLAngleLoc());
10594  TransArgs.setRAngleLoc(Old->getRAngleLoc());
10595  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10596  Old->getNumTemplateArgs(),
10597  TransArgs))
10598  return ExprError();
10599  }
10600 
10601  // FIXME: to do this check properly, we will need to preserve the
10602  // first-qualifier-in-scope here, just in case we had a dependent
10603  // base (and therefore couldn't do the check) and a
10604  // nested-name-qualifier (and therefore could do the lookup).
10605  NamedDecl *FirstQualifierInScope = nullptr;
10606 
10607  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
10608  BaseType,
10609  Old->getOperatorLoc(),
10610  Old->isArrow(),
10611  QualifierLoc,
10612  TemplateKWLoc,
10613  FirstQualifierInScope,
10614  R,
10615  (Old->hasExplicitTemplateArgs()
10616  ? &TransArgs : nullptr));
10617 }
10618 
10619 template<typename Derived>
10620 ExprResult
10621 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
10622  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10623  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10624  if (SubExpr.isInvalid())
10625  return ExprError();
10626 
10627  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
10628  return E;
10629 
10630  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10631 }
10632 
10633 template<typename Derived>
10634 ExprResult
10635 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
10636  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10637  if (Pattern.isInvalid())
10638  return ExprError();
10639 
10640  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
10641  return E;
10642 
10643  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10644  E->getNumExpansions());
10645 }
10646 
10647 template<typename Derived>
10648 ExprResult
10649 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10650  // If E is not value-dependent, then nothing will change when we transform it.
10651  // Note: This is an instantiation-centric view.
10652  if (!E->isValueDependent())
10653  return E;
10654 
10655  EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
10656 
10657  ArrayRef<TemplateArgument> PackArgs;
10658  TemplateArgument ArgStorage;
10659 
10660  // Find the argument list to transform.
10661  if (E->isPartiallySubstituted()) {
10662  PackArgs = E->getPartialArguments();
10663  } else if (E->isValueDependent()) {
10664  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10665  bool ShouldExpand = false;
10666  bool RetainExpansion = false;
10667  Optional<unsigned> NumExpansions;
10668  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10669  Unexpanded,
10670  ShouldExpand, RetainExpansion,
10671  NumExpansions))
10672  return ExprError();
10673 
10674  // If we need to expand the pack, build a template argument from it and
10675  // expand that.
10676  if (ShouldExpand) {
10677  auto *Pack = E->getPack();
10678  if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10679  ArgStorage = getSema().Context.getPackExpansionType(
10680  getSema().Context.getTypeDeclType(TTPD), None);
10681  } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10682  ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10683  } else {
10684  auto *VD = cast<ValueDecl>(Pack);
10685  ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10686  VK_RValue, E->getPackLoc());
10687  if (DRE.isInvalid())
10688  return ExprError();
10689  ArgStorage = new (getSema().Context) PackExpansionExpr(
10690  getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10691  }
10692  PackArgs = ArgStorage;
10693  }
10694  }
10695 
10696  // If we're not expanding the pack, just transform the decl.
10697  if (!PackArgs.size()) {
10698  auto *Pack = cast_or_null<NamedDecl>(
10699  getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
10700  if (!Pack)
10701  return ExprError();
10702  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10703  E->getPackLoc(),
10704  E->getRParenLoc(), None, None);
10705  }
10706 
10707  TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10708  E->getPackLoc());
10709  {
10710  TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10711  typedef TemplateArgumentLocInventIterator<
10712  Derived, const TemplateArgument*> PackLocIterator;
10713  if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10714  PackLocIterator(*this, PackArgs.end()),
10715  TransformedPackArgs, /*Uneval*/true))
10716  return ExprError();
10717  }
10718 
10719  SmallVector<TemplateArgument, 8> Args;
10720  bool PartialSubstitution = false;
10721  for (auto &Loc : TransformedPackArgs.arguments()) {
10722  Args.push_back(Loc.getArgument());
10723  if (Loc.getArgument().isPackExpansion())
10724  PartialSubstitution = true;
10725  }
10726 
10727  if (PartialSubstitution)
10728  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10729  E->getPackLoc(),
10730  E->getRParenLoc(), None, Args);
10731 
10732  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10733  E->getPackLoc(), E->getRParenLoc(),
10734  Args.size(), None);
10735 }
10736 
10737 template<typename Derived>
10738 ExprResult
10739 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10740  SubstNonTypeTemplateParmPackExpr *E) {
10741  // Default behavior is to do nothing with this transformation.
10742  return E;
10743 }
10744 
10745 template<typename Derived>
10746 ExprResult
10747 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10748  SubstNonTypeTemplateParmExpr *E) {
10749  // Default behavior is to do nothing with this transformation.
10750  return E;
10751 }
10752 
10753 template<typename Derived>
10754 ExprResult
10755 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10756  // Default behavior is to do nothing with this transformation.
10757  return E;
10758 }
10759 
10760 template<typename Derived>
10761 ExprResult
10762 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10763  MaterializeTemporaryExpr *E) {
10764  return getDerived().TransformExpr(E->GetTemporaryExpr());
10765 }
10766 
10767 template<typename Derived>
10768 ExprResult
10769 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10770  Expr *Pattern = E->getPattern();
10771 
10772  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10773  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10774  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10775 
10776  // Determine whether the set of unexpanded parameter packs can and should
10777  // be expanded.
10778  bool Expand = true;
10779  bool RetainExpansion = false;
10780  Optional<unsigned> NumExpansions;
10781  if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10782  Pattern->getSourceRange(),
10783  Unexpanded,
10784  Expand, RetainExpansion,
10785  NumExpansions))
10786  return true;
10787 
10788  if (!Expand) {
10789  // Do not expand any packs here, just transform and rebuild a fold
10790  // expression.
10791  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10792 
10793  ExprResult LHS =
10794  E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10795  if (LHS.isInvalid())
10796  return true;
10797 
10798  ExprResult RHS =
10799  E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10800  if (RHS.isInvalid())
10801  return true;
10802 
10803  if (!getDerived().AlwaysRebuild() &&
10804  LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10805  return E;
10806 
10807  return getDerived().RebuildCXXFoldExpr(
10808  E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10809  RHS.get(), E->getLocEnd());
10810  }
10811 
10812  // The transform has determined that we should perform an elementwise
10813  // expansion of the pattern. Do so.
10814  ExprResult Result = getDerived().TransformExpr(E->getInit());
10815  if (Result.isInvalid())
10816  return true;
10817  bool LeftFold = E->isLeftFold();
10818 
10819  // If we're retaining an expansion for a right fold, it is the innermost
10820  // component and takes the init (if any).
10821  if (!LeftFold && RetainExpansion) {
10822  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10823 
10824  ExprResult Out = getDerived().TransformExpr(Pattern);
10825  if (Out.isInvalid())
10826  return true;
10827 
10828  Result = getDerived().RebuildCXXFoldExpr(
10829  E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10830  Result.get(), E->getLocEnd());
10831  if (Result.isInvalid())
10832  return true;
10833  }
10834 
10835  for (unsigned I = 0; I != *NumExpansions; ++I) {
10836  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10837  getSema(), LeftFold ? I : *NumExpansions - I - 1);
10838  ExprResult Out = getDerived().TransformExpr(Pattern);
10839  if (Out.isInvalid())
10840  return true;
10841 
10842  if (Out.get()->containsUnexpandedParameterPack()) {
10843  // We still have a pack; retain a pack expansion for this slice.
10844  Result = getDerived().RebuildCXXFoldExpr(
10845  E->getLocStart(),
10846  LeftFold ? Result.get() : Out.get(),
10847  E->getOperator(), E->getEllipsisLoc(),
10848  LeftFold ? Out.get() : Result.get(),
10849  E->getLocEnd());
10850  } else if (Result.isUsable()) {
10851  // We've got down to a single element; build a binary operator.
10852  Result = getDerived().RebuildBinaryOperator(
10853  E->getEllipsisLoc(), E->getOperator(),
10854  LeftFold ? Result.get() : Out.get(),
10855  LeftFold ? Out.get() : Result.get());
10856  } else
10857  Result = Out;
10858 
10859  if (Result.isInvalid())
10860  return true;
10861  }
10862 
10863  // If we're retaining an expansion for a left fold, it is the outermost
10864  // component and takes the complete expansion so far as its init (if any).
10865  if (LeftFold && RetainExpansion) {
10866  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10867 
10868  ExprResult Out = getDerived().TransformExpr(Pattern);
10869  if (Out.isInvalid())
10870  return true;
10871 
10872  Result = getDerived().RebuildCXXFoldExpr(
10873  E->getLocStart(), Result.get(),
10874  E->getOperator(), E->getEllipsisLoc(),
10875  Out.get(), E->getLocEnd());
10876  if (Result.isInvalid())
10877  return true;
10878  }
10879 
10880  // If we had no init and an empty pack, and we're not retaining an expansion,
10881  // then produce a fallback value or error.
10882  if (Result.isUnset())
10883  return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10884  E->getOperator());
10885 
10886  return Result;
10887 }
10888 
10889 template<typename Derived>
10890 ExprResult
10891 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10892  CXXStdInitializerListExpr *E) {
10893  return getDerived().TransformExpr(E->getSubExpr());
10894 }
10895 
10896 template<typename Derived>
10897 ExprResult
10898 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
10899  return SemaRef.MaybeBindToTemporary(E);
10900 }
10901 
10902 template<typename Derived>
10903 ExprResult
10904 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
10905  return E;
10906 }
10907 
10908 template<typename Derived>
10909 ExprResult
10910 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10911  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10912  if (SubExpr.isInvalid())
10913  return ExprError();
10914 
10915  if (!getDerived().AlwaysRebuild() &&
10916  SubExpr.get() == E->getSubExpr())
10917  return E;
10918 
10919  return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
10920 }
10921 
10922 template<typename Derived>
10923 ExprResult
10924 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10925  // Transform each of the elements.
10926  SmallVector<Expr *, 8> Elements;
10927  bool ArgChanged = false;
10928  if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
10929  /*IsCall=*/false, Elements, &ArgChanged))
10930  return ExprError();
10931 
10932  if (!getDerived().AlwaysRebuild() && !ArgChanged)
10933  return SemaRef.MaybeBindToTemporary(E);
10934 
10935  return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10936  Elements.data(),
10937  Elements.size());
10938 }
10939 
10940 template<typename Derived>
10941 ExprResult
10942 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
10943  ObjCDictionaryLiteral *E) {
10944  // Transform each of the elements.
10945  SmallVector<ObjCDictionaryElement, 8> Elements;
10946  bool ArgChanged = false;
10947  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10948  ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
10949 
10950  if (OrigElement.isPackExpansion()) {
10951  // This key/value element is a pack expansion.
10952  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10953  getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10954  getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10955  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10956 
10957  // Determine whether the set of unexpanded parameter packs can
10958  // and should be expanded.
10959  bool Expand = true;
10960  bool RetainExpansion = false;
10961  Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10962  Optional<unsigned> NumExpansions = OrigNumExpansions;
10963  SourceRange PatternRange(OrigElement.Key->getLocStart(),
10964  OrigElement.Value->getLocEnd());
10965  if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10966  PatternRange,
10967  Unexpanded,
10968  Expand, RetainExpansion,
10969  NumExpansions))
10970  return ExprError();
10971 
10972  if (!Expand) {
10973  // The transform has determined that we should perform a simple
10974  // transformation on the pack expansion, producing another pack
10975  // expansion.
10976  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10977  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10978  if (Key.isInvalid())
10979  return ExprError();
10980 
10981  if (Key.get() != OrigElement.Key)
10982  ArgChanged = true;
10983 
10984  ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10985  if (Value.isInvalid())
10986  return ExprError();
10987 
10988  if (Value.get() != OrigElement.Value)
10989  ArgChanged = true;
10990 
10991  ObjCDictionaryElement Expansion = {
10992  Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10993  };
10994  Elements.push_back(Expansion);
10995  continue;
10996  }
10997 
10998  // Record right away that the argument was changed. This needs
10999  // to happen even if the array expands to nothing.
11000  ArgChanged = true;
11001 
11002  // The transform has determined that we should perform an elementwise
11003  // expansion of the pattern. Do so.
11004  for (unsigned I = 0; I != *NumExpansions; ++I) {
11005  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11006  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11007  if (Key.isInvalid())
11008  return ExprError();
11009 
11010  ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11011  if (Value.isInvalid())
11012  return ExprError();
11013 
11014  ObjCDictionaryElement Element = {
11015  Key.get(), Value.get(), SourceLocation(), NumExpansions
11016  };
11017 
11018  // If any unexpanded parameter packs remain, we still have a
11019  // pack expansion.
11020  // FIXME: Can this really happen?
11021  if (Key.get()->containsUnexpandedParameterPack() ||
11022  Value.get()->containsUnexpandedParameterPack())
11023  Element.EllipsisLoc = OrigElement.EllipsisLoc;
11024 
11025  Elements.push_back(Element);
11026  }
11027 
11028  // FIXME: Retain a pack expansion if RetainExpansion is true.
11029 
11030  // We've finished with this pack expansion.
11031  continue;
11032  }
11033 
11034  // Transform and check key.
11035  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11036  if (Key.isInvalid())
11037  return ExprError();
11038 
11039  if (Key.get() != OrigElement.Key)
11040  ArgChanged = true;
11041 
11042  // Transform and check value.
11043  ExprResult Value
11044  = getDerived().TransformExpr(OrigElement.Value);
11045  if (Value.isInvalid())
11046  return ExprError();
11047 
11048  if (Value.get() != OrigElement.Value)
11049  ArgChanged = true;
11050 
11051  ObjCDictionaryElement Element = {
11052  Key.get(), Value.get(), SourceLocation(), None
11053  };
11054  Elements.push_back(Element);
11055  }
11056 
11057  if (!getDerived().AlwaysRebuild() && !ArgChanged)
11058  return SemaRef.MaybeBindToTemporary(E);
11059 
11060  return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
11061  Elements);
11062 }
11063 
11064 template<typename Derived>
11065 ExprResult
11066 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
11067  TypeSourceInfo *EncodedTypeInfo
11068  = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11069  if (!EncodedTypeInfo)
11070  return ExprError();
11071 
11072  if (!getDerived().AlwaysRebuild() &&
11073  EncodedTypeInfo == E->getEncodedTypeSourceInfo())
11074  return E;
11075 
11076  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
11077  EncodedTypeInfo,
11078  E->getRParenLoc());
11079 }
11080 
11081 template<typename Derived>
11082 ExprResult TreeTransform<Derived>::
11083 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
11084  // This is a kind of implicit conversion, and it needs to get dropped
11085  // and recomputed for the same general reasons that ImplicitCastExprs
11086  // do, as well a more specific one: this expression is only valid when
11087  // it appears *immediately* as an argument expression.
11088  return getDerived().TransformExpr(E->getSubExpr());
11089 }
11090 
11091 template<typename Derived>
11092 ExprResult TreeTransform<Derived>::
11093 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
11094  TypeSourceInfo *TSInfo
11095  = getDerived().TransformType(E->getTypeInfoAsWritten());
11096  if (!TSInfo)
11097  return ExprError();
11098 
11099  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
11100  if (Result.isInvalid())
11101  return ExprError();
11102 
11103  if (!getDerived().AlwaysRebuild() &&
11104  TSInfo == E->getTypeInfoAsWritten() &&
11105  Result.get() == E->getSubExpr())
11106  return E;
11107 
11108  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
11109  E->getBridgeKeywordLoc(), TSInfo,
11110  Result.get());
11111 }
11112 
11113 template <typename Derived>
11114 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11115  ObjCAvailabilityCheckExpr *E) {
11116  return E;
11117 }
11118 
11119 template<typename Derived>
11120 ExprResult
11121 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
11122  // Transform arguments.
11123  bool ArgChanged = false;
11124  SmallVector<Expr*, 8> Args;
11125  Args.reserve(E->getNumArgs());
11126  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
11127  &ArgChanged))
11128  return ExprError();
11129 
11130  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11131  // Class message: transform the receiver type.
11132  TypeSourceInfo *ReceiverTypeInfo
11133  = getDerived().TransformType(E->getClassReceiverTypeInfo());
11134  if (!ReceiverTypeInfo)
11135  return ExprError();
11136 
11137  // If nothing changed, just retain the existing message send.
11138  if (!getDerived().AlwaysRebuild() &&
11139  ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
11140  return SemaRef.MaybeBindToTemporary(E);
11141 
11142  // Build a new class message send.
11143  SmallVector<SourceLocation, 16> SelLocs;
11144  E->getSelectorLocs(SelLocs);
11145  return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11146  E->getSelector(),
11147  SelLocs,
11148  E->getMethodDecl(),
11149  E->getLeftLoc(),
11150  Args,
11151  E->getRightLoc());
11152  }
11153  else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11154  E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
11155  // Build a new class message send to 'super'.
11156  SmallVector<SourceLocation, 16> SelLocs;
11157  E->getSelectorLocs(SelLocs);
11158  return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11159  E->getSelector(),
11160  SelLocs,
11161  E->getReceiverType(),
11162  E->getMethodDecl(),
11163  E->getLeftLoc(),
11164  Args,
11165  E->getRightLoc());
11166  }
11167 
11168  // Instance message: transform the receiver
11169  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11170  "Only class and instance messages may be instantiated");
11171  ExprResult Receiver
11172  = getDerived().TransformExpr(E->getInstanceReceiver());
11173  if (Receiver.isInvalid())
11174  return ExprError();
11175 
11176  // If nothing changed, just retain the existing message send.
11177  if (!getDerived().AlwaysRebuild() &&
11178  Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
11179  return SemaRef.MaybeBindToTemporary(E);
11180 
11181  // Build a new instance message send.
11182  SmallVector<SourceLocation, 16> SelLocs;
11183  E->getSelectorLocs(SelLocs);
11184  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
11185  E->getSelector(),
11186  SelLocs,
11187  E->getMethodDecl(),
11188  E->getLeftLoc(),
11189  Args,
11190  E->getRightLoc());
11191 }
11192 
11193 template<typename Derived>
11194 ExprResult
11195 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
11196  return E;
11197 }
11198 
11199 template<typename Derived>
11200 ExprResult
11201 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
11202  return E;
11203 }
11204 
11205 template<typename Derived>
11206 ExprResult
11207 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
11208  // Transform the base expression.
11209  ExprResult Base = getDerived().TransformExpr(E->getBase());
11210  if (Base.isInvalid())
11211  return ExprError();
11212 
11213  // We don't need to transform the ivar; it will never change.
11214 
11215  // If nothing changed, just retain the existing expression.
11216  if (!getDerived().AlwaysRebuild() &&
11217  Base.get() == E->getBase())
11218  return E;
11219 
11220  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
11221  E->getLocation(),
11222  E->isArrow(), E->isFreeIvar());
11223 }
11224 
11225 template<typename Derived>
11226 ExprResult
11227 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
11228  // 'super' and types never change. Property never changes. Just
11229  // retain the existing expression.
11230  if (!E->isObjectReceiver())
11231  return E;
11232 
11233  // Transform the base expression.
11234  ExprResult Base = getDerived().TransformExpr(E->getBase());
11235  if (Base.isInvalid())
11236  return ExprError();
11237 
11238  // We don't need to transform the property; it will never change.
11239 
11240  // If nothing changed, just retain the existing expression.
11241  if (!getDerived().AlwaysRebuild() &&
11242  Base.get() == E->getBase())
11243  return E;
11244 
11245  if (E->isExplicitProperty())
11246  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11247  E->getExplicitProperty(),
11248  E->getLocation());
11249 
11250  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11251  SemaRef.Context.PseudoObjectTy,
11252  E->getImplicitPropertyGetter(),
11253  E->getImplicitPropertySetter(),
11254  E->getLocation());
11255 }
11256 
11257 template<typename Derived>
11258 ExprResult
11259 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11260  // Transform the base expression.
11261  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11262  if (Base.isInvalid())
11263  return ExprError();
11264 
11265  // Transform the key expression.
11266  ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11267  if (Key.isInvalid())
11268  return ExprError();
11269 
11270  // If nothing changed, just retain the existing expression.
11271  if (!getDerived().AlwaysRebuild() &&
11272  Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
11273  return E;
11274 
11275  return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
11276  Base.get(), Key.get(),
11277  E->getAtIndexMethodDecl(),
11278  E->setAtIndexMethodDecl());
11279 }
11280 
11281 template<typename Derived>
11282 ExprResult
11283 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
11284  // Transform the base expression.
11285  ExprResult Base = getDerived().TransformExpr(E->getBase());
11286  if (Base.isInvalid())
11287  return ExprError();
11288 
11289  // If nothing changed, just retain the existing expression.
11290  if (!getDerived().AlwaysRebuild() &&
11291  Base.get() == E->getBase())
11292  return E;
11293 
11294  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
11295  E->getOpLoc(),
11296  E->isArrow());
11297 }
11298 
11299 template<typename Derived>
11300 ExprResult
11301 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
11302  bool ArgumentChanged = false;
11303  SmallVector<Expr*, 8> SubExprs;
11304  SubExprs.reserve(E->getNumSubExprs());
11305  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11306  SubExprs, &ArgumentChanged))
11307  return ExprError();
11308 
11309  if (!getDerived().AlwaysRebuild() &&
11310  !ArgumentChanged)
11311  return E;
11312 
11313  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11314  SubExprs,
11315  E->getRParenLoc());
11316 }
11317 
11318 template<typename Derived>
11319 ExprResult
11320 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11321  ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11322  if (SrcExpr.isInvalid())
11323  return ExprError();
11324 
11325  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11326  if (!Type)
11327  return ExprError();
11328 
11329  if (!getDerived().AlwaysRebuild() &&
11330  Type == E->getTypeSourceInfo() &&
11331  SrcExpr.get() == E->getSrcExpr())
11332  return E;
11333 
11334  return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11335  SrcExpr.get(), Type,
11336  E->getRParenLoc());
11337 }
11338 
11339 template<typename Derived>
11340 ExprResult
11341 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
11342  BlockDecl *oldBlock = E->getBlockDecl();
11343 
11344  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
11345  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11346 
11347  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
11348  blockScope->TheDecl->setBlockMissingReturnType(
11349  oldBlock->blockMissingReturnType());
11350 
11351  SmallVector<ParmVarDecl*, 4> params;
11352  SmallVector<QualType, 4> paramTypes;
11353 
11354  const FunctionProtoType *exprFunctionType = E->getFunctionType();
11355 
11356  // Parameter substitution.
11357  Sema::ExtParameterInfoBuilder extParamInfos;
11358  if (getDerived().TransformFunctionTypeParams(
11359  E->getCaretLocation(), oldBlock->parameters(), nullptr,
11360  exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11361  extParamInfos)) {
11362  getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11363  return ExprError();
11364  }
11365 
11366  QualType exprResultType =
11367  getDerived().TransformType(exprFunctionType->getReturnType());
11368 
11369  auto epi = exprFunctionType->getExtProtoInfo();
11370  epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11371 
11372  QualType functionType =
11373  getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
11374  blockScope->FunctionType = functionType;
11375 
11376  // Set the parameters on the block decl.
11377  if (!params.empty())
11378  blockScope->TheDecl->setParams(params);
11379 
11380  if (!oldBlock->blockMissingReturnType()) {
11381  blockScope->HasImplicitReturnType = false;
11382  blockScope->ReturnType = exprResultType;
11383  }
11384 
11385  // Transform the body
11386  StmtResult body = getDerived().TransformStmt(E->getBody());
11387  if (body.isInvalid()) {
11388  getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11389  return ExprError();
11390  }
11391 
11392 #ifndef NDEBUG
11393  // In builds with assertions, make sure that we captured everything we
11394  // captured before.
11395  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
11396  for (const auto &I : oldBlock->captures()) {
11397  VarDecl *oldCapture = I.getVariable();
11398 
11399  // Ignore parameter packs.
11400  if (isa<ParmVarDecl>(oldCapture) &&
11401  cast<ParmVarDecl>(oldCapture)->isParameterPack())
11402  continue;
11403 
11404  VarDecl *newCapture =
11405  cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11406  oldCapture));
11407  assert(blockScope->CaptureMap.count(newCapture));
11408  }
11409  assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
11410  }
11411 #endif
11412 
11413  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
11414  /*Scope=*/nullptr);
11415 }
11416 
11417 template<typename Derived>
11418 ExprResult
11419 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
11420  llvm_unreachable("Cannot transform asType expressions yet");
11421 }
11422 
11423 template<typename Derived>
11424 ExprResult
11425 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
11426  QualType RetTy = getDerived().TransformType(E->getType());
11427  bool ArgumentChanged = false;
11428  SmallVector<Expr*, 8> SubExprs;
11429  SubExprs.reserve(E->getNumSubExprs());
11430  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11431  SubExprs, &ArgumentChanged))
11432  return ExprError();
11433 
11434  if (!getDerived().AlwaysRebuild() &&
11435  !ArgumentChanged)
11436  return E;
11437 
11438  return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
11439  RetTy, E->getOp(), E->getRParenLoc());
11440 }
11441 
11442 //===----------------------------------------------------------------------===//
11443 // Type reconstruction
11444 //===----------------------------------------------------------------------===//
11445 
11446 template<typename Derived>
11448  SourceLocation Star) {
11449  return SemaRef.BuildPointerType(PointeeType, Star,
11450  getDerived().getBaseEntity());
11451 }
11452 
11453 template<typename Derived>
11455  SourceLocation Star) {
11456  return SemaRef.BuildBlockPointerType(PointeeType, Star,
11457  getDerived().getBaseEntity());
11458 }
11459 
11460 template<typename Derived>
11461 QualType
11463  bool WrittenAsLValue,
11464  SourceLocation Sigil) {
11465  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
11466  Sigil, getDerived().getBaseEntity());
11467 }
11468 
11469 template<typename Derived>
11470 QualType
11472  QualType ClassType,
11473  SourceLocation Sigil) {
11474  return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11475  getDerived().getBaseEntity());
11476 }
11477 
11478 template<typename Derived>
11480  QualType BaseType,
11481  SourceLocation Loc,
11482  SourceLocation TypeArgsLAngleLoc,
11483  ArrayRef<TypeSourceInfo *> TypeArgs,
11484  SourceLocation TypeArgsRAngleLoc,
11485  SourceLocation ProtocolLAngleLoc,
11486  ArrayRef<ObjCProtocolDecl *> Protocols,
11487  ArrayRef<SourceLocation> ProtocolLocs,
11488  SourceLocation ProtocolRAngleLoc) {
11489  return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11490  TypeArgs, TypeArgsRAngleLoc,
11491  ProtocolLAngleLoc, Protocols, ProtocolLocs,
11492  ProtocolRAngleLoc,
11493  /*FailOnError=*/true);
11494 }
11495 
11496 template<typename Derived>
11498  QualType PointeeType,
11499  SourceLocation Star) {
11500  return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11501 }
11502 
11503 template<typename Derived>
11504 QualType
11507  const llvm::APInt *Size,
11508  Expr *SizeExpr,
11509  unsigned IndexTypeQuals,
11510  SourceRange BracketsRange) {
11511  if (SizeExpr || !Size)
11512  return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11513  IndexTypeQuals, BracketsRange,
11514  getDerived().getBaseEntity());
11515 
11516  QualType Types[] = {
11517  SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11518  SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11519  SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
11520  };
11521  const unsigned NumTypes = llvm::array_lengthof(Types);
11522  QualType SizeType;
11523  for (unsigned I = 0; I != NumTypes; ++I)
11524  if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11525  SizeType = Types[I];
11526  break;
11527  }
11528 
11529  // Note that we can return a VariableArrayType here in the case where
11530  // the element type was a dependent VariableArrayType.
11531  IntegerLiteral *ArraySize
11532  = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11533  /*FIXME*/BracketsRange.getBegin());
11534  return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
11535  IndexTypeQuals, BracketsRange,
11536  getDerived().getBaseEntity());
11537 }
11538 
11539 template<typename Derived>
11540 QualType
11543  const llvm::APInt &Size,
11544  unsigned IndexTypeQuals,
11545  SourceRange BracketsRange) {
11546  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
11547  IndexTypeQuals, BracketsRange);
11548 }
11549 
11550 template<typename Derived>
11551 QualType
11554  unsigned IndexTypeQuals,
11555  SourceRange BracketsRange) {
11556  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
11557  IndexTypeQuals, BracketsRange);
11558 }
11559 
11560 template<typename Derived>
11561 QualType
11564  Expr *SizeExpr,
11565  unsigned IndexTypeQuals,
11566  SourceRange BracketsRange) {
11567  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11568  SizeExpr,
11569  IndexTypeQuals, BracketsRange);
11570 }
11571 
11572 template<typename Derived>
11573 QualType
11576  Expr *SizeExpr,
11577  unsigned IndexTypeQuals,
11578  SourceRange BracketsRange) {
11579  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11580  SizeExpr,
11581  IndexTypeQuals, BracketsRange);
11582 }
11583 
11584 template<typename Derived>
11586  unsigned NumElements,
11587  VectorType::VectorKind VecKind) {
11588  // FIXME: semantic checking!
11589  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
11590 }
11591 
11592 template<typename Derived>
11594  unsigned NumElements,
11595  SourceLocation AttributeLoc) {
11596  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11597  NumElements, true);
11598  IntegerLiteral *VectorSize
11599  = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11600  AttributeLoc);
11601  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
11602 }
11603 
11604 template<typename Derived>
11605 QualType
11607  Expr *SizeExpr,
11608  SourceLocation AttributeLoc) {
11609  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
11610 }
11611 
11612 template<typename Derived>
11614  QualType T,
11615  MutableArrayRef<QualType> ParamTypes,
11616  const FunctionProtoType::ExtProtoInfo &EPI) {
11617  return SemaRef.BuildFunctionType(T, ParamTypes,
11618  getDerived().getBaseLocation(),
11619  getDerived().getBaseEntity(),
11620  EPI);
11621 }
11622 
11623 template<typename Derived>
11625  return SemaRef.Context.getFunctionNoProtoType(T);
11626 }
11627 
11628 template<typename Derived>
11630  assert(D && "no decl found");
11631  if (D->isInvalidDecl()) return QualType();
11632 
11633  // FIXME: Doesn't account for ObjCInterfaceDecl!
11634  TypeDecl *Ty;
11635  if (isa<UsingDecl>(D)) {
11636  UsingDecl *Using = cast<UsingDecl>(D);
11637  assert(Using->hasTypename() &&
11638  "UnresolvedUsingTypenameDecl transformed to non-typename using");
11639 
11640  // A valid resolved using typename decl points to exactly one type decl.
11641  assert(++Using->shadow_begin() == Using->shadow_end());
11642  Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
11643 
11644  } else {
11645  assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11646  "UnresolvedUsingTypenameDecl transformed to non-using decl");
11647  Ty = cast<UnresolvedUsingTypenameDecl>(D);
11648  }
11649 
11650  return SemaRef.Context.getTypeDeclType(Ty);
11651 }
11652 
11653 template<typename Derived>
11655  SourceLocation Loc) {
11656  return SemaRef.BuildTypeofExprType(E, Loc);
11657 }
11658 
11659 template<typename Derived>
11661  return SemaRef.Context.getTypeOfType(Underlying);
11662 }
11663 
11664 template<typename Derived>
11666  SourceLocation Loc) {
11667  return SemaRef.BuildDecltypeType(E, Loc);
11668 }
11669 
11670 template<typename Derived>
11673  SourceLocation Loc) {
11674  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11675 }
11676 
11677 template<typename Derived>
11679  TemplateName Template,
11680  SourceLocation TemplateNameLoc,
11681  TemplateArgumentListInfo &TemplateArgs) {
11682  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
11683 }
11684 
11685 template<typename Derived>
11687  SourceLocation KWLoc) {
11688  return SemaRef.BuildAtomicType(ValueType, KWLoc);
11689 }
11690 
11691 template<typename Derived>
11693  SourceLocation KWLoc) {
11694  return SemaRef.BuildPipeType(ValueType, KWLoc);
11695 }
11696 
11697 template<typename Derived>
11700  bool TemplateKW,
11701  TemplateDecl *Template) {
11702  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
11703  Template);
11704 }
11705 
11706 template<typename Derived>
11709  const IdentifierInfo &Name,
11710  SourceLocation NameLoc,
11711  QualType ObjectType,
11712  NamedDecl *FirstQualifierInScope) {
11714  TemplateName.setIdentifier(&Name, NameLoc);
11715  Sema::TemplateTy Template;
11716  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11717  getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11718  SS, TemplateKWLoc, TemplateName,
11719  ParsedType::make(ObjectType),
11720  /*EnteringContext=*/false,
11721  Template);
11722  return Template.get();
11723 }
11724 
11725 template<typename Derived>
11728  OverloadedOperatorKind Operator,
11729  SourceLocation NameLoc,
11730  QualType ObjectType) {
11732  // FIXME: Bogus location information.
11733  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
11734  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
11735  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11736  Sema::TemplateTy Template;
11737  getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11738  SS, TemplateKWLoc, Name,
11739  ParsedType::make(ObjectType),
11740  /*EnteringContext=*/false,
11741  Template);
11742  return Template.get();
11743 }
11744 
11745 template<typename Derived>
11746 ExprResult
11748  SourceLocation OpLoc,
11749  Expr *OrigCallee,
11750  Expr *First,
11751  Expr *Second) {
11752  Expr *Callee = OrigCallee->IgnoreParenCasts();
11753  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
11754 
11755  if (First->getObjectKind() == OK_ObjCProperty) {
11758  return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11759  First, Second);
11760  ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11761  if (Result.isInvalid())
11762  return ExprError();
11763  First = Result.get();
11764  }
11765 
11766  if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11767  ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11768  if (Result.isInvalid())
11769  return ExprError();
11770  Second = Result.get();
11771  }
11772 
11773  // Determine whether this should be a builtin operation.
11774  if (Op == OO_Subscript) {
11775  if (!First->getType()->isOverloadableType() &&
11776  !Second->getType()->isOverloadableType())
11777  return getSema().CreateBuiltinArraySubscriptExpr(First,
11778  Callee->getLocStart(),
11779  Second, OpLoc);
11780  } else if (Op == OO_Arrow) {
11781  // -> is never a builtin operation.
11782  return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11783  } else if (Second == nullptr || isPostIncDec) {
11784  if (!First->getType()->isOverloadableType()) {
11785  // The argument is not of overloadable type, so try to create a
11786  // built-in unary operation.
11787  UnaryOperatorKind Opc
11788  = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
11789 
11790  return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
11791  }
11792  } else {
11793  if (!First->getType()->isOverloadableType() &&
11794  !Second->getType()->isOverloadableType()) {
11795  // Neither of the arguments is an overloadable type, so try to
11796  // create a built-in binary operation.
11798  ExprResult Result
11799  = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
11800  if (Result.isInvalid())
11801  return ExprError();
11802 
11803  return Result;
11804  }
11805  }
11806 
11807  // Compute the transformed set of functions (and function templates) to be
11808  // used during overload resolution.
11809  UnresolvedSet<16> Functions;
11810 
11811  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
11812  assert(ULE->requiresADL());
11813  Functions.append(ULE->decls_begin(), ULE->decls_end());
11814  } else {
11815  // If we've resolved this to a particular non-member function, just call
11816  // that function. If we resolved it to a member function,
11817  // CreateOverloaded* will find that function for us.
11818  NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11819  if (!isa<CXXMethodDecl>(ND))
11820  Functions.addDecl(ND);
11821  }
11822 
11823  // Add any functions found via argument-dependent lookup.
11824  Expr *Args[2] = { First, Second };
11825  unsigned NumArgs = 1 + (Second != nullptr);
11826 
11827  // Create the overloaded operator invocation for unary operators.
11828  if (NumArgs == 1 || isPostIncDec) {
11829  UnaryOperatorKind Opc
11830  = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
11831  return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
11832  }
11833 
11834  if (Op == OO_Subscript) {
11835  SourceLocation LBrace;
11836  SourceLocation RBrace;
11837 
11838  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
11839  DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
11843  NameLoc.CXXOperatorName.EndOpNameLoc);
11844  } else {
11845  LBrace = Callee->getLocStart();
11846  RBrace = OpLoc;
11847  }
11848 
11849  return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11850  First, Second);
11851  }
11852 
11853  // Create the overloaded operator invocation for binary operators.
11855  ExprResult Result
11856  = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11857  if (Result.isInvalid())
11858  return ExprError();
11859 
11860  return Result;
11861 }
11862 
11863 template<typename Derived>
11864 ExprResult
11866  SourceLocation OperatorLoc,
11867  bool isArrow,
11868  CXXScopeSpec &SS,
11869  TypeSourceInfo *ScopeType,
11870  SourceLocation CCLoc,
11871  SourceLocation TildeLoc,
11872  PseudoDestructorTypeStorage Destroyed) {
11873  QualType BaseType = Base->getType();
11874  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
11875  (!isArrow && !BaseType->getAs<RecordType>()) ||
11876  (isArrow && BaseType->getAs<PointerType>() &&
11877  !BaseType->getAs<PointerType>()->getPointeeType()
11878  ->template getAs<RecordType>())){
11879  // This pseudo-destructor expression is still a pseudo-destructor.
11880  return SemaRef.BuildPseudoDestructorExpr(
11881  Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11882  CCLoc, TildeLoc, Destroyed);
11883  }
11884 
11885  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
11886  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11887  SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11888  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11889  NameInfo.setNamedTypeInfo(DestroyedType);
11890 
11891  // The scope type is now known to be a valid nested name specifier
11892  // component. Tack it on to the end of the nested name specifier.
11893  if (ScopeType) {
11894  if (!ScopeType->getType()->getAs<TagType>()) {
11895  getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11896  diag::err_expected_class_or_namespace)
11897  << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11898  return ExprError();
11899  }
11900  SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11901  CCLoc);
11902  }
11903 
11904  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11905  return getSema().BuildMemberReferenceExpr(Base, BaseType,
11906  OperatorLoc, isArrow,
11907  SS, TemplateKWLoc,
11908  /*FIXME: FirstQualifier*/ nullptr,
11909  NameInfo,
11910  /*TemplateArgs*/ nullptr,
11911  /*S*/nullptr);
11912 }
11913 
11914 template<typename Derived>
11915 StmtResult
11917  SourceLocation Loc = S->getLocStart();
11918  CapturedDecl *CD = S->getCapturedDecl();
11919  unsigned NumParams = CD->getNumParams();
11920  unsigned ContextParamPos = CD->getContextParamPosition();
11922  for (unsigned I = 0; I < NumParams; ++I) {
11923  if (I != ContextParamPos) {
11924  Params.push_back(
11925  std::make_pair(
11926  CD->getParam(I)->getName(),
11927  getDerived().TransformType(CD->getParam(I)->getType())));
11928  } else {
11929  Params.push_back(std::make_pair(StringRef(), QualType()));
11930  }
11931  }
11932  getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
11933  S->getCapturedRegionKind(), Params);
11934  StmtResult Body;
11935  {
11936  Sema::CompoundScopeRAII CompoundScope(getSema());
11937  Body = getDerived().TransformStmt(S->getCapturedStmt());
11938  }
11939 
11940  if (Body.isInvalid()) {
11941  getSema().ActOnCapturedRegionError();
11942  return StmtError();
11943  }
11944 
11945  return getSema().ActOnCapturedRegionEnd(Body.get());
11946 }
11947 
11948 } // end namespace clang
11949 
11950 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:539
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1009
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4430
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1410
SourceLocation getEnd() const
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present...
Definition: Type.h:3425
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:64
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:5278
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:408
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
Name lookup found a set of overloaded functions that met the criteria.
Definition: Sema/Lookup.h:47
This represents 'thread_limit' clause in the '#pragma omp ...' directive.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:216
const TemplateArgumentLoc * operator->() const
The receiver is an object instance.
Definition: ExprObjC.h:1005
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:1840
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:237
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
Smart pointer class that efficiently represents Objective-C method names.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
Expr * getSourceExpression() const
Definition: TemplateBase.h:483
This represents clause 'copyin' in the '#pragma omp ...' directives.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
Build a new object-construction expression.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2179
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
unsigned Length
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2078
A (possibly-)qualified type.
Definition: Type.h:598
SourceLocation getColonLoc() const
Get colon location.
ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:212
bool isInvalid() const
Definition: Ownership.h:160
QualType RebuildDependentSizedArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Derived & getDerived()
Retrieves a reference to the derived class.
ArrayRef< OMPClause * > clauses()
Definition: StmtOpenMP.h:215
QualType TransformType(QualType T)
Transforms the given type into another type.
OMPClause * RebuildOMPToClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'to' clause.
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:3438
QualType RebuildTemplateSpecializationType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:2705
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
static ConditionResult ConditionError()
Definition: Sema.h:9007
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
Build a new object-construction expression.
static UnresolvedLookupExpr * Create(const ASTContext &C, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool ADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.h:2719
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1284
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
DeclClass * getAsSingle() const
Definition: Sema/Lookup.h:491
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1246
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Sema/Lookup.h:508
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1458
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:1759
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
QualType RebuildEnumType(EnumDecl *Enum)
Build a new Enum type.
ActionResult< Expr * > ExprResult
Definition: Ownership.h:253
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition: Sema.h:819
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1430
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
SourceLocation getLParenLoc() const
Returns the location of '('.
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
bool isRecordType() const
Definition: Type.h:5539
This represents 'grainsize' clause in the '#pragma omp ...' directive.
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:1972
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
void setType(QualType t)
Definition: Expr.h:127
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2671
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4084
Represents an attribute applied to a statement.
Definition: Stmt.h:830
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
bool isEnumeralType() const
Definition: Type.h:5542
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1619
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:315
PtrTy get() const
Definition: Ownership.h:164
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
This represents 'priority' clause in the '#pragma omp ...' directive.
The base class of the type hierarchy.
Definition: Type.h:1281
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1260
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:2858
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc)
Build a new typeof(expr) type.
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1874
DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgument > Args, QualType Canon)
QualType RebuildConstantArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt &Size, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array...
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:471
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1162
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:2874
Wrapper for source info for typedefs.
Definition: TypeLoc.h:620
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:391
SourceLocation getColonLoc() const
Returns the location of ':'.
const TemplateArgumentLoc * operator->() const
std::input_iterator_tag iterator_category
A container of type source information.
Definition: Decl.h:62
Wrapper for void* pointer.
Definition: Ownership.h:46
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, TemplateName Template)
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:305
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a function type into the given vectors.
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedExpr::IdentType IT)
Build a new predefined expression.
SourceLocation getColonLoc() const
Get colon location.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2187
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:3962
bool isSpelledAsLValue() const
Definition: Type.h:2336
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, Expr *Callee, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
Expr * getAlignment()
Returns alignment.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
An identifier, stored as an IdentifierInfo*.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:125
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:543
RAII object that enters a new expression evaluation context.
Definition: Sema.h:9606
OMPClause * RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1624
void removeObjCLifetime()
Definition: Type.h:314
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast. ...
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:247
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:46
Extra information about a function prototype.
Definition: Type.h:3167
This represents 'defaultmap' clause in the '#pragma omp ...' directive.
AutoTypeKeyword getKeyword() const
Definition: Type.h:4102
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
OMPClause * RebuildOMPThreadLimitClause(Expr *ThreadLimit, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:4695
A namespace, stored as a NamespaceDecl*.
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:2865
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:533
void transformedLocalDecl(Decl *Old, Decl *New)
Note that a local declaration has been transformed by this transformer.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:49
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1098
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, QualType RetTy, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
This represents implicit clause 'flush' for the '#pragma omp flush' directive.
Defines the Objective-C statement AST node classes.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:2936
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1553
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1377
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:3983
TemplateArgumentLocContainerIterator operator++(int)
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1739
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
This represents 'nogroup' clause in the '#pragma omp ...' directive.
The collection of all-type qualifiers we support.
Definition: Type.h:117
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:254
OpenMPDirectiveKind getDirectiveKind() const
Definition: StmtOpenMP.h:201
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3253
A semantic tree transformation that allows one to transform one abstract syntax tree into another...
Definition: TreeTransform.h:95
DeclarationName getName() const
getName - Returns the embedded declaration name.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
One of these records is kept for each identifier that is lexed.
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1270
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Sema/Lookup.h:57
SourceLocation getLParenLoc() const
Returns the location of '('.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:234
Step
Definition: OpenMPClause.h:313
This represents '#pragma omp parallel' directive.
Definition: StmtOpenMP.h:231
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1115
A C++ nested-name-specifier augmented with source location information.
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:412
ExprResult ExprEmpty()
Definition: Ownership.h:274
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1067
This represents 'simd' clause in the '#pragma omp ...' directive.
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3276
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:57
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration...
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1472
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
bool isReferenceType() const
Definition: Type.h:5491
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1267
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:84
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2293
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:93
OMPClause * RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'map' clause.
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:1647
TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given template name.
Expr * getChunkSize()
Get chunk size.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
This represents clause 'map' in the '#pragma omp ...' directives.
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3094
This represents clause 'to' in the '#pragma omp ...' directives.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
SourceLocation getLBracLoc() const
Definition: Stmt.h:629
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
Expr * getSubExpr()
Definition: Expr.h:2684
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:478
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
SourceRange getSourceRange() const LLVM_READONLY
Fetches the full source range of the argument.
Expr * getNumTeams()
Return NumTeams number.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword...
Definition: Diagnostic.h:1119
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Sema/Lookup.h:39
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:947
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:105
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool &ShouldExpand, bool &RetainExpansion, Optional< unsigned > &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
This represents clause 'copyprivate' in the '#pragma omp ...' directives.
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:100
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
Describes an C or C++ initializer list.
Definition: Expr.h:3746
Represents a C++ using-declaration.
Definition: DeclCXX.h:3039
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:3666
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
BinaryOperatorKind
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:884
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:470
Represents the results of name lookup.
Definition: Sema/Lookup.h:30
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2098
OMPClause * RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1895
< Capturing the *this object by copy
Definition: Lambda.h:37
OMPClause * RebuildOMPFromClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'from' clause.
A convenient class for passing around template argument information.
Definition: TemplateBase.h:523
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:221
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc, QualType ResultTy)
Build a new initializer list expression.
QualType getReturnType() const
Definition: Type.h:3009
QualType RebuildRecordType(RecordDecl *Record)
Build a new class/struct/union type.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
shadow_iterator shadow_begin() const
Definition: DeclCXX.h:3139
QualType RebuildArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known)...
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param)
Build a new C++ default-argument expression.
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:1643
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:3718
StmtResult StmtError()
Definition: Ownership.h:269
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:503
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:217
TypeDecl - Represents a declaration of a type.
Definition: Decl.h:2569
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:147
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
TemplateArgumentLocContainerIterator & operator++()
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorType::VectorKind VecKind)
Build a new vector type given the element type and number of elements.
OMPClause * RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Build a new pack expansion type.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation...
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Definition: Expr.cpp:2326
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
void append(iterator I, iterator E)
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2094
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1119
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:509
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc)
Build a new C++0x range-based for statement.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:87
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:720
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to...
Definition: Expr.h:2818
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
An ordinary object is located at an address in memory.
Definition: Specifiers.h:121
This represents clause 'is_device_ptr' in the '#pragma omp ...' directives.
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1263
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3625
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Sema/Lookup.h:410
Expr * getHint() const
Returns number of threads.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:2713
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result)
Build a new co_return statement.
bool empty() const
Definition: Type.h:377
detail::InMemoryDirectory::const_iterator I
unsigned getNumParams() const
Definition: TypeLoc.h:1301
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1094
QualType getType() const
Definition: Decl.h:599
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Definition: TypeLoc.h:53
TypedefNameDecl * getTypedefNameDecl() const
Definition: TypeLoc.h:624
shadow_iterator shadow_end() const
Definition: DeclCXX.h:3142
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:6785
This represents clause 'from' in the '#pragma omp ...' directives.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
Represents the this expression in C++.
Definition: ExprCXX.h:873
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
A helper class for building up ExtParameterInfos.
Definition: Sema.h:7104
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
const Derived & getDerived() const
Retrieves a reference to the derived class.
unsigned getNumParams() const
Definition: Decl.h:3664
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Definition: Type.h:3039
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
Definition: OpenMPClause.h:56
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:2851
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
SourceLocation getLocation() const
Definition: ExprCXX.h:2102
StmtResult TransformSEHHandler(Stmt *Handler)
An error occurred.
Definition: Sema.h:4130
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
bool isAssignmentOp() const
Definition: Expr.h:3025
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:551
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3073
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, unsigned NumVars)
Build 'linear' clause with given number of variables NumVars.
Definition: OpenMPClause.h:282
This represents 'threads' clause in the '#pragma omp ...' directive.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructExpr::ConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1009
void TypeWasModifiedSafely(QualType T)
Tell the TypeLocBuilder that the type it is storing has been modified in some safe way that doesn't a...
A RAII object to enter scope of a compound statement.
Definition: Sema.h:3353
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
param_type_iterator param_type_begin() const
Definition: Type.h:3392
QualType RebuildUnresolvedUsingType(Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
This represents clause 'aligned' in the '#pragma omp ...' directives.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2462
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
ASTContext * Context
QualType RebuildTypeOfType(QualType Underlying)
Build a new typeof(type) type.
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1903
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param)
Definition: ExprCXX.h:988
OMPClause * RebuildOMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:702
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1881
This represents implicit clause 'depend' for the '#pragma omp task' directive.
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:131
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:1727
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1764
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1855
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:590
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
Expr - This represents one expression.
Definition: Expr.h:105
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:102
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:4370
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
SourceLocation getMapLoc() const LLVM_READONLY
Fetches location of clause mapping kind.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, unsigned ThisTypeQuals, Fn TransformExceptionSpec)
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
Build a new MS style inline asm statement.
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:4357
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:54
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
Inits[]
Definition: OpenMPClause.h:312
TemplateArgumentLoc operator*() const
QualType TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, TemplateName Template, CXXScopeSpec &SS)
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2829
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1108
TemplateArgumentLocInventIterator & operator++()
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:2841
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4460
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:216
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3280
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
OMPClause * RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2003
ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLoc, Expr *Length, SourceLocation RBracketLoc)
Build a new array section expression.
SourceLocation getLParenLoc() const
Returns the location of '('.
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack)
Build a new template name given a template template parameter pack and the.
unsigned getContextParamPosition() const
Definition: Decl.h:3693
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
A namespace alias, stored as a NamespaceAliasDecl*.
StmtResult TransformStmt(Stmt *S)
Transform the given statement.
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:235
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1483
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:107
Expr * getSubExpr() const
Definition: Expr.h:1695
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1774
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
bool isInstanceMethod() const
Definition: DeclObjC.h:414
bool hasTrailingReturn() const
Definition: Type.h:3376
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:1960
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:269
A boolean condition, from 'if', 'while', 'for', or 'do'.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateDecl *Template)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
ConditionKind
Definition: Sema.h:9009
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:1605
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1668
struct CXXOpName CXXOperatorName
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:258
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
Expr * getDevice()
Return device number.
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4154
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
Definition: Sema.h:7123
SourceLocation getLParenLoc() const
Returns the location of '('.
const IdentifierInfo * getField() const
Definition: Designator.h:74
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
SourceLocation getCommaLoc()
Get location of ','.
The symbol exists.
Definition: Sema.h:4120
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
The result type of a method or function.
OpenMPProcBindClauseKind
OpenMP attributes for 'proc_bind' clause.
Definition: OpenMPKinds.h:51
UnresolvedSetImpl::iterator decls_iterator
Definition: ExprCXX.h:2571
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:671
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition: ExprCXX.h:1616
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:473
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:954
bool hasObjCLifetime() const
Definition: Type.h:307
TemplateArgumentLocInventIterator operator++(int)
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
SourceLocation getLocStart() const
Returns starting location of directive kind.
Definition: StmtOpenMP.h:168
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:2891
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1705
QualType RebuildDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Name, SourceLocation NameLoc, TemplateArgumentListInfo &Args)
Build a new typename type that refers to a template-id.
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
This represents 'num_teams' clause in the '#pragma omp ...' directive.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:215
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:2708
Kind
This captures a statement into a function.
Definition: Stmt.h:2006
A field in a dependent type, known only by its name.
Definition: Expr.h:1779
TypeLoc getValueLoc() const
Definition: TypeLoc.h:1988
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1325
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3153
SourceLocation getLParenLoc()
Get location of '('.
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1888
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:3188
Encodes a location in the source.
body_range body()
Definition: Stmt.h:581
This represents 'hint' clause in the '#pragma omp ...' directive.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
Definition: OpenMPKinds.h:76
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5259
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:262
const TemplateArgument * iterator
Definition: Type.h:4233
SourceLocation getLParenLoc() const
Returns the location of '('.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:33
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:119
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1274
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc)
Build a new typename type that refers to an identifier.
reference front() const
Definition: DeclBase.h:1109
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2727
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:143
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1310
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
OMPClause * RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:443
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:424
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
Expr * getPriority()
Return Priority number.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
OpenMPLinearClauseKind Modifier
Modifier of 'linear' clause.
Definition: OpenMPClause.h:262
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
C-style initialization with assignment.
Definition: Decl.h:778
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Sema/Lookup.h:52
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:32
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
Definition: Expr.h:4804
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:82
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2010
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:228
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
static CXXDefaultInitExpr * Create(const ASTContext &C, SourceLocation Loc, FieldDecl *Field)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.h:1052
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:699
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1843
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2734
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition: Stmt.h:2106
TypeLocClass getTypeLocClass() const
Definition: TypeLoc.h:90
OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY
Fetches the map type modifier for the clause.
QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the class type it refers into...
SourceLocation getLParenLoc() const
Returns the location of '('.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
SourceLocation getBegin() const
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:5849
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:165
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1309
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1407
No entity found met the criteria.
Definition: Sema/Lookup.h:34
SourceLocation getDependencyLoc() const
Get dependency type location.
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
PtrTy get() const
Definition: Ownership.h:75
The name is a dependent name, so the results will differ from one instantiation to the next...
Definition: Sema.h:4127
SourceLocation getKWLoc() const
Definition: TypeLoc.h:1996
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:7111
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2416
Expr * getGrainsize() const
Return safe iteration space distance.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:542
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:262
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:563
Opcode getOpcode() const
Definition: Expr.h:1692
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
QualType getPointeeType() const
Definition: Type.h:2193
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:1699
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:2791
Represents a pack expansion of types.
Definition: Type.h:4641
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1277
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1451
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2832
attr::Kind getKind() const
Definition: Attr.h:87
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2609
QualType getType() const
Definition: Expr.h:126
Represents a template argument.
Definition: TemplateBase.h:40
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:238
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:355
TagTypeKind
The kind of a tag type.
Definition: Type.h:4342
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition: OpenMPKinds.h:67
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2328
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
This represents 'device' clause in the '#pragma omp ...' directive.
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition: DeclCXX.h:3091
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
not evaluated yet, for special member function
UnaryOperatorKind
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:330
SourceLocation ModifierLoc
Location of linear modifier if any.
Definition: OpenMPClause.h:264
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:2884
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:1956
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:63
SourceRange getSourceRange(const SourceRange &Range)
Returns the SourceRange of a SourceRange.
Definition: FixIt.h:34
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ functional-style cast expression.
QualType RebuildElaboratedType(SourceLocation KeywordLoc, ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, QualType Named)
Build a new qualified name type.
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2481
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
A constant boolean condition from 'if constexpr'.
static ExprResult Owned(Expr *E)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:1871
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'use_device_ptr' clause.
DeclarationName - The name of a declaration.
Expr * getNumTasks() const
Return safe iteration space distance.
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3581
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
A set of unresolved declarations.
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:219
EnumDecl - Represents an enum.
Definition: Decl.h:3013
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1424
detail::InMemoryDirectory::const_iterator E
ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Build a new C++1z fold-expression.
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1111
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'is_device_ptr' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
A type that was preceded by the 'template' keyword, stored as a Type*.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
bool isImplicitMapType() const LLVM_READONLY
Is this an implicit map type? We have to capture 'IsMapTypeImplicit' from the parser for more informa...
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
Represents a __leave statement.
Definition: Stmt.h:1972
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new label statement.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:127
Name lookup found a single declaration that met the criteria.
Definition: Sema/Lookup.h:43
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
QualType RebuildIncompleteArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers...
Not an overloaded operator.
Definition: OperatorKinds.h:23
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3707
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:427
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS)
Build a new binary operator expression.
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
QualType getCanonicalType() const
Definition: Type.h:5298
This file defines OpenMP AST classes for executable directives and clauses.
bool isDeduced() const
Definition: Type.h:4114
OMPClause * RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
An implicit indirection through a C++ base class, when the field found is in a base class...
Definition: Expr.h:1782
UnqualTypeLoc getUnqualifiedLoc() const
Definition: TypeLoc.h:253
bool isNull() const
Determine whether this template name is NULL.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init, Sema::ConditionResult Cond)
Start building a new switch statement.
QualType RebuildVariableArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression...
std::iterator_traits< InputIterator >::difference_type difference_type
bool isFunctionType() const
Definition: Type.h:5479
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
Definition: DeclSpec.cpp:1238
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:59
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2319
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:254
The template argument is a type.
Definition: TemplateBase.h:48
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.h:2197
OpenMPDefaultClauseKind
OpenMP attributes for 'default' clause.
Definition: OpenMPKinds.h:43
SourceLocation getDistScheduleKindLoc()
Get kind location.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:379
bool isInvalid() const
The template argument is actually a parameter pack.
Definition: TemplateBase.h:72
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
const Expr * Replacement
Definition: AttributeList.h:58
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
bool isUsable() const
Definition: Ownership.h:161
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3155
bool hasAssociatedStmt() const
Returns true if directive has associated statement.
Definition: StmtOpenMP.h:193
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:862
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:12171
SourceLocation getAttrLoc() const
Definition: Stmt.h:861
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3157
An integral condition for a 'switch' statement.
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1084
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:139
Call-style initialization (C++98)
Definition: Decl.h:779
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::ConditionResult Cond, Stmt *Body)
Build a new while statement.
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:47
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc)
Build a new pipe type given its value type.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2315
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5339
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:231
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
BoundNodesTreeBuilder *const Builder
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Build a new template argument pack expansion.
This represents 'num_tasks' clause in the '#pragma omp ...' directive.
bool isObjCObjectPointerType() const
Definition: Type.h:5554
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword)
Build a new C++11 auto type.
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:29
An index into an array.
Definition: Expr.h:1775
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
Definition: Sema.h:814
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1878
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:92
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1849
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1307
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4391
TryCaptureKind
Definition: Sema.h:3687
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1281
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:5756
Location information for a TemplateArgument.
Definition: TemplateBase.h:368
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result)
Build a new co_await expression.
Expr * getThreadLimit()
Return ThreadLimit number.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
Definition: TemplateBase.h:322
The receiver is a class.
Definition: ExprObjC.h:1003
LookupResultKind getResultKind() const
Definition: Sema/Lookup.h:305
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Build a new expression pack expansion.
const StringRef Input
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2148
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1292
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1465
ExprResult ExprError()
Definition: Ownership.h:268
This represents 'dist_schedule' clause in the '#pragma omp ...' directive.
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2339
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
SourceLocation getRBracLoc() const
Definition: Stmt.h:630
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:203
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:181
static OpaquePtr make(QualTypeP)
Definition: Ownership.h:55
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:80
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc)
Build a new GNU statement expression.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:932
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:401
SourceLocation getLParenLoc() const
Returns the location of '('.
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
Definition: Sema.h:799
Iterator adaptor that invents template argument location information for each of the template argumen...
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
Definition: Decl.h:685
ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:109
static Designator getArray(Expr *Index, SourceLocation LBracketLoc)
Definition: Designator.h:136
A trivial tuple used to represent a source range.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:988
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:1734
Represents a C++ namespace alias.
Definition: DeclCXX.h:2718
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1486
No keyword precedes the qualified type name.
Definition: Type.h:4372
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
SourceLocation getLocEnd() const
Returns ending location of directive.
Definition: StmtOpenMP.h:170
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:665
static Designator getArrayRange(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Definition: Designator.h:146
The receiver is a superclass.
Definition: ExprObjC.h:1007
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
Stmt * getAssociatedStmt() const
Returns statement associated with the directive.
Definition: StmtOpenMP.h:196
The global specifier '::'. There is no stored value.
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:470
SourceLocation ColonLoc
Location of ':'.
Definition: OpenMPClause.h:266
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, Expr *ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
TemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon, QualType Aliased)
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:4672
Stmt * getSubStmt()
Definition: Stmt.h:865
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3187
OMPClause * RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
QualType RebuildTypedefType(TypedefNameDecl *Typedef)
Build a new typedef type.
The symbol does not exist.
Definition: Sema.h:4123
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:4315
static StmtResult Owned(Stmt *S)
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1730
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
Attr - This represents one attribute.
Definition: Attr.h:45
This represents clause 'use_device_ptr' in the '#pragma omp ...' directives.
StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, Sema::ConditionResult Cond, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, SourceLocation RParenLoc)
Build a new inline asm statement.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:5286
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.
QualType getDeducedType() const
Get the type deduced for this auto type, or null if it's either not been deduced or was deduced to a ...
Definition: Type.h:4111