Coverage Report

Created: 2018-07-22 10:17

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