Coverage Report

Created: 2020-02-15 09:57

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