1//===--- DeclSpec.h - Parsed declaration specifiers -------------*- 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///
9/// \file
10/// This file defines the classes used to store parsed information about
11/// declaration-specifiers and declarators.
12///
13/// \verbatim
14/// static const int volatile x, *y, *(*(*z)[10])(const void *x);
15/// ------------------------- - -- ---------------------------
16/// declaration-specifiers \ | /
17/// declarators
18/// \endverbatim
19///
20//===----------------------------------------------------------------------===//
21
22#ifndef LLVM_CLANG_SEMA_DECLSPEC_H
23#define LLVM_CLANG_SEMA_DECLSPEC_H
24
25#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclObjCCommon.h"
27#include "clang/AST/NestedNameSpecifier.h"
28#include "clang/Basic/ExceptionSpecificationType.h"
29#include "clang/Basic/Lambda.h"
30#include "clang/Basic/OperatorKinds.h"
31#include "clang/Basic/Specifiers.h"
32#include "clang/Lex/Token.h"
33#include "clang/Sema/Ownership.h"
34#include "clang/Sema/ParsedAttr.h"
35#include "llvm/ADT/STLExtras.h"
36#include "llvm/ADT/SmallVector.h"
37#include "llvm/Support/Compiler.h"
38#include "llvm/Support/ErrorHandling.h"
39#include <optional>
40
41namespace clang {
42 class ASTContext;
43 class CXXRecordDecl;
44 class TypeLoc;
45 class LangOptions;
46 class IdentifierInfo;
47 class NamespaceBaseDecl;
48 class ObjCDeclSpec;
49 class Sema;
50 class Declarator;
51 class OverflowBehaviorType;
52 struct TemplateIdAnnotation;
53
54/// Represents a C++ nested-name-specifier or a global scope specifier.
55///
56/// These can be in 3 states:
57/// 1) Not present, identified by isEmpty()
58/// 2) Present, identified by isNotEmpty()
59/// 2.a) Valid, identified by isValid()
60/// 2.b) Invalid, identified by isInvalid().
61///
62/// isSet() is deprecated because it mostly corresponded to "valid" but was
63/// often used as if it meant "present".
64///
65/// The actual scope is described by getScopeRep().
66///
67/// If the kind of getScopeRep() is TypeSpec then TemplateParamLists may be empty
68/// or contain the template parameter lists attached to the current declaration.
69/// Consider the following example:
70/// template <class T> void SomeType<T>::some_method() {}
71/// If CXXScopeSpec refers to SomeType<T> then TemplateParamLists will contain
72/// a single element referring to template <class T>.
73
74class CXXScopeSpec {
75 SourceRange Range;
76 NestedNameSpecifierLocBuilder Builder;
77 ArrayRef<TemplateParameterList *> TemplateParamLists;
78
79public:
80 SourceRange getRange() const { return Range; }
81 void setRange(SourceRange R) { Range = R; }
82 void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
83 void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
84 SourceLocation getBeginLoc() const { return Range.getBegin(); }
85 SourceLocation getEndLoc() const { return Range.getEnd(); }
86
87 void setTemplateParamLists(ArrayRef<TemplateParameterList *> L) {
88 TemplateParamLists = L;
89 }
90 ArrayRef<TemplateParameterList *> getTemplateParamLists() const {
91 return TemplateParamLists;
92 }
93
94 /// Retrieve the representation of the nested-name-specifier.
95 NestedNameSpecifier getScopeRep() const {
96 return Builder.getRepresentation();
97 }
98
99 /// Make a nested-name-specifier of the form 'type::'.
100 ///
101 /// \param Context The AST context in which this nested-name-specifier
102 /// resides.
103 ///
104 /// \param TemplateKWLoc The location of the 'template' keyword, if present.
105 ///
106 /// \param TL The TypeLoc that describes the type preceding the '::'.
107 ///
108 /// \param ColonColonLoc The location of the trailing '::'.
109 void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc);
110
111 /// Extend the current nested-name-specifier by another
112 /// nested-name-specifier component of the form 'namespace::'.
113 ///
114 /// \param Context The AST context in which this nested-name-specifier
115 /// resides.
116 ///
117 /// \param Namespace The namespace or the namespace alias.
118 ///
119 /// \param NamespaceLoc The location of the namespace name or the namespace
120 /// alias.
121 ///
122 /// \param ColonColonLoc The location of the trailing '::'.
123 void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace,
124 SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
125
126 /// Turn this (empty) nested-name-specifier into the global
127 /// nested-name-specifier '::'.
128 void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
129
130 /// Turns this (empty) nested-name-specifier into '__super'
131 /// nested-name-specifier.
132 ///
133 /// \param Context The AST context in which this nested-name-specifier
134 /// resides.
135 ///
136 /// \param RD The declaration of the class in which nested-name-specifier
137 /// appeared.
138 ///
139 /// \param SuperLoc The location of the '__super' keyword.
140 /// name.
141 ///
142 /// \param ColonColonLoc The location of the trailing '::'.
143 void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD,
144 SourceLocation SuperLoc,
145 SourceLocation ColonColonLoc);
146
147 /// Make a new nested-name-specifier from incomplete source-location
148 /// information.
149 ///
150 /// FIXME: This routine should be used very, very rarely, in cases where we
151 /// need to synthesize a nested-name-specifier. Most code should instead use
152 /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
153 void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier,
154 SourceRange R);
155
156 /// Adopt an existing nested-name-specifier (with source-range
157 /// information).
158 void Adopt(NestedNameSpecifierLoc Other);
159
160 /// Retrieve a nested-name-specifier with location information, copied
161 /// into the given AST context.
162 ///
163 /// \param Context The context into which this nested-name-specifier will be
164 /// copied.
165 NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
166
167 /// Retrieve the location of the name in the last qualifier
168 /// in this nested name specifier.
169 ///
170 /// For example, the location of \c bar
171 /// in
172 /// \verbatim
173 /// \::foo::bar<0>::
174 /// ^~~
175 /// \endverbatim
176 SourceLocation getLastQualifierNameLoc() const;
177
178 /// No scope specifier.
179 bool isEmpty() const { return Range.isInvalid() && !getScopeRep(); }
180 /// A scope specifier is present, but may be valid or invalid.
181 bool isNotEmpty() const { return !isEmpty(); }
182
183 /// An error occurred during parsing of the scope specifier.
184 bool isInvalid() const { return Range.isValid() && !getScopeRep(); }
185 /// A scope specifier is present, and it refers to a real scope.
186 bool isValid() const { return bool(getScopeRep()); }
187
188 /// Indicate that this nested-name-specifier is invalid.
189 void SetInvalid(SourceRange R) {
190 assert(R.isValid() && "Must have a valid source range");
191 if (Range.getBegin().isInvalid())
192 Range.setBegin(R.getBegin());
193 Range.setEnd(R.getEnd());
194 Builder.Clear();
195 }
196
197 /// Deprecated. Some call sites intend isNotEmpty() while others intend
198 /// isValid().
199 bool isSet() const { return bool(getScopeRep()); }
200
201 void clear() {
202 Range = SourceRange();
203 Builder.Clear();
204 }
205
206 /// Retrieve the data associated with the source-location information.
207 char *location_data() const { return Builder.getBuffer().first; }
208
209 /// Retrieve the size of the data associated with source-location
210 /// information.
211 unsigned location_size() const { return Builder.getBuffer().second; }
212};
213
214/// Captures information about "declaration specifiers".
215///
216/// "Declaration specifiers" encompasses storage-class-specifiers,
217/// type-specifiers, type-qualifiers, and function-specifiers.
218class DeclSpec {
219public:
220 /// storage-class-specifier
221 /// \note The order of these enumerators is important for diagnostics.
222 enum SCS {
223 SCS_unspecified = 0,
224 SCS_typedef,
225 SCS_extern,
226 SCS_static,
227 SCS_auto,
228 SCS_register,
229 SCS_private_extern,
230 SCS_mutable
231 };
232
233 // Import thread storage class specifier enumeration and constants.
234 // These can be combined with SCS_extern and SCS_static.
235 typedef ThreadStorageClassSpecifier TSCS;
236 static const TSCS TSCS_unspecified = clang::TSCS_unspecified;
237 static const TSCS TSCS___thread = clang::TSCS___thread;
238 static const TSCS TSCS_thread_local = clang::TSCS_thread_local;
239 static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local;
240
241 enum TSC {
242 TSC_unspecified,
243 TSC_imaginary, // Unsupported
244 TSC_complex
245 };
246
247 // Import type specifier type enumeration and constants.
248 typedef TypeSpecifierType TST;
249 static const TST TST_unspecified = clang::TST_unspecified;
250 static const TST TST_void = clang::TST_void;
251 static const TST TST_char = clang::TST_char;
252 static const TST TST_wchar = clang::TST_wchar;
253 static const TST TST_char8 = clang::TST_char8;
254 static const TST TST_char16 = clang::TST_char16;
255 static const TST TST_char32 = clang::TST_char32;
256 static const TST TST_int = clang::TST_int;
257 static const TST TST_int128 = clang::TST_int128;
258 static const TST TST_bitint = clang::TST_bitint;
259 static const TST TST_half = clang::TST_half;
260 static const TST TST_BFloat16 = clang::TST_BFloat16;
261 static const TST TST_float = clang::TST_float;
262 static const TST TST_double = clang::TST_double;
263 static const TST TST_float16 = clang::TST_Float16;
264 static const TST TST_accum = clang::TST_Accum;
265 static const TST TST_fract = clang::TST_Fract;
266 static const TST TST_float128 = clang::TST_float128;
267 static const TST TST_ibm128 = clang::TST_ibm128;
268 static const TST TST_bool = clang::TST_bool;
269 static const TST TST_decimal32 = clang::TST_decimal32;
270 static const TST TST_decimal64 = clang::TST_decimal64;
271 static const TST TST_decimal128 = clang::TST_decimal128;
272 static const TST TST_enum = clang::TST_enum;
273 static const TST TST_union = clang::TST_union;
274 static const TST TST_struct = clang::TST_struct;
275 static const TST TST_interface = clang::TST_interface;
276 static const TST TST_class = clang::TST_class;
277 static const TST TST_typename = clang::TST_typename;
278 static const TST TST_typeofType = clang::TST_typeofType;
279 static const TST TST_typeofExpr = clang::TST_typeofExpr;
280 static const TST TST_typeof_unqualType = clang::TST_typeof_unqualType;
281 static const TST TST_typeof_unqualExpr = clang::TST_typeof_unqualExpr;
282 static const TST TST_decltype = clang::TST_decltype;
283 static const TST TST_decltype_auto = clang::TST_decltype_auto;
284 static const TST TST_typename_pack_indexing =
285 clang::TST_typename_pack_indexing;
286#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
287 static const TST TST_##Trait = clang::TST_##Trait;
288#include "clang/Basic/TransformTypeTraits.def"
289 static const TST TST_auto = clang::TST_auto;
290 static const TST TST_auto_type = clang::TST_auto_type;
291 static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
292 static const TST TST_atomic = clang::TST_atomic;
293#define GENERIC_IMAGE_TYPE(ImgType, Id) \
294 static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
295#include "clang/Basic/OpenCLImageTypes.def"
296#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
297 static const TST TST_##Name = clang::TST_##Name;
298#include "clang/Basic/HLSLIntangibleTypes.def"
299 static const TST TST_error = clang::TST_error;
300
301 // type-qualifiers
302 enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ.
303 TQ_unspecified = 0,
304 TQ_const = 1,
305 TQ_restrict = 2,
306 TQ_volatile = 4,
307 TQ_unaligned = 8,
308 // This has no corresponding Qualifiers::TQ value, because it's not treated
309 // as a qualifier in our type system.
310 TQ_atomic = 16
311 };
312
313 /// ParsedSpecifiers - Flags to query which specifiers were applied. This is
314 /// returned by getParsedSpecifiers.
315 enum ParsedSpecifiers {
316 PQ_None = 0,
317 PQ_StorageClassSpecifier = 1,
318 PQ_TypeSpecifier = 2,
319 PQ_TypeQualifier = 4,
320 PQ_FunctionSpecifier = 8
321 // FIXME: Attributes should be included here.
322 };
323
324 enum FriendSpecified : bool { No, Yes };
325
326 enum class OverflowBehaviorState {
327 Unspecified, // No overflow behavior specified
328 Wrap, // __ob_wrap or __attribute__((overflow_behavior(wrap)))
329 Trap // __ob_trap or __attribute__((overflow_behavior(trap)))
330 };
331
332private:
333 // storage-class-specifier
334 LLVM_PREFERRED_TYPE(SCS)
335 unsigned StorageClassSpec : 3;
336 LLVM_PREFERRED_TYPE(TSCS)
337 unsigned ThreadStorageClassSpec : 2;
338 LLVM_PREFERRED_TYPE(bool)
339 unsigned SCS_extern_in_linkage_spec : 1;
340
341 // type-specifier
342 LLVM_PREFERRED_TYPE(TypeSpecifierWidth)
343 unsigned TypeSpecWidth : 2;
344 LLVM_PREFERRED_TYPE(TSC)
345 unsigned TypeSpecComplex : 2;
346 LLVM_PREFERRED_TYPE(TypeSpecifierSign)
347 unsigned TypeSpecSign : 2;
348 LLVM_PREFERRED_TYPE(TST)
349 unsigned TypeSpecType : 7;
350 LLVM_PREFERRED_TYPE(bool)
351 unsigned TypeAltiVecVector : 1;
352 LLVM_PREFERRED_TYPE(bool)
353 unsigned TypeAltiVecPixel : 1;
354 LLVM_PREFERRED_TYPE(bool)
355 unsigned TypeAltiVecBool : 1;
356 LLVM_PREFERRED_TYPE(bool)
357 unsigned TypeSpecOwned : 1;
358 LLVM_PREFERRED_TYPE(bool)
359 unsigned TypeSpecPipe : 1;
360 LLVM_PREFERRED_TYPE(bool)
361 unsigned TypeSpecSat : 1;
362 LLVM_PREFERRED_TYPE(bool)
363 unsigned ConstrainedAuto : 1;
364
365 // type-qualifiers
366 LLVM_PREFERRED_TYPE(TQ)
367 unsigned TypeQualifiers : 5; // Bitwise OR of TQ.
368
369 // overflow behavior qualifiers
370 LLVM_PREFERRED_TYPE(OverflowBehaviorState)
371 unsigned OB_state : 2;
372
373 // function-specifier
374 LLVM_PREFERRED_TYPE(bool)
375 unsigned FS_inline_specified : 1;
376 LLVM_PREFERRED_TYPE(bool)
377 unsigned FS_forceinline_specified: 1;
378 LLVM_PREFERRED_TYPE(bool)
379 unsigned FS_virtual_specified : 1;
380 LLVM_PREFERRED_TYPE(bool)
381 unsigned FS_noreturn_specified : 1;
382
383 // friend-specifier
384 LLVM_PREFERRED_TYPE(bool)
385 unsigned FriendSpecifiedFirst : 1;
386
387 // constexpr-specifier
388 LLVM_PREFERRED_TYPE(ConstexprSpecKind)
389 unsigned ConstexprSpecifier : 2;
390
391 union {
392 UnionParsedType TypeRep;
393 Decl *DeclRep;
394 Expr *ExprRep;
395 TemplateIdAnnotation *TemplateIdRep;
396 };
397 Expr *PackIndexingExpr = nullptr;
398
399 /// ExplicitSpecifier - Store information about explicit spicifer.
400 ExplicitSpecifier FS_explicit_specifier;
401
402 // attributes.
403 ParsedAttributes Attrs;
404
405 // Scope specifier for the type spec, if applicable.
406 CXXScopeSpec TypeScope;
407
408 // SourceLocation info. These are null if the item wasn't specified or if
409 // the setting was synthesized.
410 SourceRange Range;
411
412 SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
413 SourceRange TSWRange;
414 SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc, EllipsisLoc;
415 /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
416 /// typename, then this is the location of the named type (if present);
417 /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
418 /// TSTNameLoc provides source range info for tag types.
419 SourceLocation TSTNameLoc;
420 SourceRange TypeofParensRange;
421 SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
422 TQ_unalignedLoc;
423 SourceLocation OB_Loc;
424 SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;
425 SourceLocation FS_explicitCloseParenLoc;
426 SourceLocation FS_forceinlineLoc;
427 SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
428 SourceLocation TQ_pipeLoc;
429
430 WrittenBuiltinSpecs writtenBS;
431 void SaveWrittenBuiltinSpecs();
432
433 ObjCDeclSpec *ObjCQualifiers;
434
435 static bool isTypeRep(TST T) {
436 return T == TST_atomic || T == TST_typename || T == TST_typeofType ||
437 T == TST_typeof_unqualType || isTransformTypeTrait(T) ||
438 T == TST_typename_pack_indexing;
439 }
440 static bool isExprRep(TST T) {
441 return T == TST_typeofExpr || T == TST_typeof_unqualExpr ||
442 T == TST_decltype || T == TST_bitint;
443 }
444 static bool isTemplateIdRep(TST T) {
445 return (T == TST_auto || T == TST_decltype_auto);
446 }
447
448 DeclSpec(const DeclSpec &) = delete;
449 void operator=(const DeclSpec &) = delete;
450public:
451 static bool isDeclRep(TST T) {
452 return (T == TST_enum || T == TST_struct ||
453 T == TST_interface || T == TST_union ||
454 T == TST_class);
455 }
456 static bool isTransformTypeTrait(TST T) {
457 constexpr std::array<TST, 16> Traits = {
458#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait,
459#include "clang/Basic/TransformTypeTraits.def"
460 };
461
462 return T >= Traits.front() && T <= Traits.back();
463 }
464
465 DeclSpec(AttributeFactory &attrFactory)
466 : StorageClassSpec(SCS_unspecified),
467 ThreadStorageClassSpec(TSCS_unspecified),
468 SCS_extern_in_linkage_spec(false),
469 TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)),
470 TypeSpecComplex(TSC_unspecified),
471 TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)),
472 TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
473 TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
474 TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false),
475 TypeQualifiers(TQ_unspecified),
476 OB_state(static_cast<unsigned>(OverflowBehaviorState::Unspecified)),
477 FS_inline_specified(false), FS_forceinline_specified(false),
478 FS_virtual_specified(false), FS_noreturn_specified(false),
479 FriendSpecifiedFirst(false), ConstexprSpecifier(static_cast<unsigned>(
480 ConstexprSpecKind::Unspecified)),
481 Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
482
483 // storage-class-specifier
484 SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
485 TSCS getThreadStorageClassSpec() const {
486 return (TSCS)ThreadStorageClassSpec;
487 }
488 bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
489 void setExternInLinkageSpec(bool Value) {
490 SCS_extern_in_linkage_spec = Value;
491 }
492
493 SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
494 SourceLocation getThreadStorageClassSpecLoc() const {
495 return ThreadStorageClassSpecLoc;
496 }
497
498 void ClearStorageClassSpecs() {
499 StorageClassSpec = DeclSpec::SCS_unspecified;
500 ThreadStorageClassSpec = DeclSpec::TSCS_unspecified;
501 SCS_extern_in_linkage_spec = false;
502 StorageClassSpecLoc = SourceLocation();
503 ThreadStorageClassSpecLoc = SourceLocation();
504 }
505
506 void ClearTypeSpecType() {
507 TypeSpecType = DeclSpec::TST_unspecified;
508 TypeSpecOwned = false;
509 TSTLoc = SourceLocation();
510 }
511
512 // type-specifier
513 TypeSpecifierWidth getTypeSpecWidth() const {
514 return static_cast<TypeSpecifierWidth>(TypeSpecWidth);
515 }
516 TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
517 TypeSpecifierSign getTypeSpecSign() const {
518 return static_cast<TypeSpecifierSign>(TypeSpecSign);
519 }
520 TST getTypeSpecType() const { return (TST)TypeSpecType; }
521 bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
522 bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
523 bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
524 bool isTypeSpecOwned() const { return TypeSpecOwned; }
525 bool isTypeRep() const { return isTypeRep(T: (TST) TypeSpecType); }
526 bool isTypeSpecPipe() const { return TypeSpecPipe; }
527 bool isTypeSpecSat() const { return TypeSpecSat; }
528 bool isConstrainedAuto() const { return ConstrainedAuto; }
529
530 ParsedType getRepAsType() const {
531 assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
532 return TypeRep;
533 }
534 Decl *getRepAsDecl() const {
535 assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
536 return DeclRep;
537 }
538 Expr *getRepAsExpr() const {
539 assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
540 return ExprRep;
541 }
542
543 Expr *getPackIndexingExpr() const {
544 assert(TypeSpecType == TST_typename_pack_indexing &&
545 "DeclSpec is not a pack indexing expr");
546 return PackIndexingExpr;
547 }
548
549 TemplateIdAnnotation *getRepAsTemplateId() const {
550 assert(isTemplateIdRep((TST) TypeSpecType) &&
551 "DeclSpec does not store a template id");
552 return TemplateIdRep;
553 }
554 CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
555 const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
556
557 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
558 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
559 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
560
561 SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
562 SourceRange getTypeSpecWidthRange() const { return TSWRange; }
563 SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
564 SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
565 SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
566 SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
567 SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
568
569 SourceLocation getTypeSpecTypeNameLoc() const {
570 assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) ||
571 isExprRep((TST)TypeSpecType));
572 return TSTNameLoc;
573 }
574
575 SourceRange getTypeofParensRange() const { return TypeofParensRange; }
576 void setTypeArgumentRange(SourceRange range) { TypeofParensRange = range; }
577
578 bool hasAutoTypeSpec() const {
579 return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type ||
580 TypeSpecType == TST_decltype_auto);
581 }
582
583 bool hasTagDefinition() const;
584
585 /// Turn a type-specifier-type into a string like "_Bool" or "union".
586 static const char *getSpecifierName(DeclSpec::TST T,
587 const PrintingPolicy &Policy);
588 static const char *getSpecifierName(DeclSpec::TQ Q);
589 static const char *getSpecifierName(TypeSpecifierSign S);
590 static const char *getSpecifierName(DeclSpec::TSC C);
591 static const char *getSpecifierName(TypeSpecifierWidth W);
592 static const char *getSpecifierName(DeclSpec::SCS S);
593 static const char *getSpecifierName(DeclSpec::TSCS S);
594 static const char *getSpecifierName(ConstexprSpecKind C);
595 static const char *getSpecifierName(OverflowBehaviorState S);
596
597 // type-qualifiers
598
599 /// getTypeQualifiers - Return a set of TQs.
600 unsigned getTypeQualifiers() const { return TypeQualifiers; }
601 SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
602 SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
603 SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
604 SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
605 SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
606 SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
607 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
608
609 // overflow behavior qualifiers
610 OverflowBehaviorState getOverflowBehaviorState() const {
611 return static_cast<OverflowBehaviorState>(OB_state);
612 }
613 bool isWrapSpecified() const {
614 return getOverflowBehaviorState() == OverflowBehaviorState::Wrap;
615 }
616 bool isTrapSpecified() const {
617 return getOverflowBehaviorState() == OverflowBehaviorState::Trap;
618 }
619 bool isOverflowBehaviorSpecified() const {
620 return getOverflowBehaviorState() != OverflowBehaviorState::Unspecified;
621 }
622 SourceLocation getOverflowBehaviorLoc() const { return OB_Loc; }
623
624 bool SetOverflowBehavior(OverflowBehaviorType::OverflowBehaviorKind Kind,
625 SourceLocation Loc, const char *&PrevSpec,
626 unsigned &DiagID);
627
628 /// Clear out all of the type qualifiers.
629 void ClearTypeQualifiers() {
630 TypeQualifiers = 0;
631 TQ_constLoc = SourceLocation();
632 TQ_restrictLoc = SourceLocation();
633 TQ_volatileLoc = SourceLocation();
634 TQ_atomicLoc = SourceLocation();
635 TQ_unalignedLoc = SourceLocation();
636 TQ_pipeLoc = SourceLocation();
637 OB_state = static_cast<unsigned>(OverflowBehaviorState::Unspecified);
638 OB_Loc = SourceLocation();
639 }
640
641 // function-specifier
642 bool isInlineSpecified() const {
643 return FS_inline_specified | FS_forceinline_specified;
644 }
645 SourceLocation getInlineSpecLoc() const {
646 return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc;
647 }
648
649 ExplicitSpecifier getExplicitSpecifier() const {
650 return FS_explicit_specifier;
651 }
652
653 bool isVirtualSpecified() const { return FS_virtual_specified; }
654 SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
655
656 bool hasExplicitSpecifier() const {
657 return FS_explicit_specifier.isSpecified();
658 }
659 SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
660 SourceRange getExplicitSpecRange() const {
661 return FS_explicit_specifier.getExpr()
662 ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc)
663 : SourceRange(FS_explicitLoc);
664 }
665
666 bool isNoreturnSpecified() const { return FS_noreturn_specified; }
667 SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; }
668
669 void ClearFunctionSpecs() {
670 FS_inline_specified = false;
671 FS_inlineLoc = SourceLocation();
672 FS_forceinline_specified = false;
673 FS_forceinlineLoc = SourceLocation();
674 FS_virtual_specified = false;
675 FS_virtualLoc = SourceLocation();
676 FS_explicit_specifier = ExplicitSpecifier();
677 FS_explicitLoc = SourceLocation();
678 FS_explicitCloseParenLoc = SourceLocation();
679 FS_noreturn_specified = false;
680 FS_noreturnLoc = SourceLocation();
681 }
682
683 /// This method calls the passed in handler on each CVRU qual being
684 /// set.
685 /// Handle - a handler to be invoked.
686 void forEachCVRUQualifier(
687 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
688
689 /// This method calls the passed in handler on each qual being
690 /// set.
691 /// Handle - a handler to be invoked.
692 void forEachQualifier(
693 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
694
695 /// Return true if any type-specifier has been found.
696 bool hasTypeSpecifier() const {
697 return getTypeSpecType() != DeclSpec::TST_unspecified ||
698 getTypeSpecWidth() != TypeSpecifierWidth::Unspecified ||
699 getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
700 getTypeSpecSign() != TypeSpecifierSign::Unspecified;
701 }
702
703 /// Return a bitmask of which flavors of specifiers this
704 /// DeclSpec includes.
705 unsigned getParsedSpecifiers() const;
706
707 /// isEmpty - Return true if this declaration specifier is completely empty:
708 /// no tokens were parsed in the production of it.
709 bool isEmpty() const {
710 return getParsedSpecifiers() == DeclSpec::PQ_None;
711 }
712
713 void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
714 void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
715
716 /// These methods set the specified attribute of the DeclSpec and
717 /// return false if there was no error. If an error occurs (for
718 /// example, if we tried to set "auto" on a spec with "extern"
719 /// already set), they return true and set PrevSpec and DiagID
720 /// such that
721 /// Diag(Loc, DiagID) << PrevSpec;
722 /// will yield a useful result.
723 ///
724 /// TODO: use a more general approach that still allows these
725 /// diagnostics to be ignored when desired.
726 bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
727 const char *&PrevSpec, unsigned &DiagID,
728 const PrintingPolicy &Policy);
729 bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
730 const char *&PrevSpec, unsigned &DiagID);
731 bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc,
732 const char *&PrevSpec, unsigned &DiagID,
733 const PrintingPolicy &Policy);
734 bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
735 unsigned &DiagID);
736 bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc,
737 const char *&PrevSpec, unsigned &DiagID);
738 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
739 unsigned &DiagID, const PrintingPolicy &Policy);
740 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
741 unsigned &DiagID, ParsedType Rep,
742 const PrintingPolicy &Policy);
743 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
744 unsigned &DiagID, TypeResult Rep,
745 const PrintingPolicy &Policy) {
746 if (Rep.isInvalid())
747 return SetTypeSpecError();
748 return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep: Rep.get(), Policy);
749 }
750 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
751 unsigned &DiagID, Decl *Rep, bool Owned,
752 const PrintingPolicy &Policy);
753 bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
754 SourceLocation TagNameLoc, const char *&PrevSpec,
755 unsigned &DiagID, ParsedType Rep,
756 const PrintingPolicy &Policy);
757 bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
758 SourceLocation TagNameLoc, const char *&PrevSpec,
759 unsigned &DiagID, Decl *Rep, bool Owned,
760 const PrintingPolicy &Policy);
761 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
762 unsigned &DiagID, TemplateIdAnnotation *Rep,
763 const PrintingPolicy &Policy);
764
765 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
766 unsigned &DiagID, Expr *Rep,
767 const PrintingPolicy &policy);
768 bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
769 const char *&PrevSpec, unsigned &DiagID,
770 const PrintingPolicy &Policy);
771 bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
772 const char *&PrevSpec, unsigned &DiagID,
773 const PrintingPolicy &Policy);
774 bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
775 const char *&PrevSpec, unsigned &DiagID,
776 const PrintingPolicy &Policy);
777 bool SetTypePipe(bool isPipe, SourceLocation Loc,
778 const char *&PrevSpec, unsigned &DiagID,
779 const PrintingPolicy &Policy);
780 bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth,
781 const char *&PrevSpec, unsigned &DiagID,
782 const PrintingPolicy &Policy);
783 bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
784 unsigned &DiagID);
785
786 void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack);
787
788 bool SetTypeSpecError();
789 void UpdateDeclRep(Decl *Rep) {
790 assert(isDeclRep((TST) TypeSpecType));
791 DeclRep = Rep;
792 }
793 void UpdateTypeRep(ParsedType Rep) {
794 assert(isTypeRep((TST) TypeSpecType));
795 TypeRep = Rep;
796 }
797 void UpdateExprRep(Expr *Rep) {
798 assert(isExprRep((TST) TypeSpecType));
799 ExprRep = Rep;
800 }
801
802 bool SetTypeQual(TQ T, SourceLocation Loc);
803
804 bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
805 unsigned &DiagID, const LangOptions &Lang);
806
807 bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
808 unsigned &DiagID);
809 bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
810 unsigned &DiagID);
811 bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
812 unsigned &DiagID);
813 bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
814 unsigned &DiagID, ExplicitSpecifier ExplicitSpec,
815 SourceLocation CloseParenLoc);
816 bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec,
817 unsigned &DiagID);
818
819 bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
820 unsigned &DiagID);
821 bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
822 unsigned &DiagID);
823 bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc,
824 const char *&PrevSpec, unsigned &DiagID);
825
826 FriendSpecified isFriendSpecified() const {
827 return static_cast<FriendSpecified>(FriendLoc.isValid());
828 }
829
830 bool isFriendSpecifiedFirst() const { return FriendSpecifiedFirst; }
831
832 SourceLocation getFriendSpecLoc() const { return FriendLoc; }
833
834 bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
835 SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
836
837 ConstexprSpecKind getConstexprSpecifier() const {
838 return ConstexprSpecKind(ConstexprSpecifier);
839 }
840
841 SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
842 bool hasConstexprSpecifier() const {
843 return getConstexprSpecifier() != ConstexprSpecKind::Unspecified;
844 }
845
846 void ClearConstexprSpec() {
847 ConstexprSpecifier = static_cast<unsigned>(ConstexprSpecKind::Unspecified);
848 ConstexprLoc = SourceLocation();
849 }
850
851 AttributePool &getAttributePool() const {
852 return Attrs.getPool();
853 }
854
855 /// Concatenates two attribute lists.
856 ///
857 /// The GCC attribute syntax allows for the following:
858 ///
859 /// \code
860 /// short __attribute__(( unused, deprecated ))
861 /// int __attribute__(( may_alias, aligned(16) )) var;
862 /// \endcode
863 ///
864 /// This declares 4 attributes using 2 lists. The following syntax is
865 /// also allowed and equivalent to the previous declaration.
866 ///
867 /// \code
868 /// short __attribute__((unused)) __attribute__((deprecated))
869 /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
870 /// \endcode
871 ///
872 void addAttributes(const ParsedAttributesView &AL) {
873 Attrs.prepend(B: AL.begin(), E: AL.end());
874 }
875
876 bool hasAttributes() const { return !Attrs.empty(); }
877
878 ParsedAttributes &getAttributes() { return Attrs; }
879 const ParsedAttributes &getAttributes() const { return Attrs; }
880
881 void takeAttributesAppendingingFrom(ParsedAttributes &attrs) {
882 Attrs.takeAllAppendingFrom(Other&: attrs);
883 }
884
885 /// Finish - This does final analysis of the declspec, issuing diagnostics for
886 /// things like "_Complex" (lacking an FP type). After calling this method,
887 /// DeclSpec is guaranteed self-consistent, even if an error occurred.
888 void Finish(Sema &S, const PrintingPolicy &Policy);
889
890 const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
891 return writtenBS;
892 }
893
894 ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
895 void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
896
897 /// Checks if this DeclSpec can stand alone, without a Declarator.
898 ///
899 /// Only tag declspecs can stand alone.
900 bool isMissingDeclaratorOk();
901};
902
903/// Captures information about "declaration specifiers" specific to
904/// Objective-C.
905class ObjCDeclSpec {
906public:
907 /// ObjCDeclQualifier - Qualifier used on types in method
908 /// declarations. Not all combinations are sensible. Parameters
909 /// can be one of { in, out, inout } with one of { bycopy, byref }.
910 /// Returns can either be { oneway } or not.
911 ///
912 /// This should be kept in sync with Decl::ObjCDeclQualifier.
913 enum ObjCDeclQualifier {
914 DQ_None = 0x0,
915 DQ_In = 0x1,
916 DQ_Inout = 0x2,
917 DQ_Out = 0x4,
918 DQ_Bycopy = 0x8,
919 DQ_Byref = 0x10,
920 DQ_Oneway = 0x20,
921 DQ_CSNullability = 0x40
922 };
923
924 ObjCDeclSpec()
925 : objcDeclQualifier(DQ_None),
926 PropertyAttributes(ObjCPropertyAttribute::kind_noattr), Nullability(0),
927 GetterName(nullptr), SetterName(nullptr) {}
928
929 ObjCDeclQualifier getObjCDeclQualifier() const {
930 return (ObjCDeclQualifier)objcDeclQualifier;
931 }
932 void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
933 objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
934 }
935 void clearObjCDeclQualifier(ObjCDeclQualifier DQVal) {
936 objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier & ~DQVal);
937 }
938
939 ObjCPropertyAttribute::Kind getPropertyAttributes() const {
940 return ObjCPropertyAttribute::Kind(PropertyAttributes);
941 }
942 void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) {
943 PropertyAttributes =
944 (ObjCPropertyAttribute::Kind)(PropertyAttributes | PRVal);
945 }
946
947 NullabilityKind getNullability() const {
948 assert(
949 ((getObjCDeclQualifier() & DQ_CSNullability) ||
950 (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
951 "Objective-C declspec doesn't have nullability");
952 return static_cast<NullabilityKind>(Nullability);
953 }
954
955 SourceLocation getNullabilityLoc() const {
956 assert(
957 ((getObjCDeclQualifier() & DQ_CSNullability) ||
958 (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
959 "Objective-C declspec doesn't have nullability");
960 return NullabilityLoc;
961 }
962
963 void setNullability(SourceLocation loc, NullabilityKind kind) {
964 assert(
965 ((getObjCDeclQualifier() & DQ_CSNullability) ||
966 (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
967 "Set the nullability declspec or property attribute first");
968 Nullability = static_cast<unsigned>(kind);
969 NullabilityLoc = loc;
970 }
971
972 const IdentifierInfo *getGetterName() const { return GetterName; }
973 IdentifierInfo *getGetterName() { return GetterName; }
974 SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
975 void setGetterName(IdentifierInfo *name, SourceLocation loc) {
976 GetterName = name;
977 GetterNameLoc = loc;
978 }
979
980 const IdentifierInfo *getSetterName() const { return SetterName; }
981 IdentifierInfo *getSetterName() { return SetterName; }
982 SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
983 void setSetterName(IdentifierInfo *name, SourceLocation loc) {
984 SetterName = name;
985 SetterNameLoc = loc;
986 }
987
988private:
989 // FIXME: These two are unrelated and mutually exclusive. So perhaps
990 // we can put them in a union to reflect their mutual exclusivity
991 // (space saving is negligible).
992 unsigned objcDeclQualifier : 7;
993
994 // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttribute::Kind
995 unsigned PropertyAttributes : NumObjCPropertyAttrsBits;
996
997 unsigned Nullability : 2;
998
999 SourceLocation NullabilityLoc;
1000
1001 IdentifierInfo *GetterName; // getter name or NULL if no getter
1002 IdentifierInfo *SetterName; // setter name or NULL if no setter
1003 SourceLocation GetterNameLoc; // location of the getter attribute's value
1004 SourceLocation SetterNameLoc; // location of the setter attribute's value
1005
1006};
1007
1008/// Describes the kind of unqualified-id parsed.
1009enum class UnqualifiedIdKind {
1010 /// An identifier.
1011 IK_Identifier,
1012 /// An overloaded operator name, e.g., operator+.
1013 IK_OperatorFunctionId,
1014 /// A conversion function name, e.g., operator int.
1015 IK_ConversionFunctionId,
1016 /// A user-defined literal name, e.g., operator "" _i.
1017 IK_LiteralOperatorId,
1018 /// A constructor name.
1019 IK_ConstructorName,
1020 /// A constructor named via a template-id.
1021 IK_ConstructorTemplateId,
1022 /// A destructor name.
1023 IK_DestructorName,
1024 /// A template-id, e.g., f<int>.
1025 IK_TemplateId,
1026 /// An implicit 'self' parameter
1027 IK_ImplicitSelfParam,
1028 /// A deduction-guide name (a template-name)
1029 IK_DeductionGuideName
1030};
1031
1032/// Represents a C++ unqualified-id that has been parsed.
1033class UnqualifiedId {
1034private:
1035 UnqualifiedId(const UnqualifiedId &Other) = delete;
1036 const UnqualifiedId &operator=(const UnqualifiedId &) = delete;
1037
1038 /// Describes the kind of unqualified-id parsed.
1039 UnqualifiedIdKind Kind;
1040
1041public:
1042 struct OFI {
1043 /// The kind of overloaded operator.
1044 OverloadedOperatorKind Operator;
1045
1046 /// The source locations of the individual tokens that name
1047 /// the operator, e.g., the "new", "[", and "]" tokens in
1048 /// operator new [].
1049 ///
1050 /// Different operators have different numbers of tokens in their name,
1051 /// up to three. Any remaining source locations in this array will be
1052 /// set to an invalid value for operators with fewer than three tokens.
1053 SourceLocation SymbolLocations[3];
1054 };
1055
1056 /// Anonymous union that holds extra data associated with the
1057 /// parsed unqualified-id.
1058 union {
1059 /// When Kind == IK_Identifier, the parsed identifier, or when
1060 /// Kind == IK_UserLiteralId, the identifier suffix.
1061 const IdentifierInfo *Identifier;
1062
1063 /// When Kind == IK_OperatorFunctionId, the overloaded operator
1064 /// that we parsed.
1065 struct OFI OperatorFunctionId;
1066
1067 /// When Kind == IK_ConversionFunctionId, the type that the
1068 /// conversion function names.
1069 UnionParsedType ConversionFunctionId;
1070
1071 /// When Kind == IK_ConstructorName, the class-name of the type
1072 /// whose constructor is being referenced.
1073 UnionParsedType ConstructorName;
1074
1075 /// When Kind == IK_DestructorName, the type referred to by the
1076 /// class-name.
1077 UnionParsedType DestructorName;
1078
1079 /// When Kind == IK_DeductionGuideName, the parsed template-name.
1080 UnionParsedTemplateTy TemplateName;
1081
1082 /// When Kind == IK_TemplateId or IK_ConstructorTemplateId,
1083 /// the template-id annotation that contains the template name and
1084 /// template arguments.
1085 TemplateIdAnnotation *TemplateId;
1086 };
1087
1088 /// The location of the first token that describes this unqualified-id,
1089 /// which will be the location of the identifier, "operator" keyword,
1090 /// tilde (for a destructor), or the template name of a template-id.
1091 SourceLocation StartLocation;
1092
1093 /// The location of the last token that describes this unqualified-id.
1094 SourceLocation EndLocation;
1095
1096 UnqualifiedId()
1097 : Kind(UnqualifiedIdKind::IK_Identifier), Identifier(nullptr) {}
1098
1099 /// Clear out this unqualified-id, setting it to default (invalid)
1100 /// state.
1101 void clear() {
1102 Kind = UnqualifiedIdKind::IK_Identifier;
1103 Identifier = nullptr;
1104 StartLocation = SourceLocation();
1105 EndLocation = SourceLocation();
1106 }
1107
1108 /// Determine whether this unqualified-id refers to a valid name.
1109 bool isValid() const { return StartLocation.isValid(); }
1110
1111 /// Determine whether this unqualified-id refers to an invalid name.
1112 bool isInvalid() const { return !isValid(); }
1113
1114 /// Determine what kind of name we have.
1115 UnqualifiedIdKind getKind() const { return Kind; }
1116
1117 /// Specify that this unqualified-id was parsed as an identifier.
1118 ///
1119 /// \param Id the parsed identifier.
1120 /// \param IdLoc the location of the parsed identifier.
1121 void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
1122 Kind = UnqualifiedIdKind::IK_Identifier;
1123 Identifier = Id;
1124 StartLocation = EndLocation = IdLoc;
1125 }
1126
1127 /// Specify that this unqualified-id was parsed as an
1128 /// operator-function-id.
1129 ///
1130 /// \param OperatorLoc the location of the 'operator' keyword.
1131 ///
1132 /// \param Op the overloaded operator.
1133 ///
1134 /// \param SymbolLocations the locations of the individual operator symbols
1135 /// in the operator.
1136 void setOperatorFunctionId(SourceLocation OperatorLoc,
1137 OverloadedOperatorKind Op,
1138 SourceLocation SymbolLocations[3]);
1139
1140 /// Specify that this unqualified-id was parsed as a
1141 /// conversion-function-id.
1142 ///
1143 /// \param OperatorLoc the location of the 'operator' keyword.
1144 ///
1145 /// \param Ty the type to which this conversion function is converting.
1146 ///
1147 /// \param EndLoc the location of the last token that makes up the type name.
1148 void setConversionFunctionId(SourceLocation OperatorLoc,
1149 ParsedType Ty,
1150 SourceLocation EndLoc) {
1151 Kind = UnqualifiedIdKind::IK_ConversionFunctionId;
1152 StartLocation = OperatorLoc;
1153 EndLocation = EndLoc;
1154 ConversionFunctionId = Ty;
1155 }
1156
1157 /// Specific that this unqualified-id was parsed as a
1158 /// literal-operator-id.
1159 ///
1160 /// \param Id the parsed identifier.
1161 ///
1162 /// \param OpLoc the location of the 'operator' keyword.
1163 ///
1164 /// \param IdLoc the location of the identifier.
1165 void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
1166 SourceLocation IdLoc) {
1167 Kind = UnqualifiedIdKind::IK_LiteralOperatorId;
1168 Identifier = Id;
1169 StartLocation = OpLoc;
1170 EndLocation = IdLoc;
1171 }
1172
1173 /// Specify that this unqualified-id was parsed as a constructor name.
1174 ///
1175 /// \param ClassType the class type referred to by the constructor name.
1176 ///
1177 /// \param ClassNameLoc the location of the class name.
1178 ///
1179 /// \param EndLoc the location of the last token that makes up the type name.
1180 void setConstructorName(ParsedType ClassType,
1181 SourceLocation ClassNameLoc,
1182 SourceLocation EndLoc) {
1183 Kind = UnqualifiedIdKind::IK_ConstructorName;
1184 StartLocation = ClassNameLoc;
1185 EndLocation = EndLoc;
1186 ConstructorName = ClassType;
1187 }
1188
1189 /// Specify that this unqualified-id was parsed as a
1190 /// template-id that names a constructor.
1191 ///
1192 /// \param TemplateId the template-id annotation that describes the parsed
1193 /// template-id. This UnqualifiedId instance will take ownership of the
1194 /// \p TemplateId and will free it on destruction.
1195 void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
1196
1197 /// Specify that this unqualified-id was parsed as a destructor name.
1198 ///
1199 /// \param TildeLoc the location of the '~' that introduces the destructor
1200 /// name.
1201 ///
1202 /// \param ClassType the name of the class referred to by the destructor name.
1203 void setDestructorName(SourceLocation TildeLoc,
1204 ParsedType ClassType,
1205 SourceLocation EndLoc) {
1206 Kind = UnqualifiedIdKind::IK_DestructorName;
1207 StartLocation = TildeLoc;
1208 EndLocation = EndLoc;
1209 DestructorName = ClassType;
1210 }
1211
1212 /// Specify that this unqualified-id was parsed as a template-id.
1213 ///
1214 /// \param TemplateId the template-id annotation that describes the parsed
1215 /// template-id. This UnqualifiedId instance will take ownership of the
1216 /// \p TemplateId and will free it on destruction.
1217 void setTemplateId(TemplateIdAnnotation *TemplateId);
1218
1219 /// Specify that this unqualified-id was parsed as a template-name for
1220 /// a deduction-guide.
1221 ///
1222 /// \param Template The parsed template-name.
1223 /// \param TemplateLoc The location of the parsed template-name.
1224 void setDeductionGuideName(ParsedTemplateTy Template,
1225 SourceLocation TemplateLoc) {
1226 Kind = UnqualifiedIdKind::IK_DeductionGuideName;
1227 TemplateName = Template;
1228 StartLocation = EndLocation = TemplateLoc;
1229 }
1230
1231 /// Specify that this unqualified-id is an implicit 'self'
1232 /// parameter.
1233 ///
1234 /// \param Id the identifier.
1235 void setImplicitSelfParam(const IdentifierInfo *Id) {
1236 Kind = UnqualifiedIdKind::IK_ImplicitSelfParam;
1237 Identifier = Id;
1238 StartLocation = EndLocation = SourceLocation();
1239 }
1240
1241 /// Return the source range that covers this unqualified-id.
1242 SourceRange getSourceRange() const LLVM_READONLY {
1243 return SourceRange(StartLocation, EndLocation);
1244 }
1245 SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; }
1246 SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; }
1247};
1248
1249/// A set of tokens that has been cached for later parsing.
1250typedef SmallVector<Token, 4> CachedTokens;
1251
1252/// One instance of this struct is used for each type in a
1253/// declarator that is parsed.
1254///
1255/// This is intended to be a small value object.
1256struct DeclaratorChunk {
1257 DeclaratorChunk() {};
1258
1259 enum {
1260 Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe
1261 } Kind;
1262
1263 /// Loc - The place where this type was defined.
1264 SourceLocation Loc;
1265 /// EndLoc - If valid, the place where this chunck ends.
1266 SourceLocation EndLoc;
1267
1268 SourceRange getSourceRange() const {
1269 if (EndLoc.isInvalid())
1270 return SourceRange(Loc, Loc);
1271 return SourceRange(Loc, EndLoc);
1272 }
1273
1274 ParsedAttributesView AttrList;
1275
1276 struct PointerTypeInfo {
1277 /// The type qualifiers: const/volatile/restrict/unaligned/atomic.
1278 LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1279 unsigned TypeQuals : 5;
1280
1281 /// The location of the const-qualifier, if any.
1282 SourceLocation ConstQualLoc;
1283
1284 /// The location of the volatile-qualifier, if any.
1285 SourceLocation VolatileQualLoc;
1286
1287 /// The location of the restrict-qualifier, if any.
1288 SourceLocation RestrictQualLoc;
1289
1290 /// The location of the _Atomic-qualifier, if any.
1291 SourceLocation AtomicQualLoc;
1292
1293 /// The location of the __unaligned-qualifier, if any.
1294 SourceLocation UnalignedQualLoc;
1295
1296 /// The location of an __ob_wrap or __ob_trap qualifier, if any.
1297 SourceLocation OverflowBehaviorLoc;
1298
1299 /// Whether the overflow behavior qualifier is wrap (true) or trap (false).
1300 /// Only meaningful if OverflowBehaviorLoc is valid.
1301 LLVM_PREFERRED_TYPE(bool)
1302 unsigned OverflowBehaviorIsWrap : 1;
1303
1304 void destroy() {
1305 }
1306 };
1307
1308 struct ReferenceTypeInfo {
1309 /// The type qualifier: restrict. [GNU] C++ extension
1310 bool HasRestrict : 1;
1311 /// True if this is an lvalue reference, false if it's an rvalue reference.
1312 bool LValueRef : 1;
1313 void destroy() {
1314 }
1315 };
1316
1317 struct ArrayTypeInfo {
1318 /// The type qualifiers for the array:
1319 /// const/volatile/restrict/__unaligned/_Atomic.
1320 LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1321 unsigned TypeQuals : 5;
1322
1323 /// True if this dimension included the 'static' keyword.
1324 LLVM_PREFERRED_TYPE(bool)
1325 unsigned hasStatic : 1;
1326
1327 /// True if this dimension was [*]. In this case, NumElts is null.
1328 LLVM_PREFERRED_TYPE(bool)
1329 unsigned isStar : 1;
1330
1331 /// This is the size of the array, or null if [] or [*] was specified.
1332 /// Since the parser is multi-purpose, and we don't want to impose a root
1333 /// expression class on all clients, NumElts is untyped.
1334 Expr *NumElts;
1335
1336 void destroy() {}
1337 };
1338
1339 /// ParamInfo - An array of paraminfo objects is allocated whenever a function
1340 /// declarator is parsed. There are two interesting styles of parameters
1341 /// here:
1342 /// K&R-style identifier lists and parameter type lists. K&R-style identifier
1343 /// lists will have information about the identifier, but no type information.
1344 /// Parameter type lists will have type info (if the actions module provides
1345 /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
1346 struct ParamInfo {
1347 const IdentifierInfo *Ident;
1348 SourceLocation IdentLoc;
1349 Decl *Param;
1350
1351 /// DefaultArgTokens - When the parameter's default argument
1352 /// cannot be parsed immediately (because it occurs within the
1353 /// declaration of a member function), it will be stored here as a
1354 /// sequence of tokens to be parsed once the class definition is
1355 /// complete. Non-NULL indicates that there is a default argument.
1356 std::unique_ptr<CachedTokens> DefaultArgTokens;
1357
1358 ParamInfo() = default;
1359 ParamInfo(const IdentifierInfo *ident, SourceLocation iloc, Decl *param,
1360 std::unique_ptr<CachedTokens> DefArgTokens = nullptr)
1361 : Ident(ident), IdentLoc(iloc), Param(param),
1362 DefaultArgTokens(std::move(DefArgTokens)) {}
1363 };
1364
1365 struct TypeAndRange {
1366 ParsedType Ty;
1367 SourceRange Range;
1368 };
1369
1370 struct FunctionTypeInfo {
1371 /// hasPrototype - This is true if the function had at least one typed
1372 /// parameter. If the function is () or (a,b,c), then it has no prototype,
1373 /// and is treated as a K&R-style function.
1374 LLVM_PREFERRED_TYPE(bool)
1375 unsigned hasPrototype : 1;
1376
1377 /// isVariadic - If this function has a prototype, and if that
1378 /// proto ends with ',...)', this is true. When true, EllipsisLoc
1379 /// contains the location of the ellipsis.
1380 LLVM_PREFERRED_TYPE(bool)
1381 unsigned isVariadic : 1;
1382
1383 /// Can this declaration be a constructor-style initializer?
1384 LLVM_PREFERRED_TYPE(bool)
1385 unsigned isAmbiguous : 1;
1386
1387 /// Whether the ref-qualifier (if any) is an lvalue reference.
1388 /// Otherwise, it's an rvalue reference.
1389 LLVM_PREFERRED_TYPE(bool)
1390 unsigned RefQualifierIsLValueRef : 1;
1391
1392 /// ExceptionSpecType - An ExceptionSpecificationType value.
1393 LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
1394 unsigned ExceptionSpecType : 4;
1395
1396 /// DeleteParams - If this is true, we need to delete[] Params.
1397 LLVM_PREFERRED_TYPE(bool)
1398 unsigned DeleteParams : 1;
1399
1400 /// HasTrailingReturnType - If this is true, a trailing return type was
1401 /// specified.
1402 LLVM_PREFERRED_TYPE(bool)
1403 unsigned HasTrailingReturnType : 1;
1404
1405 /// The location of the left parenthesis in the source.
1406 SourceLocation LParenLoc;
1407
1408 /// When isVariadic is true, the location of the ellipsis in the source.
1409 SourceLocation EllipsisLoc;
1410
1411 /// The location of the right parenthesis in the source.
1412 SourceLocation RParenLoc;
1413
1414 /// NumParams - This is the number of formal parameters specified by the
1415 /// declarator.
1416 unsigned NumParams;
1417
1418 /// NumExceptionsOrDecls - This is the number of types in the
1419 /// dynamic-exception-decl, if the function has one. In C, this is the
1420 /// number of declarations in the function prototype.
1421 unsigned NumExceptionsOrDecls;
1422
1423 /// The location of the ref-qualifier, if any.
1424 ///
1425 /// If this is an invalid location, there is no ref-qualifier.
1426 SourceLocation RefQualifierLoc;
1427
1428 /// The location of the 'mutable' qualifer in a lambda-declarator, if
1429 /// any.
1430 SourceLocation MutableLoc;
1431
1432 /// The beginning location of the exception specification, if any.
1433 SourceLocation ExceptionSpecLocBeg;
1434
1435 /// The end location of the exception specification, if any.
1436 SourceLocation ExceptionSpecLocEnd;
1437
1438 /// Params - This is a pointer to a new[]'d array of ParamInfo objects that
1439 /// describe the parameters specified by this function declarator. null if
1440 /// there are no parameters specified.
1441 ParamInfo *Params;
1442
1443 /// DeclSpec for the function with the qualifier related info.
1444 DeclSpec *MethodQualifiers;
1445
1446 /// AttributeFactory for the MethodQualifiers.
1447 AttributeFactory *QualAttrFactory;
1448
1449 union {
1450 /// Pointer to a new[]'d array of TypeAndRange objects that
1451 /// contain the types in the function's dynamic exception specification
1452 /// and their locations, if there is one.
1453 TypeAndRange *Exceptions;
1454
1455 /// Pointer to the expression in the noexcept-specifier of this
1456 /// function, if it has one.
1457 Expr *NoexceptExpr;
1458
1459 /// Pointer to the cached tokens for an exception-specification
1460 /// that has not yet been parsed.
1461 CachedTokens *ExceptionSpecTokens;
1462
1463 /// Pointer to a new[]'d array of declarations that need to be available
1464 /// for lookup inside the function body, if one exists. Does not exist in
1465 /// C++.
1466 NamedDecl **DeclsInPrototype;
1467 };
1468
1469 /// If HasTrailingReturnType is true, this is the trailing return
1470 /// type specified.
1471 UnionParsedType TrailingReturnType;
1472
1473 /// If HasTrailingReturnType is true, this is the location of the trailing
1474 /// return type.
1475 SourceLocation TrailingReturnTypeLoc;
1476
1477 /// Reset the parameter list to having zero parameters.
1478 ///
1479 /// This is used in various places for error recovery.
1480 void freeParams() {
1481 for (unsigned I = 0; I < NumParams; ++I)
1482 Params[I].DefaultArgTokens.reset();
1483 if (DeleteParams) {
1484 delete[] Params;
1485 DeleteParams = false;
1486 }
1487 NumParams = 0;
1488 }
1489
1490 void destroy() {
1491 freeParams();
1492 delete QualAttrFactory;
1493 delete MethodQualifiers;
1494 switch (getExceptionSpecType()) {
1495 default:
1496 break;
1497 case EST_Dynamic:
1498 delete[] Exceptions;
1499 break;
1500 case EST_Unparsed:
1501 delete ExceptionSpecTokens;
1502 break;
1503 case EST_None:
1504 if (NumExceptionsOrDecls != 0)
1505 delete[] DeclsInPrototype;
1506 break;
1507 }
1508 }
1509
1510 DeclSpec &getOrCreateMethodQualifiers() {
1511 if (!MethodQualifiers) {
1512 QualAttrFactory = new AttributeFactory();
1513 MethodQualifiers = new DeclSpec(*QualAttrFactory);
1514 }
1515 return *MethodQualifiers;
1516 }
1517
1518 /// isKNRPrototype - Return true if this is a K&R style identifier list,
1519 /// like "void foo(a,b,c)". In a function definition, this will be followed
1520 /// by the parameter type definitions.
1521 bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; }
1522
1523 SourceLocation getLParenLoc() const { return LParenLoc; }
1524
1525 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
1526
1527 SourceLocation getRParenLoc() const { return RParenLoc; }
1528
1529 SourceLocation getExceptionSpecLocBeg() const {
1530 return ExceptionSpecLocBeg;
1531 }
1532
1533 SourceLocation getExceptionSpecLocEnd() const {
1534 return ExceptionSpecLocEnd;
1535 }
1536
1537 SourceRange getExceptionSpecRange() const {
1538 return SourceRange(getExceptionSpecLocBeg(), getExceptionSpecLocEnd());
1539 }
1540
1541 /// Retrieve the location of the ref-qualifier, if any.
1542 SourceLocation getRefQualifierLoc() const { return RefQualifierLoc; }
1543
1544 /// Retrieve the location of the 'const' qualifier.
1545 SourceLocation getConstQualifierLoc() const {
1546 assert(MethodQualifiers);
1547 return MethodQualifiers->getConstSpecLoc();
1548 }
1549
1550 /// Retrieve the location of the 'volatile' qualifier.
1551 SourceLocation getVolatileQualifierLoc() const {
1552 assert(MethodQualifiers);
1553 return MethodQualifiers->getVolatileSpecLoc();
1554 }
1555
1556 /// Retrieve the location of the 'restrict' qualifier.
1557 SourceLocation getRestrictQualifierLoc() const {
1558 assert(MethodQualifiers);
1559 return MethodQualifiers->getRestrictSpecLoc();
1560 }
1561
1562 /// Retrieve the location of the 'mutable' qualifier, if any.
1563 SourceLocation getMutableLoc() const { return MutableLoc; }
1564
1565 /// Determine whether this function declaration contains a
1566 /// ref-qualifier.
1567 bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
1568
1569 /// Determine whether this lambda-declarator contains a 'mutable'
1570 /// qualifier.
1571 bool hasMutableQualifier() const { return getMutableLoc().isValid(); }
1572
1573 /// Determine whether this method has qualifiers.
1574 bool hasMethodTypeQualifiers() const {
1575 return MethodQualifiers && (MethodQualifiers->getTypeQualifiers() ||
1576 MethodQualifiers->getAttributes().size());
1577 }
1578
1579 /// Get the type of exception specification this function has.
1580 ExceptionSpecificationType getExceptionSpecType() const {
1581 return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
1582 }
1583
1584 /// Get the number of dynamic exception specifications.
1585 unsigned getNumExceptions() const {
1586 assert(ExceptionSpecType != EST_None);
1587 return NumExceptionsOrDecls;
1588 }
1589
1590 /// Get the non-parameter decls defined within this function
1591 /// prototype. Typically these are tag declarations.
1592 ArrayRef<NamedDecl *> getDeclsInPrototype() const {
1593 assert(ExceptionSpecType == EST_None);
1594 return llvm::ArrayRef(DeclsInPrototype, NumExceptionsOrDecls);
1595 }
1596
1597 /// Determine whether this function declarator had a
1598 /// trailing-return-type.
1599 bool hasTrailingReturnType() const { return HasTrailingReturnType; }
1600
1601 /// Get the trailing-return-type for this function declarator.
1602 ParsedType getTrailingReturnType() const {
1603 assert(HasTrailingReturnType);
1604 return TrailingReturnType;
1605 }
1606
1607 /// Get the trailing-return-type location for this function declarator.
1608 SourceLocation getTrailingReturnTypeLoc() const {
1609 assert(HasTrailingReturnType);
1610 return TrailingReturnTypeLoc;
1611 }
1612 };
1613
1614 struct BlockPointerTypeInfo {
1615 /// For now, sema will catch these as invalid.
1616 /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
1617 LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1618 unsigned TypeQuals : 5;
1619
1620 void destroy() {
1621 }
1622 };
1623
1624 struct MemberPointerTypeInfo {
1625 /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
1626 LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1627 unsigned TypeQuals : 5;
1628 /// Location of the '*' token.
1629 SourceLocation StarLoc;
1630 // CXXScopeSpec has a constructor, so it can't be a direct member.
1631 // So we need some pointer-aligned storage and a bit of trickery.
1632 alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)];
1633 CXXScopeSpec &Scope() {
1634 return *reinterpret_cast<CXXScopeSpec *>(ScopeMem);
1635 }
1636 const CXXScopeSpec &Scope() const {
1637 return *reinterpret_cast<const CXXScopeSpec *>(ScopeMem);
1638 }
1639 void destroy() {
1640 Scope().~CXXScopeSpec();
1641 }
1642 };
1643
1644 struct PipeTypeInfo {
1645 /// The access writes.
1646 unsigned AccessWrites : 3;
1647
1648 void destroy() {}
1649 };
1650
1651 union {
1652 PointerTypeInfo Ptr;
1653 ReferenceTypeInfo Ref;
1654 ArrayTypeInfo Arr;
1655 FunctionTypeInfo Fun;
1656 BlockPointerTypeInfo Cls;
1657 MemberPointerTypeInfo Mem;
1658 PipeTypeInfo PipeInfo;
1659 };
1660
1661 void destroy() {
1662 switch (Kind) {
1663 case DeclaratorChunk::Function: return Fun.destroy();
1664 case DeclaratorChunk::Pointer: return Ptr.destroy();
1665 case DeclaratorChunk::BlockPointer: return Cls.destroy();
1666 case DeclaratorChunk::Reference: return Ref.destroy();
1667 case DeclaratorChunk::Array: return Arr.destroy();
1668 case DeclaratorChunk::MemberPointer: return Mem.destroy();
1669 case DeclaratorChunk::Paren: return;
1670 case DeclaratorChunk::Pipe: return PipeInfo.destroy();
1671 }
1672 }
1673
1674 /// If there are attributes applied to this declaratorchunk, return
1675 /// them.
1676 const ParsedAttributesView &getAttrs() const { return AttrList; }
1677 ParsedAttributesView &getAttrs() { return AttrList; }
1678
1679 /// Return a DeclaratorChunk for a pointer.
1680 static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1681 SourceLocation ConstQualLoc,
1682 SourceLocation VolatileQualLoc,
1683 SourceLocation RestrictQualLoc,
1684 SourceLocation AtomicQualLoc,
1685 SourceLocation UnalignedQualLoc,
1686 SourceLocation OverflowBehaviorLoc = {},
1687 bool OverflowBehaviorIsWrap = false) {
1688 DeclaratorChunk I;
1689 I.Kind = Pointer;
1690 I.Loc = Loc;
1691 new (&I.Ptr) PointerTypeInfo;
1692 I.Ptr.TypeQuals = TypeQuals;
1693 I.Ptr.ConstQualLoc = ConstQualLoc;
1694 I.Ptr.VolatileQualLoc = VolatileQualLoc;
1695 I.Ptr.RestrictQualLoc = RestrictQualLoc;
1696 I.Ptr.AtomicQualLoc = AtomicQualLoc;
1697 I.Ptr.UnalignedQualLoc = UnalignedQualLoc;
1698 I.Ptr.OverflowBehaviorLoc = OverflowBehaviorLoc;
1699 I.Ptr.OverflowBehaviorIsWrap = OverflowBehaviorIsWrap;
1700 return I;
1701 }
1702
1703 /// Return a DeclaratorChunk for a reference.
1704 static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
1705 bool lvalue) {
1706 DeclaratorChunk I;
1707 I.Kind = Reference;
1708 I.Loc = Loc;
1709 I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
1710 I.Ref.LValueRef = lvalue;
1711 return I;
1712 }
1713
1714 /// Return a DeclaratorChunk for an array.
1715 static DeclaratorChunk getArray(unsigned TypeQuals,
1716 bool isStatic, bool isStar, Expr *NumElts,
1717 SourceLocation LBLoc, SourceLocation RBLoc) {
1718 DeclaratorChunk I;
1719 I.Kind = Array;
1720 I.Loc = LBLoc;
1721 I.EndLoc = RBLoc;
1722 I.Arr.TypeQuals = TypeQuals;
1723 I.Arr.hasStatic = isStatic;
1724 I.Arr.isStar = isStar;
1725 I.Arr.NumElts = NumElts;
1726 return I;
1727 }
1728
1729 /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1730 /// "TheDeclarator" is the declarator that this will be added to.
1731 static DeclaratorChunk getFunction(bool HasProto,
1732 bool IsAmbiguous,
1733 SourceLocation LParenLoc,
1734 ParamInfo *Params, unsigned NumParams,
1735 SourceLocation EllipsisLoc,
1736 SourceLocation RParenLoc,
1737 bool RefQualifierIsLvalueRef,
1738 SourceLocation RefQualifierLoc,
1739 SourceLocation MutableLoc,
1740 ExceptionSpecificationType ESpecType,
1741 SourceRange ESpecRange,
1742 ParsedType *Exceptions,
1743 SourceRange *ExceptionRanges,
1744 unsigned NumExceptions,
1745 Expr *NoexceptExpr,
1746 CachedTokens *ExceptionSpecTokens,
1747 ArrayRef<NamedDecl *> DeclsInPrototype,
1748 SourceLocation LocalRangeBegin,
1749 SourceLocation LocalRangeEnd,
1750 Declarator &TheDeclarator,
1751 TypeResult TrailingReturnType =
1752 TypeResult(),
1753 SourceLocation TrailingReturnTypeLoc =
1754 SourceLocation(),
1755 DeclSpec *MethodQualifiers = nullptr);
1756
1757 /// Return a DeclaratorChunk for a block.
1758 static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
1759 SourceLocation Loc) {
1760 DeclaratorChunk I;
1761 I.Kind = BlockPointer;
1762 I.Loc = Loc;
1763 I.Cls.TypeQuals = TypeQuals;
1764 return I;
1765 }
1766
1767 /// Return a DeclaratorChunk for a block.
1768 static DeclaratorChunk getPipe(unsigned TypeQuals,
1769 SourceLocation Loc) {
1770 DeclaratorChunk I;
1771 I.Kind = Pipe;
1772 I.Loc = Loc;
1773 I.Cls.TypeQuals = TypeQuals;
1774 return I;
1775 }
1776
1777 static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
1778 unsigned TypeQuals,
1779 SourceLocation StarLoc,
1780 SourceLocation EndLoc) {
1781 DeclaratorChunk I;
1782 I.Kind = MemberPointer;
1783 I.Loc = SS.getBeginLoc();
1784 I.EndLoc = EndLoc;
1785 new (&I.Mem) MemberPointerTypeInfo;
1786 I.Mem.StarLoc = StarLoc;
1787 I.Mem.TypeQuals = TypeQuals;
1788 new (I.Mem.ScopeMem) CXXScopeSpec(SS);
1789 return I;
1790 }
1791
1792 /// Return a DeclaratorChunk for a paren.
1793 static DeclaratorChunk getParen(SourceLocation LParenLoc,
1794 SourceLocation RParenLoc) {
1795 DeclaratorChunk I;
1796 I.Kind = Paren;
1797 I.Loc = LParenLoc;
1798 I.EndLoc = RParenLoc;
1799 return I;
1800 }
1801
1802 bool isParen() const {
1803 return Kind == Paren;
1804 }
1805};
1806
1807/// A parsed C++17 decomposition declarator of the form
1808/// '[' identifier-list ']'
1809class DecompositionDeclarator {
1810public:
1811 struct Binding {
1812 IdentifierInfo *Name;
1813 SourceLocation NameLoc;
1814 std::optional<ParsedAttributes> Attrs;
1815 SourceLocation EllipsisLoc;
1816 };
1817
1818private:
1819 /// The locations of the '[' and ']' tokens.
1820 SourceLocation LSquareLoc, RSquareLoc;
1821
1822 /// The bindings.
1823 Binding *Bindings;
1824 unsigned NumBindings : 31;
1825 LLVM_PREFERRED_TYPE(bool)
1826 unsigned DeleteBindings : 1;
1827
1828 friend class Declarator;
1829
1830public:
1831 DecompositionDeclarator()
1832 : Bindings(nullptr), NumBindings(0), DeleteBindings(false) {}
1833 DecompositionDeclarator(const DecompositionDeclarator &G) = delete;
1834 DecompositionDeclarator &operator=(const DecompositionDeclarator &G) = delete;
1835 ~DecompositionDeclarator() { clear(); }
1836
1837 void clear() {
1838 LSquareLoc = RSquareLoc = SourceLocation();
1839 if (DeleteBindings)
1840 delete[] Bindings;
1841 else
1842 for (Binding &B : llvm::MutableArrayRef(Bindings, NumBindings))
1843 B.Attrs.reset();
1844 Bindings = nullptr;
1845 NumBindings = 0;
1846 DeleteBindings = false;
1847 }
1848
1849 ArrayRef<Binding> bindings() const {
1850 return llvm::ArrayRef(Bindings, NumBindings);
1851 }
1852
1853 bool isSet() const { return LSquareLoc.isValid(); }
1854
1855 SourceLocation getLSquareLoc() const { return LSquareLoc; }
1856 SourceLocation getRSquareLoc() const { return RSquareLoc; }
1857 SourceRange getSourceRange() const {
1858 return SourceRange(LSquareLoc, RSquareLoc);
1859 }
1860};
1861
1862/// Described the kind of function definition (if any) provided for
1863/// a function.
1864enum class FunctionDefinitionKind {
1865 Declaration,
1866 Definition,
1867 Defaulted,
1868 Deleted
1869};
1870
1871enum class DeclaratorContext {
1872 File, // File scope declaration.
1873 Prototype, // Within a function prototype.
1874 ObjCResult, // An ObjC method result type.
1875 ObjCParameter, // An ObjC method parameter type.
1876 KNRTypeList, // K&R type definition list for formals.
1877 TypeName, // Abstract declarator for types.
1878 FunctionalCast, // Type in a C++ functional cast expression.
1879 Member, // Struct/Union field.
1880 Block, // Declaration within a block in a function.
1881 ForInit, // Declaration within first part of a for loop.
1882 SelectionInit, // Declaration within optional init stmt of if/switch.
1883 Condition, // Condition declaration in a C++ if/switch/while/for.
1884 TemplateParam, // Within a template parameter list.
1885 CXXNew, // C++ new-expression.
1886 CXXCatch, // C++ catch exception-declaration
1887 ObjCCatch, // Objective-C catch exception-declaration
1888 BlockLiteral, // Block literal declarator.
1889 LambdaExpr, // Lambda-expression declarator.
1890 LambdaExprParameter, // Lambda-expression parameter declarator.
1891 ConversionId, // C++ conversion-type-id.
1892 TrailingReturn, // C++11 trailing-type-specifier.
1893 TrailingReturnVar, // C++11 trailing-type-specifier for variable.
1894 TemplateArg, // Any template argument (in template argument list).
1895 TemplateTypeArg, // Template type argument (in default argument).
1896 AliasDecl, // C++11 alias-declaration.
1897 AliasTemplate, // C++11 alias-declaration template.
1898 RequiresExpr, // C++2a requires-expression.
1899 Association // C11 _Generic selection expression association.
1900};
1901
1902// Describes whether the current context is a context where an implicit
1903// typename is allowed (C++2a [temp.res]p5]).
1904enum class ImplicitTypenameContext {
1905 No,
1906 Yes,
1907};
1908
1909/// Information about one declarator, including the parsed type
1910/// information and the identifier.
1911///
1912/// When the declarator is fully formed, this is turned into the appropriate
1913/// Decl object.
1914///
1915/// Declarators come in two types: normal declarators and abstract declarators.
1916/// Abstract declarators are used when parsing types, and don't have an
1917/// identifier. Normal declarators do have ID's.
1918///
1919/// Instances of this class should be a transient object that lives on the
1920/// stack, not objects that are allocated in large quantities on the heap.
1921class Declarator {
1922
1923private:
1924 const DeclSpec &DS;
1925 CXXScopeSpec SS;
1926 UnqualifiedId Name;
1927 SourceRange Range;
1928
1929 /// Where we are parsing this declarator.
1930 DeclaratorContext Context;
1931
1932 /// The C++17 structured binding, if any. This is an alternative to a Name.
1933 DecompositionDeclarator BindingGroup;
1934
1935 /// DeclTypeInfo - This holds each type that the declarator includes as it is
1936 /// parsed. This is pushed from the identifier out, which means that element
1937 /// #0 will be the most closely bound to the identifier, and
1938 /// DeclTypeInfo.back() will be the least closely bound.
1939 SmallVector<DeclaratorChunk, 4> DeclTypeInfo;
1940
1941 /// InvalidType - Set by Sema::GetTypeForDeclarator().
1942 LLVM_PREFERRED_TYPE(bool)
1943 unsigned InvalidType : 1;
1944
1945 /// GroupingParens - Set by Parser::ParseParenDeclarator().
1946 LLVM_PREFERRED_TYPE(bool)
1947 unsigned GroupingParens : 1;
1948
1949 /// FunctionDefinition - Is this Declarator for a function or member
1950 /// definition and, if so, what kind?
1951 ///
1952 /// Actually a FunctionDefinitionKind.
1953 LLVM_PREFERRED_TYPE(FunctionDefinitionKind)
1954 unsigned FunctionDefinition : 2;
1955
1956 /// Is this Declarator a redeclaration?
1957 LLVM_PREFERRED_TYPE(bool)
1958 unsigned Redeclaration : 1;
1959
1960 /// true if the declaration is preceded by \c __extension__.
1961 LLVM_PREFERRED_TYPE(bool)
1962 unsigned Extension : 1;
1963
1964 /// Indicates whether this is an Objective-C instance variable.
1965 LLVM_PREFERRED_TYPE(bool)
1966 unsigned ObjCIvar : 1;
1967
1968 /// Indicates whether this is an Objective-C 'weak' property.
1969 LLVM_PREFERRED_TYPE(bool)
1970 unsigned ObjCWeakProperty : 1;
1971
1972 /// Indicates whether the InlineParams / InlineBindings storage has been used.
1973 LLVM_PREFERRED_TYPE(bool)
1974 unsigned InlineStorageUsed : 1;
1975
1976 /// Indicates whether this declarator has an initializer.
1977 LLVM_PREFERRED_TYPE(bool)
1978 unsigned HasInitializer : 1;
1979
1980 /// Attributes attached to the declarator.
1981 ParsedAttributes Attrs;
1982
1983 /// Attributes attached to the declaration. See also documentation for the
1984 /// corresponding constructor parameter.
1985 const ParsedAttributesView &DeclarationAttrs;
1986
1987 /// The asm label, if specified.
1988 Expr *AsmLabel;
1989
1990 /// \brief The constraint-expression specified by the trailing
1991 /// requires-clause, or null if no such clause was specified.
1992 Expr *TrailingRequiresClause;
1993
1994 /// If this declarator declares a template, its template parameter lists.
1995 ArrayRef<TemplateParameterList *> TemplateParameterLists;
1996
1997 /// If the declarator declares an abbreviated function template, the innermost
1998 /// template parameter list containing the invented and explicit template
1999 /// parameters (if any).
2000 TemplateParameterList *InventedTemplateParameterList;
2001
2002#ifndef _MSC_VER
2003 union {
2004#endif
2005 /// InlineParams - This is a local array used for the first function decl
2006 /// chunk to avoid going to the heap for the common case when we have one
2007 /// function chunk in the declarator.
2008 DeclaratorChunk::ParamInfo InlineParams[16];
2009 DecompositionDeclarator::Binding InlineBindings[16];
2010#ifndef _MSC_VER
2011 };
2012#endif
2013
2014 /// If this is the second or subsequent declarator in this declaration,
2015 /// the location of the comma before this declarator.
2016 SourceLocation CommaLoc;
2017
2018 /// If provided, the source location of the ellipsis used to describe
2019 /// this declarator as a parameter pack.
2020 SourceLocation EllipsisLoc;
2021
2022 Expr *PackIndexingExpr;
2023
2024 friend struct DeclaratorChunk;
2025
2026public:
2027 /// `DS` and `DeclarationAttrs` must outlive the `Declarator`. In particular,
2028 /// take care not to pass temporary objects for these parameters.
2029 ///
2030 /// `DeclarationAttrs` contains [[]] attributes from the
2031 /// attribute-specifier-seq at the beginning of a declaration, which appertain
2032 /// to the declared entity itself. Attributes with other syntax (e.g. GNU)
2033 /// should not be placed in this attribute list; if they occur at the
2034 /// beginning of a declaration, they apply to the `DeclSpec` and should be
2035 /// attached to that instead.
2036 ///
2037 /// Here is an example of an attribute associated with a declaration:
2038 ///
2039 /// [[deprecated]] int x, y;
2040 ///
2041 /// This attribute appertains to all of the entities declared in the
2042 /// declaration, i.e. `x` and `y` in this case.
2043 Declarator(const DeclSpec &DS, const ParsedAttributesView &DeclarationAttrs,
2044 DeclaratorContext C)
2045 : DS(DS), Range(DS.getSourceRange()), Context(C),
2046 InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
2047 GroupingParens(false), FunctionDefinition(static_cast<unsigned>(
2048 FunctionDefinitionKind::Declaration)),
2049 Redeclaration(false), Extension(false), ObjCIvar(false),
2050 ObjCWeakProperty(false), InlineStorageUsed(false),
2051 HasInitializer(false), Attrs(DS.getAttributePool().getFactory()),
2052 DeclarationAttrs(DeclarationAttrs), AsmLabel(nullptr),
2053 TrailingRequiresClause(nullptr),
2054 InventedTemplateParameterList(nullptr) {
2055 assert(llvm::all_of(DeclarationAttrs,
2056 [](const ParsedAttr &AL) {
2057 return (AL.isStandardAttributeSyntax() ||
2058 AL.isRegularKeywordAttribute());
2059 }) &&
2060 "DeclarationAttrs may only contain [[]] and keyword attributes");
2061 }
2062
2063 ~Declarator() {
2064 clear();
2065 }
2066 /// getDeclSpec - Return the declaration-specifier that this declarator was
2067 /// declared with.
2068 const DeclSpec &getDeclSpec() const { return DS; }
2069
2070 /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This
2071 /// should be used with extreme care: declspecs can often be shared between
2072 /// multiple declarators, so mutating the DeclSpec affects all of the
2073 /// Declarators. This should only be done when the declspec is known to not
2074 /// be shared or when in error recovery etc.
2075 DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
2076
2077 AttributePool &getAttributePool() const {
2078 return Attrs.getPool();
2079 }
2080
2081 /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
2082 /// nested-name-specifier) that is part of the declarator-id.
2083 const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
2084 CXXScopeSpec &getCXXScopeSpec() { return SS; }
2085
2086 /// Retrieve the name specified by this declarator.
2087 UnqualifiedId &getName() { return Name; }
2088
2089 const DecompositionDeclarator &getDecompositionDeclarator() const {
2090 return BindingGroup;
2091 }
2092
2093 DeclaratorContext getContext() const { return Context; }
2094
2095 bool isPrototypeContext() const {
2096 return (Context == DeclaratorContext::Prototype ||
2097 Context == DeclaratorContext::ObjCParameter ||
2098 Context == DeclaratorContext::ObjCResult ||
2099 Context == DeclaratorContext::LambdaExprParameter);
2100 }
2101
2102 /// Get the source range that spans this declarator.
2103 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2104 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2105 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2106
2107 void SetSourceRange(SourceRange R) { Range = R; }
2108 /// SetRangeBegin - Set the start of the source range to Loc, unless it's
2109 /// invalid.
2110 void SetRangeBegin(SourceLocation Loc) {
2111 if (!Loc.isInvalid())
2112 Range.setBegin(Loc);
2113 }
2114 /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
2115 void SetRangeEnd(SourceLocation Loc) {
2116 if (!Loc.isInvalid())
2117 Range.setEnd(Loc);
2118 }
2119 /// ExtendWithDeclSpec - Extend the declarator source range to include the
2120 /// given declspec, unless its location is invalid. Adopts the range start if
2121 /// the current range start is invalid.
2122 void ExtendWithDeclSpec(const DeclSpec &DS) {
2123 SourceRange SR = DS.getSourceRange();
2124 if (Range.getBegin().isInvalid())
2125 Range.setBegin(SR.getBegin());
2126 if (!SR.getEnd().isInvalid())
2127 Range.setEnd(SR.getEnd());
2128 }
2129
2130 /// Reset the contents of this Declarator.
2131 void clear() {
2132 SS.clear();
2133 Name.clear();
2134 Range = DS.getSourceRange();
2135 BindingGroup.clear();
2136
2137 for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
2138 DeclTypeInfo[i].destroy();
2139 DeclTypeInfo.clear();
2140 Attrs.clear();
2141 AsmLabel = nullptr;
2142 InlineStorageUsed = false;
2143 HasInitializer = false;
2144 ObjCIvar = false;
2145 ObjCWeakProperty = false;
2146 CommaLoc = SourceLocation();
2147 EllipsisLoc = SourceLocation();
2148 PackIndexingExpr = nullptr;
2149 }
2150
2151 /// mayOmitIdentifier - Return true if the identifier is either optional or
2152 /// not allowed. This is true for typenames, prototypes, and template
2153 /// parameter lists.
2154 bool mayOmitIdentifier() const {
2155 switch (Context) {
2156 case DeclaratorContext::File:
2157 case DeclaratorContext::KNRTypeList:
2158 case DeclaratorContext::Member:
2159 case DeclaratorContext::Block:
2160 case DeclaratorContext::ForInit:
2161 case DeclaratorContext::SelectionInit:
2162 case DeclaratorContext::Condition:
2163 return false;
2164
2165 case DeclaratorContext::TypeName:
2166 case DeclaratorContext::FunctionalCast:
2167 case DeclaratorContext::AliasDecl:
2168 case DeclaratorContext::AliasTemplate:
2169 case DeclaratorContext::Prototype:
2170 case DeclaratorContext::LambdaExprParameter:
2171 case DeclaratorContext::ObjCParameter:
2172 case DeclaratorContext::ObjCResult:
2173 case DeclaratorContext::TemplateParam:
2174 case DeclaratorContext::CXXNew:
2175 case DeclaratorContext::CXXCatch:
2176 case DeclaratorContext::ObjCCatch:
2177 case DeclaratorContext::BlockLiteral:
2178 case DeclaratorContext::LambdaExpr:
2179 case DeclaratorContext::ConversionId:
2180 case DeclaratorContext::TemplateArg:
2181 case DeclaratorContext::TemplateTypeArg:
2182 case DeclaratorContext::TrailingReturn:
2183 case DeclaratorContext::TrailingReturnVar:
2184 case DeclaratorContext::RequiresExpr:
2185 case DeclaratorContext::Association:
2186 return true;
2187 }
2188 llvm_unreachable("unknown context kind!");
2189 }
2190
2191 /// mayHaveIdentifier - Return true if the identifier is either optional or
2192 /// required. This is true for normal declarators and prototypes, but not
2193 /// typenames.
2194 bool mayHaveIdentifier() const {
2195 switch (Context) {
2196 case DeclaratorContext::File:
2197 case DeclaratorContext::KNRTypeList:
2198 case DeclaratorContext::Member:
2199 case DeclaratorContext::Block:
2200 case DeclaratorContext::ForInit:
2201 case DeclaratorContext::SelectionInit:
2202 case DeclaratorContext::Condition:
2203 case DeclaratorContext::Prototype:
2204 case DeclaratorContext::LambdaExprParameter:
2205 case DeclaratorContext::TemplateParam:
2206 case DeclaratorContext::CXXCatch:
2207 case DeclaratorContext::ObjCCatch:
2208 case DeclaratorContext::RequiresExpr:
2209 return true;
2210
2211 case DeclaratorContext::TypeName:
2212 case DeclaratorContext::FunctionalCast:
2213 case DeclaratorContext::CXXNew:
2214 case DeclaratorContext::AliasDecl:
2215 case DeclaratorContext::AliasTemplate:
2216 case DeclaratorContext::ObjCParameter:
2217 case DeclaratorContext::ObjCResult:
2218 case DeclaratorContext::BlockLiteral:
2219 case DeclaratorContext::LambdaExpr:
2220 case DeclaratorContext::ConversionId:
2221 case DeclaratorContext::TemplateArg:
2222 case DeclaratorContext::TemplateTypeArg:
2223 case DeclaratorContext::TrailingReturn:
2224 case DeclaratorContext::TrailingReturnVar:
2225 case DeclaratorContext::Association:
2226 return false;
2227 }
2228 llvm_unreachable("unknown context kind!");
2229 }
2230
2231 /// Return true if the context permits a C++17 decomposition declarator.
2232 bool mayHaveDecompositionDeclarator() const {
2233 switch (Context) {
2234 case DeclaratorContext::File:
2235 // FIXME: It's not clear that the proposal meant to allow file-scope
2236 // structured bindings, but it does.
2237 case DeclaratorContext::Block:
2238 case DeclaratorContext::ForInit:
2239 case DeclaratorContext::SelectionInit:
2240 case DeclaratorContext::Condition:
2241 return true;
2242
2243 case DeclaratorContext::Member:
2244 case DeclaratorContext::Prototype:
2245 case DeclaratorContext::TemplateParam:
2246 case DeclaratorContext::RequiresExpr:
2247 // Maybe one day...
2248 return false;
2249
2250 // These contexts don't allow any kind of non-abstract declarator.
2251 case DeclaratorContext::KNRTypeList:
2252 case DeclaratorContext::TypeName:
2253 case DeclaratorContext::FunctionalCast:
2254 case DeclaratorContext::AliasDecl:
2255 case DeclaratorContext::AliasTemplate:
2256 case DeclaratorContext::LambdaExprParameter:
2257 case DeclaratorContext::ObjCParameter:
2258 case DeclaratorContext::ObjCResult:
2259 case DeclaratorContext::CXXNew:
2260 case DeclaratorContext::CXXCatch:
2261 case DeclaratorContext::ObjCCatch:
2262 case DeclaratorContext::BlockLiteral:
2263 case DeclaratorContext::LambdaExpr:
2264 case DeclaratorContext::ConversionId:
2265 case DeclaratorContext::TemplateArg:
2266 case DeclaratorContext::TemplateTypeArg:
2267 case DeclaratorContext::TrailingReturn:
2268 case DeclaratorContext::TrailingReturnVar:
2269 case DeclaratorContext::Association:
2270 return false;
2271 }
2272 llvm_unreachable("unknown context kind!");
2273 }
2274
2275 /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
2276 /// followed by a C++ direct initializer, e.g. "int x(1);".
2277 bool mayBeFollowedByCXXDirectInit() const {
2278 if (hasGroupingParens()) return false;
2279
2280 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
2281 return false;
2282
2283 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern &&
2284 Context != DeclaratorContext::File)
2285 return false;
2286
2287 // Special names can't have direct initializers.
2288 if (Name.getKind() != UnqualifiedIdKind::IK_Identifier)
2289 return false;
2290
2291 switch (Context) {
2292 case DeclaratorContext::File:
2293 case DeclaratorContext::Block:
2294 case DeclaratorContext::ForInit:
2295 case DeclaratorContext::SelectionInit:
2296 case DeclaratorContext::TrailingReturnVar:
2297 return true;
2298
2299 case DeclaratorContext::Condition:
2300 // This may not be followed by a direct initializer, but it can't be a
2301 // function declaration either, and we'd prefer to perform a tentative
2302 // parse in order to produce the right diagnostic.
2303 return true;
2304
2305 case DeclaratorContext::KNRTypeList:
2306 case DeclaratorContext::Member:
2307 case DeclaratorContext::Prototype:
2308 case DeclaratorContext::LambdaExprParameter:
2309 case DeclaratorContext::ObjCParameter:
2310 case DeclaratorContext::ObjCResult:
2311 case DeclaratorContext::TemplateParam:
2312 case DeclaratorContext::CXXCatch:
2313 case DeclaratorContext::ObjCCatch:
2314 case DeclaratorContext::TypeName:
2315 case DeclaratorContext::FunctionalCast: // FIXME
2316 case DeclaratorContext::CXXNew:
2317 case DeclaratorContext::AliasDecl:
2318 case DeclaratorContext::AliasTemplate:
2319 case DeclaratorContext::BlockLiteral:
2320 case DeclaratorContext::LambdaExpr:
2321 case DeclaratorContext::ConversionId:
2322 case DeclaratorContext::TemplateArg:
2323 case DeclaratorContext::TemplateTypeArg:
2324 case DeclaratorContext::TrailingReturn:
2325 case DeclaratorContext::RequiresExpr:
2326 case DeclaratorContext::Association:
2327 return false;
2328 }
2329 llvm_unreachable("unknown context kind!");
2330 }
2331
2332 /// isPastIdentifier - Return true if we have parsed beyond the point where
2333 /// the name would appear. (This may happen even if we haven't actually parsed
2334 /// a name, perhaps because this context doesn't require one.)
2335 bool isPastIdentifier() const { return Name.isValid(); }
2336
2337 /// hasName - Whether this declarator has a name, which might be an
2338 /// identifier (accessible via getIdentifier()) or some kind of
2339 /// special C++ name (constructor, destructor, etc.), or a structured
2340 /// binding (which is not exactly a name, but occupies the same position).
2341 bool hasName() const {
2342 return Name.getKind() != UnqualifiedIdKind::IK_Identifier ||
2343 Name.Identifier || isDecompositionDeclarator();
2344 }
2345
2346 /// Return whether this declarator is a decomposition declarator.
2347 bool isDecompositionDeclarator() const {
2348 return BindingGroup.isSet();
2349 }
2350
2351 const IdentifierInfo *getIdentifier() const {
2352 if (Name.getKind() == UnqualifiedIdKind::IK_Identifier)
2353 return Name.Identifier;
2354
2355 return nullptr;
2356 }
2357 SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
2358
2359 /// Set the name of this declarator to be the given identifier.
2360 void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
2361 Name.setIdentifier(Id, IdLoc);
2362 }
2363
2364 /// Set the decomposition bindings for this declarator.
2365 void setDecompositionBindings(
2366 SourceLocation LSquareLoc,
2367 MutableArrayRef<DecompositionDeclarator::Binding> Bindings,
2368 SourceLocation RSquareLoc);
2369
2370 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2371 /// EndLoc, which should be the last token of the chunk.
2372 /// This function takes attrs by R-Value reference because it takes ownership
2373 /// of those attributes from the parameter.
2374 void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs,
2375 SourceLocation EndLoc) {
2376 DeclTypeInfo.push_back(Elt: TI);
2377 DeclTypeInfo.back().getAttrs().prepend(B: attrs.begin(), E: attrs.end());
2378 getAttributePool().takeAllFrom(pool&: attrs.getPool());
2379
2380 if (!EndLoc.isInvalid())
2381 SetRangeEnd(EndLoc);
2382 }
2383
2384 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2385 /// EndLoc, which should be the last token of the chunk. This overload is for
2386 /// copying a 'chunk' from another declarator, so it takes the pool that the
2387 /// other Declarator owns so that it can 'take' the attributes from it.
2388 void AddTypeInfo(const DeclaratorChunk &TI, AttributePool &OtherPool,
2389 SourceLocation EndLoc) {
2390 DeclTypeInfo.push_back(Elt: TI);
2391 getAttributePool().takeFrom(List&: DeclTypeInfo.back().getAttrs(), Pool&: OtherPool);
2392
2393 if (!EndLoc.isInvalid())
2394 SetRangeEnd(EndLoc);
2395 }
2396
2397 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2398 /// EndLoc, which should be the last token of the chunk.
2399 void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) {
2400 DeclTypeInfo.push_back(Elt: TI);
2401
2402 assert(TI.AttrList.empty() &&
2403 "Cannot add a declarator chunk with attributes with this overload");
2404
2405 if (!EndLoc.isInvalid())
2406 SetRangeEnd(EndLoc);
2407 }
2408
2409 /// Add a new innermost chunk to this declarator.
2410 void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
2411 DeclTypeInfo.insert(I: DeclTypeInfo.begin(), Elt: TI);
2412 }
2413
2414 /// Return the number of types applied to this declarator.
2415 unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
2416
2417 /// Return the specified TypeInfo from this declarator. TypeInfo #0 is
2418 /// closest to the identifier.
2419 const DeclaratorChunk &getTypeObject(unsigned i) const {
2420 assert(i < DeclTypeInfo.size() && "Invalid type chunk");
2421 return DeclTypeInfo[i];
2422 }
2423 DeclaratorChunk &getTypeObject(unsigned i) {
2424 assert(i < DeclTypeInfo.size() && "Invalid type chunk");
2425 return DeclTypeInfo[i];
2426 }
2427
2428 typedef SmallVectorImpl<DeclaratorChunk>::const_iterator type_object_iterator;
2429 typedef llvm::iterator_range<type_object_iterator> type_object_range;
2430
2431 /// Returns the range of type objects, from the identifier outwards.
2432 type_object_range type_objects() const {
2433 return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end());
2434 }
2435
2436 void DropFirstTypeObject() {
2437 assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
2438 DeclTypeInfo.front().destroy();
2439 DeclTypeInfo.erase(CI: DeclTypeInfo.begin());
2440 }
2441
2442 /// Return the innermost (closest to the declarator) chunk of this
2443 /// declarator that is not a parens chunk, or null if there are no
2444 /// non-parens chunks.
2445 const DeclaratorChunk *getInnermostNonParenChunk() const {
2446 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2447 if (!DeclTypeInfo[i].isParen())
2448 return &DeclTypeInfo[i];
2449 }
2450 return nullptr;
2451 }
2452
2453 /// Return the outermost (furthest from the declarator) chunk of
2454 /// this declarator that is not a parens chunk, or null if there are
2455 /// no non-parens chunks.
2456 const DeclaratorChunk *getOutermostNonParenChunk() const {
2457 for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) {
2458 if (!DeclTypeInfo[i-1].isParen())
2459 return &DeclTypeInfo[i-1];
2460 }
2461 return nullptr;
2462 }
2463
2464 /// isArrayOfUnknownBound - This method returns true if the declarator
2465 /// is a declarator for an array of unknown bound (looking through
2466 /// parentheses).
2467 bool isArrayOfUnknownBound() const {
2468 const DeclaratorChunk *chunk = getInnermostNonParenChunk();
2469 return (chunk && chunk->Kind == DeclaratorChunk::Array &&
2470 !chunk->Arr.NumElts);
2471 }
2472
2473 /// isFunctionDeclarator - This method returns true if the declarator
2474 /// is a function declarator (looking through parentheses).
2475 /// If true is returned, then the reference type parameter idx is
2476 /// assigned with the index of the declaration chunk.
2477 bool isFunctionDeclarator(unsigned& idx) const {
2478 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2479 switch (DeclTypeInfo[i].Kind) {
2480 case DeclaratorChunk::Function:
2481 idx = i;
2482 return true;
2483 case DeclaratorChunk::Paren:
2484 continue;
2485 case DeclaratorChunk::Pointer:
2486 case DeclaratorChunk::Reference:
2487 case DeclaratorChunk::Array:
2488 case DeclaratorChunk::BlockPointer:
2489 case DeclaratorChunk::MemberPointer:
2490 case DeclaratorChunk::Pipe:
2491 return false;
2492 }
2493 llvm_unreachable("Invalid type chunk");
2494 }
2495 return false;
2496 }
2497
2498 /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
2499 /// this method returns true if the identifier is a function declarator
2500 /// (looking through parentheses).
2501 bool isFunctionDeclarator() const {
2502 unsigned index;
2503 return isFunctionDeclarator(idx&: index);
2504 }
2505
2506 /// getFunctionTypeInfo - Retrieves the function type info object
2507 /// (looking through parentheses).
2508 DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
2509 assert(isFunctionDeclarator() && "Not a function declarator!");
2510 unsigned index = 0;
2511 isFunctionDeclarator(idx&: index);
2512 return DeclTypeInfo[index].Fun;
2513 }
2514
2515 /// getFunctionTypeInfo - Retrieves the function type info object
2516 /// (looking through parentheses).
2517 const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
2518 return const_cast<Declarator*>(this)->getFunctionTypeInfo();
2519 }
2520
2521 /// Determine whether the declaration that will be produced from
2522 /// this declaration will be a function.
2523 ///
2524 /// A declaration can declare a function even if the declarator itself
2525 /// isn't a function declarator, if the type specifier refers to a function
2526 /// type. This routine checks for both cases.
2527 bool isDeclarationOfFunction() const;
2528
2529 /// Return true if this declaration appears in a context where a
2530 /// function declarator would be a function declaration.
2531 bool isFunctionDeclarationContext() const {
2532 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
2533 return false;
2534
2535 switch (Context) {
2536 case DeclaratorContext::File:
2537 case DeclaratorContext::Member:
2538 case DeclaratorContext::Block:
2539 case DeclaratorContext::ForInit:
2540 case DeclaratorContext::SelectionInit:
2541 return true;
2542
2543 case DeclaratorContext::Condition:
2544 case DeclaratorContext::KNRTypeList:
2545 case DeclaratorContext::TypeName:
2546 case DeclaratorContext::FunctionalCast:
2547 case DeclaratorContext::AliasDecl:
2548 case DeclaratorContext::AliasTemplate:
2549 case DeclaratorContext::Prototype:
2550 case DeclaratorContext::LambdaExprParameter:
2551 case DeclaratorContext::ObjCParameter:
2552 case DeclaratorContext::ObjCResult:
2553 case DeclaratorContext::TemplateParam:
2554 case DeclaratorContext::CXXNew:
2555 case DeclaratorContext::CXXCatch:
2556 case DeclaratorContext::ObjCCatch:
2557 case DeclaratorContext::BlockLiteral:
2558 case DeclaratorContext::LambdaExpr:
2559 case DeclaratorContext::ConversionId:
2560 case DeclaratorContext::TemplateArg:
2561 case DeclaratorContext::TemplateTypeArg:
2562 case DeclaratorContext::TrailingReturn:
2563 case DeclaratorContext::TrailingReturnVar:
2564 case DeclaratorContext::RequiresExpr:
2565 case DeclaratorContext::Association:
2566 return false;
2567 }
2568 llvm_unreachable("unknown context kind!");
2569 }
2570
2571 /// Determine whether this declaration appears in a context where an
2572 /// expression could appear.
2573 bool isExpressionContext() const {
2574 switch (Context) {
2575 case DeclaratorContext::File:
2576 case DeclaratorContext::KNRTypeList:
2577 case DeclaratorContext::Member:
2578
2579 // FIXME: sizeof(...) permits an expression.
2580 case DeclaratorContext::TypeName:
2581
2582 case DeclaratorContext::FunctionalCast:
2583 case DeclaratorContext::AliasDecl:
2584 case DeclaratorContext::AliasTemplate:
2585 case DeclaratorContext::Prototype:
2586 case DeclaratorContext::LambdaExprParameter:
2587 case DeclaratorContext::ObjCParameter:
2588 case DeclaratorContext::ObjCResult:
2589 case DeclaratorContext::TemplateParam:
2590 case DeclaratorContext::CXXNew:
2591 case DeclaratorContext::CXXCatch:
2592 case DeclaratorContext::ObjCCatch:
2593 case DeclaratorContext::BlockLiteral:
2594 case DeclaratorContext::LambdaExpr:
2595 case DeclaratorContext::ConversionId:
2596 case DeclaratorContext::TrailingReturn:
2597 case DeclaratorContext::TrailingReturnVar:
2598 case DeclaratorContext::TemplateTypeArg:
2599 case DeclaratorContext::RequiresExpr:
2600 case DeclaratorContext::Association:
2601 return false;
2602
2603 case DeclaratorContext::Block:
2604 case DeclaratorContext::ForInit:
2605 case DeclaratorContext::SelectionInit:
2606 case DeclaratorContext::Condition:
2607 case DeclaratorContext::TemplateArg:
2608 return true;
2609 }
2610
2611 llvm_unreachable("unknown context kind!");
2612 }
2613
2614 /// Return true if a function declarator at this position would be a
2615 /// function declaration.
2616 bool isFunctionDeclaratorAFunctionDeclaration() const {
2617 if (!isFunctionDeclarationContext())
2618 return false;
2619
2620 for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I)
2621 if (getTypeObject(i: I).Kind != DeclaratorChunk::Paren)
2622 return false;
2623
2624 return true;
2625 }
2626
2627 /// Determine whether a trailing return type was written (at any
2628 /// level) within this declarator.
2629 bool hasTrailingReturnType() const {
2630 for (const auto &Chunk : type_objects())
2631 if (Chunk.Kind == DeclaratorChunk::Function &&
2632 Chunk.Fun.hasTrailingReturnType())
2633 return true;
2634 return false;
2635 }
2636 /// Get the trailing return type appearing (at any level) within this
2637 /// declarator.
2638 ParsedType getTrailingReturnType() const {
2639 for (const auto &Chunk : type_objects())
2640 if (Chunk.Kind == DeclaratorChunk::Function &&
2641 Chunk.Fun.hasTrailingReturnType())
2642 return Chunk.Fun.getTrailingReturnType();
2643 return ParsedType();
2644 }
2645
2646 /// \brief Sets a trailing requires clause for this declarator.
2647 void setTrailingRequiresClause(Expr *TRC) {
2648 TrailingRequiresClause = TRC;
2649
2650 SetRangeEnd(TRC->getEndLoc());
2651 }
2652
2653 /// \brief Sets a trailing requires clause for this declarator.
2654 Expr *getTrailingRequiresClause() {
2655 return TrailingRequiresClause;
2656 }
2657
2658 /// \brief Determine whether a trailing requires clause was written in this
2659 /// declarator.
2660 bool hasTrailingRequiresClause() const {
2661 return TrailingRequiresClause != nullptr;
2662 }
2663
2664 /// Sets the template parameter lists that preceded the declarator.
2665 void setTemplateParameterLists(ArrayRef<TemplateParameterList *> TPLs) {
2666 TemplateParameterLists = TPLs;
2667 }
2668
2669 /// The template parameter lists that preceded the declarator.
2670 ArrayRef<TemplateParameterList *> getTemplateParameterLists() const {
2671 return TemplateParameterLists;
2672 }
2673
2674 /// Sets the template parameter list generated from the explicit template
2675 /// parameters along with any invented template parameters from
2676 /// placeholder-typed parameters.
2677 void setInventedTemplateParameterList(TemplateParameterList *Invented) {
2678 InventedTemplateParameterList = Invented;
2679 }
2680
2681 /// The template parameter list generated from the explicit template
2682 /// parameters along with any invented template parameters from
2683 /// placeholder-typed parameters, if there were any such parameters.
2684 TemplateParameterList * getInventedTemplateParameterList() const {
2685 return InventedTemplateParameterList;
2686 }
2687
2688 /// takeAttributesAppending - Takes attributes from the given
2689 /// ParsedAttributes set and add them to this declarator.
2690 ///
2691 /// These examples both add 3 attributes to "var":
2692 /// short int var __attribute__((aligned(16),common,deprecated));
2693 /// short int x, __attribute__((aligned(16)) var
2694 /// __attribute__((common,deprecated));
2695 ///
2696 /// Also extends the range of the declarator.
2697 void takeAttributesAppending(ParsedAttributes &attrs) {
2698 Attrs.takeAllAppendingFrom(Other&: attrs);
2699
2700 if (attrs.Range.getEnd().isValid())
2701 SetRangeEnd(attrs.Range.getEnd());
2702 }
2703
2704 const ParsedAttributes &getAttributes() const { return Attrs; }
2705 ParsedAttributes &getAttributes() { return Attrs; }
2706
2707 const ParsedAttributesView &getDeclarationAttributes() const {
2708 return DeclarationAttrs;
2709 }
2710
2711 /// hasAttributes - do we contain any attributes?
2712 bool hasAttributes() const {
2713 if (!getAttributes().empty() || !getDeclarationAttributes().empty() ||
2714 getDeclSpec().hasAttributes())
2715 return true;
2716 for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
2717 if (!getTypeObject(i).getAttrs().empty())
2718 return true;
2719 return false;
2720 }
2721
2722 void setAsmLabel(Expr *E) { AsmLabel = E; }
2723 Expr *getAsmLabel() const { return AsmLabel; }
2724
2725 void setExtension(bool Val = true) { Extension = Val; }
2726 bool getExtension() const { return Extension; }
2727
2728 void setObjCIvar(bool Val = true) { ObjCIvar = Val; }
2729 bool isObjCIvar() const { return ObjCIvar; }
2730
2731 void setObjCWeakProperty(bool Val = true) { ObjCWeakProperty = Val; }
2732 bool isObjCWeakProperty() const { return ObjCWeakProperty; }
2733
2734 void setInvalidType(bool Val = true) { InvalidType = Val; }
2735 bool isInvalidType() const {
2736 return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
2737 }
2738
2739 void setGroupingParens(bool flag) { GroupingParens = flag; }
2740 bool hasGroupingParens() const { return GroupingParens; }
2741
2742 bool isFirstDeclarator() const { return !CommaLoc.isValid(); }
2743 SourceLocation getCommaLoc() const { return CommaLoc; }
2744 void setCommaLoc(SourceLocation CL) { CommaLoc = CL; }
2745
2746 bool hasEllipsis() const { return EllipsisLoc.isValid(); }
2747 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2748 void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
2749
2750 bool hasPackIndexing() const { return PackIndexingExpr != nullptr; }
2751 Expr *getPackIndexingExpr() const { return PackIndexingExpr; }
2752 void setPackIndexingExpr(Expr *PI) { PackIndexingExpr = PI; }
2753
2754 void setFunctionDefinitionKind(FunctionDefinitionKind Val) {
2755 FunctionDefinition = static_cast<unsigned>(Val);
2756 }
2757
2758 bool isFunctionDefinition() const {
2759 return getFunctionDefinitionKind() != FunctionDefinitionKind::Declaration;
2760 }
2761
2762 FunctionDefinitionKind getFunctionDefinitionKind() const {
2763 return (FunctionDefinitionKind)FunctionDefinition;
2764 }
2765
2766 void setHasInitializer(bool Val = true) { HasInitializer = Val; }
2767 bool hasInitializer() const { return HasInitializer; }
2768
2769 /// Returns true if this declares a real member and not a friend.
2770 bool isFirstDeclarationOfMember() {
2771 return getContext() == DeclaratorContext::Member &&
2772 !getDeclSpec().isFriendSpecified();
2773 }
2774
2775 /// Returns true if this declares a static member. This cannot be called on a
2776 /// declarator outside of a MemberContext because we won't know until
2777 /// redeclaration time if the decl is static.
2778 bool isStaticMember();
2779
2780 bool isExplicitObjectMemberFunction();
2781
2782 /// Returns true if this declares a constructor or a destructor.
2783 bool isCtorOrDtor();
2784
2785 void setRedeclaration(bool Val) { Redeclaration = Val; }
2786 bool isRedeclaration() const { return Redeclaration; }
2787};
2788
2789/// This little struct is used to capture information about
2790/// structure field declarators, which is basically just a bitfield size.
2791struct FieldDeclarator {
2792 Declarator D;
2793 Expr *BitfieldSize;
2794 explicit FieldDeclarator(const DeclSpec &DS,
2795 const ParsedAttributes &DeclarationAttrs)
2796 : D(DS, DeclarationAttrs, DeclaratorContext::Member),
2797 BitfieldSize(nullptr) {}
2798};
2799
2800/// Represents a C++11 virt-specifier-seq.
2801class VirtSpecifiers {
2802public:
2803 enum Specifier {
2804 VS_None = 0,
2805 VS_Override = 1,
2806 VS_Final = 2,
2807 VS_Sealed = 4,
2808 // Represents the __final keyword, which is legal for gcc in pre-C++11 mode.
2809 VS_GNU_Final = 8,
2810 VS_Abstract = 16
2811 };
2812
2813 VirtSpecifiers() = default;
2814
2815 bool SetSpecifier(Specifier VS, SourceLocation Loc,
2816 const char *&PrevSpec);
2817
2818 bool isUnset() const { return Specifiers == 0; }
2819
2820 bool isOverrideSpecified() const { return Specifiers & VS_Override; }
2821 SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
2822
2823 bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed | VS_GNU_Final); }
2824 bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; }
2825 SourceLocation getFinalLoc() const { return VS_finalLoc; }
2826 SourceLocation getAbstractLoc() const { return VS_abstractLoc; }
2827
2828 void clear() { Specifiers = 0; }
2829
2830 static const char *getSpecifierName(Specifier VS);
2831
2832 SourceLocation getFirstLocation() const { return FirstLocation; }
2833 SourceLocation getLastLocation() const { return LastLocation; }
2834 Specifier getLastSpecifier() const { return LastSpecifier; }
2835
2836private:
2837 unsigned Specifiers = 0;
2838 Specifier LastSpecifier = VS_None;
2839
2840 SourceLocation VS_overrideLoc, VS_finalLoc, VS_abstractLoc;
2841 SourceLocation FirstLocation;
2842 SourceLocation LastLocation;
2843};
2844
2845enum class LambdaCaptureInitKind {
2846 NoInit, //!< [a]
2847 CopyInit, //!< [a = b], [a = {b}]
2848 DirectInit, //!< [a(b)]
2849 ListInit //!< [a{b}]
2850};
2851
2852/// Represents a complete lambda introducer.
2853struct LambdaIntroducer {
2854 /// An individual capture in a lambda introducer.
2855 struct LambdaCapture {
2856 LambdaCaptureKind Kind;
2857 SourceLocation Loc;
2858 IdentifierInfo *Id;
2859 SourceLocation EllipsisLoc;
2860 LambdaCaptureInitKind InitKind;
2861 ExprResult Init;
2862 ParsedType InitCaptureType;
2863 SourceRange ExplicitRange;
2864
2865 LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc,
2866 IdentifierInfo *Id, SourceLocation EllipsisLoc,
2867 LambdaCaptureInitKind InitKind, ExprResult Init,
2868 ParsedType InitCaptureType,
2869 SourceRange ExplicitRange)
2870 : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc),
2871 InitKind(InitKind), Init(Init), InitCaptureType(InitCaptureType),
2872 ExplicitRange(ExplicitRange) {}
2873 };
2874
2875 SourceRange Range;
2876 SourceLocation DefaultLoc;
2877 LambdaCaptureDefault Default = LCD_None;
2878 SmallVector<LambdaCapture, 4> Captures;
2879
2880 LambdaIntroducer() = default;
2881
2882 bool hasLambdaCapture() const {
2883 return Captures.size() > 0 || Default != LCD_None;
2884 }
2885
2886 /// Append a capture in a lambda introducer.
2887 void addCapture(LambdaCaptureKind Kind,
2888 SourceLocation Loc,
2889 IdentifierInfo* Id,
2890 SourceLocation EllipsisLoc,
2891 LambdaCaptureInitKind InitKind,
2892 ExprResult Init,
2893 ParsedType InitCaptureType,
2894 SourceRange ExplicitRange) {
2895 Captures.push_back(Elt: LambdaCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
2896 InitCaptureType, ExplicitRange));
2897 }
2898};
2899
2900struct InventedTemplateParameterInfo {
2901 /// The number of parameters in the template parameter list that were
2902 /// explicitly specified by the user, as opposed to being invented by use
2903 /// of an auto parameter.
2904 unsigned NumExplicitTemplateParams = 0;
2905
2906 /// If this is a generic lambda or abbreviated function template, use this
2907 /// as the depth of each 'auto' parameter, during initial AST construction.
2908 unsigned AutoTemplateParameterDepth = 0;
2909
2910 /// Store the list of the template parameters for a generic lambda or an
2911 /// abbreviated function template.
2912 /// If this is a generic lambda or abbreviated function template, this holds
2913 /// the explicit template parameters followed by the auto parameters
2914 /// converted into TemplateTypeParmDecls.
2915 /// It can be used to construct the generic lambda or abbreviated template's
2916 /// template parameter list during initial AST construction.
2917 SmallVector<NamedDecl*, 4> TemplateParams;
2918};
2919
2920} // end namespace clang
2921
2922#endif // LLVM_CLANG_SEMA_DECLSPEC_H
2923