clang 19.0.0git
TreeTransform.h
Go to the documentation of this file.
1//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15
17#include "TypeLocBuilder.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
36#include "clang/Sema/Lookup.h"
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
806// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
807// amount of stack usage with clang.
808#define STMT(Node, Parent) \
809 LLVM_ATTRIBUTE_NOINLINE \
810 StmtResult Transform##Node(Node *S);
811#define VALUESTMT(Node, Parent) \
812 LLVM_ATTRIBUTE_NOINLINE \
813 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
814#define EXPR(Node, Parent) \
815 LLVM_ATTRIBUTE_NOINLINE \
816 ExprResult Transform##Node(Node *E);
817#define ABSTRACT_STMT(Stmt)
818#include "clang/AST/StmtNodes.inc"
819
820#define GEN_CLANG_CLAUSE_CLASS
821#define CLAUSE_CLASS(Enum, Str, Class) \
822 LLVM_ATTRIBUTE_NOINLINE \
823 OMPClause *Transform##Class(Class *S);
824#include "llvm/Frontend/OpenMP/OMP.inc"
825
826 /// Build a new qualified type given its unqualified type and type location.
827 ///
828 /// By default, this routine adds type qualifiers only to types that can
829 /// have qualifiers, and silently suppresses those qualifiers that are not
830 /// permitted. Subclasses may override this routine to provide different
831 /// behavior.
833
834 /// Build a new pointer type given its pointee type.
835 ///
836 /// By default, performs semantic analysis when building the pointer type.
837 /// Subclasses may override this routine to provide different behavior.
839
840 /// Build a new block pointer type given its pointee type.
841 ///
842 /// By default, performs semantic analysis when building the block pointer
843 /// type. Subclasses may override this routine to provide different behavior.
845
846 /// Build a new reference type given the type it references.
847 ///
848 /// By default, performs semantic analysis when building the
849 /// reference type. Subclasses may override this routine to provide
850 /// different behavior.
851 ///
852 /// \param LValue whether the type was written with an lvalue sigil
853 /// or an rvalue sigil.
855 bool LValue,
856 SourceLocation Sigil);
857
858 /// Build a new member pointer type given the pointee type and the
859 /// class type it refers into.
860 ///
861 /// By default, performs semantic analysis when building the member pointer
862 /// type. Subclasses may override this routine to provide different behavior.
864 SourceLocation Sigil);
865
867 SourceLocation ProtocolLAngleLoc,
869 ArrayRef<SourceLocation> ProtocolLocs,
870 SourceLocation ProtocolRAngleLoc);
871
872 /// Build an Objective-C object type.
873 ///
874 /// By default, performs semantic analysis when building the object type.
875 /// Subclasses may override this routine to provide different behavior.
878 SourceLocation TypeArgsLAngleLoc,
880 SourceLocation TypeArgsRAngleLoc,
881 SourceLocation ProtocolLAngleLoc,
883 ArrayRef<SourceLocation> ProtocolLocs,
884 SourceLocation ProtocolRAngleLoc);
885
886 /// Build a new Objective-C object pointer type given the pointee type.
887 ///
888 /// By default, directly builds the pointer type, with no additional semantic
889 /// analysis.
892
893 /// Build a new array type given the element type, size
894 /// modifier, size of the array (if known), size expression, and index type
895 /// qualifiers.
896 ///
897 /// By default, performs semantic analysis when building the array type.
898 /// Subclasses may override this routine to provide different behavior.
899 /// Also by default, all of the other Rebuild*Array
901 const llvm::APInt *Size, Expr *SizeExpr,
902 unsigned IndexTypeQuals, SourceRange BracketsRange);
903
904 /// Build a new constant array type given the element type, size
905 /// modifier, (known) size of the array, and index type qualifiers.
906 ///
907 /// By default, performs semantic analysis when building the array type.
908 /// Subclasses may override this routine to provide different behavior.
910 ArraySizeModifier SizeMod,
911 const llvm::APInt &Size, Expr *SizeExpr,
912 unsigned IndexTypeQuals,
913 SourceRange BracketsRange);
914
915 /// Build a new incomplete array type given the element type, size
916 /// modifier, and index type qualifiers.
917 ///
918 /// By default, performs semantic analysis when building the array type.
919 /// Subclasses may override this routine to provide different behavior.
921 ArraySizeModifier SizeMod,
922 unsigned IndexTypeQuals,
923 SourceRange BracketsRange);
924
925 /// Build a new variable-length array type given the element type,
926 /// size modifier, size expression, and index type qualifiers.
927 ///
928 /// By default, performs semantic analysis when building the array type.
929 /// Subclasses may override this routine to provide different behavior.
931 ArraySizeModifier SizeMod, Expr *SizeExpr,
932 unsigned IndexTypeQuals,
933 SourceRange BracketsRange);
934
935 /// Build a new dependent-sized array type given the element type,
936 /// size modifier, size expression, and index type qualifiers.
937 ///
938 /// By default, performs semantic analysis when building the array type.
939 /// Subclasses may override this routine to provide different behavior.
941 ArraySizeModifier SizeMod,
942 Expr *SizeExpr,
943 unsigned IndexTypeQuals,
944 SourceRange BracketsRange);
945
946 /// Build a new vector type given the element type and
947 /// number of elements.
948 ///
949 /// By default, performs semantic analysis when building the vector type.
950 /// Subclasses may override this routine to provide different behavior.
951 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
952 VectorKind VecKind);
953
954 /// Build a new potentially dependently-sized extended vector type
955 /// given the element type and number of elements.
956 ///
957 /// By default, performs semantic analysis when building the vector type.
958 /// Subclasses may override this routine to provide different behavior.
960 SourceLocation AttributeLoc, VectorKind);
961
962 /// Build a new extended vector type given the element type and
963 /// number of elements.
964 ///
965 /// By default, performs semantic analysis when building the vector type.
966 /// Subclasses may override this routine to provide different behavior.
967 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
968 SourceLocation AttributeLoc);
969
970 /// Build a new potentially dependently-sized extended vector type
971 /// given the element type and number of elements.
972 ///
973 /// By default, performs semantic analysis when building the vector type.
974 /// Subclasses may override this routine to provide different behavior.
976 Expr *SizeExpr,
977 SourceLocation AttributeLoc);
978
979 /// Build a new matrix type given the element type and dimensions.
980 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
981 unsigned NumColumns);
982
983 /// Build a new matrix type given the type and dependently-defined
984 /// dimensions.
986 Expr *ColumnExpr,
987 SourceLocation AttributeLoc);
988
989 /// Build a new DependentAddressSpaceType or return the pointee
990 /// type variable with the correct address space (retrieved from
991 /// AddrSpaceExpr) applied to it. The former will be returned in cases
992 /// where the address space remains dependent.
993 ///
994 /// By default, performs semantic analysis when building the type with address
995 /// space applied. Subclasses may override this routine to provide different
996 /// behavior.
998 Expr *AddrSpaceExpr,
999 SourceLocation AttributeLoc);
1000
1001 /// Build a new function type.
1002 ///
1003 /// By default, performs semantic analysis when building the function type.
1004 /// Subclasses may override this routine to provide different behavior.
1006 MutableArrayRef<QualType> ParamTypes,
1008
1009 /// Build a new unprototyped function type.
1011
1012 /// Rebuild an unresolved typename type, given the decl that
1013 /// the UnresolvedUsingTypenameDecl was transformed to.
1015
1016 /// Build a new type found via an alias.
1018 return SemaRef.Context.getUsingType(Found, Underlying);
1019 }
1020
1021 /// Build a new typedef type.
1023 return SemaRef.Context.getTypeDeclType(Typedef);
1024 }
1025
1026 /// Build a new MacroDefined type.
1028 const IdentifierInfo *MacroII) {
1029 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1030 }
1031
1032 /// Build a new class/struct/union type.
1035 }
1036
1037 /// Build a new Enum type.
1040 }
1041
1042 /// Build a new typeof(expr) type.
1043 ///
1044 /// By default, performs semantic analysis when building the typeof type.
1045 /// Subclasses may override this routine to provide different behavior.
1047 TypeOfKind Kind);
1048
1049 /// Build a new typeof(type) type.
1050 ///
1051 /// By default, builds a new TypeOfType with the given underlying type.
1053
1054 /// Build a new unary transform type.
1058
1059 /// Build a new C++11 decltype type.
1060 ///
1061 /// By default, performs semantic analysis when building the decltype type.
1062 /// Subclasses may override this routine to provide different behavior.
1064
1067 SourceLocation EllipsisLoc,
1068 bool FullySubstituted,
1069 ArrayRef<QualType> Expansions = {});
1070
1071 /// Build a new C++11 auto type.
1072 ///
1073 /// By default, builds a new AutoType with the given deduced type.
1075 ConceptDecl *TypeConstraintConcept,
1076 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1077 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1078 // which has been deduced to a dependent type into an undeduced 'auto', so
1079 // that we'll retry deduction after the transformation.
1080 return SemaRef.Context.getAutoType(Deduced, Keyword,
1081 /*IsDependent*/ false, /*IsPack=*/false,
1082 TypeConstraintConcept,
1083 TypeConstraintArgs);
1084 }
1085
1086 /// By default, builds a new DeducedTemplateSpecializationType with the given
1087 /// deduced type.
1089 QualType Deduced) {
1091 Template, Deduced, /*IsDependent*/ false);
1092 }
1093
1094 /// Build a new template specialization type.
1095 ///
1096 /// By default, performs semantic analysis when building the template
1097 /// specialization type. Subclasses may override this routine to provide
1098 /// different behavior.
1100 SourceLocation TemplateLoc,
1102
1103 /// Build a new parenthesized type.
1104 ///
1105 /// By default, builds a new ParenType type from the inner type.
1106 /// Subclasses may override this routine to provide different behavior.
1108 return SemaRef.BuildParenType(InnerType);
1109 }
1110
1111 /// Build a new qualified name type.
1112 ///
1113 /// By default, builds a new ElaboratedType type from the keyword,
1114 /// the nested-name-specifier and the named type.
1115 /// Subclasses may override this routine to provide different behavior.
1117 ElaboratedTypeKeyword Keyword,
1118 NestedNameSpecifierLoc QualifierLoc,
1119 QualType Named) {
1120 return SemaRef.Context.getElaboratedType(Keyword,
1121 QualifierLoc.getNestedNameSpecifier(),
1122 Named);
1123 }
1124
1125 /// Build a new typename type that refers to a template-id.
1126 ///
1127 /// By default, builds a new DependentNameType type from the
1128 /// nested-name-specifier and the given type. Subclasses may override
1129 /// this routine to provide different behavior.
1131 ElaboratedTypeKeyword Keyword,
1132 NestedNameSpecifierLoc QualifierLoc,
1133 SourceLocation TemplateKWLoc,
1134 const IdentifierInfo *Name,
1135 SourceLocation NameLoc,
1137 bool AllowInjectedClassName) {
1138 // Rebuild the template name.
1139 // TODO: avoid TemplateName abstraction
1140 CXXScopeSpec SS;
1141 SS.Adopt(QualifierLoc);
1142 TemplateName InstName = getDerived().RebuildTemplateName(
1143 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1144 AllowInjectedClassName);
1145
1146 if (InstName.isNull())
1147 return QualType();
1148
1149 // If it's still dependent, make a dependent specialization.
1150 if (InstName.getAsDependentTemplateName())
1152 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1153 Args.arguments());
1154
1155 // Otherwise, make an elaborated type wrapping a non-dependent
1156 // specialization.
1157 QualType T =
1158 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1159 if (T.isNull())
1160 return QualType();
1162 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1163 }
1164
1165 /// Build a new typename type that refers to an identifier.
1166 ///
1167 /// By default, performs semantic analysis when building the typename type
1168 /// (or elaborated type). Subclasses may override this routine to provide
1169 /// different behavior.
1171 SourceLocation KeywordLoc,
1172 NestedNameSpecifierLoc QualifierLoc,
1173 const IdentifierInfo *Id,
1174 SourceLocation IdLoc,
1175 bool DeducedTSTContext) {
1176 CXXScopeSpec SS;
1177 SS.Adopt(QualifierLoc);
1178
1179 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1180 // If the name is still dependent, just build a new dependent name type.
1181 if (!SemaRef.computeDeclContext(SS))
1182 return SemaRef.Context.getDependentNameType(Keyword,
1183 QualifierLoc.getNestedNameSpecifier(),
1184 Id);
1185 }
1186
1187 if (Keyword == ElaboratedTypeKeyword::None ||
1189 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1190 *Id, IdLoc, DeducedTSTContext);
1191 }
1192
1194
1195 // We had a dependent elaborated-type-specifier that has been transformed
1196 // into a non-dependent elaborated-type-specifier. Find the tag we're
1197 // referring to.
1199 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1200 if (!DC)
1201 return QualType();
1202
1204 return QualType();
1205
1206 TagDecl *Tag = nullptr;
1208 switch (Result.getResultKind()) {
1211 break;
1212
1214 Tag = Result.getAsSingle<TagDecl>();
1215 break;
1216
1219 llvm_unreachable("Tag lookup cannot find non-tags");
1220
1222 // Let the LookupResult structure handle ambiguities.
1223 return QualType();
1224 }
1225
1226 if (!Tag) {
1227 // Check where the name exists but isn't a tag type and use that to emit
1228 // better diagnostics.
1231 switch (Result.getResultKind()) {
1235 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1236 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1237 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1238 << SomeDecl << NTK << llvm::to_underlying(Kind);
1239 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1240 break;
1241 }
1242 default:
1243 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1244 << llvm::to_underlying(Kind) << Id << DC
1245 << QualifierLoc.getSourceRange();
1246 break;
1247 }
1248 return QualType();
1249 }
1250
1251 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1252 IdLoc, Id)) {
1253 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1254 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1255 return QualType();
1256 }
1257
1258 // Build the elaborated-type-specifier type.
1260 return SemaRef.Context.getElaboratedType(Keyword,
1261 QualifierLoc.getNestedNameSpecifier(),
1262 T);
1263 }
1264
1265 /// Build a new pack expansion type.
1266 ///
1267 /// By default, builds a new PackExpansionType type from the given pattern.
1268 /// Subclasses may override this routine to provide different behavior.
1270 SourceLocation EllipsisLoc,
1271 std::optional<unsigned> NumExpansions) {
1272 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1273 NumExpansions);
1274 }
1275
1276 /// Build a new atomic type given its value type.
1277 ///
1278 /// By default, performs semantic analysis when building the atomic type.
1279 /// Subclasses may override this routine to provide different behavior.
1281
1282 /// Build a new pipe type given its value type.
1284 bool isReadPipe);
1285
1286 /// Build a bit-precise int given its value type.
1287 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1289
1290 /// Build a dependent bit-precise int given its value type.
1291 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1293
1294 /// Build a new template name given a nested name specifier, a flag
1295 /// indicating whether the "template" keyword was provided, and the template
1296 /// that the template name refers to.
1297 ///
1298 /// By default, builds the new template name directly. Subclasses may override
1299 /// this routine to provide different behavior.
1301 bool TemplateKW,
1302 TemplateDecl *Template);
1303
1304 /// Build a new template name given a nested name specifier and the
1305 /// name that is referred to as a template.
1306 ///
1307 /// By default, performs semantic analysis to determine whether the name can
1308 /// be resolved to a specific template, then builds the appropriate kind of
1309 /// template name. Subclasses may override this routine to provide different
1310 /// behavior.
1312 SourceLocation TemplateKWLoc,
1313 const IdentifierInfo &Name,
1314 SourceLocation NameLoc, QualType ObjectType,
1315 NamedDecl *FirstQualifierInScope,
1316 bool AllowInjectedClassName);
1317
1318 /// Build a new template name given a nested name specifier and the
1319 /// overloaded operator name that is referred to as a template.
1320 ///
1321 /// By default, performs semantic analysis to determine whether the name can
1322 /// be resolved to a specific template, then builds the appropriate kind of
1323 /// template name. Subclasses may override this routine to provide different
1324 /// behavior.
1326 SourceLocation TemplateKWLoc,
1327 OverloadedOperatorKind Operator,
1328 SourceLocation NameLoc, QualType ObjectType,
1329 bool AllowInjectedClassName);
1330
1331 /// Build a new template name given a template template parameter pack
1332 /// and the
1333 ///
1334 /// By default, performs semantic analysis to determine whether the name can
1335 /// be resolved to a specific template, then builds the appropriate kind of
1336 /// template name. Subclasses may override this routine to provide different
1337 /// behavior.
1339 Decl *AssociatedDecl, unsigned Index,
1340 bool Final) {
1342 ArgPack, AssociatedDecl, Index, Final);
1343 }
1344
1345 /// Build a new compound statement.
1346 ///
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
1350 MultiStmtArg Statements,
1351 SourceLocation RBraceLoc,
1352 bool IsStmtExpr) {
1353 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1354 IsStmtExpr);
1355 }
1356
1357 /// Build a new case statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1362 Expr *LHS,
1363 SourceLocation EllipsisLoc,
1364 Expr *RHS,
1365 SourceLocation ColonLoc) {
1366 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1367 ColonLoc);
1368 }
1369
1370 /// Attach the body to a new case statement.
1371 ///
1372 /// By default, performs semantic analysis to build the new statement.
1373 /// Subclasses may override this routine to provide different behavior.
1375 getSema().ActOnCaseStmtBody(S, Body);
1376 return S;
1377 }
1378
1379 /// Build a new default statement.
1380 ///
1381 /// By default, performs semantic analysis to build the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
1384 SourceLocation ColonLoc,
1385 Stmt *SubStmt) {
1386 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1387 /*CurScope=*/nullptr);
1388 }
1389
1390 /// Build a new label statement.
1391 ///
1392 /// By default, performs semantic analysis to build the new statement.
1393 /// Subclasses may override this routine to provide different behavior.
1395 SourceLocation ColonLoc, Stmt *SubStmt) {
1396 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1397 }
1398
1399 /// Build a new attributed statement.
1400 ///
1401 /// By default, performs semantic analysis to build the new statement.
1402 /// Subclasses may override this routine to provide different behavior.
1405 Stmt *SubStmt) {
1407 return StmtError();
1408 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1409 }
1410
1411 /// Build a new "if" statement.
1412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
1416 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1417 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1418 SourceLocation ElseLoc, Stmt *Else) {
1419 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1420 Then, ElseLoc, Else);
1421 }
1422
1423 /// Start building a new switch statement.
1424 ///
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1428 SourceLocation LParenLoc, Stmt *Init,
1430 SourceLocation RParenLoc) {
1431 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1432 RParenLoc);
1433 }
1434
1435 /// Attach the body to the switch statement.
1436 ///
1437 /// By default, performs semantic analysis to build the new statement.
1438 /// Subclasses may override this routine to provide different behavior.
1440 Stmt *Switch, Stmt *Body) {
1441 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1442 }
1443
1444 /// Build a new while statement.
1445 ///
1446 /// By default, performs semantic analysis to build the new statement.
1447 /// Subclasses may override this routine to provide different behavior.
1450 SourceLocation RParenLoc, Stmt *Body) {
1451 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1452 }
1453
1454 /// Build a new do-while statement.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1459 SourceLocation WhileLoc, SourceLocation LParenLoc,
1460 Expr *Cond, SourceLocation RParenLoc) {
1461 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1462 Cond, RParenLoc);
1463 }
1464
1465 /// Build a new for statement.
1466 ///
1467 /// By default, performs semantic analysis to build the new statement.
1468 /// Subclasses may override this routine to provide different behavior.
1471 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1472 Stmt *Body) {
1473 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1474 Inc, RParenLoc, Body);
1475 }
1476
1477 /// Build a new goto statement.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1482 LabelDecl *Label) {
1483 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1484 }
1485
1486 /// Build a new indirect goto statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
1491 SourceLocation StarLoc,
1492 Expr *Target) {
1493 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1494 }
1495
1496 /// Build a new return statement.
1497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
1501 return getSema().BuildReturnStmt(ReturnLoc, Result);
1502 }
1503
1504 /// Build a new declaration statement.
1505 ///
1506 /// By default, performs semantic analysis to build the new statement.
1507 /// Subclasses may override this routine to provide different behavior.
1509 SourceLocation StartLoc, SourceLocation EndLoc) {
1511 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1512 }
1513
1514 /// Build a new inline asm statement.
1515 ///
1516 /// By default, performs semantic analysis to build the new statement.
1517 /// Subclasses may override this routine to provide different behavior.
1519 bool IsVolatile, unsigned NumOutputs,
1520 unsigned NumInputs, IdentifierInfo **Names,
1521 MultiExprArg Constraints, MultiExprArg Exprs,
1522 Expr *AsmString, MultiExprArg Clobbers,
1523 unsigned NumLabels,
1524 SourceLocation RParenLoc) {
1525 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1526 NumInputs, Names, Constraints, Exprs,
1527 AsmString, Clobbers, NumLabels, RParenLoc);
1528 }
1529
1530 /// Build a new MS style inline asm statement.
1531 ///
1532 /// By default, performs semantic analysis to build the new statement.
1533 /// Subclasses may override this routine to provide different behavior.
1535 ArrayRef<Token> AsmToks,
1536 StringRef AsmString,
1537 unsigned NumOutputs, unsigned NumInputs,
1538 ArrayRef<StringRef> Constraints,
1539 ArrayRef<StringRef> Clobbers,
1540 ArrayRef<Expr*> Exprs,
1541 SourceLocation EndLoc) {
1542 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1543 NumOutputs, NumInputs,
1544 Constraints, Clobbers, Exprs, EndLoc);
1545 }
1546
1547 /// Build a new co_return statement.
1548 ///
1549 /// By default, performs semantic analysis to build the new statement.
1550 /// Subclasses may override this routine to provide different behavior.
1552 bool IsImplicit) {
1553 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1554 }
1555
1556 /// Build a new co_await expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
1561 UnresolvedLookupExpr *OpCoawaitLookup,
1562 bool IsImplicit) {
1563 // This function rebuilds a coawait-expr given its operator.
1564 // For an explicit coawait-expr, the rebuild involves the full set
1565 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1566 // including calling await_transform().
1567 // For an implicit coawait-expr, we need to rebuild the "operator
1568 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1569 // This mirrors how the implicit CoawaitExpr is originally created
1570 // in Sema::ActOnCoroutineBodyStart().
1571 if (IsImplicit) {
1573 CoawaitLoc, Operand, OpCoawaitLookup);
1574 if (Suspend.isInvalid())
1575 return ExprError();
1576 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1577 Suspend.get(), true);
1578 }
1579
1580 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1581 OpCoawaitLookup);
1582 }
1583
1584 /// Build a new co_await expression.
1585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
1589 Expr *Result,
1590 UnresolvedLookupExpr *Lookup) {
1591 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1592 }
1593
1594 /// Build a new co_yield expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1599 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1600 }
1601
1603 return getSema().BuildCoroutineBodyStmt(Args);
1604 }
1605
1606 /// Build a new Objective-C \@try statement.
1607 ///
1608 /// By default, performs semantic analysis to build the new statement.
1609 /// Subclasses may override this routine to provide different behavior.
1611 Stmt *TryBody,
1612 MultiStmtArg CatchStmts,
1613 Stmt *Finally) {
1614 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1615 Finally);
1616 }
1617
1618 /// Rebuild an Objective-C exception declaration.
1619 ///
1620 /// By default, performs semantic analysis to build the new declaration.
1621 /// Subclasses may override this routine to provide different behavior.
1623 TypeSourceInfo *TInfo, QualType T) {
1625 TInfo, T, ExceptionDecl->getInnerLocStart(),
1626 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1627 }
1628
1629 /// Build a new Objective-C \@catch statement.
1630 ///
1631 /// By default, performs semantic analysis to build the new statement.
1632 /// Subclasses may override this routine to provide different behavior.
1634 SourceLocation RParenLoc,
1635 VarDecl *Var,
1636 Stmt *Body) {
1637 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1638 }
1639
1640 /// Build a new Objective-C \@finally statement.
1641 ///
1642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
1645 Stmt *Body) {
1646 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1647 }
1648
1649 /// Build a new Objective-C \@throw statement.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1654 Expr *Operand) {
1655 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1656 }
1657
1658 /// Build a new OpenMP Canonical loop.
1659 ///
1660 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1661 /// OMPCanonicalLoop.
1663 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1664 }
1665
1666 /// Build a new OpenMP executable directive.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1672 OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
1673 Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
1674 OpenMPDirectiveKind PrevMappedDirective = OMPD_unknown) {
1675
1677 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc,
1678 PrevMappedDirective);
1679 }
1680
1681 /// Build a new OpenMP 'if' clause.
1682 ///
1683 /// By default, performs semantic analysis to build the new OpenMP clause.
1684 /// Subclasses may override this routine to provide different behavior.
1686 Expr *Condition, SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation NameModifierLoc,
1689 SourceLocation ColonLoc,
1690 SourceLocation EndLoc) {
1692 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1693 EndLoc);
1694 }
1695
1696 /// Build a new OpenMP 'final' clause.
1697 ///
1698 /// By default, performs semantic analysis to build the new OpenMP clause.
1699 /// Subclasses may override this routine to provide different behavior.
1701 SourceLocation LParenLoc,
1702 SourceLocation EndLoc) {
1703 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1704 LParenLoc, EndLoc);
1705 }
1706
1707 /// Build a new OpenMP 'num_threads' clause.
1708 ///
1709 /// By default, performs semantic analysis to build the new OpenMP clause.
1710 /// Subclasses may override this routine to provide different behavior.
1712 SourceLocation StartLoc,
1713 SourceLocation LParenLoc,
1714 SourceLocation EndLoc) {
1715 return getSema().OpenMP().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1716 LParenLoc, EndLoc);
1717 }
1718
1719 /// Build a new OpenMP 'safelen' clause.
1720 ///
1721 /// By default, performs semantic analysis to build the new OpenMP clause.
1722 /// Subclasses may override this routine to provide different behavior.
1724 SourceLocation LParenLoc,
1725 SourceLocation EndLoc) {
1726 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1727 EndLoc);
1728 }
1729
1730 /// Build a new OpenMP 'simdlen' clause.
1731 ///
1732 /// By default, performs semantic analysis to build the new OpenMP clause.
1733 /// Subclasses may override this routine to provide different behavior.
1735 SourceLocation LParenLoc,
1736 SourceLocation EndLoc) {
1737 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1738 EndLoc);
1739 }
1740
1742 SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation EndLoc) {
1745 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1746 EndLoc);
1747 }
1748
1749 /// Build a new OpenMP 'full' clause.
1751 SourceLocation EndLoc) {
1752 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1753 }
1754
1755 /// Build a new OpenMP 'partial' clause.
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1760 LParenLoc, EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'allocator' clause.
1764 ///
1765 /// By default, performs semantic analysis to build the new OpenMP clause.
1766 /// Subclasses may override this routine to provide different behavior.
1768 SourceLocation LParenLoc,
1769 SourceLocation EndLoc) {
1770 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1771 EndLoc);
1772 }
1773
1774 /// Build a new OpenMP 'collapse' clause.
1775 ///
1776 /// By default, performs semantic analysis to build the new OpenMP clause.
1777 /// Subclasses may override this routine to provide different behavior.
1779 SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1782 LParenLoc, EndLoc);
1783 }
1784
1785 /// Build a new OpenMP 'default' clause.
1786 ///
1787 /// By default, performs semantic analysis to build the new OpenMP clause.
1788 /// Subclasses may override this routine to provide different behavior.
1790 SourceLocation StartLoc,
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1794 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1795 }
1796
1797 /// Build a new OpenMP 'proc_bind' clause.
1798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1802 SourceLocation KindKwLoc,
1803 SourceLocation StartLoc,
1804 SourceLocation LParenLoc,
1805 SourceLocation EndLoc) {
1807 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1808 }
1809
1810 /// Build a new OpenMP 'schedule' clause.
1811 ///
1812 /// By default, performs semantic analysis to build the new OpenMP clause.
1813 /// Subclasses may override this routine to provide different behavior.
1816 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1817 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1818 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1820 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1821 CommaLoc, EndLoc);
1822 }
1823
1824 /// Build a new OpenMP 'ordered' clause.
1825 ///
1826 /// By default, performs semantic analysis to build the new OpenMP clause.
1827 /// Subclasses may override this routine to provide different behavior.
1829 SourceLocation EndLoc,
1830 SourceLocation LParenLoc, Expr *Num) {
1831 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1832 LParenLoc, Num);
1833 }
1834
1835 /// Build a new OpenMP 'private' clause.
1836 ///
1837 /// By default, performs semantic analysis to build the new OpenMP clause.
1838 /// Subclasses may override this routine to provide different behavior.
1840 SourceLocation StartLoc,
1841 SourceLocation LParenLoc,
1842 SourceLocation EndLoc) {
1843 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1844 LParenLoc, EndLoc);
1845 }
1846
1847 /// Build a new OpenMP 'firstprivate' clause.
1848 ///
1849 /// By default, performs semantic analysis to build the new OpenMP clause.
1850 /// Subclasses may override this routine to provide different behavior.
1852 SourceLocation StartLoc,
1853 SourceLocation LParenLoc,
1854 SourceLocation EndLoc) {
1855 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1856 LParenLoc, EndLoc);
1857 }
1858
1859 /// Build a new OpenMP 'lastprivate' clause.
1860 ///
1861 /// By default, performs semantic analysis to build the new OpenMP clause.
1862 /// Subclasses may override this routine to provide different behavior.
1865 SourceLocation LPKindLoc,
1866 SourceLocation ColonLoc,
1867 SourceLocation StartLoc,
1868 SourceLocation LParenLoc,
1869 SourceLocation EndLoc) {
1871 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1872 }
1873
1874 /// Build a new OpenMP 'shared' clause.
1875 ///
1876 /// By default, performs semantic analysis to build the new OpenMP clause.
1877 /// Subclasses may override this routine to provide different behavior.
1879 SourceLocation StartLoc,
1880 SourceLocation LParenLoc,
1881 SourceLocation EndLoc) {
1882 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1883 LParenLoc, EndLoc);
1884 }
1885
1886 /// Build a new OpenMP 'reduction' clause.
1887 ///
1888 /// By default, performs semantic analysis to build the new statement.
1889 /// Subclasses may override this routine to provide different behavior.
1892 SourceLocation StartLoc, SourceLocation LParenLoc,
1893 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1894 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1895 const DeclarationNameInfo &ReductionId,
1896 ArrayRef<Expr *> UnresolvedReductions) {
1898 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1899 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1900 }
1901
1902 /// Build a new OpenMP 'task_reduction' clause.
1903 ///
1904 /// By default, performs semantic analysis to build the new statement.
1905 /// Subclasses may override this routine to provide different behavior.
1907 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1908 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1909 CXXScopeSpec &ReductionIdScopeSpec,
1910 const DeclarationNameInfo &ReductionId,
1911 ArrayRef<Expr *> UnresolvedReductions) {
1913 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1914 ReductionId, UnresolvedReductions);
1915 }
1916
1917 /// Build a new OpenMP 'in_reduction' clause.
1918 ///
1919 /// By default, performs semantic analysis to build the new statement.
1920 /// Subclasses may override this routine to provide different behavior.
1921 OMPClause *
1923 SourceLocation LParenLoc, SourceLocation ColonLoc,
1924 SourceLocation EndLoc,
1925 CXXScopeSpec &ReductionIdScopeSpec,
1926 const DeclarationNameInfo &ReductionId,
1927 ArrayRef<Expr *> UnresolvedReductions) {
1929 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1930 ReductionId, UnresolvedReductions);
1931 }
1932
1933 /// Build a new OpenMP 'linear' clause.
1934 ///
1935 /// By default, performs semantic analysis to build the new OpenMP clause.
1936 /// Subclasses may override this routine to provide different behavior.
1938 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1939 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1940 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1941 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1943 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1944 StepModifierLoc, EndLoc);
1945 }
1946
1947 /// Build a new OpenMP 'aligned' 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 SourceLocation StartLoc,
1953 SourceLocation LParenLoc,
1954 SourceLocation ColonLoc,
1955 SourceLocation EndLoc) {
1957 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1958 }
1959
1960 /// Build a new OpenMP 'copyin' clause.
1961 ///
1962 /// By default, performs semantic analysis to build the new OpenMP clause.
1963 /// Subclasses may override this routine to provide different behavior.
1965 SourceLocation StartLoc,
1966 SourceLocation LParenLoc,
1967 SourceLocation EndLoc) {
1968 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1969 LParenLoc, EndLoc);
1970 }
1971
1972 /// Build a new OpenMP 'copyprivate' clause.
1973 ///
1974 /// By default, performs semantic analysis to build the new OpenMP clause.
1975 /// Subclasses may override this routine to provide different behavior.
1977 SourceLocation StartLoc,
1978 SourceLocation LParenLoc,
1979 SourceLocation EndLoc) {
1980 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
1981 LParenLoc, EndLoc);
1982 }
1983
1984 /// Build a new OpenMP 'flush' pseudo clause.
1985 ///
1986 /// By default, performs semantic analysis to build the new OpenMP clause.
1987 /// Subclasses may override this routine to provide different behavior.
1989 SourceLocation StartLoc,
1990 SourceLocation LParenLoc,
1991 SourceLocation EndLoc) {
1992 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
1993 LParenLoc, EndLoc);
1994 }
1995
1996 /// Build a new OpenMP 'depobj' pseudo clause.
1997 ///
1998 /// By default, performs semantic analysis to build the new OpenMP clause.
1999 /// Subclasses may override this routine to provide different behavior.
2001 SourceLocation LParenLoc,
2002 SourceLocation EndLoc) {
2003 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2004 LParenLoc, EndLoc);
2005 }
2006
2007 /// Build a new OpenMP 'depend' pseudo clause.
2008 ///
2009 /// By default, performs semantic analysis to build the new OpenMP clause.
2010 /// Subclasses may override this routine to provide different behavior.
2012 Expr *DepModifier, ArrayRef<Expr *> VarList,
2013 SourceLocation StartLoc,
2014 SourceLocation LParenLoc,
2015 SourceLocation EndLoc) {
2017 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2018 }
2019
2020 /// Build a new OpenMP 'device' clause.
2021 ///
2022 /// By default, performs semantic analysis to build the new statement.
2023 /// Subclasses may override this routine to provide different behavior.
2025 Expr *Device, SourceLocation StartLoc,
2026 SourceLocation LParenLoc,
2027 SourceLocation ModifierLoc,
2028 SourceLocation EndLoc) {
2030 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2031 }
2032
2033 /// Build a new OpenMP 'map' clause.
2034 ///
2035 /// By default, performs semantic analysis to build the new OpenMP clause.
2036 /// Subclasses may override this routine to provide different behavior.
2038 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2039 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2040 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2041 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2042 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2043 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2045 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2046 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2047 ColonLoc, VarList, Locs,
2048 /*NoDiagnose=*/false, UnresolvedMappers);
2049 }
2050
2051 /// Build a new OpenMP 'allocate' clause.
2052 ///
2053 /// By default, performs semantic analysis to build the new OpenMP clause.
2054 /// Subclasses may override this routine to provide different behavior.
2056 SourceLocation StartLoc,
2057 SourceLocation LParenLoc,
2058 SourceLocation ColonLoc,
2059 SourceLocation EndLoc) {
2061 Allocate, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2062 }
2063
2064 /// Build a new OpenMP 'num_teams' clause.
2065 ///
2066 /// By default, performs semantic analysis to build the new statement.
2067 /// Subclasses may override this routine to provide different behavior.
2069 SourceLocation LParenLoc,
2070 SourceLocation EndLoc) {
2071 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc,
2072 LParenLoc, EndLoc);
2073 }
2074
2075 /// Build a new OpenMP 'thread_limit' clause.
2076 ///
2077 /// By default, performs semantic analysis to build the new statement.
2078 /// Subclasses may override this routine to provide different behavior.
2080 SourceLocation StartLoc,
2081 SourceLocation LParenLoc,
2082 SourceLocation EndLoc) {
2084 ThreadLimit, StartLoc, LParenLoc, EndLoc);
2085 }
2086
2087 /// Build a new OpenMP 'priority' clause.
2088 ///
2089 /// By default, performs semantic analysis to build the new statement.
2090 /// Subclasses may override this routine to provide different behavior.
2092 SourceLocation LParenLoc,
2093 SourceLocation EndLoc) {
2094 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2095 LParenLoc, EndLoc);
2096 }
2097
2098 /// Build a new OpenMP 'grainsize' clause.
2099 ///
2100 /// By default, performs semantic analysis to build the new statement.
2101 /// Subclasses may override this routine to provide different behavior.
2103 Expr *Device, SourceLocation StartLoc,
2104 SourceLocation LParenLoc,
2105 SourceLocation ModifierLoc,
2106 SourceLocation EndLoc) {
2108 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2109 }
2110
2111 /// Build a new OpenMP 'num_tasks' clause.
2112 ///
2113 /// By default, performs semantic analysis to build the new statement.
2114 /// Subclasses may override this routine to provide different behavior.
2116 Expr *NumTasks, SourceLocation StartLoc,
2117 SourceLocation LParenLoc,
2118 SourceLocation ModifierLoc,
2119 SourceLocation EndLoc) {
2121 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2122 }
2123
2124 /// Build a new OpenMP 'hint' clause.
2125 ///
2126 /// By default, performs semantic analysis to build the new statement.
2127 /// Subclasses may override this routine to provide different behavior.
2129 SourceLocation LParenLoc,
2130 SourceLocation EndLoc) {
2131 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2132 EndLoc);
2133 }
2134
2135 /// Build a new OpenMP 'detach' clause.
2136 ///
2137 /// By default, performs semantic analysis to build the new statement.
2138 /// Subclasses may override this routine to provide different behavior.
2140 SourceLocation LParenLoc,
2141 SourceLocation EndLoc) {
2142 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2143 EndLoc);
2144 }
2145
2146 /// Build a new OpenMP 'dist_schedule' clause.
2147 ///
2148 /// By default, performs semantic analysis to build the new OpenMP clause.
2149 /// Subclasses may override this routine to provide different behavior.
2150 OMPClause *
2152 Expr *ChunkSize, SourceLocation StartLoc,
2153 SourceLocation LParenLoc, SourceLocation KindLoc,
2154 SourceLocation CommaLoc, SourceLocation EndLoc) {
2156 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2157 }
2158
2159 /// Build a new OpenMP 'to' clause.
2160 ///
2161 /// By default, performs semantic analysis to build the new statement.
2162 /// Subclasses may override this routine to provide different behavior.
2163 OMPClause *
2165 ArrayRef<SourceLocation> MotionModifiersLoc,
2166 CXXScopeSpec &MapperIdScopeSpec,
2167 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2168 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2169 ArrayRef<Expr *> UnresolvedMappers) {
2171 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2172 ColonLoc, VarList, Locs, UnresolvedMappers);
2173 }
2174
2175 /// Build a new OpenMP 'from' clause.
2176 ///
2177 /// By default, performs semantic analysis to build the new statement.
2178 /// Subclasses may override this routine to provide different behavior.
2179 OMPClause *
2181 ArrayRef<SourceLocation> MotionModifiersLoc,
2182 CXXScopeSpec &MapperIdScopeSpec,
2183 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2184 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2185 ArrayRef<Expr *> UnresolvedMappers) {
2187 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2188 ColonLoc, VarList, Locs, UnresolvedMappers);
2189 }
2190
2191 /// Build a new OpenMP 'use_device_ptr' clause.
2192 ///
2193 /// By default, performs semantic analysis to build the new OpenMP clause.
2194 /// Subclasses may override this routine to provide different behavior.
2196 const OMPVarListLocTy &Locs) {
2197 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2198 }
2199
2200 /// Build a new OpenMP 'use_device_addr' clause.
2201 ///
2202 /// By default, performs semantic analysis to build the new OpenMP clause.
2203 /// Subclasses may override this routine to provide different behavior.
2205 const OMPVarListLocTy &Locs) {
2206 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2207 }
2208
2209 /// Build a new OpenMP 'is_device_ptr' clause.
2210 ///
2211 /// By default, performs semantic analysis to build the new OpenMP clause.
2212 /// Subclasses may override this routine to provide different behavior.
2214 const OMPVarListLocTy &Locs) {
2215 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2216 }
2217
2218 /// Build a new OpenMP 'has_device_addr' clause.
2219 ///
2220 /// By default, performs semantic analysis to build the new OpenMP clause.
2221 /// Subclasses may override this routine to provide different behavior.
2223 const OMPVarListLocTy &Locs) {
2224 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2225 }
2226
2227 /// Build a new OpenMP 'defaultmap' clause.
2228 ///
2229 /// By default, performs semantic analysis to build the new OpenMP clause.
2230 /// Subclasses may override this routine to provide different behavior.
2233 SourceLocation StartLoc,
2234 SourceLocation LParenLoc,
2235 SourceLocation MLoc,
2236 SourceLocation KindLoc,
2237 SourceLocation EndLoc) {
2239 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2240 }
2241
2242 /// Build a new OpenMP 'nontemporal' clause.
2243 ///
2244 /// By default, performs semantic analysis to build the new OpenMP clause.
2245 /// Subclasses may override this routine to provide different behavior.
2247 SourceLocation StartLoc,
2248 SourceLocation LParenLoc,
2249 SourceLocation EndLoc) {
2250 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2251 LParenLoc, EndLoc);
2252 }
2253
2254 /// Build a new OpenMP 'inclusive' clause.
2255 ///
2256 /// By default, performs semantic analysis to build the new OpenMP clause.
2257 /// Subclasses may override this routine to provide different behavior.
2259 SourceLocation StartLoc,
2260 SourceLocation LParenLoc,
2261 SourceLocation EndLoc) {
2262 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2263 LParenLoc, EndLoc);
2264 }
2265
2266 /// Build a new OpenMP 'exclusive' clause.
2267 ///
2268 /// By default, performs semantic analysis to build the new OpenMP clause.
2269 /// Subclasses may override this routine to provide different behavior.
2271 SourceLocation StartLoc,
2272 SourceLocation LParenLoc,
2273 SourceLocation EndLoc) {
2274 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2275 LParenLoc, EndLoc);
2276 }
2277
2278 /// Build a new OpenMP 'uses_allocators' clause.
2279 ///
2280 /// By default, performs semantic analysis to build the new OpenMP clause.
2281 /// Subclasses may override this routine to provide different behavior.
2284 SourceLocation LParenLoc, SourceLocation EndLoc) {
2286 StartLoc, LParenLoc, EndLoc, Data);
2287 }
2288
2289 /// Build a new OpenMP 'affinity' clause.
2290 ///
2291 /// By default, performs semantic analysis to build the new OpenMP clause.
2292 /// Subclasses may override this routine to provide different behavior.
2294 SourceLocation LParenLoc,
2295 SourceLocation ColonLoc,
2296 SourceLocation EndLoc, Expr *Modifier,
2297 ArrayRef<Expr *> Locators) {
2299 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2300 }
2301
2302 /// Build a new OpenMP 'order' clause.
2303 ///
2304 /// By default, performs semantic analysis to build the new OpenMP clause.
2305 /// Subclasses may override this routine to provide different behavior.
2307 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2308 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2309 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2311 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2312 }
2313
2314 /// Build a new OpenMP 'init' clause.
2315 ///
2316 /// By default, performs semantic analysis to build the new OpenMP clause.
2317 /// Subclasses may override this routine to provide different behavior.
2319 SourceLocation StartLoc,
2320 SourceLocation LParenLoc,
2321 SourceLocation VarLoc,
2322 SourceLocation EndLoc) {
2324 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2325 }
2326
2327 /// Build a new OpenMP 'use' clause.
2328 ///
2329 /// By default, performs semantic analysis to build the new OpenMP clause.
2330 /// Subclasses may override this routine to provide different behavior.
2332 SourceLocation LParenLoc,
2333 SourceLocation VarLoc, SourceLocation EndLoc) {
2334 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2335 LParenLoc, VarLoc, EndLoc);
2336 }
2337
2338 /// Build a new OpenMP 'destroy' clause.
2339 ///
2340 /// By default, performs semantic analysis to build the new OpenMP clause.
2341 /// Subclasses may override this routine to provide different behavior.
2343 SourceLocation LParenLoc,
2344 SourceLocation VarLoc,
2345 SourceLocation EndLoc) {
2347 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2348 }
2349
2350 /// Build a new OpenMP 'novariants' clause.
2351 ///
2352 /// By default, performs semantic analysis to build the new OpenMP clause.
2353 /// Subclasses may override this routine to provide different behavior.
2355 SourceLocation StartLoc,
2356 SourceLocation LParenLoc,
2357 SourceLocation EndLoc) {
2359 LParenLoc, EndLoc);
2360 }
2361
2362 /// Build a new OpenMP 'nocontext' clause.
2363 ///
2364 /// By default, performs semantic analysis to build the new OpenMP clause.
2365 /// Subclasses may override this routine to provide different behavior.
2367 SourceLocation LParenLoc,
2368 SourceLocation EndLoc) {
2370 LParenLoc, EndLoc);
2371 }
2372
2373 /// Build a new OpenMP 'filter' clause.
2374 ///
2375 /// By default, performs semantic analysis to build the new OpenMP clause.
2376 /// Subclasses may override this routine to provide different behavior.
2378 SourceLocation LParenLoc,
2379 SourceLocation EndLoc) {
2380 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2381 LParenLoc, EndLoc);
2382 }
2383
2384 /// Build a new OpenMP 'bind' clause.
2385 ///
2386 /// By default, performs semantic analysis to build the new OpenMP clause.
2387 /// Subclasses may override this routine to provide different behavior.
2389 SourceLocation KindLoc,
2390 SourceLocation StartLoc,
2391 SourceLocation LParenLoc,
2392 SourceLocation EndLoc) {
2393 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2394 LParenLoc, EndLoc);
2395 }
2396
2397 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2398 ///
2399 /// By default, performs semantic analysis to build the new OpenMP clause.
2400 /// Subclasses may override this routine to provide different behavior.
2402 SourceLocation LParenLoc,
2403 SourceLocation EndLoc) {
2404 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2405 LParenLoc, EndLoc);
2406 }
2407
2408 /// Build a new OpenMP 'ompx_attribute' clause.
2409 ///
2410 /// By default, performs semantic analysis to build the new OpenMP clause.
2411 /// Subclasses may override this routine to provide different behavior.
2413 SourceLocation StartLoc,
2414 SourceLocation LParenLoc,
2415 SourceLocation EndLoc) {
2416 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2417 LParenLoc, EndLoc);
2418 }
2419
2420 /// Build a new OpenMP 'ompx_bare' clause.
2421 ///
2422 /// By default, performs semantic analysis to build the new OpenMP clause.
2423 /// Subclasses may override this routine to provide different behavior.
2425 SourceLocation EndLoc) {
2426 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2427 }
2428
2429 /// Build a new OpenMP 'align' clause.
2430 ///
2431 /// By default, performs semantic analysis to build the new OpenMP clause.
2432 /// Subclasses may override this routine to provide different behavior.
2434 SourceLocation LParenLoc,
2435 SourceLocation EndLoc) {
2436 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2437 EndLoc);
2438 }
2439
2440 /// Build a new OpenMP 'at' clause.
2441 ///
2442 /// By default, performs semantic analysis to build the new OpenMP clause.
2443 /// Subclasses may override this routine to provide different behavior.
2445 SourceLocation StartLoc,
2446 SourceLocation LParenLoc,
2447 SourceLocation EndLoc) {
2448 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2449 LParenLoc, EndLoc);
2450 }
2451
2452 /// Build a new OpenMP 'severity' clause.
2453 ///
2454 /// By default, performs semantic analysis to build the new OpenMP clause.
2455 /// Subclasses may override this routine to provide different behavior.
2457 SourceLocation KwLoc,
2458 SourceLocation StartLoc,
2459 SourceLocation LParenLoc,
2460 SourceLocation EndLoc) {
2461 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2462 LParenLoc, EndLoc);
2463 }
2464
2465 /// Build a new OpenMP 'message' clause.
2466 ///
2467 /// By default, performs semantic analysis to build the new OpenMP clause.
2468 /// Subclasses may override this routine to provide different behavior.
2470 SourceLocation LParenLoc,
2471 SourceLocation EndLoc) {
2472 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2473 EndLoc);
2474 }
2475
2476 /// Build a new OpenMP 'doacross' clause.
2477 ///
2478 /// By default, performs semantic analysis to build the new OpenMP clause.
2479 /// Subclasses may override this routine to provide different behavior.
2480 OMPClause *
2482 SourceLocation DepLoc, SourceLocation ColonLoc,
2483 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2484 SourceLocation LParenLoc, SourceLocation EndLoc) {
2486 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2487 }
2488
2489 /// Rebuild the operand to an Objective-C \@synchronized statement.
2490 ///
2491 /// By default, performs semantic analysis to build the new statement.
2492 /// Subclasses may override this routine to provide different behavior.
2494 Expr *object) {
2495 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2496 }
2497
2498 /// Build a new Objective-C \@synchronized statement.
2499 ///
2500 /// By default, performs semantic analysis to build the new statement.
2501 /// Subclasses may override this routine to provide different behavior.
2503 Expr *Object, Stmt *Body) {
2504 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2505 }
2506
2507 /// Build a new Objective-C \@autoreleasepool statement.
2508 ///
2509 /// By default, performs semantic analysis to build the new statement.
2510 /// Subclasses may override this routine to provide different behavior.
2512 Stmt *Body) {
2513 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2514 }
2515
2516 /// Build a new Objective-C fast enumeration statement.
2517 ///
2518 /// By default, performs semantic analysis to build the new statement.
2519 /// Subclasses may override this routine to provide different behavior.
2521 Stmt *Element,
2522 Expr *Collection,
2523 SourceLocation RParenLoc,
2524 Stmt *Body) {
2526 ForLoc, Element, Collection, RParenLoc);
2527 if (ForEachStmt.isInvalid())
2528 return StmtError();
2529
2530 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2531 Body);
2532 }
2533
2534 /// Build a new C++ exception declaration.
2535 ///
2536 /// By default, performs semantic analysis to build the new decaration.
2537 /// Subclasses may override this routine to provide different behavior.
2540 SourceLocation StartLoc,
2541 SourceLocation IdLoc,
2542 IdentifierInfo *Id) {
2544 StartLoc, IdLoc, Id);
2545 if (Var)
2546 getSema().CurContext->addDecl(Var);
2547 return Var;
2548 }
2549
2550 /// Build a new C++ catch statement.
2551 ///
2552 /// By default, performs semantic analysis to build the new statement.
2553 /// Subclasses may override this routine to provide different behavior.
2555 VarDecl *ExceptionDecl,
2556 Stmt *Handler) {
2557 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2558 Handler));
2559 }
2560
2561 /// Build a new C++ try statement.
2562 ///
2563 /// By default, performs semantic analysis to build the new statement.
2564 /// Subclasses may override this routine to provide different behavior.
2566 ArrayRef<Stmt *> Handlers) {
2567 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2568 }
2569
2570 /// Build a new C++0x range-based for statement.
2571 ///
2572 /// By default, performs semantic analysis to build the new statement.
2573 /// Subclasses may override this routine to provide different behavior.
2575 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2576 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2577 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2578 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2579 // If we've just learned that the range is actually an Objective-C
2580 // collection, treat this as an Objective-C fast enumeration loop.
2581 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2582 if (RangeStmt->isSingleDecl()) {
2583 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2584 if (RangeVar->isInvalidDecl())
2585 return StmtError();
2586
2587 Expr *RangeExpr = RangeVar->getInit();
2588 if (!RangeExpr->isTypeDependent() &&
2589 RangeExpr->getType()->isObjCObjectPointerType()) {
2590 // FIXME: Support init-statements in Objective-C++20 ranged for
2591 // statement.
2592 if (Init) {
2593 return SemaRef.Diag(Init->getBeginLoc(),
2594 diag::err_objc_for_range_init_stmt)
2595 << Init->getSourceRange();
2596 }
2598 ForLoc, LoopVar, RangeExpr, RParenLoc);
2599 }
2600 }
2601 }
2602 }
2603
2605 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2606 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2607 }
2608
2609 /// Build a new C++0x range-based for statement.
2610 ///
2611 /// By default, performs semantic analysis to build the new statement.
2612 /// Subclasses may override this routine to provide different behavior.
2614 bool IsIfExists,
2615 NestedNameSpecifierLoc QualifierLoc,
2616 DeclarationNameInfo NameInfo,
2617 Stmt *Nested) {
2618 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2619 QualifierLoc, NameInfo, Nested);
2620 }
2621
2622 /// Attach body to a C++0x range-based for statement.
2623 ///
2624 /// By default, performs semantic analysis to finish the new statement.
2625 /// Subclasses may override this routine to provide different behavior.
2627 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2628 }
2629
2631 Stmt *TryBlock, Stmt *Handler) {
2632 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2633 }
2634
2636 Stmt *Block) {
2637 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2638 }
2639
2641 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2642 }
2643
2645 SourceLocation LParen,
2646 SourceLocation RParen,
2647 TypeSourceInfo *TSI) {
2648 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2649 TSI);
2650 }
2651
2652 /// Build a new predefined expression.
2653 ///
2654 /// By default, performs semantic analysis to build the new expression.
2655 /// Subclasses may override this routine to provide different behavior.
2657 return getSema().BuildPredefinedExpr(Loc, IK);
2658 }
2659
2660 /// Build a new expression that references a declaration.
2661 ///
2662 /// By default, performs semantic analysis to build the new expression.
2663 /// Subclasses may override this routine to provide different behavior.
2665 LookupResult &R,
2666 bool RequiresADL) {
2667 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2668 }
2669
2670
2671 /// Build a new expression that references a declaration.
2672 ///
2673 /// By default, performs semantic analysis to build the new expression.
2674 /// Subclasses may override this routine to provide different behavior.
2676 ValueDecl *VD,
2677 const DeclarationNameInfo &NameInfo,
2679 TemplateArgumentListInfo *TemplateArgs) {
2680 CXXScopeSpec SS;
2681 SS.Adopt(QualifierLoc);
2682 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2683 TemplateArgs);
2684 }
2685
2686 /// Build a new expression in parentheses.
2687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
2691 SourceLocation RParen) {
2692 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2693 }
2694
2695 /// Build a new pseudo-destructor expression.
2696 ///
2697 /// By default, performs semantic analysis to build the new expression.
2698 /// Subclasses may override this routine to provide different behavior.
2700 SourceLocation OperatorLoc,
2701 bool isArrow,
2702 CXXScopeSpec &SS,
2703 TypeSourceInfo *ScopeType,
2704 SourceLocation CCLoc,
2705 SourceLocation TildeLoc,
2706 PseudoDestructorTypeStorage Destroyed);
2707
2708 /// Build a new unary operator expression.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2714 Expr *SubExpr) {
2715 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2716 }
2717
2718 /// Build a new builtin offsetof expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
2725 SourceLocation RParenLoc) {
2726 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2727 RParenLoc);
2728 }
2729
2730 /// Build a new sizeof, alignof or vec_step expression with a
2731 /// type argument.
2732 ///
2733 /// By default, performs semantic analysis to build the new expression.
2734 /// Subclasses may override this routine to provide different behavior.
2736 SourceLocation OpLoc,
2737 UnaryExprOrTypeTrait ExprKind,
2738 SourceRange R) {
2739 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2740 }
2741
2742 /// Build a new sizeof, alignof or vec step expression with an
2743 /// expression argument.
2744 ///
2745 /// By default, performs semantic analysis to build the new expression.
2746 /// Subclasses may override this routine to provide different behavior.
2748 UnaryExprOrTypeTrait ExprKind,
2749 SourceRange R) {
2751 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2752 if (Result.isInvalid())
2753 return ExprError();
2754
2755 return Result;
2756 }
2757
2758 /// Build a new array subscript expression.
2759 ///
2760 /// By default, performs semantic analysis to build the new expression.
2761 /// Subclasses may override this routine to provide different behavior.
2763 SourceLocation LBracketLoc,
2764 Expr *RHS,
2765 SourceLocation RBracketLoc) {
2766 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2767 LBracketLoc, RHS,
2768 RBracketLoc);
2769 }
2770
2771 /// Build a new matrix subscript expression.
2772 ///
2773 /// By default, performs semantic analysis to build the new expression.
2774 /// Subclasses may override this routine to provide different behavior.
2776 Expr *ColumnIdx,
2777 SourceLocation RBracketLoc) {
2778 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2779 RBracketLoc);
2780 }
2781
2782 /// Build a new array section expression.
2783 ///
2784 /// By default, performs semantic analysis to build the new expression.
2785 /// Subclasses may override this routine to provide different behavior.
2787 SourceLocation LBracketLoc,
2788 Expr *LowerBound,
2789 SourceLocation ColonLocFirst,
2790 SourceLocation ColonLocSecond,
2791 Expr *Length, Expr *Stride,
2792 SourceLocation RBracketLoc) {
2793 if (IsOMPArraySection)
2795 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2796 Stride, RBracketLoc);
2797
2798 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2799 "Stride/second colon not allowed for OpenACC");
2800
2802 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2803 }
2804
2805 /// Build a new array shaping 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 RParenLoc,
2811 ArrayRef<Expr *> Dims,
2812 ArrayRef<SourceRange> BracketsRanges) {
2814 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2815 }
2816
2817 /// Build a new iterator expression.
2818 ///
2819 /// By default, performs semantic analysis to build the new expression.
2820 /// Subclasses may override this routine to provide different behavior.
2823 SourceLocation RLoc,
2826 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2827 }
2828
2829 /// Build a new call expression.
2830 ///
2831 /// By default, performs semantic analysis to build the new expression.
2832 /// Subclasses may override this routine to provide different behavior.
2834 MultiExprArg Args,
2835 SourceLocation RParenLoc,
2836 Expr *ExecConfig = nullptr) {
2837 return getSema().ActOnCallExpr(
2838 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2839 }
2840
2842 MultiExprArg Args,
2843 SourceLocation RParenLoc) {
2845 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2846 }
2847
2848 /// Build a new member access expression.
2849 ///
2850 /// By default, performs semantic analysis to build the new expression.
2851 /// Subclasses may override this routine to provide different behavior.
2853 bool isArrow,
2854 NestedNameSpecifierLoc QualifierLoc,
2855 SourceLocation TemplateKWLoc,
2856 const DeclarationNameInfo &MemberNameInfo,
2858 NamedDecl *FoundDecl,
2859 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2860 NamedDecl *FirstQualifierInScope) {
2862 isArrow);
2863 if (!Member->getDeclName()) {
2864 // We have a reference to an unnamed field. This is always the
2865 // base of an anonymous struct/union member access, i.e. the
2866 // field is always of record type.
2867 assert(Member->getType()->isRecordType() &&
2868 "unnamed member not of record type?");
2869
2870 BaseResult =
2872 QualifierLoc.getNestedNameSpecifier(),
2873 FoundDecl, Member);
2874 if (BaseResult.isInvalid())
2875 return ExprError();
2876 Base = BaseResult.get();
2877
2878 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2879 // from the AST, so we need to re-insert them if needed (since
2880 // `BuildFieldRefereneExpr()` doesn't do this).
2881 if (!isArrow && Base->isPRValue()) {
2883 if (BaseResult.isInvalid())
2884 return ExprError();
2885 Base = BaseResult.get();
2886 }
2887
2888 CXXScopeSpec EmptySS;
2890 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2891 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2892 MemberNameInfo);
2893 }
2894
2895 CXXScopeSpec SS;
2896 SS.Adopt(QualifierLoc);
2897
2898 Base = BaseResult.get();
2899 if (Base->containsErrors())
2900 return ExprError();
2901
2902 QualType BaseType = Base->getType();
2903
2904 if (isArrow && !BaseType->isPointerType())
2905 return ExprError();
2906
2907 // FIXME: this involves duplicating earlier analysis in a lot of
2908 // cases; we should avoid this when possible.
2909 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2910 R.addDecl(FoundDecl);
2911 R.resolveKind();
2912
2913 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2914 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2915 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2916 ->getType()
2917 ->getPointeeType()
2918 ->getAsCXXRecordDecl()) {
2919 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2920 // In unevaluated contexts, an expression supposed to be a member access
2921 // might reference a member in an unrelated class.
2922 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2923 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2924 VK_LValue, Member->getLocation());
2925 }
2926 }
2927
2928 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2929 SS, TemplateKWLoc,
2930 FirstQualifierInScope,
2931 R, ExplicitTemplateArgs,
2932 /*S*/nullptr);
2933 }
2934
2935 /// Build a new binary operator expression.
2936 ///
2937 /// By default, performs semantic analysis to build the new expression.
2938 /// Subclasses may override this routine to provide different behavior.
2941 Expr *LHS, Expr *RHS) {
2942 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2943 }
2944
2945 /// Build a new rewritten operator expression.
2946 ///
2947 /// By default, performs semantic analysis to build the new expression.
2948 /// Subclasses may override this routine to provide different behavior.
2950 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2951 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2952 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2953 RHS, /*RequiresADL*/false);
2954 }
2955
2956 /// Build a new conditional operator expression.
2957 ///
2958 /// By default, performs semantic analysis to build the new expression.
2959 /// Subclasses may override this routine to provide different behavior.
2961 SourceLocation QuestionLoc,
2962 Expr *LHS,
2963 SourceLocation ColonLoc,
2964 Expr *RHS) {
2965 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2966 LHS, RHS);
2967 }
2968
2969 /// Build a new C-style cast expression.
2970 ///
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2974 TypeSourceInfo *TInfo,
2975 SourceLocation RParenLoc,
2976 Expr *SubExpr) {
2977 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2978 SubExpr);
2979 }
2980
2981 /// Build a new compound literal expression.
2982 ///
2983 /// By default, performs semantic analysis to build the new expression.
2984 /// Subclasses may override this routine to provide different behavior.
2986 TypeSourceInfo *TInfo,
2987 SourceLocation RParenLoc,
2988 Expr *Init) {
2989 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2990 Init);
2991 }
2992
2993 /// Build a new extended vector element access expression.
2994 ///
2995 /// By default, performs semantic analysis to build the new expression.
2996 /// Subclasses may override this routine to provide different behavior.
2998 bool IsArrow,
2999 SourceLocation AccessorLoc,
3000 IdentifierInfo &Accessor) {
3001
3002 CXXScopeSpec SS;
3003 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3005 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3006 /*FirstQualifierInScope*/ nullptr, NameInfo,
3007 /* TemplateArgs */ nullptr,
3008 /*S*/ nullptr);
3009 }
3010
3011 /// Build a new initializer list expression.
3012 ///
3013 /// By default, performs semantic analysis to build the new expression.
3014 /// Subclasses may override this routine to provide different behavior.
3016 MultiExprArg Inits,
3017 SourceLocation RBraceLoc) {
3018 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3019 }
3020
3021 /// Build a new designated initializer expression.
3022 ///
3023 /// By default, performs semantic analysis to build the new expression.
3024 /// Subclasses may override this routine to provide different behavior.
3026 MultiExprArg ArrayExprs,
3027 SourceLocation EqualOrColonLoc,
3028 bool GNUSyntax,
3029 Expr *Init) {
3031 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3032 Init);
3033 if (Result.isInvalid())
3034 return ExprError();
3035
3036 return Result;
3037 }
3038
3039 /// Build a new value-initialized expression.
3040 ///
3041 /// By default, builds the implicit value initialization without performing
3042 /// any semantic analysis. Subclasses may override this routine to provide
3043 /// different behavior.
3045 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3046 }
3047
3048 /// Build a new \c va_arg expression.
3049 ///
3050 /// By default, performs semantic analysis to build the new expression.
3051 /// Subclasses may override this routine to provide different behavior.
3053 Expr *SubExpr, TypeSourceInfo *TInfo,
3054 SourceLocation RParenLoc) {
3055 return getSema().BuildVAArgExpr(BuiltinLoc,
3056 SubExpr, TInfo,
3057 RParenLoc);
3058 }
3059
3060 /// Build a new expression list in parentheses.
3061 ///
3062 /// By default, performs semantic analysis to build the new expression.
3063 /// Subclasses may override this routine to provide different behavior.
3065 MultiExprArg SubExprs,
3066 SourceLocation RParenLoc) {
3067 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3068 }
3069
3070 /// Build a new address-of-label expression.
3071 ///
3072 /// By default, performs semantic analysis, using the name of the label
3073 /// rather than attempting to map the label statement itself.
3074 /// Subclasses may override this routine to provide different behavior.
3076 SourceLocation LabelLoc, LabelDecl *Label) {
3077 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3078 }
3079
3080 /// Build a new GNU statement expression.
3081 ///
3082 /// By default, performs semantic analysis to build the new expression.
3083 /// Subclasses may override this routine to provide different behavior.
3085 SourceLocation RParenLoc, unsigned TemplateDepth) {
3086 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3087 TemplateDepth);
3088 }
3089
3090 /// Build a new __builtin_choose_expr expression.
3091 ///
3092 /// By default, performs semantic analysis to build the new expression.
3093 /// Subclasses may override this routine to provide different behavior.
3095 Expr *Cond, Expr *LHS, Expr *RHS,
3096 SourceLocation RParenLoc) {
3097 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3098 Cond, LHS, RHS,
3099 RParenLoc);
3100 }
3101
3102 /// Build a new generic selection expression with an expression predicate.
3103 ///
3104 /// By default, performs semantic analysis to build the new expression.
3105 /// Subclasses may override this routine to provide different behavior.
3107 SourceLocation DefaultLoc,
3108 SourceLocation RParenLoc,
3109 Expr *ControllingExpr,
3111 ArrayRef<Expr *> Exprs) {
3112 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3113 /*PredicateIsExpr=*/true,
3114 ControllingExpr, Types, Exprs);
3115 }
3116
3117 /// Build a new generic selection expression with a type predicate.
3118 ///
3119 /// By default, performs semantic analysis to build the new expression.
3120 /// Subclasses may override this routine to provide different behavior.
3122 SourceLocation DefaultLoc,
3123 SourceLocation RParenLoc,
3124 TypeSourceInfo *ControllingType,
3126 ArrayRef<Expr *> Exprs) {
3127 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3128 /*PredicateIsExpr=*/false,
3129 ControllingType, Types, Exprs);
3130 }
3131
3132 /// Build a new overloaded operator call expression.
3133 ///
3134 /// By default, performs semantic analysis to build the new expression.
3135 /// The semantic analysis provides the behavior of template instantiation,
3136 /// copying with transformations that turn what looks like an overloaded
3137 /// operator call into a use of a builtin operator, performing
3138 /// argument-dependent lookup, etc. Subclasses may override this routine to
3139 /// provide different behavior.
3141 SourceLocation OpLoc,
3142 SourceLocation CalleeLoc,
3143 bool RequiresADL,
3144 const UnresolvedSetImpl &Functions,
3145 Expr *First, Expr *Second);
3146
3147 /// Build a new C++ "named" cast expression, such as static_cast or
3148 /// reinterpret_cast.
3149 ///
3150 /// By default, this routine dispatches to one of the more-specific routines
3151 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3152 /// Subclasses may override this routine to provide different behavior.
3155 SourceLocation LAngleLoc,
3156 TypeSourceInfo *TInfo,
3157 SourceLocation RAngleLoc,
3158 SourceLocation LParenLoc,
3159 Expr *SubExpr,
3160 SourceLocation RParenLoc) {
3161 switch (Class) {
3162 case Stmt::CXXStaticCastExprClass:
3163 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3164 RAngleLoc, LParenLoc,
3165 SubExpr, RParenLoc);
3166
3167 case Stmt::CXXDynamicCastExprClass:
3168 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3169 RAngleLoc, LParenLoc,
3170 SubExpr, RParenLoc);
3171
3172 case Stmt::CXXReinterpretCastExprClass:
3173 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3174 RAngleLoc, LParenLoc,
3175 SubExpr,
3176 RParenLoc);
3177
3178 case Stmt::CXXConstCastExprClass:
3179 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3180 RAngleLoc, LParenLoc,
3181 SubExpr, RParenLoc);
3182
3183 case Stmt::CXXAddrspaceCastExprClass:
3184 return getDerived().RebuildCXXAddrspaceCastExpr(
3185 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3186
3187 default:
3188 llvm_unreachable("Invalid C++ named cast");
3189 }
3190 }
3191
3192 /// Build a new C++ static_cast expression.
3193 ///
3194 /// By default, performs semantic analysis to build the new expression.
3195 /// Subclasses may override this routine to provide different behavior.
3197 SourceLocation LAngleLoc,
3198 TypeSourceInfo *TInfo,
3199 SourceLocation RAngleLoc,
3200 SourceLocation LParenLoc,
3201 Expr *SubExpr,
3202 SourceLocation RParenLoc) {
3203 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3204 TInfo, SubExpr,
3205 SourceRange(LAngleLoc, RAngleLoc),
3206 SourceRange(LParenLoc, RParenLoc));
3207 }
3208
3209 /// Build a new C++ dynamic_cast expression.
3210 ///
3211 /// By default, performs semantic analysis to build the new expression.
3212 /// Subclasses may override this routine to provide different behavior.
3214 SourceLocation LAngleLoc,
3215 TypeSourceInfo *TInfo,
3216 SourceLocation RAngleLoc,
3217 SourceLocation LParenLoc,
3218 Expr *SubExpr,
3219 SourceLocation RParenLoc) {
3220 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3221 TInfo, SubExpr,
3222 SourceRange(LAngleLoc, RAngleLoc),
3223 SourceRange(LParenLoc, RParenLoc));
3224 }
3225
3226 /// Build a new C++ reinterpret_cast expression.
3227 ///
3228 /// By default, performs semantic analysis to build the new expression.
3229 /// Subclasses may override this routine to provide different behavior.
3231 SourceLocation LAngleLoc,
3232 TypeSourceInfo *TInfo,
3233 SourceLocation RAngleLoc,
3234 SourceLocation LParenLoc,
3235 Expr *SubExpr,
3236 SourceLocation RParenLoc) {
3237 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3238 TInfo, SubExpr,
3239 SourceRange(LAngleLoc, RAngleLoc),
3240 SourceRange(LParenLoc, RParenLoc));
3241 }
3242
3243 /// Build a new C++ const_cast expression.
3244 ///
3245 /// By default, performs semantic analysis to build the new expression.
3246 /// Subclasses may override this routine to provide different behavior.
3248 SourceLocation LAngleLoc,
3249 TypeSourceInfo *TInfo,
3250 SourceLocation RAngleLoc,
3251 SourceLocation LParenLoc,
3252 Expr *SubExpr,
3253 SourceLocation RParenLoc) {
3254 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3255 TInfo, SubExpr,
3256 SourceRange(LAngleLoc, RAngleLoc),
3257 SourceRange(LParenLoc, RParenLoc));
3258 }
3259
3262 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3263 SourceLocation LParenLoc, Expr *SubExpr,
3264 SourceLocation RParenLoc) {
3265 return getSema().BuildCXXNamedCast(
3266 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3267 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3268 }
3269
3270 /// Build a new C++ functional-style cast expression.
3271 ///
3272 /// By default, performs semantic analysis to build the new expression.
3273 /// Subclasses may override this routine to provide different behavior.
3275 SourceLocation LParenLoc,
3276 Expr *Sub,
3277 SourceLocation RParenLoc,
3278 bool ListInitialization) {
3279 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3280 // CXXParenListInitExpr. Pass its expanded arguments so that the
3281 // CXXParenListInitExpr can be rebuilt.
3282 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3284 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3285 RParenLoc, ListInitialization);
3286 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3287 MultiExprArg(&Sub, 1), RParenLoc,
3288 ListInitialization);
3289 }
3290
3291 /// Build a new C++ __builtin_bit_cast expression.
3292 ///
3293 /// By default, performs semantic analysis to build the new expression.
3294 /// Subclasses may override this routine to provide different behavior.
3296 TypeSourceInfo *TSI, Expr *Sub,
3297 SourceLocation RParenLoc) {
3298 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3299 }
3300
3301 /// Build a new C++ typeid(type) expression.
3302 ///
3303 /// By default, performs semantic analysis to build the new expression.
3304 /// Subclasses may override this routine to provide different behavior.
3306 SourceLocation TypeidLoc,
3307 TypeSourceInfo *Operand,
3308 SourceLocation RParenLoc) {
3309 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3310 RParenLoc);
3311 }
3312
3313
3314 /// Build a new C++ typeid(expr) expression.
3315 ///
3316 /// By default, performs semantic analysis to build the new expression.
3317 /// Subclasses may override this routine to provide different behavior.
3319 SourceLocation TypeidLoc,
3320 Expr *Operand,
3321 SourceLocation RParenLoc) {
3322 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3323 RParenLoc);
3324 }
3325
3326 /// Build a new C++ __uuidof(type) expression.
3327 ///
3328 /// By default, performs semantic analysis to build the new expression.
3329 /// Subclasses may override this routine to provide different behavior.
3331 TypeSourceInfo *Operand,
3332 SourceLocation RParenLoc) {
3333 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3334 }
3335
3336 /// Build a new C++ __uuidof(expr) expression.
3337 ///
3338 /// By default, performs semantic analysis to build the new expression.
3339 /// Subclasses may override this routine to provide different behavior.
3341 Expr *Operand, SourceLocation RParenLoc) {
3342 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3343 }
3344
3345 /// Build a new C++ "this" expression.
3346 ///
3347 /// By default, performs semantic analysis to build a new "this" expression.
3348 /// Subclasses may override this routine to provide different behavior.
3350 QualType ThisType,
3351 bool isImplicit) {
3352 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3353 return ExprError();
3354 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3355 }
3356
3357 /// Build a new C++ throw expression.
3358 ///
3359 /// By default, performs semantic analysis to build the new expression.
3360 /// Subclasses may override this routine to provide different behavior.
3362 bool IsThrownVariableInScope) {
3363 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3364 }
3365
3366 /// Build a new C++ default-argument expression.
3367 ///
3368 /// By default, builds a new default-argument expression, which does not
3369 /// require any semantic analysis. Subclasses may override this routine to
3370 /// provide different behavior.
3372 Expr *RewrittenExpr) {
3373 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3374 RewrittenExpr, getSema().CurContext);
3375 }
3376
3377 /// Build a new C++11 default-initialization expression.
3378 ///
3379 /// By default, builds a new default field initialization expression, which
3380 /// does not require any semantic analysis. Subclasses may override this
3381 /// routine to provide different behavior.
3383 FieldDecl *Field) {
3384 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3385 }
3386
3387 /// Build a new C++ zero-initialization expression.
3388 ///
3389 /// By default, performs semantic analysis to build the new expression.
3390 /// Subclasses may override this routine to provide different behavior.
3392 SourceLocation LParenLoc,
3393 SourceLocation RParenLoc) {
3394 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, std::nullopt,
3395 RParenLoc,
3396 /*ListInitialization=*/false);
3397 }
3398
3399 /// Build a new C++ "new" expression.
3400 ///
3401 /// By default, performs semantic analysis to build the new expression.
3402 /// Subclasses may override this routine to provide different behavior.
3404 SourceLocation PlacementLParen,
3405 MultiExprArg PlacementArgs,
3406 SourceLocation PlacementRParen,
3407 SourceRange TypeIdParens, QualType AllocatedType,
3408 TypeSourceInfo *AllocatedTypeInfo,
3409 std::optional<Expr *> ArraySize,
3410 SourceRange DirectInitRange, Expr *Initializer) {
3411 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3412 PlacementLParen,
3413 PlacementArgs,
3414 PlacementRParen,
3415 TypeIdParens,
3416 AllocatedType,
3417 AllocatedTypeInfo,
3418 ArraySize,
3419 DirectInitRange,
3420 Initializer);
3421 }
3422
3423 /// Build a new C++ "delete" expression.
3424 ///
3425 /// By default, performs semantic analysis to build the new expression.
3426 /// Subclasses may override this routine to provide different behavior.
3428 bool IsGlobalDelete,
3429 bool IsArrayForm,
3430 Expr *Operand) {
3431 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3432 Operand);
3433 }
3434
3435 /// Build a new type trait expression.
3436 ///
3437 /// By default, performs semantic analysis to build the new expression.
3438 /// Subclasses may override this routine to provide different behavior.
3440 SourceLocation StartLoc,
3442 SourceLocation RParenLoc) {
3443 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3444 }
3445
3446 /// Build a new array type trait expression.
3447 ///
3448 /// By default, performs semantic analysis to build the new expression.
3449 /// Subclasses may override this routine to provide different behavior.
3451 SourceLocation StartLoc,
3452 TypeSourceInfo *TSInfo,
3453 Expr *DimExpr,
3454 SourceLocation RParenLoc) {
3455 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3456 }
3457
3458 /// Build a new expression 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,
3464 Expr *Queried,
3465 SourceLocation RParenLoc) {
3466 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3467 }
3468
3469 /// Build a new (previously unresolved) declaration reference
3470 /// expression.
3471 ///
3472 /// By default, performs semantic analysis to build the new expression.
3473 /// Subclasses may override this routine to provide different behavior.
3475 NestedNameSpecifierLoc QualifierLoc,
3476 SourceLocation TemplateKWLoc,
3477 const DeclarationNameInfo &NameInfo,
3478 const TemplateArgumentListInfo *TemplateArgs,
3479 bool IsAddressOfOperand,
3480 TypeSourceInfo **RecoveryTSI) {
3481 CXXScopeSpec SS;
3482 SS.Adopt(QualifierLoc);
3483
3484 if (TemplateArgs || TemplateKWLoc.isValid())
3486 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3487
3489 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3490 }
3491
3492 /// Build a new template-id expression.
3493 ///
3494 /// By default, performs semantic analysis to build the new expression.
3495 /// Subclasses may override this routine to provide different behavior.
3497 SourceLocation TemplateKWLoc,
3498 LookupResult &R,
3499 bool RequiresADL,
3500 const TemplateArgumentListInfo *TemplateArgs) {
3501 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3502 TemplateArgs);
3503 }
3504
3505 /// Build a new object-construction expression.
3506 ///
3507 /// By default, performs semantic analysis to build the new expression.
3508 /// Subclasses may override this routine to provide different behavior.
3511 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3512 bool ListInitialization, bool StdInitListInitialization,
3513 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3514 SourceRange ParenRange) {
3515 // Reconstruct the constructor we originally found, which might be
3516 // different if this is a call to an inherited constructor.
3517 CXXConstructorDecl *FoundCtor = Constructor;
3518 if (Constructor->isInheritingConstructor())
3519 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3520
3521 SmallVector<Expr *, 8> ConvertedArgs;
3522 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3523 ConvertedArgs))
3524 return ExprError();
3525
3526 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3527 IsElidable,
3528 ConvertedArgs,
3529 HadMultipleCandidates,
3530 ListInitialization,
3531 StdInitListInitialization,
3532 RequiresZeroInit, ConstructKind,
3533 ParenRange);
3534 }
3535
3536 /// Build a new implicit construction via inherited constructor
3537 /// expression.
3539 CXXConstructorDecl *Constructor,
3540 bool ConstructsVBase,
3541 bool InheritedFromVBase) {
3543 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3544 }
3545
3546 /// Build a new object-construction expression.
3547 ///
3548 /// By default, performs semantic analysis to build the new expression.
3549 /// Subclasses may override this routine to provide different behavior.
3551 SourceLocation LParenOrBraceLoc,
3552 MultiExprArg Args,
3553 SourceLocation RParenOrBraceLoc,
3554 bool ListInitialization) {
3556 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3557 }
3558
3559 /// Build a new object-construction expression.
3560 ///
3561 /// By default, performs semantic analysis to build the new expression.
3562 /// Subclasses may override this routine to provide different behavior.
3564 SourceLocation LParenLoc,
3565 MultiExprArg Args,
3566 SourceLocation RParenLoc,
3567 bool ListInitialization) {
3568 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3569 RParenLoc, ListInitialization);
3570 }
3571
3572 /// Build a new member reference expression.
3573 ///
3574 /// By default, performs semantic analysis to build the new expression.
3575 /// Subclasses may override this routine to provide different behavior.
3577 QualType BaseType,
3578 bool IsArrow,
3579 SourceLocation OperatorLoc,
3580 NestedNameSpecifierLoc QualifierLoc,
3581 SourceLocation TemplateKWLoc,
3582 NamedDecl *FirstQualifierInScope,
3583 const DeclarationNameInfo &MemberNameInfo,
3584 const TemplateArgumentListInfo *TemplateArgs) {
3585 CXXScopeSpec SS;
3586 SS.Adopt(QualifierLoc);
3587
3588 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3589 OperatorLoc, IsArrow,
3590 SS, TemplateKWLoc,
3591 FirstQualifierInScope,
3592 MemberNameInfo,
3593 TemplateArgs, /*S*/nullptr);
3594 }
3595
3596 /// Build a new member reference expression.
3597 ///
3598 /// By default, performs semantic analysis to build the new expression.
3599 /// Subclasses may override this routine to provide different behavior.
3601 SourceLocation OperatorLoc,
3602 bool IsArrow,
3603 NestedNameSpecifierLoc QualifierLoc,
3604 SourceLocation TemplateKWLoc,
3605 NamedDecl *FirstQualifierInScope,
3606 LookupResult &R,
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 R, TemplateArgs, /*S*/nullptr);
3616 }
3617
3618 /// Build a new noexcept expression.
3619 ///
3620 /// By default, performs semantic analysis to build the new expression.
3621 /// Subclasses may override this routine to provide different behavior.
3623 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3624 }
3625
3626 /// Build a new expression to compute the length of a parameter pack.
3628 SourceLocation PackLoc,
3629 SourceLocation RParenLoc,
3630 std::optional<unsigned> Length,
3631 ArrayRef<TemplateArgument> PartialArgs) {
3632 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3633 RParenLoc, Length, PartialArgs);
3634 }
3635
3637 SourceLocation RSquareLoc,
3638 Expr *PackIdExpression, Expr *IndexExpr,
3639 ArrayRef<Expr *> ExpandedExprs,
3640 bool EmptyPack = false) {
3641 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3642 IndexExpr, RSquareLoc, ExpandedExprs,
3643 EmptyPack);
3644 }
3645
3646 /// Build a new expression representing a call to a source location
3647 /// builtin.
3648 ///
3649 /// By default, performs semantic analysis to build the new expression.
3650 /// Subclasses may override this routine to provide different behavior.
3652 SourceLocation BuiltinLoc,
3653 SourceLocation RPLoc,
3654 DeclContext *ParentContext) {
3655 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3656 ParentContext);
3657 }
3658
3659 /// Build a new Objective-C boxed expression.
3660 ///
3661 /// By default, performs semantic analysis to build the new expression.
3662 /// Subclasses may override this routine to provide different behavior.
3664 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3665 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3667 CXXScopeSpec SS;
3668 SS.Adopt(NNS);
3669 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3670 ConceptNameInfo,
3671 FoundDecl,
3672 NamedConcept, TALI);
3673 if (Result.isInvalid())
3674 return ExprError();
3675 return Result;
3676 }
3677
3678 /// \brief Build a new requires expression.
3679 ///
3680 /// By default, performs semantic analysis to build the new expression.
3681 /// Subclasses may override this routine to provide different behavior.
3684 SourceLocation LParenLoc,
3685 ArrayRef<ParmVarDecl *> LocalParameters,
3686 SourceLocation RParenLoc,
3688 SourceLocation ClosingBraceLoc) {
3689 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3690 LocalParameters, RParenLoc, Requirements,
3691 ClosingBraceLoc);
3692 }
3693
3697 return SemaRef.BuildTypeRequirement(SubstDiag);
3698 }
3699
3702 }
3703
3706 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3707 SourceLocation NoexceptLoc,
3709 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3710 std::move(Ret));
3711 }
3712
3714 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3716 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3717 std::move(Ret));
3718 }
3719
3721 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3722 const ASTConstraintSatisfaction &Satisfaction) {
3723 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3724 Satisfaction);
3725 }
3726
3728 return SemaRef.BuildNestedRequirement(Constraint);
3729 }
3730
3731 /// \brief Build a new Objective-C boxed expression.
3732 ///
3733 /// By default, performs semantic analysis to build the new expression.
3734 /// Subclasses may override this routine to provide different behavior.
3736 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3737 }
3738
3739 /// Build a new Objective-C array literal.
3740 ///
3741 /// By default, performs semantic analysis to build the new expression.
3742 /// Subclasses may override this routine to provide different behavior.
3744 Expr **Elements, unsigned NumElements) {
3746 Range, MultiExprArg(Elements, NumElements));
3747 }
3748
3750 Expr *Base, Expr *Key,
3751 ObjCMethodDecl *getterMethod,
3752 ObjCMethodDecl *setterMethod) {
3754 RB, Base, Key, getterMethod, setterMethod);
3755 }
3756
3757 /// Build a new Objective-C dictionary literal.
3758 ///
3759 /// By default, performs semantic analysis to build the new expression.
3760 /// Subclasses may override this routine to provide different behavior.
3763 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3764 }
3765
3766 /// Build a new Objective-C \@encode expression.
3767 ///
3768 /// By default, performs semantic analysis to build the new expression.
3769 /// Subclasses may override this routine to provide different behavior.
3771 TypeSourceInfo *EncodeTypeInfo,
3772 SourceLocation RParenLoc) {
3773 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3774 RParenLoc);
3775 }
3776
3777 /// Build a new Objective-C class message.
3779 Selector Sel,
3780 ArrayRef<SourceLocation> SelectorLocs,
3781 ObjCMethodDecl *Method,
3782 SourceLocation LBracLoc,
3783 MultiExprArg Args,
3784 SourceLocation RBracLoc) {
3786 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3787 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3788 RBracLoc, Args);
3789 }
3790
3791 /// Build a new Objective-C instance message.
3793 Selector Sel,
3794 ArrayRef<SourceLocation> SelectorLocs,
3795 ObjCMethodDecl *Method,
3796 SourceLocation LBracLoc,
3797 MultiExprArg Args,
3798 SourceLocation RBracLoc) {
3799 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3800 /*SuperLoc=*/SourceLocation(),
3801 Sel, Method, LBracLoc,
3802 SelectorLocs, RBracLoc, Args);
3803 }
3804
3805 /// Build a new Objective-C instance/class message to 'super'.
3807 Selector Sel,
3808 ArrayRef<SourceLocation> SelectorLocs,
3809 QualType SuperType,
3810 ObjCMethodDecl *Method,
3811 SourceLocation LBracLoc,
3812 MultiExprArg Args,
3813 SourceLocation RBracLoc) {
3814 return Method->isInstanceMethod()
3816 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3817 SelectorLocs, RBracLoc, Args)
3818 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3819 Sel, Method, LBracLoc,
3820 SelectorLocs, RBracLoc, Args);
3821 }
3822
3823 /// Build a new Objective-C ivar reference expression.
3824 ///
3825 /// By default, performs semantic analysis to build the new expression.
3826 /// Subclasses may override this routine to provide different behavior.
3828 SourceLocation IvarLoc,
3829 bool IsArrow, bool IsFreeIvar) {
3830 CXXScopeSpec SS;
3831 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3833 BaseArg, BaseArg->getType(),
3834 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3835 /*FirstQualifierInScope=*/nullptr, NameInfo,
3836 /*TemplateArgs=*/nullptr,
3837 /*S=*/nullptr);
3838 if (IsFreeIvar && Result.isUsable())
3839 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3840 return Result;
3841 }
3842
3843 /// Build a new Objective-C property reference expression.
3844 ///
3845 /// By default, performs semantic analysis to build the new expression.
3846 /// Subclasses may override this routine to provide different behavior.
3849 SourceLocation PropertyLoc) {
3850 CXXScopeSpec SS;
3851 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3852 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3853 /*FIXME:*/PropertyLoc,
3854 /*IsArrow=*/false,
3855 SS, SourceLocation(),
3856 /*FirstQualifierInScope=*/nullptr,
3857 NameInfo,
3858 /*TemplateArgs=*/nullptr,
3859 /*S=*/nullptr);
3860 }
3861
3862 /// Build a new Objective-C property reference expression.
3863 ///
3864 /// By default, performs semantic analysis to build the new expression.
3865 /// Subclasses may override this routine to provide different behavior.
3867 ObjCMethodDecl *Getter,
3868 ObjCMethodDecl *Setter,
3869 SourceLocation PropertyLoc) {
3870 // Since these expressions can only be value-dependent, we do not
3871 // need to perform semantic analysis again.
3872 return Owned(
3873 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3875 PropertyLoc, Base));
3876 }
3877
3878 /// Build a new Objective-C "isa" expression.
3879 ///
3880 /// By default, performs semantic analysis to build the new expression.
3881 /// Subclasses may override this routine to provide different behavior.
3883 SourceLocation OpLoc, bool IsArrow) {
3884 CXXScopeSpec SS;
3885 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3886 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3887 OpLoc, IsArrow,
3888 SS, SourceLocation(),
3889 /*FirstQualifierInScope=*/nullptr,
3890 NameInfo,
3891 /*TemplateArgs=*/nullptr,
3892 /*S=*/nullptr);
3893 }
3894
3895 /// Build a new shuffle vector expression.
3896 ///
3897 /// By default, performs semantic analysis to build the new expression.
3898 /// Subclasses may override this routine to provide different behavior.
3900 MultiExprArg SubExprs,
3901 SourceLocation RParenLoc) {
3902 // Find the declaration for __builtin_shufflevector
3903 const IdentifierInfo &Name
3904 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3906 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3907 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3908
3909 // Build a reference to the __builtin_shufflevector builtin
3910 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3911 Expr *Callee = new (SemaRef.Context)
3912 DeclRefExpr(SemaRef.Context, Builtin, false,
3913 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3914 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3915 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3916 CK_BuiltinFnToFnPtr).get();
3917
3918 // Build the CallExpr
3919 ExprResult TheCall = CallExpr::Create(
3920 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3921 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3923
3924 // Type-check the __builtin_shufflevector expression.
3925 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3926 }
3927
3928 /// Build a new convert vector expression.
3930 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3931 SourceLocation RParenLoc) {
3932 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3933 }
3934
3935 /// Build a new template argument pack expansion.
3936 ///
3937 /// By default, performs semantic analysis to build a new pack expansion
3938 /// for a template argument. Subclasses may override this routine to provide
3939 /// different behavior.
3942 std::optional<unsigned> NumExpansions) {
3943 switch (Pattern.getArgument().getKind()) {
3947 EllipsisLoc, NumExpansions);
3948 if (Result.isInvalid())
3949 return TemplateArgumentLoc();
3950
3951 return TemplateArgumentLoc(Result.get(), Result.get());
3952 }
3953
3955 return TemplateArgumentLoc(
3958 NumExpansions),
3959 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3960 EllipsisLoc);
3961
3969 llvm_unreachable("Pack expansion pattern has no parameter packs");
3970
3972 if (TypeSourceInfo *Expansion
3973 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3974 EllipsisLoc,
3975 NumExpansions))
3976 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3977 Expansion);
3978 break;
3979 }
3980
3981 return TemplateArgumentLoc();
3982 }
3983
3984 /// Build a new expression pack expansion.
3985 ///
3986 /// By default, performs semantic analysis to build a new pack expansion
3987 /// for an expression. Subclasses may override this routine to provide
3988 /// different behavior.
3990 std::optional<unsigned> NumExpansions) {
3991 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3992 }
3993
3994 /// Build a new C++1z fold-expression.
3995 ///
3996 /// By default, performs semantic analysis in order to build a new fold
3997 /// expression.
3999 SourceLocation LParenLoc, Expr *LHS,
4000 BinaryOperatorKind Operator,
4001 SourceLocation EllipsisLoc, Expr *RHS,
4002 SourceLocation RParenLoc,
4003 std::optional<unsigned> NumExpansions) {
4004 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4005 EllipsisLoc, RHS, RParenLoc,
4006 NumExpansions);
4007 }
4008
4009 /// Build an empty C++1z fold-expression with the given operator.
4010 ///
4011 /// By default, produces the fallback value for the fold-expression, or
4012 /// produce an error if there is no fallback value.
4014 BinaryOperatorKind Operator) {
4015 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4016 }
4017
4018 /// Build a new atomic operation expression.
4019 ///
4020 /// By default, performs semantic analysis to build the new expression.
4021 /// Subclasses may override this routine to provide different behavior.
4024 SourceLocation RParenLoc) {
4025 // Use this for all of the locations, since we don't know the difference
4026 // between the call and the expr at this point.
4027 SourceRange Range{BuiltinLoc, RParenLoc};
4028 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4030 }
4031
4033 ArrayRef<Expr *> SubExprs, QualType Type) {
4034 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4035 }
4036
4038 SourceLocation BeginLoc,
4039 SourceLocation DirLoc,
4040 SourceLocation EndLoc,
4042 StmtResult StrBlock) {
4043 return getSema().OpenACC().ActOnEndStmtDirective(K, BeginLoc, DirLoc,
4044 EndLoc, Clauses, StrBlock);
4045 }
4046
4048 SourceLocation DirLoc,
4049 SourceLocation EndLoc,
4051 StmtResult Loop) {
4053 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, EndLoc, Clauses, Loop);
4054 }
4055
4056private:
4057 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4058 QualType ObjectType,
4059 NamedDecl *FirstQualifierInScope,
4060 CXXScopeSpec &SS);
4061
4062 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4063 QualType ObjectType,
4064 NamedDecl *FirstQualifierInScope,
4065 CXXScopeSpec &SS);
4066
4067 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4068 NamedDecl *FirstQualifierInScope,
4069 CXXScopeSpec &SS);
4070
4071 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4073 bool DeducibleTSTContext);
4074
4076 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4078
4080 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4081 OpenACCDirectiveKind DirKind,
4082 const OpenACCClause *OldClause);
4083};
4084
4085template <typename Derived>
4087 if (!S)
4088 return S;
4089
4090 switch (S->getStmtClass()) {
4091 case Stmt::NoStmtClass: break;
4092
4093 // Transform individual statement nodes
4094 // Pass SDK into statements that can produce a value
4095#define STMT(Node, Parent) \
4096 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4097#define VALUESTMT(Node, Parent) \
4098 case Stmt::Node##Class: \
4099 return getDerived().Transform##Node(cast<Node>(S), SDK);
4100#define ABSTRACT_STMT(Node)
4101#define EXPR(Node, Parent)
4102#include "clang/AST/StmtNodes.inc"
4103
4104 // Transform expressions by calling TransformExpr.
4105#define STMT(Node, Parent)
4106#define ABSTRACT_STMT(Stmt)
4107#define EXPR(Node, Parent) case Stmt::Node##Class:
4108#include "clang/AST/StmtNodes.inc"
4109 {
4110 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4111
4112 if (SDK == SDK_StmtExprResult)
4113 E = getSema().ActOnStmtExprResult(E);
4114 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4115 }
4116 }
4117
4118 return S;
4119}
4120
4121template<typename Derived>
4123 if (!S)
4124 return S;
4125
4126 switch (S->getClauseKind()) {
4127 default: break;
4128 // Transform individual clause nodes
4129#define GEN_CLANG_CLAUSE_CLASS
4130#define CLAUSE_CLASS(Enum, Str, Class) \
4131 case Enum: \
4132 return getDerived().Transform##Class(cast<Class>(S));
4133#include "llvm/Frontend/OpenMP/OMP.inc"
4134 }
4135
4136 return S;
4137}
4138
4139
4140template<typename Derived>
4142 if (!E)
4143 return E;
4144
4145 switch (E->getStmtClass()) {
4146 case Stmt::NoStmtClass: break;
4147#define STMT(Node, Parent) case Stmt::Node##Class: break;
4148#define ABSTRACT_STMT(Stmt)
4149#define EXPR(Node, Parent) \
4150 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4151#include "clang/AST/StmtNodes.inc"
4152 }
4153
4154 return E;
4155}
4156
4157template<typename Derived>
4159 bool NotCopyInit) {
4160 // Initializers are instantiated like expressions, except that various outer
4161 // layers are stripped.
4162 if (!Init)
4163 return Init;
4164
4165 if (auto *FE = dyn_cast<FullExpr>(Init))
4166 Init = FE->getSubExpr();
4167
4168 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4169 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4170 Init = OVE->getSourceExpr();
4171 }
4172
4173 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4174 Init = MTE->getSubExpr();
4175
4176 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4177 Init = Binder->getSubExpr();
4178
4179 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4180 Init = ICE->getSubExprAsWritten();
4181
4182 if (CXXStdInitializerListExpr *ILE =
4183 dyn_cast<CXXStdInitializerListExpr>(Init))
4184 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4185
4186 // If this is copy-initialization, we only need to reconstruct
4187 // InitListExprs. Other forms of copy-initialization will be a no-op if
4188 // the initializer is already the right type.
4189 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4190 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4191 return getDerived().TransformExpr(Init);
4192
4193 // Revert value-initialization back to empty parens.
4194 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4195 SourceRange Parens = VIE->getSourceRange();
4196 return getDerived().RebuildParenListExpr(Parens.getBegin(), std::nullopt,
4197 Parens.getEnd());
4198 }
4199
4200 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4201 if (isa<ImplicitValueInitExpr>(Init))
4202 return getDerived().RebuildParenListExpr(SourceLocation(), std::nullopt,
4203 SourceLocation());
4204
4205 // Revert initialization by constructor back to a parenthesized or braced list
4206 // of expressions. Any other form of initializer can just be reused directly.
4207 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4208 return getDerived().TransformExpr(Init);
4209
4210 // If the initialization implicitly converted an initializer list to a
4211 // std::initializer_list object, unwrap the std::initializer_list too.
4212 if (Construct && Construct->isStdInitListInitialization())
4213 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4214
4215 // Enter a list-init context if this was list initialization.
4218 Construct->isListInitialization());
4219
4220 getSema().keepInLifetimeExtendingContext();
4221 SmallVector<Expr*, 8> NewArgs;
4222 bool ArgChanged = false;
4223 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4224 /*IsCall*/true, NewArgs, &ArgChanged))
4225 return ExprError();
4226
4227 // If this was list initialization, revert to syntactic list form.
4228 if (Construct->isListInitialization())
4229 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4230 Construct->getEndLoc());
4231
4232 // Build a ParenListExpr to represent anything else.
4234 if (Parens.isInvalid()) {
4235 // This was a variable declaration's initialization for which no initializer
4236 // was specified.
4237 assert(NewArgs.empty() &&
4238 "no parens or braces but have direct init with arguments?");
4239 return ExprEmpty();
4240 }
4241 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4242 Parens.getEnd());
4243}
4244
4245template<typename Derived>
4247 unsigned NumInputs,
4248 bool IsCall,
4249 SmallVectorImpl<Expr *> &Outputs,
4250 bool *ArgChanged) {
4251 for (unsigned I = 0; I != NumInputs; ++I) {
4252 // If requested, drop call arguments that need to be dropped.
4253 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4254 if (ArgChanged)
4255 *ArgChanged = true;
4256
4257 break;
4258 }
4259
4260 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4261 Expr *Pattern = Expansion->getPattern();
4262
4264 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4265 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4266
4267 // Determine whether the set of unexpanded parameter packs can and should
4268 // be expanded.
4269 bool Expand = true;
4270 bool RetainExpansion = false;
4271 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4272 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4273 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4274 Pattern->getSourceRange(),
4275 Unexpanded,
4276 Expand, RetainExpansion,
4277 NumExpansions))
4278 return true;
4279
4280 if (!Expand) {
4281 // The transform has determined that we should perform a simple
4282 // transformation on the pack expansion, producing another pack
4283 // expansion.
4284 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4285 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4286 if (OutPattern.isInvalid())
4287 return true;
4288
4289 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4290 Expansion->getEllipsisLoc(),
4291 NumExpansions);
4292 if (Out.isInvalid())
4293 return true;
4294
4295 if (ArgChanged)
4296 *ArgChanged = true;
4297 Outputs.push_back(Out.get());
4298 continue;
4299 }
4300
4301 // Record right away that the argument was changed. This needs
4302 // to happen even if the array expands to nothing.
4303 if (ArgChanged) *ArgChanged = true;
4304
4305 // The transform has determined that we should perform an elementwise
4306 // expansion of the pattern. Do so.
4307 for (unsigned I = 0; I != *NumExpansions; ++I) {
4308 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4309 ExprResult Out = getDerived().TransformExpr(Pattern);
4310 if (Out.isInvalid())
4311 return true;
4312
4313 if (Out.get()->containsUnexpandedParameterPack()) {
4314 Out = getDerived().RebuildPackExpansion(
4315 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4316 if (Out.isInvalid())
4317 return true;
4318 }
4319
4320 Outputs.push_back(Out.get());
4321 }
4322
4323 // If we're supposed to retain a pack expansion, do so by temporarily
4324 // forgetting the partially-substituted parameter pack.
4325 if (RetainExpansion) {
4326 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4327
4328 ExprResult Out = getDerived().TransformExpr(Pattern);
4329 if (Out.isInvalid())
4330 return true;
4331
4332 Out = getDerived().RebuildPackExpansion(
4333 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4334 if (Out.isInvalid())
4335 return true;
4336
4337 Outputs.push_back(Out.get());
4338 }
4339
4340 continue;
4341 }
4342
4344 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4345 : getDerived().TransformExpr(Inputs[I]);
4346 if (Result.isInvalid())
4347 return true;
4348
4349 if (Result.get() != Inputs[I] && ArgChanged)
4350 *ArgChanged = true;
4351
4352 Outputs.push_back(Result.get());
4353 }
4354
4355 return false;
4356}
4357
4358template <typename Derived>
4361 if (Var) {
4362 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4363 getDerived().TransformDefinition(Var->getLocation(), Var));
4364
4365 if (!ConditionVar)
4366 return Sema::ConditionError();
4367
4368 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4369 }
4370
4371 if (Expr) {
4372 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4373
4374 if (CondExpr.isInvalid())
4375 return Sema::ConditionError();
4376
4377 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4378 /*MissingOK=*/true);
4379 }
4380
4381 return Sema::ConditionResult();
4382}
4383
4384template <typename Derived>
4386 NestedNameSpecifierLoc NNS, QualType ObjectType,
4387 NamedDecl *FirstQualifierInScope) {
4389
4390 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4391 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4392 Qualifier = Qualifier.getPrefix())
4393 Qualifiers.push_back(Qualifier);
4394 };
4395 insertNNS(NNS);
4396
4397 CXXScopeSpec SS;
4398 while (!Qualifiers.empty()) {
4399 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4401
4402 switch (QNNS->getKind()) {
4406 ObjectType);
4407 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4408 SS, FirstQualifierInScope, false))
4409 return NestedNameSpecifierLoc();
4410 break;
4411 }
4412
4414 NamespaceDecl *NS =
4415 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4416 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4417 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4418 break;
4419 }
4420
4422 NamespaceAliasDecl *Alias =
4423 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4425 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4426 Q.getLocalEndLoc());
4427 break;
4428 }
4429
4431 // There is no meaningful transformation that one could perform on the
4432 // global scope.
4433 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4434 break;
4435
4437 CXXRecordDecl *RD =
4438 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4439 SourceLocation(), QNNS->getAsRecordDecl()));
4440 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4441 break;
4442 }
4443
4446 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4447 FirstQualifierInScope, SS);
4448
4449 if (!TL)
4450 return NestedNameSpecifierLoc();
4451
4452 QualType T = TL.getType();
4453 if (T->isDependentType() || T->isRecordType() ||
4454 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4455 if (T->isEnumeralType())
4456 SemaRef.Diag(TL.getBeginLoc(),
4457 diag::warn_cxx98_compat_enum_nested_name_spec);
4458
4459 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4460 SS.Adopt(ETL.getQualifierLoc());
4461 TL = ETL.getNamedTypeLoc();
4462 }
4463
4464 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4465 Q.getLocalEndLoc());
4466 break;
4467 }
4468 // If the nested-name-specifier is an invalid type def, don't emit an
4469 // error because a previous error should have already been emitted.
4471 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4472 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4473 << T << SS.getRange();
4474 }
4475 return NestedNameSpecifierLoc();
4476 }
4477 }
4478
4479 // The qualifier-in-scope and object type only apply to the leftmost entity.
4480 FirstQualifierInScope = nullptr;
4481 ObjectType = QualType();
4482 }
4483
4484 // Don't rebuild the nested-name-specifier if we don't have to.
4485 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4486 !getDerived().AlwaysRebuild())
4487 return NNS;
4488
4489 // If we can re-use the source-location data from the original
4490 // nested-name-specifier, do so.
4491 if (SS.location_size() == NNS.getDataLength() &&
4492 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4494
4495 // Allocate new nested-name-specifier location information.
4496 return SS.getWithLocInContext(SemaRef.Context);
4497}
4498
4499template<typename Derived>
4503 DeclarationName Name = NameInfo.getName();
4504 if (!Name)
4505 return DeclarationNameInfo();
4506
4507 switch (Name.getNameKind()) {
4515 return NameInfo;
4516
4518 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4519 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4520 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4521 if (!NewTemplate)
4522 return DeclarationNameInfo();
4523
4524 DeclarationNameInfo NewNameInfo(NameInfo);
4525 NewNameInfo.setName(
4527 return NewNameInfo;
4528 }
4529
4533 TypeSourceInfo *NewTInfo;
4534 CanQualType NewCanTy;
4535 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4536 NewTInfo = getDerived().TransformType(OldTInfo);
4537 if (!NewTInfo)
4538 return DeclarationNameInfo();
4539 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4540 }
4541 else {
4542 NewTInfo = nullptr;
4543 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4544 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4545 if (NewT.isNull())
4546 return DeclarationNameInfo();
4547 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4548 }
4549
4550 DeclarationName NewName
4551 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4552 NewCanTy);
4553 DeclarationNameInfo NewNameInfo(NameInfo);
4554 NewNameInfo.setName(NewName);
4555 NewNameInfo.setNamedTypeInfo(NewTInfo);
4556 return NewNameInfo;
4557 }
4558 }
4559
4560 llvm_unreachable("Unknown name kind.");
4561}
4562
4563template<typename Derived>
4566 TemplateName Name,
4567 SourceLocation NameLoc,
4568 QualType ObjectType,
4569 NamedDecl *FirstQualifierInScope,
4570 bool AllowInjectedClassName) {
4571 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4572 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4573 assert(Template && "qualified template name must refer to a template");
4574
4575 TemplateDecl *TransTemplate
4576 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4577 Template));
4578 if (!TransTemplate)
4579 return TemplateName();
4580
4581 if (!getDerived().AlwaysRebuild() &&
4582 SS.getScopeRep() == QTN->getQualifier() &&
4583 TransTemplate == Template)
4584 return Name;
4585
4586 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4587 TransTemplate);
4588 }
4589
4590 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4591 if (SS.getScopeRep()) {
4592 // These apply to the scope specifier, not the template.
4593 ObjectType = QualType();
4594 FirstQualifierInScope = nullptr;
4595 }
4596
4597 if (!getDerived().AlwaysRebuild() &&
4598 SS.getScopeRep() == DTN->getQualifier() &&
4599 ObjectType.isNull())
4600 return Name;
4601
4602 // FIXME: Preserve the location of the "template" keyword.
4603 SourceLocation TemplateKWLoc = NameLoc;
4604
4605 if (DTN->isIdentifier()) {
4606 return getDerived().RebuildTemplateName(SS,
4607 TemplateKWLoc,
4608 *DTN->getIdentifier(),
4609 NameLoc,
4610 ObjectType,
4611 FirstQualifierInScope,
4612 AllowInjectedClassName);
4613 }
4614
4615 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4616 DTN->getOperator(), NameLoc,
4617 ObjectType, AllowInjectedClassName);
4618 }
4619
4620 // FIXME: Try to preserve more of the TemplateName.
4621 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4622 TemplateDecl *TransTemplate
4623 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,