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