clang  3.8.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 attributes associated with the given declaration and
414  /// place them on the new declaration.
415  ///
416  /// By default, this operation does nothing. Subclasses may override this
417  /// behavior to transform attributes.
418  void transformAttrs(Decl *Old, Decl *New) { }
419 
420  /// \brief Note that a local declaration has been transformed by this
421  /// transformer.
422  ///
423  /// Local declarations are typically transformed via a call to
424  /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425  /// the transformer itself has to transform the declarations. This routine
426  /// can be overridden by a subclass that keeps track of such mappings.
427  void transformedLocalDecl(Decl *Old, Decl *New) {
428  TransformedLocalDecls[Old] = New;
429  }
430 
431  /// \brief Transform the definition of the given declaration.
432  ///
433  /// By default, invokes TransformDecl() to transform the declaration.
434  /// Subclasses may override this function to provide alternate behavior.
436  return getDerived().TransformDecl(Loc, D);
437  }
438 
439  /// \brief Transform the given declaration, which was the first part of a
440  /// nested-name-specifier in a member access expression.
441  ///
442  /// This specific declaration transformation only applies to the first
443  /// identifier in a nested-name-specifier of a member access expression, e.g.,
444  /// the \c T in \c x->T::member
445  ///
446  /// By default, invokes TransformDecl() to transform the declaration.
447  /// Subclasses may override this function to provide alternate behavior.
449  return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
450  }
451 
452  /// \brief Transform the given nested-name-specifier with source-location
453  /// information.
454  ///
455  /// By default, transforms all of the types and declarations within the
456  /// nested-name-specifier. Subclasses may override this function to provide
457  /// alternate behavior.
459  TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460  QualType ObjectType = QualType(),
461  NamedDecl *FirstQualifierInScope = nullptr);
462 
463  /// \brief Transform the given declaration name.
464  ///
465  /// By default, transforms the types of conversion function, constructor,
466  /// and destructor names and then (if needed) rebuilds the declaration name.
467  /// Identifiers and selectors are returned unmodified. Sublcasses may
468  /// override this function to provide alternate behavior.
470  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
471 
472  /// \brief Transform the given template name.
473  ///
474  /// \param SS The nested-name-specifier that qualifies the template
475  /// name. This nested-name-specifier must already have been transformed.
476  ///
477  /// \param Name The template name to transform.
478  ///
479  /// \param NameLoc The source location of the template name.
480  ///
481  /// \param ObjectType If we're translating a template name within a member
482  /// access expression, this is the type of the object whose member template
483  /// is being referenced.
484  ///
485  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486  /// also refers to a name within the current (lexical) scope, this is the
487  /// declaration it refers to.
488  ///
489  /// By default, transforms the template name by transforming the declarations
490  /// and nested-name-specifiers that occur within the template name.
491  /// Subclasses may override this function to provide alternate behavior.
493  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494  SourceLocation NameLoc,
495  QualType ObjectType = QualType(),
496  NamedDecl *FirstQualifierInScope = nullptr);
497 
498  /// \brief Transform the given template argument.
499  ///
500  /// By default, this operation transforms the type, expression, or
501  /// declaration stored within the template argument and constructs a
502  /// new template argument from the transformed result. Subclasses may
503  /// override this function to provide alternate behavior.
504  ///
505  /// Returns true if there was an error.
506  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
507  TemplateArgumentLoc &Output,
508  bool Uneval = false);
509 
510  /// \brief Transform the given set of template arguments.
511  ///
512  /// By default, this operation transforms all of the template arguments
513  /// in the input set using \c TransformTemplateArgument(), and appends
514  /// the transformed arguments to the output list.
515  ///
516  /// Note that this overload of \c TransformTemplateArguments() is merely
517  /// a convenience function. Subclasses that wish to override this behavior
518  /// should override the iterator-based member template version.
519  ///
520  /// \param Inputs The set of template arguments to be transformed.
521  ///
522  /// \param NumInputs The number of template arguments in \p Inputs.
523  ///
524  /// \param Outputs The set of transformed template arguments output by this
525  /// routine.
526  ///
527  /// Returns true if an error occurred.
529  unsigned NumInputs,
530  TemplateArgumentListInfo &Outputs,
531  bool Uneval = false) {
532  return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533  Uneval);
534  }
535 
536  /// \brief Transform the given set of template arguments.
537  ///
538  /// By default, this operation transforms all of the template arguments
539  /// in the input set using \c TransformTemplateArgument(), and appends
540  /// the transformed arguments to the output list.
541  ///
542  /// \param First An iterator to the first template argument.
543  ///
544  /// \param Last An iterator one step past the last template argument.
545  ///
546  /// \param Outputs The set of transformed template arguments output by this
547  /// routine.
548  ///
549  /// Returns true if an error occurred.
550  template<typename InputIterator>
551  bool TransformTemplateArguments(InputIterator First,
552  InputIterator Last,
553  TemplateArgumentListInfo &Outputs,
554  bool Uneval = false);
555 
556  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558  TemplateArgumentLoc &ArgLoc);
559 
560  /// \brief Fakes up a TypeSourceInfo for a type.
562  return SemaRef.Context.getTrivialTypeSourceInfo(T,
563  getDerived().getBaseLocation());
564  }
565 
566 #define ABSTRACT_TYPELOC(CLASS, PARENT)
567 #define TYPELOC(CLASS, PARENT) \
568  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
569 #include "clang/AST/TypeLocNodes.def"
570 
571  template<typename Fn>
572  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573  FunctionProtoTypeLoc TL,
574  CXXRecordDecl *ThisContext,
575  unsigned ThisTypeQuals,
576  Fn TransformExceptionSpec);
577 
578  bool TransformExceptionSpec(SourceLocation Loc,
579  FunctionProtoType::ExceptionSpecInfo &ESI,
580  SmallVectorImpl<QualType> &Exceptions,
581  bool &Changed);
582 
583  StmtResult TransformSEHHandler(Stmt *Handler);
584 
585  QualType
586  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587  TemplateSpecializationTypeLoc TL,
588  TemplateName Template);
589 
590  QualType
591  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592  DependentTemplateSpecializationTypeLoc TL,
593  TemplateName Template,
594  CXXScopeSpec &SS);
595 
596  QualType TransformDependentTemplateSpecializationType(
597  TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598  NestedNameSpecifierLoc QualifierLoc);
599 
600  /// \brief Transforms the parameters of a function type into the
601  /// given vectors.
602  ///
603  /// The result vectors should be kept in sync; null entries in the
604  /// variables vector are acceptable.
605  ///
606  /// Return true on error.
607  bool TransformFunctionTypeParams(SourceLocation Loc,
608  ParmVarDecl **Params, unsigned NumParams,
609  const QualType *ParamTypes,
610  SmallVectorImpl<QualType> &PTypes,
611  SmallVectorImpl<ParmVarDecl*> *PVars);
612 
613  /// \brief Transforms a single function-type parameter. Return null
614  /// on error.
615  ///
616  /// \param indexAdjustment - A number to add to the parameter's
617  /// scope index; can be negative
618  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
619  int indexAdjustment,
620  Optional<unsigned> NumExpansions,
621  bool ExpectParameterPack);
622 
623  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
624 
625  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
627 
629  TemplateParameterList *TPL) {
630  return TPL;
631  }
632 
633  ExprResult TransformAddressOfOperand(Expr *E);
634 
635  ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
636  bool IsAddressOfOperand,
637  TypeSourceInfo **RecoveryTSI);
638 
639  ExprResult TransformParenDependentScopeDeclRefExpr(
640  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641  TypeSourceInfo **RecoveryTSI);
642 
643  StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
644 
645 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646 // amount of stack usage with clang.
647 #define STMT(Node, Parent) \
648  LLVM_ATTRIBUTE_NOINLINE \
649  StmtResult Transform##Node(Node *S);
650 #define EXPR(Node, Parent) \
651  LLVM_ATTRIBUTE_NOINLINE \
652  ExprResult Transform##Node(Node *E);
653 #define ABSTRACT_STMT(Stmt)
654 #include "clang/AST/StmtNodes.inc"
655 
656 #define OPENMP_CLAUSE(Name, Class) \
657  LLVM_ATTRIBUTE_NOINLINE \
658  OMPClause *Transform ## Class(Class *S);
659 #include "clang/Basic/OpenMPKinds.def"
660 
661  /// \brief Build a new pointer type given its pointee type.
662  ///
663  /// By default, performs semantic analysis when building the pointer type.
664  /// Subclasses may override this routine to provide different behavior.
665  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
666 
667  /// \brief Build a new block pointer type given its pointee type.
668  ///
669  /// By default, performs semantic analysis when building the block pointer
670  /// type. Subclasses may override this routine to provide different behavior.
671  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
672 
673  /// \brief Build a new reference type given the type it references.
674  ///
675  /// By default, performs semantic analysis when building the
676  /// reference type. Subclasses may override this routine to provide
677  /// different behavior.
678  ///
679  /// \param LValue whether the type was written with an lvalue sigil
680  /// or an rvalue sigil.
681  QualType RebuildReferenceType(QualType ReferentType,
682  bool LValue,
683  SourceLocation Sigil);
684 
685  /// \brief Build a new member pointer type given the pointee type and the
686  /// class type it refers into.
687  ///
688  /// By default, performs semantic analysis when building the member pointer
689  /// type. Subclasses may override this routine to provide different behavior.
690  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691  SourceLocation Sigil);
692 
693  /// \brief Build an Objective-C object type.
694  ///
695  /// By default, performs semantic analysis when building the object type.
696  /// Subclasses may override this routine to provide different behavior.
697  QualType RebuildObjCObjectType(QualType BaseType,
698  SourceLocation Loc,
699  SourceLocation TypeArgsLAngleLoc,
700  ArrayRef<TypeSourceInfo *> TypeArgs,
701  SourceLocation TypeArgsRAngleLoc,
702  SourceLocation ProtocolLAngleLoc,
703  ArrayRef<ObjCProtocolDecl *> Protocols,
704  ArrayRef<SourceLocation> ProtocolLocs,
705  SourceLocation ProtocolRAngleLoc);
706 
707  /// \brief Build a new Objective-C object pointer type given the pointee type.
708  ///
709  /// By default, directly builds the pointer type, with no additional semantic
710  /// analysis.
711  QualType RebuildObjCObjectPointerType(QualType PointeeType,
712  SourceLocation Star);
713 
714  /// \brief Build a new array type given the element type, size
715  /// modifier, size of the array (if known), size expression, and index type
716  /// qualifiers.
717  ///
718  /// By default, performs semantic analysis when building the array type.
719  /// Subclasses may override this routine to provide different behavior.
720  /// Also by default, all of the other Rebuild*Array
721  QualType RebuildArrayType(QualType ElementType,
723  const llvm::APInt *Size,
724  Expr *SizeExpr,
725  unsigned IndexTypeQuals,
726  SourceRange BracketsRange);
727 
728  /// \brief Build a new constant array type given the element type, size
729  /// modifier, (known) size of the array, and index type qualifiers.
730  ///
731  /// By default, performs semantic analysis when building the array type.
732  /// Subclasses may override this routine to provide different behavior.
733  QualType RebuildConstantArrayType(QualType ElementType,
735  const llvm::APInt &Size,
736  unsigned IndexTypeQuals,
737  SourceRange BracketsRange);
738 
739  /// \brief Build a new incomplete array type given the element type, size
740  /// modifier, and index type qualifiers.
741  ///
742  /// By default, performs semantic analysis when building the array type.
743  /// Subclasses may override this routine to provide different behavior.
744  QualType RebuildIncompleteArrayType(QualType ElementType,
746  unsigned IndexTypeQuals,
747  SourceRange BracketsRange);
748 
749  /// \brief Build a new variable-length array type given the element type,
750  /// size modifier, size expression, and index type qualifiers.
751  ///
752  /// By default, performs semantic analysis when building the array type.
753  /// Subclasses may override this routine to provide different behavior.
754  QualType RebuildVariableArrayType(QualType ElementType,
756  Expr *SizeExpr,
757  unsigned IndexTypeQuals,
758  SourceRange BracketsRange);
759 
760  /// \brief Build a new dependent-sized array type given the element type,
761  /// size modifier, size expression, and index type qualifiers.
762  ///
763  /// By default, performs semantic analysis when building the array type.
764  /// Subclasses may override this routine to provide different behavior.
765  QualType RebuildDependentSizedArrayType(QualType ElementType,
767  Expr *SizeExpr,
768  unsigned IndexTypeQuals,
769  SourceRange BracketsRange);
770 
771  /// \brief Build a new vector type given the element type and
772  /// number of elements.
773  ///
774  /// By default, performs semantic analysis when building the vector type.
775  /// Subclasses may override this routine to provide different behavior.
776  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
777  VectorType::VectorKind VecKind);
778 
779  /// \brief Build a new extended vector type given the element type and
780  /// number of elements.
781  ///
782  /// By default, performs semantic analysis when building the vector type.
783  /// Subclasses may override this routine to provide different behavior.
784  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785  SourceLocation AttributeLoc);
786 
787  /// \brief Build a new potentially dependently-sized extended vector type
788  /// given the element type and number of elements.
789  ///
790  /// By default, performs semantic analysis when building the vector type.
791  /// Subclasses may override this routine to provide different behavior.
792  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
793  Expr *SizeExpr,
794  SourceLocation AttributeLoc);
795 
796  /// \brief Build a new function type.
797  ///
798  /// By default, performs semantic analysis when building the function type.
799  /// Subclasses may override this routine to provide different behavior.
800  QualType RebuildFunctionProtoType(QualType T,
801  MutableArrayRef<QualType> ParamTypes,
802  const FunctionProtoType::ExtProtoInfo &EPI);
803 
804  /// \brief Build a new unprototyped function type.
805  QualType RebuildFunctionNoProtoType(QualType ResultType);
806 
807  /// \brief Rebuild an unresolved typename type, given the decl that
808  /// the UnresolvedUsingTypenameDecl was transformed to.
809  QualType RebuildUnresolvedUsingType(Decl *D);
810 
811  /// \brief Build a new typedef type.
813  return SemaRef.Context.getTypeDeclType(Typedef);
814  }
815 
816  /// \brief Build a new class/struct/union type.
818  return SemaRef.Context.getTypeDeclType(Record);
819  }
820 
821  /// \brief Build a new Enum type.
823  return SemaRef.Context.getTypeDeclType(Enum);
824  }
825 
826  /// \brief Build a new typeof(expr) type.
827  ///
828  /// By default, performs semantic analysis when building the typeof type.
829  /// Subclasses may override this routine to provide different behavior.
830  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
831 
832  /// \brief Build a new typeof(type) type.
833  ///
834  /// By default, builds a new TypeOfType with the given underlying type.
835  QualType RebuildTypeOfType(QualType Underlying);
836 
837  /// \brief Build a new unary transform type.
838  QualType RebuildUnaryTransformType(QualType BaseType,
840  SourceLocation Loc);
841 
842  /// \brief Build a new C++11 decltype type.
843  ///
844  /// By default, performs semantic analysis when building the decltype type.
845  /// Subclasses may override this routine to provide different behavior.
846  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
847 
848  /// \brief Build a new C++11 auto type.
849  ///
850  /// By default, builds a new AutoType with the given deduced type.
852  // Note, IsDependent is always false here: we implicitly convert an 'auto'
853  // which has been deduced to a dependent type into an undeduced 'auto', so
854  // that we'll retry deduction after the transformation.
855  return SemaRef.Context.getAutoType(Deduced, Keyword,
856  /*IsDependent*/ false);
857  }
858 
859  /// \brief Build a new template specialization type.
860  ///
861  /// By default, performs semantic analysis when building the template
862  /// specialization type. Subclasses may override this routine to provide
863  /// different behavior.
864  QualType RebuildTemplateSpecializationType(TemplateName Template,
865  SourceLocation TemplateLoc,
867 
868  /// \brief Build a new parenthesized type.
869  ///
870  /// By default, builds a new ParenType type from the inner type.
871  /// Subclasses may override this routine to provide different behavior.
873  return SemaRef.Context.getParenType(InnerType);
874  }
875 
876  /// \brief Build a new qualified name type.
877  ///
878  /// By default, builds a new ElaboratedType type from the keyword,
879  /// the nested-name-specifier and the named type.
880  /// Subclasses may override this routine to provide different behavior.
882  ElaboratedTypeKeyword Keyword,
883  NestedNameSpecifierLoc QualifierLoc,
884  QualType Named) {
885  return SemaRef.Context.getElaboratedType(Keyword,
886  QualifierLoc.getNestedNameSpecifier(),
887  Named);
888  }
889 
890  /// \brief Build a new typename type that refers to a template-id.
891  ///
892  /// By default, builds a new DependentNameType type from the
893  /// nested-name-specifier and the given type. Subclasses may override
894  /// this routine to provide different behavior.
896  ElaboratedTypeKeyword Keyword,
897  NestedNameSpecifierLoc QualifierLoc,
898  const IdentifierInfo *Name,
899  SourceLocation NameLoc,
900  TemplateArgumentListInfo &Args) {
901  // Rebuild the template name.
902  // TODO: avoid TemplateName abstraction
903  CXXScopeSpec SS;
904  SS.Adopt(QualifierLoc);
905  TemplateName InstName
906  = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907  nullptr);
908 
909  if (InstName.isNull())
910  return QualType();
911 
912  // If it's still dependent, make a dependent specialization.
913  if (InstName.getAsDependentTemplateName())
914  return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915  QualifierLoc.getNestedNameSpecifier(),
916  Name,
917  Args);
918 
919  // Otherwise, make an elaborated type wrapping a non-dependent
920  // specialization.
921  QualType T =
922  getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923  if (T.isNull()) return QualType();
924 
925  if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
926  return T;
927 
928  return SemaRef.Context.getElaboratedType(Keyword,
929  QualifierLoc.getNestedNameSpecifier(),
930  T);
931  }
932 
933  /// \brief Build a new typename type that refers to an identifier.
934  ///
935  /// By default, performs semantic analysis when building the typename type
936  /// (or elaborated type). Subclasses may override this routine to provide
937  /// different behavior.
939  SourceLocation KeywordLoc,
940  NestedNameSpecifierLoc QualifierLoc,
941  const IdentifierInfo *Id,
942  SourceLocation IdLoc) {
943  CXXScopeSpec SS;
944  SS.Adopt(QualifierLoc);
945 
946  if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
947  // If the name is still dependent, just build a new dependent name type.
948  if (!SemaRef.computeDeclContext(SS))
949  return SemaRef.Context.getDependentNameType(Keyword,
950  QualifierLoc.getNestedNameSpecifier(),
951  Id);
952  }
953 
954  if (Keyword == ETK_None || Keyword == ETK_Typename)
955  return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
956  *Id, IdLoc);
957 
959 
960  // We had a dependent elaborated-type-specifier that has been transformed
961  // into a non-dependent elaborated-type-specifier. Find the tag we're
962  // referring to.
963  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
964  DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965  if (!DC)
966  return QualType();
967 
968  if (SemaRef.RequireCompleteDeclContext(SS, DC))
969  return QualType();
970 
971  TagDecl *Tag = nullptr;
972  SemaRef.LookupQualifiedName(Result, DC);
973  switch (Result.getResultKind()) {
976  break;
977 
978  case LookupResult::Found:
979  Tag = Result.getAsSingle<TagDecl>();
980  break;
981 
984  llvm_unreachable("Tag lookup cannot find non-tags");
985 
987  // Let the LookupResult structure handle ambiguities.
988  return QualType();
989  }
990 
991  if (!Tag) {
992  // Check where the name exists but isn't a tag type and use that to emit
993  // better diagnostics.
994  LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995  SemaRef.LookupQualifiedName(Result, DC);
996  switch (Result.getResultKind()) {
997  case LookupResult::Found:
1000  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1001  unsigned Kind = 0;
1002  if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
1003  else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004  else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
1005  SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006  SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007  break;
1008  }
1009  default:
1010  SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1011  << Kind << Id << DC << QualifierLoc.getSourceRange();
1012  break;
1013  }
1014  return QualType();
1015  }
1016 
1017  if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1018  IdLoc, Id)) {
1019  SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1020  SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021  return QualType();
1022  }
1023 
1024  // Build the elaborated-type-specifier type.
1025  QualType T = SemaRef.Context.getTypeDeclType(Tag);
1026  return SemaRef.Context.getElaboratedType(Keyword,
1027  QualifierLoc.getNestedNameSpecifier(),
1028  T);
1029  }
1030 
1031  /// \brief Build a new pack expansion type.
1032  ///
1033  /// By default, builds a new PackExpansionType type from the given pattern.
1034  /// Subclasses may override this routine to provide different behavior.
1036  SourceRange PatternRange,
1037  SourceLocation EllipsisLoc,
1038  Optional<unsigned> NumExpansions) {
1039  return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040  NumExpansions);
1041  }
1042 
1043  /// \brief Build a new atomic type given its value type.
1044  ///
1045  /// By default, performs semantic analysis when building the atomic type.
1046  /// Subclasses may override this routine to provide different behavior.
1047  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048 
1049  /// \brief Build a new pipe type given its value type.
1050  QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc);
1051 
1052  /// \brief Build a new template name given a nested name specifier, a flag
1053  /// indicating whether the "template" keyword was provided, and the template
1054  /// that the template name refers to.
1055  ///
1056  /// By default, builds the new template name directly. Subclasses may override
1057  /// this routine to provide different behavior.
1058  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1059  bool TemplateKW,
1060  TemplateDecl *Template);
1061 
1062  /// \brief Build a new template name given a nested name specifier and the
1063  /// name that is referred to as a template.
1064  ///
1065  /// By default, performs semantic analysis to determine whether the name can
1066  /// be resolved to a specific template, then builds the appropriate kind of
1067  /// template name. Subclasses may override this routine to provide different
1068  /// behavior.
1069  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1070  const IdentifierInfo &Name,
1071  SourceLocation NameLoc,
1072  QualType ObjectType,
1073  NamedDecl *FirstQualifierInScope);
1074 
1075  /// \brief Build a new template name given a nested name specifier and the
1076  /// overloaded operator name that is referred to as a template.
1077  ///
1078  /// By default, performs semantic analysis to determine whether the name can
1079  /// be resolved to a specific template, then builds the appropriate kind of
1080  /// template name. Subclasses may override this routine to provide different
1081  /// behavior.
1082  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1083  OverloadedOperatorKind Operator,
1084  SourceLocation NameLoc,
1085  QualType ObjectType);
1086 
1087  /// \brief Build a new template name given a template template parameter pack
1088  /// and the
1089  ///
1090  /// By default, performs semantic analysis to determine whether the name can
1091  /// be resolved to a specific template, then builds the appropriate kind of
1092  /// template name. Subclasses may override this routine to provide different
1093  /// behavior.
1095  const TemplateArgument &ArgPack) {
1096  return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1097  }
1098 
1099  /// \brief Build a new compound statement.
1100  ///
1101  /// By default, performs semantic analysis to build the new statement.
1102  /// Subclasses may override this routine to provide different behavior.
1104  MultiStmtArg Statements,
1105  SourceLocation RBraceLoc,
1106  bool IsStmtExpr) {
1107  return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1108  IsStmtExpr);
1109  }
1110 
1111  /// \brief Build a new case statement.
1112  ///
1113  /// By default, performs semantic analysis to build the new statement.
1114  /// Subclasses may override this routine to provide different behavior.
1116  Expr *LHS,
1117  SourceLocation EllipsisLoc,
1118  Expr *RHS,
1120  return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1121  ColonLoc);
1122  }
1123 
1124  /// \brief Attach the body to a new case statement.
1125  ///
1126  /// By default, performs semantic analysis to build the new statement.
1127  /// Subclasses may override this routine to provide different behavior.
1129  getSema().ActOnCaseStmtBody(S, Body);
1130  return S;
1131  }
1132 
1133  /// \brief Build a new default statement.
1134  ///
1135  /// By default, performs semantic analysis to build the new statement.
1136  /// Subclasses may override this routine to provide different behavior.
1139  Stmt *SubStmt) {
1140  return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1141  /*CurScope=*/nullptr);
1142  }
1143 
1144  /// \brief Build a new label statement.
1145  ///
1146  /// By default, performs semantic analysis to build the new statement.
1147  /// Subclasses may override this routine to provide different behavior.
1149  SourceLocation ColonLoc, Stmt *SubStmt) {
1150  return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
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  ArrayRef<const Attr*> Attrs,
1159  Stmt *SubStmt) {
1160  return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1161  }
1162 
1163  /// \brief Build a new "if" statement.
1164  ///
1165  /// By default, performs semantic analysis to build the new statement.
1166  /// Subclasses may override this routine to provide different behavior.
1168  VarDecl *CondVar, Stmt *Then,
1169  SourceLocation ElseLoc, Stmt *Else) {
1170  return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
1171  }
1172 
1173  /// \brief Start building a new switch statement.
1174  ///
1175  /// By default, performs semantic analysis to build the new statement.
1176  /// Subclasses may override this routine to provide different behavior.
1178  Expr *Cond, VarDecl *CondVar) {
1179  return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1180  CondVar);
1181  }
1182 
1183  /// \brief Attach the body to the 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  Stmt *Switch, Stmt *Body) {
1189  return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1190  }
1191 
1192  /// \brief Build a new while statement.
1193  ///
1194  /// By default, performs semantic analysis to build the new statement.
1195  /// Subclasses may override this routine to provide different behavior.
1197  VarDecl *CondVar, Stmt *Body) {
1198  return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
1199  }
1200 
1201  /// \brief Build a new do-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  SourceLocation WhileLoc, SourceLocation LParenLoc,
1207  Expr *Cond, SourceLocation RParenLoc) {
1208  return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1209  Cond, RParenLoc);
1210  }
1211 
1212  /// \brief Build a new for statement.
1213  ///
1214  /// By default, performs semantic analysis to build the new statement.
1215  /// Subclasses may override this routine to provide different behavior.
1217  Stmt *Init, Sema::FullExprArg Cond,
1218  VarDecl *CondVar, Sema::FullExprArg Inc,
1219  SourceLocation RParenLoc, Stmt *Body) {
1220  return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1221  CondVar, Inc, RParenLoc, Body);
1222  }
1223 
1224  /// \brief Build a new goto statement.
1225  ///
1226  /// By default, performs semantic analysis to build the new statement.
1227  /// Subclasses may override this routine to provide different behavior.
1229  LabelDecl *Label) {
1230  return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1231  }
1232 
1233  /// \brief Build a new indirect 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  SourceLocation StarLoc,
1239  Expr *Target) {
1240  return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1241  }
1242 
1243  /// \brief Build a new return statement.
1244  ///
1245  /// By default, performs semantic analysis to build the new statement.
1246  /// Subclasses may override this routine to provide different behavior.
1248  return getSema().BuildReturnStmt(ReturnLoc, Result);
1249  }
1250 
1251  /// \brief Build a new declaration statement.
1252  ///
1253  /// By default, performs semantic analysis to build the new statement.
1254  /// Subclasses may override this routine to provide different behavior.
1256  SourceLocation StartLoc, SourceLocation EndLoc) {
1257  Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
1258  return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1259  }
1260 
1261  /// \brief Build a new inline asm statement.
1262  ///
1263  /// By default, performs semantic analysis to build the new statement.
1264  /// Subclasses may override this routine to provide different behavior.
1266  bool IsVolatile, unsigned NumOutputs,
1267  unsigned NumInputs, IdentifierInfo **Names,
1268  MultiExprArg Constraints, MultiExprArg Exprs,
1269  Expr *AsmString, MultiExprArg Clobbers,
1270  SourceLocation RParenLoc) {
1271  return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1272  NumInputs, Names, Constraints, Exprs,
1273  AsmString, Clobbers, RParenLoc);
1274  }
1275 
1276  /// \brief Build a new MS style inline asm statement.
1277  ///
1278  /// By default, performs semantic analysis to build the new statement.
1279  /// Subclasses may override this routine to provide different behavior.
1281  ArrayRef<Token> AsmToks,
1282  StringRef AsmString,
1283  unsigned NumOutputs, unsigned NumInputs,
1284  ArrayRef<StringRef> Constraints,
1285  ArrayRef<StringRef> Clobbers,
1286  ArrayRef<Expr*> Exprs,
1287  SourceLocation EndLoc) {
1288  return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1289  NumOutputs, NumInputs,
1290  Constraints, Clobbers, Exprs, EndLoc);
1291  }
1292 
1293  /// \brief Build a new co_return statement.
1294  ///
1295  /// By default, performs semantic analysis to build the new statement.
1296  /// Subclasses may override this routine to provide different behavior.
1298  return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1299  }
1300 
1301  /// \brief Build a new co_await expression.
1302  ///
1303  /// By default, performs semantic analysis to build the new expression.
1304  /// Subclasses may override this routine to provide different behavior.
1306  return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1307  }
1308 
1309  /// \brief Build a new co_yield expression.
1310  ///
1311  /// By default, performs semantic analysis to build the new expression.
1312  /// Subclasses may override this routine to provide different behavior.
1314  return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1315  }
1316 
1317  /// \brief Build a new Objective-C \@try statement.
1318  ///
1319  /// By default, performs semantic analysis to build the new statement.
1320  /// Subclasses may override this routine to provide different behavior.
1322  Stmt *TryBody,
1323  MultiStmtArg CatchStmts,
1324  Stmt *Finally) {
1325  return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1326  Finally);
1327  }
1328 
1329  /// \brief Rebuild an Objective-C exception declaration.
1330  ///
1331  /// By default, performs semantic analysis to build the new declaration.
1332  /// Subclasses may override this routine to provide different behavior.
1334  TypeSourceInfo *TInfo, QualType T) {
1335  return getSema().BuildObjCExceptionDecl(TInfo, T,
1336  ExceptionDecl->getInnerLocStart(),
1337  ExceptionDecl->getLocation(),
1338  ExceptionDecl->getIdentifier());
1339  }
1340 
1341  /// \brief Build a new Objective-C \@catch statement.
1342  ///
1343  /// By default, performs semantic analysis to build the new statement.
1344  /// Subclasses may override this routine to provide different behavior.
1346  SourceLocation RParenLoc,
1347  VarDecl *Var,
1348  Stmt *Body) {
1349  return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1350  Var, Body);
1351  }
1352 
1353  /// \brief Build a new Objective-C \@finally statement.
1354  ///
1355  /// By default, performs semantic analysis to build the new statement.
1356  /// Subclasses may override this routine to provide different behavior.
1358  Stmt *Body) {
1359  return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1360  }
1361 
1362  /// \brief Build a new Objective-C \@throw statement.
1363  ///
1364  /// By default, performs semantic analysis to build the new statement.
1365  /// Subclasses may override this routine to provide different behavior.
1367  Expr *Operand) {
1368  return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1369  }
1370 
1371  /// \brief Build a new OpenMP executable directive.
1372  ///
1373  /// By default, performs semantic analysis to build the new statement.
1374  /// Subclasses may override this routine to provide different behavior.
1376  DeclarationNameInfo DirName,
1377  OpenMPDirectiveKind CancelRegion,
1378  ArrayRef<OMPClause *> Clauses,
1379  Stmt *AStmt, SourceLocation StartLoc,
1380  SourceLocation EndLoc) {
1381  return getSema().ActOnOpenMPExecutableDirective(
1382  Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1383  }
1384 
1385  /// \brief Build a new OpenMP 'if' clause.
1386  ///
1387  /// By default, performs semantic analysis to build the new OpenMP clause.
1388  /// Subclasses may override this routine to provide different behavior.
1390  Expr *Condition, SourceLocation StartLoc,
1391  SourceLocation LParenLoc,
1392  SourceLocation NameModifierLoc,
1394  SourceLocation EndLoc) {
1395  return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1396  LParenLoc, NameModifierLoc, ColonLoc,
1397  EndLoc);
1398  }
1399 
1400  /// \brief Build a new OpenMP 'final' clause.
1401  ///
1402  /// By default, performs semantic analysis to build the new OpenMP clause.
1403  /// Subclasses may override this routine to provide different behavior.
1405  SourceLocation LParenLoc,
1406  SourceLocation EndLoc) {
1407  return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1408  EndLoc);
1409  }
1410 
1411  /// \brief Build a new OpenMP 'num_threads' clause.
1412  ///
1413  /// By default, performs semantic analysis to build the new OpenMP clause.
1414  /// Subclasses may override this routine to provide different behavior.
1416  SourceLocation StartLoc,
1417  SourceLocation LParenLoc,
1418  SourceLocation EndLoc) {
1419  return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1420  LParenLoc, EndLoc);
1421  }
1422 
1423  /// \brief Build a new OpenMP 'safelen' clause.
1424  ///
1425  /// By default, performs semantic analysis to build the new OpenMP clause.
1426  /// Subclasses may override this routine to provide different behavior.
1428  SourceLocation LParenLoc,
1429  SourceLocation EndLoc) {
1430  return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1431  }
1432 
1433  /// \brief Build a new OpenMP 'simdlen' clause.
1434  ///
1435  /// By default, performs semantic analysis to build the new OpenMP clause.
1436  /// Subclasses may override this routine to provide different behavior.
1438  SourceLocation LParenLoc,
1439  SourceLocation EndLoc) {
1440  return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1441  }
1442 
1443  /// \brief Build a new OpenMP 'collapse' clause.
1444  ///
1445  /// By default, performs semantic analysis to build the new OpenMP clause.
1446  /// Subclasses may override this routine to provide different behavior.
1448  SourceLocation LParenLoc,
1449  SourceLocation EndLoc) {
1450  return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1451  EndLoc);
1452  }
1453 
1454  /// \brief Build a new OpenMP 'default' clause.
1455  ///
1456  /// By default, performs semantic analysis to build the new OpenMP clause.
1457  /// Subclasses may override this routine to provide different behavior.
1459  SourceLocation KindKwLoc,
1460  SourceLocation StartLoc,
1461  SourceLocation LParenLoc,
1462  SourceLocation EndLoc) {
1463  return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1464  StartLoc, LParenLoc, EndLoc);
1465  }
1466 
1467  /// \brief Build a new OpenMP 'proc_bind' clause.
1468  ///
1469  /// By default, performs semantic analysis to build the new OpenMP clause.
1470  /// Subclasses may override this routine to provide different behavior.
1472  SourceLocation KindKwLoc,
1473  SourceLocation StartLoc,
1474  SourceLocation LParenLoc,
1475  SourceLocation EndLoc) {
1476  return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1477  StartLoc, LParenLoc, EndLoc);
1478  }
1479 
1480  /// \brief Build a new OpenMP 'schedule' clause.
1481  ///
1482  /// By default, performs semantic analysis to build the new OpenMP clause.
1483  /// Subclasses may override this routine to provide different behavior.
1486  OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1487  SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1488  SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1489  return getSema().ActOnOpenMPScheduleClause(
1490  M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1491  CommaLoc, EndLoc);
1492  }
1493 
1494  /// \brief Build a new OpenMP 'ordered' clause.
1495  ///
1496  /// By default, performs semantic analysis to build the new OpenMP clause.
1497  /// Subclasses may override this routine to provide different behavior.
1499  SourceLocation EndLoc,
1500  SourceLocation LParenLoc, Expr *Num) {
1501  return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1502  }
1503 
1504  /// \brief Build a new OpenMP 'private' clause.
1505  ///
1506  /// By default, performs semantic analysis to build the new OpenMP clause.
1507  /// Subclasses may override this routine to provide different behavior.
1509  SourceLocation StartLoc,
1510  SourceLocation LParenLoc,
1511  SourceLocation EndLoc) {
1512  return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1513  EndLoc);
1514  }
1515 
1516  /// \brief Build a new OpenMP 'firstprivate' clause.
1517  ///
1518  /// By default, performs semantic analysis to build the new OpenMP clause.
1519  /// Subclasses may override this routine to provide different behavior.
1521  SourceLocation StartLoc,
1522  SourceLocation LParenLoc,
1523  SourceLocation EndLoc) {
1524  return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1525  EndLoc);
1526  }
1527 
1528  /// \brief Build a new OpenMP 'lastprivate' clause.
1529  ///
1530  /// By default, performs semantic analysis to build the new OpenMP clause.
1531  /// Subclasses may override this routine to provide different behavior.
1533  SourceLocation StartLoc,
1534  SourceLocation LParenLoc,
1535  SourceLocation EndLoc) {
1536  return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1537  EndLoc);
1538  }
1539 
1540  /// \brief Build a new OpenMP 'shared' clause.
1541  ///
1542  /// By default, performs semantic analysis to build the new OpenMP clause.
1543  /// Subclasses may override this routine to provide different behavior.
1545  SourceLocation StartLoc,
1546  SourceLocation LParenLoc,
1547  SourceLocation EndLoc) {
1548  return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1549  EndLoc);
1550  }
1551 
1552  /// \brief Build a new OpenMP 'reduction' clause.
1553  ///
1554  /// By default, performs semantic analysis to build the new statement.
1555  /// Subclasses may override this routine to provide different behavior.
1557  SourceLocation StartLoc,
1558  SourceLocation LParenLoc,
1560  SourceLocation EndLoc,
1561  CXXScopeSpec &ReductionIdScopeSpec,
1562  const DeclarationNameInfo &ReductionId) {
1563  return getSema().ActOnOpenMPReductionClause(
1564  VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1565  ReductionId);
1566  }
1567 
1568  /// \brief Build a new OpenMP 'linear' clause.
1569  ///
1570  /// By default, performs semantic analysis to build the new OpenMP clause.
1571  /// Subclasses may override this routine to provide different behavior.
1573  SourceLocation StartLoc,
1574  SourceLocation LParenLoc,
1578  SourceLocation EndLoc) {
1579  return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1580  Modifier, ModifierLoc, ColonLoc,
1581  EndLoc);
1582  }
1583 
1584  /// \brief Build a new OpenMP 'aligned' clause.
1585  ///
1586  /// By default, performs semantic analysis to build the new OpenMP clause.
1587  /// Subclasses may override this routine to provide different behavior.
1589  SourceLocation StartLoc,
1590  SourceLocation LParenLoc,
1592  SourceLocation EndLoc) {
1593  return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1594  LParenLoc, ColonLoc, EndLoc);
1595  }
1596 
1597  /// \brief Build a new OpenMP 'copyin' clause.
1598  ///
1599  /// By default, performs semantic analysis to build the new OpenMP clause.
1600  /// Subclasses may override this routine to provide different behavior.
1602  SourceLocation StartLoc,
1603  SourceLocation LParenLoc,
1604  SourceLocation EndLoc) {
1605  return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1606  EndLoc);
1607  }
1608 
1609  /// \brief Build a new OpenMP 'copyprivate' clause.
1610  ///
1611  /// By default, performs semantic analysis to build the new OpenMP clause.
1612  /// Subclasses may override this routine to provide different behavior.
1614  SourceLocation StartLoc,
1615  SourceLocation LParenLoc,
1616  SourceLocation EndLoc) {
1617  return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1618  EndLoc);
1619  }
1620 
1621  /// \brief Build a new OpenMP 'flush' pseudo clause.
1622  ///
1623  /// By default, performs semantic analysis to build the new OpenMP clause.
1624  /// Subclasses may override this routine to provide different behavior.
1626  SourceLocation StartLoc,
1627  SourceLocation LParenLoc,
1628  SourceLocation EndLoc) {
1629  return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1630  EndLoc);
1631  }
1632 
1633  /// \brief Build a new OpenMP 'depend' pseudo clause.
1634  ///
1635  /// By default, performs semantic analysis to build the new OpenMP clause.
1636  /// Subclasses may override this routine to provide different behavior.
1637  OMPClause *
1640  SourceLocation StartLoc, SourceLocation LParenLoc,
1641  SourceLocation EndLoc) {
1642  return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1643  StartLoc, LParenLoc, EndLoc);
1644  }
1645 
1646  /// \brief Build a new OpenMP 'device' clause.
1647  ///
1648  /// By default, performs semantic analysis to build the new statement.
1649  /// Subclasses may override this routine to provide different behavior.
1651  SourceLocation LParenLoc,
1652  SourceLocation EndLoc) {
1653  return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1654  EndLoc);
1655  }
1656 
1657  /// \brief Build a new OpenMP 'map' clause.
1658  ///
1659  /// By default, performs semantic analysis to build the new OpenMP clause.
1660  /// Subclasses may override this routine to provide different behavior.
1662  OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType,
1664  SourceLocation StartLoc, SourceLocation LParenLoc,
1665  SourceLocation EndLoc) {
1666  return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc,
1667  ColonLoc, VarList,StartLoc,
1668  LParenLoc, EndLoc);
1669  }
1670 
1671  /// \brief Build a new OpenMP 'num_teams' clause.
1672  ///
1673  /// By default, performs semantic analysis to build the new statement.
1674  /// Subclasses may override this routine to provide different behavior.
1676  SourceLocation LParenLoc,
1677  SourceLocation EndLoc) {
1678  return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1679  EndLoc);
1680  }
1681 
1682  /// \brief Build a new OpenMP 'thread_limit' 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 StartLoc,
1688  SourceLocation LParenLoc,
1689  SourceLocation EndLoc) {
1690  return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1691  LParenLoc, EndLoc);
1692  }
1693 
1694  /// \brief Build a new OpenMP 'priority' clause.
1695  ///
1696  /// By default, performs semantic analysis to build the new statement.
1697  /// Subclasses may override this routine to provide different behavior.
1699  SourceLocation LParenLoc,
1700  SourceLocation EndLoc) {
1701  return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1702  EndLoc);
1703  }
1704 
1705  /// \brief Build a new OpenMP 'grainsize' 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().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1713  EndLoc);
1714  }
1715 
1716  /// \brief Build a new OpenMP 'num_tasks' 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().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1724  EndLoc);
1725  }
1726 
1727  /// \brief Build a new OpenMP 'hint' 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().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1735  }
1736 
1737  /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
1738  ///
1739  /// By default, performs semantic analysis to build the new statement.
1740  /// Subclasses may override this routine to provide different behavior.
1742  Expr *object) {
1743  return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1744  }
1745 
1746  /// \brief Build a new Objective-C \@synchronized statement.
1747  ///
1748  /// By default, performs semantic analysis to build the new statement.
1749  /// Subclasses may override this routine to provide different behavior.
1751  Expr *Object, Stmt *Body) {
1752  return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
1753  }
1754 
1755  /// \brief Build a new Objective-C \@autoreleasepool statement.
1756  ///
1757  /// By default, performs semantic analysis to build the new statement.
1758  /// Subclasses may override this routine to provide different behavior.
1760  Stmt *Body) {
1761  return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1762  }
1763 
1764  /// \brief Build a new Objective-C fast enumeration statement.
1765  ///
1766  /// By default, performs semantic analysis to build the new statement.
1767  /// Subclasses may override this routine to provide different behavior.
1769  Stmt *Element,
1770  Expr *Collection,
1771  SourceLocation RParenLoc,
1772  Stmt *Body) {
1773  StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1774  Element,
1775  Collection,
1776  RParenLoc);
1777  if (ForEachStmt.isInvalid())
1778  return StmtError();
1779 
1780  return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
1781  }
1782 
1783  /// \brief Build a new C++ exception declaration.
1784  ///
1785  /// By default, performs semantic analysis to build the new decaration.
1786  /// Subclasses may override this routine to provide different behavior.
1789  SourceLocation StartLoc,
1790  SourceLocation IdLoc,
1791  IdentifierInfo *Id) {
1792  VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
1793  StartLoc, IdLoc, Id);
1794  if (Var)
1795  getSema().CurContext->addDecl(Var);
1796  return Var;
1797  }
1798 
1799  /// \brief Build a new C++ catch statement.
1800  ///
1801  /// By default, performs semantic analysis to build the new statement.
1802  /// Subclasses may override this routine to provide different behavior.
1804  VarDecl *ExceptionDecl,
1805  Stmt *Handler) {
1806  return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1807  Handler));
1808  }
1809 
1810  /// \brief Build a new C++ try statement.
1811  ///
1812  /// By default, performs semantic analysis to build the new statement.
1813  /// Subclasses may override this routine to provide different behavior.
1815  ArrayRef<Stmt *> Handlers) {
1816  return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
1817  }
1818 
1819  /// \brief Build a new C++0x range-based for statement.
1820  ///
1821  /// By default, performs semantic analysis to build the new statement.
1822  /// Subclasses may override this routine to provide different behavior.
1824  SourceLocation CoawaitLoc,
1826  Stmt *Range, Stmt *BeginEnd,
1827  Expr *Cond, Expr *Inc,
1828  Stmt *LoopVar,
1829  SourceLocation RParenLoc) {
1830  // If we've just learned that the range is actually an Objective-C
1831  // collection, treat this as an Objective-C fast enumeration loop.
1832  if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1833  if (RangeStmt->isSingleDecl()) {
1834  if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1835  if (RangeVar->isInvalidDecl())
1836  return StmtError();
1837 
1838  Expr *RangeExpr = RangeVar->getInit();
1839  if (!RangeExpr->isTypeDependent() &&
1840  RangeExpr->getType()->isObjCObjectPointerType())
1841  return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1842  RParenLoc);
1843  }
1844  }
1845  }
1846 
1847  return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1848  Range, BeginEnd,
1849  Cond, Inc, LoopVar, RParenLoc,
1851  }
1852 
1853  /// \brief Build a new C++0x range-based for statement.
1854  ///
1855  /// By default, performs semantic analysis to build the new statement.
1856  /// Subclasses may override this routine to provide different behavior.
1858  bool IsIfExists,
1859  NestedNameSpecifierLoc QualifierLoc,
1860  DeclarationNameInfo NameInfo,
1861  Stmt *Nested) {
1862  return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1863  QualifierLoc, NameInfo, Nested);
1864  }
1865 
1866  /// \brief Attach body to a C++0x range-based for statement.
1867  ///
1868  /// By default, performs semantic analysis to finish the new statement.
1869  /// Subclasses may override this routine to provide different behavior.
1871  return getSema().FinishCXXForRangeStmt(ForRange, Body);
1872  }
1873 
1875  Stmt *TryBlock, Stmt *Handler) {
1876  return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
1877  }
1878 
1880  Stmt *Block) {
1881  return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
1882  }
1883 
1885  return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
1886  }
1887 
1888  /// \brief Build a new predefined expression.
1889  ///
1890  /// By default, performs semantic analysis to build the new expression.
1891  /// Subclasses may override this routine to provide different behavior.
1894  return getSema().BuildPredefinedExpr(Loc, IT);
1895  }
1896 
1897  /// \brief Build a new expression that references a declaration.
1898  ///
1899  /// By default, performs semantic analysis to build the new expression.
1900  /// Subclasses may override this routine to provide different behavior.
1902  LookupResult &R,
1903  bool RequiresADL) {
1904  return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1905  }
1906 
1907 
1908  /// \brief Build a new expression that references a declaration.
1909  ///
1910  /// By default, performs semantic analysis to build the new expression.
1911  /// Subclasses may override this routine to provide different behavior.
1913  ValueDecl *VD,
1914  const DeclarationNameInfo &NameInfo,
1915  TemplateArgumentListInfo *TemplateArgs) {
1916  CXXScopeSpec SS;
1917  SS.Adopt(QualifierLoc);
1918 
1919  // FIXME: loses template args.
1920 
1921  return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1922  }
1923 
1924  /// \brief Build a new expression in parentheses.
1925  ///
1926  /// By default, performs semantic analysis to build the new expression.
1927  /// Subclasses may override this routine to provide different behavior.
1929  SourceLocation RParen) {
1930  return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1931  }
1932 
1933  /// \brief Build a new pseudo-destructor expression.
1934  ///
1935  /// By default, performs semantic analysis to build the new expression.
1936  /// Subclasses may override this routine to provide different behavior.
1937  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1938  SourceLocation OperatorLoc,
1939  bool isArrow,
1940  CXXScopeSpec &SS,
1941  TypeSourceInfo *ScopeType,
1942  SourceLocation CCLoc,
1943  SourceLocation TildeLoc,
1944  PseudoDestructorTypeStorage Destroyed);
1945 
1946  /// \brief Build a new unary operator expression.
1947  ///
1948  /// By default, performs semantic analysis to build the new expression.
1949  /// Subclasses may override this routine to provide different behavior.
1951  UnaryOperatorKind Opc,
1952  Expr *SubExpr) {
1953  return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
1954  }
1955 
1956  /// \brief Build a new builtin offsetof expression.
1957  ///
1958  /// By default, performs semantic analysis to build the new expression.
1959  /// Subclasses may override this routine to provide different behavior.
1963  SourceLocation RParenLoc) {
1964  return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1965  RParenLoc);
1966  }
1967 
1968  /// \brief Build a new sizeof, alignof or vec_step expression with a
1969  /// type argument.
1970  ///
1971  /// By default, performs semantic analysis to build the new expression.
1972  /// Subclasses may override this routine to provide different behavior.
1974  SourceLocation OpLoc,
1975  UnaryExprOrTypeTrait ExprKind,
1976  SourceRange R) {
1977  return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1978  }
1979 
1980  /// \brief Build a new sizeof, alignof or vec step expression with an
1981  /// expression argument.
1982  ///
1983  /// By default, performs semantic analysis to build the new expression.
1984  /// Subclasses may override this routine to provide different behavior.
1986  UnaryExprOrTypeTrait ExprKind,
1987  SourceRange R) {
1989  = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1990  if (Result.isInvalid())
1991  return ExprError();
1992 
1993  return Result;
1994  }
1995 
1996  /// \brief Build a new array subscript expression.
1997  ///
1998  /// By default, performs semantic analysis to build the new expression.
1999  /// Subclasses may override this routine to provide different behavior.
2001  SourceLocation LBracketLoc,
2002  Expr *RHS,
2003  SourceLocation RBracketLoc) {
2004  return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2005  LBracketLoc, RHS,
2006  RBracketLoc);
2007  }
2008 
2009  /// \brief Build a new array section expression.
2010  ///
2011  /// By default, performs semantic analysis to build the new expression.
2012  /// Subclasses may override this routine to provide different behavior.
2014  Expr *LowerBound,
2016  SourceLocation RBracketLoc) {
2017  return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2018  ColonLoc, Length, RBracketLoc);
2019  }
2020 
2021  /// \brief Build a new call expression.
2022  ///
2023  /// By default, performs semantic analysis to build the new expression.
2024  /// Subclasses may override this routine to provide different behavior.
2026  MultiExprArg Args,
2027  SourceLocation RParenLoc,
2028  Expr *ExecConfig = nullptr) {
2029  return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
2030  Args, RParenLoc, ExecConfig);
2031  }
2032 
2033  /// \brief Build a new member access expression.
2034  ///
2035  /// By default, performs semantic analysis to build the new expression.
2036  /// Subclasses may override this routine to provide different behavior.
2038  bool isArrow,
2039  NestedNameSpecifierLoc QualifierLoc,
2040  SourceLocation TemplateKWLoc,
2041  const DeclarationNameInfo &MemberNameInfo,
2042  ValueDecl *Member,
2043  NamedDecl *FoundDecl,
2044  const TemplateArgumentListInfo *ExplicitTemplateArgs,
2045  NamedDecl *FirstQualifierInScope) {
2046  ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2047  isArrow);
2048  if (!Member->getDeclName()) {
2049  // We have a reference to an unnamed field. This is always the
2050  // base of an anonymous struct/union member access, i.e. the
2051  // field is always of record type.
2052  assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
2053  assert(Member->getType()->isRecordType() &&
2054  "unnamed member not of record type?");
2055 
2056  BaseResult =
2057  getSema().PerformObjectMemberConversion(BaseResult.get(),
2058  QualifierLoc.getNestedNameSpecifier(),
2059  FoundDecl, Member);
2060  if (BaseResult.isInvalid())
2061  return ExprError();
2062  Base = BaseResult.get();
2063  ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
2064  MemberExpr *ME = new (getSema().Context)
2065  MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2066  cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
2067  return ME;
2068  }
2069 
2070  CXXScopeSpec SS;
2071  SS.Adopt(QualifierLoc);
2072 
2073  Base = BaseResult.get();
2074  QualType BaseType = Base->getType();
2075 
2076  // FIXME: this involves duplicating earlier analysis in a lot of
2077  // cases; we should avoid this when possible.
2078  LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2079  R.addDecl(FoundDecl);
2080  R.resolveKind();
2081 
2082  return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2083  SS, TemplateKWLoc,
2084  FirstQualifierInScope,
2085  R, ExplicitTemplateArgs,
2086  /*S*/nullptr);
2087  }
2088 
2089  /// \brief Build a new binary operator expression.
2090  ///
2091  /// By default, performs semantic analysis to build the new expression.
2092  /// Subclasses may override this routine to provide different behavior.
2094  BinaryOperatorKind Opc,
2095  Expr *LHS, Expr *RHS) {
2096  return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2097  }
2098 
2099  /// \brief Build a new conditional operator expression.
2100  ///
2101  /// By default, performs semantic analysis to build the new expression.
2102  /// Subclasses may override this routine to provide different behavior.
2104  SourceLocation QuestionLoc,
2105  Expr *LHS,
2107  Expr *RHS) {
2108  return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2109  LHS, RHS);
2110  }
2111 
2112  /// \brief Build a new C-style cast expression.
2113  ///
2114  /// By default, performs semantic analysis to build the new expression.
2115  /// Subclasses may override this routine to provide different behavior.
2117  TypeSourceInfo *TInfo,
2118  SourceLocation RParenLoc,
2119  Expr *SubExpr) {
2120  return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2121  SubExpr);
2122  }
2123 
2124  /// \brief Build a new compound literal expression.
2125  ///
2126  /// By default, performs semantic analysis to build the new expression.
2127  /// Subclasses may override this routine to provide different behavior.
2129  TypeSourceInfo *TInfo,
2130  SourceLocation RParenLoc,
2131  Expr *Init) {
2132  return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2133  Init);
2134  }
2135 
2136  /// \brief Build a new extended vector element access expression.
2137  ///
2138  /// By default, performs semantic analysis to build the new expression.
2139  /// Subclasses may override this routine to provide different behavior.
2141  SourceLocation OpLoc,
2142  SourceLocation AccessorLoc,
2143  IdentifierInfo &Accessor) {
2144 
2145  CXXScopeSpec SS;
2146  DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2147  return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2148  OpLoc, /*IsArrow*/ false,
2149  SS, SourceLocation(),
2150  /*FirstQualifierInScope*/ nullptr,
2151  NameInfo,
2152  /* TemplateArgs */ nullptr,
2153  /*S*/ nullptr);
2154  }
2155 
2156  /// \brief Build a new initializer list expression.
2157  ///
2158  /// By default, performs semantic analysis to build the new expression.
2159  /// Subclasses may override this routine to provide different behavior.
2162  SourceLocation RBraceLoc,
2163  QualType ResultTy) {
2165  = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
2166  if (Result.isInvalid() || ResultTy->isDependentType())
2167  return Result;
2168 
2169  // Patch in the result type we were given, which may have been computed
2170  // when the initial InitListExpr was built.
2171  InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2172  ILE->setType(ResultTy);
2173  return Result;
2174  }
2175 
2176  /// \brief Build a new designated initializer expression.
2177  ///
2178  /// By default, performs semantic analysis to build the new expression.
2179  /// Subclasses may override this routine to provide different behavior.
2181  MultiExprArg ArrayExprs,
2182  SourceLocation EqualOrColonLoc,
2183  bool GNUSyntax,
2184  Expr *Init) {
2186  = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2187  Init);
2188  if (Result.isInvalid())
2189  return ExprError();
2190 
2191  return Result;
2192  }
2193 
2194  /// \brief Build a new value-initialized expression.
2195  ///
2196  /// By default, builds the implicit value initialization without performing
2197  /// any semantic analysis. Subclasses may override this routine to provide
2198  /// different behavior.
2200  return new (SemaRef.Context) ImplicitValueInitExpr(T);
2201  }
2202 
2203  /// \brief Build a new \c va_arg expression.
2204  ///
2205  /// By default, performs semantic analysis to build the new expression.
2206  /// Subclasses may override this routine to provide different behavior.
2208  Expr *SubExpr, TypeSourceInfo *TInfo,
2209  SourceLocation RParenLoc) {
2210  return getSema().BuildVAArgExpr(BuiltinLoc,
2211  SubExpr, TInfo,
2212  RParenLoc);
2213  }
2214 
2215  /// \brief Build a new expression list in parentheses.
2216  ///
2217  /// By default, performs semantic analysis to build the new expression.
2218  /// Subclasses may override this routine to provide different behavior.
2220  MultiExprArg SubExprs,
2221  SourceLocation RParenLoc) {
2222  return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2223  }
2224 
2225  /// \brief Build a new address-of-label expression.
2226  ///
2227  /// By default, performs semantic analysis, using the name of the label
2228  /// rather than attempting to map the label statement itself.
2229  /// Subclasses may override this routine to provide different behavior.
2231  SourceLocation LabelLoc, LabelDecl *Label) {
2232  return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2233  }
2234 
2235  /// \brief Build a new GNU statement expression.
2236  ///
2237  /// By default, performs semantic analysis to build the new expression.
2238  /// Subclasses may override this routine to provide different behavior.
2240  Stmt *SubStmt,
2241  SourceLocation RParenLoc) {
2242  return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
2243  }
2244 
2245  /// \brief Build a new __builtin_choose_expr expression.
2246  ///
2247  /// By default, performs semantic analysis to build the new expression.
2248  /// Subclasses may override this routine to provide different behavior.
2250  Expr *Cond, Expr *LHS, Expr *RHS,
2251  SourceLocation RParenLoc) {
2252  return SemaRef.ActOnChooseExpr(BuiltinLoc,
2253  Cond, LHS, RHS,
2254  RParenLoc);
2255  }
2256 
2257  /// \brief Build a new generic selection expression.
2258  ///
2259  /// By default, performs semantic analysis to build the new expression.
2260  /// Subclasses may override this routine to provide different behavior.
2262  SourceLocation DefaultLoc,
2263  SourceLocation RParenLoc,
2264  Expr *ControllingExpr,
2266  ArrayRef<Expr *> Exprs) {
2267  return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
2268  ControllingExpr, Types, Exprs);
2269  }
2270 
2271  /// \brief Build a new overloaded operator call expression.
2272  ///
2273  /// By default, performs semantic analysis to build the new expression.
2274  /// The semantic analysis provides the behavior of template instantiation,
2275  /// copying with transformations that turn what looks like an overloaded
2276  /// operator call into a use of a builtin operator, performing
2277  /// argument-dependent lookup, etc. Subclasses may override this routine to
2278  /// provide different behavior.
2279  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
2280  SourceLocation OpLoc,
2281  Expr *Callee,
2282  Expr *First,
2283  Expr *Second);
2284 
2285  /// \brief Build a new C++ "named" cast expression, such as static_cast or
2286  /// reinterpret_cast.
2287  ///
2288  /// By default, this routine dispatches to one of the more-specific routines
2289  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
2290  /// Subclasses may override this routine to provide different behavior.
2292  Stmt::StmtClass Class,
2293  SourceLocation LAngleLoc,
2294  TypeSourceInfo *TInfo,
2295  SourceLocation RAngleLoc,
2296  SourceLocation LParenLoc,
2297  Expr *SubExpr,
2298  SourceLocation RParenLoc) {
2299  switch (Class) {
2300  case Stmt::CXXStaticCastExprClass:
2301  return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
2302  RAngleLoc, LParenLoc,
2303  SubExpr, RParenLoc);
2304 
2305  case Stmt::CXXDynamicCastExprClass:
2306  return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
2307  RAngleLoc, LParenLoc,
2308  SubExpr, RParenLoc);
2309 
2310  case Stmt::CXXReinterpretCastExprClass:
2311  return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
2312  RAngleLoc, LParenLoc,
2313  SubExpr,
2314  RParenLoc);
2315 
2316  case Stmt::CXXConstCastExprClass:
2317  return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
2318  RAngleLoc, LParenLoc,
2319  SubExpr, RParenLoc);
2320 
2321  default:
2322  llvm_unreachable("Invalid C++ named cast");
2323  }
2324  }
2325 
2326  /// \brief Build a new C++ static_cast expression.
2327  ///
2328  /// By default, performs semantic analysis to build the new expression.
2329  /// Subclasses may override this routine to provide different behavior.
2331  SourceLocation LAngleLoc,
2332  TypeSourceInfo *TInfo,
2333  SourceLocation RAngleLoc,
2334  SourceLocation LParenLoc,
2335  Expr *SubExpr,
2336  SourceLocation RParenLoc) {
2337  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
2338  TInfo, SubExpr,
2339  SourceRange(LAngleLoc, RAngleLoc),
2340  SourceRange(LParenLoc, RParenLoc));
2341  }
2342 
2343  /// \brief Build a new C++ dynamic_cast expression.
2344  ///
2345  /// By default, performs semantic analysis to build the new expression.
2346  /// Subclasses may override this routine to provide different behavior.
2348  SourceLocation LAngleLoc,
2349  TypeSourceInfo *TInfo,
2350  SourceLocation RAngleLoc,
2351  SourceLocation LParenLoc,
2352  Expr *SubExpr,
2353  SourceLocation RParenLoc) {
2354  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
2355  TInfo, SubExpr,
2356  SourceRange(LAngleLoc, RAngleLoc),
2357  SourceRange(LParenLoc, RParenLoc));
2358  }
2359 
2360  /// \brief Build a new C++ reinterpret_cast expression.
2361  ///
2362  /// By default, performs semantic analysis to build the new expression.
2363  /// Subclasses may override this routine to provide different behavior.
2365  SourceLocation LAngleLoc,
2366  TypeSourceInfo *TInfo,
2367  SourceLocation RAngleLoc,
2368  SourceLocation LParenLoc,
2369  Expr *SubExpr,
2370  SourceLocation RParenLoc) {
2371  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
2372  TInfo, SubExpr,
2373  SourceRange(LAngleLoc, RAngleLoc),
2374  SourceRange(LParenLoc, RParenLoc));
2375  }
2376 
2377  /// \brief Build a new C++ const_cast expression.
2378  ///
2379  /// By default, performs semantic analysis to build the new expression.
2380  /// Subclasses may override this routine to provide different behavior.
2382  SourceLocation LAngleLoc,
2383  TypeSourceInfo *TInfo,
2384  SourceLocation RAngleLoc,
2385  SourceLocation LParenLoc,
2386  Expr *SubExpr,
2387  SourceLocation RParenLoc) {
2388  return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
2389  TInfo, SubExpr,
2390  SourceRange(LAngleLoc, RAngleLoc),
2391  SourceRange(LParenLoc, RParenLoc));
2392  }
2393 
2394  /// \brief Build a new C++ functional-style cast expression.
2395  ///
2396  /// By default, performs semantic analysis to build the new expression.
2397  /// Subclasses may override this routine to provide different behavior.
2399  SourceLocation LParenLoc,
2400  Expr *Sub,
2401  SourceLocation RParenLoc) {
2402  return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
2403  MultiExprArg(&Sub, 1),
2404  RParenLoc);
2405  }
2406 
2407  /// \brief Build a new C++ typeid(type) expression.
2408  ///
2409  /// By default, performs semantic analysis to build the new expression.
2410  /// Subclasses may override this routine to provide different behavior.
2412  SourceLocation TypeidLoc,
2413  TypeSourceInfo *Operand,
2414  SourceLocation RParenLoc) {
2415  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2416  RParenLoc);
2417  }
2418 
2419 
2420  /// \brief Build a new C++ typeid(expr) expression.
2421  ///
2422  /// By default, performs semantic analysis to build the new expression.
2423  /// Subclasses may override this routine to provide different behavior.
2425  SourceLocation TypeidLoc,
2426  Expr *Operand,
2427  SourceLocation RParenLoc) {
2428  return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
2429  RParenLoc);
2430  }
2431 
2432  /// \brief Build a new C++ __uuidof(type) expression.
2433  ///
2434  /// By default, performs semantic analysis to build the new expression.
2435  /// Subclasses may override this routine to provide different behavior.
2437  SourceLocation TypeidLoc,
2438  TypeSourceInfo *Operand,
2439  SourceLocation RParenLoc) {
2440  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2441  RParenLoc);
2442  }
2443 
2444  /// \brief Build a new C++ __uuidof(expr) expression.
2445  ///
2446  /// By default, performs semantic analysis to build the new expression.
2447  /// Subclasses may override this routine to provide different behavior.
2449  SourceLocation TypeidLoc,
2450  Expr *Operand,
2451  SourceLocation RParenLoc) {
2452  return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2453  RParenLoc);
2454  }
2455 
2456  /// \brief Build a new C++ "this" expression.
2457  ///
2458  /// By default, builds a new "this" expression without performing any
2459  /// semantic analysis. Subclasses may override this routine to provide
2460  /// different behavior.
2462  QualType ThisType,
2463  bool isImplicit) {
2464  getSema().CheckCXXThisCapture(ThisLoc);
2465  return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
2466  }
2467 
2468  /// \brief Build a new C++ throw expression.
2469  ///
2470  /// By default, performs semantic analysis to build the new expression.
2471  /// Subclasses may override this routine to provide different behavior.
2473  bool IsThrownVariableInScope) {
2474  return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
2475  }
2476 
2477  /// \brief Build a new C++ default-argument expression.
2478  ///
2479  /// By default, builds a new default-argument expression, which does not
2480  /// require any semantic analysis. Subclasses may override this routine to
2481  /// provide different behavior.
2483  ParmVarDecl *Param) {
2484  return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
2485  }
2486 
2487  /// \brief Build a new C++11 default-initialization expression.
2488  ///
2489  /// By default, builds a new default field initialization expression, which
2490  /// does not require any semantic analysis. Subclasses may override this
2491  /// routine to provide different behavior.
2493  FieldDecl *Field) {
2494  return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
2495  }
2496 
2497  /// \brief Build a new C++ zero-initialization expression.
2498  ///
2499  /// By default, performs semantic analysis to build the new expression.
2500  /// Subclasses may override this routine to provide different behavior.
2502  SourceLocation LParenLoc,
2503  SourceLocation RParenLoc) {
2504  return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
2505  None, RParenLoc);
2506  }
2507 
2508  /// \brief Build a new C++ "new" expression.
2509  ///
2510  /// By default, performs semantic analysis to build the new expression.
2511  /// Subclasses may override this routine to provide different behavior.
2513  bool UseGlobal,
2514  SourceLocation PlacementLParen,
2515  MultiExprArg PlacementArgs,
2516  SourceLocation PlacementRParen,
2517  SourceRange TypeIdParens,
2518  QualType AllocatedType,
2519  TypeSourceInfo *AllocatedTypeInfo,
2520  Expr *ArraySize,
2521  SourceRange DirectInitRange,
2522  Expr *Initializer) {
2523  return getSema().BuildCXXNew(StartLoc, UseGlobal,
2524  PlacementLParen,
2525  PlacementArgs,
2526  PlacementRParen,
2527  TypeIdParens,
2528  AllocatedType,
2529  AllocatedTypeInfo,
2530  ArraySize,
2531  DirectInitRange,
2532  Initializer);
2533  }
2534 
2535  /// \brief Build a new C++ "delete" expression.
2536  ///
2537  /// By default, performs semantic analysis to build the new expression.
2538  /// Subclasses may override this routine to provide different behavior.
2540  bool IsGlobalDelete,
2541  bool IsArrayForm,
2542  Expr *Operand) {
2543  return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
2544  Operand);
2545  }
2546 
2547  /// \brief Build a new type trait expression.
2548  ///
2549  /// By default, performs semantic analysis to build the new expression.
2550  /// Subclasses may override this routine to provide different behavior.
2552  SourceLocation StartLoc,
2554  SourceLocation RParenLoc) {
2555  return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2556  }
2557 
2558  /// \brief Build a new array type trait expression.
2559  ///
2560  /// By default, performs semantic analysis to build the new expression.
2561  /// Subclasses may override this routine to provide different behavior.
2563  SourceLocation StartLoc,
2564  TypeSourceInfo *TSInfo,
2565  Expr *DimExpr,
2566  SourceLocation RParenLoc) {
2567  return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2568  }
2569 
2570  /// \brief Build a new expression trait expression.
2571  ///
2572  /// By default, performs semantic analysis to build the new expression.
2573  /// Subclasses may override this routine to provide different behavior.
2575  SourceLocation StartLoc,
2576  Expr *Queried,
2577  SourceLocation RParenLoc) {
2578  return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2579  }
2580 
2581  /// \brief Build a new (previously unresolved) declaration reference
2582  /// expression.
2583  ///
2584  /// By default, performs semantic analysis to build the new expression.
2585  /// Subclasses may override this routine to provide different behavior.
2587  NestedNameSpecifierLoc QualifierLoc,
2588  SourceLocation TemplateKWLoc,
2589  const DeclarationNameInfo &NameInfo,
2590  const TemplateArgumentListInfo *TemplateArgs,
2591  bool IsAddressOfOperand,
2592  TypeSourceInfo **RecoveryTSI) {
2593  CXXScopeSpec SS;
2594  SS.Adopt(QualifierLoc);
2595 
2596  if (TemplateArgs || TemplateKWLoc.isValid())
2597  return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2598  TemplateArgs);
2599 
2600  return getSema().BuildQualifiedDeclarationNameExpr(
2601  SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
2602  }
2603 
2604  /// \brief Build a new template-id expression.
2605  ///
2606  /// By default, performs semantic analysis to build the new expression.
2607  /// Subclasses may override this routine to provide different behavior.
2609  SourceLocation TemplateKWLoc,
2610  LookupResult &R,
2611  bool RequiresADL,
2612  const TemplateArgumentListInfo *TemplateArgs) {
2613  return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2614  TemplateArgs);
2615  }
2616 
2617  /// \brief Build a new object-construction expression.
2618  ///
2619  /// By default, performs semantic analysis to build the new expression.
2620  /// Subclasses may override this routine to provide different behavior.
2622  SourceLocation Loc,
2623  CXXConstructorDecl *Constructor,
2624  bool IsElidable,
2625  MultiExprArg Args,
2626  bool HadMultipleCandidates,
2627  bool ListInitialization,
2628  bool StdInitListInitialization,
2629  bool RequiresZeroInit,
2630  CXXConstructExpr::ConstructionKind ConstructKind,
2631  SourceRange ParenRange) {
2632  SmallVector<Expr*, 8> ConvertedArgs;
2633  if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
2634  ConvertedArgs))
2635  return ExprError();
2636 
2637  return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
2638  ConvertedArgs,
2639  HadMultipleCandidates,
2640  ListInitialization,
2641  StdInitListInitialization,
2642  RequiresZeroInit, ConstructKind,
2643  ParenRange);
2644  }
2645 
2646  /// \brief Build a new object-construction expression.
2647  ///
2648  /// By default, performs semantic analysis to build the new expression.
2649  /// Subclasses may override this routine to provide different behavior.
2651  SourceLocation LParenLoc,
2652  MultiExprArg Args,
2653  SourceLocation RParenLoc) {
2654  return getSema().BuildCXXTypeConstructExpr(TSInfo,
2655  LParenLoc,
2656  Args,
2657  RParenLoc);
2658  }
2659 
2660  /// \brief Build a new object-construction expression.
2661  ///
2662  /// By default, performs semantic analysis to build the new expression.
2663  /// Subclasses may override this routine to provide different behavior.
2665  SourceLocation LParenLoc,
2666  MultiExprArg Args,
2667  SourceLocation RParenLoc) {
2668  return getSema().BuildCXXTypeConstructExpr(TSInfo,
2669  LParenLoc,
2670  Args,
2671  RParenLoc);
2672  }
2673 
2674  /// \brief Build a new member reference expression.
2675  ///
2676  /// By default, performs semantic analysis to build the new expression.
2677  /// Subclasses may override this routine to provide different behavior.
2679  QualType BaseType,
2680  bool IsArrow,
2681  SourceLocation OperatorLoc,
2682  NestedNameSpecifierLoc QualifierLoc,
2683  SourceLocation TemplateKWLoc,
2684  NamedDecl *FirstQualifierInScope,
2685  const DeclarationNameInfo &MemberNameInfo,
2686  const TemplateArgumentListInfo *TemplateArgs) {
2687  CXXScopeSpec SS;
2688  SS.Adopt(QualifierLoc);
2689 
2690  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2691  OperatorLoc, IsArrow,
2692  SS, TemplateKWLoc,
2693  FirstQualifierInScope,
2694  MemberNameInfo,
2695  TemplateArgs, /*S*/nullptr);
2696  }
2697 
2698  /// \brief Build a new member reference expression.
2699  ///
2700  /// By default, performs semantic analysis to build the new expression.
2701  /// Subclasses may override this routine to provide different behavior.
2703  SourceLocation OperatorLoc,
2704  bool IsArrow,
2705  NestedNameSpecifierLoc QualifierLoc,
2706  SourceLocation TemplateKWLoc,
2707  NamedDecl *FirstQualifierInScope,
2708  LookupResult &R,
2709  const TemplateArgumentListInfo *TemplateArgs) {
2710  CXXScopeSpec SS;
2711  SS.Adopt(QualifierLoc);
2712 
2713  return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2714  OperatorLoc, IsArrow,
2715  SS, TemplateKWLoc,
2716  FirstQualifierInScope,
2717  R, TemplateArgs, /*S*/nullptr);
2718  }
2719 
2720  /// \brief Build a new noexcept expression.
2721  ///
2722  /// By default, performs semantic analysis to build the new expression.
2723  /// Subclasses may override this routine to provide different behavior.
2725  return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2726  }
2727 
2728  /// \brief Build a new expression to compute the length of a parameter pack.
2730  NamedDecl *Pack,
2731  SourceLocation PackLoc,
2732  SourceLocation RParenLoc,
2734  ArrayRef<TemplateArgument> PartialArgs) {
2735  return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2736  RParenLoc, Length, PartialArgs);
2737  }
2738 
2739  /// \brief Build a new Objective-C boxed expression.
2740  ///
2741  /// By default, performs semantic analysis to build the new expression.
2742  /// Subclasses may override this routine to provide different behavior.
2744  return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2745  }
2746 
2747  /// \brief Build a new Objective-C array literal.
2748  ///
2749  /// By default, performs semantic analysis to build the new expression.
2750  /// Subclasses may override this routine to provide different behavior.
2752  Expr **Elements, unsigned NumElements) {
2753  return getSema().BuildObjCArrayLiteral(Range,
2754  MultiExprArg(Elements, NumElements));
2755  }
2756 
2758  Expr *Base, Expr *Key,
2759  ObjCMethodDecl *getterMethod,
2760  ObjCMethodDecl *setterMethod) {
2761  return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2762  getterMethod, setterMethod);
2763  }
2764 
2765  /// \brief Build a new Objective-C dictionary literal.
2766  ///
2767  /// By default, performs semantic analysis to build the new expression.
2768  /// Subclasses may override this routine to provide different behavior.
2771  return getSema().BuildObjCDictionaryLiteral(Range, Elements);
2772  }
2773 
2774  /// \brief Build a new Objective-C \@encode expression.
2775  ///
2776  /// By default, performs semantic analysis to build the new expression.
2777  /// Subclasses may override this routine to provide different behavior.
2779  TypeSourceInfo *EncodeTypeInfo,
2780  SourceLocation RParenLoc) {
2781  return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
2782  }
2783 
2784  /// \brief Build a new Objective-C class message.
2786  Selector Sel,
2787  ArrayRef<SourceLocation> SelectorLocs,
2788  ObjCMethodDecl *Method,
2789  SourceLocation LBracLoc,
2790  MultiExprArg Args,
2791  SourceLocation RBracLoc) {
2792  return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2793  ReceiverTypeInfo->getType(),
2794  /*SuperLoc=*/SourceLocation(),
2795  Sel, Method, LBracLoc, SelectorLocs,
2796  RBracLoc, Args);
2797  }
2798 
2799  /// \brief Build a new Objective-C instance message.
2801  Selector Sel,
2802  ArrayRef<SourceLocation> SelectorLocs,
2803  ObjCMethodDecl *Method,
2804  SourceLocation LBracLoc,
2805  MultiExprArg Args,
2806  SourceLocation RBracLoc) {
2807  return SemaRef.BuildInstanceMessage(Receiver,
2808  Receiver->getType(),
2809  /*SuperLoc=*/SourceLocation(),
2810  Sel, Method, LBracLoc, SelectorLocs,
2811  RBracLoc, Args);
2812  }
2813 
2814  /// \brief Build a new Objective-C instance/class message to 'super'.
2816  Selector Sel,
2817  ArrayRef<SourceLocation> SelectorLocs,
2818  QualType SuperType,
2819  ObjCMethodDecl *Method,
2820  SourceLocation LBracLoc,
2821  MultiExprArg Args,
2822  SourceLocation RBracLoc) {
2823  return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2824  SuperType,
2825  SuperLoc,
2826  Sel, Method, LBracLoc, SelectorLocs,
2827  RBracLoc, Args)
2828  : SemaRef.BuildClassMessage(nullptr,
2829  SuperType,
2830  SuperLoc,
2831  Sel, Method, LBracLoc, SelectorLocs,
2832  RBracLoc, Args);
2833 
2834 
2835  }
2836 
2837  /// \brief Build a new Objective-C ivar reference expression.
2838  ///
2839  /// By default, performs semantic analysis to build the new expression.
2840  /// Subclasses may override this routine to provide different behavior.
2842  SourceLocation IvarLoc,
2843  bool IsArrow, bool IsFreeIvar) {
2844  // FIXME: We lose track of the IsFreeIvar bit.
2845  CXXScopeSpec SS;
2846  DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2847  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2848  /*FIXME:*/IvarLoc, IsArrow,
2849  SS, SourceLocation(),
2850  /*FirstQualifierInScope=*/nullptr,
2851  NameInfo,
2852  /*TemplateArgs=*/nullptr,
2853  /*S=*/nullptr);
2854  }
2855 
2856  /// \brief Build a new Objective-C property reference expression.
2857  ///
2858  /// By default, performs semantic analysis to build the new expression.
2859  /// Subclasses may override this routine to provide different behavior.
2861  ObjCPropertyDecl *Property,
2862  SourceLocation PropertyLoc) {
2863  CXXScopeSpec SS;
2864  DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2865  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2866  /*FIXME:*/PropertyLoc,
2867  /*IsArrow=*/false,
2868  SS, SourceLocation(),
2869  /*FirstQualifierInScope=*/nullptr,
2870  NameInfo,
2871  /*TemplateArgs=*/nullptr,
2872  /*S=*/nullptr);
2873  }
2874 
2875  /// \brief Build a new Objective-C property reference expression.
2876  ///
2877  /// By default, performs semantic analysis to build the new expression.
2878  /// Subclasses may override this routine to provide different behavior.
2880  ObjCMethodDecl *Getter,
2881  ObjCMethodDecl *Setter,
2882  SourceLocation PropertyLoc) {
2883  // Since these expressions can only be value-dependent, we do not
2884  // need to perform semantic analysis again.
2885  return Owned(
2886  new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2888  PropertyLoc, Base));
2889  }
2890 
2891  /// \brief Build a new Objective-C "isa" expression.
2892  ///
2893  /// By default, performs semantic analysis to build the new expression.
2894  /// Subclasses may override this routine to provide different behavior.
2896  SourceLocation OpLoc, bool IsArrow) {
2897  CXXScopeSpec SS;
2898  DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2899  return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2900  OpLoc, IsArrow,
2901  SS, SourceLocation(),
2902  /*FirstQualifierInScope=*/nullptr,
2903  NameInfo,
2904  /*TemplateArgs=*/nullptr,
2905  /*S=*/nullptr);
2906  }
2907 
2908  /// \brief Build a new shuffle vector expression.
2909  ///
2910  /// By default, performs semantic analysis to build the new expression.
2911  /// Subclasses may override this routine to provide different behavior.
2913  MultiExprArg SubExprs,
2914  SourceLocation RParenLoc) {
2915  // Find the declaration for __builtin_shufflevector
2916  const IdentifierInfo &Name
2917  = SemaRef.Context.Idents.get("__builtin_shufflevector");
2918  TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2919  DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2920  assert(!Lookup.empty() && "No __builtin_shufflevector?");
2921 
2922  // Build a reference to the __builtin_shufflevector builtin
2923  FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
2924  Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2925  SemaRef.Context.BuiltinFnTy,
2926  VK_RValue, BuiltinLoc);
2927  QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2928  Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2929  CK_BuiltinFnToFnPtr).get();
2930 
2931  // Build the CallExpr
2932  ExprResult TheCall = new (SemaRef.Context) CallExpr(
2933  SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2934  Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
2935 
2936  // Type-check the __builtin_shufflevector expression.
2937  return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
2938  }
2939 
2940  /// \brief Build a new convert vector expression.
2942  Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2943  SourceLocation RParenLoc) {
2944  return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2945  BuiltinLoc, RParenLoc);
2946  }
2947 
2948  /// \brief Build a new template argument pack expansion.
2949  ///
2950  /// By default, performs semantic analysis to build a new pack expansion
2951  /// for a template argument. Subclasses may override this routine to provide
2952  /// different behavior.
2954  SourceLocation EllipsisLoc,
2955  Optional<unsigned> NumExpansions) {
2956  switch (Pattern.getArgument().getKind()) {
2959  = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2960  EllipsisLoc, NumExpansions);
2961  if (Result.isInvalid())
2962  return TemplateArgumentLoc();
2963 
2964  return TemplateArgumentLoc(Result.get(), Result.get());
2965  }
2966 
2969  Pattern.getArgument().getAsTemplate(),
2970  NumExpansions),
2971  Pattern.getTemplateQualifierLoc(),
2972  Pattern.getTemplateNameLoc(),
2973  EllipsisLoc);
2974 
2981  llvm_unreachable("Pack expansion pattern has no parameter packs");
2982 
2984  if (TypeSourceInfo *Expansion
2985  = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2986  EllipsisLoc,
2987  NumExpansions))
2988  return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2989  Expansion);
2990  break;
2991  }
2992 
2993  return TemplateArgumentLoc();
2994  }
2995 
2996  /// \brief Build a new expression pack expansion.
2997  ///
2998  /// By default, performs semantic analysis to build a new pack expansion
2999  /// for an expression. Subclasses may override this routine to provide
3000  /// different behavior.
3002  Optional<unsigned> NumExpansions) {
3003  return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3004  }
3005 
3006  /// \brief Build a new C++1z fold-expression.
3007  ///
3008  /// By default, performs semantic analysis in order to build a new fold
3009  /// expression.
3011  BinaryOperatorKind Operator,
3012  SourceLocation EllipsisLoc, Expr *RHS,
3013  SourceLocation RParenLoc) {
3014  return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3015  RHS, RParenLoc);
3016  }
3017 
3018  /// \brief Build an empty C++1z fold-expression with the given operator.
3019  ///
3020  /// By default, produces the fallback value for the fold-expression, or
3021  /// produce an error if there is no fallback value.
3023  BinaryOperatorKind Operator) {
3024  return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3025  }
3026 
3027  /// \brief Build a new atomic operation expression.
3028  ///
3029  /// By default, performs semantic analysis to build the new expression.
3030  /// Subclasses may override this routine to provide different behavior.
3032  MultiExprArg SubExprs,
3033  QualType RetTy,
3035  SourceLocation RParenLoc) {
3036  // Just create the expression; there is not any interesting semantic
3037  // analysis here because we can't actually build an AtomicExpr until
3038  // we are sure it is semantically sound.
3039  return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
3040  RParenLoc);
3041  }
3042 
3043 private:
3044  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3045  QualType ObjectType,
3046  NamedDecl *FirstQualifierInScope,
3047  CXXScopeSpec &SS);
3048 
3049  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3050  QualType ObjectType,
3051  NamedDecl *FirstQualifierInScope,
3052  CXXScopeSpec &SS);
3053 
3054  TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3055  NamedDecl *FirstQualifierInScope,
3056  CXXScopeSpec &SS);
3057 };
3058 
3059 template<typename Derived>
3061  if (!S)
3062  return S;
3063 
3064  switch (S->getStmtClass()) {
3065  case Stmt::NoStmtClass: break;
3066 
3067  // Transform individual statement nodes
3068 #define STMT(Node, Parent) \
3069  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3070 #define ABSTRACT_STMT(Node)
3071 #define EXPR(Node, Parent)
3072 #include "clang/AST/StmtNodes.inc"
3073 
3074  // Transform expressions by calling TransformExpr.
3075 #define STMT(Node, Parent)
3076 #define ABSTRACT_STMT(Stmt)
3077 #define EXPR(Node, Parent) case Stmt::Node##Class:
3078 #include "clang/AST/StmtNodes.inc"
3079  {
3080  ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3081  if (E.isInvalid())
3082  return StmtError();
3083 
3084  return getSema().ActOnExprStmt(E);
3085  }
3086  }
3087 
3088  return S;
3089 }
3090 
3091 template<typename Derived>
3093  if (!S)
3094  return S;
3095 
3096  switch (S->getClauseKind()) {
3097  default: break;
3098  // Transform individual clause nodes
3099 #define OPENMP_CLAUSE(Name, Class) \
3100  case OMPC_ ## Name : \
3101  return getDerived().Transform ## Class(cast<Class>(S));
3102 #include "clang/Basic/OpenMPKinds.def"
3103  }
3104 
3105  return S;
3106 }
3107 
3108 
3109 template<typename Derived>
3111  if (!E)
3112  return E;
3113 
3114  switch (E->getStmtClass()) {
3115  case Stmt::NoStmtClass: break;
3116 #define STMT(Node, Parent) case Stmt::Node##Class: break;
3117 #define ABSTRACT_STMT(Stmt)
3118 #define EXPR(Node, Parent) \
3119  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
3120 #include "clang/AST/StmtNodes.inc"
3121  }
3122 
3123  return E;
3124 }
3125 
3126 template<typename Derived>
3128  bool NotCopyInit) {
3129  // Initializers are instantiated like expressions, except that various outer
3130  // layers are stripped.
3131  if (!Init)
3132  return Init;
3133 
3134  if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3135  Init = ExprTemp->getSubExpr();
3136 
3137  if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3138  Init = MTE->GetTemporaryExpr();
3139 
3140  while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3141  Init = Binder->getSubExpr();
3142 
3143  if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3144  Init = ICE->getSubExprAsWritten();
3145 
3146  if (CXXStdInitializerListExpr *ILE =
3147  dyn_cast<CXXStdInitializerListExpr>(Init))
3148  return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
3149 
3150  // If this is copy-initialization, we only need to reconstruct
3151  // InitListExprs. Other forms of copy-initialization will be a no-op if
3152  // the initializer is already the right type.
3153  CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
3154  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
3155  return getDerived().TransformExpr(Init);
3156 
3157  // Revert value-initialization back to empty parens.
3158  if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3159  SourceRange Parens = VIE->getSourceRange();
3160  return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
3161  Parens.getEnd());
3162  }
3163 
3164  // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3165  if (isa<ImplicitValueInitExpr>(Init))
3166  return getDerived().RebuildParenListExpr(SourceLocation(), None,
3167  SourceLocation());
3168 
3169  // Revert initialization by constructor back to a parenthesized or braced list
3170  // of expressions. Any other form of initializer can just be reused directly.
3171  if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
3172  return getDerived().TransformExpr(Init);
3173 
3174  // If the initialization implicitly converted an initializer list to a
3175  // std::initializer_list object, unwrap the std::initializer_list too.
3176  if (Construct && Construct->isStdInitListInitialization())
3177  return TransformInitializer(Construct->getArg(0), NotCopyInit);
3178 
3179  SmallVector<Expr*, 8> NewArgs;
3180  bool ArgChanged = false;
3181  if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
3182  /*IsCall*/true, NewArgs, &ArgChanged))
3183  return ExprError();
3184 
3185  // If this was list initialization, revert to list form.
3186  if (Construct->isListInitialization())
3187  return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3188  Construct->getLocEnd(),
3189  Construct->getType());
3190 
3191  // Build a ParenListExpr to represent anything else.
3192  SourceRange Parens = Construct->getParenOrBraceRange();
3193  if (Parens.isInvalid()) {
3194  // This was a variable declaration's initialization for which no initializer
3195  // was specified.
3196  assert(NewArgs.empty() &&
3197  "no parens or braces but have direct init with arguments?");
3198  return ExprEmpty();
3199  }
3200  return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3201  Parens.getEnd());
3202 }
3203 
3204 template<typename Derived>
3206  unsigned NumInputs,
3207  bool IsCall,
3208  SmallVectorImpl<Expr *> &Outputs,
3209  bool *ArgChanged) {
3210  for (unsigned I = 0; I != NumInputs; ++I) {
3211  // If requested, drop call arguments that need to be dropped.
3212  if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3213  if (ArgChanged)
3214  *ArgChanged = true;
3215 
3216  break;
3217  }
3218 
3219  if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3220  Expr *Pattern = Expansion->getPattern();
3221 
3223  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3224  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3225 
3226  // Determine whether the set of unexpanded parameter packs can and should
3227  // be expanded.
3228  bool Expand = true;
3229  bool RetainExpansion = false;
3230  Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3231  Optional<unsigned> NumExpansions = OrigNumExpansions;
3232  if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3233  Pattern->getSourceRange(),
3234  Unexpanded,
3235  Expand, RetainExpansion,
3236  NumExpansions))
3237  return true;
3238 
3239  if (!Expand) {
3240  // The transform has determined that we should perform a simple
3241  // transformation on the pack expansion, producing another pack
3242  // expansion.
3243  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3244  ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3245  if (OutPattern.isInvalid())
3246  return true;
3247 
3248  ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
3249  Expansion->getEllipsisLoc(),
3250  NumExpansions);
3251  if (Out.isInvalid())
3252  return true;
3253 
3254  if (ArgChanged)
3255  *ArgChanged = true;
3256  Outputs.push_back(Out.get());
3257  continue;
3258  }
3259 
3260  // Record right away that the argument was changed. This needs
3261  // to happen even if the array expands to nothing.
3262  if (ArgChanged) *ArgChanged = true;
3263 
3264  // The transform has determined that we should perform an elementwise
3265  // expansion of the pattern. Do so.
3266  for (unsigned I = 0; I != *NumExpansions; ++I) {
3267  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3268  ExprResult Out = getDerived().TransformExpr(Pattern);
3269  if (Out.isInvalid())
3270  return true;
3271 
3272  // FIXME: Can this happen? We should not try to expand the pack
3273  // in this case.
3274  if (Out.get()->containsUnexpandedParameterPack()) {
3275  Out = getDerived().RebuildPackExpansion(
3276  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3277  if (Out.isInvalid())
3278  return true;
3279  }
3280 
3281  Outputs.push_back(Out.get());
3282  }
3283 
3284  // If we're supposed to retain a pack expansion, do so by temporarily
3285  // forgetting the partially-substituted parameter pack.
3286  if (RetainExpansion) {
3287  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3288 
3289  ExprResult Out = getDerived().TransformExpr(Pattern);
3290  if (Out.isInvalid())
3291  return true;
3292 
3293  Out = getDerived().RebuildPackExpansion(
3294  Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3295  if (Out.isInvalid())
3296  return true;
3297 
3298  Outputs.push_back(Out.get());
3299  }
3300 
3301  continue;
3302  }
3303 
3304  ExprResult Result =
3305  IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3306  : getDerived().TransformExpr(Inputs[I]);
3307  if (Result.isInvalid())
3308  return true;
3309 
3310  if (Result.get() != Inputs[I] && ArgChanged)
3311  *ArgChanged = true;
3312 
3313  Outputs.push_back(Result.get());
3314  }
3315 
3316  return false;
3317 }
3318 
3319 template<typename Derived>
3323  QualType ObjectType,
3324  NamedDecl *FirstQualifierInScope) {
3326  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
3327  Qualifier = Qualifier.getPrefix())
3328  Qualifiers.push_back(Qualifier);
3329 
3330  CXXScopeSpec SS;
3331  while (!Qualifiers.empty()) {
3332  NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3334 
3335  switch (QNNS->getKind()) {
3337  if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
3338  *QNNS->getAsIdentifier(),
3339  Q.getLocalBeginLoc(),
3340  Q.getLocalEndLoc(),
3341  ObjectType, false, SS,
3342  FirstQualifierInScope, false))
3343  return NestedNameSpecifierLoc();
3344 
3345  break;
3346 
3348  NamespaceDecl *NS
3349  = cast_or_null<NamespaceDecl>(
3350  getDerived().TransformDecl(
3351  Q.getLocalBeginLoc(),
3352  QNNS->getAsNamespace()));
3353  SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3354  break;
3355  }
3356 
3358  NamespaceAliasDecl *Alias
3359  = cast_or_null<NamespaceAliasDecl>(
3360  getDerived().TransformDecl(Q.getLocalBeginLoc(),
3361  QNNS->getAsNamespaceAlias()));
3362  SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
3363  Q.getLocalEndLoc());
3364  break;
3365  }
3366 
3368  // There is no meaningful transformation that one could perform on the
3369  // global scope.
3370  SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3371  break;
3372 
3374  CXXRecordDecl *RD =
3375  cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3376  SourceLocation(), QNNS->getAsRecordDecl()));
3377  SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3378  break;
3379  }
3380 
3383  TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3384  FirstQualifierInScope, SS);
3385 
3386  if (!TL)
3387  return NestedNameSpecifierLoc();
3388 
3389  if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
3390  (SemaRef.getLangOpts().CPlusPlus11 &&
3391  TL.getType()->isEnumeralType())) {
3392  assert(!TL.getType().hasLocalQualifiers() &&
3393  "Can't get cv-qualifiers here");
3394  if (TL.getType()->isEnumeralType())
3395  SemaRef.Diag(TL.getBeginLoc(),
3396  diag::warn_cxx98_compat_enum_nested_name_spec);
3397  SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3398  Q.getLocalEndLoc());
3399  break;
3400  }
3401  // If the nested-name-specifier is an invalid type def, don't emit an
3402  // error because a previous error should have already been emitted.
3403  TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3404  if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
3405  SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
3406  << TL.getType() << SS.getRange();
3407  }
3408  return NestedNameSpecifierLoc();
3409  }
3410  }
3411 
3412  // The qualifier-in-scope and object type only apply to the leftmost entity.
3413  FirstQualifierInScope = nullptr;
3414  ObjectType = QualType();
3415  }
3416 
3417  // Don't rebuild the nested-name-specifier if we don't have to.
3418  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
3419  !getDerived().AlwaysRebuild())
3420  return NNS;
3421 
3422  // If we can re-use the source-location data from the original
3423  // nested-name-specifier, do so.
3424  if (SS.location_size() == NNS.getDataLength() &&
3425  memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3426  return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3427 
3428  // Allocate new nested-name-specifier location information.
3429  return SS.getWithLocInContext(SemaRef.Context);
3430 }
3431 
3432 template<typename Derived>
3436  DeclarationName Name = NameInfo.getName();
3437  if (!Name)
3438  return DeclarationNameInfo();
3439 
3440  switch (Name.getNameKind()) {
3448  return NameInfo;
3449 
3453  TypeSourceInfo *NewTInfo;
3454  CanQualType NewCanTy;
3455  if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
3456  NewTInfo = getDerived().TransformType(OldTInfo);
3457  if (!NewTInfo)
3458  return DeclarationNameInfo();
3459  NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
3460  }
3461  else {
3462  NewTInfo = nullptr;
3463  TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
3464  QualType NewT = getDerived().TransformType(Name.getCXXNameType());
3465  if (NewT.isNull())
3466  return DeclarationNameInfo();
3467  NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3468  }
3469 
3470  DeclarationName NewName
3471  = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3472  NewCanTy);
3473  DeclarationNameInfo NewNameInfo(NameInfo);
3474  NewNameInfo.setName(NewName);
3475  NewNameInfo.setNamedTypeInfo(NewTInfo);
3476  return NewNameInfo;
3477  }
3478  }
3479 
3480  llvm_unreachable("Unknown name kind.");
3481 }
3482 
3483 template<typename Derived>
3487  SourceLocation NameLoc,
3488  QualType ObjectType,
3489  NamedDecl *FirstQualifierInScope) {
3491  TemplateDecl *Template = QTN->getTemplateDecl();
3492  assert(Template && "qualified template name must refer to a template");
3493 
3494  TemplateDecl *TransTemplate
3495  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3496  Template));
3497  if (!TransTemplate)
3498  return TemplateName();
3499 
3500  if (!getDerived().AlwaysRebuild() &&
3501  SS.getScopeRep() == QTN->getQualifier() &&
3502  TransTemplate == Template)
3503  return Name;
3504 
3505  return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3506  TransTemplate);
3507  }
3508 
3510  if (SS.getScopeRep()) {
3511  // These apply to the scope specifier, not the template.
3512  ObjectType = QualType();
3513  FirstQualifierInScope = nullptr;
3514  }
3515 
3516  if (!getDerived().AlwaysRebuild() &&
3517  SS.getScopeRep() == DTN->getQualifier() &&
3518  ObjectType.isNull())
3519  return Name;
3520 
3521  if (DTN->isIdentifier()) {
3522  return getDerived().RebuildTemplateName(SS,
3523  *DTN->getIdentifier(),
3524  NameLoc,
3525  ObjectType,
3526  FirstQualifierInScope);
3527  }
3528 
3529  return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3530  ObjectType);
3531  }
3532 
3533  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3534  TemplateDecl *TransTemplate
3535  = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
3536  Template));
3537  if (!TransTemplate)
3538  return TemplateName();
3539 
3540  if (!getDerived().AlwaysRebuild() &&
3541  TransTemplate == Template)
3542  return Name;
3543 
3544  return TemplateName(TransTemplate);
3545  }
3546 
3549  TemplateTemplateParmDecl *TransParam
3550  = cast_or_null<TemplateTemplateParmDecl>(
3551  getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3552  if (!TransParam)
3553  return TemplateName();
3554 
3555  if (!getDerived().AlwaysRebuild() &&
3556  TransParam == SubstPack->getParameterPack())
3557  return Name;
3558 
3559  return getDerived().RebuildTemplateName(TransParam,
3560  SubstPack->getArgumentPack());
3561  }
3562 
3563  // These should be getting filtered out before they reach the AST.
3564  llvm_unreachable("overloaded function decl survived to here");
3565 }
3566 
3567 template<typename Derived>
3569  const TemplateArgument &Arg,
3570  TemplateArgumentLoc &Output) {
3571  SourceLocation Loc = getDerived().getBaseLocation();
3572  switch (Arg.getKind()) {
3574  llvm_unreachable("null template argument in TreeTransform");
3575  break;
3576 
3578  Output = TemplateArgumentLoc(Arg,
3579  SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
3580 
3581  break;
3582 
3587  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3588  Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3589  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3590  Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
3591 
3592  if (Arg.getKind() == TemplateArgument::Template)
3593  Output = TemplateArgumentLoc(Arg,
3594  Builder.getWithLocInContext(SemaRef.Context),
3595  Loc);
3596  else
3597  Output = TemplateArgumentLoc(Arg,
3598  Builder.getWithLocInContext(SemaRef.Context),
3599  Loc, Loc);
3600 
3601  break;
3602  }
3603 
3605  Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3606  break;
3607 
3613  break;
3614  }
3615 }
3616 
3617 template<typename Derived>
3619  const TemplateArgumentLoc &Input,
3620  TemplateArgumentLoc &Output, bool Uneval) {
3621  const TemplateArgument &Arg = Input.getArgument();
3622  switch (Arg.getKind()) {
3628  llvm_unreachable("Unexpected TemplateArgument");
3629 
3630  case TemplateArgument::Type: {
3631  TypeSourceInfo *DI = Input.getTypeSourceInfo();
3632  if (!DI)
3633  DI = InventTypeSourceInfo(Input.getArgument().getAsType());
3634 
3635  DI = getDerived().TransformType(DI);
3636  if (!DI) return true;
3637 
3638  Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3639  return false;
3640  }
3641 
3643  NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3644  if (QualifierLoc) {
3645  QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3646  if (!QualifierLoc)
3647  return true;
3648  }
3649 
3650  CXXScopeSpec SS;
3651  SS.Adopt(QualifierLoc);
3652  TemplateName Template
3653  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3654  Input.getTemplateNameLoc());
3655  if (Template.isNull())
3656  return true;
3657 
3658  Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3659  Input.getTemplateNameLoc());
3660  return false;
3661  }
3662 
3664  llvm_unreachable("Caller should expand pack expansions");
3665 
3667  // Template argument expressions are constant expressions.
3669  getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
3670 
3671  Expr *InputExpr = Input.getSourceExpression();
3672  if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3673 
3674  ExprResult E = getDerived().TransformExpr(InputExpr);
3675  E = SemaRef.ActOnConstantExpression(E);
3676  if (E.isInvalid()) return true;
3677  Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
3678  return false;
3679  }
3680  }
3681 
3682  // Work around bogus GCC warning
3683  return true;
3684 }
3685 
3686 /// \brief Iterator adaptor that invents template argument location information
3687 /// for each of the template arguments in its underlying iterator.
3688 template<typename Derived, typename InputIterator>
3690  TreeTransform<Derived> &Self;
3691  InputIterator Iter;
3692 
3693 public:
3696  typedef typename std::iterator_traits<InputIterator>::difference_type
3698  typedef std::input_iterator_tag iterator_category;
3699 
3700  class pointer {
3701  TemplateArgumentLoc Arg;
3702 
3703  public:
3704  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3705 
3706  const TemplateArgumentLoc *operator->() const { return &Arg; }
3707  };
3708 
3710 
3712  InputIterator Iter)
3713  : Self(Self), Iter(Iter) { }
3714 
3716  ++Iter;
3717  return *this;
3718  }
3719 
3722  ++(*this);
3723  return Old;
3724  }
3725 
3728  Self.InventTemplateArgumentLoc(*Iter, Result);
3729  return Result;
3730  }
3731 
3732  pointer operator->() const { return pointer(**this); }
3733 
3736  return X.Iter == Y.Iter;
3737  }
3738 
3741  return X.Iter != Y.Iter;
3742  }
3743 };
3744 
3745 template<typename Derived>
3746 template<typename InputIterator>
3748  InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3749  bool Uneval) {
3750  for (; First != Last; ++First) {
3751  TemplateArgumentLoc Out;
3752  TemplateArgumentLoc In = *First;
3753 
3754  if (In.getArgument().getKind() == TemplateArgument::Pack) {
3755  // Unpack argument packs, which we translate them into separate
3756  // arguments.
3757  // FIXME: We could do much better if we could guarantee that the
3758  // TemplateArgumentLocInfo for the pack expansion would be usable for
3759  // all of the template arguments in the argument pack.
3760  typedef TemplateArgumentLocInventIterator<Derived,
3762  PackLocIterator;
3763  if (TransformTemplateArguments(PackLocIterator(*this,
3764  In.getArgument().pack_begin()),
3765  PackLocIterator(*this,
3766  In.getArgument().pack_end()),
3767  Outputs, Uneval))
3768  return true;
3769 
3770  continue;
3771  }
3772 
3773  if (In.getArgument().isPackExpansion()) {
3774  // We have a pack expansion, for which we will be substituting into
3775  // the pattern.
3776  SourceLocation Ellipsis;
3777  Optional<unsigned> OrigNumExpansions;
3778  TemplateArgumentLoc Pattern
3779  = getSema().getTemplateArgumentPackExpansionPattern(
3780  In, Ellipsis, OrigNumExpansions);
3781 
3783  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3784  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3785 
3786  // Determine whether the set of unexpanded parameter packs can and should
3787  // be expanded.
3788  bool Expand = true;
3789  bool RetainExpansion = false;
3790  Optional<unsigned> NumExpansions = OrigNumExpansions;
3791  if (getDerived().TryExpandParameterPacks(Ellipsis,
3792  Pattern.getSourceRange(),
3793  Unexpanded,
3794  Expand,
3795  RetainExpansion,
3796  NumExpansions))
3797  return true;
3798 
3799  if (!Expand) {
3800  // The transform has determined that we should perform a simple
3801  // transformation on the pack expansion, producing another pack
3802  // expansion.
3803  TemplateArgumentLoc OutPattern;
3804  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3805  if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
3806  return true;
3807 
3808  Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3809  NumExpansions);
3810  if (Out.getArgument().isNull())
3811  return true;
3812 
3813  Outputs.addArgument(Out);
3814  continue;
3815  }
3816 
3817  // The transform has determined that we should perform an elementwise
3818  // expansion of the pattern. Do so.
3819  for (unsigned I = 0; I != *NumExpansions; ++I) {
3820  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3821 
3822  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3823  return true;
3824 
3826  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3827  OrigNumExpansions);
3828  if (Out.getArgument().isNull())
3829  return true;
3830  }
3831 
3832  Outputs.addArgument(Out);
3833  }
3834 
3835  // If we're supposed to retain a pack expansion, do so by temporarily
3836  // forgetting the partially-substituted parameter pack.
3837  if (RetainExpansion) {
3838  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3839 
3840  if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
3841  return true;
3842 
3843  Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3844  OrigNumExpansions);
3845  if (Out.getArgument().isNull())
3846  return true;
3847 
3848  Outputs.addArgument(Out);
3849  }
3850 
3851  continue;
3852  }
3853 
3854  // The simple case:
3855  if (getDerived().TransformTemplateArgument(In, Out, Uneval))
3856  return true;
3857 
3858  Outputs.addArgument(Out);
3859  }
3860 
3861  return false;
3862 
3863 }
3864 
3865 //===----------------------------------------------------------------------===//
3866 // Type transformation
3867 //===----------------------------------------------------------------------===//
3868 
3869 template<typename Derived>
3871  if (getDerived().AlreadyTransformed(T))
3872  return T;
3873 
3874  // Temporary workaround. All of these transformations should
3875  // eventually turn into transformations on TypeLocs.
3876  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3877  getDerived().getBaseLocation());
3878 
3879  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
3880 
3881  if (!NewDI)
3882  return QualType();
3883 
3884  return NewDI->getType();
3885 }
3886 
3887 template<typename Derived>
3889  // Refine the base location to the type's location.
3890  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3891  getDerived().getBaseEntity());
3892  if (getDerived().AlreadyTransformed(DI->getType()))
3893  return DI;
3894 
3895  TypeLocBuilder TLB;
3896 
3897  TypeLoc TL = DI->getTypeLoc();
3898  TLB.reserve(TL.getFullDataSize());
3899 
3900  QualType Result = getDerived().TransformType(TLB, TL);
3901  if (Result.isNull())
3902  return nullptr;
3903 
3904  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3905 }
3906 
3907 template<typename Derived>
3908 QualType
3910  switch (T.getTypeLocClass()) {
3911 #define ABSTRACT_TYPELOC(CLASS, PARENT)
3912 #define TYPELOC(CLASS, PARENT) \
3913  case TypeLoc::CLASS: \
3914  return getDerived().Transform##CLASS##Type(TLB, \
3915  T.castAs<CLASS##TypeLoc>());
3916 #include "clang/AST/TypeLocNodes.def"
3917  }
3918 
3919  llvm_unreachable("unhandled type loc!");
3920 }
3921 
3922 /// FIXME: By default, this routine adds type qualifiers only to types
3923 /// that can have qualifiers, and silently suppresses those qualifiers
3924 /// that are not permitted (e.g., qualifiers on reference or function
3925 /// types). This is the right thing for template instantiation, but
3926 /// probably not for other clients.
3927 template<typename Derived>
3928 QualType
3930  QualifiedTypeLoc T) {
3931  Qualifiers Quals = T.getType().getLocalQualifiers();
3932 
3933  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3934  if (Result.isNull())
3935  return QualType();
3936 
3937  // Silently suppress qualifiers if the result type can't be qualified.
3938  // FIXME: this is the right thing for template instantiation, but
3939  // probably not for other clients.
3940  if (Result->isFunctionType() || Result->isReferenceType())
3941  return Result;
3942 
3943  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3944  // resulting type.
3945  if (Quals.hasObjCLifetime()) {
3946  if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3947  Quals.removeObjCLifetime();
3948  else if (Result.getObjCLifetime()) {
3949  // Objective-C ARC:
3950  // A lifetime qualifier applied to a substituted template parameter
3951  // overrides the lifetime qualifier from the template argument.
3952  const AutoType *AutoTy;
3953  if (const SubstTemplateTypeParmType *SubstTypeParam
3954  = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3955  QualType Replacement = SubstTypeParam->getReplacementType();
3956  Qualifiers Qs = Replacement.getQualifiers();
3957  Qs.removeObjCLifetime();
3958  Replacement
3959  = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3960  Qs);
3961  Result = SemaRef.Context.getSubstTemplateTypeParmType(
3962  SubstTypeParam->getReplacedParameter(),
3963  Replacement);
3964  TLB.TypeWasModifiedSafely(Result);
3965  } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3966  // 'auto' types behave the same way as template parameters.
3967  QualType Deduced = AutoTy->getDeducedType();
3968  Qualifiers Qs = Deduced.getQualifiers();
3969  Qs.removeObjCLifetime();
3970  Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3971  Qs);
3972  Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
3973  AutoTy->isDependentType());
3974  TLB.TypeWasModifiedSafely(Result);
3975  } else {
3976  // Otherwise, complain about the addition of a qualifier to an
3977  // already-qualified type.
3978  SourceRange R = T.getUnqualifiedLoc().getSourceRange();
3979  SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
3980  << Result << R;
3981 
3982  Quals.removeObjCLifetime();
3983  }
3984  }
3985  }
3986  if (!Quals.empty()) {
3987  Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3988  // BuildQualifiedType might not add qualifiers if they are invalid.
3989  if (Result.hasLocalQualifiers())
3990  TLB.push<QualifiedTypeLoc>(Result);
3991  // No location information to preserve.
3992  }
3993 
3994  return Result;
3995 }
3996 
3997 template<typename Derived>
3998 TypeLoc
3999 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4000  QualType ObjectType,
4001  NamedDecl *UnqualLookup,
4002  CXXScopeSpec &SS) {
4003  if (getDerived().AlreadyTransformed(TL.getType()))
4004  return TL;
4005 
4006  TypeSourceInfo *TSI =
4007  TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4008  if (TSI)
4009  return TSI->getTypeLoc();
4010  return TypeLoc();
4011 }
4012 
4013 template<typename Derived>
4014 TypeSourceInfo *
4015 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4016  QualType ObjectType,
4017  NamedDecl *UnqualLookup,
4018  CXXScopeSpec &SS) {
4019  if (getDerived().AlreadyTransformed(TSInfo->getType()))
4020  return TSInfo;
4021 
4022  return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4023  UnqualLookup, SS);
4024 }
4025 
4026 template <typename Derived>
4027 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4028  TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4029  CXXScopeSpec &SS) {
4030  QualType T = TL.getType();
4031  assert(!getDerived().AlreadyTransformed(T));
4032 
4033  TypeLocBuilder TLB;
4034  QualType Result;
4035 
4036  if (isa<TemplateSpecializationType>(T)) {
4037  TemplateSpecializationTypeLoc SpecTL =
4038  TL.castAs<TemplateSpecializationTypeLoc>();
4039 
4040  TemplateName Template
4041  = getDerived().TransformTemplateName(SS,
4042  SpecTL.getTypePtr()->getTemplateName(),
4043  SpecTL.getTemplateNameLoc(),
4044  ObjectType, UnqualLookup);
4045  if (Template.isNull())
4046  return nullptr;
4047 
4048  Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
4049  Template);
4050  } else if (isa<DependentTemplateSpecializationType>(T)) {
4051  DependentTemplateSpecializationTypeLoc SpecTL =
4052  TL.castAs<DependentTemplateSpecializationTypeLoc>();
4053 
4054  TemplateName Template
4055  = getDerived().RebuildTemplateName(SS,
4056  *SpecTL.getTypePtr()->getIdentifier(),
4057  SpecTL.getTemplateNameLoc(),
4058  ObjectType, UnqualLookup);
4059  if (Template.isNull())
4060  return nullptr;
4061 
4062  Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
4063  SpecTL,
4064  Template,
4065  SS);
4066  } else {
4067  // Nothing special needs to be done for these.
4068  Result = getDerived().TransformType(TLB, TL);
4069  }
4070 
4071  if (Result.isNull())
4072  return nullptr;
4073 
4074  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4075 }
4076 
4077 template <class TyLoc> static inline
4079  TyLoc NewT = TLB.push<TyLoc>(T.getType());
4080  NewT.setNameLoc(T.getNameLoc());
4081  return T.getType();
4082 }
4083 
4084 template<typename Derived>
4085 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
4086  BuiltinTypeLoc T) {
4087  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4088  NewT.setBuiltinLoc(T.getBuiltinLoc());
4089  if (T.needsExtraLocalData())
4090  NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4091  return T.getType();
4092 }
4093 
4094 template<typename Derived>
4095 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
4096  ComplexTypeLoc T) {
4097  // FIXME: recurse?
4098  return TransformTypeSpecType(TLB, T);
4099 }
4100 
4101 template <typename Derived>
4102 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4103  AdjustedTypeLoc TL) {
4104  // Adjustments applied during transformation are handled elsewhere.
4105  return getDerived().TransformType(TLB, TL.getOriginalLoc());
4106 }
4107 
4108 template<typename Derived>
4109 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4110  DecayedTypeLoc TL) {
4111  QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4112  if (OriginalType.isNull())
4113  return QualType();
4114 
4115  QualType Result = TL.getType();
4116  if (getDerived().AlwaysRebuild() ||
4117  OriginalType != TL.getOriginalLoc().getType())
4118  Result = SemaRef.Context.getDecayedType(OriginalType);
4119  TLB.push<DecayedTypeLoc>(Result);
4120  // Nothing to set for DecayedTypeLoc.
4121  return Result;
4122 }
4123 
4124 template<typename Derived>
4125 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
4126  PointerTypeLoc TL) {
4127  QualType PointeeType
4128  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4129  if (PointeeType.isNull())
4130  return QualType();
4131 
4132  QualType Result = TL.getType();
4133  if (PointeeType->getAs<ObjCObjectType>()) {
4134  // A dependent pointer type 'T *' has is being transformed such
4135  // that an Objective-C class type is being replaced for 'T'. The
4136  // resulting pointer type is an ObjCObjectPointerType, not a
4137  // PointerType.
4138  Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
4139 
4140  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4141  NewT.setStarLoc(TL.getStarLoc());
4142  return Result;
4143  }
4144 
4145  if (getDerived().AlwaysRebuild() ||
4146  PointeeType != TL.getPointeeLoc().getType()) {
4147  Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4148  if (Result.isNull())
4149  return QualType();
4150  }
4151 
4152  // Objective-C ARC can add lifetime qualifiers to the type that we're
4153  // pointing to.
4154  TLB.TypeWasModifiedSafely(Result->getPointeeType());
4155 
4156  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4157  NewT.setSigilLoc(TL.getSigilLoc());
4158  return Result;
4159 }
4160 
4161 template<typename Derived>
4162 QualType
4163 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
4164  BlockPointerTypeLoc TL) {
4165  QualType PointeeType
4166  = getDerived().TransformType(TLB, TL.getPointeeLoc());
4167  if (PointeeType.isNull())
4168  return QualType();
4169 
4170  QualType Result = TL.getType();
4171  if (getDerived().AlwaysRebuild() ||
4172  PointeeType != TL.getPointeeLoc().getType()) {
4173  Result = getDerived().RebuildBlockPointerType(PointeeType,
4174  TL.getSigilLoc());
4175  if (Result.isNull())
4176  return QualType();
4177  }
4178 
4179  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
4180  NewT.setSigilLoc(TL.getSigilLoc());
4181  return Result;
4182 }
4183 
4184 /// Transforms a reference type. Note that somewhat paradoxically we
4185 /// don't care whether the type itself is an l-value type or an r-value
4186 /// type; we only care if the type was *written* as an l-value type
4187 /// or an r-value type.
4188 template<typename Derived>
4189 QualType
4191  ReferenceTypeLoc TL) {
4192  const ReferenceType *T = TL.getTypePtr();
4193 
4194  // Note that this works with the pointee-as-written.
4195  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4196  if (PointeeType.isNull())
4197  return QualType();
4198 
4199  QualType Result = TL.getType();
4200  if (getDerived().AlwaysRebuild() ||
4201  PointeeType != T->getPointeeTypeAsWritten()) {
4202  Result = getDerived().RebuildReferenceType(PointeeType,
4203  T->isSpelledAsLValue(),
4204  TL.getSigilLoc());
4205  if (Result.isNull())
4206  return QualType();
4207  }
4208 
4209  // Objective-C ARC can add lifetime qualifiers to the type that we're
4210  // referring to.
4213 
4214  // r-value references can be rebuilt as l-value references.
4215  ReferenceTypeLoc NewTL;
4216  if (isa<LValueReferenceType>(Result))
4217  NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4218  else
4219  NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4220  NewTL.setSigilLoc(TL.getSigilLoc());
4221 
4222  return Result;
4223 }
4224 
4225 template<typename Derived>
4226 QualType
4229  return TransformReferenceType(TLB, TL);
4230 }
4231 
4232 template<typename Derived>
4233 QualType
4234 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
4235  RValueReferenceTypeLoc TL) {
4236  return TransformReferenceType(TLB, TL);
4237 }
4238 
4239 template<typename Derived>
4240 QualType
4241 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
4242  MemberPointerTypeLoc TL) {
4243  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4244  if (PointeeType.isNull())
4245  return QualType();
4246 
4247  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
4248  TypeSourceInfo *NewClsTInfo = nullptr;
4249  if (OldClsTInfo) {
4250  NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4251  if (!NewClsTInfo)
4252  return QualType();
4253  }
4254 
4255  const MemberPointerType *T = TL.getTypePtr();
4256  QualType OldClsType = QualType(T->getClass(), 0);
4257  QualType NewClsType;
4258  if (NewClsTInfo)
4259  NewClsType = NewClsTInfo->getType();
4260  else {
4261  NewClsType = getDerived().TransformType(OldClsType);
4262  if (NewClsType.isNull())
4263  return QualType();
4264  }
4265 
4266  QualType Result = TL.getType();
4267  if (getDerived().AlwaysRebuild() ||
4268  PointeeType != T->getPointeeType() ||
4269  NewClsType != OldClsType) {
4270  Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
4271  TL.getStarLoc());
4272  if (Result.isNull())
4273  return QualType();
4274  }
4275 
4276  // If we had to adjust the pointee type when building a member pointer, make
4277  // sure to push TypeLoc info for it.
4278  const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4279  if (MPT && PointeeType != MPT->getPointeeType()) {
4280  assert(isa<AdjustedType>(MPT->getPointeeType()));
4281  TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4282  }
4283 
4284  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4285  NewTL.setSigilLoc(TL.getSigilLoc());
4286  NewTL.setClassTInfo(NewClsTInfo);
4287 
4288  return Result;
4289 }
4290 
4291 template<typename Derived>
4292 QualType
4293 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
4294  ConstantArrayTypeLoc TL) {
4295  const ConstantArrayType *T = TL.getTypePtr();
4296  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4297  if (ElementType.isNull())
4298  return QualType();
4299 
4300  QualType Result = TL.getType();
4301  if (getDerived().AlwaysRebuild() ||
4302  ElementType != T->getElementType()) {
4303  Result = getDerived().RebuildConstantArrayType(ElementType,
4304  T->getSizeModifier(),
4305  T->getSize(),
4306  T->getIndexTypeCVRQualifiers(),
4307  TL.getBracketsRange());
4308  if (Result.isNull())
4309  return QualType();
4310  }
4311 
4312  // We might have either a ConstantArrayType or a VariableArrayType now:
4313  // a ConstantArrayType is allowed to have an element type which is a
4314  // VariableArrayType if the type is dependent. Fortunately, all array
4315  // types have the same location layout.
4316  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4317  NewTL.setLBracketLoc(TL.getLBracketLoc());
4318  NewTL.setRBracketLoc(TL.getRBracketLoc());
4319 
4320  Expr *Size = TL.getSizeExpr();
4321  if (Size) {
4322  EnterExpressionEvaluationContext Unevaluated(SemaRef,
4324  Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4325  Size = SemaRef.ActOnConstantExpression(Size).get();
4326  }
4327  NewTL.setSizeExpr(Size);
4328 
4329  return Result;
4330 }
4331 
4332 template<typename Derived>
4333 QualType TreeTransform<Derived>::TransformIncompleteArrayType(
4334  TypeLocBuilder &TLB,
4335  IncompleteArrayTypeLoc TL) {
4336  const IncompleteArrayType *T = TL.getTypePtr();
4337  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4338  if (ElementType.isNull())
4339  return QualType();
4340 
4341  QualType Result = TL.getType();
4342  if (getDerived().AlwaysRebuild() ||
4343  ElementType != T->getElementType()) {
4344  Result = getDerived().RebuildIncompleteArrayType(ElementType,
4345  T->getSizeModifier(),
4346  T->getIndexTypeCVRQualifiers(),
4347  TL.getBracketsRange());
4348  if (Result.isNull())
4349  return QualType();
4350  }
4351 
4352  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4353  NewTL.setLBracketLoc(TL.getLBracketLoc());
4354  NewTL.setRBracketLoc(TL.getRBracketLoc());
4355  NewTL.setSizeExpr(nullptr);
4356 
4357  return Result;
4358 }
4359 
4360 template<typename Derived>
4361 QualType
4362 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
4363  VariableArrayTypeLoc TL) {
4364  const VariableArrayType *T = TL.getTypePtr();
4365  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4366  if (ElementType.isNull())
4367  return QualType();
4368 
4369  ExprResult SizeResult
4370  = getDerived().TransformExpr(T->getSizeExpr());
4371  if (SizeResult.isInvalid())
4372  return QualType();
4373 
4374  Expr *Size = SizeResult.get();
4375 
4376  QualType Result = TL.getType();
4377  if (getDerived().AlwaysRebuild() ||
4378  ElementType != T->getElementType() ||
4379  Size != T->getSizeExpr()) {
4380  Result = getDerived().RebuildVariableArrayType(ElementType,
4381  T->getSizeModifier(),
4382  Size,
4383  T->getIndexTypeCVRQualifiers(),
4384  TL.getBracketsRange());
4385  if (Result.isNull())
4386  return QualType();
4387  }
4388 
4389  // We might have constant size array now, but fortunately it has the same
4390  // location layout.
4391  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4392  NewTL.setLBracketLoc(TL.getLBracketLoc());
4393  NewTL.setRBracketLoc(TL.getRBracketLoc());
4394  NewTL.setSizeExpr(Size);
4395 
4396  return Result;
4397 }
4398 
4399 template<typename Derived>
4400 QualType
4401 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
4402  DependentSizedArrayTypeLoc TL) {
4403  const DependentSizedArrayType *T = TL.getTypePtr();
4404  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4405  if (ElementType.isNull())
4406  return QualType();
4407 
4408  // Array bounds are constant expressions.
4409  EnterExpressionEvaluationContext Unevaluated(SemaRef,
4411 
4412  // Prefer the expression from the TypeLoc; the other may have been uniqued.
4413  Expr *origSize = TL.getSizeExpr();
4414  if (!origSize) origSize = T->getSizeExpr();
4415 
4416  ExprResult sizeResult
4417  = getDerived().TransformExpr(origSize);
4418  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
4419  if (sizeResult.isInvalid())
4420  return QualType();
4421 
4422  Expr *size = sizeResult.get();
4423 
4424  QualType Result = TL.getType();
4425  if (getDerived().AlwaysRebuild() ||
4426  ElementType != T->getElementType() ||
4427  size != origSize) {
4428  Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4429  T->getSizeModifier(),
4430  size,
4431  T->getIndexTypeCVRQualifiers(),
4432  TL.getBracketsRange());
4433  if (Result.isNull())
4434  return QualType();
4435  }
4436 
4437  // We might have any sort of array type now, but fortunately they
4438  // all have the same location layout.
4439  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4440  NewTL.setLBracketLoc(TL.getLBracketLoc());
4441  NewTL.setRBracketLoc(TL.getRBracketLoc());
4442  NewTL.setSizeExpr(size);
4443 
4444  return Result;
4445 }
4446 
4447 template<typename Derived>
4448 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
4449  TypeLocBuilder &TLB,
4450  DependentSizedExtVectorTypeLoc TL) {
4451  const DependentSizedExtVectorType *T = TL.getTypePtr();
4452 
4453  // FIXME: ext vector locs should be nested
4454  QualType ElementType = getDerived().TransformType(T->getElementType());
4455  if (ElementType.isNull())
4456  return QualType();
4457 
4458  // Vector sizes are constant expressions.
4459  EnterExpressionEvaluationContext Unevaluated(SemaRef,
4461 
4462  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4463  Size = SemaRef.ActOnConstantExpression(Size);
4464  if (Size.isInvalid())
4465  return QualType();
4466 
4467  QualType Result = TL.getType();
4468  if (getDerived().AlwaysRebuild() ||
4469  ElementType != T->getElementType() ||
4470  Size.get() != T->getSizeExpr()) {
4471  Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
4472  Size.get(),
4473  T->getAttributeLoc());
4474  if (Result.isNull())
4475  return QualType();
4476  }
4477 
4478  // Result might be dependent or not.
4479  if (isa<DependentSizedExtVectorType>(Result)) {
4480  DependentSizedExtVectorTypeLoc NewTL
4481  = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4482  NewTL.setNameLoc(TL.getNameLoc());
4483  } else {
4484  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4485  NewTL.setNameLoc(TL.getNameLoc());
4486  }
4487 
4488  return Result;
4489 }
4490 
4491 template<typename Derived>
4492 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
4493  VectorTypeLoc TL) {
4494  const VectorType *T = TL.getTypePtr();
4495  QualType ElementType = getDerived().TransformType(T->getElementType());
4496  if (ElementType.isNull())
4497  return QualType();
4498 
4499  QualType Result = TL.getType();
4500  if (getDerived().AlwaysRebuild() ||
4501  ElementType != T->getElementType()) {
4502  Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
4503  T->getVectorKind());
4504  if (Result.isNull())
4505  return QualType();
4506  }
4507 
4508  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4509  NewTL.setNameLoc(TL.getNameLoc());
4510 
4511  return Result;
4512 }
4513 
4514 template<typename Derived>
4515 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
4516  ExtVectorTypeLoc TL) {
4517  const VectorType *T = TL.getTypePtr();
4518  QualType ElementType = getDerived().TransformType(T->getElementType());
4519  if (ElementType.isNull())
4520  return QualType();
4521 
4522  QualType Result = TL.getType();
4523  if (getDerived().AlwaysRebuild() ||
4524  ElementType != T->getElementType()) {
4525  Result = getDerived().RebuildExtVectorType(ElementType,
4526  T->getNumElements(),
4527  /*FIXME*/ SourceLocation());
4528  if (Result.isNull())
4529  return QualType();
4530  }
4531 
4532  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4533  NewTL.setNameLoc(TL.getNameLoc());
4534 
4535  return Result;
4536 }
4537 
4538 template <typename Derived>
4540  ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4541  bool ExpectParameterPack) {
4542  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
4543  TypeSourceInfo *NewDI = nullptr;
4544 
4545  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
4546  // If we're substituting into a pack expansion type and we know the
4547  // length we want to expand to, just substitute for the pattern.
4548  TypeLoc OldTL = OldDI->getTypeLoc();
4549  PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
4550 
4551  TypeLocBuilder TLB;
4552  TypeLoc NewTL = OldDI->getTypeLoc();
4553  TLB.reserve(NewTL.getFullDataSize());
4554 
4555  QualType Result = getDerived().TransformType(TLB,
4556  OldExpansionTL.getPatternLoc());
4557  if (Result.isNull())
4558  return nullptr;
4559 
4560  Result = RebuildPackExpansionType(Result,
4561  OldExpansionTL.getPatternLoc().getSourceRange(),
4562  OldExpansionTL.getEllipsisLoc(),
4563  NumExpansions);
4564  if (Result.isNull())
4565  return nullptr;
4566 
4567  PackExpansionTypeLoc NewExpansionTL
4568  = TLB.push<PackExpansionTypeLoc>(Result);
4569  NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4570  NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4571  } else
4572  NewDI = getDerived().TransformType(OldDI);
4573  if (!NewDI)
4574  return nullptr;
4575 
4576  if (NewDI == OldDI && indexAdjustment == 0)
4577  return OldParm;
4578 
4579  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4580  OldParm->getDeclContext(),
4581  OldParm->getInnerLocStart(),
4582  OldParm->getLocation(),
4583  OldParm->getIdentifier(),
4584  NewDI->getType(),
4585  NewDI,
4586  OldParm->getStorageClass(),
4587  /* DefArg */ nullptr);
4588  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4589  OldParm->getFunctionScopeIndex() + indexAdjustment);
4590  return newParm;
4591 }
4592 
4593 template<typename Derived>
4596  ParmVarDecl **Params, unsigned NumParams,
4597  const QualType *ParamTypes,
4598  SmallVectorImpl<QualType> &OutParamTypes,
4600  int indexAdjustment = 0;
4601 
4602  for (unsigned i = 0; i != NumParams; ++i) {
4603  if (ParmVarDecl *OldParm = Params[i]) {
4604  assert(OldParm->getFunctionScopeIndex() == i);
4605 
4606  Optional<unsigned> NumExpansions;
4607  ParmVarDecl *NewParm = nullptr;
4608  if (OldParm->isParameterPack()) {
4609  // We have a function parameter pack that may need to be expanded.
4611 
4612  // Find the parameter packs that could be expanded.
4613  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4614  PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
4615  TypeLoc Pattern = ExpansionTL.getPatternLoc();
4616  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
4617  assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4618 
4619  // Determine whether we should expand the parameter packs.
4620  bool ShouldExpand = false;
4621  bool RetainExpansion = false;
4622  Optional<unsigned> OrigNumExpansions =
4623  ExpansionTL.getTypePtr()->getNumExpansions();
4624  NumExpansions = OrigNumExpansions;
4625  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4626  Pattern.getSourceRange(),
4627  Unexpanded,
4628  ShouldExpand,
4629  RetainExpansion,
4630  NumExpansions)) {
4631  return true;
4632  }
4633 
4634  if (ShouldExpand) {
4635  // Expand the function parameter pack into multiple, separate
4636  // parameters.
4637  getDerived().ExpandingFunctionParameterPack(OldParm);
4638  for (unsigned I = 0; I != *NumExpansions; ++I) {
4639  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4640  ParmVarDecl *NewParm
4641  = getDerived().TransformFunctionTypeParam(OldParm,
4642  indexAdjustment++,
4643  OrigNumExpansions,
4644  /*ExpectParameterPack=*/false);
4645  if (!NewParm)
4646  return true;
4647 
4648  OutParamTypes.push_back(NewParm->getType());
4649  if (PVars)
4650  PVars->push_back(NewParm);
4651  }
4652 
4653  // If we're supposed to retain a pack expansion, do so by temporarily
4654  // forgetting the partially-substituted parameter pack.
4655  if (RetainExpansion) {
4656  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4657  ParmVarDecl *NewParm
4658  = getDerived().TransformFunctionTypeParam(OldParm,
4659  indexAdjustment++,
4660  OrigNumExpansions,
4661  /*ExpectParameterPack=*/false);
4662  if (!NewParm)
4663  return true;
4664 
4665  OutParamTypes.push_back(NewParm->getType());
4666  if (PVars)
4667  PVars->push_back(NewParm);
4668  }
4669 
4670  // The next parameter should have the same adjustment as the
4671  // last thing we pushed, but we post-incremented indexAdjustment
4672  // on every push. Also, if we push nothing, the adjustment should
4673  // go down by one.
4674  indexAdjustment--;
4675 
4676  // We're done with the pack expansion.
4677  continue;
4678  }
4679 
4680  // We'll substitute the parameter now without expanding the pack
4681  // expansion.
4682  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4683  NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4684  indexAdjustment,
4685  NumExpansions,
4686  /*ExpectParameterPack=*/true);
4687  } else {
4688  NewParm = getDerived().TransformFunctionTypeParam(
4689  OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
4690  }
4691 
4692  if (!NewParm)
4693  return true;
4694 
4695  OutParamTypes.push_back(NewParm->getType());
4696  if (PVars)
4697  PVars->push_back(NewParm);
4698  continue;
4699  }
4700 
4701  // Deal with the possibility that we don't have a parameter
4702  // declaration for this parameter.
4703  QualType OldType = ParamTypes[i];
4704  bool IsPackExpansion = false;
4705  Optional<unsigned> NumExpansions;
4706  QualType NewType;
4707  if (const PackExpansionType *Expansion
4708  = dyn_cast<PackExpansionType>(OldType)) {
4709  // We have a function parameter pack that may need to be expanded.
4710  QualType Pattern = Expansion->getPattern();
4712  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4713 
4714  // Determine whether we should expand the parameter packs.
4715  bool ShouldExpand = false;
4716  bool RetainExpansion = false;
4717  if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
4718  Unexpanded,
4719  ShouldExpand,
4720  RetainExpansion,
4721  NumExpansions)) {
4722  return true;
4723  }
4724 
4725  if (ShouldExpand) {
4726  // Expand the function parameter pack into multiple, separate
4727  // parameters.
4728  for (unsigned I = 0; I != *NumExpansions; ++I) {
4729  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4730  QualType NewType = getDerived().TransformType(Pattern);
4731  if (NewType.isNull())
4732  return true;
4733 
4734  OutParamTypes.push_back(NewType);
4735  if (PVars)
4736  PVars->push_back(nullptr);
4737  }
4738 
4739  // We're done with the pack expansion.
4740  continue;
4741  }
4742 
4743  // If we're supposed to retain a pack expansion, do so by temporarily
4744  // forgetting the partially-substituted parameter pack.
4745  if (RetainExpansion) {
4746  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4747  QualType NewType = getDerived().TransformType(Pattern);
4748  if (NewType.isNull())
4749  return true;
4750 
4751  OutParamTypes.push_back(NewType);
4752  if (PVars)
4753  PVars->push_back(nullptr);
4754  }
4755 
4756  // We'll substitute the parameter now without expanding the pack
4757  // expansion.
4758  OldType = Expansion->getPattern();
4759  IsPackExpansion = true;
4760  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4761  NewType = getDerived().TransformType(OldType);
4762  } else {
4763  NewType = getDerived().TransformType(OldType);
4764  }
4765 
4766  if (NewType.isNull())
4767  return true;
4768 
4769  if (IsPackExpansion)
4770  NewType = getSema().Context.getPackExpansionType(NewType,
4771  NumExpansions);
4772 
4773  OutParamTypes.push_back(NewType);
4774  if (PVars)
4775  PVars->push_back(nullptr);
4776  }
4777 
4778 #ifndef NDEBUG
4779  if (PVars) {
4780  for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4781  if (ParmVarDecl *parm = (*PVars)[i])
4782  assert(parm->getFunctionScopeIndex() == i);
4783  }
4784 #endif
4785 
4786  return false;
4787 }
4788 
4789 template<typename Derived>
4790 QualType
4792  FunctionProtoTypeLoc TL) {
4793  SmallVector<QualType, 4> ExceptionStorage;
4794  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
4795  return getDerived().TransformFunctionProtoType(
4796  TLB, TL, nullptr, 0,
4797  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4798  return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4799  ExceptionStorage, Changed);
4800  });
4801 }
4802 
4803 template<typename Derived> template<typename Fn>
4805  TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4806  unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
4807  // Transform the parameters and return type.
4808  //
4809  // We are required to instantiate the params and return type in source order.
4810  // When the function has a trailing return type, we instantiate the
4811  // parameters before the return type, since the return type can then refer
4812  // to the parameters themselves (via decltype, sizeof, etc.).
4813  //
4814  SmallVector<QualType, 4> ParamTypes;
4815  SmallVector<ParmVarDecl*, 4> ParamDecls;
4816  const FunctionProtoType *T = TL.getTypePtr();
4817 
4818  QualType ResultType;
4819 
4820  if (T->hasTrailingReturn()) {
4821  if (getDerived().TransformFunctionTypeParams(
4822  TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
4823  TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
4824  return QualType();
4825 
4826  {
4827  // C++11 [expr.prim.general]p3:
4828  // If a declaration declares a member function or member function
4829  // template of a class X, the expression this is a prvalue of type
4830  // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4831  // and the end of the function-definition, member-declarator, or
4832  // declarator.
4833  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4834 
4835  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4836  if (ResultType.isNull())
4837  return QualType();
4838  }
4839  }
4840  else {
4841  ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4842  if (ResultType.isNull())
4843  return QualType();
4844 
4845  if (getDerived().TransformFunctionTypeParams(
4846  TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
4847  TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
4848  return QualType();
4849  }
4850 
4852 
4853  bool EPIChanged = false;
4854  if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4855  return QualType();
4856 
4857  // FIXME: Need to transform ConsumedParameters for variadic template
4858  // expansion.
4859 
4860  QualType Result = TL.getType();
4861  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
4862  T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
4863  Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
4864  if (Result.isNull())
4865  return QualType();
4866  }
4867 
4868  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4870  NewTL.setLParenLoc(TL.getLParenLoc());
4871  NewTL.setRParenLoc(TL.getRParenLoc());
4872  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4873  for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4874  NewTL.setParam(i, ParamDecls[i]);
4875 
4876  return Result;
4877 }
4878 
4879 template<typename Derived>
4882  SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4883  assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4884 
4885  // Instantiate a dynamic noexcept expression, if any.
4886  if (ESI.Type == EST_ComputedNoexcept) {
4887  EnterExpressionEvaluationContext Unevaluated(getSema(),
4889  ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4890  if (NoexceptExpr.isInvalid())
4891  return true;
4892 
4893  NoexceptExpr = getSema().CheckBooleanCondition(
4894  NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4895  if (NoexceptExpr.isInvalid())
4896  return true;
4897 
4898  if (!NoexceptExpr.get()->isValueDependent()) {
4899  NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4900  NoexceptExpr.get(), nullptr,
4901  diag::err_noexcept_needs_constant_expression,
4902  /*AllowFold*/false);
4903  if (NoexceptExpr.isInvalid())
4904  return true;
4905  }
4906 
4907  if (ESI.NoexceptExpr != NoexceptExpr.get())
4908  Changed = true;
4909  ESI.NoexceptExpr = NoexceptExpr.get();
4910  }
4911 
4912  if (ESI.Type != EST_Dynamic)
4913  return false;
4914 
4915  // Instantiate a dynamic exception specification's type.
4916  for (QualType T : ESI.Exceptions) {
4917  if (const PackExpansionType *PackExpansion =
4918  T->getAs<PackExpansionType>()) {
4919  Changed = true;
4920 
4921  // We have a pack expansion. Instantiate it.
4923  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4924  Unexpanded);
4925  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4926 
4927  // Determine whether the set of unexpanded parameter packs can and
4928  // should
4929  // be expanded.
4930  bool Expand = false;
4931  bool RetainExpansion = false;
4932  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4933  // FIXME: Track the location of the ellipsis (and track source location
4934  // information for the types in the exception specification in general).
4935  if (getDerived().TryExpandParameterPacks(
4936  Loc, SourceRange(), Unexpanded, Expand,
4937  RetainExpansion, NumExpansions))
4938  return true;
4939 
4940  if (!Expand) {
4941  // We can't expand this pack expansion into separate arguments yet;
4942  // just substitute into the pattern and create a new pack expansion
4943  // type.
4944  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4945  QualType U = getDerived().TransformType(PackExpansion->getPattern());
4946  if (U.isNull())
4947  return true;
4948 
4949  U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4950  Exceptions.push_back(U);
4951  continue;
4952  }
4953 
4954  // Substitute into the pack expansion pattern for each slice of the
4955  // pack.
4956  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4957  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4958 
4959  QualType U = getDerived().TransformType(PackExpansion->getPattern());
4960  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4961  return true;
4962 
4963  Exceptions.push_back(U);
4964  }
4965  } else {
4966  QualType U = getDerived().TransformType(T);
4967  if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4968  return true;
4969  if (T != U)
4970  Changed = true;
4971 
4972  Exceptions.push_back(U);
4973  }
4974  }
4975 
4976  ESI.Exceptions = Exceptions;
4977  return false;
4978 }
4979 
4980 template<typename Derived>
4982  TypeLocBuilder &TLB,
4984  const FunctionNoProtoType *T = TL.getTypePtr();
4985  QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
4986  if (ResultType.isNull())
4987  return QualType();
4988 
4989  QualType Result = TL.getType();
4990  if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
4991  Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4992 
4993  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4995  NewTL.setLParenLoc(TL.getLParenLoc());
4996  NewTL.setRParenLoc(TL.getRParenLoc());
4997  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4998 
4999  return Result;
5000 }
5001 
5002 template<typename Derived> QualType
5003 TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
5004  UnresolvedUsingTypeLoc TL) {
5005  const UnresolvedUsingType *T = TL.getTypePtr();
5006  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
5007  if (!D)
5008  return QualType();
5009 
5010  QualType Result = TL.getType();
5011  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5012  Result = getDerived().RebuildUnresolvedUsingType(D);
5013  if (Result.isNull())
5014  return QualType();
5015  }
5016 
5017  // We might get an arbitrary type spec type back. We should at
5018  // least always get a type spec type, though.
5019  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5020  NewTL.setNameLoc(TL.getNameLoc());
5021 
5022  return Result;
5023 }
5024 
5025 template<typename Derived>
5026 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
5027  TypedefTypeLoc TL) {
5028  const TypedefType *T = TL.getTypePtr();
5029  TypedefNameDecl *Typedef
5030  = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5031  T->getDecl()));
5032  if (!Typedef)
5033  return QualType();
5034 
5035  QualType Result = TL.getType();
5036  if (getDerived().AlwaysRebuild() ||
5037  Typedef != T->getDecl()) {
5038  Result = getDerived().RebuildTypedefType(Typedef);
5039  if (Result.isNull())
5040  return QualType();
5041  }
5042 
5043  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5044  NewTL.setNameLoc(TL.getNameLoc());
5045 
5046  return Result;
5047 }
5048 
5049 template<typename Derived>
5050 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
5051  TypeOfExprTypeLoc TL) {
5052  // typeof expressions are not potentially evaluated contexts
5053  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5055 
5056  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
5057  if (E.isInvalid())
5058  return QualType();
5059 
5060  E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5061  if (E.isInvalid())
5062  return QualType();
5063 
5064  QualType Result = TL.getType();
5065  if (getDerived().AlwaysRebuild() ||
5066  E.get() != TL.getUnderlyingExpr()) {
5067  Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
5068  if (Result.isNull())
5069  return QualType();
5070  }
5071  else E.get();
5072 
5073  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
5074  NewTL.setTypeofLoc(TL.getTypeofLoc());
5075  NewTL.setLParenLoc(TL.getLParenLoc());
5076  NewTL.setRParenLoc(TL.getRParenLoc());
5077 
5078  return Result;
5079 }
5080 
5081 template<typename Derived>
5082 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
5083  TypeOfTypeLoc TL) {
5084  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5085  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5086  if (!New_Under_TI)
5087  return QualType();
5088 
5089  QualType Result = TL.getType();
5090  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5091  Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
5092  if (Result.isNull())
5093  return QualType();
5094  }
5095 
5096  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
5097  NewTL.setTypeofLoc(TL.getTypeofLoc());
5098  NewTL.setLParenLoc(TL.getLParenLoc());
5099  NewTL.setRParenLoc(TL.getRParenLoc());
5100  NewTL.setUnderlyingTInfo(New_Under_TI);
5101 
5102  return Result;
5103 }
5104 
5105 template<typename Derived>
5106 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
5107  DecltypeTypeLoc TL) {
5108  const DecltypeType *T = TL.getTypePtr();
5109 
5110  // decltype expressions are not potentially evaluated contexts
5111  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5112  nullptr, /*IsDecltype=*/ true);
5113 
5114  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
5115  if (E.isInvalid())
5116  return QualType();
5117 
5118  E = getSema().ActOnDecltypeExpression(E.get());
5119  if (E.isInvalid())
5120  return QualType();
5121 
5122  QualType Result = TL.getType();
5123  if (getDerived().AlwaysRebuild() ||
5124  E.get() != T->getUnderlyingExpr()) {
5125  Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
5126  if (Result.isNull())
5127  return QualType();
5128  }
5129  else E.get();
5130 
5131  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5132  NewTL.setNameLoc(TL.getNameLoc());
5133 
5134  return Result;
5135 }
5136 
5137 template<typename Derived>
5138 QualType TreeTransform<Derived>::TransformUnaryTransformType(
5139  TypeLocBuilder &TLB,
5140  UnaryTransformTypeLoc TL) {
5141  QualType Result = TL.getType();
5142  if (Result->isDependentType()) {
5143  const UnaryTransformType *T = TL.getTypePtr();
5144  QualType NewBase =
5145  getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5146  Result = getDerived().RebuildUnaryTransformType(NewBase,
5147  T->getUTTKind(),
5148  TL.getKWLoc());
5149  if (Result.isNull())
5150  return QualType();
5151  }
5152 
5153  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5154  NewTL.setKWLoc(TL.getKWLoc());
5155  NewTL.setParensRange(TL.getParensRange());
5156  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5157  return Result;
5158 }
5159 
5160 template<typename Derived>
5161 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5162  AutoTypeLoc TL) {
5163  const AutoType *T = TL.getTypePtr();
5164  QualType OldDeduced = T->getDeducedType();
5165  QualType NewDeduced;
5166  if (!OldDeduced.isNull()) {
5167  NewDeduced = getDerived().TransformType(OldDeduced);
5168  if (NewDeduced.isNull())
5169  return QualType();
5170  }
5171 
5172  QualType Result = TL.getType();
5173  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5174  T->isDependentType()) {
5175  Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
5176  if (Result.isNull())
5177  return QualType();
5178  }
5179 
5180  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5181  NewTL.setNameLoc(TL.getNameLoc());
5182 
5183  return Result;
5184 }
5185 
5186 template<typename Derived>
5187 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
5188  RecordTypeLoc TL) {
5189  const RecordType *T = TL.getTypePtr();
5190  RecordDecl *Record
5191  = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5192  T->getDecl()));
5193  if (!Record)
5194  return QualType();
5195 
5196  QualType Result = TL.getType();
5197  if (getDerived().AlwaysRebuild() ||
5198  Record != T->getDecl()) {
5199  Result = getDerived().RebuildRecordType(Record);
5200  if (Result.isNull())
5201  return QualType();
5202  }
5203 
5204  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5205  NewTL.setNameLoc(TL.getNameLoc());
5206 
5207  return Result;
5208 }
5209 
5210 template<typename Derived>
5211 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
5212  EnumTypeLoc TL) {
5213  const EnumType *T = TL.getTypePtr();
5214  EnumDecl *Enum
5215  = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5216  T->getDecl()));
5217  if (!Enum)
5218  return QualType();
5219 
5220  QualType Result = TL.getType();
5221  if (getDerived().AlwaysRebuild() ||
5222  Enum != T->getDecl()) {
5223  Result = getDerived().RebuildEnumType(Enum);
5224  if (Result.isNull())
5225  return QualType();
5226  }
5227 
5228  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5229  NewTL.setNameLoc(TL.getNameLoc());
5230 
5231  return Result;
5232 }
5233 
5234 template<typename Derived>
5235 QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5236  TypeLocBuilder &TLB,
5237  InjectedClassNameTypeLoc TL) {
5238  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5239  TL.getTypePtr()->getDecl());
5240  if (!D) return QualType();
5241 
5242  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5243  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5244  return T;
5245 }
5246 
5247 template<typename Derived>
5248 QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
5249  TypeLocBuilder &TLB,
5250  TemplateTypeParmTypeLoc TL) {
5251  return TransformTypeSpecType(TLB, TL);
5252 }
5253 
5254 template<typename Derived>
5255 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
5256  TypeLocBuilder &TLB,
5257  SubstTemplateTypeParmTypeLoc TL) {
5258  const SubstTemplateTypeParmType *T = TL.getTypePtr();
5259 
5260  // Substitute into the replacement type, which itself might involve something
5261  // that needs to be transformed. This only tends to occur with default
5262  // template arguments of template template parameters.
5263  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5264  QualType Replacement = getDerived().TransformType(T->getReplacementType());
5265  if (Replacement.isNull())
5266  return QualType();
5267 
5268  // Always canonicalize the replacement type.
5269  Replacement = SemaRef.Context.getCanonicalType(Replacement);
5270  QualType Result
5271  = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
5272  Replacement);
5273 
5274  // Propagate type-source information.
5275  SubstTemplateTypeParmTypeLoc NewTL
5276  = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5277  NewTL.setNameLoc(TL.getNameLoc());
5278  return Result;
5279 
5280 }
5281 
5282 template<typename Derived>
5283 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5284  TypeLocBuilder &TLB,
5285  SubstTemplateTypeParmPackTypeLoc TL) {
5286  return TransformTypeSpecType(TLB, TL);
5287 }
5288 
5289 template<typename Derived>
5291  TypeLocBuilder &TLB,
5293  const TemplateSpecializationType *T = TL.getTypePtr();
5294 
5295  // The nested-name-specifier never matters in a TemplateSpecializationType,
5296  // because we can't have a dependent nested-name-specifier anyway.
5297  CXXScopeSpec SS;
5298  TemplateName Template
5299  = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5300  TL.getTemplateNameLoc());
5301  if (Template.isNull())
5302  return QualType();
5303 
5304  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5305 }
5306 
5307 template<typename Derived>
5309  AtomicTypeLoc TL) {
5310  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5311  if (ValueType.isNull())
5312  return QualType();
5313 
5314  QualType Result = TL.getType();
5315  if (getDerived().AlwaysRebuild() ||
5316  ValueType != TL.getValueLoc().getType()) {
5317  Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5318  if (Result.isNull())
5319  return QualType();
5320  }
5321 
5322  AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5323  NewTL.setKWLoc(TL.getKWLoc());
5324  NewTL.setLParenLoc(TL.getLParenLoc());
5325  NewTL.setRParenLoc(TL.getRParenLoc());
5326 
5327  return Result;
5328 }
5329 
5330 template <typename Derived>
5331 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5332  PipeTypeLoc TL) {
5333  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5334  if (ValueType.isNull())
5335  return QualType();
5336 
5337  QualType Result = TL.getType();
5338  if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
5339  Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc());
5340  if (Result.isNull())
5341  return QualType();
5342  }
5343 
5344  PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5345  NewTL.setKWLoc(TL.getKWLoc());
5346 
5347  return Result;
5348 }
5349 
5350  /// \brief Simple iterator that traverses the template arguments in a
5351  /// container that provides a \c getArgLoc() member function.
5352  ///
5353  /// This iterator is intended to be used with the iterator form of
5354  /// \c TreeTransform<Derived>::TransformTemplateArguments().
5355  template<typename ArgLocContainer>
5357  ArgLocContainer *Container;
5358  unsigned Index;
5359 
5360  public:
5363  typedef int difference_type;
5364  typedef std::input_iterator_tag iterator_category;
5365 
5366  class pointer {
5367  TemplateArgumentLoc Arg;
5368 
5369  public:
5370  explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5371 
5373  return &Arg;
5374  }
5375  };
5376 
5377 
5379 
5380  TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5381  unsigned Index)
5382  : Container(&Container), Index(Index) { }
5383 
5385  ++Index;
5386  return *this;
5387  }
5388 
5391  ++(*this);
5392  return Old;
5393  }
5394 
5396  return Container->getArgLoc(Index);
5397  }
5398 
5400  return pointer(Container->getArgLoc(Index));
5401  }
5402 
5405  return X.Container == Y.Container && X.Index == Y.Index;
5406  }
5407 
5410  return !(X == Y);
5411  }
5412  };
5413 
5414 
5415 template <typename Derived>
5417  TypeLocBuilder &TLB,
5418  TemplateSpecializationTypeLoc TL,
5419  TemplateName Template) {
5420  TemplateArgumentListInfo NewTemplateArgs;
5421  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5422  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5423  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5424  ArgIterator;
5425  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5426  ArgIterator(TL, TL.getNumArgs()),
5427  NewTemplateArgs))
5428  return QualType();
5429 
5430  // FIXME: maybe don't rebuild if all the template arguments are the same.
5431 
5432  QualType Result =
5433  getDerived().RebuildTemplateSpecializationType(Template,
5434  TL.getTemplateNameLoc(),
5435  NewTemplateArgs);
5436 
5437  if (!Result.isNull()) {
5438  // Specializations of template template parameters are represented as
5439  // TemplateSpecializationTypes, and substitution of type alias templates
5440  // within a dependent context can transform them into
5441  // DependentTemplateSpecializationTypes.
5442  if (isa<DependentTemplateSpecializationType>(Result)) {
5443  DependentTemplateSpecializationTypeLoc NewTL
5444  = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
5445  NewTL.setElaboratedKeywordLoc(SourceLocation());
5446  NewTL.setQualifierLoc(NestedNameSpecifierLoc());
5447  NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5448  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5449  NewTL.setLAngleLoc(TL.getLAngleLoc());
5450  NewTL.setRAngleLoc(TL.getRAngleLoc());
5451  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5452  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5453  return Result;
5454  }
5455 
5456  TemplateSpecializationTypeLoc NewTL
5457  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5458  NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
5459  NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5460  NewTL.setLAngleLoc(TL.getLAngleLoc());
5461  NewTL.setRAngleLoc(TL.getRAngleLoc());
5462  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5463  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5464  }
5465 
5466  return Result;
5467 }
5468 
5469 template <typename Derived>
5471  TypeLocBuilder &TLB,
5473  TemplateName Template,
5474  CXXScopeSpec &SS) {
5475  TemplateArgumentListInfo NewTemplateArgs;
5476  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5477  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5480  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5481  ArgIterator(TL, TL.getNumArgs()),
5482  NewTemplateArgs))
5483  return QualType();
5484 
5485  // FIXME: maybe don't rebuild if all the template arguments are the same.
5486 
5487  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5488  QualType Result
5489  = getSema().Context.getDependentTemplateSpecializationType(
5490  TL.getTypePtr()->getKeyword(),
5491  DTN->getQualifier(),
5492  DTN->getIdentifier(),
5493  NewTemplateArgs);
5494 
5498  NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
5501  NewTL.setLAngleLoc(TL.getLAngleLoc());
5502  NewTL.setRAngleLoc(TL.getRAngleLoc());
5503  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5504  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5505  return Result;
5506  }
5507 
5508  QualType Result
5509  = getDerived().RebuildTemplateSpecializationType(Template,
5510  TL.getTemplateNameLoc(),
5511  NewTemplateArgs);
5512 
5513  if (!Result.isNull()) {
5514  /// FIXME: Wrap this in an elaborated-type-specifier?
5516  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5519  NewTL.setLAngleLoc(TL.getLAngleLoc());
5520  NewTL.setRAngleLoc(TL.getRAngleLoc());
5521  for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5522  NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5523  }
5524 
5525  return Result;
5526 }
5527 
5528 template<typename Derived>
5529 QualType
5531  ElaboratedTypeLoc TL) {
5532  const ElaboratedType *T = TL.getTypePtr();
5533 
5534  NestedNameSpecifierLoc QualifierLoc;
5535  // NOTE: the qualifier in an ElaboratedType is optional.
5536  if (TL.getQualifierLoc()) {
5537  QualifierLoc
5538  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5539  if (!QualifierLoc)
5540  return QualType();
5541  }
5542 
5543  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5544  if (NamedT.isNull())
5545  return QualType();
5546 
5547  // C++0x [dcl.type.elab]p2:
5548  // If the identifier resolves to a typedef-name or the simple-template-id
5549  // resolves to an alias template specialization, the
5550  // elaborated-type-specifier is ill-formed.
5551  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5552  if (const TemplateSpecializationType *TST =
5553  NamedT->getAs<TemplateSpecializationType>()) {
5554  TemplateName Template = TST->getTemplateName();
5555  if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5556  Template.getAsTemplateDecl())) {
5557  SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5558  diag::err_tag_reference_non_tag) << 4;
5559  SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5560  }
5561  }
5562  }
5563 
5564  QualType Result = TL.getType();
5565  if (getDerived().AlwaysRebuild() ||
5566  QualifierLoc != TL.getQualifierLoc() ||
5567  NamedT != T->getNamedType()) {
5568  Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
5569  T->getKeyword(),
5570  QualifierLoc, NamedT);
5571  if (Result.isNull())
5572  return QualType();
5573  }
5574 
5575  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5576  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5577  NewTL.setQualifierLoc(QualifierLoc);
5578  return Result;
5579 }
5580 
5581 template<typename Derived>
5582 QualType TreeTransform<Derived>::TransformAttributedType(
5583  TypeLocBuilder &TLB,
5584  AttributedTypeLoc TL) {
5585  const AttributedType *oldType = TL.getTypePtr();
5586  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5587  if (modifiedType.isNull())
5588  return QualType();
5589 
5590  QualType result = TL.getType();
5591 
5592  // FIXME: dependent operand expressions?
5593  if (getDerived().AlwaysRebuild() ||
5594  modifiedType != oldType->getModifiedType()) {
5595  // TODO: this is really lame; we should really be rebuilding the
5596  // equivalent type from first principles.
5597  QualType equivalentType
5598  = getDerived().TransformType(oldType->getEquivalentType());
5599  if (equivalentType.isNull())
5600  return QualType();
5601 
5602  // Check whether we can add nullability; it is only represented as
5603  // type sugar, and therefore cannot be diagnosed in any other way.
5604  if (auto nullability = oldType->getImmediateNullability()) {
5605  if (!modifiedType->canHaveNullability()) {
5606  SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
5607  << DiagNullabilityKind(*nullability, false) << modifiedType;
5608  return QualType();
5609  }
5610  }
5611 
5612  result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5613  modifiedType,
5614  equivalentType);
5615  }
5616 
5617  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5618  newTL.setAttrNameLoc(TL.getAttrNameLoc());
5619  if (TL.hasAttrOperand())
5620  newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5621  if (TL.hasAttrExprOperand())
5622  newTL.setAttrExprOperand(TL.getAttrExprOperand());
5623  else if (TL.hasAttrEnumOperand())
5624  newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5625 
5626  return result;
5627 }
5628 
5629 template<typename Derived>
5630 QualType
5631 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5632  ParenTypeLoc TL) {
5633  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5634  if (Inner.isNull())
5635  return QualType();
5636 
5637  QualType Result = TL.getType();
5638  if (getDerived().AlwaysRebuild() ||
5639  Inner != TL.getInnerLoc().getType()) {
5640  Result = getDerived().RebuildParenType(Inner);
5641  if (Result.isNull())
5642  return QualType();
5643  }
5644 
5645  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5646  NewTL.setLParenLoc(TL.getLParenLoc());
5647  NewTL.setRParenLoc(TL.getRParenLoc());
5648  return Result;
5649 }
5650 
5651 template<typename Derived>
5652 QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
5653  DependentNameTypeLoc TL) {
5654  const DependentNameType *T = TL.getTypePtr();
5655 
5656  NestedNameSpecifierLoc QualifierLoc
5657  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5658  if (!QualifierLoc)
5659  return QualType();
5660 
5661  QualType Result
5662  = getDerived().RebuildDependentNameType(T->getKeyword(),
5663  TL.getElaboratedKeywordLoc(),
5664  QualifierLoc,
5665  T->getIdentifier(),
5666  TL.getNameLoc());
5667  if (Result.isNull())
5668  return QualType();
5669 
5670  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5671  QualType NamedT = ElabT->getNamedType();
5672  TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5673 
5674  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5675  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5676  NewTL.setQualifierLoc(QualifierLoc);
5677  } else {
5678  DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
5679  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
5680  NewTL.setQualifierLoc(QualifierLoc);
5681  NewTL.setNameLoc(TL.getNameLoc());
5682  }
5683  return Result;
5684 }
5685 
5686 template<typename Derived>
5687 QualType TreeTransform<Derived>::
5689  DependentTemplateSpecializationTypeLoc TL) {
5690  NestedNameSpecifierLoc QualifierLoc;
5691  if (TL.getQualifierLoc()) {
5692  QualifierLoc
5693  = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5694  if (!QualifierLoc)
5695  return QualType();
5696  }
5697 
5698  return getDerived()
5699  .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
5700 }
5701 
5702 template<typename Derived>
5703 QualType TreeTransform<Derived>::
5706  NestedNameSpecifierLoc QualifierLoc) {
5708 
5709  TemplateArgumentListInfo NewTemplateArgs;
5710  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5711  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5712 
5715  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5716  ArgIterator(TL, TL.getNumArgs()),
5717  NewTemplateArgs))
5718  return QualType();
5719 
5720  QualType Result
5721  = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5722  QualifierLoc,
5723  T->getIdentifier(),
5724  TL.getTemplateNameLoc(),
5725  NewTemplateArgs);
5726  if (Result.isNull())
5727  return QualType();
5728 
5729  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5730  QualType NamedT = ElabT->getNamedType();
5731 
5732  // Copy information relevant to the template specialization.
5734  = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
5736  NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5737  NamedTL.setLAngleLoc(TL.getLAngleLoc());
5738  NamedTL.setRAngleLoc(TL.getRAngleLoc());
5739  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5740  NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5741 
5742  // Copy information relevant to the elaborated type.
5743  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
5745  NewTL.setQualifierLoc(QualifierLoc);
5746  } else if (isa<DependentTemplateSpecializationType>(Result)) {
5750  SpecTL.setQualifierLoc(QualifierLoc);
5753  SpecTL.setLAngleLoc(TL.getLAngleLoc());
5754  SpecTL.setRAngleLoc(TL.getRAngleLoc());
5755  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5756  SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5757  } else {
5759  = TLB.push<TemplateSpecializationTypeLoc>(Result);
5762  SpecTL.setLAngleLoc(TL.getLAngleLoc());
5763  SpecTL.setRAngleLoc(TL.getRAngleLoc());
5764  for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
5765  SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
5766  }
5767  return Result;
5768 }
5769 
5770 template<typename Derived>
5772  PackExpansionTypeLoc TL) {
5773  QualType Pattern
5774  = getDerived().TransformType(TLB, TL.getPatternLoc());
5775  if (Pattern.isNull())
5776  return QualType();
5777 
5778  QualType Result = TL.getType();
5779  if (getDerived().AlwaysRebuild() ||
5780  Pattern != TL.getPatternLoc().getType()) {
5781  Result = getDerived().RebuildPackExpansionType(Pattern,
5783  TL.getEllipsisLoc(),
5784  TL.getTypePtr()->getNumExpansions());
5785  if (Result.isNull())
5786  return QualType();
5787  }
5788 
5789  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5790  NewT.setEllipsisLoc(TL.getEllipsisLoc());
5791  return Result;
5792 }
5793 
5794 template<typename Derived>
5795 QualType
5796 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
5797  ObjCInterfaceTypeLoc TL) {
5798  // ObjCInterfaceType is never dependent.
5799  TLB.pushFullCopy(TL);
5800  return TL.getType();
5801 }
5802 
5803 template<typename Derived>
5804 QualType
5805 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
5806  ObjCObjectTypeLoc TL) {
5807  // Transform base type.
5808  QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5809  if (BaseType.isNull())
5810  return QualType();
5811 
5812  bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5813 
5814  // Transform type arguments.
5815  SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5816  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5817  TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5818  TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5819  QualType TypeArg = TypeArgInfo->getType();
5820  if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5821  AnyChanged = true;
5822 
5823  // We have a pack expansion. Instantiate it.
5824  const auto *PackExpansion = PackExpansionLoc.getType()
5825  ->castAs<PackExpansionType>();
5826  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5827  SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5828  Unexpanded);
5829  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5830 
5831  // Determine whether the set of unexpanded parameter packs can
5832  // and should be expanded.
5833  TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5834  bool Expand = false;
5835  bool RetainExpansion = false;
5836  Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5837  if (getDerived().TryExpandParameterPacks(
5838  PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5839  Unexpanded, Expand, RetainExpansion, NumExpansions))
5840  return QualType();
5841 
5842  if (!Expand) {
5843  // We can't expand this pack expansion into separate arguments yet;
5844  // just substitute into the pattern and create a new pack expansion
5845  // type.
5846  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5847 
5848  TypeLocBuilder TypeArgBuilder;
5849  TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5850  QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5851  PatternLoc);
5852  if (NewPatternType.isNull())
5853  return QualType();
5854 
5855  QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5856  NewPatternType, NumExpansions);
5857  auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5858  NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5859  NewTypeArgInfos.push_back(
5860  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5861  continue;
5862  }
5863 
5864  // Substitute into the pack expansion pattern for each slice of the
5865  // pack.
5866  for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5867  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5868 
5869  TypeLocBuilder TypeArgBuilder;
5870  TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5871 
5872  QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5873  PatternLoc);
5874  if (NewTypeArg.isNull())
5875  return QualType();
5876 
5877  NewTypeArgInfos.push_back(
5878  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5879  }
5880 
5881  continue;
5882  }
5883 
5884  TypeLocBuilder TypeArgBuilder;
5885  TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5886  QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5887  if (NewTypeArg.isNull())
5888  return QualType();
5889 
5890  // If nothing changed, just keep the old TypeSourceInfo.
5891  if (NewTypeArg == TypeArg) {
5892  NewTypeArgInfos.push_back(TypeArgInfo);
5893  continue;
5894  }
5895 
5896  NewTypeArgInfos.push_back(
5897  TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5898  AnyChanged = true;
5899  }
5900 
5901  QualType Result = TL.getType();
5902  if (getDerived().AlwaysRebuild() || AnyChanged) {
5903  // Rebuild the type.
5904  Result = getDerived().RebuildObjCObjectType(
5905  BaseType,
5906  TL.getLocStart(),
5907  TL.getTypeArgsLAngleLoc(),
5908  NewTypeArgInfos,
5909  TL.getTypeArgsRAngleLoc(),
5910  TL.getProtocolLAngleLoc(),
5911  llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5912  TL.getNumProtocols()),
5913  TL.getProtocolLocs(),
5914  TL.getProtocolRAngleLoc());
5915 
5916  if (Result.isNull())
5917  return QualType();
5918  }
5919 
5920  ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5921  assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5922  NewT.setHasBaseTypeAsWritten(true);
5923  NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5924  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5925  NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5926  NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5927  NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5928  for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5929  NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5930  NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5931  return Result;
5932 }
5933 
5934 template<typename Derived>
5935 QualType
5936 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
5937  ObjCObjectPointerTypeLoc TL) {
5938  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5939  if (PointeeType.isNull())
5940  return QualType();
5941 
5942  QualType Result = TL.getType();
5943  if (getDerived().AlwaysRebuild() ||
5944  PointeeType != TL.getPointeeLoc().getType()) {
5945  Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5946  TL.getStarLoc());
5947  if (Result.isNull())
5948  return QualType();
5949  }
5950 
5951  ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5952  NewT.setStarLoc(TL.getStarLoc());
5953  return Result;
5954 }
5955 
5956 //===----------------------------------------------------------------------===//
5957 // Statement transformation
5958 //===----------------------------------------------------------------------===//
5959 template<typename Derived>
5960 StmtResult
5961 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
5962  return S;
5963 }
5964 
5965 template<typename Derived>
5966 StmtResult
5968  return getDerived().TransformCompoundStmt(S, false);
5969 }
5970 
5971 template<typename Derived>
5972 StmtResult
5974  bool IsStmtExpr) {
5975  Sema::CompoundScopeRAII CompoundScope(getSema());
5976 
5977  bool SubStmtInvalid = false;
5978  bool SubStmtChanged = false;
5979  SmallVector<Stmt*, 8> Statements;
5980  for (auto *B : S->body()) {
5981  StmtResult Result = getDerived().TransformStmt(B);
5982  if (Result.isInvalid()) {
5983  // Immediately fail if this was a DeclStmt, since it's very
5984  // likely that this will cause problems for future statements.
5985  if (isa<DeclStmt>(B))
5986  return StmtError();
5987 
5988  // Otherwise, just keep processing substatements and fail later.
5989  SubStmtInvalid = true;
5990  continue;
5991  }
5992 
5993  SubStmtChanged = SubStmtChanged || Result.get() != B;
5994  Statements.push_back(Result.getAs<Stmt>());
5995  }
5996 
5997  if (SubStmtInvalid)
5998  return StmtError();
5999 
6000  if (!getDerived().AlwaysRebuild() &&
6001  !SubStmtChanged)
6002  return S;
6003 
6004  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
6005  Statements,
6006  S->getRBracLoc(),
6007  IsStmtExpr);
6008 }
6009 
6010 template<typename Derived>
6011 StmtResult
6012 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
6013  ExprResult LHS, RHS;
6014  {
6015  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6017 
6018  // Transform the left-hand case value.
6019  LHS = getDerived().TransformExpr(S->getLHS());
6020  LHS = SemaRef.ActOnConstantExpression(LHS);
6021  if (LHS.isInvalid())
6022  return StmtError();
6023 
6024  // Transform the right-hand case value (for the GNU case-range extension).
6025  RHS = getDerived().TransformExpr(S->getRHS());
6026  RHS = SemaRef.ActOnConstantExpression(RHS);
6027  if (RHS.isInvalid())
6028  return StmtError();
6029  }
6030 
6031  // Build the case statement.
6032  // Case statements are always rebuilt so that they will attached to their
6033  // transformed switch statement.
6034  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
6035  LHS.get(),
6036  S->getEllipsisLoc(),
6037  RHS.get(),
6038  S->getColonLoc());
6039  if (Case.isInvalid())
6040  return StmtError();
6041 
6042  // Transform the statement following the case
6043  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6044  if (SubStmt.isInvalid())
6045  return StmtError();
6046 
6047  // Attach the body to the case statement
6048  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
6049 }
6050 
6051 template<typename Derived>
6052 StmtResult
6053 TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
6054  // Transform the statement following the default case
6055  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6056  if (SubStmt.isInvalid())
6057  return StmtError();
6058 
6059  // Default statements are always rebuilt
6060  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
6061  SubStmt.get());
6062 }
6063 
6064 template<typename Derived>
6065 StmtResult
6066 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
6067  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6068  if (SubStmt.isInvalid())
6069  return StmtError();
6070 
6071  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6072  S->getDecl());
6073  if (!LD)
6074  return StmtError();
6075 
6076 
6077  // FIXME: Pass the real colon location in.
6078  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
6079  cast<LabelDecl>(LD), SourceLocation(),
6080  SubStmt.get());
6081 }
6082 
6083 template <typename Derived>
6085  if (!R)
6086  return R;
6087 
6088  switch (R->getKind()) {
6089 // Transform attributes with a pragma spelling by calling TransformXXXAttr.
6090 #define ATTR(X)
6091 #define PRAGMA_SPELLING_ATTR(X) \
6092  case attr::X: \
6093  return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6094 #include "clang/Basic/AttrList.inc"
6095  default:
6096  return R;
6097  }
6098 }
6099 
6100 template <typename Derived>
6102  bool AttrsChanged = false;
6104 
6105  // Visit attributes and keep track if any are transformed.
6106  for (const auto *I : S->getAttrs()) {
6107  const Attr *R = getDerived().TransformAttr(I);
6108  AttrsChanged |= (I != R);
6109  Attrs.push_back(R);
6110  }
6111 
6112  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6113  if (SubStmt.isInvalid())
6114  return StmtError();
6115 
6116  if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
6117  return S;
6118 
6119  return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
6120  SubStmt.get());
6121 }
6122 
6123 template<typename Derived>
6124 StmtResult
6125 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
6126  // Transform the condition
6127  ExprResult Cond;
6128  VarDecl *ConditionVar = nullptr;
6129  if (S->getConditionVariable()) {
6130  ConditionVar
6131  = cast_or_null<VarDecl>(
6132  getDerived().TransformDefinition(
6133  S->getConditionVariable()->getLocation(),
6134  S->getConditionVariable()));
6135  if (!ConditionVar)
6136  return StmtError();
6137  } else {
6138  Cond = getDerived().TransformExpr(S->getCond());
6139 
6140  if (Cond.isInvalid())
6141  return StmtError();
6142 
6143  // Convert the condition to a boolean value.
6144  if (S->getCond()) {
6145  ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
6146  Cond.get());
6147  if (CondE.isInvalid())
6148  return StmtError();
6149 
6150  Cond = CondE.get();
6151  }
6152  }
6153 
6154  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get(), S->getIfLoc()));
6155  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
6156  return StmtError();
6157 
6158  // Transform the "then" branch.
6159  StmtResult Then = getDerived().TransformStmt(S->getThen());
6160  if (Then.isInvalid())
6161  return StmtError();
6162 
6163  // Transform the "else" branch.
6164  StmtResult Else = getDerived().TransformStmt(S->getElse());
6165  if (Else.isInvalid())
6166  return StmtError();
6167 
6168  if (!getDerived().AlwaysRebuild() &&
6169  FullCond.get() == S->getCond() &&
6170  ConditionVar == S->getConditionVariable() &&
6171  Then.get() == S->getThen() &&
6172  Else.get() == S->getElse())
6173  return S;
6174 
6175  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
6176  Then.get(),
6177  S->getElseLoc(), Else.get());
6178 }
6179 
6180 template<typename Derived>
6181 StmtResult
6182 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
6183  // Transform the condition.
6184  ExprResult Cond;
6185  VarDecl *ConditionVar = nullptr;
6186  if (S->getConditionVariable()) {
6187  ConditionVar
6188  = cast_or_null<VarDecl>(
6189  getDerived().TransformDefinition(
6190  S->getConditionVariable()->getLocation(),
6191  S->getConditionVariable()));
6192  if (!ConditionVar)
6193  return StmtError();
6194  } else {
6195  Cond = getDerived().TransformExpr(S->getCond());
6196 
6197  if (Cond.isInvalid())
6198  return StmtError();
6199  }
6200 
6201  // Rebuild the switch statement.
6202  StmtResult Switch
6203  = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
6204  ConditionVar);
6205  if (Switch.isInvalid())
6206  return StmtError();
6207 
6208  // Transform the body of the switch statement.
6209  StmtResult Body = getDerived().TransformStmt(S->getBody());
6210  if (Body.isInvalid())
6211  return StmtError();
6212 
6213  // Complete the switch statement.
6214  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6215  Body.get());
6216 }
6217 
6218 template<typename Derived>
6219 StmtResult
6220 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
6221  // Transform the condition
6222  ExprResult Cond;
6223  VarDecl *ConditionVar = nullptr;
6224  if (S->getConditionVariable()) {
6225  ConditionVar
6226  = cast_or_null<VarDecl>(
6227  getDerived().TransformDefinition(
6228  S->getConditionVariable()->getLocation(),
6229  S->getConditionVariable()));
6230  if (!ConditionVar)
6231  return StmtError();
6232  } else {
6233  Cond = getDerived().TransformExpr(S->getCond());
6234 
6235  if (Cond.isInvalid())
6236  return StmtError();
6237 
6238  if (S->getCond()) {
6239  // Convert the condition to a boolean value.
6240  ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6241  S->getWhileLoc(),
6242  Cond.get());
6243  if (CondE.isInvalid())
6244  return StmtError();
6245  Cond = CondE;
6246  }
6247  }
6248 
6249  Sema::FullExprArg FullCond(
6250  getSema().MakeFullExpr(Cond.get(), S->getWhileLoc()));
6251  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
6252  return StmtError();
6253 
6254  // Transform the body
6255  StmtResult Body = getDerived().TransformStmt(S->getBody());
6256  if (Body.isInvalid())
6257  return StmtError();
6258 
6259  if (!getDerived().AlwaysRebuild() &&
6260  FullCond.get() == S->getCond() &&
6261  ConditionVar == S->getConditionVariable() &&
6262  Body.get() == S->getBody())
6263  return Owned(S);
6264 
6265  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
6266  ConditionVar, Body.get());
6267 }
6268 
6269 template<typename Derived>
6270 StmtResult
6271 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
6272  // Transform the body
6273  StmtResult Body = getDerived().TransformStmt(S->getBody());
6274  if (Body.isInvalid())
6275  return StmtError();
6276 
6277  // Transform the condition
6278  ExprResult Cond = getDerived().TransformExpr(S->getCond());
6279  if (Cond.isInvalid())
6280  return StmtError();
6281 
6282  if (!getDerived().AlwaysRebuild() &&
6283  Cond.get() == S->getCond() &&
6284  Body.get() == S->getBody())
6285  return S;
6286 
6287  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6288  /*FIXME:*/S->getWhileLoc(), Cond.get(),
6289  S->getRParenLoc());
6290 }
6291 
6292 template<typename Derived>
6293 StmtResult
6294 TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
6295  // Transform the initialization statement
6296  StmtResult Init = getDerived().TransformStmt(S->getInit());
6297  if (Init.isInvalid())
6298  return StmtError();
6299 
6300  // In OpenMP loop region loop control variable must be captured and be
6301  // private. Perform analysis of first part (if any).
6302  if (getSema().getLangOpts().OpenMP && Init.isUsable())
6303  getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6304 
6305  // Transform the condition
6306  ExprResult Cond;
6307  VarDecl *ConditionVar = nullptr;
6308  if (S->getConditionVariable()) {
6309  ConditionVar
6310  = cast_or_null<VarDecl>(
6311  getDerived().TransformDefinition(
6312  S->getConditionVariable()->getLocation(),
6313  S->getConditionVariable()));
6314  if (!ConditionVar)
6315  return StmtError();
6316  } else {
6317  Cond = getDerived().TransformExpr(S->getCond());
6318 
6319  if (Cond.isInvalid())
6320  return StmtError();
6321 
6322  if (S->getCond()) {
6323  // Convert the condition to a boolean value.
6324  ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6325  S->getForLoc(),
6326  Cond.get());
6327  if (CondE.isInvalid())
6328  return StmtError();
6329 
6330  Cond = CondE.get();
6331  }
6332  }
6333 
6334  Sema::FullExprArg FullCond(
6335  getSema().MakeFullExpr(Cond.get(), S->getForLoc()));
6336  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
6337  return StmtError();
6338 
6339  // Transform the increment
6340  ExprResult Inc = getDerived().TransformExpr(S->getInc());
6341  if (Inc.isInvalid())
6342  return StmtError();
6343 
6344  Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
6345  if (S->getInc() && !FullInc.get())
6346  return StmtError();
6347 
6348  // Transform the body
6349  StmtResult Body = getDerived().TransformStmt(S->getBody());
6350  if (Body.isInvalid())
6351  return StmtError();
6352 
6353  if (!getDerived().AlwaysRebuild() &&
6354  Init.get() == S->getInit() &&
6355  FullCond.get() == S->getCond() &&
6356  Inc.get() == S->getInc() &&
6357  Body.get() == S->getBody())
6358  return S;
6359 
6360  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
6361  Init.get(), FullCond, ConditionVar,
6362  FullInc, S->getRParenLoc(), Body.get());
6363 }
6364 
6365 template<typename Derived>
6366 StmtResult
6367 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
6368  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6369  S->getLabel());
6370  if (!LD)
6371  return StmtError();
6372 
6373  // Goto statements must always be rebuilt, to resolve the label.
6374  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
6375  cast<LabelDecl>(LD));
6376 }
6377 
6378 template<typename Derived>
6379 StmtResult
6380 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
6381  ExprResult Target = getDerived().TransformExpr(S->getTarget());
6382  if (Target.isInvalid())
6383  return StmtError();
6384  Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
6385 
6386  if (!getDerived().AlwaysRebuild() &&
6387  Target.get() == S->getTarget())
6388  return S;
6389 
6390  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
6391  Target.get());
6392 }
6393 
6394 template<typename Derived>
6395 StmtResult
6396 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
6397  return S;
6398 }
6399 
6400 template<typename Derived>
6401 StmtResult
6402 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
6403  return S;
6404 }
6405 
6406 template<typename Derived>
6407 StmtResult
6408 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
6409  ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6410  /*NotCopyInit*/false);
6411  if (Result.isInvalid())
6412  return StmtError();
6413 
6414  // FIXME: We always rebuild the return statement because there is no way
6415  // to tell whether the return type of the function has changed.
6416  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
6417 }
6418 
6419 template<typename Derived>
6420 StmtResult
6421 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
6422  bool DeclChanged = false;
6423  SmallVector<Decl *, 4> Decls;
6424  for (auto *D : S->decls()) {
6425  Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
6426  if (!Transformed)
6427  return StmtError();
6428 
6429  if (Transformed != D)
6430  DeclChanged = true;
6431 
6432  Decls.push_back(Transformed);
6433  }
6434 
6435  if (!getDerived().AlwaysRebuild() && !DeclChanged)
6436  return S;
6437 
6438  return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
6439 }
6440 
6441 template<typename Derived>
6442 StmtResult
6443 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
6444 
6445  SmallVector<Expr*, 8> Constraints;
6446  SmallVector<Expr*, 8> Exprs;
6447  SmallVector<IdentifierInfo *, 4> Names;
6448 
6449  ExprResult AsmString;
6450  SmallVector<Expr*, 8> Clobbers;
6451 
6452  bool ExprsChanged = false;
6453 
6454  // Go through the outputs.
6455  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
6456  Names.push_back(S->getOutputIdentifier(I));
6457 
6458  // No need to transform the constraint literal.
6459  Constraints.push_back(S->getOutputConstraintLiteral(I));
6460 
6461  // Transform the output expr.
6462  Expr *OutputExpr = S->getOutputExpr(I);
6463  ExprResult Result = getDerived().TransformExpr(OutputExpr);
6464  if (Result.isInvalid())
6465  return StmtError();
6466 
6467  ExprsChanged |= Result.get() != OutputExpr;
6468 
6469  Exprs.push_back(Result.get());
6470  }
6471 
6472  // Go through the inputs.
6473  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
6474  Names.push_back(S->getInputIdentifier(I));
6475 
6476  // No need to transform the constraint literal.
6477  Constraints.push_back(S->getInputConstraintLiteral(I));
6478 
6479  // Transform the input expr.
6480  Expr *InputExpr = S->getInputExpr(I);
6481  ExprResult Result = getDerived().TransformExpr(InputExpr);
6482  if (Result.isInvalid())
6483  return StmtError();
6484 
6485  ExprsChanged |= Result.get() != InputExpr;
6486 
6487  Exprs.push_back(Result.get());
6488  }
6489 
6490  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
6491  return S;
6492 
6493  // Go through the clobbers.
6494  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
6495  Clobbers.push_back(S->getClobberStringLiteral(I));
6496 
6497  // No need to transform the asm string literal.
6498  AsmString = S->getAsmString();
6499  return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6500  S->isVolatile(), S->getNumOutputs(),
6501  S->getNumInputs(), Names.data(),
6502  Constraints, Exprs, AsmString.get(),
6503  Clobbers, S->getRParenLoc());
6504 }
6505 
6506 template<typename Derived>
6507 StmtResult
6508 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
6509  ArrayRef<Token> AsmToks =
6510  llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
6511 
6512  bool HadError = false, HadChange = false;
6513 
6514  ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6515  SmallVector<Expr*, 8> TransformedExprs;
6516  TransformedExprs.reserve(SrcExprs.size());
6517  for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6518  ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6519  if (!Result.isUsable()) {
6520  HadError = true;
6521  } else {
6522  HadChange |= (Result.get() != SrcExprs[i]);
6523  TransformedExprs.push_back(Result.get());
6524  }
6525  }
6526 
6527  if (HadError) return StmtError();
6528  if (!HadChange && !getDerived().AlwaysRebuild())
6529  return Owned(S);
6530 
6531  return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
6532  AsmToks, S->getAsmString(),
6533  S->getNumOutputs(), S->getNumInputs(),
6534  S->getAllConstraints(), S->getClobbers(),
6535  TransformedExprs, S->getEndLoc());
6536 }
6537 
6538 // C++ Coroutines TS
6539 
6540 template<typename Derived>
6541 StmtResult
6542 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6543  // The coroutine body should be re-formed by the caller if necessary.
6544  return getDerived().TransformStmt(S->getBody());
6545 }
6546 
6547 template<typename Derived>
6548 StmtResult
6549 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6550  ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6551  /*NotCopyInit*/false);
6552  if (Result.isInvalid())
6553  return StmtError();
6554 
6555  // Always rebuild; we don't know if this needs to be injected into a new
6556  // context or if the promise type has changed.
6557  return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6558 }
6559 
6560 template<typename Derived>
6561 ExprResult
6562 TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6563  ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6564  /*NotCopyInit*/false);
6565  if (Result.isInvalid())
6566  return ExprError();
6567 
6568  // Always rebuild; we don't know if this needs to be injected into a new
6569  // context or if the promise type has changed.
6570  return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6571 }
6572 
6573 template<typename Derived>
6574 ExprResult
6575 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6576  ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6577  /*NotCopyInit*/false);
6578  if (Result.isInvalid())
6579  return ExprError();
6580 
6581  // Always rebuild; we don't know if this needs to be injected into a new
6582  // context or if the promise type has changed.
6583  return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6584 }
6585 
6586 // Objective-C Statements.
6587 
6588 template<typename Derived>
6589 StmtResult
6590 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
6591  // Transform the body of the @try.
6592  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
6593  if (TryBody.isInvalid())
6594  return StmtError();
6595 
6596  // Transform the @catch statements (if present).
6597  bool AnyCatchChanged = false;
6598  SmallVector<Stmt*, 8> CatchStmts;
6599  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
6600  StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
6601  if (Catch.isInvalid())
6602  return StmtError();
6603  if (Catch.get() != S->getCatchStmt(I))
6604  AnyCatchChanged = true;
6605  CatchStmts.push_back(Catch.get());
6606  }
6607 
6608  // Transform the @finally statement (if present).
6609  StmtResult Finally;
6610  if (S->getFinallyStmt()) {
6611  Finally = getDerived().TransformStmt(S->getFinallyStmt());
6612  if (Finally.isInvalid())
6613  return StmtError();
6614  }
6615 
6616  // If nothing changed, just retain this statement.
6617  if (!getDerived().AlwaysRebuild() &&
6618  TryBody.get() == S->getTryBody() &&
6619  !AnyCatchChanged &&
6620  Finally.get() == S->getFinallyStmt())
6621  return S;
6622 
6623  // Build a new statement.
6624  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
6625  CatchStmts, Finally.get());
6626 }
6627 
6628 template<typename Derived>
6629 StmtResult
6630 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
6631  // Transform the @catch parameter, if there is one.
6632  VarDecl *Var = nullptr;
6633  if (VarDecl *FromVar = S->getCatchParamDecl()) {
6634  TypeSourceInfo *TSInfo = nullptr;
6635  if (FromVar->getTypeSourceInfo()) {
6636  TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6637  if (!TSInfo)
6638  return StmtError();
6639  }
6640 
6641  QualType T;
6642  if (TSInfo)
6643  T = TSInfo->getType();
6644  else {
6645  T = getDerived().TransformType(FromVar->getType());
6646  if (T.isNull())
6647  return StmtError();
6648  }
6649 
6650  Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6651  if (!Var)
6652  return StmtError();
6653  }
6654 
6655  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
6656  if (Body.isInvalid())
6657  return StmtError();
6658 
6659  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
6660  S->getRParenLoc(),
6661  Var, Body.get());
6662 }
6663 
6664 template<typename Derived>
6665 StmtResult
6666 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
6667  // Transform the body.
6668  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
6669  if (Body.isInvalid())
6670  return StmtError();
6671 
6672  // If nothing changed, just retain this statement.
6673  if (!getDerived().AlwaysRebuild() &&
6674  Body.get() == S->getFinallyBody())
6675  return S;
6676 
6677  // Build a new statement.
6678  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
6679  Body.get());
6680 }
6681 
6682 template<typename Derived>
6683 StmtResult
6684 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
6685  ExprResult Operand;
6686  if (S->getThrowExpr()) {
6687  Operand = getDerived().TransformExpr(S->getThrowExpr());
6688  if (Operand.isInvalid())
6689  return StmtError();
6690  }
6691 
6692  if (!getDerived().AlwaysRebuild() &&
6693  Operand.get() == S->getThrowExpr())
6694  return S;
6695 
6696  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
6697 }
6698 
6699 template<typename Derived>
6700 StmtResult
6701 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
6702  ObjCAtSynchronizedStmt *S) {
6703  // Transform the object we are locking.
6704  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
6705  if (Object.isInvalid())
6706  return StmtError();
6707  Object =
6708  getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6709  Object.get());
6710  if (Object.isInvalid())
6711  return StmtError();
6712 
6713  // Transform the body.
6714  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
6715  if (Body.isInvalid())
6716  return StmtError();
6717 
6718  // If nothing change, just retain the current statement.
6719  if (!getDerived().AlwaysRebuild() &&
6720  Object.get() == S->getSynchExpr() &&
6721  Body.get() == S->getSynchBody())
6722  return S;
6723 
6724  // Build a new statement.
6725  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
6726  Object.get(), Body.get());
6727 }
6728 
6729 template<typename Derived>
6730 StmtResult
6731 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6732  ObjCAutoreleasePoolStmt *S) {
6733  // Transform the body.
6734  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6735  if (Body.isInvalid())
6736  return StmtError();
6737 
6738  // If nothing changed, just retain this statement.
6739  if (!getDerived().AlwaysRebuild() &&
6740  Body.get() == S->getSubStmt())
6741  return S;
6742 
6743  // Build a new statement.
6744  return getDerived().RebuildObjCAutoreleasePoolStmt(
6745  S->getAtLoc(), Body.get());
6746 }
6747 
6748 template<typename Derived>
6749 StmtResult
6750 TreeTransform<Derived>::TransformObjCForCollectionStmt(
6751  ObjCForCollectionStmt *S) {
6752  // Transform the element statement.
6753  StmtResult Element = getDerived().TransformStmt(S->getElement());
6754  if (Element.isInvalid())
6755  return StmtError();
6756 
6757  // Transform the collection expression.
6758  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
6759  if (Collection.isInvalid())
6760  return StmtError();
6761 
6762  // Transform the body.
6763  StmtResult Body = getDerived().TransformStmt(S->getBody());
6764  if (Body.isInvalid())
6765  return StmtError();
6766 
6767  // If nothing changed, just retain this statement.
6768  if (!getDerived().AlwaysRebuild() &&
6769  Element.get() == S->getElement() &&
6770  Collection.get() == S->getCollection() &&
6771  Body.get() == S->getBody())
6772  return S;
6773 
6774  // Build a new statement.
6775  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
6776  Element.get(),
6777  Collection.get(),
6778  S->getRParenLoc(),
6779  Body.get());
6780 }
6781 
6782 template <typename Derived>
6783 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6784  // Transform the exception declaration, if any.
6785  VarDecl *Var = nullptr;
6786  if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6787  TypeSourceInfo *T =
6788  getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
6789  if (!T)
6790  return StmtError();
6791 
6792  Var = getDerived().RebuildExceptionDecl(
6793  ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6794  ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
6795  if (!Var || Var->isInvalidDecl())
6796  return StmtError();
6797  }
6798 
6799  // Transform the actual exception handler.
6800  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
6801  if (Handler.isInvalid())
6802  return StmtError();
6803 
6804  if (!getDerived().AlwaysRebuild() && !Var &&
6805  Handler.get() == S->getHandlerBlock())
6806  return S;
6807 
6808  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
6809 }
6810 
6811 template <typename Derived>
6812 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6813  // Transform the try block itself.
6814  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
6815  if (TryBlock.isInvalid())
6816  return StmtError();
6817 
6818  // Transform the handlers.
6819  bool HandlerChanged = false;
6820  SmallVector<Stmt *, 8> Handlers;
6821  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
6822  StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6823  if (Handler.isInvalid())
6824  return StmtError();
6825 
6826  HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6827  Handlers.push_back(Handler.getAs<Stmt>());
6828  }
6829 
6830  if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6831  !HandlerChanged)
6832  return S;
6833 
6834  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
6835  Handlers);
6836 }
6837 
6838 template<typename Derived>
6839 StmtResult
6840 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6841  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6842  if (Range.isInvalid())
6843  return StmtError();
6844 
6845  StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6846  if (BeginEnd.isInvalid())
6847  return StmtError();
6848 
6849  ExprResult Cond = getDerived().TransformExpr(S->getCond());
6850  if (Cond.isInvalid())
6851  return StmtError();
6852  if (Cond.get())
6853  Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
6854  if (Cond.isInvalid())
6855  return StmtError();
6856  if (Cond.get())
6857  Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
6858 
6859  ExprResult Inc = getDerived().TransformExpr(S->getInc());
6860  if (Inc.isInvalid())
6861  return StmtError();
6862  if (Inc.get())
6863  Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
6864 
6865  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6866  if (LoopVar.isInvalid())
6867  return StmtError();
6868 
6869  StmtResult NewStmt = S;
6870  if (getDerived().AlwaysRebuild() ||
6871  Range.get() != S->getRangeStmt() ||
6872  BeginEnd.get() != S->getBeginEndStmt() ||
6873  Cond.get() != S->getCond() ||
6874  Inc.get() != S->getInc() ||
6875  LoopVar.get() != S->getLoopVarStmt()) {
6876  NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6877  S->getCoawaitLoc(),
6878  S->getColonLoc(), Range.get(),
6879  BeginEnd.get(), Cond.get(),
6880  Inc.get(), LoopVar.get(),
6881  S->getRParenLoc());
6882  if (NewStmt.isInvalid())
6883  return StmtError();
6884  }
6885 
6886  StmtResult Body = getDerived().TransformStmt(S->getBody());
6887  if (Body.isInvalid())
6888  return StmtError();
6889 
6890  // Body has changed but we didn't rebuild the for-range statement. Rebuild
6891  // it now so we have a new statement to attach the body to.
6892  if (Body.get() != S->getBody() && NewStmt.get() == S) {
6893  NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6894  S->getCoawaitLoc(),
6895  S->getColonLoc(), Range.get(),
6896  BeginEnd.get(), Cond.get(),
6897  Inc.get(), LoopVar.get(),
6898  S->getRParenLoc());
6899  if (NewStmt.isInvalid())
6900  return StmtError();
6901  }
6902 
6903  if (NewStmt.get() == S)
6904  return S;
6905 
6906  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6907 }
6908 
6909 template<typename Derived>
6910 StmtResult
6911 TreeTransform<Derived>::TransformMSDependentExistsStmt(
6912  MSDependentExistsStmt *S) {
6913  // Transform the nested-name-specifier, if any.
6914  NestedNameSpecifierLoc QualifierLoc;
6915  if (S->getQualifierLoc()) {
6916  QualifierLoc
6917  = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6918  if (!QualifierLoc)
6919  return StmtError();
6920  }
6921 
6922  // Transform the declaration name.
6923  DeclarationNameInfo NameInfo = S->getNameInfo();
6924  if (NameInfo.getName()) {
6925  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6926  if (!NameInfo.getName())
6927  return StmtError();
6928  }
6929 
6930  // Check whether anything changed.
6931  if (!getDerived().AlwaysRebuild() &&
6932  QualifierLoc == S->getQualifierLoc() &&
6933  NameInfo.getName() == S->getNameInfo().getName())
6934  return S;
6935 
6936  // Determine whether this name exists, if we can.
6937  CXXScopeSpec SS;
6938  SS.Adopt(QualifierLoc);
6939  bool Dependent = false;
6940  switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
6941  case Sema::IER_Exists:
6942  if (S->isIfExists())
6943  break;
6944 
6945  return new (getSema().Context) NullStmt(S->getKeywordLoc());
6946 
6948  if (S->isIfNotExists())
6949  break;
6950 
6951  return new (getSema().Context) NullStmt(S->getKeywordLoc());
6952 
6953  case Sema::IER_Dependent:
6954  Dependent = true;
6955  break;
6956 
6957  case Sema::IER_Error:
6958  return StmtError();
6959  }
6960 
6961  // We need to continue with the instantiation, so do so now.
6962  StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6963  if (SubStmt.isInvalid())
6964  return StmtError();
6965 
6966  // If we have resolved the name, just transform to the substatement.
6967  if (!Dependent)
6968  return SubStmt;
6969 
6970  // The name is still dependent, so build a dependent expression again.
6971  return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6972  S->isIfExists(),
6973  QualifierLoc,
6974  NameInfo,
6975  SubStmt.get());
6976 }
6977 
6978 template<typename Derived>
6979 ExprResult
6980 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6981  NestedNameSpecifierLoc QualifierLoc;
6982  if (E->getQualifierLoc()) {
6983  QualifierLoc
6984  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6985  if (!QualifierLoc)
6986  return ExprError();
6987  }
6988 
6989  MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6990  getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6991  if (!PD)
6992  return ExprError();
6993 
6994  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6995  if (Base.isInvalid())
6996  return ExprError();
6997 
6998  return new (SemaRef.getASTContext())
6999  MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7000  SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7001  QualifierLoc, E->getMemberLoc());
7002 }
7003 
7004 template <typename Derived>
7005 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7006  MSPropertySubscriptExpr *E) {
7007  auto BaseRes = getDerived().TransformExpr(E->getBase());
7008  if (BaseRes.isInvalid())
7009  return ExprError();
7010  auto IdxRes = getDerived().TransformExpr(E->getIdx());
7011  if (IdxRes.isInvalid())
7012  return ExprError();
7013 
7014  if (!getDerived().AlwaysRebuild() &&
7015  BaseRes.get() == E->getBase() &&
7016  IdxRes.get() == E->getIdx())
7017  return E;
7018 
7019  return getDerived().RebuildArraySubscriptExpr(
7020  BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7021 }
7022 
7023 template <typename Derived>
7024 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
7025  StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
7026  if (TryBlock.isInvalid())
7027  return StmtError();
7028 
7029  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
7030  if (Handler.isInvalid())
7031  return StmtError();
7032 
7033  if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7034  Handler.get() == S->getHandler())
7035  return S;
7036 
7037  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7038  TryBlock.get(), Handler.get());
7039 }
7040 
7041 template <typename Derived>
7042 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
7043  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7044  if (Block.isInvalid())
7045  return StmtError();
7046 
7047  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
7048 }
7049 
7050 template <typename Derived>
7051 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
7052  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
7053  if (FilterExpr.isInvalid())
7054  return StmtError();
7055 
7056  StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
7057  if (Block.isInvalid())
7058  return StmtError();
7059 
7060  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7061  Block.get());
7062 }
7063 
7064 template <typename Derived>
7066  if (isa<SEHFinallyStmt>(Handler))
7067  return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7068  else
7069  return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7070 }
7071 
7072 template<typename Derived>
7073 StmtResult
7075  return S;
7076 }
7077 
7078 //===----------------------------------------------------------------------===//
7079 // OpenMP directive transformation
7080 //===----------------------------------------------------------------------===//
7081 template <typename Derived>
7084 
7085  // Transform the clauses
7087  ArrayRef<OMPClause *> Clauses = D->clauses();
7088  TClauses.reserve(Clauses.size());
7089  for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7090  I != E; ++I) {
7091  if (*I) {
7092  getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
7093  OMPClause *Clause = getDerived().TransformOMPClause(*I);
7094  getDerived().getSema().EndOpenMPClause();
7095  if (Clause)
7096  TClauses.push_back(Clause);
7097  } else {
7098  TClauses.push_back(nullptr);
7099  }
7100  }
7101  StmtResult AssociatedStmt;
7102  if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
7103  getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7104  /*CurScope=*/nullptr);
7105  StmtResult Body;
7106  {
7107  Sema::CompoundScopeRAII CompoundScope(getSema());
7108  Body = getDerived().TransformStmt(
7109  cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7110  }
7111  AssociatedStmt =
7112  getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
7113  if (AssociatedStmt.isInvalid()) {
7114  return StmtError();
7115  }
7116  }
7117  if (TClauses.size() != Clauses.size()) {
7118  return StmtError();
7119  }
7120 
7121  // Transform directive name for 'omp critical' directive.
7122  DeclarationNameInfo DirName;
7123  if (D->getDirectiveKind() == OMPD_critical) {
7124  DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7125  DirName = getDerived().TransformDeclarationNameInfo(DirName);
7126  }
7127  OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7128  if (D->getDirectiveKind() == OMPD_cancellation_point) {
7129  CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
7130  } else if (D->getDirectiveKind() == OMPD_cancel) {
7131  CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
7132  }
7133 
7134  return getDerived().RebuildOMPExecutableDirective(
7135  D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7136  AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
7137 }
7138 
7139 template <typename Derived>
7140 StmtResult
7142  DeclarationNameInfo DirName;
7143  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7144  D->getLocStart());
7145  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7146  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7147  return Res;
7148 }
7149 
7150 template <typename Derived>
7151 StmtResult
7152 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7153  DeclarationNameInfo DirName;
7154  getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7155  D->getLocStart());
7156  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7157  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7158  return Res;
7159 }
7160 
7161 template <typename Derived>
7162 StmtResult
7163 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7164  DeclarationNameInfo DirName;
7165  getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7166  D->getLocStart());
7167  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7168  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7169  return Res;
7170 }
7171 
7172 template <typename Derived>
7173 StmtResult
7174 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7175  DeclarationNameInfo DirName;
7176  getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7177  D->getLocStart());
7178  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7179  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7180  return Res;
7181 }
7182 
7183 template <typename Derived>
7184 StmtResult
7185 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7186  DeclarationNameInfo DirName;
7187  getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7188  D->getLocStart());
7189  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7190  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7191  return Res;
7192 }
7193 
7194 template <typename Derived>
7195 StmtResult
7196 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7197  DeclarationNameInfo DirName;
7198  getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7199  D->getLocStart());
7200  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7201  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7202  return Res;
7203 }
7204 
7205 template <typename Derived>
7206 StmtResult
7207 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7208  DeclarationNameInfo DirName;
7209  getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7210  D->getLocStart());
7211  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7212  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7213  return Res;
7214 }
7215 
7216 template <typename Derived>
7217 StmtResult
7218 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7219  DeclarationNameInfo DirName;
7220  getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7221  D->getLocStart());
7222  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7223  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7224  return Res;
7225 }
7226 
7227 template <typename Derived>
7228 StmtResult
7229 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7230  getDerived().getSema().StartOpenMPDSABlock(
7231  OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7232  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7233  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7234  return Res;
7235 }
7236 
7237 template <typename Derived>
7238 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7239  OMPParallelForDirective *D) {
7240  DeclarationNameInfo DirName;
7241  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7242  nullptr, D->getLocStart());
7243  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7244  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7245  return Res;
7246 }
7247 
7248 template <typename Derived>
7249 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7250  OMPParallelForSimdDirective *D) {
7251  DeclarationNameInfo DirName;
7252  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7253  nullptr, D->getLocStart());
7254  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7255  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7256  return Res;
7257 }
7258 
7259 template <typename Derived>
7260 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7261  OMPParallelSectionsDirective *D) {
7262  DeclarationNameInfo DirName;
7263  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7264  nullptr, D->getLocStart());
7265  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7266  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7267  return Res;
7268 }
7269 
7270 template <typename Derived>
7271 StmtResult
7272 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7273  DeclarationNameInfo DirName;
7274  getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7275  D->getLocStart());
7276  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7277  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7278  return Res;
7279 }
7280 
7281 template <typename Derived>
7282 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7283  OMPTaskyieldDirective *D) {
7284  DeclarationNameInfo DirName;
7285  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7286  D->getLocStart());
7287  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7288  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7289  return Res;
7290 }
7291 
7292 template <typename Derived>
7293 StmtResult
7294 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7295  DeclarationNameInfo DirName;
7296  getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7297  D->getLocStart());
7298  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7299  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7300  return Res;
7301 }
7302 
7303 template <typename Derived>
7304 StmtResult
7305 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7306  DeclarationNameInfo DirName;
7307  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7308  D->getLocStart());
7309  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7310  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7311  return Res;
7312 }
7313 
7314 template <typename Derived>
7315 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7316  OMPTaskgroupDirective *D) {
7317  DeclarationNameInfo DirName;
7318  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7319  D->getLocStart());
7320  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7321  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7322  return Res;
7323 }
7324 
7325 template <typename Derived>
7326 StmtResult
7327 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7328  DeclarationNameInfo DirName;
7329  getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7330  D->getLocStart());
7331  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7332  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7333  return Res;
7334 }
7335 
7336 template <typename Derived>
7337 StmtResult
7338 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7339  DeclarationNameInfo DirName;
7340  getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7341  D->getLocStart());
7342  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7343  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7344  return Res;
7345 }
7346 
7347 template <typename Derived>
7348 StmtResult
7349 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7350  DeclarationNameInfo DirName;
7351  getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7352  D->getLocStart());
7353  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7354  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7355  return Res;
7356 }
7357 
7358 template <typename Derived>
7359 StmtResult
7360 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7361  DeclarationNameInfo DirName;
7362  getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7363  D->getLocStart());
7364  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7365  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7366  return Res;
7367 }
7368 
7369 template <typename Derived>
7370 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7371  OMPTargetDataDirective *D) {
7372  DeclarationNameInfo DirName;
7373  getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7374  D->getLocStart());
7375  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7376  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7377  return Res;
7378 }
7379 
7380 template <typename Derived>
7381 StmtResult
7382 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7383  DeclarationNameInfo DirName;
7384  getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7385  D->getLocStart());
7386  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7387  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7388  return Res;
7389 }
7390 
7391 template <typename Derived>
7392 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7393  OMPCancellationPointDirective *D) {
7394  DeclarationNameInfo DirName;
7395  getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7396  nullptr, D->getLocStart());
7397  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7398  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7399  return Res;
7400 }
7401 
7402 template <typename Derived>
7403 StmtResult
7404 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7405  DeclarationNameInfo DirName;
7406  getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7407  D->getLocStart());
7408  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7409  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7410  return Res;
7411 }
7412 
7413 template <typename Derived>
7414 StmtResult
7415 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7416  DeclarationNameInfo DirName;
7417  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7418  D->getLocStart());
7419  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7420  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7421  return Res;
7422 }
7423 
7424 template <typename Derived>
7425 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7426  OMPTaskLoopSimdDirective *D) {
7427  DeclarationNameInfo DirName;
7428  getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7429  nullptr, D->getLocStart());
7430  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7431  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7432  return Res;
7433 }
7434 
7435 template <typename Derived>
7436 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7437  OMPDistributeDirective *D) {
7438  DeclarationNameInfo DirName;
7439  getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7440  D->getLocStart());
7441  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7442  getDerived().getSema().EndOpenMPDSABlock(Res.get());
7443  return Res;
7444 }
7445 
7446 //===----------------------------------------------------------------------===//
7447 // OpenMP clause transformation
7448 //===----------------------------------------------------------------------===//
7449 template <typename Derived>
7450 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
7451  ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7452  if (Cond.isInvalid())
7453  return nullptr;
7454  return getDerived().RebuildOMPIfClause(
7455  C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7456  C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
7457 }
7458 
7459 template <typename Derived>
7460 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7461  ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7462  if (Cond.isInvalid())
7463  return nullptr;
7464  return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7465  C->getLParenLoc(), C->getLocEnd());
7466 }
7467 
7468 template <typename Derived>
7469 OMPClause *
7470 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7471  ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7472  if (NumThreads.isInvalid())
7473  return nullptr;
7474  return getDerived().RebuildOMPNumThreadsClause(
7475  NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7476 }
7477 
7478 template <typename Derived>
7479 OMPClause *
7480 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7481  ExprResult E = getDerived().TransformExpr(C->getSafelen());
7482  if (E.isInvalid())
7483  return nullptr;
7484  return getDerived().RebuildOMPSafelenClause(
7485  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7486 }
7487 
7488 template <typename Derived>
7489 OMPClause *
7490 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7491  ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7492  if (E.isInvalid())
7493  return nullptr;
7494  return getDerived().RebuildOMPSimdlenClause(
7495  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7496 }
7497 
7498 template <typename Derived>
7499 OMPClause *
7500 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7501  ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7502  if (E.isInvalid())
7503  return nullptr;
7504  return getDerived().RebuildOMPCollapseClause(
7505  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7506 }
7507 
7508 template <typename Derived>
7509 OMPClause *
7510 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
7511  return getDerived().RebuildOMPDefaultClause(
7512  C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7513  C->getLParenLoc(), C->getLocEnd());
7514 }
7515 
7516 template <typename Derived>
7517 OMPClause *
7518 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
7519  return getDerived().RebuildOMPProcBindClause(
7520  C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7521  C->getLParenLoc(), C->getLocEnd());
7522 }
7523 
7524 template <typename Derived>
7525 OMPClause *
7526 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7527  ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7528  if (E.isInvalid())
7529  return nullptr;
7530  return getDerived().RebuildOMPScheduleClause(
7531  C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
7532  C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7533  C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
7534  C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7535 }
7536 
7537 template <typename Derived>
7538 OMPClause *
7539 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7540  ExprResult E;
7541  if (auto *Num = C->getNumForLoops()) {
7542  E = getDerived().TransformExpr(Num);
7543  if (E.isInvalid())
7544  return nullptr;
7545  }
7546  return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7547  C->getLParenLoc(), E.get());
7548 }
7549 
7550 template <typename Derived>
7551 OMPClause *
7552 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7553  // No need to rebuild this clause, no template-dependent parameters.
7554  return C;
7555 }
7556 
7557 template <typename Derived>
7558 OMPClause *
7559 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7560  // No need to rebuild this clause, no template-dependent parameters.
7561  return C;
7562 }
7563 
7564 template <typename Derived>
7565 OMPClause *
7566 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7567  // No need to rebuild this clause, no template-dependent parameters.
7568  return C;
7569 }
7570 
7571 template <typename Derived>
7572 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7573  // No need to rebuild this clause, no template-dependent parameters.
7574  return C;
7575 }
7576 
7577 template <typename Derived>
7578 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7579  // No need to rebuild this clause, no template-dependent parameters.
7580  return C;
7581 }
7582 
7583 template <typename Derived>
7584 OMPClause *
7585 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7586  // No need to rebuild this clause, no template-dependent parameters.
7587  return C;
7588 }
7589 
7590 template <typename Derived>
7591 OMPClause *
7592 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7593  // No need to rebuild this clause, no template-dependent parameters.
7594  return C;
7595 }
7596 
7597 template <typename Derived>
7598 OMPClause *
7599 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7600  // No need to rebuild this clause, no template-dependent parameters.
7601  return C;
7602 }
7603 
7604 template <typename Derived>
7605 OMPClause *
7606 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7607  // No need to rebuild this clause, no template-dependent parameters.
7608  return C;
7609 }
7610 
7611 template <typename Derived>
7612 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7613  // No need to rebuild this clause, no template-dependent parameters.
7614  return C;
7615 }
7616 
7617 template <typename Derived>
7618 OMPClause *
7619 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7620  // No need to rebuild this clause, no template-dependent parameters.
7621  return C;
7622 }
7623 
7624 template <typename Derived>
7625 OMPClause *
7626 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
7628  Vars.reserve(C->varlist_size());
7629  for (auto *VE : C->varlists()) {
7630  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7631  if (EVar.isInvalid())
7632  return nullptr;
7633  Vars.push_back(EVar.get());
7634  }
7635  return getDerived().RebuildOMPPrivateClause(
7636  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7637 }
7638 
7639 template <typename Derived>
7640 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7641  OMPFirstprivateClause *C) {
7643  Vars.reserve(C->varlist_size());
7644  for (auto *VE : C->varlists()) {
7645  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7646  if (EVar.isInvalid())
7647  return nullptr;
7648  Vars.push_back(EVar.get());
7649  }
7650  return getDerived().RebuildOMPFirstprivateClause(
7651  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7652 }
7653 
7654 template <typename Derived>
7655 OMPClause *
7656 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7658  Vars.reserve(C->varlist_size());
7659  for (auto *VE : C->varlists()) {
7660  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7661  if (EVar.isInvalid())
7662  return nullptr;
7663  Vars.push_back(EVar.get());
7664  }
7665  return getDerived().RebuildOMPLastprivateClause(
7666  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7667 }
7668 
7669 template <typename Derived>
7670 OMPClause *
7671 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7673  Vars.reserve(C->varlist_size());
7674  for (auto *VE : C->varlists()) {
7675  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7676  if (EVar.isInvalid())
7677  return nullptr;
7678  Vars.push_back(EVar.get());
7679  }
7680  return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7681  C->getLParenLoc(), C->getLocEnd());
7682 }
7683 
7684 template <typename Derived>
7685 OMPClause *
7686 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7688  Vars.reserve(C->varlist_size());
7689  for (auto *VE : C->varlists()) {
7690  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7691  if (EVar.isInvalid())
7692  return nullptr;
7693  Vars.push_back(EVar.get());
7694  }
7695  CXXScopeSpec ReductionIdScopeSpec;
7696  ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7697 
7698  DeclarationNameInfo NameInfo = C->getNameInfo();
7699  if (NameInfo.getName()) {
7700  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7701  if (!NameInfo.getName())
7702  return nullptr;
7703  }
7704  return getDerived().RebuildOMPReductionClause(
7705  Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7706  C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7707 }
7708 
7709 template <typename Derived>
7710 OMPClause *
7711 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7713  Vars.reserve(C->varlist_size());
7714  for (auto *VE : C->varlists()) {
7715  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7716  if (EVar.isInvalid())
7717  return nullptr;
7718  Vars.push_back(EVar.get());
7719  }
7720  ExprResult Step = getDerived().TransformExpr(C->getStep());
7721  if (Step.isInvalid())
7722  return nullptr;
7723  return getDerived().RebuildOMPLinearClause(
7724  Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7725  C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
7726 }
7727 
7728 template <typename Derived>
7729 OMPClause *
7730 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7732  Vars.reserve(C->varlist_size());
7733  for (auto *VE : C->varlists()) {
7734  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7735  if (EVar.isInvalid())
7736  return nullptr;
7737  Vars.push_back(EVar.get());
7738  }
7739  ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7740  if (Alignment.isInvalid())
7741  return nullptr;
7742  return getDerived().RebuildOMPAlignedClause(
7743  Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7744  C->getColonLoc(), C->getLocEnd());
7745 }
7746 
7747 template <typename Derived>
7748 OMPClause *
7749 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7751  Vars.reserve(C->varlist_size());
7752  for (auto *VE : C->varlists()) {
7753  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7754  if (EVar.isInvalid())
7755  return nullptr;
7756  Vars.push_back(EVar.get());
7757  }
7758  return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7759  C->getLParenLoc(), C->getLocEnd());
7760 }
7761 
7762 template <typename Derived>
7763 OMPClause *
7764 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7766  Vars.reserve(C->varlist_size());
7767  for (auto *VE : C->varlists()) {
7768  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7769  if (EVar.isInvalid())
7770  return nullptr;
7771  Vars.push_back(EVar.get());
7772  }
7773  return getDerived().RebuildOMPCopyprivateClause(
7774  Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7775 }
7776 
7777 template <typename Derived>
7778 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7780  Vars.reserve(C->varlist_size());
7781  for (auto *VE : C->varlists()) {
7782  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7783  if (EVar.isInvalid())
7784  return nullptr;
7785  Vars.push_back(EVar.get());
7786  }
7787  return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7788  C->getLParenLoc(), C->getLocEnd());
7789 }
7790 
7791 template <typename Derived>
7792 OMPClause *
7793 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7795  Vars.reserve(C->varlist_size());
7796  for (auto *VE : C->varlists()) {
7797  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7798  if (EVar.isInvalid())
7799  return nullptr;
7800  Vars.push_back(EVar.get());
7801  }
7802  return getDerived().RebuildOMPDependClause(
7803  C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7804  C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7805 }
7806 
7807 template <typename Derived>
7808 OMPClause *
7809 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7810  ExprResult E = getDerived().TransformExpr(C->getDevice());
7811  if (E.isInvalid())
7812  return nullptr;
7813  return getDerived().RebuildOMPDeviceClause(
7814  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7815 }
7816 
7817 template <typename Derived>
7818 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
7820  Vars.reserve(C->varlist_size());
7821  for (auto *VE : C->varlists()) {
7822  ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7823  if (EVar.isInvalid())
7824  return nullptr;
7825  Vars.push_back(EVar.get());
7826  }
7827  return getDerived().RebuildOMPMapClause(
7828  C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(),
7829  C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(),
7830  C->getLocEnd());
7831 }
7832 
7833 template <typename Derived>
7834 OMPClause *
7835 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
7836  ExprResult E = getDerived().TransformExpr(C->getNumTeams());
7837  if (E.isInvalid())
7838  return nullptr;
7839  return getDerived().RebuildOMPNumTeamsClause(
7840  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7841 }
7842 
7843 template <typename Derived>
7844 OMPClause *
7845 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
7846  ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
7847  if (E.isInvalid())
7848  return nullptr;
7849  return getDerived().RebuildOMPThreadLimitClause(
7850  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7851 }
7852 
7853 template <typename Derived>
7854 OMPClause *
7855 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
7856  ExprResult E = getDerived().TransformExpr(C->getPriority());
7857  if (E.isInvalid())
7858  return nullptr;
7859  return getDerived().RebuildOMPPriorityClause(
7860  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7861 }
7862 
7863 template <typename Derived>
7864 OMPClause *
7865 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
7866  ExprResult E = getDerived().TransformExpr(C->getGrainsize());
7867  if (E.isInvalid())
7868  return nullptr;
7869  return getDerived().RebuildOMPGrainsizeClause(
7870  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7871 }
7872 
7873 template <typename Derived>
7874 OMPClause *
7875 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
7876  ExprResult E = getDerived().TransformExpr(C->getNumTasks());
7877  if (E.isInvalid())
7878  return nullptr;
7879  return getDerived().RebuildOMPNumTasksClause(
7880  E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7881 }
7882 
7883 template <typename Derived>
7884 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
7885  ExprResult E = getDerived().TransformExpr(C->getHint());
7886  if (E.isInvalid())
7887  return nullptr;
7888  return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
7889  C->getLParenLoc(), C->getLocEnd());
7890 }
7891 
7892 //===----------------------------------------------------------------------===//
7893 // Expression transformation
7894 //===----------------------------------------------------------------------===//
7895 template<typename Derived>
7896 ExprResult
7897 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
7898  if (!E->isTypeDependent())
7899  return E;
7900 
7901  return getDerived().RebuildPredefinedExpr(E->getLocation(),
7902  E->getIdentType());
7903 }
7904 
7905 template<typename Derived>
7906 ExprResult
7907 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
7908  NestedNameSpecifierLoc QualifierLoc;
7909  if (E->getQualifierLoc()) {
7910  QualifierLoc
7911  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7912  if (!QualifierLoc)
7913  return ExprError();
7914  }
7915 
7916  ValueDecl *ND
7917  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7918  E->getDecl()));
7919  if (!ND)
7920  return ExprError();
7921 
7922  DeclarationNameInfo NameInfo = E->getNameInfo();
7923  if (NameInfo.getName()) {
7924  NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7925  if (!NameInfo.getName())
7926  return ExprError();
7927  }
7928 
7929  if (!getDerived().AlwaysRebuild() &&
7930  QualifierLoc == E->getQualifierLoc() &&
7931  ND == E->getDecl() &&
7932  NameInfo.getName() == E->getDecl()->getDeclName() &&
7933  !E->hasExplicitTemplateArgs()) {
7934 
7935  // Mark it referenced in the new context regardless.
7936  // FIXME: this is a bit instantiation-specific.
7937  SemaRef.MarkDeclRefReferenced(E);
7938 
7939  return E;
7940  }
7941 
7942  TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
7943  if (E->hasExplicitTemplateArgs()) {
7944  TemplateArgs = &TransArgs;
7945  TransArgs.setLAngleLoc(E->getLAngleLoc());
7946  TransArgs.setRAngleLoc(E->getRAngleLoc());
7947  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7948  E->getNumTemplateArgs(),
7949  TransArgs))
7950  return ExprError();
7951  }
7952 
7953  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
7954  TemplateArgs);
7955 }
7956 
7957 template<typename Derived>
7958 ExprResult
7959 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
7960  return E;
7961 }
7962 
7963 template<typename Derived>
7964 ExprResult
7965 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
7966  return E;
7967 }
7968 
7969 template<typename Derived>
7970 ExprResult
7971 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
7972  return E;
7973 }
7974 
7975 template<typename Derived>
7976 ExprResult
7977 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
7978  return E;
7979 }
7980 
7981 template<typename Derived>
7982 ExprResult
7983 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
7984  return E;
7985 }
7986 
7987 template<typename Derived>
7988 ExprResult
7989 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
7990  if (FunctionDecl *FD = E->getDirectCallee())
7991  SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
7992  return SemaRef.MaybeBindToTemporary(E);
7993 }
7994 
7995 template<typename Derived>
7996 ExprResult
7997 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7998  ExprResult ControllingExpr =
7999  getDerived().TransformExpr(E->getControllingExpr());
8000  if (ControllingExpr.isInvalid())
8001  return ExprError();
8002 
8003  SmallVector<Expr *, 4> AssocExprs;
8004  SmallVector<TypeSourceInfo *, 4> AssocTypes;
8005  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8006  TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8007  if (TS) {
8008  TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8009  if (!AssocType)
8010  return ExprError();
8011  AssocTypes.push_back(AssocType);
8012  } else {
8013  AssocTypes.push_back(nullptr);
8014  }
8015 
8016  ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8017  if (AssocExpr.isInvalid())
8018  return ExprError();
8019  AssocExprs.push_back(AssocExpr.get());
8020  }
8021 
8022  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8023  E->getDefaultLoc(),
8024  E->getRParenLoc(),
8025  ControllingExpr.get(),
8026  AssocTypes,
8027  AssocExprs);
8028 }
8029 
8030 template<typename Derived>
8031 ExprResult
8032 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
8033  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8034  if (SubExpr.isInvalid())
8035  return ExprError();
8036 
8037  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8038  return E;
8039 
8040  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
8041  E->getRParen());
8042 }
8043 
8044 /// \brief The operand of a unary address-of operator has special rules: it's
8045 /// allowed to refer to a non-static member of a class even if there's no 'this'
8046 /// object available.
8047 template<typename Derived>
8048 ExprResult
8050  if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
8051  return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
8052  else
8053  return getDerived().TransformExpr(E);
8054 }
8055 
8056 template<typename Derived>
8057 ExprResult
8059  ExprResult SubExpr;
8060  if (E->getOpcode() == UO_AddrOf)
8061  SubExpr = TransformAddressOfOperand(E->getSubExpr());
8062  else
8063  SubExpr = TransformExpr(E->getSubExpr());
8064  if (SubExpr.isInvalid())
8065  return ExprError();
8066 
8067  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
8068  return E;
8069 
8070  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8071  E->getOpcode(),
8072  SubExpr.get());
8073 }
8074 
8075 template<typename Derived>
8076 ExprResult
8077 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8078  // Transform the type.
8079  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8080  if (!Type)
8081  return ExprError();
8082 
8083  // Transform all of the components into components similar to what the
8084  // parser uses.
8085  // FIXME: It would be slightly more efficient in the non-dependent case to
8086  // just map FieldDecls, rather than requiring the rebuilder to look for
8087  // the fields again. However, __builtin_offsetof is rare enough in
8088  // template code that we don't care.
8089  bool ExprChanged = false;
8090  typedef Sema::OffsetOfComponent Component;
8091  SmallVector<Component, 4> Components;
8092  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
8093  const OffsetOfNode &ON = E->getComponent(I);
8094  Component Comp;
8095  Comp.isBrackets = true;
8096  Comp.LocStart = ON.getSourceRange().getBegin();
8097  Comp.LocEnd = ON.getSourceRange().getEnd();
8098  switch (ON.getKind()) {
8099  case OffsetOfNode::Array: {
8100  Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
8101  ExprResult Index = getDerived().TransformExpr(FromIndex);
8102  if (Index.isInvalid())
8103  return ExprError();
8104 
8105  ExprChanged = ExprChanged || Index.get() != FromIndex;
8106  Comp.isBrackets = true;
8107  Comp.U.E = Index.get();
8108  break;
8109  }
8110 
8111  case OffsetOfNode::Field:
8113  Comp.isBrackets = false;
8114  Comp.U.IdentInfo = ON.getFieldName();
8115  if (!Comp.U.IdentInfo)
8116  continue;
8117 
8118  break;
8119 
8120  case OffsetOfNode::Base:
8121  // Will be recomputed during the rebuild.
8122  continue;
8123  }
8124 
8125  Components.push_back(Comp);
8126  }
8127 
8128  // If nothing changed, retain the existing expression.
8129  if (!getDerived().AlwaysRebuild() &&
8130  Type == E->getTypeSourceInfo() &&
8131  !ExprChanged)
8132  return E;
8133 
8134  // Build a new offsetof expression.
8135  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
8136  Components, E->getRParenLoc());
8137 }
8138 
8139 template<typename Derived>
8140 ExprResult
8141 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
8142  assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
8143  "opaque value expression requires transformation");
8144  return E;
8145 }
8146 
8147 template<typename Derived>
8148 ExprResult
8149 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8150  return E;
8151 }
8152 
8153 template<typename Derived>
8154 ExprResult
8155 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
8156  // Rebuild the syntactic form. The original syntactic form has
8157  // opaque-value expressions in it, so strip those away and rebuild
8158  // the result. This is a really awful way of doing this, but the
8159  // better solution (rebuilding the semantic expressions and
8160  // rebinding OVEs as necessary) doesn't work; we'd need
8161  // TreeTransform to not strip away implicit conversions.
8162  Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8163  ExprResult result = getDerived().TransformExpr(newSyntacticForm);
8164  if (result.isInvalid()) return ExprError();
8165 
8166  // If that gives us a pseudo-object result back, the pseudo-object
8167  // expression must have been an lvalue-to-rvalue conversion which we
8168  // should reapply.
8169  if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
8170  result = SemaRef.checkPseudoObjectRValue(result.get());
8171 
8172  return result;
8173 }
8174 
8175 template<typename Derived>
8176 ExprResult
8177 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8178  UnaryExprOrTypeTraitExpr *E) {
8179  if (E->isArgumentType()) {
8180  TypeSourceInfo *OldT = E->getArgumentTypeInfo();
8181 
8182  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8183  if (!NewT)
8184  return ExprError();
8185 
8186  if (!getDerived().AlwaysRebuild() && OldT == NewT)
8187  return E;
8188 
8189  return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8190  E->getKind(),
8191  E->getSourceRange());
8192  }
8193 
8194  // C++0x [expr.sizeof]p1:
8195  // The operand is either an expression, which is an unevaluated operand
8196  // [...]
8197  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8199 
8200  // Try to recover if we have something like sizeof(T::X) where X is a type.
8201  // Notably, there must be *exactly* one set of parens if X is a type.
8202  TypeSourceInfo *RecoveryTSI = nullptr;
8203  ExprResult SubExpr;
8204  auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8205  if (auto *DRE =
8206  PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8207  SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8208  PE, DRE, false, &RecoveryTSI);
8209  else
8210  SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8211 
8212  if (RecoveryTSI) {
8213  return getDerived().RebuildUnaryExprOrTypeTrait(
8214  RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8215  } else if (SubExpr.isInvalid())
8216  return ExprError();
8217 
8218  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
8219  return E;
8220 
8221  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8222  E->getOperatorLoc(),
8223  E->getKind(),
8224  E->getSourceRange());
8225 }
8226 
8227 template<typename Derived>
8228 ExprResult
8229 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
8230  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8231  if (LHS.isInvalid())
8232  return ExprError();
8233 
8234  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8235  if (RHS.isInvalid())
8236  return ExprError();
8237 
8238 
8239  if (!getDerived().AlwaysRebuild() &&
8240  LHS.get() == E->getLHS() &&
8241  RHS.get() == E->getRHS())
8242  return E;
8243 
8244  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
8245  /*FIXME:*/E->getLHS()->getLocStart(),
8246  RHS.get(),
8247  E->getRBracketLoc());
8248 }
8249 
8250 template <typename Derived>
8251 ExprResult
8252 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8253  ExprResult Base = getDerived().TransformExpr(E->getBase());
8254  if (Base.isInvalid())
8255  return ExprError();
8256 
8257  ExprResult LowerBound;
8258  if (E->getLowerBound()) {
8259  LowerBound = getDerived().TransformExpr(E->getLowerBound());
8260  if (LowerBound.isInvalid())
8261  return ExprError();
8262  }
8263 
8265  if (E->getLength()) {
8266  Length = getDerived().TransformExpr(E->getLength());
8267  if (Length.isInvalid())
8268  return ExprError();
8269  }
8270 
8271  if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8272  LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8273  return E;
8274 
8275  return getDerived().RebuildOMPArraySectionExpr(
8276  Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8277  Length.get(), E->getRBracketLoc());
8278 }
8279 
8280 template<typename Derived>
8281 ExprResult
8282 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
8283  // Transform the callee.
8284  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8285  if (Callee.isInvalid())
8286  return ExprError();
8287 
8288  // Transform arguments.
8289  bool ArgChanged = false;
8290  SmallVector<Expr*, 8> Args;
8291  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8292  &ArgChanged))
8293  return ExprError();
8294 
8295  if (!getDerived().AlwaysRebuild() &&
8296  Callee.get() == E->getCallee() &&
8297  !ArgChanged)
8298  return SemaRef.MaybeBindToTemporary(E);
8299 
8300  // FIXME: Wrong source location information for the '('.
8301  SourceLocation FakeLParenLoc
8302  = ((Expr *)Callee.get())->getSourceRange().getBegin();
8303  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
8304  Args,
8305  E->getRParenLoc());
8306 }
8307 
8308 template<typename Derived>
8309 ExprResult
8310 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
8311  ExprResult Base = getDerived().TransformExpr(E->getBase());
8312  if (Base.isInvalid())
8313  return ExprError();
8314 
8315  NestedNameSpecifierLoc QualifierLoc;
8316  if (E->hasQualifier()) {
8317  QualifierLoc
8318  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8319 
8320  if (!QualifierLoc)
8321  return ExprError();
8322  }
8323  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8324 
8325  ValueDecl *Member
8326  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8327  E->getMemberDecl()));
8328  if (!Member)
8329  return ExprError();
8330 
8331  NamedDecl *FoundDecl = E->getFoundDecl();
8332  if (FoundDecl == E->getMemberDecl()) {
8333  FoundDecl = Member;
8334  } else {
8335  FoundDecl = cast_or_null<NamedDecl>(
8336  getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8337  if (!FoundDecl)
8338  return ExprError();
8339  }
8340 
8341  if (!getDerived().AlwaysRebuild() &&
8342  Base.get() == E->getBase() &&
8343  QualifierLoc == E->getQualifierLoc() &&
8344  Member == E->getMemberDecl() &&
8345  FoundDecl == E->getFoundDecl() &&
8346  !E->hasExplicitTemplateArgs()) {
8347 
8348  // Mark it referenced in the new context regardless.
8349  // FIXME: this is a bit instantiation-specific.
8350  SemaRef.MarkMemberReferenced(E);
8351 
8352  return E;
8353  }
8354 
8355  TemplateArgumentListInfo TransArgs;
8356  if (E->hasExplicitTemplateArgs()) {
8357  TransArgs.setLAngleLoc(E->getLAngleLoc());
8358  TransArgs.setRAngleLoc(E->getRAngleLoc());
8359  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8360  E->getNumTemplateArgs(),
8361  TransArgs))
8362  return ExprError();
8363  }
8364 
8365  // FIXME: Bogus source location for the operator
8366  SourceLocation FakeOperatorLoc =
8367  SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
8368 
8369  // FIXME: to do this check properly, we will need to preserve the
8370  // first-qualifier-in-scope here, just in case we had a dependent
8371  // base (and therefore couldn't do the check) and a
8372  // nested-name-qualifier (and therefore could do the lookup).
8373  NamedDecl *FirstQualifierInScope = nullptr;
8374 
8375  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
8376  E->isArrow(),
8377  QualifierLoc,
8378  TemplateKWLoc,
8379  E->getMemberNameInfo(),
8380  Member,
8381  FoundDecl,
8382  (E->hasExplicitTemplateArgs()
8383  ? &TransArgs : nullptr),
8384  FirstQualifierInScope);
8385 }
8386 
8387 template<typename Derived>
8388 ExprResult
8389 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
8390  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8391  if (LHS.isInvalid())
8392  return ExprError();
8393 
8394  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8395  if (RHS.isInvalid())
8396  return ExprError();
8397 
8398  if (!getDerived().AlwaysRebuild() &&
8399  LHS.get() == E->getLHS() &&
8400  RHS.get() == E->getRHS())
8401  return E;
8402 
8403  Sema::FPContractStateRAII FPContractState(getSema());
8404  getSema().FPFeatures.fp_contract = E->isFPContractable();
8405 
8406  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
8407  LHS.get(), RHS.get());
8408 }
8409 
8410 template<typename Derived>
8411 ExprResult
8412 TreeTransform<Derived>::TransformCompoundAssignOperator(
8413  CompoundAssignOperator *E) {
8414  return getDerived().TransformBinaryOperator(E);
8415 }
8416 
8417 template<typename Derived>
8418 ExprResult TreeTransform<Derived>::
8419 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8420  // Just rebuild the common and RHS expressions and see whether we
8421  // get any changes.
8422 
8423  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8424  if (commonExpr.isInvalid())
8425  return ExprError();
8426 
8427  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8428  if (rhs.isInvalid())
8429  return ExprError();
8430 
8431  if (!getDerived().AlwaysRebuild() &&
8432  commonExpr.get() == e->getCommon() &&
8433  rhs.get() == e->getFalseExpr())
8434  return e;
8435 
8436  return getDerived().RebuildConditionalOperator(commonExpr.get(),
8437  e->getQuestionLoc(),
8438  nullptr,
8439  e->getColonLoc(),
8440  rhs.get());
8441 }
8442 
8443 template<typename Derived>
8444 ExprResult
8445 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
8446  ExprResult Cond = getDerived().TransformExpr(E->getCond());
8447  if (Cond.isInvalid())
8448  return ExprError();
8449 
8450  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8451  if (LHS.isInvalid())
8452  return ExprError();
8453 
8454  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8455  if (RHS.isInvalid())
8456  return ExprError();
8457 
8458  if (!getDerived().AlwaysRebuild() &&
8459  Cond.get() == E->getCond() &&
8460  LHS.get() == E->getLHS() &&
8461  RHS.get() == E->getRHS())
8462  return E;
8463 
8464  return getDerived().RebuildConditionalOperator(Cond.get(),
8465  E->getQuestionLoc(),
8466  LHS.get(),
8467  E->getColonLoc(),
8468  RHS.get());
8469 }
8470 
8471 template<typename Derived>
8472 ExprResult
8473 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
8474  // Implicit casts are eliminated during transformation, since they
8475  // will be recomputed by semantic analysis after transformation.
8476  return getDerived().TransformExpr(E->getSubExprAsWritten());
8477 }
8478 
8479 template<typename Derived>
8480 ExprResult
8481 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
8482  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8483  if (!Type)
8484  return ExprError();
8485 
8486  ExprResult SubExpr
8487  = getDerived().TransformExpr(E->getSubExprAsWritten());
8488  if (SubExpr.isInvalid())
8489  return ExprError();
8490 
8491  if (!getDerived().AlwaysRebuild() &&
8492  Type == E->getTypeInfoAsWritten() &&
8493  SubExpr.get() == E->getSubExpr())
8494  return E;
8495 
8496  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
8497  Type,
8498  E->getRParenLoc(),
8499  SubExpr.get());
8500 }
8501 
8502 template<typename Derived>
8503 ExprResult
8504 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
8505  TypeSourceInfo *OldT = E->getTypeSourceInfo();
8506  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8507  if (!NewT)
8508  return ExprError();
8509 
8510  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
8511  if (Init.isInvalid())
8512  return ExprError();
8513 
8514  if (!getDerived().AlwaysRebuild() &&
8515  OldT == NewT &&
8516  Init.get() == E->getInitializer())
8517  return SemaRef.MaybeBindToTemporary(E);
8518 
8519  // Note: the expression type doesn't necessarily match the
8520  // type-as-written, but that's okay, because it should always be
8521  // derivable from the initializer.
8522 
8523  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
8524  /*FIXME:*/E->getInitializer()->getLocEnd(),
8525  Init.get());
8526 }
8527 
8528 template<typename Derived>
8529 ExprResult
8530 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
8531  ExprResult Base = getDerived().TransformExpr(E->getBase());
8532  if (Base.isInvalid())
8533  return ExprError();
8534 
8535  if (!getDerived().AlwaysRebuild() &&
8536  Base.get() == E->getBase())
8537  return E;
8538 
8539  // FIXME: Bad source location
8540  SourceLocation FakeOperatorLoc =
8541  SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
8542  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
8543  E->getAccessorLoc(),
8544  E->getAccessor());
8545 }
8546 
8547 template<typename Derived>
8548 ExprResult
8549 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
8550  if (InitListExpr *Syntactic = E->getSyntacticForm())
8551  E = Syntactic;
8552 
8553  bool InitChanged = false;
8554 
8555  SmallVector<Expr*, 4> Inits;
8556  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
8557  Inits, &InitChanged))
8558  return ExprError();
8559 
8560  if (!getDerived().AlwaysRebuild() && !InitChanged) {
8561  // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8562  // in some cases. We can't reuse it in general, because the syntactic and
8563  // semantic forms are linked, and we can't know that semantic form will
8564  // match even if the syntactic form does.
8565  }
8566 
8567  return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
8568  E->getRBraceLoc(), E->getType());
8569 }
8570 
8571 template<typename Derived>
8572 ExprResult
8573 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
8574  Designation Desig;
8575 
8576  // transform the initializer value
8577  ExprResult Init = getDerived().TransformExpr(E->getInit());
8578  if (Init.isInvalid())
8579  return ExprError();
8580 
8581  // transform the designators.
8582  SmallVector<Expr*, 4> ArrayExprs;
8583  bool ExprChanged = false;
8584  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8585  DEnd = E->designators_end();
8586  D != DEnd; ++D) {
8587  if (D->isFieldDesignator()) {
8588  Desig.AddDesignator(Designator::getField(D->getFieldName(),
8589  D->getDotLoc(),
8590  D->getFieldLoc()));
8591  continue;
8592  }
8593 
8594  if (D->isArrayDesignator()) {
8595  ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
8596  if (Index.isInvalid())
8597  return ExprError();
8598 
8599  Desig.AddDesignator(Designator::getArray(Index.get(),
8600  D->getLBracketLoc()));
8601 
8602  ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
8603  ArrayExprs.push_back(Index.get());
8604  continue;
8605  }
8606 
8607  assert(D->isArrayRangeDesignator() && "New kind of designator?");
8608  ExprResult Start
8609  = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8610  if (Start.isInvalid())
8611  return ExprError();
8612 
8613  ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
8614  if (End.isInvalid())
8615  return ExprError();
8616 
8617  Desig.AddDesignator(Designator::getArrayRange(Start.get(),
8618  End.get(),
8619  D->getLBracketLoc(),
8620  D->getEllipsisLoc()));
8621 
8622  ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8623  End.get() != E->getArrayRangeEnd(*D);
8624 
8625  ArrayExprs.push_back(Start.get());
8626  ArrayExprs.push_back(End.get());
8627  }
8628 
8629  if (!getDerived().AlwaysRebuild() &&
8630  Init.get() == E->getInit() &&
8631  !ExprChanged)
8632  return E;
8633 
8634  return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
8635  E->getEqualOrColonLoc(),
8636  E->usesGNUSyntax(), Init.get());
8637 }
8638 
8639 // Seems that if TransformInitListExpr() only works on the syntactic form of an
8640 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8641 template<typename Derived>
8642 ExprResult
8643 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8644  DesignatedInitUpdateExpr *E) {
8645  llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8646  "initializer");
8647  return ExprError();
8648 }
8649 
8650 template<typename Derived>
8651 ExprResult
8652 TreeTransform<Derived>::TransformNoInitExpr(
8653  NoInitExpr *E) {
8654  llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8655  return ExprError();
8656 }
8657 
8658 template<typename Derived>
8659 ExprResult
8660 TreeTransform<Derived>::TransformImplicitValueInitExpr(
8661  ImplicitValueInitExpr *E) {
8662  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
8663 
8664  // FIXME: Will we ever have proper type location here? Will we actually
8665  // need to transform the type?
8666  QualType T = getDerived().TransformType(E->getType());
8667  if (T.isNull())
8668  return ExprError();
8669 
8670  if (!getDerived().AlwaysRebuild() &&
8671  T == E->getType())
8672  return E;
8673 
8674  return getDerived().RebuildImplicitValueInitExpr(T);
8675 }
8676 
8677 template<typename Derived>
8678 ExprResult
8679 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
8680  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8681  if (!TInfo)
8682  return ExprError();
8683 
8684  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8685  if (SubExpr.isInvalid())
8686  return ExprError();
8687 
8688  if (!getDerived().AlwaysRebuild() &&
8689  TInfo == E->getWrittenTypeInfo() &&
8690  SubExpr.get() == E->getSubExpr())
8691  return E;
8692 
8693  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
8694  TInfo, E->getRParenLoc());
8695 }
8696 
8697 template<typename Derived>
8698 ExprResult
8699 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
8700  bool ArgumentChanged = false;
8701  SmallVector<Expr*, 4> Inits;
8702  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8703  &ArgumentChanged))
8704  return ExprError();
8705 
8706  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
8707  Inits,
8708  E->getRParenLoc());
8709 }
8710 
8711 /// \brief Transform an address-of-label expression.
8712 ///
8713 /// By default, the transformation of an address-of-label expression always
8714 /// rebuilds the expression, so that the label identifier can be resolved to
8715 /// the corresponding label statement by semantic analysis.
8716 template<typename Derived>
8717 ExprResult
8718 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
8719  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8720  E->getLabel());
8721  if (!LD)
8722  return ExprError();
8723 
8724  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
8725  cast<LabelDecl>(LD));
8726 }
8727 
8728 template<typename Derived>
8729 ExprResult
8730 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
8731  SemaRef.ActOnStartStmtExpr();
8732  StmtResult SubStmt
8733  = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
8734  if (SubStmt.isInvalid()) {
8735  SemaRef.ActOnStmtExprError();
8736  return ExprError();
8737  }
8738 
8739  if (!getDerived().AlwaysRebuild() &&
8740  SubStmt.get() == E->getSubStmt()) {
8741  // Calling this an 'error' is unintuitive, but it does the right thing.
8742  SemaRef.ActOnStmtExprError();
8743  return SemaRef.MaybeBindToTemporary(E);
8744  }
8745 
8746  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
8747  SubStmt.get(),
8748  E->getRParenLoc());
8749 }
8750 
8751 template<typename Derived>
8752 ExprResult
8753 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
8754  ExprResult Cond = getDerived().TransformExpr(E->getCond());
8755  if (Cond.isInvalid())
8756  return ExprError();
8757 
8758  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
8759  if (LHS.isInvalid())
8760  return ExprError();
8761 
8762  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
8763  if (RHS.isInvalid())
8764  return ExprError();
8765 
8766  if (!getDerived().AlwaysRebuild() &&
8767  Cond.get() == E->getCond() &&
8768  LHS.get() == E->getLHS() &&
8769  RHS.get() == E->getRHS())
8770  return E;
8771 
8772  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
8773  Cond.get(), LHS.get(), RHS.get(),
8774  E->getRParenLoc());
8775 }
8776 
8777 template<typename Derived>
8778 ExprResult
8779 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
8780  return E;
8781 }
8782 
8783 template<typename Derived>
8784 ExprResult
8785 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
8786  switch (E->getOperator()) {
8787  case OO_New:
8788  case OO_Delete:
8789  case OO_Array_New:
8790  case OO_Array_Delete:
8791  llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
8792 
8793  case OO_Call: {
8794  // This is a call to an object's operator().
8795  assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8796 
8797  // Transform the object itself.
8798  ExprResult Object = getDerived().TransformExpr(E->getArg(0));
8799  if (Object.isInvalid())
8800  return ExprError();
8801 
8802  // FIXME: Poor location information
8803  SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8804  static_cast<Expr *>(Object.get())->getLocEnd());
8805 
8806  // Transform the call arguments.
8807  SmallVector<Expr*, 8> Args;
8808  if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
8809  Args))
8810  return ExprError();
8811 
8812  return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
8813  Args,
8814  E->getLocEnd());
8815  }
8816 
8817 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8818  case OO_##Name:
8819 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8820 #include "clang/Basic/OperatorKinds.def"
8821  case OO_Subscript:
8822  // Handled below.
8823  break;
8824 
8825  case OO_Conditional:
8826  llvm_unreachable("conditional operator is not actually overloadable");
8827 
8828  case OO_None:
8830  llvm_unreachable("not an overloaded operator?");
8831  }
8832 
8833  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8834  if (Callee.isInvalid())
8835  return ExprError();
8836 
8837  ExprResult First;
8838  if (E->getOperator() == OO_Amp)
8839  First = getDerived().TransformAddressOfOperand(E->getArg(0));
8840  else
8841  First = getDerived().TransformExpr(E->getArg(0));
8842  if (First.isInvalid())
8843  return ExprError();
8844 
8845  ExprResult Second;
8846  if (E->getNumArgs() == 2) {
8847  Second = getDerived().TransformExpr(E->getArg(1));
8848  if (Second.isInvalid())
8849  return ExprError();
8850  }
8851 
8852  if (!getDerived().AlwaysRebuild() &&
8853  Callee.get() == E->getCallee() &&
8854  First.get() == E->getArg(0) &&
8855  (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
8856  return SemaRef.MaybeBindToTemporary(E);
8857 
8858  Sema::FPContractStateRAII FPContractState(getSema());
8859  getSema().FPFeatures.fp_contract = E->isFPContractable();
8860 
8861  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8862  E->getOperatorLoc(),
8863  Callee.get(),
8864  First.get(),
8865  Second.get());
8866 }
8867 
8868 template<typename Derived>
8869 ExprResult
8870 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8871  return getDerived().TransformCallExpr(E);
8872 }
8873 
8874 template<typename Derived>
8875 ExprResult
8876 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8877  // Transform the callee.
8878  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8879  if (Callee.isInvalid())
8880  return ExprError();
8881 
8882  // Transform exec config.
8883  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8884  if (EC.isInvalid())
8885  return ExprError();
8886 
8887  // Transform arguments.
8888  bool ArgChanged = false;
8889  SmallVector<Expr*, 8> Args;
8890  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
8891  &ArgChanged))
8892  return ExprError();
8893 
8894  if (!getDerived().AlwaysRebuild() &&
8895  Callee.get() == E->getCallee() &&
8896  !ArgChanged)
8897  return SemaRef.MaybeBindToTemporary(E);
8898 
8899  // FIXME: Wrong source location information for the '('.
8900  SourceLocation FakeLParenLoc
8901  = ((Expr *)Callee.get())->getSourceRange().getBegin();
8902  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
8903  Args,
8904  E->getRParenLoc(), EC.get());
8905 }
8906 
8907 template<typename Derived>
8908 ExprResult
8910  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8911  if (!Type)
8912  return ExprError();
8913 
8914  ExprResult SubExpr
8915  = getDerived().TransformExpr(E->getSubExprAsWritten());
8916  if (SubExpr.isInvalid())
8917  return ExprError();
8918 
8919  if (!getDerived().AlwaysRebuild() &&
8920  Type == E->getTypeInfoAsWritten() &&
8921  SubExpr.get() == E->getSubExpr())
8922  return E;
8923  return getDerived().RebuildCXXNamedCastExpr(
8924  E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8925  Type, E->getAngleBrackets().getEnd(),
8926  // FIXME. this should be '(' location
8927  E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
8928 }
8929 
8930 template<typename Derived>
8931 ExprResult
8933  return getDerived().TransformCXXNamedCastExpr(E);
8934 }
8935 
8936 template<typename Derived>
8937 ExprResult
8938 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8939  return getDerived().TransformCXXNamedCastExpr(E);
8940 }
8941 
8942 template<typename Derived>
8943 ExprResult
8944 TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
8945  CXXReinterpretCastExpr *E) {
8946  return getDerived().TransformCXXNamedCastExpr(E);
8947 }
8948 
8949 template<typename Derived>
8950 ExprResult
8951 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8952  return getDerived().TransformCXXNamedCastExpr(E);
8953 }
8954 
8955 template<typename Derived>
8956 ExprResult
8957 TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
8958  CXXFunctionalCastExpr *E) {
8959  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8960  if (!Type)
8961  return ExprError();
8962 
8963  ExprResult SubExpr
8964  = getDerived().TransformExpr(E->getSubExprAsWritten());
8965  if (SubExpr.isInvalid())
8966  return ExprError();
8967 
8968  if (!getDerived().AlwaysRebuild() &&
8969  Type == E->getTypeInfoAsWritten() &&
8970  SubExpr.get() == E->getSubExpr())
8971  return E;
8972 
8973  return getDerived().RebuildCXXFunctionalCastExpr(Type,
8974  E->getLParenLoc(),
8975  SubExpr.get(),
8976  E->getRParenLoc());
8977 }
8978 
8979 template<typename Derived>
8980 ExprResult
8981 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
8982  if (E->isTypeOperand()) {
8983  TypeSourceInfo *TInfo
8984  = getDerived().TransformType(E->getTypeOperandSourceInfo());
8985  if (!TInfo)
8986  return ExprError();
8987 
8988  if (!getDerived().AlwaysRebuild() &&
8989  TInfo == E->getTypeOperandSourceInfo())
8990  return E;
8991 
8992  return getDerived().RebuildCXXTypeidExpr(E->getType(),
8993  E->getLocStart(),
8994  TInfo,
8995  E->getLocEnd());
8996  }
8997 
8998  // We don't know whether the subexpression is potentially evaluated until
8999  // after we perform semantic analysis. We speculatively assume it is
9000  // unevaluated; it will get fixed later if the subexpression is in fact
9001  // potentially evaluated.
9002  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9004 
9005  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9006  if (SubExpr.isInvalid())
9007  return ExprError();
9008 
9009  if (!getDerived().AlwaysRebuild() &&
9010  SubExpr.get() == E->getExprOperand())
9011  return E;
9012 
9013  return getDerived().RebuildCXXTypeidExpr(E->getType(),
9014  E->getLocStart(),
9015  SubExpr.get(),
9016  E->getLocEnd());
9017 }
9018 
9019 template<typename Derived>
9020 ExprResult
9021 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9022  if (E->isTypeOperand()) {
9023  TypeSourceInfo *TInfo
9024  = getDerived().TransformType(E->getTypeOperandSourceInfo());
9025  if (!TInfo)
9026  return ExprError();
9027 
9028  if (!getDerived().AlwaysRebuild() &&
9029  TInfo == E->getTypeOperandSourceInfo())
9030  return E;
9031 
9032  return getDerived().RebuildCXXUuidofExpr(E->getType(),
9033  E->getLocStart(),
9034  TInfo,
9035  E->getLocEnd());
9036  }
9037 
9038  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9039 
9040  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9041  if (SubExpr.isInvalid())
9042  return ExprError();
9043 
9044  if (!getDerived().AlwaysRebuild() &&
9045  SubExpr.get() == E->getExprOperand())
9046  return E;
9047 
9048  return getDerived().RebuildCXXUuidofExpr(E->getType(),
9049  E->getLocStart(),
9050  SubExpr.get(),
9051  E->getLocEnd());
9052 }
9053 
9054 template<typename Derived>
9055 ExprResult
9056 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
9057  return E;
9058 }
9059 
9060 template<typename Derived>
9061 ExprResult
9062 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
9063  CXXNullPtrLiteralExpr *E) {
9064  return E;
9065 }
9066 
9067 template<typename Derived>
9068 ExprResult
9069 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
9070  QualType T = getSema().getCurrentThisType();
9071 
9072  if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9073  // Make sure that we capture 'this'.
9074  getSema().CheckCXXThisCapture(E->getLocStart());
9075  return E;
9076  }
9077 
9078  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
9079 }
9080 
9081 template<typename Derived>
9082 ExprResult
9083 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
9084  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9085  if (SubExpr.isInvalid())
9086  return ExprError();
9087 
9088  if (!getDerived().AlwaysRebuild() &&
9089  SubExpr.get() == E->getSubExpr())
9090  return E;
9091 
9092  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9093  E->isThrownVariableInScope());
9094 }
9095 
9096 template<typename Derived>
9097 ExprResult
9098 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
9099  ParmVarDecl *Param
9100  = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9101  E->getParam()));
9102  if (!Param)
9103  return ExprError();
9104 
9105  if (!getDerived().AlwaysRebuild() &&
9106  Param == E->getParam())
9107  return E;
9108 
9109  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
9110 }
9111 
9112 template<typename Derived>
9113 ExprResult
9114 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9115  FieldDecl *Field
9116  = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9117  E->getField()));
9118  if (!Field)
9119  return ExprError();
9120 
9121  if (!getDerived().AlwaysRebuild() && Field == E->getField())
9122  return E;
9123 
9124  return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9125 }
9126 
9127 template<typename Derived>
9128 ExprResult
9129 TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9130  CXXScalarValueInitExpr *E) {
9131  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9132  if (!T)
9133  return ExprError();
9134 
9135  if (!getDerived().AlwaysRebuild() &&
9136  T == E->getTypeSourceInfo())
9137  return E;
9138 
9139  return getDerived().RebuildCXXScalarValueInitExpr(T,
9140  /*FIXME:*/T->getTypeLoc().getEndLoc(),
9141  E->getRParenLoc());
9142 }
9143 
9144 template<typename Derived>
9145 ExprResult
9146 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
9147  // Transform the type that we're allocating
9148  TypeSourceInfo *AllocTypeInfo
9149  = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9150  if (!AllocTypeInfo)
9151  return ExprError();
9152 
9153  // Transform the size of the array we're allocating (if any).
9154  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
9155  if (ArraySize.isInvalid())
9156  return ExprError();
9157 
9158  // Transform the placement arguments (if any).
9159  bool ArgumentChanged = false;
9160  SmallVector<Expr*, 8> PlacementArgs;
9161  if (getDerived().TransformExprs(E->getPlacementArgs(),
9162  E->getNumPlacementArgs(), true,
9163  PlacementArgs, &ArgumentChanged))
9164  return ExprError();
9165 
9166  // Transform the initializer (if any).
9167  Expr *OldInit = E->getInitializer();
9168  ExprResult NewInit;
9169  if (OldInit)
9170  NewInit = getDerived().TransformInitializer(OldInit, true);
9171  if (NewInit.isInvalid())
9172  return ExprError();
9173 
9174  // Transform new operator and delete operator.
9175  FunctionDecl *OperatorNew = nullptr;
9176  if (E->getOperatorNew()) {
9177  OperatorNew = cast_or_null<FunctionDecl>(
9178  getDerived().TransformDecl(E->getLocStart(),
9179  E->getOperatorNew()));
9180  if (!OperatorNew)
9181  return ExprError();
9182  }
9183 
9184  FunctionDecl *OperatorDelete = nullptr;
9185  if (E->getOperatorDelete()) {
9186  OperatorDelete = cast_or_null<FunctionDecl>(
9187  getDerived().TransformDecl(E->getLocStart(),
9188  E->getOperatorDelete()));
9189  if (!OperatorDelete)
9190  return ExprError();
9191  }
9192 
9193  if (!getDerived().AlwaysRebuild() &&
9194  AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
9195  ArraySize.get() == E->getArraySize() &&
9196  NewInit.get() == OldInit &&
9197  OperatorNew == E->getOperatorNew() &&
9198  OperatorDelete == E->getOperatorDelete() &&
9199  !ArgumentChanged) {
9200  // Mark any declarations we need as referenced.
9201  // FIXME: instantiation-specific.
9202  if (OperatorNew)
9203  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
9204  if (OperatorDelete)
9205  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9206 
9207  if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
9208  QualType ElementType
9209  = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9210  if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9211  CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9212  if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
9213  SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
9214  }
9215  }
9216  }
9217 
9218  return E;
9219  }
9220 
9221  QualType AllocType = AllocTypeInfo->getType();
9222  if (!ArraySize.get()) {
9223  // If no array size was specified, but the new expression was
9224  // instantiated with an array type (e.g., "new T" where T is
9225  // instantiated with "int[4]"), extract the outer bound from the
9226  // array type as our array size. We do this with constant and
9227  // dependently-sized array types.
9228  const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9229  if (!ArrayT) {
9230  // Do nothing
9231  } else if (const ConstantArrayType *ConsArrayT
9232  = dyn_cast<ConstantArrayType>(ArrayT)) {
9233  ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9234  SemaRef.Context.getSizeType(),
9235  /*FIXME:*/ E->getLocStart());
9236  AllocType = ConsArrayT->getElementType();
9237  } else if (const DependentSizedArrayType *DepArrayT
9238  = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9239  if (DepArrayT->getSizeExpr()) {
9240  ArraySize = DepArrayT->getSizeExpr();
9241  AllocType = DepArrayT->getElementType();
9242  }
9243  }
9244  }
9245 
9246  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9247  E->isGlobalNew(),
9248  /*FIXME:*/E->getLocStart(),
9249  PlacementArgs,
9250  /*FIXME:*/E->getLocStart(),
9251  E->getTypeIdParens(),
9252  AllocType,
9253  AllocTypeInfo,
9254  ArraySize.get(),
9255  E->getDirectInitRange(),
9256  NewInit.get());
9257 }
9258 
9259 template<typename Derived>
9260 ExprResult
9261 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
9262  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
9263  if (Operand.isInvalid())
9264  return ExprError();
9265 
9266  // Transform the delete operator, if known.
9267  FunctionDecl *OperatorDelete = nullptr;
9268  if (E->getOperatorDelete()) {
9269  OperatorDelete = cast_or_null<FunctionDecl>(
9270  getDerived().TransformDecl(E->getLocStart(),
9271  E->getOperatorDelete()));
9272  if (!OperatorDelete)
9273  return ExprError();
9274  }
9275 
9276  if (!getDerived().AlwaysRebuild() &&
9277  Operand.get() == E->getArgument() &&
9278  OperatorDelete == E->getOperatorDelete()) {
9279  // Mark any declarations we need as referenced.
9280  // FIXME: instantiation-specific.
9281  if (OperatorDelete)
9282  SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
9283 
9284  if (!E->getArgument()->isTypeDependent()) {
9285  QualType Destroyed = SemaRef.Context.getBaseElementType(
9286  E->getDestroyedType());
9287  if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9288  CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
9289  SemaRef.MarkFunctionReferenced(E->getLocStart(),
9290  SemaRef.LookupDestructor(Record));
9291  }
9292  }
9293 
9294  return E;
9295  }
9296 
9297  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9298  E->isGlobalDelete(),
9299  E->isArrayForm(),
9300  Operand.get());
9301 }
9302 
9303 template<typename Derived>
9304 ExprResult
9305 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
9306  CXXPseudoDestructorExpr *E) {
9307  ExprResult Base = getDerived().TransformExpr(E->getBase());
9308  if (Base.isInvalid())
9309  return ExprError();
9310 
9311  ParsedType ObjectTypePtr;
9312  bool MayBePseudoDestructor = false;
9313  Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
9314  E->getOperatorLoc(),
9315  E->isArrow()? tok::arrow : tok::period,
9316  ObjectTypePtr,
9317  MayBePseudoDestructor);
9318  if (Base.isInvalid())
9319  return ExprError();
9320 
9321  QualType ObjectType = ObjectTypePtr.get();
9322  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9323  if (QualifierLoc) {
9324  QualifierLoc
9325  = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9326  if (!QualifierLoc)
9327  return ExprError();
9328  }
9329  CXXScopeSpec SS;
9330  SS.Adopt(QualifierLoc);
9331 
9332  PseudoDestructorTypeStorage Destroyed;
9333  if (E->getDestroyedTypeInfo()) {
9334  TypeSourceInfo *DestroyedTypeInfo
9335  = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
9336  ObjectType, nullptr, SS);
9337  if (!DestroyedTypeInfo)
9338  return ExprError();
9339  Destroyed = DestroyedTypeInfo;
9340  } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
9341  // We aren't likely to be able to resolve the identifier down to a type
9342  // now anyway, so just retain the identifier.
9343  Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9344  E->getDestroyedTypeLoc());
9345  } else {
9346  // Look for a destructor known with the given name.
9347  ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
9348  *E->getDestroyedTypeIdentifier(),
9349  E->getDestroyedTypeLoc(),
9350  /*Scope=*/nullptr,
9351  SS, ObjectTypePtr,
9352  false);
9353  if (!T)
9354  return ExprError();
9355 
9356  Destroyed
9357  = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9358  E->getDestroyedTypeLoc());
9359  }
9360 
9361  TypeSourceInfo *ScopeTypeInfo = nullptr;
9362  if (E->getScopeTypeInfo()) {
9363  CXXScopeSpec EmptySS;
9364  ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
9365  E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
9366  if (!ScopeTypeInfo)
9367  return ExprError();
9368  }
9369 
9370  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
9371  E->getOperatorLoc(),
9372  E->isArrow(),
9373  SS,
9374  ScopeTypeInfo,
9375  E->getColonColonLoc(),
9376  E->getTildeLoc(),
9377  Destroyed);
9378 }
9379 
9380 template<typename Derived>
9381 ExprResult
9382 TreeTransform<Derived>::TransformUnresolvedLookupExpr(
9383  UnresolvedLookupExpr *Old) {
9384  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9386 
9387  // Transform all the decls.
9388  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9389  E = Old->decls_end(); I != E; ++I) {
9390  NamedDecl *InstD = static_cast<NamedDecl*>(
9391  getDerived().TransformDecl(Old->getNameLoc(),
9392  *I));
9393  if (!InstD) {
9394  // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9395  // This can happen because of dependent hiding.
9396  if (isa<UsingShadowDecl>(*I))
9397  continue;
9398  else {
9399  R.clear();
9400  return ExprError();
9401  }
9402  }
9403 
9404  // Expand using declarations.
9405  if (isa<UsingDecl>(InstD)) {
9406  UsingDecl *UD = cast<UsingDecl>(InstD);
9407  for (auto *I : UD->shadows())
9408  R.addDecl(I);
9409  continue;
9410  }
9411 
9412  R.addDecl(InstD);
9413  }
9414 
9415  // Resolve a kind, but don't do any further analysis. If it's
9416  // ambiguous, the callee needs to deal with it.
9417  R.resolveKind();
9418 
9419  // Rebuild the nested-name qualifier, if present.
9420  CXXScopeSpec SS;
9421  if (Old->getQualifierLoc()) {
9422  NestedNameSpecifierLoc QualifierLoc
9423  = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9424  if (!QualifierLoc)
9425  return ExprError();
9426 
9427  SS.Adopt(QualifierLoc);
9428  }
9429 
9430  if (Old->getNamingClass()) {
9431  CXXRecordDecl *NamingClass
9432  = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9433  Old->getNameLoc(),
9434  Old->getNamingClass()));
9435  if (!NamingClass) {
9436  R.clear();
9437  return ExprError();
9438  }
9439 
9440  R.setNamingClass(NamingClass);
9441  }
9442 
9443  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9444 
9445  // If we have neither explicit template arguments, nor the template keyword,
9446  // it's a normal declaration name or member reference.
9447  if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9448  NamedDecl *D = R.getAsSingle<NamedDecl>();
9449  // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9450  // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9451  // give a good diagnostic.
9452  if (D && D->isCXXInstanceMember()) {
9453  return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9454  /*TemplateArgs=*/nullptr,
9455  /*Scope=*/nullptr);
9456  }
9457 
9458  return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9459  }
9460 
9461  // If we have template arguments, rebuild them, then rebuild the
9462  // templateid expression.
9463  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
9464  if (Old->hasExplicitTemplateArgs() &&
9465  getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9466  Old->getNumTemplateArgs(),
9467  TransArgs)) {
9468  R.clear();
9469  return ExprError();
9470  }
9471 
9472  return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
9473  Old->requiresADL(), &TransArgs);
9474 }
9475 
9476 template<typename Derived>
9477 ExprResult
9478 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9479  bool ArgChanged = false;
9480  SmallVector<TypeSourceInfo *, 4> Args;
9481  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9482  TypeSourceInfo *From = E->getArg(I);
9483  TypeLoc FromTL = From->getTypeLoc();
9484  if (!FromTL.getAs<PackExpansionTypeLoc>()) {
9485  TypeLocBuilder TLB;
9486  TLB.reserve(FromTL.getFullDataSize());
9487  QualType To = getDerived().TransformType(TLB, FromTL);
9488  if (To.isNull())
9489  return ExprError();
9490 
9491  if (To == From->getType())
9492  Args.push_back(From);
9493  else {
9494  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9495  ArgChanged = true;
9496  }
9497  continue;
9498  }
9499 
9500  ArgChanged = true;
9501 
9502  // We have a pack expansion. Instantiate it.
9503  PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
9504  TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9505  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9506  SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
9507 
9508  // Determine whether the set of unexpanded parameter packs can and should
9509  // be expanded.
9510  bool Expand = true;
9511  bool RetainExpansion = false;
9512  Optional<unsigned> OrigNumExpansions =
9513  ExpansionTL.getTypePtr()->getNumExpansions();
9514  Optional<unsigned> NumExpansions = OrigNumExpansions;
9515  if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9516  PatternTL.getSourceRange(),
9517  Unexpanded,
9518  Expand, RetainExpansion,
9519  NumExpansions))
9520  return ExprError();
9521 
9522  if (!Expand) {
9523  // The transform has determined that we should perform a simple
9524  // transformation on the pack expansion, producing another pack
9525  // expansion.
9526  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9527 
9528  TypeLocBuilder TLB;
9529  TLB.reserve(From->getTypeLoc().getFullDataSize());
9530 
9531  QualType To = getDerived().TransformType(TLB, PatternTL);
9532  if (To.isNull())
9533  return ExprError();
9534 
9535  To = getDerived().RebuildPackExpansionType(To,
9536  PatternTL.getSourceRange(),
9537  ExpansionTL.getEllipsisLoc(),
9538  NumExpansions);
9539  if (To.isNull())
9540  return ExprError();
9541 
9542  PackExpansionTypeLoc ToExpansionTL
9543  = TLB.push<PackExpansionTypeLoc>(To);
9544  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9545  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9546  continue;
9547  }
9548 
9549  // Expand the pack expansion by substituting for each argument in the
9550  // pack(s).
9551  for (unsigned I = 0; I != *NumExpansions; ++I) {
9552  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9553  TypeLocBuilder TLB;
9554  TLB.reserve(PatternTL.getFullDataSize());
9555  QualType To = getDerived().TransformType(TLB, PatternTL);
9556  if (To.isNull())
9557  return ExprError();
9558 
9559  if (To->containsUnexpandedParameterPack()) {
9560  To = getDerived().RebuildPackExpansionType(To,
9561  PatternTL.getSourceRange(),
9562  ExpansionTL.getEllipsisLoc(),
9563  NumExpansions);
9564  if (To.isNull())
9565  return ExprError();
9566 
9567  PackExpansionTypeLoc ToExpansionTL
9568  = TLB.push<PackExpansionTypeLoc>(To);
9569  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9570  }
9571 
9572  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9573  }
9574 
9575  if (!RetainExpansion)
9576  continue;
9577 
9578  // If we're supposed to retain a pack expansion, do so by temporarily
9579  // forgetting the partially-substituted parameter pack.
9580  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9581 
9582  TypeLocBuilder TLB;
9583  TLB.reserve(From->getTypeLoc().getFullDataSize());
9584 
9585  QualType To = getDerived().TransformType(TLB, PatternTL);
9586  if (To.isNull())
9587  return ExprError();
9588 
9589  To = getDerived().RebuildPackExpansionType(To,
9590  PatternTL.getSourceRange(),
9591  ExpansionTL.getEllipsisLoc(),
9592  NumExpansions);
9593  if (To.isNull())
9594  return ExprError();
9595 
9596  PackExpansionTypeLoc ToExpansionTL
9597  = TLB.push<PackExpansionTypeLoc>(To);
9598  ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9599  Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9600  }
9601 
9602  if (!getDerived().AlwaysRebuild() && !ArgChanged)
9603  return E;
9604 
9605  return getDerived().RebuildTypeTrait(E->getTrait(),
9606  E->getLocStart(),
9607  Args,
9608  E->getLocEnd());
9609 }
9610 
9611 template<typename Derived>
9612 ExprResult
9613 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9614  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9615  if (!T)
9616  return ExprError();
9617 
9618  if (!getDerived().AlwaysRebuild() &&
9619  T == E->getQueriedTypeSourceInfo())
9620  return E;
9621 
9622  ExprResult SubExpr;
9623  {
9624  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9625  SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9626  if (SubExpr.isInvalid())
9627  return ExprError();
9628 
9629  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
9630  return E;
9631  }
9632 
9633  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9634  E->getLocStart(),
9635  T,
9636  SubExpr.get(),
9637  E->getLocEnd());
9638 }
9639 
9640 template<typename Derived>
9641 ExprResult
9642 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9643  ExprResult SubExpr;
9644  {
9645  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9646  SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9647  if (SubExpr.isInvalid())
9648  return ExprError();
9649 
9650  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
9651  return E;
9652  }
9653 
9654  return getDerived().RebuildExpressionTrait(
9655  E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9656 }
9657 
9658 template <typename Derived>
9660  ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9661  TypeSourceInfo **RecoveryTSI) {
9662  ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9663  DRE, AddrTaken, RecoveryTSI);
9664 
9665  // Propagate both errors and recovered types, which return ExprEmpty.
9666  if (!NewDRE.isUsable())
9667  return NewDRE;
9668 
9669  // We got an expr, wrap it up in parens.
9670  if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9671  return PE;
9672  return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9673  PE->getRParen());
9674 }
9675 
9676 template <typename Derived>
9679  return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9680  nullptr);
9681 }
9682 
9683 template<typename Derived>
9684 ExprResult
9687  bool IsAddressOfOperand,
9688  TypeSourceInfo **RecoveryTSI) {
9689  assert(E->getQualifierLoc());
9690  NestedNameSpecifierLoc QualifierLoc
9691  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9692  if (!QualifierLoc)
9693  return ExprError();
9694  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9695 
9696  // TODO: If this is a conversion-function-id, verify that the
9697  // destination type name (if present) resolves the same way after
9698  // instantiation as it did in the local scope.
9699 
9700  DeclarationNameInfo NameInfo
9701  = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9702  if (!NameInfo.getName())
9703  return ExprError();
9704 
9705  if (!E->hasExplicitTemplateArgs()) {
9706  if (!getDerived().AlwaysRebuild() &&
9707  QualifierLoc == E->getQualifierLoc() &&
9708  // Note: it is sufficient to compare the Name component of NameInfo:
9709  // if name has not changed, DNLoc has not changed either.
9710  NameInfo.getName() == E->getDeclName())
9711  return E;
9712 
9713  return getDerived().RebuildDependentScopeDeclRefExpr(
9714  QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9715  IsAddressOfOperand, RecoveryTSI);
9716  }
9717 
9718  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
9719  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9720  E->getNumTemplateArgs(),
9721  TransArgs))
9722  return ExprError();
9723 
9724  return getDerived().RebuildDependentScopeDeclRefExpr(
9725  QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9726  RecoveryTSI);
9727 }
9728 
9729 template<typename Derived>
9730 ExprResult
9731 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
9732  // CXXConstructExprs other than for list-initialization and
9733  // CXXTemporaryObjectExpr are always implicit, so when we have
9734  // a 1-argument construction we just transform that argument.
9735  if ((E->getNumArgs() == 1 ||
9736  (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
9737  (!getDerived().DropCallArgument(E->getArg(0))) &&
9738  !E->isListInitialization())
9739  return getDerived().TransformExpr(E->getArg(0));
9740 
9741  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9742 
9743  QualType T = getDerived().TransformType(E->getType());
9744  if (T.isNull())
9745  return ExprError();
9746 
9747  CXXConstructorDecl *Constructor
9748  = cast_or_null<CXXConstructorDecl>(
9749  getDerived().TransformDecl(E->getLocStart(),
9750  E->getConstructor()));
9751  if (!Constructor)
9752  return ExprError();
9753 
9754  bool ArgumentChanged = false;
9755  SmallVector<Expr*, 8> Args;
9756  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9757  &ArgumentChanged))
9758  return ExprError();
9759 
9760  if (!getDerived().AlwaysRebuild() &&
9761  T == E->getType() &&
9762  Constructor == E->getConstructor() &&
9763  !ArgumentChanged) {
9764  // Mark the constructor as referenced.
9765  // FIXME: Instantiation-specific
9766  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
9767  return E;
9768  }
9769 
9770  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9771  Constructor, E->isElidable(),
9772  Args,
9773  E->hadMultipleCandidates(),
9774  E->isListInitialization(),
9775  E->isStdInitListInitialization(),
9776  E->requiresZeroInitialization(),
9777  E->getConstructionKind(),
9778  E->getParenOrBraceRange());
9779 }
9780 
9781 /// \brief Transform a C++ temporary-binding expression.
9782 ///
9783 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9784 /// transform the subexpression and return that.
9785 template<typename Derived>
9786 ExprResult
9787 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
9788  return getDerived().TransformExpr(E->getSubExpr());
9789 }
9790 
9791 /// \brief Transform a C++ expression that contains cleanups that should
9792 /// be run after the expression is evaluated.
9793 ///
9794 /// Since ExprWithCleanups nodes are implicitly generated, we
9795 /// just transform the subexpression and return that.
9796 template<typename Derived>
9797 ExprResult
9798 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
9799  return getDerived().TransformExpr(E->getSubExpr());
9800 }
9801 
9802 template<typename Derived>
9803 ExprResult
9804 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
9805  CXXTemporaryObjectExpr *E) {
9806  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9807  if (!T)
9808  return ExprError();
9809 
9810  CXXConstructorDecl *Constructor
9811  = cast_or_null<CXXConstructorDecl>(
9812  getDerived().TransformDecl(E->getLocStart(),
9813  E->getConstructor()));
9814  if (!Constructor)
9815  return ExprError();
9816 
9817  bool ArgumentChanged = false;
9818  SmallVector<Expr*, 8> Args;
9819  Args.reserve(E->getNumArgs());
9820  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
9821  &ArgumentChanged))
9822  return ExprError();
9823 
9824  if (!getDerived().AlwaysRebuild() &&
9825  T == E->getTypeSourceInfo() &&
9826  Constructor == E->getConstructor() &&
9827  !ArgumentChanged) {
9828  // FIXME: Instantiation-specific
9829  SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
9830  return SemaRef.MaybeBindToTemporary(E);
9831  }
9832 
9833  // FIXME: Pass in E->isListInitialization().
9834  return getDerived().RebuildCXXTemporaryObjectExpr(T,
9835  /*FIXME:*/T->getTypeLoc().getEndLoc(),
9836  Args,
9837  E->getLocEnd());
9838 }
9839 
9840 template<typename Derived>
9841 ExprResult
9842 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
9843  // Transform any init-capture expressions before entering the scope of the
9844  // lambda body, because they are not semantically within that scope.
9845  typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
9846  SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9847  InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
9848  E->explicit_capture_begin());
9849  for (LambdaExpr::capture_iterator C = E->capture_begin(),
9850  CEnd = E->capture_end();
9851  C != CEnd; ++C) {
9852  if (!E->isInitCapture(C))
9853  continue;
9854  EnterExpressionEvaluationContext EEEC(getSema(),
9856  ExprResult NewExprInitResult = getDerived().TransformInitializer(
9857  C->getCapturedVar()->getInit(),
9858  C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
9859 
9860  if (NewExprInitResult.isInvalid())
9861  return ExprError();
9862  Expr *NewExprInit = NewExprInitResult.get();
9863 
9864  VarDecl *OldVD = C->getCapturedVar();
9865  QualType NewInitCaptureType =
9866  getSema().buildLambdaInitCaptureInitialization(
9867  C->getLocation(), OldVD->getType()->isReferenceType(),
9868  OldVD->getIdentifier(),
9869  C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
9870  NewExprInitResult = NewExprInit;
9871  InitCaptureExprsAndTypes[C - E->capture_begin()] =
9872  std::make_pair(NewExprInitResult, NewInitCaptureType);
9873  }
9874 
9875  // Transform the template parameters, and add them to the current
9876  // instantiation scope. The null case is handled correctly.
9877  auto TPL = getDerived().TransformTemplateParameterList(
9878  E->getTemplateParameterList());
9879 
9880  // Transform the type of the original lambda's call operator.
9881  // The transformation MUST be done in the CurrentInstantiationScope since
9882  // it introduces a mapping of the original to the newly created
9883  // transformed parameters.
9884  TypeSourceInfo *NewCallOpTSI = nullptr;
9885  {
9886  TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9887  FunctionProtoTypeLoc OldCallOpFPTL =
9888  OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
9889 
9890  TypeLocBuilder NewCallOpTLBuilder;
9891  SmallVector<QualType, 4> ExceptionStorage;
9892  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
9893  QualType NewCallOpType = TransformFunctionProtoType(
9894  NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
9895  [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9896  return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9897  ExceptionStorage, Changed);
9898  });
9899  if (NewCallOpType.isNull())
9900  return ExprError();
9901  NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9902  NewCallOpType);
9903  }
9904 
9905  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9906  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9907  LSI->GLTemplateParameterList = TPL;
9908 
9909  // Create the local class that will describe the lambda.
9910  CXXRecordDecl *Class
9911  = getSema().createLambdaClosureType(E->getIntroducerRange(),
9912  NewCallOpTSI,
9913  /*KnownDependent=*/false,
9914  E->getCaptureDefault());
9915  getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9916 
9917  // Build the call operator.
9918  CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9919  Class, E->getIntroducerRange(), NewCallOpTSI,
9920  E->getCallOperator()->getLocEnd(),
9921  NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
9922  LSI->CallOperator = NewCallOperator;
9923 
9924  getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9925  getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
9926 
9927  // Introduce the context of the call operator.
9928  Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
9929  /*NewThisContext*/false);
9930 
9931  // Enter the scope of the lambda.
9932  getSema().buildLambdaScope(LSI, NewCallOperator,
9933  E->getIntroducerRange(),
9934  E->getCaptureDefault(),
9935  E->getCaptureDefaultLoc(),
9936  E->hasExplicitParameters(),
9937  E->hasExplicitResultType(),
9938  E->isMutable());
9939 
9940  bool Invalid = false;
9941 
9942  // Transform captures.
9943  bool FinishedExplicitCaptures = false;
9944  for (LambdaExpr::capture_iterator C = E->capture_begin(),
9945  CEnd = E->capture_end();
9946  C != CEnd; ++C) {
9947  // When we hit the first implicit capture, tell Sema that we've finished
9948  // the list of explicit captures.
9949  if (!FinishedExplicitCaptures && C->isImplicit()) {
9950  getSema().finishLambdaExplicitCaptures(LSI);
9951  FinishedExplicitCaptures = true;
9952  }
9953 
9954  // Capturing 'this' is trivial.
9955  if (C->capturesThis()) {
9956  getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9957  continue;
9958  }
9959  // Captured expression will be recaptured during captured variables
9960  // rebuilding.
9961  if (C->capturesVLAType())
9962  continue;
9963 
9964  // Rebuild init-captures, including the implied field declaration.
9965  if (E->isInitCapture(C)) {
9966  InitCaptureInfoTy InitExprTypePair =
9967  InitCaptureExprsAndTypes[C - E->capture_begin()];
9968  ExprResult Init = InitExprTypePair.first;
9969  QualType InitQualType = InitExprTypePair.second;
9970  if (Init.isInvalid() || InitQualType.isNull()) {
9971  Invalid = true;
9972  continue;
9973  }
9974  VarDecl *OldVD = C->getCapturedVar();
9975  VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9976  OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
9977  OldVD->getInitStyle(), Init.get());
9978  if (!NewVD)
9979  Invalid = true;
9980  else {
9981  getDerived().transformedLocalDecl(OldVD, NewVD);
9982  }
9983  getSema().buildInitCaptureField(LSI, NewVD);
9984  continue;
9985  }
9986 
9987  assert(C->capturesVariable() && "unexpected kind of lambda capture");
9988 
9989  // Determine the capture kind for Sema.
9991  = C->isImplicit()? Sema::TryCapture_Implicit
9992  : C->getCaptureKind() == LCK_ByCopy
9995  SourceLocation EllipsisLoc;
9996  if (C->isPackExpansion()) {
9997  UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9998  bool ShouldExpand = false;
9999  bool RetainExpansion = false;
10000  Optional<unsigned> NumExpansions;
10001  if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10002  C->getLocation(),
10003  Unexpanded,
10004  ShouldExpand, RetainExpansion,
10005  NumExpansions)) {
10006  Invalid = true;
10007  continue;
10008  }
10009 
10010  if (ShouldExpand) {
10011  // The transform has determined that we should perform an expansion;
10012  // transform and capture each of the arguments.
10013  // expansion of the pattern. Do so.
10014  VarDecl *Pack = C->getCapturedVar();
10015  for (unsigned I = 0; I != *NumExpansions; ++I) {
10016  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10017  VarDecl *CapturedVar
10018  = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10019  Pack));
10020  if (!CapturedVar) {
10021  Invalid = true;
10022  continue;
10023  }
10024 
10025  // Capture the transformed variable.
10026  getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10027  }
10028 
10029  // FIXME: Retain a pack expansion if RetainExpansion is true.
10030 
10031  continue;
10032  }
10033 
10034  EllipsisLoc = C->getEllipsisLoc();
10035  }
10036 
10037  // Transform the captured variable.
10038  VarDecl *CapturedVar
10039  = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
10040  C->getCapturedVar()));
10041  if (!CapturedVar || CapturedVar->isInvalidDecl()) {
10042  Invalid = true;
10043  continue;
10044  }
10045 
10046  // Capture the transformed variable.
10047  getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10048  EllipsisLoc);
10049  }
10050  if (!FinishedExplicitCaptures)
10051  getSema().finishLambdaExplicitCaptures(LSI);
10052 
10053  // Enter a new evaluation context to insulate the lambda from any
10054  // cleanups from the enclosing full-expression.
10055  getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
10056 
10057  // Instantiate the body of the lambda expression.
10058  StmtResult Body =
10059  Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10060 
10061  // ActOnLambda* will pop the function scope for us.
10062  FuncScopeCleanup.disable();
10063 
10064  if (Body.isInvalid()) {
10065  SavedContext.pop();
10066  getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
10067  /*IsInstantiation=*/true);
10068  return ExprError();
10069  }
10070 
10071  // Copy the LSI before ActOnFinishFunctionBody removes it.
10072  // FIXME: This is dumb. Store the lambda information somewhere that outlives
10073  // the call operator.
10074  auto LSICopy = *LSI;
10075  getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10076  /*IsInstantiation*/ true);
10077  SavedContext.pop();
10078 
10079  return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10080  &LSICopy);
10081 }
10082 
10083 template<typename Derived>
10084 ExprResult
10085 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
10086  CXXUnresolvedConstructExpr *E) {
10087  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10088  if (!T)
10089  return ExprError();
10090 
10091  bool ArgumentChanged = false;
10092  SmallVector<Expr*, 8> Args;
10093  Args.reserve(E->arg_size());
10094  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
10095  &ArgumentChanged))
10096  return ExprError();
10097 
10098  if (!getDerived().AlwaysRebuild() &&
10099  T == E->getTypeSourceInfo() &&
10100  !ArgumentChanged)
10101  return E;
10102 
10103  // FIXME: we're faking the locations of the commas
10104  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
10105  E->getLParenLoc(),
10106  Args,
10107  E->getRParenLoc());
10108 }
10109 
10110 template<typename Derived>
10111 ExprResult
10112 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
10113  CXXDependentScopeMemberExpr *E) {
10114  // Transform the base of the expression.
10115  ExprResult Base((Expr*) nullptr);
10116  Expr *OldBase;
10117  QualType BaseType;
10118  QualType ObjectType;
10119  if (!E->isImplicitAccess()) {
10120  OldBase = E->getBase();
10121  Base = getDerived().TransformExpr(OldBase);
10122  if (Base.isInvalid())
10123  return ExprError();
10124 
10125  // Start the member reference and compute the object's type.
10126  ParsedType ObjectTy;
10127  bool MayBePseudoDestructor = false;
10128  Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
10129  E->getOperatorLoc(),
10130  E->isArrow()? tok::arrow : tok::period,
10131  ObjectTy,
10132  MayBePseudoDestructor);
10133  if (Base.isInvalid())
10134  return ExprError();
10135 
10136  ObjectType = ObjectTy.get();
10137  BaseType = ((Expr*) Base.get())->getType();
10138  } else {
10139  OldBase = nullptr;
10140  BaseType = getDerived().TransformType(E->getBaseType());
10141  ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10142  }
10143 
10144  // Transform the first part of the nested-name-specifier that qualifies
10145  // the member name.
10146  NamedDecl *FirstQualifierInScope
10147  = getDerived().TransformFirstQualifierInScope(
10148  E->getFirstQualifierFoundInScope(),
10149  E->getQualifierLoc().getBeginLoc());
10150 
10151  NestedNameSpecifierLoc QualifierLoc;
10152  if (E->getQualifier()) {
10153  QualifierLoc
10154  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10155  ObjectType,
10156  FirstQualifierInScope);
10157  if (!QualifierLoc)
10158  return ExprError();
10159  }
10160 
10161  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10162 
10163  // TODO: If this is a conversion-function-id, verify that the
10164  // destination type name (if present) resolves the same way after
10165  // instantiation as it did in the local scope.
10166 
10167  DeclarationNameInfo NameInfo
10168  = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
10169  if (!NameInfo.getName())
10170  return ExprError();
10171 
10172  if (!E->hasExplicitTemplateArgs()) {
10173  // This is a reference to a member without an explicitly-specified
10174  // template argument list. Optimize for this common case.
10175  if (!getDerived().AlwaysRebuild() &&
10176  Base.get() == OldBase &&
10177  BaseType == E->getBaseType() &&
10178  QualifierLoc == E->getQualifierLoc() &&
10179  NameInfo.getName() == E->getMember() &&
10180  FirstQualifierInScope == E->getFirstQualifierFoundInScope())
10181  return E;
10182 
10183  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10184  BaseType,
10185  E->isArrow(),
10186  E->getOperatorLoc(),
10187  QualifierLoc,
10188  TemplateKWLoc,
10189  FirstQualifierInScope,
10190  NameInfo,
10191  /*TemplateArgs*/nullptr);
10192  }
10193 
10194  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
10195  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10196  E->getNumTemplateArgs(),
10197  TransArgs))
10198  return ExprError();
10199 
10200  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
10201  BaseType,
10202  E->isArrow(),
10203  E->getOperatorLoc(),
10204  QualifierLoc,
10205  TemplateKWLoc,
10206  FirstQualifierInScope,
10207  NameInfo,
10208  &TransArgs);
10209 }
10210 
10211 template<typename Derived>
10212 ExprResult
10213 TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
10214  // Transform the base of the expression.
10215  ExprResult Base((Expr*) nullptr);
10216  QualType BaseType;
10217  if (!Old->isImplicitAccess()) {
10218  Base = getDerived().TransformExpr(Old->getBase());
10219  if (Base.isInvalid())
10220  return ExprError();
10221  Base = getSema().PerformMemberExprBaseConversion(Base.get(),
10222  Old->isArrow());
10223  if (Base.isInvalid())
10224  return ExprError();
10225  BaseType = Base.get()->getType();
10226  } else {
10227  BaseType = getDerived().TransformType(Old->getBaseType());
10228  }
10229 
10230  NestedNameSpecifierLoc QualifierLoc;
10231  if (Old->getQualifierLoc()) {
10232  QualifierLoc
10233  = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10234  if (!QualifierLoc)
10235  return ExprError();
10236  }
10237 
10238  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10239 
10240  LookupResult R(SemaRef, Old->getMemberNameInfo(),
10242 
10243  // Transform all the decls.
10244  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10245  E = Old->decls_end(); I != E; ++I) {
10246  NamedDecl *InstD = static_cast<NamedDecl*>(
10247  getDerived().TransformDecl(Old->getMemberLoc(),
10248  *I));
10249  if (!InstD) {
10250  // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10251  // This can happen because of dependent hiding.
10252  if (isa<UsingShadowDecl>(*I))
10253  continue;
10254  else {
10255  R.clear();
10256  return ExprError();
10257  }
10258  }
10259 
10260  // Expand using declarations.
10261  if (isa<UsingDecl>(InstD)) {
10262  UsingDecl *UD = cast<UsingDecl>(InstD);
10263  for (auto *I : UD->shadows())
10264  R.addDecl(I);
10265  continue;
10266  }
10267 
10268  R.addDecl(InstD);
10269  }
10270 
10271  R.resolveKind();
10272 
10273  // Determine the naming class.
10274  if (Old->getNamingClass()) {
10275  CXXRecordDecl *NamingClass
10276  = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10277  Old->getMemberLoc(),
10278  Old->getNamingClass()));
10279  if (!NamingClass)
10280  return ExprError();
10281 
10282  R.setNamingClass(NamingClass);
10283  }
10284 
10285  TemplateArgumentListInfo TransArgs;
10286  if (Old->hasExplicitTemplateArgs()) {
10287  TransArgs.setLAngleLoc(Old->getLAngleLoc());
10288  TransArgs.setRAngleLoc(Old->getRAngleLoc());
10289  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10290  Old->getNumTemplateArgs(),
10291  TransArgs))
10292  return ExprError();
10293  }
10294 
10295  // FIXME: to do this check properly, we will need to preserve the
10296  // first-qualifier-in-scope here, just in case we had a dependent
10297  // base (and therefore couldn't do the check) and a
10298  // nested-name-qualifier (and therefore could do the lookup).
10299  NamedDecl *FirstQualifierInScope = nullptr;
10300 
10301  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
10302  BaseType,
10303  Old->getOperatorLoc(),
10304  Old->isArrow(),
10305  QualifierLoc,
10306  TemplateKWLoc,
10307  FirstQualifierInScope,
10308  R,
10309  (Old->hasExplicitTemplateArgs()
10310  ? &TransArgs : nullptr));
10311 }
10312 
10313 template<typename Derived>
10314 ExprResult
10315 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
10316  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10317  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10318  if (SubExpr.isInvalid())
10319  return ExprError();
10320 
10321  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
10322  return E;
10323 
10324  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10325 }
10326 
10327 template<typename Derived>
10328 ExprResult
10329 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
10330  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10331  if (Pattern.isInvalid())
10332  return ExprError();
10333 
10334  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
10335  return E;
10336 
10337  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10338  E->getNumExpansions());
10339 }
10340 
10341 template<typename Derived>
10342 ExprResult
10343 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10344  // If E is not value-dependent, then nothing will change when we transform it.
10345  // Note: This is an instantiation-centric view.
10346  if (!E->isValueDependent())
10347  return E;
10348 
10349  EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
10350 
10351  ArrayRef<TemplateArgument> PackArgs;
10352  TemplateArgument ArgStorage;
10353 
10354  // Find the argument list to transform.
10355  if (E->isPartiallySubstituted()) {
10356  PackArgs = E->getPartialArguments();
10357  } else if (E->isValueDependent()) {
10358  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10359  bool ShouldExpand = false;
10360  bool RetainExpansion = false;
10361  Optional<unsigned> NumExpansions;
10362  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10363  Unexpanded,
10364  ShouldExpand, RetainExpansion,
10365  NumExpansions))
10366  return ExprError();
10367 
10368  // If we need to expand the pack, build a template argument from it and
10369  // expand that.
10370  if (ShouldExpand) {
10371  auto *Pack = E->getPack();
10372  if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10373  ArgStorage = getSema().Context.getPackExpansionType(
10374  getSema().Context.getTypeDeclType(TTPD), None);
10375  } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10376  ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10377  } else {
10378  auto *VD = cast<ValueDecl>(Pack);
10379  ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10380  VK_RValue, E->getPackLoc());
10381  if (DRE.isInvalid())
10382  return ExprError();
10383  ArgStorage = new (getSema().Context) PackExpansionExpr(
10384  getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10385  }
10386  PackArgs = ArgStorage;
10387  }
10388  }
10389 
10390  // If we're not expanding the pack, just transform the decl.
10391  if (!PackArgs.size()) {
10392  auto *Pack = cast_or_null<NamedDecl>(
10393  getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
10394  if (!Pack)
10395  return ExprError();
10396  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10397  E->getPackLoc(),
10398  E->getRParenLoc(), None, None);
10399  }
10400 
10401  TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10402  E->getPackLoc());
10403  {
10404  TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10405  typedef TemplateArgumentLocInventIterator<
10406  Derived, const TemplateArgument*> PackLocIterator;
10407  if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10408  PackLocIterator(*this, PackArgs.end()),
10409  TransformedPackArgs, /*Uneval*/true))
10410  return ExprError();
10411  }
10412 
10413  SmallVector<TemplateArgument, 8> Args;
10414  bool PartialSubstitution = false;
10415  for (auto &Loc : TransformedPackArgs.arguments()) {
10416  Args.push_back(Loc.getArgument());
10417  if (Loc.getArgument().isPackExpansion())
10418  PartialSubstitution = true;
10419  }
10420 
10421  if (PartialSubstitution)
10422  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10423  E->getPackLoc(),
10424  E->getRParenLoc(), None, Args);
10425 
10426  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10427  E->getPackLoc(), E->getRParenLoc(),
10428  Args.size(), None);
10429 }
10430 
10431 template<typename Derived>
10432 ExprResult
10433 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10434  SubstNonTypeTemplateParmPackExpr *E) {
10435  // Default behavior is to do nothing with this transformation.
10436  return E;
10437 }
10438 
10439 template<typename Derived>
10440 ExprResult
10441 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10442  SubstNonTypeTemplateParmExpr *E) {
10443  // Default behavior is to do nothing with this transformation.
10444  return E;
10445 }
10446 
10447 template<typename Derived>
10448 ExprResult
10449 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10450  // Default behavior is to do nothing with this transformation.
10451  return E;
10452 }
10453 
10454 template<typename Derived>
10455 ExprResult
10456 TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10457  MaterializeTemporaryExpr *E) {
10458  return getDerived().TransformExpr(E->GetTemporaryExpr());
10459 }
10460 
10461 template<typename Derived>
10462 ExprResult
10463 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10464  Expr *Pattern = E->getPattern();
10465 
10466  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10467  getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10468  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10469 
10470  // Determine whether the set of unexpanded parameter packs can and should
10471  // be expanded.
10472  bool Expand = true;
10473  bool RetainExpansion = false;
10474  Optional<unsigned> NumExpansions;
10475  if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10476  Pattern->getSourceRange(),
10477  Unexpanded,
10478  Expand, RetainExpansion,
10479  NumExpansions))
10480  return true;
10481 
10482  if (!Expand) {
10483  // Do not expand any packs here, just transform and rebuild a fold
10484  // expression.
10485  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10486 
10487  ExprResult LHS =
10488  E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10489  if (LHS.isInvalid())
10490  return true;
10491 
10492  ExprResult RHS =
10493  E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10494  if (RHS.isInvalid())
10495  return true;
10496 
10497  if (!getDerived().AlwaysRebuild() &&
10498  LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10499  return E;
10500 
10501  return getDerived().RebuildCXXFoldExpr(
10502  E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10503  RHS.get(), E->getLocEnd());
10504  }
10505 
10506  // The transform has determined that we should perform an elementwise
10507  // expansion of the pattern. Do so.
10508  ExprResult Result = getDerived().TransformExpr(E->getInit());
10509  if (Result.isInvalid())
10510  return true;
10511  bool LeftFold = E->isLeftFold();
10512 
10513  // If we're retaining an expansion for a right fold, it is the innermost
10514  // component and takes the init (if any).
10515  if (!LeftFold && RetainExpansion) {
10516  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10517 
10518  ExprResult Out = getDerived().TransformExpr(Pattern);
10519  if (Out.isInvalid())
10520  return true;
10521 
10522  Result = getDerived().RebuildCXXFoldExpr(
10523  E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10524  Result.get(), E->getLocEnd());
10525  if (Result.isInvalid())
10526  return true;
10527  }
10528 
10529  for (unsigned I = 0; I != *NumExpansions; ++I) {
10530  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10531  getSema(), LeftFold ? I : *NumExpansions - I - 1);
10532  ExprResult Out = getDerived().TransformExpr(Pattern);
10533  if (Out.isInvalid())
10534  return true;
10535 
10536  if (Out.get()->containsUnexpandedParameterPack()) {
10537  // We still have a pack; retain a pack expansion for this slice.
10538  Result = getDerived().RebuildCXXFoldExpr(
10539  E->getLocStart(),
10540  LeftFold ? Result.get() : Out.get(),
10541  E->getOperator(), E->getEllipsisLoc(),
10542  LeftFold ? Out.get() : Result.get(),
10543  E->getLocEnd());
10544  } else if (Result.isUsable()) {
10545  // We've got down to a single element; build a binary operator.
10546  Result = getDerived().RebuildBinaryOperator(
10547  E->getEllipsisLoc(), E->getOperator(),
10548  LeftFold ? Result.get() : Out.get(),
10549  LeftFold ? Out.get() : Result.get());
10550  } else
10551  Result = Out;
10552 
10553  if (Result.isInvalid())
10554  return true;
10555  }
10556 
10557  // If we're retaining an expansion for a left fold, it is the outermost
10558  // component and takes the complete expansion so far as its init (if any).
10559  if (LeftFold && RetainExpansion) {
10560  ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10561 
10562  ExprResult Out = getDerived().TransformExpr(Pattern);
10563  if (Out.isInvalid())
10564  return true;
10565 
10566  Result = getDerived().RebuildCXXFoldExpr(
10567  E->getLocStart(), Result.get(),
10568  E->getOperator(), E->getEllipsisLoc(),
10569  Out.get(), E->getLocEnd());
10570  if (Result.isInvalid())
10571  return true;
10572  }
10573 
10574  // If we had no init and an empty pack, and we're not retaining an expansion,
10575  // then produce a fallback value or error.
10576  if (Result.isUnset())
10577  return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10578  E->getOperator());
10579 
10580  return Result;
10581 }
10582 
10583 template<typename Derived>
10584 ExprResult
10585 TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10586  CXXStdInitializerListExpr *E) {
10587  return getDerived().TransformExpr(E->getSubExpr());
10588 }
10589 
10590 template<typename Derived>
10591 ExprResult
10592 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
10593  return SemaRef.MaybeBindToTemporary(E);
10594 }
10595 
10596 template<typename Derived>
10597 ExprResult
10598 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
10599  return E;
10600 }
10601 
10602 template<typename Derived>
10603 ExprResult
10604 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10605  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10606  if (SubExpr.isInvalid())
10607  return ExprError();
10608 
10609  if (!getDerived().AlwaysRebuild() &&
10610  SubExpr.get() == E->getSubExpr())
10611  return E;
10612 
10613  return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
10614 }
10615 
10616 template<typename Derived>
10617 ExprResult
10618 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10619  // Transform each of the elements.
10620  SmallVector<Expr *, 8> Elements;
10621  bool ArgChanged = false;
10622  if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
10623  /*IsCall=*/false, Elements, &ArgChanged))
10624  return ExprError();
10625 
10626  if (!getDerived().AlwaysRebuild() && !ArgChanged)
10627  return SemaRef.MaybeBindToTemporary(E);
10628 
10629  return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10630  Elements.data(),
10631  Elements.size());
10632 }
10633 
10634 template<typename Derived>
10635 ExprResult
10636 TreeTransform<Derived>::TransformObjCDictionaryLiteral(
10637  ObjCDictionaryLiteral *E) {
10638  // Transform each of the elements.
10639  SmallVector<ObjCDictionaryElement, 8> Elements;
10640  bool ArgChanged = false;
10641  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10642  ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
10643 
10644  if (OrigElement.isPackExpansion()) {
10645  // This key/value element is a pack expansion.
10646  SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10647  getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10648  getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10649  assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10650 
10651  // Determine whether the set of unexpanded parameter packs can
10652  // and should be expanded.
10653  bool Expand = true;
10654  bool RetainExpansion = false;
10655  Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10656  Optional<unsigned> NumExpansions = OrigNumExpansions;
10657  SourceRange PatternRange(OrigElement.Key->getLocStart(),
10658  OrigElement.Value->getLocEnd());
10659  if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10660  PatternRange,
10661  Unexpanded,
10662  Expand, RetainExpansion,
10663  NumExpansions))
10664  return ExprError();
10665 
10666  if (!Expand) {
10667  // The transform has determined that we should perform a simple
10668  // transformation on the pack expansion, producing another pack
10669  // expansion.
10670  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10671  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10672  if (Key.isInvalid())
10673  return ExprError();
10674 
10675  if (Key.get() != OrigElement.Key)
10676  ArgChanged = true;
10677 
10678  ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10679  if (Value.isInvalid())
10680  return ExprError();
10681 
10682  if (Value.get() != OrigElement.Value)
10683  ArgChanged = true;
10684 
10685  ObjCDictionaryElement Expansion = {
10686  Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10687  };
10688  Elements.push_back(Expansion);
10689  continue;
10690  }
10691 
10692  // Record right away that the argument was changed. This needs
10693  // to happen even if the array expands to nothing.
10694  ArgChanged = true;
10695 
10696  // The transform has determined that we should perform an elementwise
10697  // expansion of the pattern. Do so.
10698  for (unsigned I = 0; I != *NumExpansions; ++I) {
10699  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10700  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10701  if (Key.isInvalid())
10702  return ExprError();
10703 
10704  ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10705  if (Value.isInvalid())
10706  return ExprError();
10707 
10708  ObjCDictionaryElement Element = {
10709  Key.get(), Value.get(), SourceLocation(), NumExpansions
10710  };
10711 
10712  // If any unexpanded parameter packs remain, we still have a
10713  // pack expansion.
10714  // FIXME: Can this really happen?
10715  if (Key.get()->containsUnexpandedParameterPack() ||
10716  Value.get()->containsUnexpandedParameterPack())
10717  Element.EllipsisLoc = OrigElement.EllipsisLoc;
10718 
10719  Elements.push_back(Element);
10720  }
10721 
10722  // FIXME: Retain a pack expansion if RetainExpansion is true.
10723 
10724  // We've finished with this pack expansion.
10725  continue;
10726  }
10727 
10728  // Transform and check key.
10729  ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10730  if (Key.isInvalid())
10731  return ExprError();
10732 
10733  if (Key.get() != OrigElement.Key)
10734  ArgChanged = true;
10735 
10736  // Transform and check value.
10737  ExprResult Value
10738  = getDerived().TransformExpr(OrigElement.Value);
10739  if (Value.isInvalid())
10740  return ExprError();
10741 
10742  if (Value.get() != OrigElement.Value)
10743  ArgChanged = true;
10744 
10745  ObjCDictionaryElement Element = {
10746  Key.get(), Value.get(), SourceLocation(), None
10747  };
10748  Elements.push_back(Element);
10749  }
10750 
10751  if (!getDerived().AlwaysRebuild() && !ArgChanged)
10752  return SemaRef.MaybeBindToTemporary(E);
10753 
10754  return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10755  Elements);
10756 }
10757 
10758 template<typename Derived>
10759 ExprResult
10760 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
10761  TypeSourceInfo *EncodedTypeInfo
10762  = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10763  if (!EncodedTypeInfo)
10764  return ExprError();
10765 
10766  if (!getDerived().AlwaysRebuild() &&
10767  EncodedTypeInfo == E->getEncodedTypeSourceInfo())
10768  return E;
10769 
10770  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
10771  EncodedTypeInfo,
10772  E->getRParenLoc());
10773 }
10774 
10775 template<typename Derived>
10776 ExprResult TreeTransform<Derived>::
10777 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
10778  // This is a kind of implicit conversion, and it needs to get dropped
10779  // and recomputed for the same general reasons that ImplicitCastExprs
10780  // do, as well a more specific one: this expression is only valid when
10781  // it appears *immediately* as an argument expression.
10782  return getDerived().TransformExpr(E->getSubExpr());
10783 }
10784 
10785 template<typename Derived>
10786 ExprResult TreeTransform<Derived>::
10787 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
10788  TypeSourceInfo *TSInfo
10789  = getDerived().TransformType(E->getTypeInfoAsWritten());
10790  if (!TSInfo)
10791  return ExprError();
10792 
10793  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
10794  if (Result.isInvalid())
10795  return ExprError();
10796 
10797  if (!getDerived().AlwaysRebuild() &&
10798  TSInfo == E->getTypeInfoAsWritten() &&
10799  Result.get() == E->getSubExpr())
10800  return E;
10801 
10802  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
10803  E->getBridgeKeywordLoc(), TSInfo,
10804  Result.get());
10805 }
10806 
10807 template<typename Derived>
10808 ExprResult
10809 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
10810  // Transform arguments.
10811  bool ArgChanged = false;
10812  SmallVector<Expr*, 8> Args;
10813  Args.reserve(E->getNumArgs());
10814  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
10815  &ArgChanged))
10816  return ExprError();
10817 
10818  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10819  // Class message: transform the receiver type.
10820  TypeSourceInfo *ReceiverTypeInfo
10821  = getDerived().TransformType(E->getClassReceiverTypeInfo());
10822  if (!ReceiverTypeInfo)
10823  return ExprError();
10824 
10825  // If nothing changed, just retain the existing message send.
10826  if (!getDerived().AlwaysRebuild() &&
10827  ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
10828  return SemaRef.MaybeBindToTemporary(E);
10829 
10830  // Build a new class message send.
10831  SmallVector<SourceLocation, 16> SelLocs;
10832  E->getSelectorLocs(SelLocs);
10833  return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10834  E->getSelector(),
10835  SelLocs,
10836  E->getMethodDecl(),
10837  E->getLeftLoc(),
10838  Args,
10839  E->getRightLoc());
10840  }
10841  else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10842  E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10843  // Build a new class message send to 'super'.
10844  SmallVector<SourceLocation, 16> SelLocs;
10845  E->getSelectorLocs(SelLocs);
10846  return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10847  E->getSelector(),
10848  SelLocs,
10849  E->getReceiverType(),
10850  E->getMethodDecl(),
10851  E->getLeftLoc(),
10852  Args,
10853  E->getRightLoc());
10854  }
10855 
10856  // Instance message: transform the receiver
10857  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10858  "Only class and instance messages may be instantiated");
10859  ExprResult Receiver
10860  = getDerived().TransformExpr(E->getInstanceReceiver());
10861  if (Receiver.isInvalid())
10862  return ExprError();
10863 
10864  // If nothing changed, just retain the existing message send.
10865  if (!getDerived().AlwaysRebuild() &&
10866  Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
10867  return SemaRef.MaybeBindToTemporary(E);
10868 
10869  // Build a new instance message send.
10870  SmallVector<SourceLocation, 16> SelLocs;
10871  E->getSelectorLocs(SelLocs);
10872  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
10873  E->getSelector(),
10874  SelLocs,
10875  E->getMethodDecl(),
10876  E->getLeftLoc(),
10877  Args,
10878  E->getRightLoc());
10879 }
10880 
10881 template<typename Derived>
10882 ExprResult
10883 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
10884  return E;
10885 }
10886 
10887 template<typename Derived>
10888 ExprResult
10889 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
10890  return E;
10891 }
10892 
10893 template<typename Derived>
10894 ExprResult
10895 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
10896  // Transform the base expression.
10897  ExprResult Base = getDerived().TransformExpr(E->getBase());
10898  if (Base.isInvalid())
10899  return ExprError();
10900 
10901  // We don't need to transform the ivar; it will never change.
10902 
10903  // If nothing changed, just retain the existing expression.
10904  if (!getDerived().AlwaysRebuild() &&
10905  Base.get() == E->getBase())
10906  return E;
10907 
10908  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
10909  E->getLocation(),
10910  E->isArrow(), E->isFreeIvar());
10911 }
10912 
10913 template<typename Derived>
10914 ExprResult
10915 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
10916  // 'super' and types never change. Property never changes. Just
10917  // retain the existing expression.
10918  if (!E->isObjectReceiver())
10919  return E;
10920 
10921  // Transform the base expression.
10922  ExprResult Base = getDerived().TransformExpr(E->getBase());
10923  if (Base.isInvalid())
10924  return ExprError();
10925 
10926  // We don't need to transform the property; it will never change.
10927 
10928  // If nothing changed, just retain the existing expression.
10929  if (!getDerived().AlwaysRebuild() &&
10930  Base.get() == E->getBase())
10931  return E;
10932 
10933  if (E->isExplicitProperty())
10934  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10935  E->getExplicitProperty(),
10936  E->getLocation());
10937 
10938  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10939  SemaRef.Context.PseudoObjectTy,
10940  E->getImplicitPropertyGetter(),
10941  E->getImplicitPropertySetter(),
10942  E->getLocation());
10943 }
10944 
10945 template<typename Derived>
10946 ExprResult
10947 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10948  // Transform the base expression.
10949  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10950  if (Base.isInvalid())
10951  return ExprError();
10952 
10953  // Transform the key expression.
10954  ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10955  if (Key.isInvalid())
10956  return ExprError();
10957 
10958  // If nothing changed, just retain the existing expression.
10959  if (!getDerived().AlwaysRebuild() &&
10960  Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
10961  return E;
10962 
10963  return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
10964  Base.get(), Key.get(),
10965  E->getAtIndexMethodDecl(),
10966  E->setAtIndexMethodDecl());
10967 }
10968 
10969 template<typename Derived>
10970 ExprResult
10971 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
10972  // Transform the base expression.
10973  ExprResult Base = getDerived().TransformExpr(E->getBase());
10974  if (Base.isInvalid())
10975  return ExprError();
10976 
10977  // If nothing changed, just retain the existing expression.
10978  if (!getDerived().AlwaysRebuild() &&
10979  Base.get() == E->getBase())
10980  return E;
10981 
10982  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
10983  E->getOpLoc(),
10984  E->isArrow());
10985 }
10986 
10987 template<typename Derived>
10988 ExprResult
10989 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
10990  bool ArgumentChanged = false;
10991  SmallVector<Expr*, 8> SubExprs;
10992  SubExprs.reserve(E->getNumSubExprs());
10993  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10994  SubExprs, &ArgumentChanged))
10995  return ExprError();
10996 
10997  if (!getDerived().AlwaysRebuild() &&
10998  !ArgumentChanged)
10999  return E;
11000 
11001  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
11002  SubExprs,
11003  E->getRParenLoc());
11004 }
11005 
11006 template<typename Derived>
11007 ExprResult
11008 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11009  ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11010  if (SrcExpr.isInvalid())
11011  return ExprError();
11012 
11013  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11014  if (!Type)
11015  return ExprError();
11016 
11017  if (!getDerived().AlwaysRebuild() &&
11018  Type == E->getTypeSourceInfo() &&
11019  SrcExpr.get() == E->getSrcExpr())
11020  return E;
11021 
11022  return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11023  SrcExpr.get(), Type,
11024  E->getRParenLoc());
11025 }
11026 
11027 template<typename Derived>
11028 ExprResult
11029 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
11030  BlockDecl *oldBlock = E->getBlockDecl();
11031 
11032  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
11033  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11034 
11035  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
11036  blockScope->TheDecl->setBlockMissingReturnType(
11037  oldBlock->blockMissingReturnType());
11038 
11039  SmallVector<ParmVarDecl*, 4> params;
11040  SmallVector<QualType, 4> paramTypes;
11041 
11042  // Parameter substitution.
11043  if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
11044  oldBlock->param_begin(),
11045  oldBlock->param_size(),
11046  nullptr, paramTypes, &params)) {
11047  getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11048  return ExprError();
11049  }
11050 
11051  const FunctionProtoType *exprFunctionType = E->getFunctionType();
11052  QualType exprResultType =
11053  getDerived().TransformType(exprFunctionType->getReturnType());
11054 
11055  QualType functionType =
11056  getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
11057  exprFunctionType->getExtProtoInfo());
11058  blockScope->FunctionType = functionType;
11059 
11060  // Set the parameters on the block decl.
11061  if (!params.empty())
11062  blockScope->TheDecl->setParams(params);
11063 
11064  if (!oldBlock->blockMissingReturnType()) {
11065  blockScope->HasImplicitReturnType = false;
11066  blockScope->ReturnType = exprResultType;
11067  }
11068 
11069  // Transform the body
11070  StmtResult body = getDerived().TransformStmt(E->getBody());
11071  if (body.isInvalid()) {
11072  getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
11073  return ExprError();
11074  }
11075 
11076 #ifndef NDEBUG
11077  // In builds with assertions, make sure that we captured everything we
11078  // captured before.
11079  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
11080  for (const auto &I : oldBlock->captures()) {
11081  VarDecl *oldCapture = I.getVariable();
11082 
11083  // Ignore parameter packs.
11084  if (isa<ParmVarDecl>(oldCapture) &&
11085  cast<ParmVarDecl>(oldCapture)->isParameterPack())
11086  continue;
11087 
11088  VarDecl *newCapture =
11089  cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11090  oldCapture));
11091  assert(blockScope->CaptureMap.count(newCapture));
11092  }
11093  assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
11094  }
11095 #endif
11096 
11097  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
11098  /*Scope=*/nullptr);
11099 }
11100 
11101 template<typename Derived>
11102 ExprResult
11103 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
11104  llvm_unreachable("Cannot transform asType expressions yet");
11105 }
11106 
11107 template<typename Derived>
11108 ExprResult
11109 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
11110  QualType RetTy = getDerived().TransformType(E->getType());
11111  bool ArgumentChanged = false;
11112  SmallVector<Expr*, 8> SubExprs;
11113  SubExprs.reserve(E->getNumSubExprs());
11114  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11115  SubExprs, &ArgumentChanged))
11116  return ExprError();
11117 
11118  if (!getDerived().AlwaysRebuild() &&
11119  !ArgumentChanged)
11120  return E;
11121 
11122  return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
11123  RetTy, E->getOp(), E->getRParenLoc());
11124 }
11125 
11126 //===----------------------------------------------------------------------===//
11127 // Type reconstruction
11128 //===----------------------------------------------------------------------===//
11129 
11130 template<typename Derived>
11132  SourceLocation Star) {
11133  return SemaRef.BuildPointerType(PointeeType, Star,
11134  getDerived().getBaseEntity());
11135 }
11136 
11137 template<typename Derived>
11139  SourceLocation Star) {
11140  return SemaRef.BuildBlockPointerType(PointeeType, Star,
11141  getDerived().getBaseEntity());
11142 }
11143 
11144 template<typename Derived>
11145 QualType
11147  bool WrittenAsLValue,
11148  SourceLocation Sigil) {
11149  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
11150  Sigil, getDerived().getBaseEntity());
11151 }
11152 
11153 template<typename Derived>
11154 QualType
11156  QualType ClassType,
11157  SourceLocation Sigil) {
11158  return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11159  getDerived().getBaseEntity());
11160 }
11161 
11162 template<typename Derived>
11164  QualType BaseType,
11165  SourceLocation Loc,
11166  SourceLocation TypeArgsLAngleLoc,
11167  ArrayRef<TypeSourceInfo *> TypeArgs,
11168  SourceLocation TypeArgsRAngleLoc,
11169  SourceLocation ProtocolLAngleLoc,
11170  ArrayRef<ObjCProtocolDecl *> Protocols,
11171  ArrayRef<SourceLocation> ProtocolLocs,
11172  SourceLocation ProtocolRAngleLoc) {
11173  return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11174  TypeArgs, TypeArgsRAngleLoc,
11175  ProtocolLAngleLoc, Protocols, ProtocolLocs,
11176  ProtocolRAngleLoc,
11177  /*FailOnError=*/true);
11178 }
11179 
11180 template<typename Derived>
11182  QualType PointeeType,
11183  SourceLocation Star) {
11184  return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11185 }
11186 
11187 template<typename Derived>
11188 QualType
11191  const llvm::APInt *Size,
11192  Expr *SizeExpr,
11193  unsigned IndexTypeQuals,
11194  SourceRange BracketsRange) {
11195  if (SizeExpr || !Size)
11196  return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11197  IndexTypeQuals, BracketsRange,
11198  getDerived().getBaseEntity());
11199 
11200  QualType Types[] = {
11201  SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11202  SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11203  SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
11204  };
11205  const unsigned NumTypes = llvm::array_lengthof(Types);
11206  QualType SizeType;
11207  for (unsigned I = 0; I != NumTypes; ++I)
11208  if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11209  SizeType = Types[I];
11210  break;
11211  }
11212 
11213  // Note that we can return a VariableArrayType here in the case where
11214  // the element type was a dependent VariableArrayType.
11215  IntegerLiteral *ArraySize
11216  = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11217  /*FIXME*/BracketsRange.getBegin());
11218  return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
11219  IndexTypeQuals, BracketsRange,
11220  getDerived().getBaseEntity());
11221 }
11222 
11223 template<typename Derived>
11224 QualType
11227  const llvm::APInt &Size,
11228  unsigned IndexTypeQuals,
11229  SourceRange BracketsRange) {
11230  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
11231  IndexTypeQuals, BracketsRange);
11232 }
11233 
11234 template<typename Derived>
11235 QualType
11238  unsigned IndexTypeQuals,
11239  SourceRange BracketsRange) {
11240  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
11241  IndexTypeQuals, BracketsRange);
11242 }
11243 
11244 template<typename Derived>
11245 QualType
11248  Expr *SizeExpr,
11249  unsigned IndexTypeQuals,
11250  SourceRange BracketsRange) {
11251  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11252  SizeExpr,
11253  IndexTypeQuals, BracketsRange);
11254 }
11255 
11256 template<typename Derived>
11257 QualType
11260  Expr *SizeExpr,
11261  unsigned IndexTypeQuals,
11262  SourceRange BracketsRange) {
11263  return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
11264  SizeExpr,
11265  IndexTypeQuals, BracketsRange);
11266 }
11267 
11268 template<typename Derived>
11270  unsigned NumElements,
11271  VectorType::VectorKind VecKind) {
11272  // FIXME: semantic checking!
11273  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
11274 }
11275 
11276 template<typename Derived>
11278  unsigned NumElements,
11279  SourceLocation AttributeLoc) {
11280  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11281  NumElements, true);
11282  IntegerLiteral *VectorSize
11283  = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11284  AttributeLoc);
11285  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
11286 }
11287 
11288 template<typename Derived>
11289 QualType
11291  Expr *SizeExpr,
11292  SourceLocation AttributeLoc) {
11293  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
11294 }
11295 
11296 template<typename Derived>
11298  QualType T,
11299  MutableArrayRef<QualType> ParamTypes,
11300  const FunctionProtoType::ExtProtoInfo &EPI) {
11301  return SemaRef.BuildFunctionType(T, ParamTypes,
11302  getDerived().getBaseLocation(),
11303  getDerived().getBaseEntity(),
11304  EPI);
11305 }
11306 
11307 template<typename Derived>
11309  return SemaRef.Context.getFunctionNoProtoType(T);
11310 }
11311 
11312 template<typename Derived>
11314  assert(D && "no decl found");
11315  if (D->isInvalidDecl()) return QualType();
11316 
11317  // FIXME: Doesn't account for ObjCInterfaceDecl!
11318  TypeDecl *Ty;
11319  if (isa<UsingDecl>(D)) {
11320  UsingDecl *Using = cast<UsingDecl>(D);
11321  assert(Using->hasTypename() &&
11322  "UnresolvedUsingTypenameDecl transformed to non-typename using");
11323 
11324  // A valid resolved using typename decl points to exactly one type decl.
11325  assert(++Using->shadow_begin() == Using->shadow_end());
11326  Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
11327 
11328  } else {
11329  assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11330  "UnresolvedUsingTypenameDecl transformed to non-using decl");
11331  Ty = cast<UnresolvedUsingTypenameDecl>(D);
11332  }
11333 
11334  return SemaRef.Context.getTypeDeclType(Ty);
11335 }
11336 
11337 template<typename Derived>
11339  SourceLocation Loc) {
11340  return SemaRef.BuildTypeofExprType(E, Loc);
11341 }
11342 
11343 template<typename Derived>
11345  return SemaRef.Context.getTypeOfType(Underlying);
11346 }
11347 
11348 template<typename Derived>
11350  SourceLocation Loc) {
11351  return SemaRef.BuildDecltypeType(E, Loc);
11352 }
11353 
11354 template<typename Derived>
11357  SourceLocation Loc) {
11358  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11359 }
11360 
11361 template<typename Derived>
11363  TemplateName Template,
11364  SourceLocation TemplateNameLoc,
11365  TemplateArgumentListInfo &TemplateArgs) {
11366  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
11367 }
11368 
11369 template<typename Derived>
11371  SourceLocation KWLoc) {
11372  return SemaRef.BuildAtomicType(ValueType, KWLoc);
11373 }
11374 
11375 template<typename Derived>
11377  SourceLocation KWLoc) {
11378  return SemaRef.BuildPipeType(ValueType, KWLoc);
11379 }
11380 
11381 template<typename Derived>
11384  bool TemplateKW,
11385  TemplateDecl *Template) {
11386  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
11387  Template);
11388 }
11389 
11390 template<typename Derived>
11393  const IdentifierInfo &Name,
11394  SourceLocation NameLoc,
11395  QualType ObjectType,
11396  NamedDecl *FirstQualifierInScope) {
11398  TemplateName.setIdentifier(&Name, NameLoc);
11399  Sema::TemplateTy Template;
11400  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11401  getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11402  SS, TemplateKWLoc, TemplateName,
11403  ParsedType::make(ObjectType),
11404  /*EnteringContext=*/false,
11405  Template);
11406  return Template.get();
11407 }
11408 
11409 template<typename Derived>
11412  OverloadedOperatorKind Operator,
11413  SourceLocation NameLoc,
11414  QualType ObjectType) {
11416  // FIXME: Bogus location information.
11417  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
11418  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
11419  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11420  Sema::TemplateTy Template;
11421  getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
11422  SS, TemplateKWLoc, Name,
11423  ParsedType::make(ObjectType),
11424  /*EnteringContext=*/false,
11425  Template);
11426  return Template.get();
11427 }
11428 
11429 template<typename Derived>
11430 ExprResult
11432  SourceLocation OpLoc,
11433  Expr *OrigCallee,
11434  Expr *First,
11435  Expr *Second) {
11436  Expr *Callee = OrigCallee->IgnoreParenCasts();
11437  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
11438 
11439  if (First->getObjectKind() == OK_ObjCProperty) {
11442  return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11443  First, Second);
11444  ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11445  if (Result.isInvalid())
11446  return ExprError();
11447  First = Result.get();
11448  }
11449 
11450  if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11451  ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11452  if (Result.isInvalid())
11453  return ExprError();
11454  Second = Result.get();
11455  }
11456 
11457  // Determine whether this should be a builtin operation.
11458  if (Op == OO_Subscript) {
11459  if (!First->getType()->isOverloadableType() &&
11460  !Second->getType()->isOverloadableType())
11461  return getSema().CreateBuiltinArraySubscriptExpr(First,
11462  Callee->getLocStart(),
11463  Second, OpLoc);
11464  } else if (Op == OO_Arrow) {
11465  // -> is never a builtin operation.
11466  return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11467  } else if (Second == nullptr || isPostIncDec) {
11468  if (!First->getType()->isOverloadableType()) {
11469  // The argument is not of overloadable type, so try to create a
11470  // built-in unary operation.
11471  UnaryOperatorKind Opc
11472  = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
11473 
11474  return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
11475  }
11476  } else {
11477  if (!First->getType()->isOverloadableType() &&
11478  !Second->getType()->isOverloadableType()) {
11479  // Neither of the arguments is an overloadable type, so try to
11480  // create a built-in binary operation.
11482  ExprResult Result
11483  = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
11484  if (Result.isInvalid())
11485  return ExprError();
11486 
11487  return Result;
11488  }
11489  }
11490 
11491  // Compute the transformed set of functions (and function templates) to be
11492  // used during overload resolution.
11493  UnresolvedSet<16> Functions;
11494 
11495  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
11496  assert(ULE->requiresADL());
11497  Functions.append(ULE->decls_begin(), ULE->decls_end());
11498  } else {
11499  // If we've resolved this to a particular non-member function, just call
11500  // that function. If we resolved it to a member function,
11501  // CreateOverloaded* will find that function for us.
11502  NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11503  if (!isa<CXXMethodDecl>(ND))
11504  Functions.addDecl(ND);
11505  }
11506 
11507  // Add any functions found via argument-dependent lookup.
11508  Expr *Args[2] = { First, Second };
11509  unsigned NumArgs = 1 + (Second != nullptr);
11510 
11511  // Create the overloaded operator invocation for unary operators.
11512  if (NumArgs == 1 || isPostIncDec) {
11513  UnaryOperatorKind Opc
11514  = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
11515  return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
11516  }
11517 
11518  if (Op == OO_Subscript) {
11519  SourceLocation LBrace;
11520  SourceLocation RBrace;
11521 
11522  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
11523  DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
11527  NameLoc.CXXOperatorName.EndOpNameLoc);
11528  } else {
11529  LBrace = Callee->getLocStart();
11530  RBrace = OpLoc;
11531  }
11532 
11533  return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11534  First, Second);
11535  }
11536 
11537  // Create the overloaded operator invocation for binary operators.
11539  ExprResult Result
11540  = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11541  if (Result.isInvalid())
11542  return ExprError();
11543 
11544  return Result;
11545 }
11546 
11547 template<typename Derived>
11548 ExprResult
11550  SourceLocation OperatorLoc,
11551  bool isArrow,
11552  CXXScopeSpec &SS,
11553  TypeSourceInfo *ScopeType,
11554  SourceLocation CCLoc,
11555  SourceLocation TildeLoc,
11556  PseudoDestructorTypeStorage Destroyed) {
11557  QualType BaseType = Base->getType();
11558  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
11559  (!isArrow && !BaseType->getAs<RecordType>()) ||
11560  (isArrow && BaseType->getAs<PointerType>() &&
11561  !BaseType->getAs<PointerType>()->getPointeeType()
11562  ->template getAs<RecordType>())){
11563  // This pseudo-destructor expression is still a pseudo-destructor.
11564  return SemaRef.BuildPseudoDestructorExpr(
11565  Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11566  CCLoc, TildeLoc, Destroyed);
11567  }
11568 
11569  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
11570  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11571  SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11572  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11573  NameInfo.setNamedTypeInfo(DestroyedType);
11574 
11575  // The scope type is now known to be a valid nested name specifier
11576  // component. Tack it on to the end of the nested name specifier.
11577  if (ScopeType) {
11578  if (!ScopeType->getType()->getAs<TagType>()) {
11579  getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11580  diag::err_expected_class_or_namespace)
11581  << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11582  return ExprError();
11583  }
11584  SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11585  CCLoc);
11586  }
11587 
11588  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
11589  return getSema().BuildMemberReferenceExpr(Base, BaseType,
11590  OperatorLoc, isArrow,
11591  SS, TemplateKWLoc,
11592  /*FIXME: FirstQualifier*/ nullptr,
11593  NameInfo,
11594  /*TemplateArgs*/ nullptr,
11595  /*S*/nullptr);
11596 }
11597 
11598 template<typename Derived>
11599 StmtResult
11601  SourceLocation Loc = S->getLocStart();
11602  CapturedDecl *CD = S->getCapturedDecl();
11603  unsigned NumParams = CD->getNumParams();
11604  unsigned ContextParamPos = CD->getContextParamPosition();
11606  for (unsigned I = 0; I < NumParams; ++I) {
11607  if (I != ContextParamPos) {
11608  Params.push_back(
11609  std::make_pair(
11610  CD->getParam(I)->getName(),
11611  getDerived().TransformType(CD->getParam(I)->getType())));
11612  } else {
11613  Params.push_back(std::make_pair(StringRef(), QualType()));
11614  }
11615  }
11616  getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
11617  S->getCapturedRegionKind(), Params);
11618  StmtResult Body;
11619  {
11620  Sema::CompoundScopeRAII CompoundScope(getSema());
11621  Body = getDerived().TransformStmt(S->getCapturedStmt());
11622  }
11623 
11624  if (Body.isInvalid()) {
11625  getSema().ActOnCapturedRegionError();
11626  return StmtError();
11627  }
11628 
11629  return getSema().ActOnCapturedRegionEnd(Body.get());
11630 }
11631 
11632 } // end namespace clang
11633 
11634 #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:4262
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1332
SourceLocation getEnd() const
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:5108
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:407
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::FullExprArg Cond, VarDecl *CondVar, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
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:212
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:169
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:477
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:2147
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:1997
A (possibly-)qualified type.
Definition: Type.h:575
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:211
bool isInvalid() const
Definition: Ownership.h:159
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:216
QualType TransformType(QualType T)
Transforms the given type into another type.
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:3356
QualType RebuildTemplateSpecializationType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, VarDecl *CondVar, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
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:2636
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:164
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.
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
Build a new object-construction expression.
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:448
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Expr *Cond, VarDecl *CondVar)
Start building a new switch statement.
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1214
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Sema/Lookup.h:465
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:252
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:781
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:1352
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:5362
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:77
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:126
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2586
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId)
Build a new OpenMP 'reduction' clause.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:3918
Represents an attribute applied to a statement.
Definition: Stmt.h:818
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
bool isEnumeralType() const
Definition: Type.h:5365
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1605
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:163
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.
TemplateSpecializationType(TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon, QualType Aliased)
Definition: Type.cpp:3118
This represents 'priority' clause in the '#pragma omp ...' directive.
The base class of the type hierarchy.
Definition: Type.h:1249
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1260
DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, unsigned NumArgs, const TemplateArgument *Args, QualType Canon)
Definition: Type.cpp:2454
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:2773
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc)
Build a new typeof(expr) type.
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1874
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:402
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1149
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:2789
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:390
SourceLocation getColonLoc() const
Returns the location of ':'.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const TemplateArgumentLoc * operator->() const
std::input_iterator_tag iterator_category
A container of type source information.
Definition: Decl.h:61
Wrapper for void* pointer.
Definition: Ownership.h:45
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.
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:2134
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:3864
bool isSpelledAsLValue() const
Definition: Type.h:2304
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:537
RAII object that enters a new expression evaluation context.
Definition: Sema.h:9238
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:699
bool TransformFunctionTypeParams(SourceLocation Loc, ParmVarDecl **Params, unsigned NumParams, const QualType *ParamTypes, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars)
Transforms the parameters of a function type into the given vectors.
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1608
void removeObjCLifetime()
Definition: Type.h:296
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:3067
AutoTypeKeyword getKeyword() const
Definition: Type.h:3936
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:4583
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:2780
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:517
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:48
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1088
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:2847
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
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:1299
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:3817
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:116
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:238
OpenMPDirectiveKind getDirectiveKind() const
Definition: StmtOpenMP.h:202
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:3166
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:233
Step
Definition: OpenMPClause.h:311
This represents '#pragma omp parallel' directive.
Definition: StmtOpenMP.h:232
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
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:411
ExprResult ExprEmpty()
Definition: Ownership.h:273
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1054
This represents 'simd' clause in the '#pragma omp ...' directive.
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3165
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:5314
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:83
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2209
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:92
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:1633
TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given template name.
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.
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:617
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
Expr * getSubExpr()
Definition: Expr.h:2662
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:472
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:1112
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:875
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:102
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.
A location where the result (returned value) of evaluating a statement should be stored.
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
Describes an C or C++ initializer list.
Definition: Expr.h:3724
Represents a C++ using-declaration.
Definition: DeclCXX.h:2858
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:3601
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:874
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:459
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:2017
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 by copy (a.k.a., by value)
Definition: Lambda.h:36
A convenient class for passing around template argument information.
Definition: TemplateBase.h:517
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:2977
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:2958
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)...
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:1629
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:3723
StmtResult StmtError()
Definition: Ownership.h:268
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:497
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:2486
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:146
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:2464
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:2013
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, SourceLocation ColonLoc, Stmt *Range, Stmt *BeginEnd, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc)
Build a new C++0x range-based for statement.
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1106
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:503
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:86
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:2796
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:118
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1263
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3560
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Sema/Lookup.h:367
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:2644
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result)
Build a new co_return statement.
bool empty() const
Definition: Type.h:359
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:1106
QualType getType() const
Definition: Decl.h:530
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:2961
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:6650
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:860
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
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:3599
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Definition: Type.h:3007
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:2766
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
SourceLocation getLocation() const
Definition: ExprCXX.h:2021
StmtResult TransformSEHHandler(Stmt *Handler)
An error occurred.
Definition: Sema.h:4039
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:259
bool isAssignmentOp() const
Definition: Expr.h:3003
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:539
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3041
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:980
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:3274
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:3281
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:2430
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:975
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:679
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:128
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:1683
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:521
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
Expr - This represents one expression.
Definition: Expr.h:104
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:99
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:4202
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:4189
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:310
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:2744
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:2756
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4292
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:216
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3169
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
DeclContext * getDeclContext()
Definition: DeclBase.h:393
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:3620
Represents a C++ template name within the type system.
Definition: TemplateName.h:175
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:219
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:1681
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1751
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
bool isInstanceMethod() const
Definition: DeclObjC.h:419
bool hasTrailingReturn() const
Definition: Type.h:3265
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
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...
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:1717
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1654
struct CXXOpName CXXOperatorName
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:190
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:3988
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.
The symbol exists.
Definition: Sema.h:4029
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:50
UnresolvedSetImpl::iterator decls_iterator
Definition: ExprCXX.h:2490
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:602
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:1535
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:943
bool hasObjCLifetime() const
Definition: Type.h:289
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:169
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:2806
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:1843
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:2639
Kind
This captures a statement into a function.
Definition: Stmt.h:1984
A field in a dependent type, known only by its name.
Definition: Expr.h:1765
TypeLoc getValueLoc() const
Definition: TypeLoc.h:1988
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3053
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...
Encodes a location in the source.
body_range body()
Definition: Stmt.h:569
This represents 'hint' clause in the '#pragma omp ...' directive.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
Definition: OpenMPKinds.h:75
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5089
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:4070
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:118
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:1096
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2644
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:1374
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:431
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:355
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:709
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:4817
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:77
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2010
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, VarDecl *CondVar, Stmt *Body)
Build a new while statement.
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:212
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:1039
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:2416
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1843
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2712
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition: Stmt.h:2084
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:5706
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:164
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:1368
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:74
The name is a dependent name, so the results will differ from one instantiation to the next...
Definition: Sema.h:4036
SourceLocation getKWLoc() const
Definition: TypeLoc.h:1996
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2410
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:536
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:261
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:69
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:557
Opcode getOpcode() const
Definition: Expr.h:1678
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
QualType getPointeeType() const
Definition: Type.h:2161
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:1685
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:2706
Represents a pack expansion of types.
Definition: Type.h:4471
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:2747
attr::Kind getKind() const
Definition: Attr.h:86
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2526
QualType getType() const
Definition: Expr.h:125
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:354
TagTypeKind
The kind of a tag type.
Definition: Type.h:4174
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition: OpenMPKinds.h:66
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2334
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:2910
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
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1121
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:331
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:2799
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
bool isInvalidDecl() const
Definition: DeclBase.h:509
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:2619
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static ExprResult Owned(Expr *E)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:1871
DeclarationName - The name of a declaration.
OMPClause * RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'map' clause.
Expr * getNumTasks() const
Return safe iteration space distance.
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3483
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:2930
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1346
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
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.
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:1950
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:3544
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:421
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:5675
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:5128
This file defines OpenMP AST classes for executable directives and clauses.
bool isDeduced() const
Definition: Type.h:3948
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:1768
UnqualTypeLoc getUnqualifiedLoc() const
Definition: TypeLoc.h:253
bool isNull() const
Determine whether this template name is NULL.
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:5302
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
Definition: DeclSpec.cpp:1228
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:58
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2287
The template argument is a type.
Definition: TemplateBase.h:48
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.h:2175
OpenMPDefaultClauseKind
OpenMP attributes for 'default' clause.
Definition: OpenMPKinds.h:42
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.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
bool isUsable() const
Definition: Ownership.h:160
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3055
bool hasAssociatedStmt() const
Returns true if directive has associated statement.
Definition: StmtOpenMP.h:194
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:850
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:11761
SourceLocation getAttrLoc() const
Definition: Stmt.h:849
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3057
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1074
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:710
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:2297
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:5169
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:215
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
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:5377
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
Designator * designators_iterator
Definition: Expr.h:4136
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:1761
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
Definition: Sema.h:776
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1878
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:91
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1609
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:4223
TryCaptureKind
Definition: Sema.h:3598
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:5622
Location information for a TemplateArgument.
Definition: TemplateBase.h:362
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:262
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:2134
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1465
ExprResult ExprError()
Definition: Ownership.h:267
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2307
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
SourceLocation getRBracLoc() const
Definition: Stmt.h:618
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:187
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:54
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:79
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:922
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:400
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:766
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:616
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:106
static Designator getArray(Expr *Index, SourceLocation LBracketLoc)
Definition: Designator.h:136
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
Definition: DeclBase.h:384
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:145
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:978
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:1734
Represents a C++ namespace alias.
Definition: DeclCXX.h:2649
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1486
ParmVarDecl ** getParmArray() const
Definition: TypeLoc.h:1297
No keyword precedes the qualified type name.
Definition: Type.h:4204
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:171
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:642
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:197
The global specifier '::'. There is no stored value.
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:464
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:296
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.
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:4502
Stmt * getSubStmt()
Definition: Stmt.h:853
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3087
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:4032
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:4328
static StmtResult Owned(Stmt *S)
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1730
Attr - This represents one attribute.
Definition: Attr.h:44
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:5116
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:3945