Coverage Report

Created: 2019-02-15 18:59

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