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