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