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