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

source code of clang/include/clang/Sema/DeclSpec.h