Coverage Report

Created: 2019-07-24 05:18

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