clang 20.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"
22#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"
32#include "clang/AST/StmtSYCL.h"
37#include "clang/Sema/Lookup.h"
43#include "clang/Sema/SemaObjC.h"
47#include "clang/Sema/SemaSYCL.h"
48#include "llvm/ADT/ArrayRef.h"
49#include "llvm/Support/ErrorHandling.h"
50#include <algorithm>
51#include <optional>
52
53using namespace llvm::omp;
54
55namespace clang {
56using namespace sema;
57
58/// A semantic tree transformation that allows one to transform one
59/// abstract syntax tree into another.
60///
61/// A new tree transformation is defined by creating a new subclass \c X of
62/// \c TreeTransform<X> and then overriding certain operations to provide
63/// behavior specific to that transformation. For example, template
64/// instantiation is implemented as a tree transformation where the
65/// transformation of TemplateTypeParmType nodes involves substituting the
66/// template arguments for their corresponding template parameters; a similar
67/// transformation is performed for non-type template parameters and
68/// template template parameters.
69///
70/// This tree-transformation template uses static polymorphism to allow
71/// subclasses to customize any of its operations. Thus, a subclass can
72/// override any of the transformation or rebuild operators by providing an
73/// operation with the same signature as the default implementation. The
74/// overriding function should not be virtual.
75///
76/// Semantic tree transformations are split into two stages, either of which
77/// can be replaced by a subclass. The "transform" step transforms an AST node
78/// or the parts of an AST node using the various transformation functions,
79/// then passes the pieces on to the "rebuild" step, which constructs a new AST
80/// node of the appropriate kind from the pieces. The default transformation
81/// routines recursively transform the operands to composite AST nodes (e.g.,
82/// the pointee type of a PointerType node) and, if any of those operand nodes
83/// were changed by the transformation, invokes the rebuild operation to create
84/// a new AST node.
85///
86/// Subclasses can customize the transformation at various levels. The
87/// most coarse-grained transformations involve replacing TransformType(),
88/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
89/// TransformTemplateName(), or TransformTemplateArgument() with entirely
90/// new implementations.
91///
92/// For more fine-grained transformations, subclasses can replace any of the
93/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
94/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
95/// replacing TransformTemplateTypeParmType() allows template instantiation
96/// to substitute template arguments for their corresponding template
97/// parameters. Additionally, subclasses can override the \c RebuildXXX
98/// functions to control how AST nodes are rebuilt when their operands change.
99/// By default, \c TreeTransform will invoke semantic analysis to rebuild
100/// AST nodes. However, certain other tree transformations (e.g, cloning) may
101/// be able to use more efficient rebuild steps.
102///
103/// There are a handful of other functions that can be overridden, allowing one
104/// to avoid traversing nodes that don't need any transformation
105/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
106/// operands have not changed (\c AlwaysRebuild()), and customize the
107/// default locations and entity names used for type-checking
108/// (\c getBaseLocation(), \c getBaseEntity()).
109template<typename Derived>
111 /// Private RAII object that helps us forget and then re-remember
112 /// the template argument corresponding to a partially-substituted parameter
113 /// pack.
114 class ForgetPartiallySubstitutedPackRAII {
115 Derived &Self;
117 // Set the pack expansion index to -1 to avoid pack substitution and
118 // indicate that parameter packs should be instantiated as themselves.
119 Sema::ArgumentPackSubstitutionIndexRAII ResetPackSubstIndex;
120
121 public:
122 ForgetPartiallySubstitutedPackRAII(Derived &Self)
123 : Self(Self), ResetPackSubstIndex(Self.getSema(), -1) {
124 Old = Self.ForgetPartiallySubstitutedPack();
125 }
126
127 ~ForgetPartiallySubstitutedPackRAII() {
128 Self.RememberPartiallySubstitutedPack(Old);
129 }
130 };
131
132protected:
134
135 /// The set of local declarations that have been transformed, for
136 /// cases where we are forced to build new declarations within the transformer
137 /// rather than in the subclass (e.g., lambda closure types).
138 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
139
140public:
141 /// Initializes a new tree transformer.
143
144 /// Retrieves a reference to the derived class.
145 Derived &getDerived() { return static_cast<Derived&>(*this); }
146
147 /// Retrieves a reference to the derived class.
148 const Derived &getDerived() const {
149 return static_cast<const Derived&>(*this);
150 }
151
152 static inline ExprResult Owned(Expr *E) { return E; }
153 static inline StmtResult Owned(Stmt *S) { return S; }
154
155 /// Retrieves a reference to the semantic analysis object used for
156 /// this tree transform.
157 Sema &getSema() const { return SemaRef; }
158
159 /// Whether the transformation should always rebuild AST nodes, even
160 /// if none of the children have changed.
161 ///
162 /// Subclasses may override this function to specify when the transformation
163 /// should rebuild all AST nodes.
164 ///
165 /// We must always rebuild all AST nodes when performing variadic template
166 /// pack expansion, in order to avoid violating the AST invariant that each
167 /// statement node appears at most once in its containing declaration.
169
170 /// Whether the transformation is forming an expression or statement that
171 /// replaces the original. In this case, we'll reuse mangling numbers from
172 /// existing lambdas.
173 bool ReplacingOriginal() { return false; }
174
175 /// Wether CXXConstructExpr can be skipped when they are implicit.
176 /// They will be reconstructed when used if needed.
177 /// This is useful when the user that cause rebuilding of the
178 /// CXXConstructExpr is outside of the expression at which the TreeTransform
179 /// started.
180 bool AllowSkippingCXXConstructExpr() { return true; }
181
182 /// Returns the location of the entity being transformed, if that
183 /// information was not available elsewhere in the AST.
184 ///
185 /// By default, returns no source-location information. Subclasses can
186 /// provide an alternative implementation that provides better location
187 /// information.
189
190 /// Returns the name of the entity being transformed, if that
191 /// information was not available elsewhere in the AST.
192 ///
193 /// By default, returns an empty name. Subclasses can provide an alternative
194 /// implementation with a more precise name.
196
197 /// Sets the "base" location and entity when that
198 /// information is known based on another transformation.
199 ///
200 /// By default, the source location and entity are ignored. Subclasses can
201 /// override this function to provide a customized implementation.
203
204 /// RAII object that temporarily sets the base location and entity
205 /// used for reporting diagnostics in types.
207 TreeTransform &Self;
208 SourceLocation OldLocation;
209 DeclarationName OldEntity;
210
211 public:
213 DeclarationName Entity) : Self(Self) {
214 OldLocation = Self.getDerived().getBaseLocation();
215 OldEntity = Self.getDerived().getBaseEntity();
216
217 if (Location.isValid())
218 Self.getDerived().setBase(Location, Entity);
219 }
220
222 Self.getDerived().setBase(OldLocation, OldEntity);
223 }
224 };
225
226 /// Determine whether the given type \p T has already been
227 /// transformed.
228 ///
229 /// Subclasses can provide an alternative implementation of this routine
230 /// to short-circuit evaluation when it is known that a given type will
231 /// not change. For example, template instantiation need not traverse
232 /// non-dependent types.
234 return T.isNull();
235 }
236
237 /// Transform a template parameter depth level.
238 ///
239 /// During a transformation that transforms template parameters, this maps
240 /// an old template parameter depth to a new depth.
241 unsigned TransformTemplateDepth(unsigned Depth) {
242 return Depth;
243 }
244
245 /// Determine whether the given call argument should be dropped, e.g.,
246 /// because it is a default argument.
247 ///
248 /// Subclasses can provide an alternative implementation of this routine to
249 /// determine which kinds of call arguments get dropped. By default,
250 /// CXXDefaultArgument nodes are dropped (prior to transformation).
252 return E->isDefaultArgument();
253 }
254
255 /// Determine whether we should expand a pack expansion with the
256 /// given set of parameter packs into separate arguments by repeatedly
257 /// transforming the pattern.
258 ///
259 /// By default, the transformer never tries to expand pack expansions.
260 /// Subclasses can override this routine to provide different behavior.
261 ///
262 /// \param EllipsisLoc The location of the ellipsis that identifies the
263 /// pack expansion.
264 ///
265 /// \param PatternRange The source range that covers the entire pattern of
266 /// the pack expansion.
267 ///
268 /// \param Unexpanded The set of unexpanded parameter packs within the
269 /// pattern.
270 ///
271 /// \param ShouldExpand Will be set to \c true if the transformer should
272 /// expand the corresponding pack expansions into separate arguments. When
273 /// set, \c NumExpansions must also be set.
274 ///
275 /// \param RetainExpansion Whether the caller should add an unexpanded
276 /// pack expansion after all of the expanded arguments. This is used
277 /// when extending explicitly-specified template argument packs per
278 /// C++0x [temp.arg.explicit]p9.
279 ///
280 /// \param NumExpansions The number of separate arguments that will be in
281 /// the expanded form of the corresponding pack expansion. This is both an
282 /// input and an output parameter, which can be set by the caller if the
283 /// number of expansions is known a priori (e.g., due to a prior substitution)
284 /// and will be set by the callee when the number of expansions is known.
285 /// The callee must set this value when \c ShouldExpand is \c true; it may
286 /// set this value in other cases.
287 ///
288 /// \returns true if an error occurred (e.g., because the parameter packs
289 /// are to be instantiated with arguments of different lengths), false
290 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
291 /// must be set.
293 SourceRange PatternRange,
295 bool &ShouldExpand, bool &RetainExpansion,
296 std::optional<unsigned> &NumExpansions) {
297 ShouldExpand = false;
298 return false;
299 }
300
301 /// "Forget" about the partially-substituted pack template argument,
302 /// when performing an instantiation that must preserve the parameter pack
303 /// use.
304 ///
305 /// This routine is meant to be overridden by the template instantiator.
307 return TemplateArgument();
308 }
309
310 /// "Remember" the partially-substituted pack template argument
311 /// after performing an instantiation that must preserve the parameter pack
312 /// use.
313 ///
314 /// This routine is meant to be overridden by the template instantiator.
316
317 /// Note to the derived class when a function parameter pack is
318 /// being expanded.
320
321 /// Transforms the given type into another type.
322 ///
323 /// By default, this routine transforms a type by creating a
324 /// TypeSourceInfo for it and delegating to the appropriate
325 /// function. This is expensive, but we don't mind, because
326 /// this method is deprecated anyway; all users should be
327 /// switched to storing TypeSourceInfos.
328 ///
329 /// \returns the transformed type.
331
332 /// Transforms the given type-with-location into a new
333 /// type-with-location.
334 ///
335 /// By default, this routine transforms a type by delegating to the
336 /// appropriate TransformXXXType to build a new type. Subclasses
337 /// may override this function (to take over all type
338 /// transformations) or some set of the TransformXXXType functions
339 /// to alter the transformation.
341
342 /// Transform the given type-with-location into a new
343 /// type, collecting location information in the given builder
344 /// as necessary.
345 ///
347
348 /// Transform a type that is permitted to produce a
349 /// DeducedTemplateSpecializationType.
350 ///
351 /// This is used in the (relatively rare) contexts where it is acceptable
352 /// for transformation to produce a class template type with deduced
353 /// template arguments.
354 /// @{
357 /// @}
358
359 /// The reason why the value of a statement is not discarded, if any.
364 };
365
366 /// Transform the given statement.
367 ///
368 /// By default, this routine transforms a statement by delegating to the
369 /// appropriate TransformXXXStmt function to transform a specific kind of
370 /// statement or the TransformExpr() function to transform an expression.
371 /// Subclasses may override this function to transform statements using some
372 /// other mechanism.
373 ///
374 /// \returns the transformed statement.
376
377 /// Transform the given statement.
378 ///
379 /// By default, this routine transforms a statement by delegating to the
380 /// appropriate TransformOMPXXXClause function to transform a specific kind
381 /// of clause. Subclasses may override this function to transform statements
382 /// using some other mechanism.
383 ///
384 /// \returns the transformed OpenMP clause.
386
387 /// Transform the given attribute.
388 ///
389 /// By default, this routine transforms a statement by delegating to the
390 /// appropriate TransformXXXAttr function to transform a specific kind
391 /// of attribute. Subclasses may override this function to transform
392 /// attributed statements/types using some other mechanism.
393 ///
394 /// \returns the transformed attribute
395 const Attr *TransformAttr(const Attr *S);
396
397 // Transform the given statement attribute.
398 //
399 // Delegates to the appropriate TransformXXXAttr function to transform a
400 // specific kind of statement attribute. Unlike the non-statement taking
401 // version of this, this implements all attributes, not just pragmas.
402 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
403 const Attr *A);
404
405 // Transform the specified attribute.
406 //
407 // Subclasses should override the transformation of attributes with a pragma
408 // spelling to transform expressions stored within the attribute.
409 //
410 // \returns the transformed attribute.
411#define ATTR(X) \
412 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
413#include "clang/Basic/AttrList.inc"
414
415 // Transform the specified attribute.
416 //
417 // Subclasses should override the transformation of attributes to do
418 // transformation and checking of statement attributes. By default, this
419 // delegates to the non-statement taking version.
420 //
421 // \returns the transformed attribute.
422#define ATTR(X) \
423 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
424 const X##Attr *A) { \
425 return getDerived().Transform##X##Attr(A); \
426 }
427#include "clang/Basic/AttrList.inc"
428
429 /// Transform the given expression.
430 ///
431 /// By default, this routine transforms an expression by delegating to the
432 /// appropriate TransformXXXExpr function to build a new expression.
433 /// Subclasses may override this function to transform expressions using some
434 /// other mechanism.
435 ///
436 /// \returns the transformed expression.
438
439 /// Transform the given initializer.
440 ///
441 /// By default, this routine transforms an initializer by stripping off the
442 /// semantic nodes added by initialization, then passing the result to
443 /// TransformExpr or TransformExprs.
444 ///
445 /// \returns the transformed initializer.
447
448 /// Transform the given list of expressions.
449 ///
450 /// This routine transforms a list of expressions by invoking
451 /// \c TransformExpr() for each subexpression. However, it also provides
452 /// support for variadic templates by expanding any pack expansions (if the
453 /// derived class permits such expansion) along the way. When pack expansions
454 /// are present, the number of outputs may not equal the number of inputs.
455 ///
456 /// \param Inputs The set of expressions to be transformed.
457 ///
458 /// \param NumInputs The number of expressions in \c Inputs.
459 ///
460 /// \param IsCall If \c true, then this transform is being performed on
461 /// function-call arguments, and any arguments that should be dropped, will
462 /// be.
463 ///
464 /// \param Outputs The transformed input expressions will be added to this
465 /// vector.
466 ///
467 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
468 /// due to transformation.
469 ///
470 /// \returns true if an error occurred, false otherwise.
471 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
473 bool *ArgChanged = nullptr);
474
475 /// Transform the given declaration, which is referenced from a type
476 /// or expression.
477 ///
478 /// By default, acts as the identity function on declarations, unless the
479 /// transformer has had to transform the declaration itself. Subclasses
480 /// may override this function to provide alternate behavior.
482 llvm::DenseMap<Decl *, Decl *>::iterator Known
483 = TransformedLocalDecls.find(D);
484 if (Known != TransformedLocalDecls.end())
485 return Known->second;
486
487 return D;
488 }
489
490 /// Transform the specified condition.
491 ///
492 /// By default, this transforms the variable and expression and rebuilds
493 /// the condition.
495 Expr *Expr,
497
498 /// Transform the attributes associated with the given declaration and
499 /// place them on the new declaration.
500 ///
501 /// By default, this operation does nothing. Subclasses may override this
502 /// behavior to transform attributes.
503 void transformAttrs(Decl *Old, Decl *New) { }
504
505 /// Note that a local declaration has been transformed by this
506 /// transformer.
507 ///
508 /// Local declarations are typically transformed via a call to
509 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
510 /// the transformer itself has to transform the declarations. This routine
511 /// can be overridden by a subclass that keeps track of such mappings.
513 assert(New.size() == 1 &&
514 "must override transformedLocalDecl if performing pack expansion");
515 TransformedLocalDecls[Old] = New.front();
516 }
517
518 /// Transform the definition of the given declaration.
519 ///
520 /// By default, invokes TransformDecl() to transform the declaration.
521 /// Subclasses may override this function to provide alternate behavior.
523 return getDerived().TransformDecl(Loc, D);
524 }
525
526 /// Transform the given declaration, which was the first part of a
527 /// nested-name-specifier in a member access expression.
528 ///
529 /// This specific declaration transformation only applies to the first
530 /// identifier in a nested-name-specifier of a member access expression, e.g.,
531 /// the \c T in \c x->T::member
532 ///
533 /// By default, invokes TransformDecl() to transform the declaration.
534 /// Subclasses may override this function to provide alternate behavior.
536 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
537 }
538
539 /// Transform the set of declarations in an OverloadExpr.
540 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
541 LookupResult &R);
542
543 /// Transform the given nested-name-specifier with source-location
544 /// information.
545 ///
546 /// By default, transforms all of the types and declarations within the
547 /// nested-name-specifier. Subclasses may override this function to provide
548 /// alternate behavior.
551 QualType ObjectType = QualType(),
552 NamedDecl *FirstQualifierInScope = nullptr);
553
554 /// Transform the given declaration name.
555 ///
556 /// By default, transforms the types of conversion function, constructor,
557 /// and destructor names and then (if needed) rebuilds the declaration name.
558 /// Identifiers and selectors are returned unmodified. Subclasses may
559 /// override this function to provide alternate behavior.
562
572
573 /// Transform the given template name.
574 ///
575 /// \param SS The nested-name-specifier that qualifies the template
576 /// name. This nested-name-specifier must already have been transformed.
577 ///
578 /// \param Name The template name to transform.
579 ///
580 /// \param NameLoc The source location of the template name.
581 ///
582 /// \param ObjectType If we're translating a template name within a member
583 /// access expression, this is the type of the object whose member template
584 /// is being referenced.
585 ///
586 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
587 /// also refers to a name within the current (lexical) scope, this is the
588 /// declaration it refers to.
589 ///
590 /// By default, transforms the template name by transforming the declarations
591 /// and nested-name-specifiers that occur within the template name.
592 /// Subclasses may override this function to provide alternate behavior.
595 SourceLocation NameLoc,
596 QualType ObjectType = QualType(),
597 NamedDecl *FirstQualifierInScope = nullptr,
598 bool AllowInjectedClassName = false);
599
600 /// Transform the given template argument.
601 ///
602 /// By default, this operation transforms the type, expression, or
603 /// declaration stored within the template argument and constructs a
604 /// new template argument from the transformed result. Subclasses may
605 /// override this function to provide alternate behavior.
606 ///
607 /// Returns true if there was an error.
609 TemplateArgumentLoc &Output,
610 bool Uneval = false);
611
612 /// Transform the given set of template arguments.
613 ///
614 /// By default, this operation transforms all of the template arguments
615 /// in the input set using \c TransformTemplateArgument(), and appends
616 /// the transformed arguments to the output list.
617 ///
618 /// Note that this overload of \c TransformTemplateArguments() is merely
619 /// a convenience function. Subclasses that wish to override this behavior
620 /// should override the iterator-based member template version.
621 ///
622 /// \param Inputs The set of template arguments to be transformed.
623 ///
624 /// \param NumInputs The number of template arguments in \p Inputs.
625 ///
626 /// \param Outputs The set of transformed template arguments output by this
627 /// routine.
628 ///
629 /// Returns true if an error occurred.
631 unsigned NumInputs,
633 bool Uneval = false) {
634 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
635 Uneval);
636 }
637
638 /// Transform the given set of template arguments.
639 ///
640 /// By default, this operation transforms all of the template arguments
641 /// in the input set using \c TransformTemplateArgument(), and appends
642 /// the transformed arguments to the output list.
643 ///
644 /// \param First An iterator to the first template argument.
645 ///
646 /// \param Last An iterator one step past the last template argument.
647 ///
648 /// \param Outputs The set of transformed template arguments output by this
649 /// routine.
650 ///
651 /// Returns true if an error occurred.
652 template<typename InputIterator>
654 InputIterator Last,
656 bool Uneval = false);
657
658 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
660 TemplateArgumentLoc &ArgLoc);
661
662 /// Fakes up a TypeSourceInfo for a type.
666 }
667
668#define ABSTRACT_TYPELOC(CLASS, PARENT)
669#define TYPELOC(CLASS, PARENT) \
670 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
671#include "clang/AST/TypeLocNodes.def"
672
675 bool SuppressObjCLifetime);
679 bool SuppressObjCLifetime);
680
681 template<typename Fn>
684 CXXRecordDecl *ThisContext,
685 Qualifiers ThisTypeQuals,
687
690 SmallVectorImpl<QualType> &Exceptions,
691 bool &Changed);
692
694
698 TemplateName Template);
699
703 TemplateName Template,
704 CXXScopeSpec &SS);
705
708 NestedNameSpecifierLoc QualifierLoc);
709
710 /// Transforms the parameters of a function type into the
711 /// given vectors.
712 ///
713 /// The result vectors should be kept in sync; null entries in the
714 /// variables vector are acceptable.
715 ///
716 /// LastParamTransformed, if non-null, will be set to the index of the last
717 /// parameter on which transfromation was started. In the event of an error,
718 /// this will contain the parameter which failed to instantiate.
719 ///
720 /// Return true on error.
723 const QualType *ParamTypes,
724 const FunctionProtoType::ExtParameterInfo *ParamInfos,
726 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
727
730 const QualType *ParamTypes,
731 const FunctionProtoType::ExtParameterInfo *ParamInfos,
734 return getDerived().TransformFunctionTypeParams(
735 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
736 }
737
738 /// Transforms the parameters of a requires expresison into the given vectors.
739 ///
740 /// The result vectors should be kept in sync; null entries in the
741 /// variables vector are acceptable.
742 ///
743 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
744 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
745 /// which are cases where transformation shouldn't continue.
747 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
753 KWLoc, Params, /*ParamTypes=*/nullptr,
754 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
755 return ExprError();
756
757 return ExprResult{};
758 }
759
760 /// Transforms a single function-type parameter. Return null
761 /// on error.
762 ///
763 /// \param indexAdjustment - A number to add to the parameter's
764 /// scope index; can be negative
766 int indexAdjustment,
767 std::optional<unsigned> NumExpansions,
768 bool ExpectParameterPack);
769
770 /// Transform the body of a lambda-expression.
772 /// Alternative implementation of TransformLambdaBody that skips transforming
773 /// the body.
775
778 return static_cast<CXXRecordDecl::LambdaDependencyKind>(
780 }
781
783
786
789 return TPL;
790 }
791
793
795 bool IsAddressOfOperand,
796 TypeSourceInfo **RecoveryTSI);
797
799 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
800 TypeSourceInfo **RecoveryTSI);
801
803 bool IsAddressOfOperand);
804
806
808
809// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
810// amount of stack usage with clang.
811#define STMT(Node, Parent) \
812 LLVM_ATTRIBUTE_NOINLINE \
813 StmtResult Transform##Node(Node *S);
814#define VALUESTMT(Node, Parent) \
815 LLVM_ATTRIBUTE_NOINLINE \
816 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
817#define EXPR(Node, Parent) \
818 LLVM_ATTRIBUTE_NOINLINE \
819 ExprResult Transform##Node(Node *E);
820#define ABSTRACT_STMT(Stmt)
821#include "clang/AST/StmtNodes.inc"
822
823#define GEN_CLANG_CLAUSE_CLASS
824#define CLAUSE_CLASS(Enum, Str, Class) \
825 LLVM_ATTRIBUTE_NOINLINE \
826 OMPClause *Transform##Class(Class *S);
827#include "llvm/Frontend/OpenMP/OMP.inc"
828
829 /// Build a new qualified type given its unqualified type and type location.
830 ///
831 /// By default, this routine adds type qualifiers only to types that can
832 /// have qualifiers, and silently suppresses those qualifiers that are not
833 /// permitted. Subclasses may override this routine to provide different
834 /// behavior.
836
837 /// Build a new pointer type given its pointee type.
838 ///
839 /// By default, performs semantic analysis when building the pointer type.
840 /// Subclasses may override this routine to provide different behavior.
842
843 /// Build a new block pointer type given its pointee type.
844 ///
845 /// By default, performs semantic analysis when building the block pointer
846 /// type. Subclasses may override this routine to provide different behavior.
848
849 /// Build a new reference type given the type it references.
850 ///
851 /// By default, performs semantic analysis when building the
852 /// reference type. Subclasses may override this routine to provide
853 /// different behavior.
854 ///
855 /// \param LValue whether the type was written with an lvalue sigil
856 /// or an rvalue sigil.
858 bool LValue,
859 SourceLocation Sigil);
860
861 /// Build a new member pointer type given the pointee type and the
862 /// class type it refers into.
863 ///
864 /// By default, performs semantic analysis when building the member pointer
865 /// type. Subclasses may override this routine to provide different behavior.
867 SourceLocation Sigil);
868
870 SourceLocation ProtocolLAngleLoc,
872 ArrayRef<SourceLocation> ProtocolLocs,
873 SourceLocation ProtocolRAngleLoc);
874
875 /// Build an Objective-C object type.
876 ///
877 /// By default, performs semantic analysis when building the object type.
878 /// Subclasses may override this routine to provide different behavior.
881 SourceLocation TypeArgsLAngleLoc,
883 SourceLocation TypeArgsRAngleLoc,
884 SourceLocation ProtocolLAngleLoc,
886 ArrayRef<SourceLocation> ProtocolLocs,
887 SourceLocation ProtocolRAngleLoc);
888
889 /// Build a new Objective-C object pointer type given the pointee type.
890 ///
891 /// By default, directly builds the pointer type, with no additional semantic
892 /// analysis.
895
896 /// Build a new array type given the element type, size
897 /// modifier, size of the array (if known), size expression, and index type
898 /// qualifiers.
899 ///
900 /// By default, performs semantic analysis when building the array type.
901 /// Subclasses may override this routine to provide different behavior.
902 /// Also by default, all of the other Rebuild*Array
904 const llvm::APInt *Size, Expr *SizeExpr,
905 unsigned IndexTypeQuals, SourceRange BracketsRange);
906
907 /// Build a new constant array type given the element type, size
908 /// modifier, (known) size of the array, and index type qualifiers.
909 ///
910 /// By default, performs semantic analysis when building the array type.
911 /// Subclasses may override this routine to provide different behavior.
913 ArraySizeModifier SizeMod,
914 const llvm::APInt &Size, Expr *SizeExpr,
915 unsigned IndexTypeQuals,
916 SourceRange BracketsRange);
917
918 /// Build a new incomplete array type given the element type, size
919 /// modifier, and index type qualifiers.
920 ///
921 /// By default, performs semantic analysis when building the array type.
922 /// Subclasses may override this routine to provide different behavior.
924 ArraySizeModifier SizeMod,
925 unsigned IndexTypeQuals,
926 SourceRange BracketsRange);
927
928 /// Build a new variable-length array type given the element type,
929 /// size modifier, size expression, and index type qualifiers.
930 ///
931 /// By default, performs semantic analysis when building the array type.
932 /// Subclasses may override this routine to provide different behavior.
934 ArraySizeModifier SizeMod, Expr *SizeExpr,
935 unsigned IndexTypeQuals,
936 SourceRange BracketsRange);
937
938 /// Build a new dependent-sized array type given the element type,
939 /// size modifier, size expression, and index type qualifiers.
940 ///
941 /// By default, performs semantic analysis when building the array type.
942 /// Subclasses may override this routine to provide different behavior.
944 ArraySizeModifier SizeMod,
945 Expr *SizeExpr,
946 unsigned IndexTypeQuals,
947 SourceRange BracketsRange);
948
949 /// Build a new vector type given the element type and
950 /// number of elements.
951 ///
952 /// By default, performs semantic analysis when building the vector type.
953 /// Subclasses may override this routine to provide different behavior.
954 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
955 VectorKind VecKind);
956
957 /// Build a new potentially dependently-sized extended vector type
958 /// given the element type and number of elements.
959 ///
960 /// By default, performs semantic analysis when building the vector type.
961 /// Subclasses may override this routine to provide different behavior.
963 SourceLocation AttributeLoc, VectorKind);
964
965 /// Build a new extended vector type given the element type and
966 /// number of elements.
967 ///
968 /// By default, performs semantic analysis when building the vector type.
969 /// Subclasses may override this routine to provide different behavior.
970 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
971 SourceLocation AttributeLoc);
972
973 /// Build a new potentially dependently-sized extended vector type
974 /// given the element type and number of elements.
975 ///
976 /// By default, performs semantic analysis when building the vector type.
977 /// Subclasses may override this routine to provide different behavior.
979 Expr *SizeExpr,
980 SourceLocation AttributeLoc);
981
982 /// Build a new matrix type given the element type and dimensions.
983 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
984 unsigned NumColumns);
985
986 /// Build a new matrix type given the type and dependently-defined
987 /// dimensions.
989 Expr *ColumnExpr,
990 SourceLocation AttributeLoc);
991
992 /// Build a new DependentAddressSpaceType or return the pointee
993 /// type variable with the correct address space (retrieved from
994 /// AddrSpaceExpr) applied to it. The former will be returned in cases
995 /// where the address space remains dependent.
996 ///
997 /// By default, performs semantic analysis when building the type with address
998 /// space applied. Subclasses may override this routine to provide different
999 /// behavior.
1001 Expr *AddrSpaceExpr,
1002 SourceLocation AttributeLoc);
1003
1004 /// Build a new function type.
1005 ///
1006 /// By default, performs semantic analysis when building the function type.
1007 /// Subclasses may override this routine to provide different behavior.
1009 MutableArrayRef<QualType> ParamTypes,
1011
1012 /// Build a new unprototyped function type.
1014
1015 /// Rebuild an unresolved typename type, given the decl that
1016 /// the UnresolvedUsingTypenameDecl was transformed to.
1018
1019 /// Build a new type found via an alias.
1021 return SemaRef.Context.getUsingType(Found, Underlying);
1022 }
1023
1024 /// Build a new typedef type.
1026 return SemaRef.Context.getTypeDeclType(Typedef);
1027 }
1028
1029 /// Build a new MacroDefined type.
1031 const IdentifierInfo *MacroII) {
1032 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1033 }
1034
1035 /// Build a new class/struct/union type.
1038 }
1039
1040 /// Build a new Enum type.
1043 }
1044
1045 /// Build a new typeof(expr) type.
1046 ///
1047 /// By default, performs semantic analysis when building the typeof type.
1048 /// Subclasses may override this routine to provide different behavior.
1050 TypeOfKind Kind);
1051
1052 /// Build a new typeof(type) type.
1053 ///
1054 /// By default, builds a new TypeOfType with the given underlying type.
1056
1057 /// Build a new unary transform type.
1061
1062 /// Build a new C++11 decltype type.
1063 ///
1064 /// By default, performs semantic analysis when building the decltype type.
1065 /// Subclasses may override this routine to provide different behavior.
1067
1070 SourceLocation EllipsisLoc,
1071 bool FullySubstituted,
1072 ArrayRef<QualType> Expansions = {});
1073
1074 /// Build a new C++11 auto type.
1075 ///
1076 /// By default, builds a new AutoType with the given deduced type.
1078 ConceptDecl *TypeConstraintConcept,
1079 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1080 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1081 // which has been deduced to a dependent type into an undeduced 'auto', so
1082 // that we'll retry deduction after the transformation.
1083 return SemaRef.Context.getAutoType(Deduced, Keyword,
1084 /*IsDependent*/ false, /*IsPack=*/false,
1085 TypeConstraintConcept,
1086 TypeConstraintArgs);
1087 }
1088
1089 /// By default, builds a new DeducedTemplateSpecializationType with the given
1090 /// deduced type.
1092 QualType Deduced) {
1094 Template, Deduced, /*IsDependent*/ false);
1095 }
1096
1097 /// Build a new template specialization type.
1098 ///
1099 /// By default, performs semantic analysis when building the template
1100 /// specialization type. Subclasses may override this routine to provide
1101 /// different behavior.
1103 SourceLocation TemplateLoc,
1105
1106 /// Build a new parenthesized type.
1107 ///
1108 /// By default, builds a new ParenType type from the inner type.
1109 /// Subclasses may override this routine to provide different behavior.
1111 return SemaRef.BuildParenType(InnerType);
1112 }
1113
1114 /// Build a new qualified name type.
1115 ///
1116 /// By default, builds a new ElaboratedType type from the keyword,
1117 /// the nested-name-specifier and the named type.
1118 /// Subclasses may override this routine to provide different behavior.
1120 ElaboratedTypeKeyword Keyword,
1121 NestedNameSpecifierLoc QualifierLoc,
1122 QualType Named) {
1123 return SemaRef.Context.getElaboratedType(Keyword,
1124 QualifierLoc.getNestedNameSpecifier(),
1125 Named);
1126 }
1127
1128 /// Build a new typename type that refers to a template-id.
1129 ///
1130 /// By default, builds a new DependentNameType type from the
1131 /// nested-name-specifier and the given type. Subclasses may override
1132 /// this routine to provide different behavior.
1134 ElaboratedTypeKeyword Keyword,
1135 NestedNameSpecifierLoc QualifierLoc,
1136 SourceLocation TemplateKWLoc,
1137 const IdentifierInfo *Name,
1138 SourceLocation NameLoc,
1140 bool AllowInjectedClassName) {
1141 // Rebuild the template name.
1142 // TODO: avoid TemplateName abstraction
1143 CXXScopeSpec SS;
1144 SS.Adopt(QualifierLoc);
1145 TemplateName InstName = getDerived().RebuildTemplateName(
1146 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1147 AllowInjectedClassName);
1148
1149 if (InstName.isNull())
1150 return QualType();
1151
1152 // If it's still dependent, make a dependent specialization.
1153 if (InstName.getAsDependentTemplateName())
1155 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1156 Args.arguments());
1157
1158 // Otherwise, make an elaborated type wrapping a non-dependent
1159 // specialization.
1160 QualType T =
1161 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1162 if (T.isNull())
1163 return QualType();
1165 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1166 }
1167
1168 /// Build a new typename type that refers to an identifier.
1169 ///
1170 /// By default, performs semantic analysis when building the typename type
1171 /// (or elaborated type). Subclasses may override this routine to provide
1172 /// different behavior.
1174 SourceLocation KeywordLoc,
1175 NestedNameSpecifierLoc QualifierLoc,
1176 const IdentifierInfo *Id,
1177 SourceLocation IdLoc,
1178 bool DeducedTSTContext) {
1179 CXXScopeSpec SS;
1180 SS.Adopt(QualifierLoc);
1181
1182 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1183 // If the name is still dependent, just build a new dependent name type.
1184 if (!SemaRef.computeDeclContext(SS))
1185 return SemaRef.Context.getDependentNameType(Keyword,
1186 QualifierLoc.getNestedNameSpecifier(),
1187 Id);
1188 }
1189
1190 if (Keyword == ElaboratedTypeKeyword::None ||
1192 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1193 *Id, IdLoc, DeducedTSTContext);
1194 }
1195
1197
1198 // We had a dependent elaborated-type-specifier that has been transformed
1199 // into a non-dependent elaborated-type-specifier. Find the tag we're
1200 // referring to.
1202 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1203 if (!DC)
1204 return QualType();
1205
1207 return QualType();
1208
1209 TagDecl *Tag = nullptr;
1211 switch (Result.getResultKind()) {
1214 break;
1215
1217 Tag = Result.getAsSingle<TagDecl>();
1218 break;
1219
1222 llvm_unreachable("Tag lookup cannot find non-tags");
1223
1225 // Let the LookupResult structure handle ambiguities.
1226 return QualType();
1227 }
1228
1229 if (!Tag) {
1230 // Check where the name exists but isn't a tag type and use that to emit
1231 // better diagnostics.
1234 switch (Result.getResultKind()) {
1238 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1239 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1240 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1241 << SomeDecl << NTK << llvm::to_underlying(Kind);
1242 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1243 break;
1244 }
1245 default:
1246 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1247 << llvm::to_underlying(Kind) << Id << DC
1248 << QualifierLoc.getSourceRange();
1249 break;
1250 }
1251 return QualType();
1252 }
1253
1254 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1255 IdLoc, Id)) {
1256 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1257 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1258 return QualType();
1259 }
1260
1261 // Build the elaborated-type-specifier type.
1263 return SemaRef.Context.getElaboratedType(Keyword,
1264 QualifierLoc.getNestedNameSpecifier(),
1265 T);
1266 }
1267
1268 /// Build a new pack expansion type.
1269 ///
1270 /// By default, builds a new PackExpansionType type from the given pattern.
1271 /// Subclasses may override this routine to provide different behavior.
1273 SourceLocation EllipsisLoc,
1274 std::optional<unsigned> NumExpansions) {
1275 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1276 NumExpansions);
1277 }
1278
1279 /// Build a new atomic type given its value type.
1280 ///
1281 /// By default, performs semantic analysis when building the atomic type.
1282 /// Subclasses may override this routine to provide different behavior.
1284
1285 /// Build a new pipe type given its value type.
1287 bool isReadPipe);
1288
1289 /// Build a bit-precise int given its value type.
1290 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1292
1293 /// Build a dependent bit-precise int given its value type.
1294 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1296
1297 /// Build a new template name given a nested name specifier, a flag
1298 /// indicating whether the "template" keyword was provided, and the template
1299 /// that the template name refers to.
1300 ///
1301 /// By default, builds the new template name directly. Subclasses may override
1302 /// this routine to provide different behavior.
1304 bool TemplateKW,
1305 TemplateDecl *Template);
1306
1307 /// Build a new template name given a nested name specifier and the
1308 /// name that is referred to as a template.
1309 ///
1310 /// By default, performs semantic analysis to determine whether the name can
1311 /// be resolved to a specific template, then builds the appropriate kind of
1312 /// template name. Subclasses may override this routine to provide different
1313 /// behavior.
1315 SourceLocation TemplateKWLoc,
1316 const IdentifierInfo &Name,
1317 SourceLocation NameLoc, QualType ObjectType,
1318 NamedDecl *FirstQualifierInScope,
1319 bool AllowInjectedClassName);
1320
1321 /// Build a new template name given a nested name specifier and the
1322 /// overloaded operator name that is referred to as a template.
1323 ///
1324 /// By default, performs semantic analysis to determine whether the name can
1325 /// be resolved to a specific template, then builds the appropriate kind of
1326 /// template name. Subclasses may override this routine to provide different
1327 /// behavior.
1329 SourceLocation TemplateKWLoc,
1330 OverloadedOperatorKind Operator,
1331 SourceLocation NameLoc, QualType ObjectType,
1332 bool AllowInjectedClassName);
1333
1334 /// Build a new template name given a template template parameter pack
1335 /// and the
1336 ///
1337 /// By default, performs semantic analysis to determine whether the name can
1338 /// be resolved to a specific template, then builds the appropriate kind of
1339 /// template name. Subclasses may override this routine to provide different
1340 /// behavior.
1342 Decl *AssociatedDecl, unsigned Index,
1343 bool Final) {
1345 ArgPack, AssociatedDecl, Index, Final);
1346 }
1347
1348 /// Build a new compound statement.
1349 ///
1350 /// By default, performs semantic analysis to build the new statement.
1351 /// Subclasses may override this routine to provide different behavior.
1353 MultiStmtArg Statements,
1354 SourceLocation RBraceLoc,
1355 bool IsStmtExpr) {
1356 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1357 IsStmtExpr);
1358 }
1359
1360 /// Build a new case statement.
1361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
1365 Expr *LHS,
1366 SourceLocation EllipsisLoc,
1367 Expr *RHS,
1368 SourceLocation ColonLoc) {
1369 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1370 ColonLoc);
1371 }
1372
1373 /// Attach the body to a new case statement.
1374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
1378 getSema().ActOnCaseStmtBody(S, Body);
1379 return S;
1380 }
1381
1382 /// Build a new default statement.
1383 ///
1384 /// By default, performs semantic analysis to build the new statement.
1385 /// Subclasses may override this routine to provide different behavior.
1387 SourceLocation ColonLoc,
1388 Stmt *SubStmt) {
1389 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1390 /*CurScope=*/nullptr);
1391 }
1392
1393 /// Build a new label statement.
1394 ///
1395 /// By default, performs semantic analysis to build the new statement.
1396 /// Subclasses may override this routine to provide different behavior.
1398 SourceLocation ColonLoc, Stmt *SubStmt) {
1399 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1400 }
1401
1402 /// Build a new attributed statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
1408 Stmt *SubStmt) {
1410 return StmtError();
1411 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1412 }
1413
1414 /// Build a new "if" statement.
1415 ///
1416 /// By default, performs semantic analysis to build the new statement.
1417 /// Subclasses may override this routine to provide different behavior.
1419 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1420 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1421 SourceLocation ElseLoc, Stmt *Else) {
1422 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1423 Then, ElseLoc, Else);
1424 }
1425
1426 /// Start building a new switch statement.
1427 ///
1428 /// By default, performs semantic analysis to build the new statement.
1429 /// Subclasses may override this routine to provide different behavior.
1431 SourceLocation LParenLoc, Stmt *Init,
1433 SourceLocation RParenLoc) {
1434 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1435 RParenLoc);
1436 }
1437
1438 /// Attach the body to the switch statement.
1439 ///
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
1443 Stmt *Switch, Stmt *Body) {
1444 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1445 }
1446
1447 /// Build a new while statement.
1448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
1453 SourceLocation RParenLoc, Stmt *Body) {
1454 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1455 }
1456
1457 /// Build a new do-while statement.
1458 ///
1459 /// By default, performs semantic analysis to build the new statement.
1460 /// Subclasses may override this routine to provide different behavior.
1462 SourceLocation WhileLoc, SourceLocation LParenLoc,
1463 Expr *Cond, SourceLocation RParenLoc) {
1464 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1465 Cond, RParenLoc);
1466 }
1467
1468 /// Build a new for statement.
1469 ///
1470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
1474 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1475 Stmt *Body) {
1476 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1477 Inc, RParenLoc, Body);
1478 }
1479
1480 /// Build a new goto statement.
1481 ///
1482 /// By default, performs semantic analysis to build the new statement.
1483 /// Subclasses may override this routine to provide different behavior.
1485 LabelDecl *Label) {
1486 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1487 }
1488
1489 /// Build a new indirect goto statement.
1490 ///
1491 /// By default, performs semantic analysis to build the new statement.
1492 /// Subclasses may override this routine to provide different behavior.
1494 SourceLocation StarLoc,
1495 Expr *Target) {
1496 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1497 }
1498
1499 /// Build a new return statement.
1500 ///
1501 /// By default, performs semantic analysis to build the new statement.
1502 /// Subclasses may override this routine to provide different behavior.
1504 return getSema().BuildReturnStmt(ReturnLoc, Result);
1505 }
1506
1507 /// Build a new declaration statement.
1508 ///
1509 /// By default, performs semantic analysis to build the new statement.
1510 /// Subclasses may override this routine to provide different behavior.
1512 SourceLocation StartLoc, SourceLocation EndLoc) {
1514 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1515 }
1516
1517 /// Build a new inline asm statement.
1518 ///
1519 /// By default, performs semantic analysis to build the new statement.
1520 /// Subclasses may override this routine to provide different behavior.
1522 bool IsVolatile, unsigned NumOutputs,
1523 unsigned NumInputs, IdentifierInfo **Names,
1524 MultiExprArg Constraints, MultiExprArg Exprs,
1525 Expr *AsmString, MultiExprArg Clobbers,
1526 unsigned NumLabels,
1527 SourceLocation RParenLoc) {
1528 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1529 NumInputs, Names, Constraints, Exprs,
1530 AsmString, Clobbers, NumLabels, RParenLoc);
1531 }
1532
1533 /// Build a new MS style inline asm statement.
1534 ///
1535 /// By default, performs semantic analysis to build the new statement.
1536 /// Subclasses may override this routine to provide different behavior.
1538 ArrayRef<Token> AsmToks,
1539 StringRef AsmString,
1540 unsigned NumOutputs, unsigned NumInputs,
1541 ArrayRef<StringRef> Constraints,
1542 ArrayRef<StringRef> Clobbers,
1543 ArrayRef<Expr*> Exprs,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1546 NumOutputs, NumInputs,
1547 Constraints, Clobbers, Exprs, EndLoc);
1548 }
1549
1550 /// Build a new co_return statement.
1551 ///
1552 /// By default, performs semantic analysis to build the new statement.
1553 /// Subclasses may override this routine to provide different behavior.
1555 bool IsImplicit) {
1556 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
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 UnresolvedLookupExpr *OpCoawaitLookup,
1565 bool IsImplicit) {
1566 // This function rebuilds a coawait-expr given its operator.
1567 // For an explicit coawait-expr, the rebuild involves the full set
1568 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1569 // including calling await_transform().
1570 // For an implicit coawait-expr, we need to rebuild the "operator
1571 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1572 // This mirrors how the implicit CoawaitExpr is originally created
1573 // in Sema::ActOnCoroutineBodyStart().
1574 if (IsImplicit) {
1576 CoawaitLoc, Operand, OpCoawaitLookup);
1577 if (Suspend.isInvalid())
1578 return ExprError();
1579 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1580 Suspend.get(), true);
1581 }
1582
1583 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1584 OpCoawaitLookup);
1585 }
1586
1587 /// Build a new co_await expression.
1588 ///
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
1592 Expr *Result,
1593 UnresolvedLookupExpr *Lookup) {
1594 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1595 }
1596
1597 /// Build a new co_yield expression.
1598 ///
1599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
1602 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1603 }
1604
1606 return getSema().BuildCoroutineBodyStmt(Args);
1607 }
1608
1609 /// Build a new Objective-C \@try statement.
1610 ///
1611 /// By default, performs semantic analysis to build the new statement.
1612 /// Subclasses may override this routine to provide different behavior.
1614 Stmt *TryBody,
1615 MultiStmtArg CatchStmts,
1616 Stmt *Finally) {
1617 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1618 Finally);
1619 }
1620
1621 /// Rebuild an Objective-C exception declaration.
1622 ///
1623 /// By default, performs semantic analysis to build the new declaration.
1624 /// Subclasses may override this routine to provide different behavior.
1626 TypeSourceInfo *TInfo, QualType T) {
1628 TInfo, T, ExceptionDecl->getInnerLocStart(),
1629 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1630 }
1631
1632 /// Build a new Objective-C \@catch statement.
1633 ///
1634 /// By default, performs semantic analysis to build the new statement.
1635 /// Subclasses may override this routine to provide different behavior.
1637 SourceLocation RParenLoc,
1638 VarDecl *Var,
1639 Stmt *Body) {
1640 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1641 }
1642
1643 /// Build a new Objective-C \@finally statement.
1644 ///
1645 /// By default, performs semantic analysis to build the new statement.
1646 /// Subclasses may override this routine to provide different behavior.
1648 Stmt *Body) {
1649 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1650 }
1651
1652 /// Build a new Objective-C \@throw statement.
1653 ///
1654 /// By default, performs semantic analysis to build the new statement.
1655 /// Subclasses may override this routine to provide different behavior.
1657 Expr *Operand) {
1658 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1659 }
1660
1661 /// Build a new OpenMP Canonical loop.
1662 ///
1663 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1664 /// OMPCanonicalLoop.
1666 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1667 }
1668
1669 /// Build a new OpenMP executable directive.
1670 ///
1671 /// By default, performs semantic analysis to build the new statement.
1672 /// Subclasses may override this routine to provide different behavior.
1674 DeclarationNameInfo DirName,
1675 OpenMPDirectiveKind CancelRegion,
1676 ArrayRef<OMPClause *> Clauses,
1677 Stmt *AStmt, SourceLocation StartLoc,
1678 SourceLocation EndLoc) {
1679
1681 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1682 }
1683
1684 /// Build a new OpenMP informational directive.
1686 DeclarationNameInfo DirName,
1687 ArrayRef<OMPClause *> Clauses,
1688 Stmt *AStmt,
1689 SourceLocation StartLoc,
1690 SourceLocation EndLoc) {
1691
1693 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1694 }
1695
1696 /// Build a new OpenMP 'if' clause.
1697 ///
1698 /// By default, performs semantic analysis to build the new OpenMP clause.
1699 /// Subclasses may override this routine to provide different behavior.
1701 Expr *Condition, SourceLocation StartLoc,
1702 SourceLocation LParenLoc,
1703 SourceLocation NameModifierLoc,
1704 SourceLocation ColonLoc,
1705 SourceLocation EndLoc) {
1707 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1708 EndLoc);
1709 }
1710
1711 /// Build a new OpenMP 'final' clause.
1712 ///
1713 /// By default, performs semantic analysis to build the new OpenMP clause.
1714 /// Subclasses may override this routine to provide different behavior.
1716 SourceLocation LParenLoc,
1717 SourceLocation EndLoc) {
1718 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1719 LParenLoc, EndLoc);
1720 }
1721
1722 /// Build a new OpenMP 'num_threads' clause.
1723 ///
1724 /// By default, performs semantic analysis to build the new OpenMP clause.
1725 /// Subclasses may override this routine to provide different behavior.
1727 SourceLocation StartLoc,
1728 SourceLocation LParenLoc,
1729 SourceLocation EndLoc) {
1730 return getSema().OpenMP().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1731 LParenLoc, EndLoc);
1732 }
1733
1734 /// Build a new OpenMP 'safelen' clause.
1735 ///
1736 /// By default, performs semantic analysis to build the new OpenMP clause.
1737 /// Subclasses may override this routine to provide different behavior.
1739 SourceLocation LParenLoc,
1740 SourceLocation EndLoc) {
1741 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1742 EndLoc);
1743 }
1744
1745 /// Build a new OpenMP 'simdlen' clause.
1746 ///
1747 /// By default, performs semantic analysis to build the new OpenMP clause.
1748 /// Subclasses may override this routine to provide different behavior.
1750 SourceLocation LParenLoc,
1751 SourceLocation EndLoc) {
1752 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1753 EndLoc);
1754 }
1755
1757 SourceLocation StartLoc,
1758 SourceLocation LParenLoc,
1759 SourceLocation EndLoc) {
1760 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1761 EndLoc);
1762 }
1763
1764 /// Build a new OpenMP 'permutation' clause.
1766 SourceLocation StartLoc,
1767 SourceLocation LParenLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1770 LParenLoc, EndLoc);
1771 }
1772
1773 /// Build a new OpenMP 'full' clause.
1775 SourceLocation EndLoc) {
1776 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1777 }
1778
1779 /// Build a new OpenMP 'partial' clause.
1781 SourceLocation LParenLoc,
1782 SourceLocation EndLoc) {
1783 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1784 LParenLoc, EndLoc);
1785 }
1786
1787 /// Build a new OpenMP 'allocator' clause.
1788 ///
1789 /// By default, performs semantic analysis to build the new OpenMP clause.
1790 /// Subclasses may override this routine to provide different behavior.
1792 SourceLocation LParenLoc,
1793 SourceLocation EndLoc) {
1794 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1795 EndLoc);
1796 }
1797
1798 /// Build a new OpenMP 'collapse' clause.
1799 ///
1800 /// By default, performs semantic analysis to build the new OpenMP clause.
1801 /// Subclasses may override this routine to provide different behavior.
1803 SourceLocation LParenLoc,
1804 SourceLocation EndLoc) {
1805 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1806 LParenLoc, EndLoc);
1807 }
1808
1809 /// Build a new OpenMP 'default' clause.
1810 ///
1811 /// By default, performs semantic analysis to build the new OpenMP clause.
1812 /// Subclasses may override this routine to provide different behavior.
1814 SourceLocation StartLoc,
1815 SourceLocation LParenLoc,
1816 SourceLocation EndLoc) {
1818 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1819 }
1820
1821 /// Build a new OpenMP 'proc_bind' clause.
1822 ///
1823 /// By default, performs semantic analysis to build the new OpenMP clause.
1824 /// Subclasses may override this routine to provide different behavior.
1826 SourceLocation KindKwLoc,
1827 SourceLocation StartLoc,
1828 SourceLocation LParenLoc,
1829 SourceLocation EndLoc) {
1831 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1832 }
1833
1834 /// Build a new OpenMP 'schedule' clause.
1835 ///
1836 /// By default, performs semantic analysis to build the new OpenMP clause.
1837 /// Subclasses may override this routine to provide different behavior.
1840 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1841 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1842 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1844 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1845 CommaLoc, EndLoc);
1846 }
1847
1848 /// Build a new OpenMP 'ordered' clause.
1849 ///
1850 /// By default, performs semantic analysis to build the new OpenMP clause.
1851 /// Subclasses may override this routine to provide different behavior.
1853 SourceLocation EndLoc,
1854 SourceLocation LParenLoc, Expr *Num) {
1855 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1856 LParenLoc, Num);
1857 }
1858
1859 /// Build a new OpenMP 'private' clause.
1860 ///
1861 /// By default, performs semantic analysis to build the new OpenMP clause.
1862 /// Subclasses may override this routine to provide different behavior.
1864 SourceLocation StartLoc,
1865 SourceLocation LParenLoc,
1866 SourceLocation EndLoc) {
1867 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1868 LParenLoc, EndLoc);
1869 }
1870
1871 /// Build a new OpenMP 'firstprivate' clause.
1872 ///
1873 /// By default, performs semantic analysis to build the new OpenMP clause.
1874 /// Subclasses may override this routine to provide different behavior.
1876 SourceLocation StartLoc,
1877 SourceLocation LParenLoc,
1878 SourceLocation EndLoc) {
1879 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1880 LParenLoc, EndLoc);
1881 }
1882
1883 /// Build a new OpenMP 'lastprivate' clause.
1884 ///
1885 /// By default, performs semantic analysis to build the new OpenMP clause.
1886 /// Subclasses may override this routine to provide different behavior.
1889 SourceLocation LPKindLoc,
1890 SourceLocation ColonLoc,
1891 SourceLocation StartLoc,
1892 SourceLocation LParenLoc,
1893 SourceLocation EndLoc) {
1895 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1896 }
1897
1898 /// Build a new OpenMP 'shared' clause.
1899 ///
1900 /// By default, performs semantic analysis to build the new OpenMP clause.
1901 /// Subclasses may override this routine to provide different behavior.
1903 SourceLocation StartLoc,
1904 SourceLocation LParenLoc,
1905 SourceLocation EndLoc) {
1906 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1907 LParenLoc, EndLoc);
1908 }
1909
1910 /// Build a new OpenMP 'reduction' clause.
1911 ///
1912 /// By default, performs semantic analysis to build the new statement.
1913 /// Subclasses may override this routine to provide different behavior.
1916 SourceLocation StartLoc, SourceLocation LParenLoc,
1917 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1918 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1919 const DeclarationNameInfo &ReductionId,
1920 ArrayRef<Expr *> UnresolvedReductions) {
1922 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1923 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1924 }
1925
1926 /// Build a new OpenMP 'task_reduction' clause.
1927 ///
1928 /// By default, performs semantic analysis to build the new statement.
1929 /// Subclasses may override this routine to provide different behavior.
1931 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1932 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1933 CXXScopeSpec &ReductionIdScopeSpec,
1934 const DeclarationNameInfo &ReductionId,
1935 ArrayRef<Expr *> UnresolvedReductions) {
1937 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1938 ReductionId, UnresolvedReductions);
1939 }
1940
1941 /// Build a new OpenMP 'in_reduction' clause.
1942 ///
1943 /// By default, performs semantic analysis to build the new statement.
1944 /// Subclasses may override this routine to provide different behavior.
1945 OMPClause *
1947 SourceLocation LParenLoc, SourceLocation ColonLoc,
1948 SourceLocation EndLoc,
1949 CXXScopeSpec &ReductionIdScopeSpec,
1950 const DeclarationNameInfo &ReductionId,
1951 ArrayRef<Expr *> UnresolvedReductions) {
1953 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1954 ReductionId, UnresolvedReductions);
1955 }
1956
1957 /// Build a new OpenMP 'linear' 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 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1963 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1964 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1965 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1967 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1968 StepModifierLoc, EndLoc);
1969 }
1970
1971 /// Build a new OpenMP 'aligned' clause.
1972 ///
1973 /// By default, performs semantic analysis to build the new OpenMP clause.
1974 /// Subclasses may override this routine to provide different behavior.
1976 SourceLocation StartLoc,
1977 SourceLocation LParenLoc,
1978 SourceLocation ColonLoc,
1979 SourceLocation EndLoc) {
1981 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1982 }
1983
1984 /// Build a new OpenMP 'copyin' clause.
1985 ///
1986 /// By default, performs semantic analysis to build the new OpenMP clause.
1987 /// Subclasses may override this routine to provide different behavior.
1989 SourceLocation StartLoc,
1990 SourceLocation LParenLoc,
1991 SourceLocation EndLoc) {
1992 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1993 LParenLoc, EndLoc);
1994 }
1995
1996 /// Build a new OpenMP 'copyprivate' clause.
1997 ///
1998 /// By default, performs semantic analysis to build the new OpenMP clause.
1999 /// Subclasses may override this routine to provide different behavior.
2001 SourceLocation StartLoc,
2002 SourceLocation LParenLoc,
2003 SourceLocation EndLoc) {
2004 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2005 LParenLoc, EndLoc);
2006 }
2007
2008 /// Build a new OpenMP 'flush' pseudo clause.
2009 ///
2010 /// By default, performs semantic analysis to build the new OpenMP clause.
2011 /// Subclasses may override this routine to provide different behavior.
2013 SourceLocation StartLoc,
2014 SourceLocation LParenLoc,
2015 SourceLocation EndLoc) {
2016 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2017 LParenLoc, EndLoc);
2018 }
2019
2020 /// Build a new OpenMP 'depobj' pseudo clause.
2021 ///
2022 /// By default, performs semantic analysis to build the new OpenMP clause.
2023 /// Subclasses may override this routine to provide different behavior.
2025 SourceLocation LParenLoc,
2026 SourceLocation EndLoc) {
2027 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2028 LParenLoc, EndLoc);
2029 }
2030
2031 /// Build a new OpenMP 'depend' pseudo clause.
2032 ///
2033 /// By default, performs semantic analysis to build the new OpenMP clause.
2034 /// Subclasses may override this routine to provide different behavior.
2036 Expr *DepModifier, ArrayRef<Expr *> VarList,
2037 SourceLocation StartLoc,
2038 SourceLocation LParenLoc,
2039 SourceLocation EndLoc) {
2041 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2042 }
2043
2044 /// Build a new OpenMP 'device' clause.
2045 ///
2046 /// By default, performs semantic analysis to build the new statement.
2047 /// Subclasses may override this routine to provide different behavior.
2049 Expr *Device, SourceLocation StartLoc,
2050 SourceLocation LParenLoc,
2051 SourceLocation ModifierLoc,
2052 SourceLocation EndLoc) {
2054 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2055 }
2056
2057 /// Build a new OpenMP 'map' clause.
2058 ///
2059 /// By default, performs semantic analysis to build the new OpenMP clause.
2060 /// Subclasses may override this routine to provide different behavior.
2062 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2063 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2064 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2065 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2066 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2067 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2069 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2070 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2071 ColonLoc, VarList, Locs,
2072 /*NoDiagnose=*/false, UnresolvedMappers);
2073 }
2074
2075 /// Build a new OpenMP 'allocate' clause.
2076 ///
2077 /// By default, performs semantic analysis to build the new OpenMP clause.
2078 /// Subclasses may override this routine to provide different behavior.
2079 OMPClause *
2080 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2081 OpenMPAllocateClauseModifier FirstModifier,
2082 SourceLocation FirstModifierLoc,
2083 OpenMPAllocateClauseModifier SecondModifier,
2084 SourceLocation SecondModifierLoc,
2085 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2086 SourceLocation LParenLoc, SourceLocation ColonLoc,
2087 SourceLocation EndLoc) {
2089 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2090 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2091 }
2092
2093 /// Build a new OpenMP 'num_teams' clause.
2094 ///
2095 /// By default, performs semantic analysis to build the new statement.
2096 /// Subclasses may override this routine to provide different behavior.
2098 SourceLocation StartLoc,
2099 SourceLocation LParenLoc,
2100 SourceLocation EndLoc) {
2101 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2102 LParenLoc, EndLoc);
2103 }
2104
2105 /// Build a new OpenMP 'thread_limit' clause.
2106 ///
2107 /// By default, performs semantic analysis to build the new statement.
2108 /// Subclasses may override this routine to provide different behavior.
2110 SourceLocation StartLoc,
2111 SourceLocation LParenLoc,
2112 SourceLocation EndLoc) {
2113 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2114 LParenLoc, EndLoc);
2115 }
2116
2117 /// Build a new OpenMP 'priority' clause.
2118 ///
2119 /// By default, performs semantic analysis to build the new statement.
2120 /// Subclasses may override this routine to provide different behavior.
2122 SourceLocation LParenLoc,
2123 SourceLocation EndLoc) {
2124 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2125 LParenLoc, EndLoc);
2126 }
2127
2128 /// Build a new OpenMP 'grainsize' clause.
2129 ///
2130 /// By default, performs semantic analysis to build the new statement.
2131 /// Subclasses may override this routine to provide different behavior.
2133 Expr *Device, SourceLocation StartLoc,
2134 SourceLocation LParenLoc,
2135 SourceLocation ModifierLoc,
2136 SourceLocation EndLoc) {
2138 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2139 }
2140
2141 /// Build a new OpenMP 'num_tasks' clause.
2142 ///
2143 /// By default, performs semantic analysis to build the new statement.
2144 /// Subclasses may override this routine to provide different behavior.
2146 Expr *NumTasks, SourceLocation StartLoc,
2147 SourceLocation LParenLoc,
2148 SourceLocation ModifierLoc,
2149 SourceLocation EndLoc) {
2151 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2152 }
2153
2154 /// Build a new OpenMP 'hint' clause.
2155 ///
2156 /// By default, performs semantic analysis to build the new statement.
2157 /// Subclasses may override this routine to provide different behavior.
2159 SourceLocation LParenLoc,
2160 SourceLocation EndLoc) {
2161 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2162 EndLoc);
2163 }
2164
2165 /// Build a new OpenMP 'detach' clause.
2166 ///
2167 /// By default, performs semantic analysis to build the new statement.
2168 /// Subclasses may override this routine to provide different behavior.
2170 SourceLocation LParenLoc,
2171 SourceLocation EndLoc) {
2172 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2173 EndLoc);
2174 }
2175
2176 /// Build a new OpenMP 'dist_schedule' clause.
2177 ///
2178 /// By default, performs semantic analysis to build the new OpenMP clause.
2179 /// Subclasses may override this routine to provide different behavior.
2180 OMPClause *
2182 Expr *ChunkSize, SourceLocation StartLoc,
2183 SourceLocation LParenLoc, SourceLocation KindLoc,
2184 SourceLocation CommaLoc, SourceLocation EndLoc) {
2186 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2187 }
2188
2189 /// Build a new OpenMP 'to' clause.
2190 ///
2191 /// By default, performs semantic analysis to build the new statement.
2192 /// Subclasses may override this routine to provide different behavior.
2193 OMPClause *
2195 ArrayRef<SourceLocation> MotionModifiersLoc,
2196 CXXScopeSpec &MapperIdScopeSpec,
2197 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2198 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2199 ArrayRef<Expr *> UnresolvedMappers) {
2201 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2202 ColonLoc, VarList, Locs, UnresolvedMappers);
2203 }
2204
2205 /// Build a new OpenMP 'from' clause.
2206 ///
2207 /// By default, performs semantic analysis to build the new statement.
2208 /// Subclasses may override this routine to provide different behavior.
2209 OMPClause *
2211 ArrayRef<SourceLocation> MotionModifiersLoc,
2212 CXXScopeSpec &MapperIdScopeSpec,
2213 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2214 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2215 ArrayRef<Expr *> UnresolvedMappers) {
2217 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2218 ColonLoc, VarList, Locs, UnresolvedMappers);
2219 }
2220
2221 /// Build a new OpenMP 'use_device_ptr' clause.
2222 ///
2223 /// By default, performs semantic analysis to build the new OpenMP clause.
2224 /// Subclasses may override this routine to provide different behavior.
2226 const OMPVarListLocTy &Locs) {
2227 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2228 }
2229
2230 /// Build a new OpenMP 'use_device_addr' clause.
2231 ///
2232 /// By default, performs semantic analysis to build the new OpenMP clause.
2233 /// Subclasses may override this routine to provide different behavior.
2235 const OMPVarListLocTy &Locs) {
2236 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2237 }
2238
2239 /// Build a new OpenMP 'is_device_ptr' clause.
2240 ///
2241 /// By default, performs semantic analysis to build the new OpenMP clause.
2242 /// Subclasses may override this routine to provide different behavior.
2244 const OMPVarListLocTy &Locs) {
2245 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2246 }
2247
2248 /// Build a new OpenMP 'has_device_addr' clause.
2249 ///
2250 /// By default, performs semantic analysis to build the new OpenMP clause.
2251 /// Subclasses may override this routine to provide different behavior.
2253 const OMPVarListLocTy &Locs) {
2254 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2255 }
2256
2257 /// Build a new OpenMP 'defaultmap' clause.
2258 ///
2259 /// By default, performs semantic analysis to build the new OpenMP clause.
2260 /// Subclasses may override this routine to provide different behavior.
2263 SourceLocation StartLoc,
2264 SourceLocation LParenLoc,
2265 SourceLocation MLoc,
2266 SourceLocation KindLoc,
2267 SourceLocation EndLoc) {
2269 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2270 }
2271
2272 /// Build a new OpenMP 'nontemporal' clause.
2273 ///
2274 /// By default, performs semantic analysis to build the new OpenMP clause.
2275 /// Subclasses may override this routine to provide different behavior.
2277 SourceLocation StartLoc,
2278 SourceLocation LParenLoc,
2279 SourceLocation EndLoc) {
2280 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2281 LParenLoc, EndLoc);
2282 }
2283
2284 /// Build a new OpenMP 'inclusive' clause.
2285 ///
2286 /// By default, performs semantic analysis to build the new OpenMP clause.
2287 /// Subclasses may override this routine to provide different behavior.
2289 SourceLocation StartLoc,
2290 SourceLocation LParenLoc,
2291 SourceLocation EndLoc) {
2292 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2293 LParenLoc, EndLoc);
2294 }
2295
2296 /// Build a new OpenMP 'exclusive' clause.
2297 ///
2298 /// By default, performs semantic analysis to build the new OpenMP clause.
2299 /// Subclasses may override this routine to provide different behavior.
2301 SourceLocation StartLoc,
2302 SourceLocation LParenLoc,
2303 SourceLocation EndLoc) {
2304 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2305 LParenLoc, EndLoc);
2306 }
2307
2308 /// Build a new OpenMP 'uses_allocators' clause.
2309 ///
2310 /// By default, performs semantic analysis to build the new OpenMP clause.
2311 /// Subclasses may override this routine to provide different behavior.
2314 SourceLocation LParenLoc, SourceLocation EndLoc) {
2316 StartLoc, LParenLoc, EndLoc, Data);
2317 }
2318
2319 /// Build a new OpenMP 'affinity' clause.
2320 ///
2321 /// By default, performs semantic analysis to build the new OpenMP clause.
2322 /// Subclasses may override this routine to provide different behavior.
2324 SourceLocation LParenLoc,
2325 SourceLocation ColonLoc,
2326 SourceLocation EndLoc, Expr *Modifier,
2327 ArrayRef<Expr *> Locators) {
2329 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2330 }
2331
2332 /// Build a new OpenMP 'order' clause.
2333 ///
2334 /// By default, performs semantic analysis to build the new OpenMP clause.
2335 /// Subclasses may override this routine to provide different behavior.
2337 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2338 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2339 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2341 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2342 }
2343
2344 /// Build a new OpenMP 'init' 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 StartLoc,
2350 SourceLocation LParenLoc,
2351 SourceLocation VarLoc,
2352 SourceLocation EndLoc) {
2354 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2355 }
2356
2357 /// Build a new OpenMP 'use' clause.
2358 ///
2359 /// By default, performs semantic analysis to build the new OpenMP clause.
2360 /// Subclasses may override this routine to provide different behavior.
2362 SourceLocation LParenLoc,
2363 SourceLocation VarLoc, SourceLocation EndLoc) {
2364 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2365 LParenLoc, VarLoc, EndLoc);
2366 }
2367
2368 /// Build a new OpenMP 'destroy' 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 VarLoc,
2375 SourceLocation EndLoc) {
2377 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2378 }
2379
2380 /// Build a new OpenMP 'novariants' clause.
2381 ///
2382 /// By default, performs semantic analysis to build the new OpenMP clause.
2383 /// Subclasses may override this routine to provide different behavior.
2385 SourceLocation StartLoc,
2386 SourceLocation LParenLoc,
2387 SourceLocation EndLoc) {
2389 LParenLoc, EndLoc);
2390 }
2391
2392 /// Build a new OpenMP 'nocontext' clause.
2393 ///
2394 /// By default, performs semantic analysis to build the new OpenMP clause.
2395 /// Subclasses may override this routine to provide different behavior.
2397 SourceLocation LParenLoc,
2398 SourceLocation EndLoc) {
2400 LParenLoc, EndLoc);
2401 }
2402
2403 /// Build a new OpenMP 'filter' clause.
2404 ///
2405 /// By default, performs semantic analysis to build the new OpenMP clause.
2406 /// Subclasses may override this routine to provide different behavior.
2408 SourceLocation LParenLoc,
2409 SourceLocation EndLoc) {
2410 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2411 LParenLoc, EndLoc);
2412 }
2413
2414 /// Build a new OpenMP 'bind' 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 KindLoc,
2420 SourceLocation StartLoc,
2421 SourceLocation LParenLoc,
2422 SourceLocation EndLoc) {
2423 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2424 LParenLoc, EndLoc);
2425 }
2426
2427 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2428 ///
2429 /// By default, performs semantic analysis to build the new OpenMP clause.
2430 /// Subclasses may override this routine to provide different behavior.
2432 SourceLocation LParenLoc,
2433 SourceLocation EndLoc) {
2434 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2435 LParenLoc, EndLoc);
2436 }
2437
2438 /// Build a new OpenMP 'ompx_attribute' clause.
2439 ///
2440 /// By default, performs semantic analysis to build the new OpenMP clause.
2441 /// Subclasses may override this routine to provide different behavior.
2443 SourceLocation StartLoc,
2444 SourceLocation LParenLoc,
2445 SourceLocation EndLoc) {
2446 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2447 LParenLoc, EndLoc);
2448 }
2449
2450 /// Build a new OpenMP 'ompx_bare' clause.
2451 ///
2452 /// By default, performs semantic analysis to build the new OpenMP clause.
2453 /// Subclasses may override this routine to provide different behavior.
2455 SourceLocation EndLoc) {
2456 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2457 }
2458
2459 /// Build a new OpenMP 'align' clause.
2460 ///
2461 /// By default, performs semantic analysis to build the new OpenMP clause.
2462 /// Subclasses may override this routine to provide different behavior.
2464 SourceLocation LParenLoc,
2465 SourceLocation EndLoc) {
2466 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2467 EndLoc);
2468 }
2469
2470 /// Build a new OpenMP 'at' clause.
2471 ///
2472 /// By default, performs semantic analysis to build the new OpenMP clause.
2473 /// Subclasses may override this routine to provide different behavior.
2475 SourceLocation StartLoc,
2476 SourceLocation LParenLoc,
2477 SourceLocation EndLoc) {
2478 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2479 LParenLoc, EndLoc);
2480 }
2481
2482 /// Build a new OpenMP 'severity' clause.
2483 ///
2484 /// By default, performs semantic analysis to build the new OpenMP clause.
2485 /// Subclasses may override this routine to provide different behavior.
2487 SourceLocation KwLoc,
2488 SourceLocation StartLoc,
2489 SourceLocation LParenLoc,
2490 SourceLocation EndLoc) {
2491 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2492 LParenLoc, EndLoc);
2493 }
2494
2495 /// Build a new OpenMP 'message' clause.
2496 ///
2497 /// By default, performs semantic analysis to build the new OpenMP clause.
2498 /// Subclasses may override this routine to provide different behavior.
2500 SourceLocation LParenLoc,
2501 SourceLocation EndLoc) {
2502 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2503 EndLoc);
2504 }
2505
2506 /// Build a new OpenMP 'doacross' clause.
2507 ///
2508 /// By default, performs semantic analysis to build the new OpenMP clause.
2509 /// Subclasses may override this routine to provide different behavior.
2510 OMPClause *
2512 SourceLocation DepLoc, SourceLocation ColonLoc,
2513 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2514 SourceLocation LParenLoc, SourceLocation EndLoc) {
2516 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2517 }
2518
2519 /// Build a new OpenMP 'holds' clause.
2521 SourceLocation LParenLoc,
2522 SourceLocation EndLoc) {
2523 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2524 EndLoc);
2525 }
2526
2527 /// Rebuild the operand to an Objective-C \@synchronized statement.
2528 ///
2529 /// By default, performs semantic analysis to build the new statement.
2530 /// Subclasses may override this routine to provide different behavior.
2532 Expr *object) {
2533 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2534 }
2535
2536 /// Build a new Objective-C \@synchronized statement.
2537 ///
2538 /// By default, performs semantic analysis to build the new statement.
2539 /// Subclasses may override this routine to provide different behavior.
2541 Expr *Object, Stmt *Body) {
2542 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2543 }
2544
2545 /// Build a new Objective-C \@autoreleasepool statement.
2546 ///
2547 /// By default, performs semantic analysis to build the new statement.
2548 /// Subclasses may override this routine to provide different behavior.
2550 Stmt *Body) {
2551 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2552 }
2553
2554 /// Build a new Objective-C fast enumeration statement.
2555 ///
2556 /// By default, performs semantic analysis to build the new statement.
2557 /// Subclasses may override this routine to provide different behavior.
2559 Stmt *Element,
2560 Expr *Collection,
2561 SourceLocation RParenLoc,
2562 Stmt *Body) {
2564 ForLoc, Element, Collection, RParenLoc);
2565 if (ForEachStmt.isInvalid())
2566 return StmtError();
2567
2568 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2569 Body);
2570 }
2571
2572 /// Build a new C++ exception declaration.
2573 ///
2574 /// By default, performs semantic analysis to build the new decaration.
2575 /// Subclasses may override this routine to provide different behavior.
2578 SourceLocation StartLoc,
2579 SourceLocation IdLoc,
2580 IdentifierInfo *Id) {
2582 StartLoc, IdLoc, Id);
2583 if (Var)
2584 getSema().CurContext->addDecl(Var);
2585 return Var;
2586 }
2587
2588 /// Build a new C++ catch statement.
2589 ///
2590 /// By default, performs semantic analysis to build the new statement.
2591 /// Subclasses may override this routine to provide different behavior.
2593 VarDecl *ExceptionDecl,
2594 Stmt *Handler) {
2595 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2596 Handler));
2597 }
2598
2599 /// Build a new C++ try statement.
2600 ///
2601 /// By default, performs semantic analysis to build the new statement.
2602 /// Subclasses may override this routine to provide different behavior.
2604 ArrayRef<Stmt *> Handlers) {
2605 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2606 }
2607
2608 /// Build a new C++0x range-based for statement.
2609 ///
2610 /// By default, performs semantic analysis to build the new statement.
2611 /// Subclasses may override this routine to provide different behavior.
2613 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2614 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2615 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2616 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2617 // If we've just learned that the range is actually an Objective-C
2618 // collection, treat this as an Objective-C fast enumeration loop.
2619 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2620 if (RangeStmt->isSingleDecl()) {
2621 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2622 if (RangeVar->isInvalidDecl())
2623 return StmtError();
2624
2625 Expr *RangeExpr = RangeVar->getInit();
2626 if (!RangeExpr->isTypeDependent() &&
2627 RangeExpr->getType()->isObjCObjectPointerType()) {
2628 // FIXME: Support init-statements in Objective-C++20 ranged for
2629 // statement.
2630 if (Init) {
2631 return SemaRef.Diag(Init->getBeginLoc(),
2632 diag::err_objc_for_range_init_stmt)
2633 << Init->getSourceRange();
2634 }
2636 ForLoc, LoopVar, RangeExpr, RParenLoc);
2637 }
2638 }
2639 }
2640 }
2641
2643 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2644 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2645 }
2646
2647 /// Build a new C++0x range-based for statement.
2648 ///
2649 /// By default, performs semantic analysis to build the new statement.
2650 /// Subclasses may override this routine to provide different behavior.
2652 bool IsIfExists,
2653 NestedNameSpecifierLoc QualifierLoc,
2654 DeclarationNameInfo NameInfo,
2655 Stmt *Nested) {
2656 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2657 QualifierLoc, NameInfo, Nested);
2658 }
2659
2660 /// Attach body to a C++0x range-based for statement.
2661 ///
2662 /// By default, performs semantic analysis to finish the new statement.
2663 /// Subclasses may override this routine to provide different behavior.
2665 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2666 }
2667
2669 Stmt *TryBlock, Stmt *Handler) {
2670 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2671 }
2672
2674 Stmt *Block) {
2675 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2676 }
2677
2679 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2680 }
2681
2683 SourceLocation LParen,
2684 SourceLocation RParen,
2685 TypeSourceInfo *TSI) {
2686 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2687 TSI);
2688 }
2689
2690 /// Build a new predefined expression.
2691 ///
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
2695 return getSema().BuildPredefinedExpr(Loc, IK);
2696 }
2697
2698 /// Build a new expression that references a declaration.
2699 ///
2700 /// By default, performs semantic analysis to build the new expression.
2701 /// Subclasses may override this routine to provide different behavior.
2703 LookupResult &R,
2704 bool RequiresADL) {
2705 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2706 }
2707
2708
2709 /// Build a new expression that references a declaration.
2710 ///
2711 /// By default, performs semantic analysis to build the new expression.
2712 /// Subclasses may override this routine to provide different behavior.
2714 ValueDecl *VD,
2715 const DeclarationNameInfo &NameInfo,
2717 TemplateArgumentListInfo *TemplateArgs) {
2718 CXXScopeSpec SS;
2719 SS.Adopt(QualifierLoc);
2720 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2721 TemplateArgs);
2722 }
2723
2724 /// Build a new expression in parentheses.
2725 ///
2726 /// By default, performs semantic analysis to build the new expression.
2727 /// Subclasses may override this routine to provide different behavior.
2729 SourceLocation RParen) {
2730 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2731 }
2732
2733 /// Build a new pseudo-destructor expression.
2734 ///
2735 /// By default, performs semantic analysis to build the new expression.
2736 /// Subclasses may override this routine to provide different behavior.
2738 SourceLocation OperatorLoc,
2739 bool isArrow,
2740 CXXScopeSpec &SS,
2741 TypeSourceInfo *ScopeType,
2742 SourceLocation CCLoc,
2743 SourceLocation TildeLoc,
2744 PseudoDestructorTypeStorage Destroyed);
2745
2746 /// Build a new unary operator expression.
2747 ///
2748 /// By default, performs semantic analysis to build the new expression.
2749 /// Subclasses may override this routine to provide different behavior.
2752 Expr *SubExpr) {
2753 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2754 }
2755
2756 /// Build a new builtin offsetof expression.
2757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
2763 SourceLocation RParenLoc) {
2764 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2765 RParenLoc);
2766 }
2767
2768 /// Build a new sizeof, alignof or vec_step expression with a
2769 /// type argument.
2770 ///
2771 /// By default, performs semantic analysis to build the new expression.
2772 /// Subclasses may override this routine to provide different behavior.
2774 SourceLocation OpLoc,
2775 UnaryExprOrTypeTrait ExprKind,
2776 SourceRange R) {
2777 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2778 }
2779
2780 /// Build a new sizeof, alignof or vec step expression with an
2781 /// expression argument.
2782 ///
2783 /// By default, performs semantic analysis to build the new expression.
2784 /// Subclasses may override this routine to provide different behavior.
2786 UnaryExprOrTypeTrait ExprKind,
2787 SourceRange R) {
2789 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2790 if (Result.isInvalid())
2791 return ExprError();
2792
2793 return Result;
2794 }
2795
2796 /// Build a new array subscript expression.
2797 ///
2798 /// By default, performs semantic analysis to build the new expression.
2799 /// Subclasses may override this routine to provide different behavior.
2801 SourceLocation LBracketLoc,
2802 Expr *RHS,
2803 SourceLocation RBracketLoc) {
2804 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2805 LBracketLoc, RHS,
2806 RBracketLoc);
2807 }
2808
2809 /// Build a new matrix subscript expression.
2810 ///
2811 /// By default, performs semantic analysis to build the new expression.
2812 /// Subclasses may override this routine to provide different behavior.
2814 Expr *ColumnIdx,
2815 SourceLocation RBracketLoc) {
2816 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2817 RBracketLoc);
2818 }
2819
2820 /// Build a new array section expression.
2821 ///
2822 /// By default, performs semantic analysis to build the new expression.
2823 /// Subclasses may override this routine to provide different behavior.
2825 SourceLocation LBracketLoc,
2826 Expr *LowerBound,
2827 SourceLocation ColonLocFirst,
2828 SourceLocation ColonLocSecond,
2829 Expr *Length, Expr *Stride,
2830 SourceLocation RBracketLoc) {
2831 if (IsOMPArraySection)
2833 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2834 Stride, RBracketLoc);
2835
2836 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2837 "Stride/second colon not allowed for OpenACC");
2838
2840 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2841 }
2842
2843 /// Build a new array shaping expression.
2844 ///
2845 /// By default, performs semantic analysis to build the new expression.
2846 /// Subclasses may override this routine to provide different behavior.
2848 SourceLocation RParenLoc,
2849 ArrayRef<Expr *> Dims,
2850 ArrayRef<SourceRange> BracketsRanges) {
2852 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2853 }
2854
2855 /// Build a new iterator expression.
2856 ///
2857 /// By default, performs semantic analysis to build the new expression.
2858 /// Subclasses may override this routine to provide different behavior.
2861 SourceLocation RLoc,
2864 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2865 }
2866
2867 /// Build a new call expression.
2868 ///
2869 /// By default, performs semantic analysis to build the new expression.
2870 /// Subclasses may override this routine to provide different behavior.
2872 MultiExprArg Args,
2873 SourceLocation RParenLoc,
2874 Expr *ExecConfig = nullptr) {
2875 return getSema().ActOnCallExpr(
2876 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2877 }
2878
2880 MultiExprArg Args,
2881 SourceLocation RParenLoc) {
2883 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2884 }
2885
2886 /// Build a new member access expression.
2887 ///
2888 /// By default, performs semantic analysis to build the new expression.
2889 /// Subclasses may override this routine to provide different behavior.
2891 bool isArrow,
2892 NestedNameSpecifierLoc QualifierLoc,
2893 SourceLocation TemplateKWLoc,
2894 const DeclarationNameInfo &MemberNameInfo,
2896 NamedDecl *FoundDecl,
2897 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2898 NamedDecl *FirstQualifierInScope) {
2900 isArrow);
2901 if (!Member->getDeclName()) {
2902 // We have a reference to an unnamed field. This is always the
2903 // base of an anonymous struct/union member access, i.e. the
2904 // field is always of record type.
2905 assert(Member->getType()->isRecordType() &&
2906 "unnamed member not of record type?");
2907
2908 BaseResult =
2910 QualifierLoc.getNestedNameSpecifier(),
2911 FoundDecl, Member);
2912 if (BaseResult.isInvalid())
2913 return ExprError();
2914 Base = BaseResult.get();
2915
2916 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2917 // from the AST, so we need to re-insert them if needed (since
2918 // `BuildFieldRefereneExpr()` doesn't do this).
2919 if (!isArrow && Base->isPRValue()) {
2921 if (BaseResult.isInvalid())
2922 return ExprError();
2923 Base = BaseResult.get();
2924 }
2925
2926 CXXScopeSpec EmptySS;
2928 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2929 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2930 MemberNameInfo);
2931 }
2932
2933 CXXScopeSpec SS;
2934 SS.Adopt(QualifierLoc);
2935
2936 Base = BaseResult.get();
2937 if (Base->containsErrors())
2938 return ExprError();
2939
2940 QualType BaseType = Base->getType();
2941
2942 if (isArrow && !BaseType->isPointerType())
2943 return ExprError();
2944
2945 // FIXME: this involves duplicating earlier analysis in a lot of
2946 // cases; we should avoid this when possible.
2947 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2948 R.addDecl(FoundDecl);
2949 R.resolveKind();
2950
2951 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2952 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2953 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2954 ->getType()
2955 ->getPointeeType()
2956 ->getAsCXXRecordDecl()) {
2957 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2958 // In unevaluated contexts, an expression supposed to be a member access
2959 // might reference a member in an unrelated class.
2960 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2961 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2962 VK_LValue, Member->getLocation());
2963 }
2964 }
2965
2966 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2967 SS, TemplateKWLoc,
2968 FirstQualifierInScope,
2969 R, ExplicitTemplateArgs,
2970 /*S*/nullptr);
2971 }
2972
2973 /// Build a new binary operator expression.
2974 ///
2975 /// By default, performs semantic analysis to build the new expression.
2976 /// Subclasses may override this routine to provide different behavior.
2979 Expr *LHS, Expr *RHS) {
2980 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2981 }
2982
2983 /// Build a new rewritten operator expression.
2984 ///
2985 /// By default, performs semantic analysis to build the new expression.
2986 /// Subclasses may override this routine to provide different behavior.
2988 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2989 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2990 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2991 RHS, /*RequiresADL*/false);
2992 }
2993
2994 /// Build a new conditional operator 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 QuestionLoc,
3000 Expr *LHS,
3001 SourceLocation ColonLoc,
3002 Expr *RHS) {
3003 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3004 LHS, RHS);
3005 }
3006
3007 /// Build a new C-style cast expression.
3008 ///
3009 /// By default, performs semantic analysis to build the new expression.
3010 /// Subclasses may override this routine to provide different behavior.
3012 TypeSourceInfo *TInfo,
3013 SourceLocation RParenLoc,
3014 Expr *SubExpr) {
3015 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3016 SubExpr);
3017 }
3018
3019 /// Build a new compound literal expression.
3020 ///
3021 /// By default, performs semantic analysis to build the new expression.
3022 /// Subclasses may override this routine to provide different behavior.
3024 TypeSourceInfo *TInfo,
3025 SourceLocation RParenLoc,
3026 Expr *Init) {
3027 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3028 Init);
3029 }
3030
3031 /// Build a new extended vector element access expression.
3032 ///
3033 /// By default, performs semantic analysis to build the new expression.
3034 /// Subclasses may override this routine to provide different behavior.
3036 bool IsArrow,
3037 SourceLocation AccessorLoc,
3038 IdentifierInfo &Accessor) {
3039
3040 CXXScopeSpec SS;
3041 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3043 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3044 /*FirstQualifierInScope*/ nullptr, NameInfo,
3045 /* TemplateArgs */ nullptr,
3046 /*S*/ nullptr);
3047 }
3048
3049 /// Build a new initializer list expression.
3050 ///
3051 /// By default, performs semantic analysis to build the new expression.
3052 /// Subclasses may override this routine to provide different behavior.
3054 MultiExprArg Inits,
3055 SourceLocation RBraceLoc) {
3056 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3057 }
3058
3059 /// Build a new designated initializer expression.
3060 ///
3061 /// By default, performs semantic analysis to build the new expression.
3062 /// Subclasses may override this routine to provide different behavior.
3064 MultiExprArg ArrayExprs,
3065 SourceLocation EqualOrColonLoc,
3066 bool GNUSyntax,
3067 Expr *Init) {
3069 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3070 Init);
3071 if (Result.isInvalid())
3072 return ExprError();
3073
3074 return Result;
3075 }
3076
3077 /// Build a new value-initialized expression.
3078 ///
3079 /// By default, builds the implicit value initialization without performing
3080 /// any semantic analysis. Subclasses may override this routine to provide
3081 /// different behavior.
3083 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3084 }
3085
3086 /// Build a new \c va_arg expression.
3087 ///
3088 /// By default, performs semantic analysis to build the new expression.
3089 /// Subclasses may override this routine to provide different behavior.
3091 Expr *SubExpr, TypeSourceInfo *TInfo,
3092 SourceLocation RParenLoc) {
3093 return getSema().BuildVAArgExpr(BuiltinLoc,
3094 SubExpr, TInfo,
3095 RParenLoc);
3096 }
3097
3098 /// Build a new expression list in parentheses.
3099 ///
3100 /// By default, performs semantic analysis to build the new expression.
3101 /// Subclasses may override this routine to provide different behavior.
3103 MultiExprArg SubExprs,
3104 SourceLocation RParenLoc) {
3105 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3106 }
3107
3108 /// Build a new address-of-label expression.
3109 ///
3110 /// By default, performs semantic analysis, using the name of the label
3111 /// rather than attempting to map the label statement itself.
3112 /// Subclasses may override this routine to provide different behavior.
3114 SourceLocation LabelLoc, LabelDecl *Label) {
3115 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3116 }
3117
3118 /// Build a new GNU statement expression.
3119 ///
3120 /// By default, performs semantic analysis to build the new expression.
3121 /// Subclasses may override this routine to provide different behavior.
3123 SourceLocation RParenLoc, unsigned TemplateDepth) {
3124 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3125 TemplateDepth);
3126 }
3127
3128 /// Build a new __builtin_choose_expr expression.
3129 ///
3130 /// By default, performs semantic analysis to build the new expression.
3131 /// Subclasses may override this routine to provide different behavior.
3133 Expr *Cond, Expr *LHS, Expr *RHS,
3134 SourceLocation RParenLoc) {
3135 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3136 Cond, LHS, RHS,
3137 RParenLoc);
3138 }
3139
3140 /// Build a new generic selection expression with an expression predicate.
3141 ///
3142 /// By default, performs semantic analysis to build the new expression.
3143 /// Subclasses may override this routine to provide different behavior.
3145 SourceLocation DefaultLoc,
3146 SourceLocation RParenLoc,
3147 Expr *ControllingExpr,
3149 ArrayRef<Expr *> Exprs) {
3150 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3151 /*PredicateIsExpr=*/true,
3152 ControllingExpr, Types, Exprs);
3153 }
3154
3155 /// Build a new generic selection expression with a type predicate.
3156 ///
3157 /// By default, performs semantic analysis to build the new expression.
3158 /// Subclasses may override this routine to provide different behavior.
3160 SourceLocation DefaultLoc,
3161 SourceLocation RParenLoc,
3162 TypeSourceInfo *ControllingType,
3164 ArrayRef<Expr *> Exprs) {
3165 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3166 /*PredicateIsExpr=*/false,
3167 ControllingType, Types, Exprs);
3168 }
3169
3170 /// Build a new overloaded operator call expression.
3171 ///
3172 /// By default, performs semantic analysis to build the new expression.
3173 /// The semantic analysis provides the behavior of template instantiation,
3174 /// copying with transformations that turn what looks like an overloaded
3175 /// operator call into a use of a builtin operator, performing
3176 /// argument-dependent lookup, etc. Subclasses may override this routine to
3177 /// provide different behavior.
3179 SourceLocation OpLoc,
3180 SourceLocation CalleeLoc,
3181 bool RequiresADL,
3182 const UnresolvedSetImpl &Functions,
3183 Expr *First, Expr *Second);
3184
3185 /// Build a new C++ "named" cast expression, such as static_cast or
3186 /// reinterpret_cast.
3187 ///
3188 /// By default, this routine dispatches to one of the more-specific routines
3189 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3190 /// Subclasses may override this routine to provide different behavior.
3193 SourceLocation LAngleLoc,
3194 TypeSourceInfo *TInfo,
3195 SourceLocation RAngleLoc,
3196 SourceLocation LParenLoc,
3197 Expr *SubExpr,
3198 SourceLocation RParenLoc) {
3199 switch (Class) {
3200 case Stmt::CXXStaticCastExprClass:
3201 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3202 RAngleLoc, LParenLoc,
3203 SubExpr, RParenLoc);
3204
3205 case Stmt::CXXDynamicCastExprClass:
3206 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3207 RAngleLoc, LParenLoc,
3208 SubExpr, RParenLoc);
3209
3210 case Stmt::CXXReinterpretCastExprClass:
3211 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3212 RAngleLoc, LParenLoc,
3213 SubExpr,
3214 RParenLoc);
3215
3216 case Stmt::CXXConstCastExprClass:
3217 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3218 RAngleLoc, LParenLoc,
3219 SubExpr, RParenLoc);
3220
3221 case Stmt::CXXAddrspaceCastExprClass:
3222 return getDerived().RebuildCXXAddrspaceCastExpr(
3223 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3224
3225 default:
3226 llvm_unreachable("Invalid C++ named cast");
3227 }
3228 }
3229
3230 /// Build a new C++ static_cast expression.
3231 ///
3232 /// By default, performs semantic analysis to build the new expression.
3233 /// Subclasses may override this routine to provide different behavior.
3235 SourceLocation LAngleLoc,
3236 TypeSourceInfo *TInfo,
3237 SourceLocation RAngleLoc,
3238 SourceLocation LParenLoc,
3239 Expr *SubExpr,
3240 SourceLocation RParenLoc) {
3241 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3242 TInfo, SubExpr,
3243 SourceRange(LAngleLoc, RAngleLoc),
3244 SourceRange(LParenLoc, RParenLoc));
3245 }
3246
3247 /// Build a new C++ dynamic_cast expression.
3248 ///
3249 /// By default, performs semantic analysis to build the new expression.
3250 /// Subclasses may override this routine to provide different behavior.
3252 SourceLocation LAngleLoc,
3253 TypeSourceInfo *TInfo,
3254 SourceLocation RAngleLoc,
3255 SourceLocation LParenLoc,
3256 Expr *SubExpr,
3257 SourceLocation RParenLoc) {
3258 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3259 TInfo, SubExpr,
3260 SourceRange(LAngleLoc, RAngleLoc),
3261 SourceRange(LParenLoc, RParenLoc));
3262 }
3263
3264 /// Build a new C++ reinterpret_cast expression.
3265 ///
3266 /// By default, performs semantic analysis to build the new expression.
3267 /// Subclasses may override this routine to provide different behavior.
3269 SourceLocation LAngleLoc,
3270 TypeSourceInfo *TInfo,
3271 SourceLocation RAngleLoc,
3272 SourceLocation LParenLoc,
3273 Expr *SubExpr,
3274 SourceLocation RParenLoc) {
3275 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3276 TInfo, SubExpr,
3277 SourceRange(LAngleLoc, RAngleLoc),
3278 SourceRange(LParenLoc, RParenLoc));
3279 }
3280
3281 /// Build a new C++ const_cast expression.
3282 ///
3283 /// By default, performs semantic analysis to build the new expression.
3284 /// Subclasses may override this routine to provide different behavior.
3286 SourceLocation LAngleLoc,
3287 TypeSourceInfo *TInfo,
3288 SourceLocation RAngleLoc,
3289 SourceLocation LParenLoc,
3290 Expr *SubExpr,
3291 SourceLocation RParenLoc) {
3292 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3293 TInfo, SubExpr,
3294 SourceRange(LAngleLoc, RAngleLoc),
3295 SourceRange(LParenLoc, RParenLoc));
3296 }
3297
3300 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3301 SourceLocation LParenLoc, Expr *SubExpr,
3302 SourceLocation RParenLoc) {
3303 return getSema().BuildCXXNamedCast(
3304 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3305 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3306 }
3307
3308 /// Build a new C++ functional-style cast expression.
3309 ///
3310 /// By default, performs semantic analysis to build the new expression.
3311 /// Subclasses may override this routine to provide different behavior.
3313 SourceLocation LParenLoc,
3314 Expr *Sub,
3315 SourceLocation RParenLoc,
3316 bool ListInitialization) {
3317 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3318 // CXXParenListInitExpr. Pass its expanded arguments so that the
3319 // CXXParenListInitExpr can be rebuilt.
3320 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3322 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3323 RParenLoc, ListInitialization);
3324 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3325 MultiExprArg(&Sub, 1), RParenLoc,
3326 ListInitialization);
3327 }
3328
3329 /// Build a new C++ __builtin_bit_cast expression.
3330 ///
3331 /// By default, performs semantic analysis to build the new expression.
3332 /// Subclasses may override this routine to provide different behavior.
3334 TypeSourceInfo *TSI, Expr *Sub,
3335 SourceLocation RParenLoc) {
3336 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3337 }
3338
3339 /// Build a new C++ typeid(type) expression.
3340 ///
3341 /// By default, performs semantic analysis to build the new expression.
3342 /// Subclasses may override this routine to provide different behavior.
3344 SourceLocation TypeidLoc,
3345 TypeSourceInfo *Operand,
3346 SourceLocation RParenLoc) {
3347 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3348 RParenLoc);
3349 }
3350
3351
3352 /// Build a new C++ typeid(expr) expression.
3353 ///
3354 /// By default, performs semantic analysis to build the new expression.
3355 /// Subclasses may override this routine to provide different behavior.
3357 SourceLocation TypeidLoc,
3358 Expr *Operand,
3359 SourceLocation RParenLoc) {
3360 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3361 RParenLoc);
3362 }
3363
3364 /// Build a new C++ __uuidof(type) expression.
3365 ///
3366 /// By default, performs semantic analysis to build the new expression.
3367 /// Subclasses may override this routine to provide different behavior.
3369 TypeSourceInfo *Operand,
3370 SourceLocation RParenLoc) {
3371 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3372 }
3373
3374 /// Build a new C++ __uuidof(expr) expression.
3375 ///
3376 /// By default, performs semantic analysis to build the new expression.
3377 /// Subclasses may override this routine to provide different behavior.
3379 Expr *Operand, SourceLocation RParenLoc) {
3380 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3381 }
3382
3383 /// Build a new C++ "this" expression.
3384 ///
3385 /// By default, performs semantic analysis to build a new "this" expression.
3386 /// Subclasses may override this routine to provide different behavior.
3388 QualType ThisType,
3389 bool isImplicit) {
3390 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3391 return ExprError();
3392 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3393 }
3394
3395 /// Build a new C++ throw expression.
3396 ///
3397 /// By default, performs semantic analysis to build the new expression.
3398 /// Subclasses may override this routine to provide different behavior.
3400 bool IsThrownVariableInScope) {
3401 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3402 }
3403
3404 /// Build a new C++ default-argument expression.
3405 ///
3406 /// By default, builds a new default-argument expression, which does not
3407 /// require any semantic analysis. Subclasses may override this routine to
3408 /// provide different behavior.
3410 Expr *RewrittenExpr) {
3411 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3412 RewrittenExpr, getSema().CurContext);
3413 }
3414
3415 /// Build a new C++11 default-initialization expression.
3416 ///
3417 /// By default, builds a new default field initialization expression, which
3418 /// does not require any semantic analysis. Subclasses may override this
3419 /// routine to provide different behavior.
3421 FieldDecl *Field) {
3422 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3423 }
3424
3425 /// Build a new C++ zero-initialization expression.
3426 ///
3427 /// By default, performs semantic analysis to build the new expression.
3428 /// Subclasses may override this routine to provide different behavior.
3430 SourceLocation LParenLoc,
3431 SourceLocation RParenLoc) {
3432 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3433 /*ListInitialization=*/false);
3434 }
3435
3436 /// Build a new C++ "new" expression.
3437 ///
3438 /// By default, performs semantic analysis to build the new expression.
3439 /// Subclasses may override this routine to provide different behavior.
3441 SourceLocation PlacementLParen,
3442 MultiExprArg PlacementArgs,
3443 SourceLocation PlacementRParen,
3444 SourceRange TypeIdParens, QualType AllocatedType,
3445 TypeSourceInfo *AllocatedTypeInfo,
3446 std::optional<Expr *> ArraySize,
3447 SourceRange DirectInitRange, Expr *Initializer) {
3448 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3449 PlacementLParen,
3450 PlacementArgs,
3451 PlacementRParen,
3452 TypeIdParens,
3453 AllocatedType,
3454 AllocatedTypeInfo,
3455 ArraySize,
3456 DirectInitRange,
3457 Initializer);
3458 }
3459
3460 /// Build a new C++ "delete" expression.
3461 ///
3462 /// By default, performs semantic analysis to build the new expression.
3463 /// Subclasses may override this routine to provide different behavior.
3465 bool IsGlobalDelete,
3466 bool IsArrayForm,
3467 Expr *Operand) {
3468 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3469 Operand);
3470 }
3471
3472 /// Build a new type trait expression.
3473 ///
3474 /// By default, performs semantic analysis to build the new expression.
3475 /// Subclasses may override this routine to provide different behavior.
3477 SourceLocation StartLoc,
3479 SourceLocation RParenLoc) {
3480 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3481 }
3482
3483 /// Build a new array type trait expression.
3484 ///
3485 /// By default, performs semantic analysis to build the new expression.
3486 /// Subclasses may override this routine to provide different behavior.
3488 SourceLocation StartLoc,
3489 TypeSourceInfo *TSInfo,
3490 Expr *DimExpr,
3491 SourceLocation RParenLoc) {
3492 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3493 }
3494
3495 /// Build a new expression trait expression.
3496 ///
3497 /// By default, performs semantic analysis to build the new expression.
3498 /// Subclasses may override this routine to provide different behavior.
3500 SourceLocation StartLoc,
3501 Expr *Queried,
3502 SourceLocation RParenLoc) {
3503 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3504 }
3505
3506 /// Build a new (previously unresolved) declaration reference
3507 /// expression.
3508 ///
3509 /// By default, performs semantic analysis to build the new expression.
3510 /// Subclasses may override this routine to provide different behavior.
3512 NestedNameSpecifierLoc QualifierLoc,
3513 SourceLocation TemplateKWLoc,
3514 const DeclarationNameInfo &NameInfo,
3515 const TemplateArgumentListInfo *TemplateArgs,
3516 bool IsAddressOfOperand,
3517 TypeSourceInfo **RecoveryTSI) {
3518 CXXScopeSpec SS;
3519 SS.Adopt(QualifierLoc);
3520
3521 if (TemplateArgs || TemplateKWLoc.isValid())
3523 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3524
3526 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3527 }
3528
3529 /// Build a new template-id expression.
3530 ///
3531 /// By default, performs semantic analysis to build the new expression.
3532 /// Subclasses may override this routine to provide different behavior.
3534 SourceLocation TemplateKWLoc,
3535 LookupResult &R,
3536 bool RequiresADL,
3537 const TemplateArgumentListInfo *TemplateArgs) {
3538 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3539 TemplateArgs);
3540 }
3541
3542 /// Build a new object-construction expression.
3543 ///
3544 /// By default, performs semantic analysis to build the new expression.
3545 /// Subclasses may override this routine to provide different behavior.
3548 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3549 bool ListInitialization, bool StdInitListInitialization,
3550 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3551 SourceRange ParenRange) {
3552 // Reconstruct the constructor we originally found, which might be
3553 // different if this is a call to an inherited constructor.
3554 CXXConstructorDecl *FoundCtor = Constructor;
3555 if (Constructor->isInheritingConstructor())
3556 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3557
3558 SmallVector<Expr *, 8> ConvertedArgs;
3559 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3560 ConvertedArgs))
3561 return ExprError();
3562
3563 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3564 IsElidable,
3565 ConvertedArgs,
3566 HadMultipleCandidates,
3567 ListInitialization,
3568 StdInitListInitialization,
3569 RequiresZeroInit, ConstructKind,
3570 ParenRange);
3571 }
3572
3573 /// Build a new implicit construction via inherited constructor
3574 /// expression.
3576 CXXConstructorDecl *Constructor,
3577 bool ConstructsVBase,
3578 bool InheritedFromVBase) {
3580 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3581 }
3582
3583 /// Build a new object-construction expression.
3584 ///
3585 /// By default, performs semantic analysis to build the new expression.
3586 /// Subclasses may override this routine to provide different behavior.
3588 SourceLocation LParenOrBraceLoc,
3589 MultiExprArg Args,
3590 SourceLocation RParenOrBraceLoc,
3591 bool ListInitialization) {
3593 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3594 }
3595
3596 /// Build a new object-construction expression.
3597 ///
3598 /// By default, performs semantic analysis to build the new expression.
3599 /// Subclasses may override this routine to provide different behavior.
3601 SourceLocation LParenLoc,
3602 MultiExprArg Args,
3603 SourceLocation RParenLoc,
3604 bool ListInitialization) {
3605 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3606 RParenLoc, ListInitialization);
3607 }
3608
3609 /// Build a new member reference expression.
3610 ///
3611 /// By default, performs semantic analysis to build the new expression.
3612 /// Subclasses may override this routine to provide different behavior.
3614 QualType BaseType,
3615 bool IsArrow,
3616 SourceLocation OperatorLoc,
3617 NestedNameSpecifierLoc QualifierLoc,
3618 SourceLocation TemplateKWLoc,
3619 NamedDecl *FirstQualifierInScope,
3620 const DeclarationNameInfo &MemberNameInfo,
3621 const TemplateArgumentListInfo *TemplateArgs) {
3622 CXXScopeSpec SS;
3623 SS.Adopt(QualifierLoc);
3624
3625 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3626 OperatorLoc, IsArrow,
3627 SS, TemplateKWLoc,
3628 FirstQualifierInScope,
3629 MemberNameInfo,
3630 TemplateArgs, /*S*/nullptr);
3631 }
3632
3633 /// Build a new member reference expression.
3634 ///
3635 /// By default, performs semantic analysis to build the new expression.
3636 /// Subclasses may override this routine to provide different behavior.
3638 SourceLocation OperatorLoc,
3639 bool IsArrow,
3640 NestedNameSpecifierLoc QualifierLoc,
3641 SourceLocation TemplateKWLoc,
3642 NamedDecl *FirstQualifierInScope,
3643 LookupResult &R,
3644 const TemplateArgumentListInfo *TemplateArgs) {
3645 CXXScopeSpec SS;
3646 SS.Adopt(QualifierLoc);
3647
3648 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3649 OperatorLoc, IsArrow,
3650 SS, TemplateKWLoc,
3651 FirstQualifierInScope,
3652 R, TemplateArgs, /*S*/nullptr);
3653 }
3654
3655 /// Build a new noexcept expression.
3656 ///
3657 /// By default, performs semantic analysis to build the new expression.
3658 /// Subclasses may override this routine to provide different behavior.
3660 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3661 }
3662
3663 /// Build a new expression to compute the length of a parameter pack.
3665 SourceLocation PackLoc,
3666 SourceLocation RParenLoc,
3667 std::optional<unsigned> Length,
3668 ArrayRef<TemplateArgument> PartialArgs) {
3669 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3670 RParenLoc, Length, PartialArgs);
3671 }
3672
3674 SourceLocation RSquareLoc,
3675 Expr *PackIdExpression, Expr *IndexExpr,
3676 ArrayRef<Expr *> ExpandedExprs,
3677 bool FullySubstituted = false) {
3678 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3679 IndexExpr, RSquareLoc, ExpandedExprs,
3680 FullySubstituted);
3681 }
3682
3683 /// Build a new expression representing a call to a source location
3684 /// builtin.
3685 ///
3686 /// By default, performs semantic analysis to build the new expression.
3687 /// Subclasses may override this routine to provide different behavior.
3689 SourceLocation BuiltinLoc,
3690 SourceLocation RPLoc,
3691 DeclContext *ParentContext) {
3692 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3693 ParentContext);
3694 }
3695
3696 /// Build a new Objective-C boxed expression.
3697 ///
3698 /// By default, performs semantic analysis to build the new expression.
3699 /// Subclasses may override this routine to provide different behavior.
3701 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3702 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3704 CXXScopeSpec SS;
3705 SS.Adopt(NNS);
3706 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3707 ConceptNameInfo,
3708 FoundDecl,
3709 NamedConcept, TALI);
3710 if (Result.isInvalid())
3711 return ExprError();
3712 return Result;
3713 }
3714
3715 /// \brief Build a new requires expression.
3716 ///
3717 /// By default, performs semantic analysis to build the new expression.
3718 /// Subclasses may override this routine to provide different behavior.
3721 SourceLocation LParenLoc,
3722 ArrayRef<ParmVarDecl *> LocalParameters,
3723 SourceLocation RParenLoc,
3725 SourceLocation ClosingBraceLoc) {
3726 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3727 LocalParameters, RParenLoc, Requirements,
3728 ClosingBraceLoc);
3729 }
3730
3734 return SemaRef.BuildTypeRequirement(SubstDiag);
3735 }
3736
3739 }
3740
3743 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3744 SourceLocation NoexceptLoc,
3746 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3747 std::move(Ret));
3748 }
3749
3751 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3753 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3754 std::move(Ret));
3755 }
3756
3758 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3759 const ASTConstraintSatisfaction &Satisfaction) {
3760 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3761 Satisfaction);
3762 }
3763
3765 return SemaRef.BuildNestedRequirement(Constraint);
3766 }
3767
3768 /// \brief Build a new Objective-C boxed expression.
3769 ///
3770 /// By default, performs semantic analysis to build the new expression.
3771 /// Subclasses may override this routine to provide different behavior.
3773 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3774 }
3775
3776 /// Build a new Objective-C array literal.
3777 ///
3778 /// By default, performs semantic analysis to build the new expression.
3779 /// Subclasses may override this routine to provide different behavior.
3781 Expr **Elements, unsigned NumElements) {
3783 Range, MultiExprArg(Elements, NumElements));
3784 }
3785
3787 Expr *Base, Expr *Key,
3788 ObjCMethodDecl *getterMethod,
3789 ObjCMethodDecl *setterMethod) {
3791 RB, Base, Key, getterMethod, setterMethod);
3792 }
3793
3794 /// Build a new Objective-C dictionary literal.
3795 ///
3796 /// By default, performs semantic analysis to build the new expression.
3797 /// Subclasses may override this routine to provide different behavior.
3800 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3801 }
3802
3803 /// Build a new Objective-C \@encode expression.
3804 ///
3805 /// By default, performs semantic analysis to build the new expression.
3806 /// Subclasses may override this routine to provide different behavior.
3808 TypeSourceInfo *EncodeTypeInfo,
3809 SourceLocation RParenLoc) {
3810 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3811 RParenLoc);
3812 }
3813
3814 /// Build a new Objective-C class message.
3816 Selector Sel,
3817 ArrayRef<SourceLocation> SelectorLocs,
3818 ObjCMethodDecl *Method,
3819 SourceLocation LBracLoc,
3820 MultiExprArg Args,
3821 SourceLocation RBracLoc) {
3823 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3824 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3825 RBracLoc, Args);
3826 }
3827
3828 /// Build a new Objective-C instance message.
3830 Selector Sel,
3831 ArrayRef<SourceLocation> SelectorLocs,
3832 ObjCMethodDecl *Method,
3833 SourceLocation LBracLoc,
3834 MultiExprArg Args,
3835 SourceLocation RBracLoc) {
3836 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3837 /*SuperLoc=*/SourceLocation(),
3838 Sel, Method, LBracLoc,
3839 SelectorLocs, RBracLoc, Args);
3840 }
3841
3842 /// Build a new Objective-C instance/class message to 'super'.
3844 Selector Sel,
3845 ArrayRef<SourceLocation> SelectorLocs,
3846 QualType SuperType,
3847 ObjCMethodDecl *Method,
3848 SourceLocation LBracLoc,
3849 MultiExprArg Args,
3850 SourceLocation RBracLoc) {
3851 return Method->isInstanceMethod()
3853 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3854 SelectorLocs, RBracLoc, Args)
3855 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3856 Sel, Method, LBracLoc,
3857 SelectorLocs, RBracLoc, Args);
3858 }
3859
3860 /// Build a new Objective-C ivar reference expression.
3861 ///
3862 /// By default, performs semantic analysis to build the new expression.
3863 /// Subclasses may override this routine to provide different behavior.
3865 SourceLocation IvarLoc,
3866 bool IsArrow, bool IsFreeIvar) {
3867 CXXScopeSpec SS;
3868 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3870 BaseArg, BaseArg->getType(),
3871 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3872 /*FirstQualifierInScope=*/nullptr, NameInfo,
3873 /*TemplateArgs=*/nullptr,
3874 /*S=*/nullptr);
3875 if (IsFreeIvar && Result.isUsable())
3876 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3877 return Result;
3878 }
3879
3880 /// Build a new Objective-C property reference expression.
3881 ///
3882 /// By default, performs semantic analysis to build the new expression.
3883 /// Subclasses may override this routine to provide different behavior.
3886 SourceLocation PropertyLoc) {
3887 CXXScopeSpec SS;
3888 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3889 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3890 /*FIXME:*/PropertyLoc,
3891 /*IsArrow=*/false,
3892 SS, SourceLocation(),
3893 /*FirstQualifierInScope=*/nullptr,
3894 NameInfo,
3895 /*TemplateArgs=*/nullptr,
3896 /*S=*/nullptr);
3897 }
3898
3899 /// Build a new Objective-C property reference expression.
3900 ///
3901 /// By default, performs semantic analysis to build the new expression.
3902 /// Subclasses may override this routine to provide different behavior.
3904 ObjCMethodDecl *Getter,
3905 ObjCMethodDecl *Setter,
3906 SourceLocation PropertyLoc) {
3907 // Since these expressions can only be value-dependent, we do not
3908 // need to perform semantic analysis again.
3909 return Owned(
3910 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3912 PropertyLoc, Base));
3913 }
3914
3915 /// Build a new Objective-C "isa" expression.
3916 ///
3917 /// By default, performs semantic analysis to build the new expression.
3918 /// Subclasses may override this routine to provide different behavior.
3920 SourceLocation OpLoc, bool IsArrow) {
3921 CXXScopeSpec SS;
3922 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3923 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3924 OpLoc, IsArrow,
3925 SS, SourceLocation(),
3926 /*FirstQualifierInScope=*/nullptr,
3927 NameInfo,
3928 /*TemplateArgs=*/nullptr,
3929 /*S=*/nullptr);
3930 }
3931
3932 /// Build a new shuffle vector expression.
3933 ///
3934 /// By default, performs semantic analysis to build the new expression.
3935 /// Subclasses may override this routine to provide different behavior.
3937 MultiExprArg SubExprs,
3938 SourceLocation RParenLoc) {
3939 // Find the declaration for __builtin_shufflevector
3940 const IdentifierInfo &Name
3941 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3943 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3944 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3945
3946 // Build a reference to the __builtin_shufflevector builtin
3947 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3948 Expr *Callee = new (SemaRef.Context)
3949 DeclRefExpr(SemaRef.Context, Builtin, false,
3950 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3951 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3952 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3953 CK_BuiltinFnToFnPtr).get();
3954
3955 // Build the CallExpr
3956 ExprResult TheCall = CallExpr::Create(
3957 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3958 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3960
3961 // Type-check the __builtin_shufflevector expression.
3962 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3963 }
3964
3965 /// Build a new convert vector expression.
3967 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3968 SourceLocation RParenLoc) {
3969 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3970 }
3971
3972 /// Build a new template argument pack expansion.
3973 ///
3974 /// By default, performs semantic analysis to build a new pack expansion
3975 /// for a template argument. Subclasses may override this routine to provide
3976 /// different behavior.
3979 std::optional<unsigned> NumExpansions) {
3980 switch (Pattern.getArgument().getKind()) {
3984 EllipsisLoc, NumExpansions);
3985 if (Result.isInvalid())
3986 return TemplateArgumentLoc();
3987
3988 return TemplateArgumentLoc(Result.get(), Result.get());
3989 }
3990
3992 return TemplateArgumentLoc(
3995 NumExpansions),
3996 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3997 EllipsisLoc);
3998
4006 llvm_unreachable("Pack expansion pattern has no parameter packs");
4007
4009 if (TypeSourceInfo *Expansion
4010 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4011 EllipsisLoc,
4012 NumExpansions))
4013 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4014 Expansion);
4015 break;
4016 }
4017
4018 return TemplateArgumentLoc();
4019 }
4020
4021 /// Build a new expression pack expansion.
4022 ///
4023 /// By default, performs semantic analysis to build a new pack expansion
4024 /// for an expression. Subclasses may override this routine to provide
4025 /// different behavior.
4027 std::optional<unsigned> NumExpansions) {
4028 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4029 }
4030
4031 /// Build a new C++1z fold-expression.
4032 ///
4033 /// By default, performs semantic analysis in order to build a new fold
4034 /// expression.
4036 SourceLocation LParenLoc, Expr *LHS,
4037 BinaryOperatorKind Operator,
4038 SourceLocation EllipsisLoc, Expr *RHS,
4039 SourceLocation RParenLoc,
4040 std::optional<unsigned> NumExpansions) {
4041 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4042 EllipsisLoc, RHS, RParenLoc,
4043 NumExpansions);
4044 }
4045
4047 LambdaScopeInfo *LSI) {
4048 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4049 if (Expr *Init = PVD->getInit())
4051 Init->containsUnexpandedParameterPack();
4052 else if (PVD->hasUninstantiatedDefaultArg())
4054 PVD->getUninstantiatedDefaultArg()
4055 ->containsUnexpandedParameterPack();
4056 }
4057 return getSema().BuildLambdaExpr(StartLoc, EndLoc, LSI);
4058 }
4059
4060 /// Build an empty C++1z fold-expression with the given operator.
4061 ///
4062 /// By default, produces the fallback value for the fold-expression, or
4063 /// produce an error if there is no fallback value.
4065 BinaryOperatorKind Operator) {
4066 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4067 }
4068
4069 /// Build a new atomic operation expression.
4070 ///
4071 /// By default, performs semantic analysis to build the new expression.
4072 /// Subclasses may override this routine to provide different behavior.
4075 SourceLocation RParenLoc) {
4076 // Use this for all of the locations, since we don't know the difference
4077 // between the call and the expr at this point.
4078 SourceRange Range{BuiltinLoc, RParenLoc};
4079 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4081 }
4082
4084 ArrayRef<Expr *> SubExprs, QualType Type) {
4085 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4086 }
4087
4089 SourceLocation BeginLoc,
4090 SourceLocation DirLoc,
4091 SourceLocation EndLoc,
4093 StmtResult StrBlock) {
4095 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4096 SourceLocation{}, EndLoc, Clauses, StrBlock);
4097 }
4098
4100 SourceLocation DirLoc,
4101 SourceLocation EndLoc,
4103 StmtResult Loop) {
4105 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{},
4106 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, Loop);
4107 }
4108
4110 SourceLocation BeginLoc,
4111 SourceLocation DirLoc,
4112 SourceLocation EndLoc,
4114 StmtResult Loop) {
4116 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4117 SourceLocation{}, EndLoc, Clauses, Loop);
4118 }
4119
4121 SourceLocation DirLoc,
4122 SourceLocation EndLoc,
4124 StmtResult StrBlock) {
4126 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4127 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4128 }
4129
4132 SourceLocation DirLoc, SourceLocation EndLoc,
4133 ArrayRef<OpenACCClause *> Clauses) {
4136 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4137 }
4138
4141 SourceLocation DirLoc, SourceLocation EndLoc,
4142 ArrayRef<OpenACCClause *> Clauses) {
4145 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4146 }
4147
4149 SourceLocation DirLoc,
4150 SourceLocation EndLoc,
4152 StmtResult StrBlock) {
4155 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4156 }
4157
4159 SourceLocation DirLoc,
4160 SourceLocation EndLoc,
4161 ArrayRef<OpenACCClause *> Clauses) {
4163 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4164 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4165 }
4166
4169 SourceLocation DirLoc, SourceLocation EndLoc,
4170 ArrayRef<OpenACCClause *> Clauses) {
4173 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4174 }
4175
4177 SourceLocation DirLoc,
4178 SourceLocation EndLoc,
4179 ArrayRef<OpenACCClause *> Clauses) {
4181 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4182 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4183 }
4184
4186 SourceLocation DirLoc,
4187 SourceLocation EndLoc,
4188 ArrayRef<OpenACCClause *> Clauses) {
4190 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4191 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4192 }
4193
4195 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4196 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4197 SourceLocation RParenLoc, SourceLocation EndLoc,
4198 ArrayRef<OpenACCClause *> Clauses) {
4200 Exprs.push_back(DevNumExpr);
4201 Exprs.insert(Exprs.end(), QueueIdExprs.begin(), QueueIdExprs.end());
4203 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4204 Exprs, RParenLoc, EndLoc, Clauses, {});
4205 }
4206
4208 return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc);
4209 }
4210
4211private:
4212 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4213 QualType ObjectType,
4214 NamedDecl *FirstQualifierInScope,
4215 CXXScopeSpec &SS);
4216
4217 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4218 QualType ObjectType,
4219 NamedDecl *FirstQualifierInScope,
4220 CXXScopeSpec &SS);
4221
4222 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4223 NamedDecl *FirstQualifierInScope,
4224 CXXScopeSpec &SS);
4225
4226 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4228 bool DeducibleTSTContext);
4229
4231 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4233
4235 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4236 OpenACCDirectiveKind DirKind,
4237 const OpenACCClause *OldClause);
4238};
4239
4240template <typename Derived>
4242 if (!S)
4243 return S;
4244
4245 switch (S->getStmtClass()) {
4246 case Stmt::NoStmtClass: break;
4247
4248 // Transform individual statement nodes
4249 // Pass SDK into statements that can produce a value
4250#define STMT(Node, Parent) \
4251 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4252#define VALUESTMT(Node, Parent) \
4253 case Stmt::Node##Class: \
4254 return getDerived().Transform##Node(cast<Node>(S), SDK);
4255#define ABSTRACT_STMT(Node)
4256#define EXPR(Node, Parent)
4257#include "clang/AST/StmtNodes.inc"
4258
4259 // Transform expressions by calling TransformExpr.
4260#define STMT(Node, Parent)
4261#define ABSTRACT_STMT(Stmt)
4262#define EXPR(Node, Parent) case Stmt::Node##Class:
4263#include "clang/AST/StmtNodes.inc"
4264 {
4265 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4266
4267 if (SDK == SDK_StmtExprResult)
4268 E = getSema().ActOnStmtExprResult(E);
4269 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4270 }
4271 }
4272
4273 return S;
4274}
4275
4276template<typename Derived>
4278 if (!S)
4279 return S;
4280
4281 switch (S->getClauseKind()) {
4282 default: break;
4283 // Transform individual clause nodes
4284#define GEN_CLANG_CLAUSE_CLASS
4285#define CLAUSE_CLASS(Enum, Str, Class) \
4286 case Enum: \
4287 return getDerived().Transform##Class(cast<Class>(S));
4288#include "llvm/Frontend/OpenMP/OMP.inc"
4289 }
4290
4291 return S;
4292}
4293
4294
4295template<typename Derived>
4297 if (!E)
4298 return E;
4299
4300 switch (E->getStmtClass()) {
4301 case Stmt::NoStmtClass: break;
4302#define STMT(Node, Parent) case Stmt::Node##Class: break;
4303#define ABSTRACT_STMT(Stmt)
4304#define EXPR(Node, Parent) \
4305 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4306#include "clang/AST/StmtNodes.inc"
4307 }
4308
4309 return E;
4310}
4311
4312template<typename Derived>
4314 bool NotCopyInit) {
4315 // Initializers are instantiated like expressions, except that various outer
4316 // layers are stripped.
4317 if (!Init)
4318 return Init;
4319
4320 if (auto *FE = dyn_cast<FullExpr>(Init))
4321 Init = FE->getSubExpr();
4322
4323 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4324 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4325 Init = OVE->getSourceExpr();
4326 }
4327
4328 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4329 Init = MTE->getSubExpr();
4330
4331 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4332 Init = Binder->getSubExpr();
4333
4334 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4335 Init = ICE->getSubExprAsWritten();
4336
4337 if (CXXStdInitializerListExpr *ILE =
4338 dyn_cast<CXXStdInitializerListExpr>(Init))
4339 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4340
4341 // If this is copy-initialization, we only need to reconstruct
4342 // InitListExprs. Other forms of copy-initialization will be a no-op if
4343 // the initializer is already the right type.
4344 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4345 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4346 return getDerived().TransformExpr(Init);
4347
4348 // Revert value-initialization back to empty parens.
4349 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4350 SourceRange Parens = VIE->getSourceRange();
4351 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4352 Parens.getEnd());
4353 }
4354
4355 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4356 if (isa<ImplicitValueInitExpr>(Init))
4357 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4358 SourceLocation());
4359
4360 // Revert initialization by constructor back to a parenthesized or braced list
4361 // of expressions. Any other form of initializer can just be reused directly.
4362 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4363 return getDerived().TransformExpr(Init);
4364
4365 // If the initialization implicitly converted an initializer list to a
4366 // std::initializer_list object, unwrap the std::initializer_list too.
4367 if (Construct && Construct->isStdInitListInitialization())
4368 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4369
4370 // Enter a list-init context if this was list initialization.
4373 Construct->isListInitialization());
4374
4375 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4376 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4377 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4378 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4379 SmallVector<Expr*, 8> NewArgs;
4380 bool ArgChanged = false;
4381 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4382 /*IsCall*/true, NewArgs, &ArgChanged))
4383 return ExprError();
4384
4385 // If this was list initialization, revert to syntactic list form.
4386 if (Construct->isListInitialization())
4387 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4388 Construct->getEndLoc());
4389
4390 // Build a ParenListExpr to represent anything else.
4392 if (Parens.isInvalid()) {
4393 // This was a variable declaration's initialization for which no initializer
4394 // was specified.
4395 assert(NewArgs.empty() &&
4396 "no parens or braces but have direct init with arguments?");
4397 return ExprEmpty();
4398 }
4399 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4400 Parens.getEnd());
4401}
4402
4403template<typename Derived>
4405 unsigned NumInputs,
4406 bool IsCall,
4407 SmallVectorImpl<Expr *> &Outputs,
4408 bool *ArgChanged) {
4409 for (unsigned I = 0; I != NumInputs; ++I) {
4410 // If requested, drop call arguments that need to be dropped.
4411 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4412 if (ArgChanged)
4413 *ArgChanged = true;
4414
4415 break;
4416 }
4417
4418 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4419 Expr *Pattern = Expansion->getPattern();
4420
4422 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4423 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4424
4425 // Determine whether the set of unexpanded parameter packs can and should
4426 // be expanded.
4427 bool Expand = true;
4428 bool RetainExpansion = false;
4429 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4430 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4431 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4432 Pattern->getSourceRange(),
4433 Unexpanded,
4434 Expand, RetainExpansion,
4435 NumExpansions))
4436 return true;
4437
4438 if (!Expand) {
4439 // The transform has determined that we should perform a simple
4440 // transformation on the pack expansion, producing another pack
4441 // expansion.
4442 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4443 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4444 if (OutPattern.isInvalid())
4445 return true;
4446
4447 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4448 Expansion->getEllipsisLoc(),
4449 NumExpansions);
4450 if (Out.isInvalid())
4451 return true;
4452
4453 if (ArgChanged)
4454 *ArgChanged = true;
4455 Outputs.push_back(Out.get());
4456 continue;
4457 }
4458
4459 // Record right away that the argument was changed. This needs
4460 // to happen even if the array expands to nothing.
4461 if (ArgChanged) *ArgChanged = true;
4462
4463 // The transform has determined that we should perform an elementwise
4464 // expansion of the pattern. Do so.
4465 for (unsigned I = 0; I != *NumExpansions; ++I) {
4466 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4467 ExprResult Out = getDerived().TransformExpr(Pattern);
4468 if (Out.isInvalid())
4469 return true;
4470
4471 if (Out.get()->containsUnexpandedParameterPack()) {
4472 Out = getDerived().RebuildPackExpansion(
4473 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4474 if (Out.isInvalid())
4475 return true;
4476 }
4477
4478 Outputs.push_back(Out.get());
4479 }
4480
4481 // If we're supposed to retain a pack expansion, do so by temporarily
4482 // forgetting the partially-substituted parameter pack.
4483 if (RetainExpansion) {
4484 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4485
4486 ExprResult Out = getDerived().TransformExpr(Pattern);
4487 if (Out.isInvalid())
4488 return true;
4489
4490 Out = getDerived().RebuildPackExpansion(
4491 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4492 if (Out.isInvalid())
4493 return true;
4494
4495 Outputs.push_back(Out.get());
4496 }
4497
4498 continue;
4499 }
4500
4502 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4503 : getDerived().TransformExpr(Inputs[I]);
4504 if (Result.isInvalid())
4505 return true;
4506
4507 if (Result.get() != Inputs[I] && ArgChanged)
4508 *ArgChanged = true;
4509
4510 Outputs.push_back(Result.get());
4511 }
4512
4513 return false;
4514}
4515
4516template <typename Derived>
4519 if (Var) {
4520 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4521 getDerived().TransformDefinition(Var->getLocation(), Var));
4522
4523 if (!ConditionVar)
4524 return Sema::ConditionError();
4525
4526 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4527 }
4528
4529 if (Expr) {
4530 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4531
4532 if (CondExpr.isInvalid())
4533 return Sema::ConditionError();
4534
4535 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4536 /*MissingOK=*/true);
4537 }
4538
4539 return Sema::ConditionResult();
4540}
4541
4542template <typename Derived>
4544 NestedNameSpecifierLoc NNS, QualType ObjectType,
4545 NamedDecl *FirstQualifierInScope) {
4547
4548 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4549 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4550 Qualifier = Qualifier.getPrefix())
4551 Qualifiers.push_back(Qualifier);
4552 };
4553 insertNNS(NNS);
4554
4555 CXXScopeSpec SS;
4556 while (!Qualifiers.empty()) {
4557 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4559
4560 switch (QNNS->getKind()) {
4564 ObjectType);
4565 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4566 SS, FirstQualifierInScope, false))
4567 return NestedNameSpecifierLoc();
4568 break;
4569 }
4570
4572 NamespaceDecl *NS =
4573 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4574 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4575 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4576 break;
4577 }
4578
4580 NamespaceAliasDecl *Alias =
4581 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4583 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4584 Q.getLocalEndLoc());
4585 break;
4586 }
4587
4589 // There is no meaningful transformation that one could perform on the
4590 // global scope.
4591 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4592 break;
4593
4595 CXXRecordDecl *RD =
4596 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4597 SourceLocation(), QNNS->getAsRecordDecl()));
4598 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4599 break;
4600 }
4601
4604 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4605 FirstQualifierInScope, SS);
4606
4607 if (!TL)
4608 return NestedNameSpecifierLoc();
4609
4610 QualType T = TL.getType();
4611 if (T->isDependentType() || T->isRecordType() ||
4612 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4613 if (T->isEnumeralType())
4614 SemaRef.Diag(TL.getBeginLoc(),
4615 diag::warn_cxx98_compat_enum_nested_name_spec);
4616
4617 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4618 SS.Adopt(ETL.getQualifierLoc());
4619 TL = ETL.getNamedTypeLoc();
4620 }
4621
4622 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4623 Q.getLocalEndLoc());
4624 break;
4625 }
4626 // If the nested-name-specifier is an invalid type def, don't emit an
4627 // error because a previous error should have already been emitted.
4629 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4630 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4631 << T << SS.getRange();
4632 }
4633 return NestedNameSpecifierLoc();
4634 }
4635 }
4636
4637 // The qualifier-in-scope and object type only apply to the leftmost entity.
4638 FirstQualifierInScope = nullptr;
4639 ObjectType = QualType();
4640 }
4641
4642 // Don't rebuild the nested-name-specifier if we don't have to.
4643 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4644 !getDerived().AlwaysRebuild())
4645 return NNS;
4646
4647 // If we can re-use the source-location data from the original
4648 // nested-name-specifier, do so.
4649 if (SS.location_size() == NNS.getDataLength() &&
4650 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4652
4653 // Allocate new nested-name-specifier location information.
4654 return SS.getWithLocInContext(SemaRef.Context);
4655}
4656
4657template<typename Derived>
4661 DeclarationName Name = NameInfo.getName();
4662 if (!Name)
4663 return DeclarationNameInfo();
4664
4665 switch (Name.getNameKind()) {
4673 return NameInfo;
4674
4676 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4677 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4678 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4679 if (!NewTemplate)
4680 return DeclarationNameInfo();
4681
4682 DeclarationNameInfo NewNameInfo(NameInfo);
4683 NewNameInfo.setName(
4685 return NewNameInfo;
4686 }
4687
4691 TypeSourceInfo *NewTInfo;
4692 CanQualType NewCanTy;
4693 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4694 NewTInfo = getDerived().TransformType(OldTInfo);
4695 if (!NewTInfo)
4696 return DeclarationNameInfo();
4697 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4698 }
4699 else {
4700 NewTInfo = nullptr;
4701 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4702 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4703 if (NewT.isNull())
4704 return DeclarationNameInfo();
4705 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4706 }
4707
4708 DeclarationName NewName
4709 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4710 NewCanTy);
4711 DeclarationNameInfo NewNameInfo(NameInfo);
4712 NewNameInfo.setName(NewName);
4713 NewNameInfo.setNamedTypeInfo(NewTInfo);
4714 return NewNameInfo;
4715 }
4716 }
4717
4718 llvm_unreachable("Unknown name kind.");
4719}
4720
4721template<typename Derived>
4724 TemplateName Name,
4725 SourceLocation NameLoc,
4726 QualType ObjectType,
4727 NamedDecl *FirstQualifierInScope,
4728 bool AllowInjectedClassName) {
4729 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4730 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4731 assert(Template && "qualified template name must refer to a template");
4732
4733 TemplateDecl *TransTemplate
4734 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4735 Template));
4736 if (!TransTemplate)
4737 return TemplateName();
4738
4739 if (!getDerived().AlwaysRebuild() &&
4740 SS.getScopeRep() == QTN->getQualifier() &&
4741 TransTemplate == Template)
4742 return Name;
4743
4744 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4745 TransTemplate);
4746 }
4747
4748 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4749 if (SS.getScopeRep()) {
4750 // These apply to the scope specifier, not the template.
4751 ObjectType = QualType();
4752 FirstQualifierInScope = nullptr;
4753 }
4754
4755 if (!getDerived().AlwaysRebuild() &&
4756 SS.getScopeRep() == DTN->getQualifier() &&
4757 ObjectType.isNull())
4758 return Name;
4759
4760 // FIXME: Preserve the location of the "template" keyword.
4761 SourceLocation TemplateKWLoc = NameLoc;
4762
4763 if (DTN->isIdentifier()) {
4764 return getDerived().RebuildTemplateName(SS,
4765 TemplateKWLoc,
4766 *DTN->getIdentifier(),
4767 NameLoc,
4768 ObjectType,
4769 FirstQualifierInScope,
4770 AllowInjectedClassName);
4771 }
4772
4773 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4774 DTN->getOperator(), NameLoc,
4775 ObjectType, AllowInjectedClassName);
4776 }
4777
4778 // FIXME: Try to preserve more of the TemplateName.
4779 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4780 TemplateDecl *TransTemplate
4781 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4782 Template));
4783 if (!TransTemplate)
4784 return TemplateName();
4785
4786 return getDerived().RebuildTemplateName(SS, /*TemplateKeyword=*/false,
4787 TransTemplate);
4788 }
4789
4791 = Name.getAsSubstTemplateTemplateParmPack()) {
4792 return getDerived().RebuildTemplateName(
4793 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4794 SubstPack->getIndex(), SubstPack->getFinal());
4795 }
4796
4797 // These should be getting filtered out before they reach the AST.
4798 llvm_unreachable("overloaded function decl survived to here");
4799}
4800
4801template<typename Derived>
4803 const TemplateArgument &Arg,
4804 TemplateArgumentLoc &Output) {
4805 Output = getSema().getTrivialTemplateArgumentLoc(
4806 Arg, QualType(), getDerived().getBaseLocation());
4807}
4808
4809template <typename Derived>
4811 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4812 bool Uneval) {
4813 const TemplateArgument &Arg = Input.getArgument();
4814 switch (Arg.getKind()) {
4817 llvm_unreachable("Unexpected TemplateArgument");
4818
4823 // Transform a resolved template argument straight to a resolved template
4824 // argument. We get here when substituting into an already-substituted
4825 // template type argument during concept satisfaction checking.
4827 QualType NewT = getDerived().TransformType(T);
4828 if (NewT.isNull())
4829 return true;
4830
4832 ? Arg.getAsDecl()
4833 : nullptr;
4834 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4835 getDerived().getBaseLocation(), D))
4836 : nullptr;
4837 if (D && !NewD)
4838 return true;
4839
4840 if (NewT == T && D == NewD)
4841 Output = Input;
4842 else if (Arg.getKind() == TemplateArgument::Integral)
4843 Output = TemplateArgumentLoc(
4844 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4846 else if (Arg.getKind() == TemplateArgument::NullPtr)
4847 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4849 else if (Arg.getKind() == TemplateArgument::Declaration)
4850 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4853 Output = TemplateArgumentLoc(
4854 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4856 else
4857 llvm_unreachable("unexpected template argument kind");
4858
4859 return false;
4860 }
4861
4863 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4864 if (!DI)
4865 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4866
4867 DI = getDerived().TransformType(DI);
4868 if (!DI)
4869 return true;
4870
4871 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4872 return false;
4873 }
4874
4876 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4877 if (QualifierLoc) {
4878 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4879 if (!QualifierLoc)
4880 return true;
4881 }
4882
4883 CXXScopeSpec SS;
4884 SS.Adopt(QualifierLoc);
4885 TemplateName Template = getDerived().TransformTemplateName(
4886 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4887 if (Template.isNull())
4888 return true;
4889
4890 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4891 QualifierLoc, Input.getTemplateNameLoc());
4892 return false;
4893 }
4894
4896 llvm_unreachable("Caller should expand pack expansions");
4897
4899 // Template argument expressions are constant expressions.
4901 getSema(),
4904 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4906
4907 Expr *InputExpr = Input.getSourceExpression();
4908 if (!InputExpr)
4909 InputExpr = Input.getArgument().getAsExpr();
4910
4911 ExprResult E = getDerived().TransformExpr(InputExpr);
4912 E = SemaRef.ActOnConstantExpression(E);
4913 if (E.isInvalid())
4914 return true;
4915 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4916 return false;
4917 }
4918 }
4919
4920 // Work around bogus GCC warning
4921 return true;
4922}
4923
4924/// Iterator adaptor that invents template argument location information
4925/// for each of the template arguments in its underlying iterator.
4926template<typename Derived, typename InputIterator>
4929 InputIterator Iter;
4930
4931public:
4934 typedef typename std::iterator_traits<InputIterator>::difference_type
4936 typedef std::input_iterator_tag iterator_category;
4937
4938 class pointer {
4940
4941 public:
4942 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4943
4944 const TemplateArgumentLoc *operator->() const { return &Arg; }
4945 };
4946
4948 InputIterator Iter)
4949 : Self(Self), Iter(Iter) { }
4950
4952 ++Iter;
4953 return *this;
4954 }
4955
4958 ++(*this);
4959 return Old;
4960 }
4961
4964 Self.InventTemplateArgumentLoc(*Iter, Result);
4965 return Result;
4966 }
4967
4968 pointer operator->() const { return pointer(**this); }
4969
4972 return X.Iter == Y.Iter;
4973 }
4974
4977 return X.Iter != Y.Iter;
4978 }
4979};
4980
4981template<typename Derived>
4982template<typename InputIterator>
4984 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4985 bool Uneval) {
4986 for (; First != Last; ++First) {
4989
4990 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4991 // Unpack argument packs, which we translate them into separate
4992 // arguments.
4993 // FIXME: We could do much better if we could guarantee that the
4994 // TemplateArgumentLocInfo for the pack expansion would be usable for
4995 // all of the template arguments in the argument pack.
4996 typedef TemplateArgumentLocInventIterator<Derived,
4998 PackLocIterator;
4999 if (TransformTemplateArguments(PackLocIterator(*this,
5000 In.getArgument().pack_begin()),
5001 PackLocIterator(*this,
5002 In.getArgument().pack_end()),
5003 Outputs, Uneval))
5004 return true;
5005
5006 continue;
5007 }
5008
5009 if (In.getArgument().isPackExpansion()) {
5010 // We have a pack expansion, for which we will be substituting into
5011 // the pattern.
5012 SourceLocation Ellipsis;
5013 std::optional<unsigned> OrigNumExpansions;
5014 TemplateArgumentLoc Pattern
5015 = getSema().getTemplateArgumentPackExpansionPattern(
5016 In, Ellipsis, OrigNumExpansions);
5017
5019 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5020 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5021
5022 // Determine whether the set of unexpanded parameter packs can and should
5023 // be expanded.
5024 bool Expand = true;
5025 bool RetainExpansion = false;
5026 std::optional<unsigned> NumExpansions = OrigNumExpansions;
5027 if (getDerived().TryExpandParameterPacks(Ellipsis,
5028 Pattern.getSourceRange(),
5029 Unexpanded,
5030 Expand,
5031 RetainExpansion,
5032 NumExpansions))
5033 return true;
5034
5035 if (!Expand) {
5036 // The transform has determined that we should perform a simple
5037 // transformation on the pack expansion, producing another pack
5038 // expansion.
5039 TemplateArgumentLoc OutPattern;
5040 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5041 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5042 return true;
5043
5044 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
5045 NumExpansions);
5046 if (Out.getArgument().isNull())
5047 return true;
5048
5049 Outputs.addArgument(Out);
5050 continue;
5051 }
5052
5053 // The transform has determined that we should perform an elementwise
5054 // expansion of the pattern. Do so.
5055 for (unsigned I = 0; I != *NumExpansions; ++I) {
5056 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5057
5058 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5059 return true;
5060
5061 if (Out.getArgument().containsUnexpandedParameterPack()) {
5062 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5063 OrigNumExpansions);
5064 if (Out.getArgument().isNull())
5065 return true;
5066 }
5067
5068 Outputs.addArgument(Out);
5069 }
5070
5071 // If we're supposed to retain a pack expansion, do so by temporarily
5072 // forgetting the partially-substituted parameter pack.
5073 if (RetainExpansion) {
5074 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5075
5076 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5077 return true;
5078
5079 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5080 OrigNumExpansions);
5081 if (Out.getArgument().isNull())
5082 return true;
5083
5084 Outputs.addArgument(Out);
5085 }
5086
5087 continue;
5088 }
5089
5090 // The simple case:
5091 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5092 return true;
5093
5094 Outputs.addArgument(Out);
5095 }
5096
5097 return false;
5098
5099}
5100
5101//===----------------------------------------------------------------------===//
5102// Type transformation