clang 17.0.0git
TreeTransform.h
Go to the documentation of this file.
1//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15
17#include "TypeLocBuilder.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
23#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
34#include "clang/Sema/Lookup.h"
40#include "llvm/ADT/ArrayRef.h"
41#include "llvm/Support/ErrorHandling.h"
42#include <algorithm>
43#include <optional>
44
45using namespace llvm::omp;
46
47namespace clang {
48using namespace sema;
49
50/// A semantic tree transformation that allows one to transform one
51/// abstract syntax tree into another.
52///
53/// A new tree transformation is defined by creating a new subclass \c X of
54/// \c TreeTransform<X> and then overriding certain operations to provide
55/// behavior specific to that transformation. For example, template
56/// instantiation is implemented as a tree transformation where the
57/// transformation of TemplateTypeParmType nodes involves substituting the
58/// template arguments for their corresponding template parameters; a similar
59/// transformation is performed for non-type template parameters and
60/// template template parameters.
61///
62/// This tree-transformation template uses static polymorphism to allow
63/// subclasses to customize any of its operations. Thus, a subclass can
64/// override any of the transformation or rebuild operators by providing an
65/// operation with the same signature as the default implementation. The
66/// overriding function should not be virtual.
67///
68/// Semantic tree transformations are split into two stages, either of which
69/// can be replaced by a subclass. The "transform" step transforms an AST node
70/// or the parts of an AST node using the various transformation functions,
71/// then passes the pieces on to the "rebuild" step, which constructs a new AST
72/// node of the appropriate kind from the pieces. The default transformation
73/// routines recursively transform the operands to composite AST nodes (e.g.,
74/// the pointee type of a PointerType node) and, if any of those operand nodes
75/// were changed by the transformation, invokes the rebuild operation to create
76/// a new AST node.
77///
78/// Subclasses can customize the transformation at various levels. The
79/// most coarse-grained transformations involve replacing TransformType(),
80/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
81/// TransformTemplateName(), or TransformTemplateArgument() with entirely
82/// new implementations.
83///
84/// For more fine-grained transformations, subclasses can replace any of the
85/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
86/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
87/// replacing TransformTemplateTypeParmType() allows template instantiation
88/// to substitute template arguments for their corresponding template
89/// parameters. Additionally, subclasses can override the \c RebuildXXX
90/// functions to control how AST nodes are rebuilt when their operands change.
91/// By default, \c TreeTransform will invoke semantic analysis to rebuild
92/// AST nodes. However, certain other tree transformations (e.g, cloning) may
93/// be able to use more efficient rebuild steps.
94///
95/// There are a handful of other functions that can be overridden, allowing one
96/// to avoid traversing nodes that don't need any transformation
97/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
98/// operands have not changed (\c AlwaysRebuild()), and customize the
99/// default locations and entity names used for type-checking
100/// (\c getBaseLocation(), \c getBaseEntity()).
101template<typename Derived>
103 /// Private RAII object that helps us forget and then re-remember
104 /// the template argument corresponding to a partially-substituted parameter
105 /// pack.
106 class ForgetPartiallySubstitutedPackRAII {
107 Derived &Self;
109
110 public:
111 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
112 Old = Self.ForgetPartiallySubstitutedPack();
113 }
114
115 ~ForgetPartiallySubstitutedPackRAII() {
116 Self.RememberPartiallySubstitutedPack(Old);
117 }
118 };
119
120protected:
122
123 /// The set of local declarations that have been transformed, for
124 /// cases where we are forced to build new declarations within the transformer
125 /// rather than in the subclass (e.g., lambda closure types).
126 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
127
128public:
129 /// Initializes a new tree transformer.
131
132 /// Retrieves a reference to the derived class.
133 Derived &getDerived() { return static_cast<Derived&>(*this); }
134
135 /// Retrieves a reference to the derived class.
136 const Derived &getDerived() const {
137 return static_cast<const Derived&>(*this);
138 }
139
140 static inline ExprResult Owned(Expr *E) { return E; }
141 static inline StmtResult Owned(Stmt *S) { return S; }
142
143 /// Retrieves a reference to the semantic analysis object used for
144 /// this tree transform.
145 Sema &getSema() const { return SemaRef; }
146
147 /// Whether the transformation should always rebuild AST nodes, even
148 /// if none of the children have changed.
149 ///
150 /// Subclasses may override this function to specify when the transformation
151 /// should rebuild all AST nodes.
152 ///
153 /// We must always rebuild all AST nodes when performing variadic template
154 /// pack expansion, in order to avoid violating the AST invariant that each
155 /// statement node appears at most once in its containing declaration.
157
158 /// Whether the transformation is forming an expression or statement that
159 /// replaces the original. In this case, we'll reuse mangling numbers from
160 /// existing lambdas.
161 bool ReplacingOriginal() { return false; }
162
163 /// Wether CXXConstructExpr can be skipped when they are implicit.
164 /// They will be reconstructed when used if needed.
165 /// This is useful when the user that cause rebuilding of the
166 /// CXXConstructExpr is outside of the expression at which the TreeTransform
167 /// started.
168 bool AllowSkippingCXXConstructExpr() { return true; }
169
170 /// Returns the location of the entity being transformed, if that
171 /// information was not available elsewhere in the AST.
172 ///
173 /// By default, returns no source-location information. Subclasses can
174 /// provide an alternative implementation that provides better location
175 /// information.
177
178 /// Returns the name of the entity being transformed, if that
179 /// information was not available elsewhere in the AST.
180 ///
181 /// By default, returns an empty name. Subclasses can provide an alternative
182 /// implementation with a more precise name.
184
185 /// Sets the "base" location and entity when that
186 /// information is known based on another transformation.
187 ///
188 /// By default, the source location and entity are ignored. Subclasses can
189 /// override this function to provide a customized implementation.
191
192 /// RAII object that temporarily sets the base location and entity
193 /// used for reporting diagnostics in types.
195 TreeTransform &Self;
196 SourceLocation OldLocation;
197 DeclarationName OldEntity;
198
199 public:
201 DeclarationName Entity) : Self(Self) {
202 OldLocation = Self.getDerived().getBaseLocation();
203 OldEntity = Self.getDerived().getBaseEntity();
204
205 if (Location.isValid())
206 Self.getDerived().setBase(Location, Entity);
207 }
208
210 Self.getDerived().setBase(OldLocation, OldEntity);
211 }
212 };
213
214 /// Determine whether the given type \p T has already been
215 /// transformed.
216 ///
217 /// Subclasses can provide an alternative implementation of this routine
218 /// to short-circuit evaluation when it is known that a given type will
219 /// not change. For example, template instantiation need not traverse
220 /// non-dependent types.
222 return T.isNull();
223 }
224
225 /// Transform a template parameter depth level.
226 ///
227 /// During a transformation that transforms template parameters, this maps
228 /// an old template parameter depth to a new depth.
229 unsigned TransformTemplateDepth(unsigned Depth) {
230 return Depth;
231 }
232
233 /// Determine whether the given call argument should be dropped, e.g.,
234 /// because it is a default argument.
235 ///
236 /// Subclasses can provide an alternative implementation of this routine to
237 /// determine which kinds of call arguments get dropped. By default,
238 /// CXXDefaultArgument nodes are dropped (prior to transformation).
240 return E->isDefaultArgument();
241 }
242
243 /// Determine whether we should expand a pack expansion with the
244 /// given set of parameter packs into separate arguments by repeatedly
245 /// transforming the pattern.
246 ///
247 /// By default, the transformer never tries to expand pack expansions.
248 /// Subclasses can override this routine to provide different behavior.
249 ///
250 /// \param EllipsisLoc The location of the ellipsis that identifies the
251 /// pack expansion.
252 ///
253 /// \param PatternRange The source range that covers the entire pattern of
254 /// the pack expansion.
255 ///
256 /// \param Unexpanded The set of unexpanded parameter packs within the
257 /// pattern.
258 ///
259 /// \param ShouldExpand Will be set to \c true if the transformer should
260 /// expand the corresponding pack expansions into separate arguments. When
261 /// set, \c NumExpansions must also be set.
262 ///
263 /// \param RetainExpansion Whether the caller should add an unexpanded
264 /// pack expansion after all of the expanded arguments. This is used
265 /// when extending explicitly-specified template argument packs per
266 /// C++0x [temp.arg.explicit]p9.
267 ///
268 /// \param NumExpansions The number of separate arguments that will be in
269 /// the expanded form of the corresponding pack expansion. This is both an
270 /// input and an output parameter, which can be set by the caller if the
271 /// number of expansions is known a priori (e.g., due to a prior substitution)
272 /// and will be set by the callee when the number of expansions is known.
273 /// The callee must set this value when \c ShouldExpand is \c true; it may
274 /// set this value in other cases.
275 ///
276 /// \returns true if an error occurred (e.g., because the parameter packs
277 /// are to be instantiated with arguments of different lengths), false
278 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
279 /// must be set.
281 SourceRange PatternRange,
283 bool &ShouldExpand, bool &RetainExpansion,
284 std::optional<unsigned> &NumExpansions) {
285 ShouldExpand = false;
286 return false;
287 }
288
289 /// "Forget" about the partially-substituted pack template argument,
290 /// when performing an instantiation that must preserve the parameter pack
291 /// use.
292 ///
293 /// This routine is meant to be overridden by the template instantiator.
295 return TemplateArgument();
296 }
297
298 /// "Remember" the partially-substituted pack template argument
299 /// after performing an instantiation that must preserve the parameter pack
300 /// use.
301 ///
302 /// This routine is meant to be overridden by the template instantiator.
304
305 /// Note to the derived class when a function parameter pack is
306 /// being expanded.
308
309 /// Transforms the given type into another type.
310 ///
311 /// By default, this routine transforms a type by creating a
312 /// TypeSourceInfo for it and delegating to the appropriate
313 /// function. This is expensive, but we don't mind, because
314 /// this method is deprecated anyway; all users should be
315 /// switched to storing TypeSourceInfos.
316 ///
317 /// \returns the transformed type.
319
320 /// Transforms the given type-with-location into a new
321 /// type-with-location.
322 ///
323 /// By default, this routine transforms a type by delegating to the
324 /// appropriate TransformXXXType to build a new type. Subclasses
325 /// may override this function (to take over all type
326 /// transformations) or some set of the TransformXXXType functions
327 /// to alter the transformation.
329
330 /// Transform the given type-with-location into a new
331 /// type, collecting location information in the given builder
332 /// as necessary.
333 ///
335
336 /// Transform a type that is permitted to produce a
337 /// DeducedTemplateSpecializationType.
338 ///
339 /// This is used in the (relatively rare) contexts where it is acceptable
340 /// for transformation to produce a class template type with deduced
341 /// template arguments.
342 /// @{
345 /// @}
346
347 /// The reason why the value of a statement is not discarded, if any.
352 };
353
354 /// Transform the given statement.
355 ///
356 /// By default, this routine transforms a statement by delegating to the
357 /// appropriate TransformXXXStmt function to transform a specific kind of
358 /// statement or the TransformExpr() function to transform an expression.
359 /// Subclasses may override this function to transform statements using some
360 /// other mechanism.
361 ///
362 /// \returns the transformed statement.
364
365 /// Transform the given statement.
366 ///
367 /// By default, this routine transforms a statement by delegating to the
368 /// appropriate TransformOMPXXXClause function to transform a specific kind
369 /// of clause. Subclasses may override this function to transform statements
370 /// using some other mechanism.
371 ///
372 /// \returns the transformed OpenMP clause.
374
375 /// Transform the given attribute.
376 ///
377 /// By default, this routine transforms a statement by delegating to the
378 /// appropriate TransformXXXAttr function to transform a specific kind
379 /// of attribute. Subclasses may override this function to transform
380 /// attributed statements/types using some other mechanism.
381 ///
382 /// \returns the transformed attribute
383 const Attr *TransformAttr(const Attr *S);
384
385 // Transform the given statement attribute.
386 //
387 // Delegates to the appropriate TransformXXXAttr function to transform a
388 // specific kind of statement attribute. Unlike the non-statement taking
389 // version of this, this implements all attributes, not just pragmas.
390 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
391 const Attr *A);
392
393 // Transform the specified attribute.
394 //
395 // Subclasses should override the transformation of attributes with a pragma
396 // spelling to transform expressions stored within the attribute.
397 //
398 // \returns the transformed attribute.
399#define ATTR(X) \
400 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
401#include "clang/Basic/AttrList.inc"
402
403 // Transform the specified attribute.
404 //
405 // Subclasses should override the transformation of attributes to do
406 // transformation and checking of statement attributes. By default, this
407 // delegates to the non-statement taking version.
408 //
409 // \returns the transformed attribute.
410#define ATTR(X) \
411 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
412 const X##Attr *A) { \
413 return getDerived().Transform##X##Attr(A); \
414 }
415#include "clang/Basic/AttrList.inc"
416
417 /// Transform the given expression.
418 ///
419 /// By default, this routine transforms an expression by delegating to the
420 /// appropriate TransformXXXExpr function to build a new expression.
421 /// Subclasses may override this function to transform expressions using some
422 /// other mechanism.
423 ///
424 /// \returns the transformed expression.
426
427 /// Transform the given initializer.
428 ///
429 /// By default, this routine transforms an initializer by stripping off the
430 /// semantic nodes added by initialization, then passing the result to
431 /// TransformExpr or TransformExprs.
432 ///
433 /// \returns the transformed initializer.
434 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
435
436 /// Transform the given list of expressions.
437 ///
438 /// This routine transforms a list of expressions by invoking
439 /// \c TransformExpr() for each subexpression. However, it also provides
440 /// support for variadic templates by expanding any pack expansions (if the
441 /// derived class permits such expansion) along the way. When pack expansions
442 /// are present, the number of outputs may not equal the number of inputs.
443 ///
444 /// \param Inputs The set of expressions to be transformed.
445 ///
446 /// \param NumInputs The number of expressions in \c Inputs.
447 ///
448 /// \param IsCall If \c true, then this transform is being performed on
449 /// function-call arguments, and any arguments that should be dropped, will
450 /// be.
451 ///
452 /// \param Outputs The transformed input expressions will be added to this
453 /// vector.
454 ///
455 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
456 /// due to transformation.
457 ///
458 /// \returns true if an error occurred, false otherwise.
459 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
461 bool *ArgChanged = nullptr);
462
463 /// Transform the given declaration, which is referenced from a type
464 /// or expression.
465 ///
466 /// By default, acts as the identity function on declarations, unless the
467 /// transformer has had to transform the declaration itself. Subclasses
468 /// may override this function to provide alternate behavior.
470 llvm::DenseMap<Decl *, Decl *>::iterator Known
471 = TransformedLocalDecls.find(D);
472 if (Known != TransformedLocalDecls.end())
473 return Known->second;
474
475 return D;
476 }
477
478 /// Transform the specified condition.
479 ///
480 /// By default, this transforms the variable and expression and rebuilds
481 /// the condition.
483 Expr *Expr,
485
486 /// Transform the attributes associated with the given declaration and
487 /// place them on the new declaration.
488 ///
489 /// By default, this operation does nothing. Subclasses may override this
490 /// behavior to transform attributes.
491 void transformAttrs(Decl *Old, Decl *New) { }
492
493 /// Note that a local declaration has been transformed by this
494 /// transformer.
495 ///
496 /// Local declarations are typically transformed via a call to
497 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
498 /// the transformer itself has to transform the declarations. This routine
499 /// can be overridden by a subclass that keeps track of such mappings.
501 assert(New.size() == 1 &&
502 "must override transformedLocalDecl if performing pack expansion");
503 TransformedLocalDecls[Old] = New.front();
504 }
505
506 /// Transform the definition of the given declaration.
507 ///
508 /// By default, invokes TransformDecl() to transform the declaration.
509 /// Subclasses may override this function to provide alternate behavior.
511 return getDerived().TransformDecl(Loc, D);
512 }
513
514 /// Transform the given declaration, which was the first part of a
515 /// nested-name-specifier in a member access expression.
516 ///
517 /// This specific declaration transformation only applies to the first
518 /// identifier in a nested-name-specifier of a member access expression, e.g.,
519 /// the \c T in \c x->T::member
520 ///
521 /// By default, invokes TransformDecl() to transform the declaration.
522 /// Subclasses may override this function to provide alternate behavior.
524 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
525 }
526
527 /// Transform the set of declarations in an OverloadExpr.
528 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
529 LookupResult &R);
530
531 /// Transform the given nested-name-specifier with source-location
532 /// information.
533 ///
534 /// By default, transforms all of the types and declarations within the
535 /// nested-name-specifier. Subclasses may override this function to provide
536 /// alternate behavior.
539 QualType ObjectType = QualType(),
540 NamedDecl *FirstQualifierInScope = nullptr);
541
542 /// Transform the given declaration name.
543 ///
544 /// By default, transforms the types of conversion function, constructor,
545 /// and destructor names and then (if needed) rebuilds the declaration name.
546 /// Identifiers and selectors are returned unmodified. Subclasses may
547 /// override this function to provide alternate behavior.
550
559
560 /// Transform the given template name.
561 ///
562 /// \param SS The nested-name-specifier that qualifies the template
563 /// name. This nested-name-specifier must already have been transformed.
564 ///
565 /// \param Name The template name to transform.
566 ///
567 /// \param NameLoc The source location of the template name.
568 ///
569 /// \param ObjectType If we're translating a template name within a member
570 /// access expression, this is the type of the object whose member template
571 /// is being referenced.
572 ///
573 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
574 /// also refers to a name within the current (lexical) scope, this is the
575 /// declaration it refers to.
576 ///
577 /// By default, transforms the template name by transforming the declarations
578 /// and nested-name-specifiers that occur within the template name.
579 /// Subclasses may override this function to provide alternate behavior.
582 SourceLocation NameLoc,
583 QualType ObjectType = QualType(),
584 NamedDecl *FirstQualifierInScope = nullptr,
585 bool AllowInjectedClassName = false);
586
587 /// Transform the given template argument.
588 ///
589 /// By default, this operation transforms the type, expression, or
590 /// declaration stored within the template argument and constructs a
591 /// new template argument from the transformed result. Subclasses may
592 /// override this function to provide alternate behavior.
593 ///
594 /// Returns true if there was an error.
596 TemplateArgumentLoc &Output,
597 bool Uneval = false);
598
599 /// Transform the given set of template arguments.
600 ///
601 /// By default, this operation transforms all of the template arguments
602 /// in the input set using \c TransformTemplateArgument(), and appends
603 /// the transformed arguments to the output list.
604 ///
605 /// Note that this overload of \c TransformTemplateArguments() is merely
606 /// a convenience function. Subclasses that wish to override this behavior
607 /// should override the iterator-based member template version.
608 ///
609 /// \param Inputs The set of template arguments to be transformed.
610 ///
611 /// \param NumInputs The number of template arguments in \p Inputs.
612 ///
613 /// \param Outputs The set of transformed template arguments output by this
614 /// routine.
615 ///
616 /// Returns true if an error occurred.
618 unsigned NumInputs,
620 bool Uneval = false) {
621 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
622 Uneval);
623 }
624
625 /// Transform the given set of template arguments.
626 ///
627 /// By default, this operation transforms all of the template arguments
628 /// in the input set using \c TransformTemplateArgument(), and appends
629 /// the transformed arguments to the output list.
630 ///
631 /// \param First An iterator to the first template argument.
632 ///
633 /// \param Last An iterator one step past the last template argument.
634 ///
635 /// \param Outputs The set of transformed template arguments output by this
636 /// routine.
637 ///
638 /// Returns true if an error occurred.
639 template<typename InputIterator>
641 InputIterator Last,
643 bool Uneval = false);
644
645 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
647 TemplateArgumentLoc &ArgLoc);
648
649 /// Fakes up a TypeSourceInfo for a type.
653 }
654
655#define ABSTRACT_TYPELOC(CLASS, PARENT)
656#define TYPELOC(CLASS, PARENT) \
657 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
658#include "clang/AST/TypeLocNodes.def"
659
662 bool SuppressObjCLifetime);
666 bool SuppressObjCLifetime);
667
668 template<typename Fn>
671 CXXRecordDecl *ThisContext,
672 Qualifiers ThisTypeQuals,
674
677 SmallVectorImpl<QualType> &Exceptions,
678 bool &Changed);
679
681
685 TemplateName Template);
686
690 TemplateName Template,
691 CXXScopeSpec &SS);
692
695 NestedNameSpecifierLoc QualifierLoc);
696
697 /// Transforms the parameters of a function type into the
698 /// given vectors.
699 ///
700 /// The result vectors should be kept in sync; null entries in the
701 /// variables vector are acceptable.
702 ///
703 /// LastParamTransformed, if non-null, will be set to the index of the last
704 /// parameter on which transfromation was started. In the event of an error,
705 /// this will contain the parameter which failed to instantiate.
706 ///
707 /// Return true on error.
710 const QualType *ParamTypes,
711 const FunctionProtoType::ExtParameterInfo *ParamInfos,
713 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
714
717 const QualType *ParamTypes,
718 const FunctionProtoType::ExtParameterInfo *ParamInfos,
721 return getDerived().TransformFunctionTypeParams(
722 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
723 }
724
725 /// Transforms the parameters of a requires expresison into the given vectors.
726 ///
727 /// The result vectors should be kept in sync; null entries in the
728 /// variables vector are acceptable.
729 ///
730 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
731 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
732 /// which are cases where transformation shouldn't continue.
734 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
740 KWLoc, Params, /*ParamTypes=*/nullptr,
741 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
742 return ExprError();
743
744 return ExprResult{};
745 }
746
747 /// Transforms a single function-type parameter. Return null
748 /// on error.
749 ///
750 /// \param indexAdjustment - A number to add to the parameter's
751 /// scope index; can be negative
753 int indexAdjustment,
754 std::optional<unsigned> NumExpansions,
755 bool ExpectParameterPack);
756
757 /// Transform the body of a lambda-expression.
759 /// Alternative implementation of TransformLambdaBody that skips transforming
760 /// the body.
762
764
767
770 return TPL;
771 }
772
774
776 bool IsAddressOfOperand,
777 TypeSourceInfo **RecoveryTSI);
778
780 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
781 TypeSourceInfo **RecoveryTSI);
782
784
785// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
786// amount of stack usage with clang.
787#define STMT(Node, Parent) \
788 LLVM_ATTRIBUTE_NOINLINE \
789 StmtResult Transform##Node(Node *S);
790#define VALUESTMT(Node, Parent) \
791 LLVM_ATTRIBUTE_NOINLINE \
792 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
793#define EXPR(Node, Parent) \
794 LLVM_ATTRIBUTE_NOINLINE \
795 ExprResult Transform##Node(Node *E);
796#define ABSTRACT_STMT(Stmt)
797#include "clang/AST/StmtNodes.inc"
798
799#define GEN_CLANG_CLAUSE_CLASS
800#define CLAUSE_CLASS(Enum, Str, Class) \
801 LLVM_ATTRIBUTE_NOINLINE \
802 OMPClause *Transform##Class(Class *S);
803#include "llvm/Frontend/OpenMP/OMP.inc"
804
805 /// Build a new qualified type given its unqualified type and type location.
806 ///
807 /// By default, this routine adds type qualifiers only to types that can
808 /// have qualifiers, and silently suppresses those qualifiers that are not
809 /// permitted. Subclasses may override this routine to provide different
810 /// behavior.
812
813 /// Build a new pointer type given its pointee type.
814 ///
815 /// By default, performs semantic analysis when building the pointer type.
816 /// Subclasses may override this routine to provide different behavior.
818
819 /// Build a new block pointer type given its pointee type.
820 ///
821 /// By default, performs semantic analysis when building the block pointer
822 /// type. Subclasses may override this routine to provide different behavior.
824
825 /// Build a new reference type given the type it references.
826 ///
827 /// By default, performs semantic analysis when building the
828 /// reference type. Subclasses may override this routine to provide
829 /// different behavior.
830 ///
831 /// \param LValue whether the type was written with an lvalue sigil
832 /// or an rvalue sigil.
834 bool LValue,
835 SourceLocation Sigil);
836
837 /// Build a new member pointer type given the pointee type and the
838 /// class type it refers into.
839 ///
840 /// By default, performs semantic analysis when building the member pointer
841 /// type. Subclasses may override this routine to provide different behavior.
843 SourceLocation Sigil);
844
846 SourceLocation ProtocolLAngleLoc,
848 ArrayRef<SourceLocation> ProtocolLocs,
849 SourceLocation ProtocolRAngleLoc);
850
851 /// Build an Objective-C object type.
852 ///
853 /// By default, performs semantic analysis when building the object type.
854 /// Subclasses may override this routine to provide different behavior.
856 SourceLocation Loc,
857 SourceLocation TypeArgsLAngleLoc,
859 SourceLocation TypeArgsRAngleLoc,
860 SourceLocation ProtocolLAngleLoc,
862 ArrayRef<SourceLocation> ProtocolLocs,
863 SourceLocation ProtocolRAngleLoc);
864
865 /// Build a new Objective-C object pointer type given the pointee type.
866 ///
867 /// By default, directly builds the pointer type, with no additional semantic
868 /// analysis.
870 SourceLocation Star);
871
872 /// Build a new array type given the element type, size
873 /// modifier, size of the array (if known), size expression, and index type
874 /// qualifiers.
875 ///
876 /// By default, performs semantic analysis when building the array type.
877 /// Subclasses may override this routine to provide different behavior.
878 /// Also by default, all of the other Rebuild*Array
881 const llvm::APInt *Size,
882 Expr *SizeExpr,
883 unsigned IndexTypeQuals,
884 SourceRange BracketsRange);
885
886 /// Build a new constant array type given the element type, size
887 /// modifier, (known) size of the array, and index type qualifiers.
888 ///
889 /// By default, performs semantic analysis when building the array type.
890 /// Subclasses may override this routine to provide different behavior.
893 const llvm::APInt &Size,
894 Expr *SizeExpr,
895 unsigned IndexTypeQuals,
896 SourceRange BracketsRange);
897
898 /// Build a new incomplete array type given the element type, size
899 /// modifier, and index type qualifiers.
900 ///
901 /// By default, performs semantic analysis when building the array type.
902 /// Subclasses may override this routine to provide different behavior.
905 unsigned IndexTypeQuals,
906 SourceRange BracketsRange);
907
908 /// Build a new variable-length array type given the element type,
909 /// size modifier, size expression, and index type qualifiers.
910 ///
911 /// By default, performs semantic analysis when building the array type.
912 /// Subclasses may override this routine to provide different behavior.
915 Expr *SizeExpr,
916 unsigned IndexTypeQuals,
917 SourceRange BracketsRange);
918
919 /// Build a new dependent-sized array type given the element type,
920 /// size modifier, size expression, and index type qualifiers.
921 ///
922 /// By default, performs semantic analysis when building the array type.
923 /// Subclasses may override this routine to provide different behavior.
926 Expr *SizeExpr,
927 unsigned IndexTypeQuals,
928 SourceRange BracketsRange);
929
930 /// Build a new vector type given the element type and
931 /// number of elements.
932 ///
933 /// By default, performs semantic analysis when building the vector type.
934 /// Subclasses may override this routine to provide different behavior.
935 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
936 VectorType::VectorKind VecKind);
937
938 /// Build a new potentially dependently-sized extended vector type
939 /// given the element type and number of elements.
940 ///
941 /// By default, performs semantic analysis when building the vector type.
942 /// Subclasses may override this routine to provide different behavior.
944 SourceLocation AttributeLoc,
946
947 /// Build a new extended vector type given the element type and
948 /// number of elements.
949 ///
950 /// By default, performs semantic analysis when building the vector type.
951 /// Subclasses may override this routine to provide different behavior.
952 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
953 SourceLocation AttributeLoc);
954
955 /// Build a new potentially dependently-sized extended vector type
956 /// given the element type and number of elements.
957 ///
958 /// By default, performs semantic analysis when building the vector type.
959 /// Subclasses may override this routine to provide different behavior.
961 Expr *SizeExpr,
962 SourceLocation AttributeLoc);
963
964 /// Build a new matrix type given the element type and dimensions.
965 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
966 unsigned NumColumns);
967
968 /// Build a new matrix type given the type and dependently-defined
969 /// dimensions.
971 Expr *ColumnExpr,
972 SourceLocation AttributeLoc);
973
974 /// Build a new DependentAddressSpaceType or return the pointee
975 /// type variable with the correct address space (retrieved from
976 /// AddrSpaceExpr) applied to it. The former will be returned in cases
977 /// where the address space remains dependent.
978 ///
979 /// By default, performs semantic analysis when building the type with address
980 /// space applied. Subclasses may override this routine to provide different
981 /// behavior.
983 Expr *AddrSpaceExpr,
984 SourceLocation AttributeLoc);
985
986 /// Build a new function type.
987 ///
988 /// By default, performs semantic analysis when building the function type.
989 /// Subclasses may override this routine to provide different behavior.
991 MutableArrayRef<QualType> ParamTypes,
993
994 /// Build a new unprototyped function type.
996
997 /// Rebuild an unresolved typename type, given the decl that
998 /// the UnresolvedUsingTypenameDecl was transformed to.
1000
1001 /// Build a new type found via an alias.
1003 return SemaRef.Context.getUsingType(Found, Underlying);
1004 }
1005
1006 /// Build a new typedef type.
1008 return SemaRef.Context.getTypeDeclType(Typedef);
1009 }
1010
1011 /// Build a new MacroDefined type.
1013 const IdentifierInfo *MacroII) {
1014 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1015 }
1016
1017 /// Build a new class/struct/union type.
1019 return SemaRef.Context.getTypeDeclType(Record);
1020 }
1021
1022 /// Build a new Enum type.
1025 }
1026
1027 /// Build a new typeof(expr) type.
1028 ///
1029 /// By default, performs semantic analysis when building the typeof type.
1030 /// Subclasses may override this routine to provide different behavior.
1032 TypeOfKind Kind);
1033
1034 /// Build a new typeof(type) type.
1035 ///
1036 /// By default, builds a new TypeOfType with the given underlying type.
1038
1039 /// Build a new unary transform type.
1042 SourceLocation Loc);
1043
1044 /// Build a new C++11 decltype type.
1045 ///
1046 /// By default, performs semantic analysis when building the decltype type.
1047 /// Subclasses may override this routine to provide different behavior.
1049
1050 /// Build a new C++11 auto type.
1051 ///
1052 /// By default, builds a new AutoType with the given deduced type.
1054 ConceptDecl *TypeConstraintConcept,
1055 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1056 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1057 // which has been deduced to a dependent type into an undeduced 'auto', so
1058 // that we'll retry deduction after the transformation.
1059 return SemaRef.Context.getAutoType(Deduced, Keyword,
1060 /*IsDependent*/ false, /*IsPack=*/false,
1061 TypeConstraintConcept,
1062 TypeConstraintArgs);
1063 }
1064
1065 /// By default, builds a new DeducedTemplateSpecializationType with the given
1066 /// deduced type.
1068 QualType Deduced) {
1070 Template, Deduced, /*IsDependent*/ false);
1071 }
1072
1073 /// Build a new template specialization type.
1074 ///
1075 /// By default, performs semantic analysis when building the template
1076 /// specialization type. Subclasses may override this routine to provide
1077 /// different behavior.
1079 SourceLocation TemplateLoc,
1081
1082 /// Build a new parenthesized type.
1083 ///
1084 /// By default, builds a new ParenType type from the inner type.
1085 /// Subclasses may override this routine to provide different behavior.
1087 return SemaRef.BuildParenType(InnerType);
1088 }
1089
1090 /// Build a new qualified name type.
1091 ///
1092 /// By default, builds a new ElaboratedType type from the keyword,
1093 /// the nested-name-specifier and the named type.
1094 /// Subclasses may override this routine to provide different behavior.
1096 ElaboratedTypeKeyword Keyword,
1097 NestedNameSpecifierLoc QualifierLoc,
1098 QualType Named) {
1099 return SemaRef.Context.getElaboratedType(Keyword,
1100 QualifierLoc.getNestedNameSpecifier(),
1101 Named);
1102 }
1103
1104 /// Build a new typename type that refers to a template-id.
1105 ///
1106 /// By default, builds a new DependentNameType type from the
1107 /// nested-name-specifier and the given type. Subclasses may override
1108 /// this routine to provide different behavior.
1110 ElaboratedTypeKeyword Keyword,
1111 NestedNameSpecifierLoc QualifierLoc,
1112 SourceLocation TemplateKWLoc,
1113 const IdentifierInfo *Name,
1114 SourceLocation NameLoc,
1116 bool AllowInjectedClassName) {
1117 // Rebuild the template name.
1118 // TODO: avoid TemplateName abstraction
1119 CXXScopeSpec SS;
1120 SS.Adopt(QualifierLoc);
1121 TemplateName InstName = getDerived().RebuildTemplateName(
1122 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1123 AllowInjectedClassName);
1124
1125 if (InstName.isNull())
1126 return QualType();
1127
1128 // If it's still dependent, make a dependent specialization.
1129 if (InstName.getAsDependentTemplateName())
1131 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1132 Args.arguments());
1133
1134 // Otherwise, make an elaborated type wrapping a non-dependent
1135 // specialization.
1136 QualType T =
1137 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1138 if (T.isNull())
1139 return QualType();
1141 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1142 }
1143
1144 /// Build a new typename type that refers to an identifier.
1145 ///
1146 /// By default, performs semantic analysis when building the typename type
1147 /// (or elaborated type). Subclasses may override this routine to provide
1148 /// different behavior.
1150 SourceLocation KeywordLoc,
1151 NestedNameSpecifierLoc QualifierLoc,
1152 const IdentifierInfo *Id,
1153 SourceLocation IdLoc,
1154 bool DeducedTSTContext) {
1155 CXXScopeSpec SS;
1156 SS.Adopt(QualifierLoc);
1157
1158 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1159 // If the name is still dependent, just build a new dependent name type.
1160 if (!SemaRef.computeDeclContext(SS))
1161 return SemaRef.Context.getDependentNameType(Keyword,
1162 QualifierLoc.getNestedNameSpecifier(),
1163 Id);
1164 }
1165
1166 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1167 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1168 *Id, IdLoc, DeducedTSTContext);
1169 }
1170
1172
1173 // We had a dependent elaborated-type-specifier that has been transformed
1174 // into a non-dependent elaborated-type-specifier. Find the tag we're
1175 // referring to.
1177 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1178 if (!DC)
1179 return QualType();
1180
1182 return QualType();
1183
1184 TagDecl *Tag = nullptr;
1186 switch (Result.getResultKind()) {
1189 break;
1190
1192 Tag = Result.getAsSingle<TagDecl>();
1193 break;
1194
1197 llvm_unreachable("Tag lookup cannot find non-tags");
1198
1200 // Let the LookupResult structure handle ambiguities.
1201 return QualType();
1202 }
1203
1204 if (!Tag) {
1205 // Check where the name exists but isn't a tag type and use that to emit
1206 // better diagnostics.
1209 switch (Result.getResultKind()) {
1213 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1214 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1215 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1216 << NTK << Kind;
1217 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1218 break;
1219 }
1220 default:
1221 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1222 << Kind << Id << DC << QualifierLoc.getSourceRange();
1223 break;
1224 }
1225 return QualType();
1226 }
1227
1228 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1229 IdLoc, Id)) {
1230 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1231 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1232 return QualType();
1233 }
1234
1235 // Build the elaborated-type-specifier type.
1237 return SemaRef.Context.getElaboratedType(Keyword,
1238 QualifierLoc.getNestedNameSpecifier(),
1239 T);
1240 }
1241
1242 /// Build a new pack expansion type.
1243 ///
1244 /// By default, builds a new PackExpansionType type from the given pattern.
1245 /// Subclasses may override this routine to provide different behavior.
1247 SourceLocation EllipsisLoc,
1248 std::optional<unsigned> NumExpansions) {
1249 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1250 NumExpansions);
1251 }
1252
1253 /// Build a new atomic type given its value type.
1254 ///
1255 /// By default, performs semantic analysis when building the atomic type.
1256 /// Subclasses may override this routine to provide different behavior.
1258
1259 /// Build a new pipe type given its value type.
1261 bool isReadPipe);
1262
1263 /// Build a bit-precise int given its value type.
1264 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1265 SourceLocation Loc);
1266
1267 /// Build a dependent bit-precise int given its value type.
1268 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1269 SourceLocation Loc);
1270
1271 /// Build a new template name given a nested name specifier, a flag
1272 /// indicating whether the "template" keyword was provided, and the template
1273 /// that the template name refers to.
1274 ///
1275 /// By default, builds the new template name directly. Subclasses may override
1276 /// this routine to provide different behavior.
1278 bool TemplateKW,
1279 TemplateDecl *Template);
1280
1281 /// Build a new template name given a nested name specifier and the
1282 /// name that is referred to as a template.
1283 ///
1284 /// By default, performs semantic analysis to determine whether the name can
1285 /// be resolved to a specific template, then builds the appropriate kind of
1286 /// template name. Subclasses may override this routine to provide different
1287 /// behavior.
1289 SourceLocation TemplateKWLoc,
1290 const IdentifierInfo &Name,
1291 SourceLocation NameLoc, QualType ObjectType,
1292 NamedDecl *FirstQualifierInScope,
1293 bool AllowInjectedClassName);
1294
1295 /// Build a new template name given a nested name specifier and the
1296 /// overloaded operator name that is referred to as a template.
1297 ///
1298 /// By default, performs semantic analysis to determine whether the name can
1299 /// be resolved to a specific template, then builds the appropriate kind of
1300 /// template name. Subclasses may override this routine to provide different
1301 /// behavior.
1303 SourceLocation TemplateKWLoc,
1304 OverloadedOperatorKind Operator,
1305 SourceLocation NameLoc, QualType ObjectType,
1306 bool AllowInjectedClassName);
1307
1308 /// Build a new template name given a template template parameter pack
1309 /// and the
1310 ///
1311 /// By default, performs semantic analysis to determine whether the name can
1312 /// be resolved to a specific template, then builds the appropriate kind of
1313 /// template name. Subclasses may override this routine to provide different
1314 /// behavior.
1316 Decl *AssociatedDecl, unsigned Index,
1317 bool Final) {
1319 ArgPack, AssociatedDecl, Index, Final);
1320 }
1321
1322 /// Build a new compound statement.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
1327 MultiStmtArg Statements,
1328 SourceLocation RBraceLoc,
1329 bool IsStmtExpr) {
1330 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1331 IsStmtExpr);
1332 }
1333
1334 /// Build a new case statement.
1335 ///
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
1339 Expr *LHS,
1340 SourceLocation EllipsisLoc,
1341 Expr *RHS,
1342 SourceLocation ColonLoc) {
1343 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1344 ColonLoc);
1345 }
1346
1347 /// Attach the body to a new case statement.
1348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
1352 getSema().ActOnCaseStmtBody(S, Body);
1353 return S;
1354 }
1355
1356 /// Build a new default statement.
1357 ///
1358 /// By default, performs semantic analysis to build the new statement.
1359 /// Subclasses may override this routine to provide different behavior.
1361 SourceLocation ColonLoc,
1362 Stmt *SubStmt) {
1363 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1364 /*CurScope=*/nullptr);
1365 }
1366
1367 /// Build a new label statement.
1368 ///
1369 /// By default, performs semantic analysis to build the new statement.
1370 /// Subclasses may override this routine to provide different behavior.
1372 SourceLocation ColonLoc, Stmt *SubStmt) {
1373 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1374 }
1375
1376 /// Build a new attributed statement.
1377 ///
1378 /// By default, performs semantic analysis to build the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
1382 Stmt *SubStmt) {
1383 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1384 }
1385
1386 /// Build a new "if" statement.
1387 ///
1388 /// By default, performs semantic analysis to build the new statement.
1389 /// Subclasses may override this routine to provide different behavior.
1391 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1392 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1393 SourceLocation ElseLoc, Stmt *Else) {
1394 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1395 Then, ElseLoc, Else);
1396 }
1397
1398 /// Start building a new switch statement.
1399 ///
1400 /// By default, performs semantic analysis to build the new statement.
1401 /// Subclasses may override this routine to provide different behavior.
1403 SourceLocation LParenLoc, Stmt *Init,
1405 SourceLocation RParenLoc) {
1406 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1407 RParenLoc);
1408 }
1409
1410 /// Attach the body to the switch statement.
1411 ///
1412 /// By default, performs semantic analysis to build the new statement.
1413 /// Subclasses may override this routine to provide different behavior.
1415 Stmt *Switch, Stmt *Body) {
1416 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1417 }
1418
1419 /// Build a new while statement.
1420 ///
1421 /// By default, performs semantic analysis to build the new statement.
1422 /// Subclasses may override this routine to provide different behavior.
1425 SourceLocation RParenLoc, Stmt *Body) {
1426 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1427 }
1428
1429 /// Build a new do-while statement.
1430 ///
1431 /// By default, performs semantic analysis to build the new statement.
1432 /// Subclasses may override this routine to provide different behavior.
1434 SourceLocation WhileLoc, SourceLocation LParenLoc,
1435 Expr *Cond, SourceLocation RParenLoc) {
1436 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1437 Cond, RParenLoc);
1438 }
1439
1440 /// Build a new for statement.
1441 ///
1442 /// By default, performs semantic analysis to build the new statement.
1443 /// Subclasses may override this routine to provide different behavior.
1445 Stmt *Init, Sema::ConditionResult Cond,
1446 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1447 Stmt *Body) {
1448 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1449 Inc, RParenLoc, Body);
1450 }
1451
1452 /// Build a new goto statement.
1453 ///
1454 /// By default, performs semantic analysis to build the new statement.
1455 /// Subclasses may override this routine to provide different behavior.
1457 LabelDecl *Label) {
1458 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1459 }
1460
1461 /// Build a new indirect goto statement.
1462 ///
1463 /// By default, performs semantic analysis to build the new statement.
1464 /// Subclasses may override this routine to provide different behavior.
1466 SourceLocation StarLoc,
1467 Expr *Target) {
1468 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1469 }
1470
1471 /// Build a new return statement.
1472 ///
1473 /// By default, performs semantic analysis to build the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
1476 return getSema().BuildReturnStmt(ReturnLoc, Result);
1477 }
1478
1479 /// Build a new declaration statement.
1480 ///
1481 /// By default, performs semantic analysis to build the new statement.
1482 /// Subclasses may override this routine to provide different behavior.
1484 SourceLocation StartLoc, SourceLocation EndLoc) {
1486 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1487 }
1488
1489 /// Build a new inline asm statement.
1490 ///
1491 /// By default, performs semantic analysis to build the new statement.
1492 /// Subclasses may override this routine to provide different behavior.
1494 bool IsVolatile, unsigned NumOutputs,
1495 unsigned NumInputs, IdentifierInfo **Names,
1496 MultiExprArg Constraints, MultiExprArg Exprs,
1497 Expr *AsmString, MultiExprArg Clobbers,
1498 unsigned NumLabels,
1499 SourceLocation RParenLoc) {
1500 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1501 NumInputs, Names, Constraints, Exprs,
1502 AsmString, Clobbers, NumLabels, RParenLoc);
1503 }
1504
1505 /// Build a new MS style inline asm statement.
1506 ///
1507 /// By default, performs semantic analysis to build the new statement.
1508 /// Subclasses may override this routine to provide different behavior.
1510 ArrayRef<Token> AsmToks,
1511 StringRef AsmString,
1512 unsigned NumOutputs, unsigned NumInputs,
1513 ArrayRef<StringRef> Constraints,
1514 ArrayRef<StringRef> Clobbers,
1515 ArrayRef<Expr*> Exprs,
1516 SourceLocation EndLoc) {
1517 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1518 NumOutputs, NumInputs,
1519 Constraints, Clobbers, Exprs, EndLoc);
1520 }
1521
1522 /// Build a new co_return statement.
1523 ///
1524 /// By default, performs semantic analysis to build the new statement.
1525 /// Subclasses may override this routine to provide different behavior.
1527 bool IsImplicit) {
1528 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1529 }
1530
1531 /// Build a new co_await expression.
1532 ///
1533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
1536 UnresolvedLookupExpr *OpCoawaitLookup,
1537 bool IsImplicit) {
1538 // This function rebuilds a coawait-expr given its operator.
1539 // For an explicit coawait-expr, the rebuild involves the full set
1540 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1541 // including calling await_transform().
1542 // For an implicit coawait-expr, we need to rebuild the "operator
1543 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1544 // This mirrors how the implicit CoawaitExpr is originally created
1545 // in Sema::ActOnCoroutineBodyStart().
1546 if (IsImplicit) {
1548 CoawaitLoc, Operand, OpCoawaitLookup);
1549 if (Suspend.isInvalid())
1550 return ExprError();
1551 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1552 Suspend.get(), true);
1553 }
1554
1555 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1556 OpCoawaitLookup);
1557 }
1558
1559 /// Build a new co_await expression.
1560 ///
1561 /// By default, performs semantic analysis to build the new expression.
1562 /// Subclasses may override this routine to provide different behavior.
1564 Expr *Result,
1565 UnresolvedLookupExpr *Lookup) {
1566 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1567 }
1568
1569 /// Build a new co_yield expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
1574 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1575 }
1576
1578 return getSema().BuildCoroutineBodyStmt(Args);
1579 }
1580
1581 /// Build a new Objective-C \@try statement.
1582 ///
1583 /// By default, performs semantic analysis to build the new statement.
1584 /// Subclasses may override this routine to provide different behavior.
1586 Stmt *TryBody,
1587 MultiStmtArg CatchStmts,
1588 Stmt *Finally) {
1589 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1590 Finally);
1591 }
1592
1593 /// Rebuild an Objective-C exception declaration.
1594 ///
1595 /// By default, performs semantic analysis to build the new declaration.
1596 /// Subclasses may override this routine to provide different behavior.
1598 TypeSourceInfo *TInfo, QualType T) {
1599 return getSema().BuildObjCExceptionDecl(TInfo, T,
1600 ExceptionDecl->getInnerLocStart(),
1601 ExceptionDecl->getLocation(),
1602 ExceptionDecl->getIdentifier());
1603 }
1604
1605 /// Build a new Objective-C \@catch statement.
1606 ///
1607 /// By default, performs semantic analysis to build the new statement.
1608 /// Subclasses may override this routine to provide different behavior.
1610 SourceLocation RParenLoc,
1611 VarDecl *Var,
1612 Stmt *Body) {
1613 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1614 Var, Body);
1615 }
1616
1617 /// Build a new Objective-C \@finally statement.
1618 ///
1619 /// By default, performs semantic analysis to build the new statement.
1620 /// Subclasses may override this routine to provide different behavior.
1622 Stmt *Body) {
1623 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1624 }
1625
1626 /// Build a new Objective-C \@throw statement.
1627 ///
1628 /// By default, performs semantic analysis to build the new statement.
1629 /// Subclasses may override this routine to provide different behavior.
1631 Expr *Operand) {
1632 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1633 }
1634
1635 /// Build a new OpenMP Canonical loop.
1636 ///
1637 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1638 /// OMPCanonicalLoop.
1640 return getSema().ActOnOpenMPCanonicalLoop(LoopStmt);
1641 }
1642
1643 /// Build a new OpenMP executable directive.
1644 ///
1645 /// By default, performs semantic analysis to build the new statement.
1646 /// Subclasses may override this routine to provide different behavior.
1648 DeclarationNameInfo DirName,
1649 OpenMPDirectiveKind CancelRegion,
1650 ArrayRef<OMPClause *> Clauses,
1651 Stmt *AStmt, SourceLocation StartLoc,
1652 SourceLocation EndLoc) {
1654 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1655 }
1656
1657 /// Build a new OpenMP 'if' 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 Expr *Condition, SourceLocation StartLoc,
1663 SourceLocation LParenLoc,
1664 SourceLocation NameModifierLoc,
1665 SourceLocation ColonLoc,
1666 SourceLocation EndLoc) {
1667 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1668 LParenLoc, NameModifierLoc, ColonLoc,
1669 EndLoc);
1670 }
1671
1672 /// Build a new OpenMP 'final' clause.
1673 ///
1674 /// By default, performs semantic analysis to build the new OpenMP clause.
1675 /// Subclasses may override this routine to provide different behavior.
1677 SourceLocation LParenLoc,
1678 SourceLocation EndLoc) {
1679 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1680 EndLoc);
1681 }
1682
1683 /// Build a new OpenMP 'num_threads' clause.
1684 ///
1685 /// By default, performs semantic analysis to build the new OpenMP clause.
1686 /// Subclasses may override this routine to provide different behavior.
1688 SourceLocation StartLoc,
1689 SourceLocation LParenLoc,
1690 SourceLocation EndLoc) {
1691 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1692 LParenLoc, EndLoc);
1693 }
1694
1695 /// Build a new OpenMP 'safelen' clause.
1696 ///
1697 /// By default, performs semantic analysis to build the new OpenMP clause.
1698 /// Subclasses may override this routine to provide different behavior.
1700 SourceLocation LParenLoc,
1701 SourceLocation EndLoc) {
1702 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1703 }
1704
1705 /// Build a new OpenMP 'simdlen' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new OpenMP clause.
1708 /// Subclasses may override this routine to provide different behavior.
1710 SourceLocation LParenLoc,
1711 SourceLocation EndLoc) {
1712 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1713 }
1714
1716 SourceLocation StartLoc,
1717 SourceLocation LParenLoc,
1718 SourceLocation EndLoc) {
1719 return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc);
1720 }
1721
1722 /// Build a new OpenMP 'full' clause.
1724 SourceLocation EndLoc) {
1725 return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc);
1726 }
1727
1728 /// Build a new OpenMP 'partial' clause.
1730 SourceLocation LParenLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc,
1733 EndLoc);
1734 }
1735
1736 /// Build a new OpenMP 'allocator' clause.
1737 ///
1738 /// By default, performs semantic analysis to build the new OpenMP clause.
1739 /// Subclasses may override this routine to provide different behavior.
1741 SourceLocation LParenLoc,
1742 SourceLocation EndLoc) {
1743 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1744 }
1745
1746 /// Build a new OpenMP 'collapse' clause.
1747 ///
1748 /// By default, performs semantic analysis to build the new OpenMP clause.
1749 /// Subclasses may override this routine to provide different behavior.
1751 SourceLocation LParenLoc,
1752 SourceLocation EndLoc) {
1753 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1754 EndLoc);
1755 }
1756
1757 /// Build a new OpenMP 'default' clause.
1758 ///
1759 /// By default, performs semantic analysis to build the new OpenMP clause.
1760 /// Subclasses may override this routine to provide different behavior.
1762 SourceLocation StartLoc,
1763 SourceLocation LParenLoc,
1764 SourceLocation EndLoc) {
1765 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1766 StartLoc, LParenLoc, EndLoc);
1767 }
1768
1769 /// Build a new OpenMP 'proc_bind' clause.
1770 ///
1771 /// By default, performs semantic analysis to build the new OpenMP clause.
1772 /// Subclasses may override this routine to provide different behavior.
1774 SourceLocation KindKwLoc,
1775 SourceLocation StartLoc,
1776 SourceLocation LParenLoc,
1777 SourceLocation EndLoc) {
1778 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1779 StartLoc, LParenLoc, EndLoc);
1780 }
1781
1782 /// Build a new OpenMP 'schedule' clause.
1783 ///
1784 /// By default, performs semantic analysis to build the new OpenMP clause.
1785 /// Subclasses may override this routine to provide different behavior.
1788 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1789 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1790 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1792 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1793 CommaLoc, EndLoc);
1794 }
1795
1796 /// Build a new OpenMP 'ordered' clause.
1797 ///
1798 /// By default, performs semantic analysis to build the new OpenMP clause.
1799 /// Subclasses may override this routine to provide different behavior.
1801 SourceLocation EndLoc,
1802 SourceLocation LParenLoc, Expr *Num) {
1803 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1804 }
1805
1806 /// Build a new OpenMP 'private' clause.
1807 ///
1808 /// By default, performs semantic analysis to build the new OpenMP clause.
1809 /// Subclasses may override this routine to provide different behavior.
1811 SourceLocation StartLoc,
1812 SourceLocation LParenLoc,
1813 SourceLocation EndLoc) {
1814 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1815 EndLoc);
1816 }
1817
1818 /// Build a new OpenMP 'firstprivate' clause.
1819 ///
1820 /// By default, performs semantic analysis to build the new OpenMP clause.
1821 /// Subclasses may override this routine to provide different behavior.
1823 SourceLocation StartLoc,
1824 SourceLocation LParenLoc,
1825 SourceLocation EndLoc) {
1826 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1827 EndLoc);
1828 }
1829
1830 /// Build a new OpenMP 'lastprivate' clause.
1831 ///
1832 /// By default, performs semantic analysis to build the new OpenMP clause.
1833 /// Subclasses may override this routine to provide different behavior.
1836 SourceLocation LPKindLoc,
1837 SourceLocation ColonLoc,
1838 SourceLocation StartLoc,
1839 SourceLocation LParenLoc,
1840 SourceLocation EndLoc) {
1842 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1843 }
1844
1845 /// Build a new OpenMP 'shared' clause.
1846 ///
1847 /// By default, performs semantic analysis to build the new OpenMP clause.
1848 /// Subclasses may override this routine to provide different behavior.
1850 SourceLocation StartLoc,
1851 SourceLocation LParenLoc,
1852 SourceLocation EndLoc) {
1853 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1854 EndLoc);
1855 }
1856
1857 /// Build a new OpenMP 'reduction' clause.
1858 ///
1859 /// By default, performs semantic analysis to build the new statement.
1860 /// Subclasses may override this routine to provide different behavior.
1863 SourceLocation StartLoc, SourceLocation LParenLoc,
1864 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1865 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1866 const DeclarationNameInfo &ReductionId,
1867 ArrayRef<Expr *> UnresolvedReductions) {
1869 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1870 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1871 }
1872
1873 /// Build a new OpenMP 'task_reduction' clause.
1874 ///
1875 /// By default, performs semantic analysis to build the new statement.
1876 /// Subclasses may override this routine to provide different behavior.
1878 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1879 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1880 CXXScopeSpec &ReductionIdScopeSpec,
1881 const DeclarationNameInfo &ReductionId,
1882 ArrayRef<Expr *> UnresolvedReductions) {
1884 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1885 ReductionId, UnresolvedReductions);
1886 }
1887
1888 /// Build a new OpenMP 'in_reduction' clause.
1889 ///
1890 /// By default, performs semantic analysis to build the new statement.
1891 /// Subclasses may override this routine to provide different behavior.
1892 OMPClause *
1894 SourceLocation LParenLoc, SourceLocation ColonLoc,
1895 SourceLocation EndLoc,
1896 CXXScopeSpec &ReductionIdScopeSpec,
1897 const DeclarationNameInfo &ReductionId,
1898 ArrayRef<Expr *> UnresolvedReductions) {
1900 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1901 ReductionId, UnresolvedReductions);
1902 }
1903
1904 /// Build a new OpenMP 'linear' clause.
1905 ///
1906 /// By default, performs semantic analysis to build the new OpenMP clause.
1907 /// Subclasses may override this routine to provide different behavior.
1909 SourceLocation StartLoc,
1910 SourceLocation LParenLoc,
1911 OpenMPLinearClauseKind Modifier,
1912 SourceLocation ModifierLoc,
1913 SourceLocation ColonLoc,
1914 SourceLocation EndLoc) {
1915 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1916 Modifier, ModifierLoc, ColonLoc,
1917 EndLoc);
1918 }
1919
1920 /// Build a new OpenMP 'aligned' clause.
1921 ///
1922 /// By default, performs semantic analysis to build the new OpenMP clause.
1923 /// Subclasses may override this routine to provide different behavior.
1925 SourceLocation StartLoc,
1926 SourceLocation LParenLoc,
1927 SourceLocation ColonLoc,
1928 SourceLocation EndLoc) {
1929 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1930 LParenLoc, ColonLoc, EndLoc);
1931 }
1932
1933 /// Build a new OpenMP 'copyin' clause.
1934 ///
1935 /// By default, performs semantic analysis to build the new OpenMP clause.
1936 /// Subclasses may override this routine to provide different behavior.
1938 SourceLocation StartLoc,
1939 SourceLocation LParenLoc,
1940 SourceLocation EndLoc) {
1941 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1942 EndLoc);
1943 }
1944
1945 /// Build a new OpenMP 'copyprivate' clause.
1946 ///
1947 /// By default, performs semantic analysis to build the new OpenMP clause.
1948 /// Subclasses may override this routine to provide different behavior.
1950 SourceLocation StartLoc,
1951 SourceLocation LParenLoc,
1952 SourceLocation EndLoc) {
1953 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1954 EndLoc);
1955 }
1956
1957 /// Build a new OpenMP 'flush' pseudo clause.
1958 ///
1959 /// By default, performs semantic analysis to build the new OpenMP clause.
1960 /// Subclasses may override this routine to provide different behavior.
1962 SourceLocation StartLoc,
1963 SourceLocation LParenLoc,
1964 SourceLocation EndLoc) {
1965 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1966 EndLoc);
1967 }
1968
1969 /// Build a new OpenMP 'depobj' pseudo clause.
1970 ///
1971 /// By default, performs semantic analysis to build the new OpenMP clause.
1972 /// Subclasses may override this routine to provide different behavior.
1974 SourceLocation LParenLoc,
1975 SourceLocation EndLoc) {
1976 return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc,
1977 EndLoc);
1978 }
1979
1980 /// Build a new OpenMP 'depend' pseudo clause.
1981 ///
1982 /// By default, performs semantic analysis to build the new OpenMP clause.
1983 /// Subclasses may override this routine to provide different behavior.
1985 Expr *DepModifier, ArrayRef<Expr *> VarList,
1986 SourceLocation StartLoc,
1987 SourceLocation LParenLoc,
1988 SourceLocation EndLoc) {
1989 return getSema().ActOnOpenMPDependClause(Data, DepModifier, VarList,
1990 StartLoc, LParenLoc, EndLoc);
1991 }
1992
1993 /// Build a new OpenMP 'device' clause.
1994 ///
1995 /// By default, performs semantic analysis to build the new statement.
1996 /// Subclasses may override this routine to provide different behavior.
1998 Expr *Device, SourceLocation StartLoc,
1999 SourceLocation LParenLoc,
2000 SourceLocation ModifierLoc,
2001 SourceLocation EndLoc) {
2002 return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc,
2003 LParenLoc, ModifierLoc, EndLoc);
2004 }
2005
2006 /// Build a new OpenMP 'map' clause.
2007 ///
2008 /// By default, performs semantic analysis to build the new OpenMP clause.
2009 /// Subclasses may override this routine to provide different behavior.
2011 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2012 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2013 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2014 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2015 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2016 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2018 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2019 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2020 ColonLoc, VarList, Locs,
2021 /*NoDiagnose=*/false, UnresolvedMappers);
2022 }
2023
2024 /// Build a new OpenMP 'allocate' clause.
2025 ///
2026 /// By default, performs semantic analysis to build the new OpenMP clause.
2027 /// Subclasses may override this routine to provide different behavior.
2029 SourceLocation StartLoc,
2030 SourceLocation LParenLoc,
2031 SourceLocation ColonLoc,
2032 SourceLocation EndLoc) {
2033 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
2034 LParenLoc, ColonLoc, EndLoc);
2035 }
2036
2037 /// Build a new OpenMP 'num_teams' clause.
2038 ///
2039 /// By default, performs semantic analysis to build the new statement.
2040 /// Subclasses may override this routine to provide different behavior.
2042 SourceLocation LParenLoc,
2043 SourceLocation EndLoc) {
2044 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
2045 EndLoc);
2046 }
2047
2048 /// Build a new OpenMP 'thread_limit' clause.
2049 ///
2050 /// By default, performs semantic analysis to build the new statement.
2051 /// Subclasses may override this routine to provide different behavior.
2053 SourceLocation StartLoc,
2054 SourceLocation LParenLoc,
2055 SourceLocation EndLoc) {
2056 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
2057 LParenLoc, EndLoc);
2058 }
2059
2060 /// Build a new OpenMP 'priority' clause.
2061 ///
2062 /// By default, performs semantic analysis to build the new statement.
2063 /// Subclasses may override this routine to provide different behavior.
2065 SourceLocation LParenLoc,
2066 SourceLocation EndLoc) {
2067 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
2068 EndLoc);
2069 }
2070
2071 /// Build a new OpenMP 'grainsize' clause.
2072 ///
2073 /// By default, performs semantic analysis to build the new statement.
2074 /// Subclasses may override this routine to provide different behavior.
2076 Expr *Device, SourceLocation StartLoc,
2077 SourceLocation LParenLoc,
2078 SourceLocation ModifierLoc,
2079 SourceLocation EndLoc) {
2080 return getSema().ActOnOpenMPGrainsizeClause(Modifier, Device, StartLoc,
2081 LParenLoc, ModifierLoc, EndLoc);
2082 }
2083
2084 /// Build a new OpenMP 'num_tasks' clause.
2085 ///
2086 /// By default, performs semantic analysis to build the new statement.
2087 /// Subclasses may override this routine to provide different behavior.
2089 Expr *NumTasks, SourceLocation StartLoc,
2090 SourceLocation LParenLoc,
2091 SourceLocation ModifierLoc,
2092 SourceLocation EndLoc) {
2093 return getSema().ActOnOpenMPNumTasksClause(Modifier, NumTasks, StartLoc,
2094 LParenLoc, ModifierLoc, EndLoc);
2095 }
2096
2097 /// Build a new OpenMP 'hint' clause.
2098 ///
2099 /// By default, performs semantic analysis to build the new statement.
2100 /// Subclasses may override this routine to provide different behavior.
2102 SourceLocation LParenLoc,
2103 SourceLocation EndLoc) {
2104 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
2105 }
2106
2107 /// Build a new OpenMP 'detach' clause.
2108 ///
2109 /// By default, performs semantic analysis to build the new statement.
2110 /// Subclasses may override this routine to provide different behavior.
2112 SourceLocation LParenLoc,
2113 SourceLocation EndLoc) {
2114 return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);
2115 }
2116
2117 /// Build a new OpenMP 'dist_schedule' clause.
2118 ///
2119 /// By default, performs semantic analysis to build the new OpenMP clause.
2120 /// Subclasses may override this routine to provide different behavior.
2121 OMPClause *
2123 Expr *ChunkSize, SourceLocation StartLoc,
2124 SourceLocation LParenLoc, SourceLocation KindLoc,
2125 SourceLocation CommaLoc, SourceLocation EndLoc) {
2127 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2128 }
2129
2130 /// Build a new OpenMP 'to' clause.
2131 ///
2132 /// By default, performs semantic analysis to build the new statement.
2133 /// Subclasses may override this routine to provide different behavior.
2134 OMPClause *
2136 ArrayRef<SourceLocation> MotionModifiersLoc,
2137 CXXScopeSpec &MapperIdScopeSpec,
2138 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2139 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2140 ArrayRef<Expr *> UnresolvedMappers) {
2141 return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc,
2142 MapperIdScopeSpec, MapperId, ColonLoc,
2143 VarList, Locs, UnresolvedMappers);
2144 }
2145
2146 /// Build a new OpenMP 'from' clause.
2147 ///
2148 /// By default, performs semantic analysis to build the new statement.
2149 /// Subclasses may override this routine to provide different behavior.
2150 OMPClause *
2152 ArrayRef<SourceLocation> MotionModifiersLoc,
2153 CXXScopeSpec &MapperIdScopeSpec,
2154 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2155 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2156 ArrayRef<Expr *> UnresolvedMappers) {
2158 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2159 ColonLoc, VarList, Locs, UnresolvedMappers);
2160 }
2161
2162 /// Build a new OpenMP 'use_device_ptr' clause.
2163 ///
2164 /// By default, performs semantic analysis to build the new OpenMP clause.
2165 /// Subclasses may override this routine to provide different behavior.
2167 const OMPVarListLocTy &Locs) {
2168 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2169 }
2170
2171 /// Build a new OpenMP 'use_device_addr' clause.
2172 ///
2173 /// By default, performs semantic analysis to build the new OpenMP clause.
2174 /// Subclasses may override this routine to provide different behavior.
2176 const OMPVarListLocTy &Locs) {
2177 return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2178 }
2179
2180 /// Build a new OpenMP 'is_device_ptr' clause.
2181 ///
2182 /// By default, performs semantic analysis to build the new OpenMP clause.
2183 /// Subclasses may override this routine to provide different behavior.
2185 const OMPVarListLocTy &Locs) {
2186 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2187 }
2188
2189 /// Build a new OpenMP 'has_device_addr' clause.
2190 ///
2191 /// By default, performs semantic analysis to build the new OpenMP clause.
2192 /// Subclasses may override this routine to provide different behavior.
2194 const OMPVarListLocTy &Locs) {
2195 return getSema().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2196 }
2197
2198 /// Build a new OpenMP 'defaultmap' clause.
2199 ///
2200 /// By default, performs semantic analysis to build the new OpenMP clause.
2201 /// Subclasses may override this routine to provide different behavior.
2204 SourceLocation StartLoc,
2205 SourceLocation LParenLoc,
2206 SourceLocation MLoc,
2207 SourceLocation KindLoc,
2208 SourceLocation EndLoc) {
2209 return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc,
2210 MLoc, KindLoc, EndLoc);
2211 }
2212
2213 /// Build a new OpenMP 'nontemporal' clause.
2214 ///
2215 /// By default, performs semantic analysis to build the new OpenMP clause.
2216 /// Subclasses may override this routine to provide different behavior.
2218 SourceLocation StartLoc,
2219 SourceLocation LParenLoc,
2220 SourceLocation EndLoc) {
2221 return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc,
2222 EndLoc);
2223 }
2224
2225 /// Build a new OpenMP 'inclusive' clause.
2226 ///
2227 /// By default, performs semantic analysis to build the new OpenMP clause.
2228 /// Subclasses may override this routine to provide different behavior.
2230 SourceLocation StartLoc,
2231 SourceLocation LParenLoc,
2232 SourceLocation EndLoc) {
2233 return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc,
2234 EndLoc);
2235 }
2236
2237 /// Build a new OpenMP 'exclusive' clause.
2238 ///
2239 /// By default, performs semantic analysis to build the new OpenMP clause.
2240 /// Subclasses may override this routine to provide different behavior.
2242 SourceLocation StartLoc,
2243 SourceLocation LParenLoc,
2244 SourceLocation EndLoc) {
2245 return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc,
2246 EndLoc);
2247 }
2248
2249 /// Build a new OpenMP 'uses_allocators' clause.
2250 ///
2251 /// By default, performs semantic analysis to build the new OpenMP clause.
2252 /// Subclasses may override this routine to provide different behavior.
2255 SourceLocation LParenLoc, SourceLocation EndLoc) {
2256 return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc,
2257 Data);
2258 }
2259
2260 /// Build a new OpenMP 'affinity' clause.
2261 ///
2262 /// By default, performs semantic analysis to build the new OpenMP clause.
2263 /// Subclasses may override this routine to provide different behavior.
2265 SourceLocation LParenLoc,
2266 SourceLocation ColonLoc,
2267 SourceLocation EndLoc, Expr *Modifier,
2268 ArrayRef<Expr *> Locators) {
2269 return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc,
2270 EndLoc, Modifier, Locators);
2271 }
2272
2273 /// Build a new OpenMP 'order' clause.
2274 ///
2275 /// By default, performs semantic analysis to build the new OpenMP clause.
2276 /// Subclasses may override this routine to provide different behavior.
2278 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2279 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2280 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2281 return getSema().ActOnOpenMPOrderClause(Modifier, Kind, StartLoc, LParenLoc,
2282 ModifierKwLoc, KindKwLoc, EndLoc);
2283 }
2284
2285 /// Build a new OpenMP 'init' clause.
2286 ///
2287 /// By default, performs semantic analysis to build the new OpenMP clause.
2288 /// Subclasses may override this routine to provide different behavior.
2290 SourceLocation StartLoc,
2291 SourceLocation LParenLoc,
2292 SourceLocation VarLoc,
2293 SourceLocation EndLoc) {
2294 return getSema().ActOnOpenMPInitClause(InteropVar, InteropInfo, StartLoc,
2295 LParenLoc, VarLoc, EndLoc);
2296 }
2297
2298 /// Build a new OpenMP 'use' clause.
2299 ///
2300 /// By default, performs semantic analysis to build the new OpenMP clause.
2301 /// Subclasses may override this routine to provide different behavior.
2303 SourceLocation LParenLoc,
2304 SourceLocation VarLoc, SourceLocation EndLoc) {
2305 return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc,
2306 VarLoc, EndLoc);
2307 }
2308
2309 /// Build a new OpenMP 'destroy' clause.
2310 ///
2311 /// By default, performs semantic analysis to build the new OpenMP clause.
2312 /// Subclasses may override this routine to provide different behavior.
2314 SourceLocation LParenLoc,
2315 SourceLocation VarLoc,
2316 SourceLocation EndLoc) {
2317 return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc,
2318 VarLoc, EndLoc);
2319 }
2320
2321 /// Build a new OpenMP 'novariants' clause.
2322 ///
2323 /// By default, performs semantic analysis to build the new OpenMP clause.
2324 /// Subclasses may override this routine to provide different behavior.
2326 SourceLocation StartLoc,
2327 SourceLocation LParenLoc,
2328 SourceLocation EndLoc) {
2329 return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc,
2330 EndLoc);
2331 }
2332
2333 /// Build a new OpenMP 'nocontext' clause.
2334 ///
2335 /// By default, performs semantic analysis to build the new OpenMP clause.
2336 /// Subclasses may override this routine to provide different behavior.
2338 SourceLocation LParenLoc,
2339 SourceLocation EndLoc) {
2340 return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc,
2341 EndLoc);
2342 }
2343
2344 /// Build a new OpenMP 'filter' clause.
2345 ///
2346 /// By default, performs semantic analysis to build the new OpenMP clause.
2347 /// Subclasses may override this routine to provide different behavior.
2349 SourceLocation LParenLoc,
2350 SourceLocation EndLoc) {
2351 return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc,
2352 EndLoc);
2353 }
2354
2355 /// Build a new OpenMP 'bind' clause.
2356 ///
2357 /// By default, performs semantic analysis to build the new OpenMP clause.
2358 /// Subclasses may override this routine to provide different behavior.
2360 SourceLocation KindLoc,
2361 SourceLocation StartLoc,
2362 SourceLocation LParenLoc,
2363 SourceLocation EndLoc) {
2364 return getSema().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, LParenLoc,
2365 EndLoc);
2366 }
2367
2368 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2369 ///
2370 /// By default, performs semantic analysis to build the new OpenMP clause.
2371 /// Subclasses may override this routine to provide different behavior.
2373 SourceLocation LParenLoc,
2374 SourceLocation EndLoc) {
2375 return getSema().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc, LParenLoc,
2376 EndLoc);
2377 }
2378
2379 /// Build a new OpenMP 'align' clause.
2380 ///
2381 /// By default, performs semantic analysis to build the new OpenMP clause.
2382 /// Subclasses may override this routine to provide different behavior.
2384 SourceLocation LParenLoc,
2385 SourceLocation EndLoc) {
2386 return getSema().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
2387 }
2388
2389 /// Build a new OpenMP 'at' clause.
2390 ///
2391 /// By default, performs semantic analysis to build the new OpenMP clause.
2392 /// Subclasses may override this routine to provide different behavior.
2394 SourceLocation StartLoc,
2395 SourceLocation LParenLoc,
2396 SourceLocation EndLoc) {
2397 return getSema().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc, LParenLoc,
2398 EndLoc);
2399 }
2400
2401 /// Build a new OpenMP 'severity' clause.
2402 ///
2403 /// By default, performs semantic analysis to build the new OpenMP clause.
2404 /// Subclasses may override this routine to provide different behavior.
2406 SourceLocation KwLoc,
2407 SourceLocation StartLoc,
2408 SourceLocation LParenLoc,
2409 SourceLocation EndLoc) {
2410 return getSema().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc, LParenLoc,
2411 EndLoc);
2412 }
2413
2414 /// Build a new OpenMP 'message' clause.
2415 ///
2416 /// By default, performs semantic analysis to build the new OpenMP clause.
2417 /// Subclasses may override this routine to provide different behavior.
2419 SourceLocation LParenLoc,
2420 SourceLocation EndLoc) {
2421 return getSema().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc, EndLoc);
2422 }
2423
2424 /// Rebuild the operand to an Objective-C \@synchronized statement.
2425 ///
2426 /// By default, performs semantic analysis to build the new statement.
2427 /// Subclasses may override this routine to provide different behavior.
2429 Expr *object) {
2430 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
2431 }
2432
2433 /// Build a new Objective-C \@synchronized statement.
2434 ///
2435 /// By default, performs semantic analysis to build the new statement.
2436 /// Subclasses may override this routine to provide different behavior.
2438 Expr *Object, Stmt *Body) {
2439 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2440 }
2441
2442 /// Build a new Objective-C \@autoreleasepool statement.
2443 ///
2444 /// By default, performs semantic analysis to build the new statement.
2445 /// Subclasses may override this routine to provide different behavior.
2447 Stmt *Body) {
2448 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2449 }
2450
2451 /// Build a new Objective-C fast enumeration statement.
2452 ///
2453 /// By default, performs semantic analysis to build the new statement.
2454 /// Subclasses may override this routine to provide different behavior.
2456 Stmt *Element,
2457 Expr *Collection,
2458 SourceLocation RParenLoc,
2459 Stmt *Body) {
2460 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
2461 Element,
2462 Collection,
2463 RParenLoc);
2464 if (ForEachStmt.isInvalid())
2465 return StmtError();
2466
2467 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
2468 }
2469
2470 /// Build a new C++ exception declaration.
2471 ///
2472 /// By default, performs semantic analysis to build the new decaration.
2473 /// Subclasses may override this routine to provide different behavior.
2476 SourceLocation StartLoc,
2477 SourceLocation IdLoc,
2478 IdentifierInfo *Id) {
2480 StartLoc, IdLoc, Id);
2481 if (Var)
2482 getSema().CurContext->addDecl(Var);
2483 return Var;
2484 }
2485
2486 /// Build a new C++ catch statement.
2487 ///
2488 /// By default, performs semantic analysis to build the new statement.
2489 /// Subclasses may override this routine to provide different behavior.
2491 VarDecl *ExceptionDecl,
2492 Stmt *Handler) {
2493 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2494 Handler));
2495 }
2496
2497 /// Build a new C++ try statement.
2498 ///
2499 /// By default, performs semantic analysis to build the new statement.
2500 /// Subclasses may override this routine to provide different behavior.
2502 ArrayRef<Stmt *> Handlers) {
2503 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2504 }
2505
2506 /// Build a new C++0x range-based for statement.
2507 ///
2508 /// By default, performs semantic analysis to build the new statement.
2509 /// Subclasses may override this routine to provide different behavior.
2511 SourceLocation CoawaitLoc, Stmt *Init,
2512 SourceLocation ColonLoc, Stmt *Range,
2513 Stmt *Begin, Stmt *End, Expr *Cond,
2514 Expr *Inc, Stmt *LoopVar,
2515 SourceLocation RParenLoc) {
2516 // If we've just learned that the range is actually an Objective-C
2517 // collection, treat this as an Objective-C fast enumeration loop.
2518 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2519 if (RangeStmt->isSingleDecl()) {
2520 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2521 if (RangeVar->isInvalidDecl())
2522 return StmtError();
2523
2524 Expr *RangeExpr = RangeVar->getInit();
2525 if (!RangeExpr->isTypeDependent() &&
2526 RangeExpr->getType()->isObjCObjectPointerType()) {
2527 // FIXME: Support init-statements in Objective-C++20 ranged for
2528 // statement.
2529 if (Init) {
2530 return SemaRef.Diag(Init->getBeginLoc(),
2531 diag::err_objc_for_range_init_stmt)
2532 << Init->getSourceRange();
2533 }
2534 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2535 RangeExpr, RParenLoc);
2536 }
2537 }
2538 }
2539 }
2540
2541 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2542 Range, Begin, End, Cond, Inc, LoopVar,
2543 RParenLoc, Sema::BFRK_Rebuild);
2544 }
2545
2546 /// Build a new C++0x range-based for statement.
2547 ///
2548 /// By default, performs semantic analysis to build the new statement.
2549 /// Subclasses may override this routine to provide different behavior.
2551 bool IsIfExists,
2552 NestedNameSpecifierLoc QualifierLoc,
2553 DeclarationNameInfo NameInfo,
2554 Stmt *Nested) {
2555 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2556 QualifierLoc, NameInfo, Nested);
2557 }
2558
2559 /// Attach body to a C++0x range-based for statement.
2560 ///
2561 /// By default, performs semantic analysis to finish the new statement.
2562 /// Subclasses may override this routine to provide different behavior.
2564 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2565 }
2566
2568 Stmt *TryBlock, Stmt *Handler) {
2569 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2570 }
2571
2573 Stmt *Block) {
2574 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2575 }
2576
2578 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2579 }
2580
2582 SourceLocation LParen,
2583 SourceLocation RParen,
2584 TypeSourceInfo *TSI) {
2585 return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI);
2586 }
2587
2588 /// Build a new predefined expression.
2589 ///
2590 /// By default, performs semantic analysis to build the new expression.
2591 /// Subclasses may override this routine to provide different behavior.
2594 return getSema().BuildPredefinedExpr(Loc, IK);
2595 }
2596
2597 /// Build a new expression that references a declaration.
2598 ///
2599 /// By default, performs semantic analysis to build the new expression.
2600 /// Subclasses may override this routine to provide different behavior.
2602 LookupResult &R,
2603 bool RequiresADL) {
2604 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2605 }
2606
2607
2608 /// Build a new expression that references a declaration.
2609 ///
2610 /// By default, performs semantic analysis to build the new expression.
2611 /// Subclasses may override this routine to provide different behavior.
2613 ValueDecl *VD,
2614 const DeclarationNameInfo &NameInfo,
2615 NamedDecl *Found,
2616 TemplateArgumentListInfo *TemplateArgs) {
2617 CXXScopeSpec SS;
2618 SS.Adopt(QualifierLoc);
2619 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2620 TemplateArgs);
2621 }
2622
2623 /// Build a new expression in parentheses.
2624 ///
2625 /// By default, performs semantic analysis to build the new expression.
2626 /// Subclasses may override this routine to provide different behavior.
2628 SourceLocation RParen) {
2629 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2630 }
2631
2632 /// Build a new pseudo-destructor expression.
2633 ///
2634 /// By default, performs semantic analysis to build the new expression.
2635 /// Subclasses may override this routine to provide different behavior.
2637 SourceLocation OperatorLoc,
2638 bool isArrow,
2639 CXXScopeSpec &SS,
2640 TypeSourceInfo *ScopeType,
2641 SourceLocation CCLoc,
2642 SourceLocation TildeLoc,
2643 PseudoDestructorTypeStorage Destroyed);
2644
2645 /// Build a new unary operator expression.
2646 ///
2647 /// By default, performs semantic analysis to build the new expression.
2648 /// Subclasses may override this routine to provide different behavior.
2651 Expr *SubExpr) {
2652 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2653 }
2654
2655 /// Build a new builtin offsetof expression.
2656 ///
2657 /// By default, performs semantic analysis to build the new expression.
2658 /// Subclasses may override this routine to provide different behavior.
2662 SourceLocation RParenLoc) {
2663 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2664 RParenLoc);
2665 }
2666
2667 /// Build a new sizeof, alignof or vec_step expression with a
2668 /// type argument.
2669 ///
2670 /// By default, performs semantic analysis to build the new expression.
2671 /// Subclasses may override this routine to provide different behavior.
2673 SourceLocation OpLoc,
2674 UnaryExprOrTypeTrait ExprKind,
2675 SourceRange R) {
2676 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2677 }
2678
2679 /// Build a new sizeof, alignof or vec step expression with an
2680 /// expression argument.
2681 ///
2682 /// By default, performs semantic analysis to build the new expression.
2683 /// Subclasses may override this routine to provide different behavior.
2685 UnaryExprOrTypeTrait ExprKind,
2686 SourceRange R) {
2688 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2689 if (Result.isInvalid())
2690 return ExprError();
2691
2692 return Result;
2693 }
2694
2695 /// Build a new array subscript expression.
2696 ///
2697 /// By default, performs semantic analysis to build the new expression.
2698 /// Subclasses may override this routine to provide different behavior.
2700 SourceLocation LBracketLoc,
2701 Expr *RHS,
2702 SourceLocation RBracketLoc) {
2703 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2704 LBracketLoc, RHS,
2705 RBracketLoc);
2706 }
2707
2708 /// Build a new matrix subscript expression.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2713 Expr *ColumnIdx,
2714 SourceLocation RBracketLoc) {
2715 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2716 RBracketLoc);
2717 }
2718
2719 /// Build a new array section expression.
2720 ///
2721 /// By default, performs semantic analysis to build the new expression.
2722 /// Subclasses may override this routine to provide different behavior.
2724 Expr *LowerBound,
2725 SourceLocation ColonLocFirst,
2726 SourceLocation ColonLocSecond,
2727 Expr *Length, Expr *Stride,
2728 SourceLocation RBracketLoc) {
2729 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2730 ColonLocFirst, ColonLocSecond,
2731 Length, Stride, RBracketLoc);
2732 }
2733
2734 /// Build a new array shaping expression.
2735 ///
2736 /// By default, performs semantic analysis to build the new expression.
2737 /// Subclasses may override this routine to provide different behavior.
2739 SourceLocation RParenLoc,
2740 ArrayRef<Expr *> Dims,
2741 ArrayRef<SourceRange> BracketsRanges) {
2742 return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims,
2743 BracketsRanges);
2744 }
2745
2746 /// Build a new iterator expression.
2747 ///
2748 /// By default, performs semantic analysis to build the new expression.
2749 /// Subclasses may override this routine to provide different behavior.
2751 SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc,
2753 return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc,
2754 LLoc, RLoc, Data);
2755 }
2756
2757 /// Build a new call expression.
2758 ///
2759 /// By default, performs semantic analysis to build the new expression.
2760 /// Subclasses may override this routine to provide different behavior.
2762 MultiExprArg Args,
2763 SourceLocation RParenLoc,
2764 Expr *ExecConfig = nullptr) {
2765 return getSema().ActOnCallExpr(
2766 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2767 }
2768
2770 MultiExprArg Args,
2771 SourceLocation RParenLoc) {
2773 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2774 }
2775
2776 /// Build a new member access expression.
2777 ///
2778 /// By default, performs semantic analysis to build the new expression.
2779 /// Subclasses may override this routine to provide different behavior.
2781 bool isArrow,
2782 NestedNameSpecifierLoc QualifierLoc,
2783 SourceLocation TemplateKWLoc,
2784 const DeclarationNameInfo &MemberNameInfo,
2786 NamedDecl *FoundDecl,
2787 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2788 NamedDecl *FirstQualifierInScope) {
2790 isArrow);
2791 if (!Member->getDeclName()) {
2792 // We have a reference to an unnamed field. This is always the
2793 // base of an anonymous struct/union member access, i.e. the
2794 // field is always of record type.
2795 assert(Member->getType()->isRecordType() &&
2796 "unnamed member not of record type?");
2797
2798 BaseResult =
2800 QualifierLoc.getNestedNameSpecifier(),
2801 FoundDecl, Member);
2802 if (BaseResult.isInvalid())
2803 return ExprError();
2804 Base = BaseResult.get();
2805
2806 CXXScopeSpec EmptySS;
2808 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2809 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
2810 }
2811
2812 CXXScopeSpec SS;
2813 SS.Adopt(QualifierLoc);
2814
2815 Base = BaseResult.get();
2816 QualType BaseType = Base->getType();
2817
2818 if (isArrow && !BaseType->isPointerType())
2819 return ExprError();
2820
2821 // FIXME: this involves duplicating earlier analysis in a lot of
2822 // cases; we should avoid this when possible.
2823 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2824 R.addDecl(FoundDecl);
2825 R.resolveKind();
2826
2827 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2828 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2829 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2830 ->getType()
2831 ->getPointeeType()
2832 ->getAsCXXRecordDecl()) {
2833 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2834 // In unevaluated contexts, an expression supposed to be a member access
2835 // might reference a member in an unrelated class.
2836 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2837 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2838 VK_LValue, Member->getLocation());
2839 }
2840 }
2841
2842 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2843 SS, TemplateKWLoc,
2844 FirstQualifierInScope,
2845 R, ExplicitTemplateArgs,
2846 /*S*/nullptr);
2847 }
2848
2849 /// Build a new binary operator expression.
2850 ///
2851 /// By default, performs semantic analysis to build the new expression.
2852 /// Subclasses may override this routine to provide different behavior.
2855 Expr *LHS, Expr *RHS) {
2856 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2857 }
2858
2859 /// Build a new rewritten operator expression.
2860 ///
2861 /// By default, performs semantic analysis to build the new expression.
2862 /// Subclasses may override this routine to provide different behavior.
2864 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2865 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2866 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2867 RHS, /*RequiresADL*/false);
2868 }
2869
2870 /// Build a new conditional operator expression.
2871 ///
2872 /// By default, performs semantic analysis to build the new expression.
2873 /// Subclasses may override this routine to provide different behavior.
2875 SourceLocation QuestionLoc,
2876 Expr *LHS,
2877 SourceLocation ColonLoc,
2878 Expr *RHS) {
2879 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2880 LHS, RHS);
2881 }
2882
2883 /// Build a new C-style cast expression.
2884 ///
2885 /// By default, performs semantic analysis to build the new expression.
2886 /// Subclasses may override this routine to provide different behavior.
2888 TypeSourceInfo *TInfo,
2889 SourceLocation RParenLoc,
2890 Expr *SubExpr) {
2891 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2892 SubExpr);
2893 }
2894
2895 /// Build a new compound literal expression.
2896 ///
2897 /// By default, performs semantic analysis to build the new expression.
2898 /// Subclasses may override this routine to provide different behavior.
2900 TypeSourceInfo *TInfo,
2901 SourceLocation RParenLoc,
2902 Expr *Init) {
2903 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2904 Init);
2905 }
2906
2907 /// Build a new extended vector element access expression.
2908 ///
2909 /// By default, performs semantic analysis to build the new expression.
2910 /// Subclasses may override this routine to provide different behavior.
2912 bool IsArrow,
2913 SourceLocation AccessorLoc,
2914 IdentifierInfo &Accessor) {
2915
2916 CXXScopeSpec SS;
2917 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2919 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
2920 /*FirstQualifierInScope*/ nullptr, NameInfo,
2921 /* TemplateArgs */ nullptr,
2922 /*S*/ nullptr);
2923 }
2924
2925 /// Build a new initializer list expression.
2926 ///
2927 /// By default, performs semantic analysis to build the new expression.
2928 /// Subclasses may override this routine to provide different behavior.
2930 MultiExprArg Inits,
2931 SourceLocation RBraceLoc) {
2932 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
2933 }
2934
2935 /// Build a new designated initializer expression.
2936 ///
2937 /// By default, performs semantic analysis to build the new expression.
2938 /// Subclasses may override this routine to provide different behavior.
2940 MultiExprArg ArrayExprs,
2941 SourceLocation EqualOrColonLoc,
2942 bool GNUSyntax,
2943 Expr *Init) {
2945 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2946 Init);
2947 if (Result.isInvalid())
2948 return ExprError();
2949
2950 return Result;
2951 }
2952
2953 /// Build a new value-initialized expression.
2954 ///
2955 /// By default, builds the implicit value initialization without performing
2956 /// any semantic analysis. Subclasses may override this routine to provide
2957 /// different behavior.
2959 return new (SemaRef.Context) ImplicitValueInitExpr(T);
2960 }
2961
2962 /// Build a new \c va_arg expression.
2963 ///
2964 /// By default, performs semantic analysis to build the new expression.
2965 /// Subclasses may override this routine to provide different behavior.
2967 Expr *SubExpr, TypeSourceInfo *TInfo,
2968 SourceLocation RParenLoc) {
2969 return getSema().BuildVAArgExpr(BuiltinLoc,
2970 SubExpr, TInfo,
2971 RParenLoc);
2972 }
2973
2974 /// Build a new expression list in parentheses.
2975 ///
2976 /// By default, performs semantic analysis to build the new expression.
2977 /// Subclasses may override this routine to provide different behavior.
2979 MultiExprArg SubExprs,
2980 SourceLocation RParenLoc) {
2981 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
2982 }
2983
2984 /// Build a new address-of-label expression.
2985 ///
2986 /// By default, performs semantic analysis, using the name of the label
2987 /// rather than attempting to map the label statement itself.
2988 /// Subclasses may override this routine to provide different behavior.
2990 SourceLocation LabelLoc, LabelDecl *Label) {
2991 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
2992 }
2993
2994 /// Build a new GNU statement expression.
2995 ///
2996 /// By default, performs semantic analysis to build the new expression.
2997 /// Subclasses may override this routine to provide different behavior.
2999 SourceLocation RParenLoc, unsigned TemplateDepth) {
3000 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3001 TemplateDepth);
3002 }
3003
3004 /// Build a new __builtin_choose_expr expression.
3005 ///
3006 /// By default, performs semantic analysis to build the new expression.
3007 /// Subclasses may override this routine to provide different behavior.
3009 Expr *Cond, Expr *LHS, Expr *RHS,
3010 SourceLocation RParenLoc) {
3011 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3012 Cond, LHS, RHS,
3013 RParenLoc);
3014 }
3015
3016 /// Build a new generic selection expression.
3017 ///
3018 /// By default, performs semantic analysis to build the new expression.
3019 /// Subclasses may override this routine to provide different behavior.
3021 SourceLocation DefaultLoc,
3022 SourceLocation RParenLoc,
3023 Expr *ControllingExpr,
3025 ArrayRef<Expr *> Exprs) {
3026 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3027 ControllingExpr, Types, Exprs);
3028 }
3029
3030 /// Build a new overloaded operator call expression.
3031 ///
3032 /// By default, performs semantic analysis to build the new expression.
3033 /// The semantic analysis provides the behavior of template instantiation,
3034 /// copying with transformations that turn what looks like an overloaded
3035 /// operator call into a use of a builtin operator, performing
3036 /// argument-dependent lookup, etc. Subclasses may override this routine to
3037 /// provide different behavior.
3039 SourceLocation OpLoc,
3040 Expr *Callee,
3041 Expr *First,
3042 Expr *Second);
3043
3044 /// Build a new C++ "named" cast expression, such as static_cast or
3045 /// reinterpret_cast.
3046 ///
3047 /// By default, this routine dispatches to one of the more-specific routines
3048 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3049 /// Subclasses may override this routine to provide different behavior.
3051 Stmt::StmtClass Class,
3052 SourceLocation LAngleLoc,
3053 TypeSourceInfo *TInfo,
3054 SourceLocation RAngleLoc,
3055 SourceLocation LParenLoc,
3056 Expr *SubExpr,
3057 SourceLocation RParenLoc) {
3058 switch (Class) {
3059 case Stmt::CXXStaticCastExprClass:
3060 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3061 RAngleLoc, LParenLoc,
3062 SubExpr, RParenLoc);
3063
3064 case Stmt::CXXDynamicCastExprClass:
3065 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3066 RAngleLoc, LParenLoc,
3067 SubExpr, RParenLoc);
3068
3069 case Stmt::CXXReinterpretCastExprClass:
3070 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3071 RAngleLoc, LParenLoc,
3072 SubExpr,
3073 RParenLoc);
3074
3075 case Stmt::CXXConstCastExprClass:
3076 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3077 RAngleLoc, LParenLoc,
3078 SubExpr, RParenLoc);
3079
3080 case Stmt::CXXAddrspaceCastExprClass:
3081 return getDerived().RebuildCXXAddrspaceCastExpr(
3082 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3083
3084 default:
3085 llvm_unreachable("Invalid C++ named cast");
3086 }
3087 }
3088
3089 /// Build a new C++ static_cast expression.
3090 ///
3091 /// By default, performs semantic analysis to build the new expression.
3092 /// Subclasses may override this routine to provide different behavior.
3094 SourceLocation LAngleLoc,
3095 TypeSourceInfo *TInfo,
3096 SourceLocation RAngleLoc,
3097 SourceLocation LParenLoc,
3098 Expr *SubExpr,
3099 SourceLocation RParenLoc) {
3100 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3101 TInfo, SubExpr,
3102 SourceRange(LAngleLoc, RAngleLoc),
3103 SourceRange(LParenLoc, RParenLoc));
3104 }
3105
3106 /// Build a new C++ dynamic_cast expression.
3107 ///
3108 /// By default, performs semantic analysis to build the new expression.
3109 /// Subclasses may override this routine to provide different behavior.
3111 SourceLocation LAngleLoc,
3112 TypeSourceInfo *TInfo,
3113 SourceLocation RAngleLoc,
3114 SourceLocation LParenLoc,
3115 Expr *SubExpr,
3116 SourceLocation RParenLoc) {
3117 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3118 TInfo, SubExpr,
3119 SourceRange(LAngleLoc, RAngleLoc),
3120 SourceRange(LParenLoc, RParenLoc));
3121 }
3122
3123 /// Build a new C++ reinterpret_cast expression.
3124 ///
3125 /// By default, performs semantic analysis to build the new expression.
3126 /// Subclasses may override this routine to provide different behavior.
3128 SourceLocation LAngleLoc,
3129 TypeSourceInfo *TInfo,
3130 SourceLocation RAngleLoc,
3131 SourceLocation LParenLoc,
3132 Expr *SubExpr,
3133 SourceLocation RParenLoc) {
3134 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3135 TInfo, SubExpr,
3136 SourceRange(LAngleLoc, RAngleLoc),
3137 SourceRange(LParenLoc, RParenLoc));
3138 }
3139
3140 /// Build a new C++ const_cast expression.
3141 ///
3142 /// By default, performs semantic analysis to build the new expression.
3143 /// Subclasses may override this routine to provide different behavior.
3145 SourceLocation LAngleLoc,
3146 TypeSourceInfo *TInfo,
3147 SourceLocation RAngleLoc,
3148 SourceLocation LParenLoc,
3149 Expr *SubExpr,
3150 SourceLocation RParenLoc) {
3151 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3152 TInfo, SubExpr,
3153 SourceRange(LAngleLoc, RAngleLoc),
3154 SourceRange(LParenLoc, RParenLoc));
3155 }
3156
3159 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3160 SourceLocation LParenLoc, Expr *SubExpr,
3161 SourceLocation RParenLoc) {
3162 return getSema().BuildCXXNamedCast(
3163 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3164 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3165 }
3166
3167 /// Build a new C++ functional-style cast expression.
3168 ///
3169 /// By default, performs semantic analysis to build the new expression.
3170 /// Subclasses may override this routine to provide different behavior.
3172 SourceLocation LParenLoc,
3173 Expr *Sub,
3174 SourceLocation RParenLoc,
3175 bool ListInitialization) {
3176 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3177 MultiExprArg(&Sub, 1), RParenLoc,
3178 ListInitialization);
3179 }
3180
3181 /// Build a new C++ __builtin_bit_cast expression.
3182 ///
3183 /// By default, performs semantic analysis to build the new expression.
3184 /// Subclasses may override this routine to provide different behavior.
3186 TypeSourceInfo *TSI, Expr *Sub,
3187 SourceLocation RParenLoc) {
3188 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3189 }
3190
3191 /// Build a new C++ typeid(type) expression.
3192 ///
3193 /// By default, performs semantic analysis to build the new expression.
3194 /// Subclasses may override this routine to provide different behavior.
3196 SourceLocation TypeidLoc,
3197 TypeSourceInfo *Operand,
3198 SourceLocation RParenLoc) {
3199 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3200 RParenLoc);
3201 }
3202
3203
3204 /// Build a new C++ typeid(expr) expression.
3205 ///
3206 /// By default, performs semantic analysis to build the new expression.
3207 /// Subclasses may override this routine to provide different behavior.
3209 SourceLocation TypeidLoc,
3210 Expr *Operand,
3211 SourceLocation RParenLoc) {
3212 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3213 RParenLoc);
3214 }
3215
3216 /// Build a new C++ __uuidof(type) expression.
3217 ///
3218 /// By default, performs semantic analysis to build the new expression.
3219 /// Subclasses may override this routine to provide different behavior.
3221 TypeSourceInfo *Operand,
3222 SourceLocation RParenLoc) {
3223 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3224 }
3225
3226 /// Build a new C++ __uuidof(expr) expression.
3227 ///
3228 /// By default, performs semantic analysis to build the new expression.
3229 /// Subclasses may override this routine to provide different behavior.
3231 Expr *Operand, SourceLocation RParenLoc) {
3232 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3233 }
3234
3235 /// Build a new C++ "this" expression.
3236 ///
3237 /// By default, builds a new "this" expression without performing any
3238 /// semantic analysis. Subclasses may override this routine to provide
3239 /// different behavior.
3241 QualType ThisType,
3242 bool isImplicit) {
3243 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3244 }
3245
3246 /// Build a new C++ throw expression.
3247 ///
3248 /// By default, performs semantic analysis to build the new expression.
3249 /// Subclasses may override this routine to provide different behavior.
3251 bool IsThrownVariableInScope) {
3252 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3253 }
3254
3255 /// Build a new C++ default-argument expression.
3256 ///
3257 /// By default, builds a new default-argument expression, which does not
3258 /// require any semantic analysis. Subclasses may override this routine to
3259 /// provide different behavior.
3261 Expr *RewrittenExpr) {
3262 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3263 RewrittenExpr, getSema().CurContext);
3264 }
3265
3266 /// Build a new C++11 default-initialization expression.
3267 ///
3268 /// By default, builds a new default field initialization expression, which
3269 /// does not require any semantic analysis. Subclasses may override this
3270 /// routine to provide different behavior.
3272 FieldDecl *Field) {
3273 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3274 }
3275
3276 /// Build a new C++ zero-initialization expression.
3277 ///
3278 /// By default, performs semantic analysis to build the new expression.
3279 /// Subclasses may override this routine to provide different behavior.
3281 SourceLocation LParenLoc,
3282 SourceLocation RParenLoc) {
3283 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, std::nullopt,
3284 RParenLoc,
3285 /*ListInitialization=*/false);
3286 }
3287
3288 /// Build a new C++ "new" expression.
3289 ///
3290 /// By default, performs semantic analysis to build the new expression.
3291 /// Subclasses may override this routine to provide different behavior.
3293 SourceLocation PlacementLParen,
3294 MultiExprArg PlacementArgs,
3295 SourceLocation PlacementRParen,
3296 SourceRange TypeIdParens, QualType AllocatedType,
3297 TypeSourceInfo *AllocatedTypeInfo,
3298 std::optional<Expr *> ArraySize,
3299 SourceRange DirectInitRange, Expr *Initializer) {
3300 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3301 PlacementLParen,
3302 PlacementArgs,
3303 PlacementRParen,
3304 TypeIdParens,
3305 AllocatedType,
3306 AllocatedTypeInfo,
3307 ArraySize,
3308 DirectInitRange,
3309 Initializer);
3310 }
3311
3312 /// Build a new C++ "delete" expression.
3313 ///
3314 /// By default, performs semantic analysis to build the new expression.
3315 /// Subclasses may override this routine to provide different behavior.
3317 bool IsGlobalDelete,
3318 bool IsArrayForm,
3319 Expr *Operand) {
3320 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3321 Operand);
3322 }
3323
3324 /// Build a new type trait expression.
3325 ///
3326 /// By default, performs semantic analysis to build the new expression.
3327 /// Subclasses may override this routine to provide different behavior.
3329 SourceLocation StartLoc,
3331 SourceLocation RParenLoc) {
3332 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3333 }
3334
3335 /// Build a new array type trait expression.
3336 ///
3337 /// By default, performs semantic analysis to build the new expression.
3338 /// Subclasses may override this routine to provide different behavior.
3340 SourceLocation StartLoc,
3341 TypeSourceInfo *TSInfo,
3342 Expr *DimExpr,
3343 SourceLocation RParenLoc) {
3344 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3345 }
3346
3347 /// Build a new expression trait expression.
3348 ///
3349 /// By default, performs semantic analysis to build the new expression.
3350 /// Subclasses may override this routine to provide different behavior.
3352 SourceLocation StartLoc,
3353 Expr *Queried,
3354 SourceLocation RParenLoc) {
3355 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3356 }
3357
3358 /// Build a new (previously unresolved) declaration reference
3359 /// expression.
3360 ///
3361 /// By default, performs semantic analysis to build the new expression.
3362 /// Subclasses may override this routine to provide different behavior.
3364 NestedNameSpecifierLoc QualifierLoc,
3365 SourceLocation TemplateKWLoc,
3366 const DeclarationNameInfo &NameInfo,
3367 const TemplateArgumentListInfo *TemplateArgs,
3368 bool IsAddressOfOperand,
3369 TypeSourceInfo **RecoveryTSI) {
3370 CXXScopeSpec SS;
3371 SS.Adopt(QualifierLoc);
3372
3373 if (TemplateArgs || TemplateKWLoc.isValid())
3374 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
3375 TemplateArgs);
3376
3378 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
3379 }
3380
3381 /// Build a new template-id expression.
3382 ///
3383 /// By default, performs semantic analysis to build the new expression.
3384 /// Subclasses may override this routine to provide different behavior.
3386 SourceLocation TemplateKWLoc,
3387 LookupResult &R,
3388 bool RequiresADL,
3389 const TemplateArgumentListInfo *TemplateArgs) {
3390 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3391 TemplateArgs);
3392 }
3393
3394 /// Build a new object-construction expression.
3395 ///
3396 /// By default, performs semantic analysis to build the new expression.
3397 /// Subclasses may override this routine to provide different behavior.
3399 SourceLocation Loc,
3400 CXXConstructorDecl *Constructor,
3401 bool IsElidable,
3402 MultiExprArg Args,
3403 bool HadMultipleCandidates,
3404 bool ListInitialization,
3405 bool StdInitListInitialization,
3406 bool RequiresZeroInit,
3408 SourceRange ParenRange) {
3409 // Reconstruct the constructor we originally found, which might be
3410 // different if this is a call to an inherited constructor.
3411 CXXConstructorDecl *FoundCtor = Constructor;
3412 if (Constructor->isInheritingConstructor())
3413 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3414
3415 SmallVector<Expr *, 8> ConvertedArgs;
3416 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3417 ConvertedArgs))
3418 return ExprError();
3419
3420 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3421 IsElidable,
3422 ConvertedArgs,
3423 HadMultipleCandidates,
3424 ListInitialization,
3425 StdInitListInitialization,
3426 RequiresZeroInit, ConstructKind,
3427 ParenRange);
3428 }
3429
3430 /// Build a new implicit construction via inherited constructor
3431 /// expression.
3433 CXXConstructorDecl *Constructor,
3434 bool ConstructsVBase,
3435 bool InheritedFromVBase) {
3437 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3438 }
3439
3440 /// Build a new object-construction expression.
3441 ///
3442 /// By default, performs semantic analysis to build the new expression.
3443 /// Subclasses may override this routine to provide different behavior.
3445 SourceLocation LParenOrBraceLoc,
3446 MultiExprArg Args,
3447 SourceLocation RParenOrBraceLoc,
3448 bool ListInitialization) {
3450 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3451 }
3452
3453 /// Build a new object-construction expression.
3454 ///
3455 /// By default, performs semantic analysis to build the new expression.
3456 /// Subclasses may override this routine to provide different behavior.
3458 SourceLocation LParenLoc,
3459 MultiExprArg Args,
3460 SourceLocation RParenLoc,
3461 bool ListInitialization) {
3462 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3463 RParenLoc, ListInitialization);
3464 }
3465
3466 /// Build a new member reference expression.
3467 ///
3468 /// By default, performs semantic analysis to build the new expression.
3469 /// Subclasses may override this routine to provide different behavior.
3471 QualType BaseType,
3472 bool IsArrow,
3473 SourceLocation OperatorLoc,
3474 NestedNameSpecifierLoc QualifierLoc,
3475 SourceLocation TemplateKWLoc,
3476 NamedDecl *FirstQualifierInScope,
3477 const DeclarationNameInfo &MemberNameInfo,
3478 const TemplateArgumentListInfo *TemplateArgs) {
3479 CXXScopeSpec SS;
3480 SS.Adopt(QualifierLoc);
3481
3482 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3483 OperatorLoc, IsArrow,
3484 SS, TemplateKWLoc,
3485 FirstQualifierInScope,
3486 MemberNameInfo,
3487 TemplateArgs, /*S*/nullptr);
3488 }
3489
3490 /// Build a new member reference expression.
3491 ///
3492 /// By default, performs semantic analysis to build the new expression.
3493 /// Subclasses may override this routine to provide different behavior.
3495 SourceLocation OperatorLoc,
3496 bool IsArrow,
3497 NestedNameSpecifierLoc QualifierLoc,
3498 SourceLocation TemplateKWLoc,
3499 NamedDecl *FirstQualifierInScope,
3500 LookupResult &R,
3501 const TemplateArgumentListInfo *TemplateArgs) {
3502 CXXScopeSpec SS;
3503 SS.Adopt(QualifierLoc);
3504
3505 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3506 OperatorLoc, IsArrow,
3507 SS, TemplateKWLoc,
3508 FirstQualifierInScope,
3509 R, TemplateArgs, /*S*/nullptr);
3510 }
3511
3512 /// Build a new noexcept expression.
3513 ///
3514 /// By default, performs semantic analysis to build the new expression.
3515 /// Subclasses may override this routine to provide different behavior.
3517 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3518 }
3519
3520 /// Build a new expression to compute the length of a parameter pack.
3522 SourceLocation PackLoc,
3523 SourceLocation RParenLoc,
3524 std::optional<unsigned> Length,
3525 ArrayRef<TemplateArgument> PartialArgs) {
3526 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3527 RParenLoc, Length, PartialArgs);
3528 }
3529
3530 /// Build a new expression representing a call to a source location
3531 /// builtin.
3532 ///
3533 /// By default, performs semantic analysis to build the new expression.
3534 /// Subclasses may override this routine to provide different behavior.
3536 QualType ResultTy, SourceLocation BuiltinLoc,
3537 SourceLocation RPLoc,
3538 DeclContext *ParentContext) {
3539 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3540 ParentContext);
3541 }
3542
3543 /// Build a new Objective-C boxed expression.
3544 ///
3545 /// By default, performs semantic analysis to build the new expression.
3546 /// Subclasses may override this routine to provide different behavior.
3548 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3549 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3551 CXXScopeSpec SS;
3552 SS.Adopt(NNS);
3553 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3554 ConceptNameInfo,
3555 FoundDecl,
3556 NamedConcept, TALI);
3557 if (Result.isInvalid())
3558 return ExprError();
3559 return Result;
3560 }
3561
3562 /// \brief Build a new requires expression.
3563 ///
3564 /// By default, performs semantic analysis to build the new expression.
3565 /// Subclasses may override this routine to provide different behavior.
3568 ArrayRef<ParmVarDecl *> LocalParameters,
3570 SourceLocation ClosingBraceLoc) {
3571 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body,
3572 LocalParameters, Requirements, ClosingBraceLoc);
3573 }
3574
3578 return SemaRef.BuildTypeRequirement(SubstDiag);
3579 }
3580
3582 return SemaRef.BuildTypeRequirement(T);
3583 }
3584
3587 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3588 SourceLocation NoexceptLoc,
3590 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3591 std::move(Ret));
3592 }
3593
3595 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3597 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3598 std::move(Ret));
3599 }
3600
3602 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3603 const ASTConstraintSatisfaction &Satisfaction) {
3604 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3605 Satisfaction);
3606 }
3607
3609 return SemaRef.BuildNestedRequirement(Constraint);
3610 }
3611
3612 /// \brief Build a new Objective-C boxed expression.
3613 ///
3614 /// By default, performs semantic analysis to build the new expression.
3615 /// Subclasses may override this routine to provide different behavior.
3617 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3618 }
3619
3620 /// Build a new Objective-C array literal.
3621 ///
3622 /// By default, performs semantic analysis to build the new expression.
3623 /// Subclasses may override this routine to provide different behavior.
3625 Expr **Elements, unsigned NumElements) {
3626 return getSema().BuildObjCArrayLiteral(Range,
3627 MultiExprArg(Elements, NumElements));
3628 }
3629
3631 Expr *Base, Expr *Key,
3632 ObjCMethodDecl *getterMethod,
3633 ObjCMethodDecl *setterMethod) {
3634 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3635 getterMethod, setterMethod);
3636 }
3637
3638 /// Build a new Objective-C dictionary literal.
3639 ///
3640 /// By default, performs semantic analysis to build the new expression.
3641 /// Subclasses may override this routine to provide different behavior.
3644 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
3645 }
3646
3647 /// Build a new Objective-C \@encode expression.
3648 ///
3649 /// By default, performs semantic analysis to build the new expression.
3650 /// Subclasses may override this routine to provide different behavior.
3652 TypeSourceInfo *EncodeTypeInfo,
3653 SourceLocation RParenLoc) {
3654 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
3655 }
3656
3657 /// Build a new Objective-C class message.
3659 Selector Sel,
3660 ArrayRef<SourceLocation> SelectorLocs,
3661 ObjCMethodDecl *Method,
3662 SourceLocation LBracLoc,
3663 MultiExprArg Args,
3664 SourceLocation RBracLoc) {
3665 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3666 ReceiverTypeInfo->getType(),
3667 /*SuperLoc=*/SourceLocation(),
3668 Sel, Method, LBracLoc, SelectorLocs,
3669 RBracLoc, Args);
3670 }
3671
3672 /// Build a new Objective-C instance message.
3674 Selector Sel,
3675 ArrayRef<SourceLocation> SelectorLocs,
3676 ObjCMethodDecl *Method,
3677 SourceLocation LBracLoc,
3678 MultiExprArg Args,
3679 SourceLocation RBracLoc) {
3680 return SemaRef.BuildInstanceMessage(Receiver,
3681 Receiver->getType(),
3682 /*SuperLoc=*/SourceLocation(),
3683 Sel, Method, LBracLoc, SelectorLocs,
3684 RBracLoc, Args);
3685 }
3686
3687 /// Build a new Objective-C instance/class message to 'super'.
3689 Selector Sel,
3690 ArrayRef<SourceLocation> SelectorLocs,
3691 QualType SuperType,
3692 ObjCMethodDecl *Method,
3693 SourceLocation LBracLoc,
3694 MultiExprArg Args,
3695 SourceLocation RBracLoc) {
3696 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3697 SuperType,
3698 SuperLoc,
3699 Sel, Method, LBracLoc, SelectorLocs,
3700 RBracLoc, Args)
3701 : SemaRef.BuildClassMessage(nullptr,
3702 SuperType,
3703 SuperLoc,
3704 Sel, Method, LBracLoc, SelectorLocs,
3705 RBracLoc, Args);
3706
3707
3708 }
3709
3710 /// Build a new Objective-C ivar reference expression.
3711 ///
3712 /// By default, performs semantic analysis to build the new expression.
3713 /// Subclasses may override this routine to provide different behavior.
3715 SourceLocation IvarLoc,
3716 bool IsArrow, bool IsFreeIvar) {
3717 CXXScopeSpec SS;
3718 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3720 BaseArg, BaseArg->getType(),
3721 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3722 /*FirstQualifierInScope=*/nullptr, NameInfo,
3723 /*TemplateArgs=*/nullptr,
3724 /*S=*/nullptr);
3725 if (IsFreeIvar && Result.isUsable())
3726 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3727 return Result;
3728 }
3729
3730 /// Build a new Objective-C property reference expression.
3731 ///
3732 /// By default, performs semantic analysis to build the new expression.
3733 /// Subclasses may override this routine to provide different behavior.
3736 SourceLocation PropertyLoc) {
3737 CXXScopeSpec SS;
3738 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3739 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3740 /*FIXME:*/PropertyLoc,
3741 /*IsArrow=*/false,
3742 SS, SourceLocation(),
3743 /*FirstQualifierInScope=*/nullptr,
3744 NameInfo,
3745 /*TemplateArgs=*/nullptr,
3746 /*S=*/nullptr);
3747 }
3748
3749 /// Build a new Objective-C property reference expression.
3750 ///
3751 /// By default, performs semantic analysis to build the new expression.
3752 /// Subclasses may override this routine to provide different behavior.
3754 ObjCMethodDecl *Getter,
3755 ObjCMethodDecl *Setter,
3756 SourceLocation PropertyLoc) {
3757 // Since these expressions can only be value-dependent, we do not
3758 // need to perform semantic analysis again.
3759 return Owned(
3760 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3762 PropertyLoc, Base));
3763 }
3764
3765 /// Build a new Objective-C "isa" expression.
3766 ///
3767 /// By default, performs semantic analysis to build the new expression.
3768 /// Subclasses may override this routine to provide different behavior.
3770 SourceLocation OpLoc, bool IsArrow) {
3771 CXXScopeSpec SS;
3772 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3773 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3774 OpLoc, IsArrow,
3775 SS, SourceLocation(),
3776 /*FirstQualifierInScope=*/nullptr,
3777 NameInfo,
3778 /*TemplateArgs=*/nullptr,
3779 /*S=*/nullptr);
3780 }
3781
3782 /// Build a new shuffle vector expression.
3783 ///
3784 /// By default, performs semantic analysis to build the new expression.
3785 /// Subclasses may override this routine to provide different behavior.
3787 MultiExprArg SubExprs,
3788 SourceLocation RParenLoc) {
3789 // Find the declaration for __builtin_shufflevector
3790 const IdentifierInfo &Name
3791 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3793 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3794 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3795
3796 // Build a reference to the __builtin_shufflevector builtin
3797 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3798 Expr *Callee = new (SemaRef.Context)
3799 DeclRefExpr(SemaRef.Context, Builtin, false,
3800 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3801 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3802 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3803 CK_BuiltinFnToFnPtr).get();
3804
3805 // Build the CallExpr
3806 ExprResult TheCall = CallExpr::Create(
3807 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3808 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3810
3811 // Type-check the __builtin_shufflevector expression.
3812 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3813 }
3814
3815 /// Build a new convert vector expression.
3817 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3818 SourceLocation RParenLoc) {
3819 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3820 BuiltinLoc, RParenLoc);
3821 }
3822
3823 /// Build a new template argument pack expansion.
3824 ///
3825 /// By default, performs semantic analysis to build a new pack expansion
3826 /// for a template argument. Subclasses may override this routine to provide
3827 /// different behavior.
3830 std::optional<unsigned> NumExpansions) {
3831 switch (Pattern.getArgument().getKind()) {
3835 EllipsisLoc, NumExpansions);
3836 if (Result.isInvalid())
3837 return TemplateArgumentLoc();
3838
3839 return TemplateArgumentLoc(Result.get(), Result.get());
3840 }
3841
3843 return TemplateArgumentLoc(
3846 NumExpansions),
3847 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3848 EllipsisLoc);
3849
3856 llvm_unreachable("Pack expansion pattern has no parameter packs");
3857
3859 if (TypeSourceInfo *Expansion
3860 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3861 EllipsisLoc,
3862 NumExpansions))
3863 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3864 Expansion);
3865 break;
3866 }
3867
3868 return TemplateArgumentLoc();
3869 }
3870
3871 /// Build a new expression pack expansion.
3872 ///
3873 /// By default, performs semantic analysis to build a new pack expansion
3874 /// for an expression. Subclasses may override this routine to provide
3875 /// different behavior.
3877 std::optional<unsigned> NumExpansions) {
3878 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3879 }
3880
3881 /// Build a new C++1z fold-expression.
3882 ///
3883 /// By default, performs semantic analysis in order to build a new fold
3884 /// expression.
3886 SourceLocation LParenLoc, Expr *LHS,
3887 BinaryOperatorKind Operator,
3888 SourceLocation EllipsisLoc, Expr *RHS,
3889 SourceLocation RParenLoc,
3890 std::optional<unsigned> NumExpansions) {
3891 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
3892 EllipsisLoc, RHS, RParenLoc,
3893 NumExpansions);
3894 }
3895
3896 /// Build an empty C++1z fold-expression with the given operator.
3897 ///
3898 /// By default, produces the fallback value for the fold-expression, or
3899 /// produce an error if there is no fallback value.
3901 BinaryOperatorKind Operator) {
3902 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3903 }
3904
3906 unsigned NumUserSpecifiedExprs,
3907 SourceLocation InitLoc,
3908 SourceLocation LParenLoc,
3909 SourceLocation RParenLoc) {
3910 return CXXParenListInitExpr::Create(getSema().Context, Args, T,
3911 NumUserSpecifiedExprs, InitLoc,
3912 LParenLoc, RParenLoc);
3913 }
3914
3915 /// Build a new atomic operation expression.
3916 ///
3917 /// By default, performs semantic analysis to build the new expression.
3918 /// Subclasses may override this routine to provide different behavior.
3921 SourceLocation RParenLoc) {
3922 // Use this for all of the locations, since we don't know the difference
3923 // between the call and the expr at this point.
3924 SourceRange Range{BuiltinLoc, RParenLoc};
3925 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
3927 }
3928
3930 ArrayRef<Expr *> SubExprs, QualType Type) {
3931 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
3932 }
3933
3934private:
3935 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3936 QualType ObjectType,
3937 NamedDecl *FirstQualifierInScope,
3938 CXXScopeSpec &SS);
3939
3940 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3941 QualType ObjectType,
3942 NamedDecl *FirstQualifierInScope,
3943 CXXScopeSpec &SS);
3944
3945 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3946 NamedDecl *FirstQualifierInScope,
3947 CXXScopeSpec &SS);
3948
3949 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3951 bool DeducibleTSTContext);
3952};
3953
3954template <typename Derived>
3956 if (!S)
3957 return S;
3958
3959 switch (S->getStmtClass()) {
3960 case Stmt::NoStmtClass: break;
3961
3962 // Transform individual statement nodes
3963 // Pass SDK into statements that can produce a value
3964#define STMT(Node, Parent) \
3965 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
3966#define VALUESTMT(Node, Parent) \
3967 case Stmt::Node##Class: \
3968 return getDerived().Transform##Node(cast<Node>(S), SDK);
3969#define ABSTRACT_STMT(Node)
3970#define EXPR(Node, Parent)
3971#include "clang/AST/StmtNodes.inc"
3972
3973 // Transform expressions by calling TransformExpr.
3974#define STMT(Node, Parent)
3975#define ABSTRACT_STMT(Stmt)
3976#define EXPR(Node, Parent) case Stmt::Node##Class:
3977#include "clang/AST/StmtNodes.inc"
3978 {
3979 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
3980
3981 if (SDK == SDK_StmtExprResult)
3982 E = getSema().ActOnStmtExprResult(E);
3983 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
3984 }
3985 }
3986
3987 return S;
3988}
3989
3990template<typename Derived>
3992 if (!S)
3993 return S;
3994
3995 switch (S->getClauseKind()) {
3996 default: break;
3997 // Transform individual clause nodes
3998#define GEN_CLANG_CLAUSE_CLASS
3999#define CLAUSE_CLASS(Enum, Str, Class) \
4000 case Enum: \
4001 return getDerived().Transform##Class(cast<Class>(S));
4002#include "llvm/Frontend/OpenMP/OMP.inc"
4003 }
4004
4005 return S;
4006}
4007
4008
4009template<typename Derived>
4011 if (!E)
4012 return E;
4013
4014 switch (E->getStmtClass()) {
4015 case Stmt::NoStmtClass: break;
4016#define STMT(Node, Parent) case Stmt::Node##Class: break;
4017#define ABSTRACT_STMT(Stmt)
4018#define EXPR(Node, Parent) \
4019 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4020#include "clang/AST/StmtNodes.inc"
4021 }
4022
4023 return E;
4024}
4025
4026template<typename Derived>
4028 bool NotCopyInit) {
4029 // Initializers are instantiated like expressions, except that various outer
4030 // layers are stripped.
4031 if (!Init)
4032 return Init;
4033
4034 if (auto *FE = dyn_cast<FullExpr>(Init))
4035 Init = FE->getSubExpr();
4036
4037 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4038 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4039 Init = OVE->getSourceExpr();
4040 }
4041
4042 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4043 Init = MTE->getSubExpr();
4044
4045 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4046 Init = Binder->getSubExpr();
4047
4048 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4049 Init = ICE->getSubExprAsWritten();
4050
4051 if (CXXStdInitializerListExpr *ILE =
4052 dyn_cast<CXXStdInitializerListExpr>(Init))
4053 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4054
4055 // If this is copy-initialization, we only need to reconstruct
4056 // InitListExprs. Other forms of copy-initialization will be a no-op if
4057 // the initializer is already the right type.
4058 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4059 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4060 return getDerived().TransformExpr(Init);
4061
4062 // Revert value-initialization back to empty parens.
4063 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4064 SourceRange Parens = VIE->getSourceRange();
4065 return getDerived().RebuildParenListExpr(Parens.getBegin(), std::nullopt,
4066 Parens.getEnd());
4067 }
4068
4069 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4070 if (isa<ImplicitValueInitExpr>(Init))
4071 return getDerived().RebuildParenListExpr(SourceLocation(), std::nullopt,
4072 SourceLocation());
4073
4074 // Revert initialization by constructor back to a parenthesized or braced list
4075 // of expressions. Any other form of initializer can just be reused directly.
4076 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4077 return getDerived().TransformExpr(Init);
4078
4079 // If the initialization implicitly converted an initializer list to a
4080 // std::initializer_list object, unwrap the std::initializer_list too.
4081 if (Construct && Construct->isStdInitListInitialization())
4082 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4083
4084 // Enter a list-init context if this was list initialization.
4087 Construct->isListInitialization());
4088
4089 SmallVector<Expr*, 8> NewArgs;
4090 bool ArgChanged = false;
4091 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4092 /*IsCall*/true, NewArgs, &ArgChanged))
4093 return ExprError();
4094
4095 // If this was list initialization, revert to syntactic list form.
4096 if (Construct->isListInitialization())
4097 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4098 Construct->getEndLoc());
4099
4100 // Build a ParenListExpr to represent anything else.
4101 SourceRange Parens = Construct->getParenOrBraceRange();
4102 if (Parens.isInvalid()) {
4103 // This was a variable declaration's initialization for which no initializer
4104 // was specified.
4105 assert(NewArgs.empty() &&
4106 "no parens or braces but have direct init with arguments?");
4107 return ExprEmpty();
4108 }
4109 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4110 Parens.getEnd());
4111}
4112
4113template<typename Derived>
4115 unsigned NumInputs,
4116 bool IsCall,
4117 SmallVectorImpl<Expr *> &Outputs,
4118 bool *ArgChanged) {
4119 for (unsigned I = 0; I != NumInputs; ++I) {
4120 // If requested, drop call arguments that need to be dropped.
4121 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4122 if (ArgChanged)
4123 *ArgChanged = true;
4124
4125 break;
4126 }
4127
4128 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4129 Expr *Pattern = Expansion->getPattern();
4130
4132 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4133 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4134
4135 // Determine whether the set of unexpanded parameter packs can and should
4136 // be expanded.
4137 bool Expand = true;
4138 bool RetainExpansion = false;
4139 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4140 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4141 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4142 Pattern->getSourceRange(),
4143 Unexpanded,
4144 Expand, RetainExpansion,
4145 NumExpansions))
4146 return true;
4147
4148 if (!Expand) {
4149 // The transform has determined that we should perform a simple
4150 // transformation on the pack expansion, producing another pack
4151 // expansion.
4152 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4153 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4154 if (OutPattern.isInvalid())
4155 return true;
4156
4157 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4158 Expansion->getEllipsisLoc(),
4159 NumExpansions);
4160 if (Out.isInvalid())
4161 return true;
4162
4163 if (ArgChanged)
4164 *ArgChanged = true;
4165 Outputs.push_back(Out.get());
4166 continue;
4167 }
4168
4169 // Record right away that the argument was changed. This needs
4170 // to happen even if the array expands to nothing.
4171 if (ArgChanged) *ArgChanged = true;
4172
4173 // The transform has determined that we should perform an elementwise
4174 // expansion of the pattern. Do so.
4175 for (unsigned I = 0; I != *NumExpansions; ++I) {
4176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4177 ExprResult Out = getDerived().TransformExpr(Pattern);
4178 if (Out.isInvalid())
4179 return true;
4180
4181 if (Out.get()->containsUnexpandedParameterPack()) {
4182 Out = getDerived().RebuildPackExpansion(
4183 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4184 if (Out.isInvalid())
4185 return true;
4186 }
4187
4188 Outputs.push_back(Out.get());
4189 }
4190
4191 // If we're supposed to retain a pack expansion, do so by temporarily
4192 // forgetting the partially-substituted parameter pack.
4193 if (RetainExpansion) {
4194 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4195
4196 ExprResult Out = getDerived().TransformExpr(Pattern);
4197 if (Out.isInvalid())
4198 return true;
4199
4200 Out = getDerived().RebuildPackExpansion(
4201 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4202 if (Out.isInvalid())
4203 return true;
4204
4205 Outputs.push_back(Out.get());
4206 }
4207
4208 continue;
4209 }
4210
4212 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4213 : getDerived().TransformExpr(Inputs[I]);
4214 if (Result.isInvalid())
4215 return true;
4216
4217 if (Result.get() != Inputs[I] && ArgChanged)
4218 *ArgChanged = true;
4219
4220 Outputs.push_back(Result.get());
4221 }
4222
4223 return false;
4224}
4225
4226template <typename Derived>
4229 if (Var) {
4230 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4231 getDerived().TransformDefinition(Var->getLocation(), Var));
4232
4233 if (!ConditionVar)
4234 return Sema::ConditionError();
4235
4236 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4237 }
4238
4239 if (Expr) {
4240 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4241
4242 if (CondExpr.isInvalid())
4243 return Sema::ConditionError();
4244
4245 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4246 /*MissingOK=*/true);
4247 }
4248
4249 return Sema::ConditionResult();
4250}
4251
4252template <typename Derived>
4254 NestedNameSpecifierLoc NNS, QualType ObjectType,
4255 NamedDecl *FirstQualifierInScope) {
4257
4258 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4259 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4260 Qualifier = Qualifier.getPrefix())
4261 Qualifiers.push_back(Qualifier);
4262 };
4263 insertNNS(NNS);
4264
4265 CXXScopeSpec SS;
4266 while (!Qualifiers.empty()) {
4267 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4269
4270 switch (QNNS->getKind()) {
4274 ObjectType);
4275 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4276 SS, FirstQualifierInScope, false))
4277 return NestedNameSpecifierLoc();
4278 break;
4279 }
4280
4282 NamespaceDecl *NS =
4283 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4284 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4285 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4286 break;
4287 }
4288
4290 NamespaceAliasDecl *Alias =
4291 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4293 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4294 Q.getLocalEndLoc());
4295 break;
4296 }
4297
4299 // There is no meaningful transformation that one could perform on the
4300 // global scope.
4301 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4302 break;
4303
4305 CXXRecordDecl *RD =
4306 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4307 SourceLocation(), QNNS->getAsRecordDecl()));
4308 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4309 break;
4310 }
4311
4314 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4315 FirstQualifierInScope, SS);
4316
4317 if (!TL)
4318 return NestedNameSpecifierLoc();
4319
4320 QualType T = TL.getType();
4321 if (T->isDependentType() || T->isRecordType() ||
4322 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4323 if (T->isEnumeralType())
4324 SemaRef.Diag(TL.getBeginLoc(),
4325 diag::warn_cxx98_compat_enum_nested_name_spec);
4326
4327 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4328 SS.Adopt(ETL.getQualifierLoc());
4329 TL = ETL.getNamedTypeLoc();
4330 }
4331 SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL,
4332 Q.getLocalEndLoc());
4333 break;
4334 }
4335 // If the nested-name-specifier is an invalid type def, don't emit an
4336 // error because a previous error should have already been emitted.
4338 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4339 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4340 << T << SS.getRange();
4341 }
4342 return NestedNameSpecifierLoc();
4343 }
4344 }
4345
4346 // The qualifier-in-scope and object type only apply to the leftmost entity.
4347 FirstQualifierInScope = nullptr;
4348 ObjectType = QualType();
4349 }
4350
4351 // Don't rebuild the nested-name-specifier if we don't have to.
4352 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4353 !getDerived().AlwaysRebuild())
4354 return NNS;
4355
4356 // If we can re-use the source-location data from the original
4357 // nested-name-specifier, do so.
4358 if (SS.location_size() == NNS.getDataLength() &&
4359 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4361
4362 // Allocate new nested-name-specifier location information.
4363 return SS.getWithLocInContext(SemaRef.Context);
4364}
4365
4366template<typename Derived>
4370 DeclarationName Name = NameInfo.getName();
4371 if (!Name)
4372 return DeclarationNameInfo();
4373
4374 switch (Name.getNameKind()) {
4382 return NameInfo;
4383
4385 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4386 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4387 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4388 if (!NewTemplate)
4389 return DeclarationNameInfo();
4390
4391 DeclarationNameInfo NewNameInfo(NameInfo);
4392 NewNameInfo.setName(
4394 return NewNameInfo;
4395 }
4396
4400 TypeSourceInfo *NewTInfo;
4401 CanQualType NewCanTy;
4402 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4403 NewTInfo = getDerived().TransformType(OldTInfo);
4404 if (!NewTInfo)
4405 return DeclarationNameInfo();
4406 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4407 }
4408 else {
4409 NewTInfo = nullptr;
4410 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4411 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4412 if (NewT.isNull())
4413 return DeclarationNameInfo();
4414 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4415 }
4416
4417 DeclarationName NewName
4418 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4419 NewCanTy);
4420 DeclarationNameInfo NewNameInfo(NameInfo);
4421 NewNameInfo.setName(NewName);
4422 NewNameInfo.setNamedTypeInfo(NewTInfo);
4423 return NewNameInfo;
4424 }
4425 }
4426
4427 llvm_unreachable("Unknown name kind.");
4428}
4429
4430template<typename Derived>
4433 TemplateName Name,
4434 SourceLocation NameLoc,
4435 QualType ObjectType,
4436 NamedDecl *FirstQualifierInScope,
4437 bool AllowInjectedClassName) {
4438 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4439 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4440 assert(Template && "qualified template name must refer to a template");
4441
4442 TemplateDecl *TransTemplate
4443 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4444 Template));
4445 if (!TransTemplate)
4446 return TemplateName();
4447
4448 if (!getDerived().AlwaysRebuild() &&
4449 SS.getScopeRep() == QTN->getQualifier() &&
4450 TransTemplate == Template)
4451 return Name;
4452
4453 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4454 TransTemplate);
4455 }
4456
4457 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4458 if (SS.getScopeRep()) {
4459 // These apply to the scope specifier, not the template.
4460 ObjectType = QualType();
4461 FirstQualifierInScope = nullptr;
4462 }
4463
4464 if (!getDerived().AlwaysRebuild() &&
4465 SS.getScopeRep() == DTN->getQualifier() &&
4466 ObjectType.isNull())
4467 return Name;
4468
4469 // FIXME: Preserve the location of the "template" keyword.
4470 SourceLocation TemplateKWLoc = NameLoc;
4471
4472 if (DTN->isIdentifier()) {
4473 return getDerived().RebuildTemplateName(SS,
4474 TemplateKWLoc,
4475 *DTN->getIdentifier(),
4476 NameLoc,
4477 ObjectType,
4478 FirstQualifierInScope,
4479 AllowInjectedClassName);
4480 }
4481
4482 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4483 DTN->getOperator(), NameLoc,
4484 ObjectType, AllowInjectedClassName);
4485 }
4486
4487 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4488 TemplateDecl *TransTemplate
4489 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4490 Template));
4491 if (!TransTemplate)
4492 return TemplateName();
4493
4494 if (!getDerived().AlwaysRebuild() &&
4495 TransTemplate == Template)
4496 return Name;
4497
4498 return TemplateName(TransTemplate);
4499 }
4500
4502 = Name.getAsSubstTemplateTemplateParmPack()) {
4503 return getDerived().RebuildTemplateName(
4504 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4505 SubstPack->getIndex(), SubstPack->getFinal());
4506 }
4507
4508 // These should be getting filtered out before they reach the AST.
4509 llvm_unreachable("overloaded function decl survived to here");
4510}
4511
4512template<typename Derived>
4514 const TemplateArgument &Arg,
4515 TemplateArgumentLoc &Output) {
4516 Output = getSema().getTrivialTemplateArgumentLoc(
4517 Arg, QualType(), getDerived().getBaseLocation());
4518}
4519
4520template <typename Derived>
4522 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4523 bool Uneval) {
4524 const TemplateArgument &Arg = Input.getArgument();
4525 switch (Arg.getKind()) {
4528 llvm_unreachable("Unexpected TemplateArgument");
4529
4533 // Transform a resolved template argument straight to a resolved template
4534 // argument. We get here when substituting into an already-substituted
4535 // template type argument during concept satisfaction checking.
4537 QualType NewT = getDerived().TransformType(T);
4538 if (NewT.isNull())
4539 return true;
4540
4542 ? Arg.getAsDecl()
4543 : nullptr;
4544 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4545 getDerived().getBaseLocation(), D))
4546 : nullptr;
4547 if (D && !NewD)
4548 return true;
4549
4550 if (NewT == T && D == NewD)
4551 Output = Input;
4552 else if (Arg.getKind() == TemplateArgument::Integral)
4553 Output = TemplateArgumentLoc(
4554 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4556 else if (Arg.getKind() == TemplateArgument::NullPtr)
4557 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4559 else
4560 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4562
4563 return false;
4564 }
4565
4567 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4568 if (!DI)
4569 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4570
4571 DI = getDerived().TransformType(DI);
4572 if (!DI)
4573 return true;
4574
4575 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4576 return false;
4577 }
4578
4580 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4581 if (QualifierLoc) {
4582 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4583 if (!QualifierLoc)
4584 return true;
4585 }
4586
4587 CXXScopeSpec SS;
4588 SS.Adopt(QualifierLoc);
4589 TemplateName Template = getDerived().TransformTemplateName(
4590 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4591 if (Template.isNull())
4592 return true;
4593
4594 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4595 QualifierLoc, Input.getTemplateNameLoc());
4596 return false;
4597 }
4598
4600 llvm_unreachable("Caller should expand pack expansions");
4601
4603 // Template argument expressions are constant expressions.
4605 getSema(),
4608 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4610
4611 Expr *InputExpr = Input.getSourceExpression();
4612 if (!InputExpr)
4613 InputExpr = Input.getArgument().getAsExpr();
4614
4615 ExprResult E = getDerived().TransformExpr(InputExpr);
4616 E = SemaRef.ActOnConstantExpression(E);
4617 if (E.isInvalid())
4618 return true;
4619 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4620 return false;
4621 }
4622 }
4623
4624 // Work around bogus GCC warning
4625 return true;
4626}
4627
4628/// Iterator adaptor that invents template argument location information
4629/// for each of the template arguments in its underlying iterator.
4630template<typename Derived, typename InputIterator>
4633 InputIterator Iter;
4634
4635public:
4638 typedef typename std::iterator_traits<InputIterator>::difference_type
4640 typedef std::input_iterator_tag iterator_category;
4641
4642 class pointer {
4644
4645 public:
4646 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4647
4648 const TemplateArgumentLoc *operator->() const { return &Arg; }
4649 };
4650
4652
4654 InputIterator Iter)
4655 : Self(Self), Iter(Iter) { }
4656
4658 ++Iter;
4659 return *this;
4660 }
4661
4664 ++(*this);
4665 return Old;
4666 }
4667
4670 Self.InventTemplateArgumentLoc(*Iter, Result);
4671 return Result;
4672 }
4673
4674 pointer operator->() const { return pointer(**this); }
4675
4678 return X.Iter == Y.Iter;
4679 }
4680
4683 return X.Iter != Y.Iter;
4684 }
4685};
4686
4687template<typename Derived>
4688template<typename InputIterator>
4690 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4691 bool Uneval) {
4692 for (; First != Last; ++First) {
4695
4697 // Unpack argument packs, which we translate them into separate
4698 // arguments.
4699 // FIXME: We could do much better if we could guarantee that the
4700 // TemplateArgumentLocInfo for the pack expansion would be usable for
4701 // all of the template arguments in the argument pack.
4702 typedef TemplateArgumentLocInventIterator<Derived,
4704 PackLocIterator;
4705 if (TransformTemplateArguments(PackLocIterator(*this,
4706 In.getArgument().pack_begin()),
4707 PackLocIterator(*this,
4708 In.getArgument().pack_end()),
4709 Outputs, Uneval))
4710 return true;
4711
4712 continue;
4713 }
4714
4715 if (In.getArgument().isPackExpansion()) {
4716 // We have a pack expansion, for which we will be substituting into
4717 // the pattern.
4718 SourceLocation Ellipsis;
4719 std::optional<unsigned> OrigNumExpansions;
4720 TemplateArgumentLoc Pattern
4721 = getSema().getTemplateArgumentPackExpansionPattern(
4722 In, Ellipsis, OrigNumExpansions);
4723
4725 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4726 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4727
4728 // Determine whether the set of unexpanded parameter packs can and should
4729 // be expanded.
4730 bool Expand = true;
4731 bool RetainExpansion = false;
4732 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4733 if (getDerived().TryExpandParameterPacks(Ellipsis,
4734 Pattern.getSourceRange(),
4735 Unexpanded,
4736 Expand,
4737 RetainExpansion,
4738 NumExpansions))
4739 return true;
4740
4741 if (!Expand) {
4742 // The transform has determined that we should perform a simple
4743 // transformation on the pack expansion, producing another pack
4744 // expansion.
4745 TemplateArgumentLoc OutPattern;
4746 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4747 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4748 return true;
4749
4750 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4751 NumExpansions);
4752 if (Out.getArgument().isNull())
4753 return true;
4754
4755 Outputs.addArgument(Out);
4756 continue;
4757 }
4758
4759 // The transform has determined that we should perform an elementwise
4760 // expansion of the pattern. Do so.
4761 for (unsigned I = 0; I != *NumExpansions; ++I) {
4762 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4763
4764 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4765 return true;
4766
4767 if (Out.getArgument().containsUnexpandedParameterPack()) {
4768 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4769 OrigNumExpansions);
4770 if (Out.getArgument().isNull())
4771 return