Coverage Report

Created: 2021-09-21 08:58

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