Coverage Report

Created: 2022-07-16 07:03

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