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