DeclSpec.h revision 555f57e3549fb5cc963a2ce38180c4f3643a6f95
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// This file defines the classes used to store parsed information about
11// declaration-specifiers and declarators.
12//
13//   static const int volatile x, *y, *(*(*z)[10])(const void *x);
14//   ------------------------- -  --  ---------------------------
15//     declaration-specifiers  \  |   /
16//                            declarators
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef LLVM_CLANG_SEMA_DECLSPEC_H
21#define LLVM_CLANG_SEMA_DECLSPEC_H
22
23#include "clang/Sema/AttributeList.h"
24#include "clang/Sema/Ownership.h"
25#include "clang/AST/NestedNameSpecifier.h"
26#include "clang/Lex/Token.h"
27#include "clang/Basic/ExceptionSpecificationType.h"
28#include "clang/Basic/OperatorKinds.h"
29#include "clang/Basic/Specifiers.h"
30#include "llvm/ADT/SmallVector.h"
31#include "llvm/Support/ErrorHandling.h"
32
33namespace clang {
34  class ASTContext;
35  class TypeLoc;
36  class LangOptions;
37  class Diagnostic;
38  class IdentifierInfo;
39  class NamespaceAliasDecl;
40  class NamespaceDecl;
41  class NestedNameSpecifier;
42  class NestedNameSpecifierLoc;
43  class ObjCDeclSpec;
44  class Preprocessor;
45  class Declarator;
46  struct TemplateIdAnnotation;
47
48/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope
49/// specifier.  These can be in 3 states:
50///   1) Not present, identified by isEmpty()
51///   2) Present, identified by isNotEmpty()
52///      2.a) Valid, idenified by isValid()
53///      2.b) Invalid, identified by isInvalid().
54///
55/// isSet() is deprecated because it mostly corresponded to "valid" but was
56/// often used as if it meant "present".
57///
58/// The actual scope is described by getScopeRep().
59class CXXScopeSpec {
60  SourceRange Range;
61  NestedNameSpecifierLocBuilder Builder;
62
63public:
64  const SourceRange &getRange() const { return Range; }
65  void setRange(const SourceRange &R) { Range = R; }
66  void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
67  void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
68  SourceLocation getBeginLoc() const { return Range.getBegin(); }
69  SourceLocation getEndLoc() const { return Range.getEnd(); }
70
71  /// \brief Retrieve the representation of the nested-name-specifier.
72  NestedNameSpecifier *getScopeRep() const {
73    return Builder.getRepresentation();
74  }
75
76  /// \brief Extend the current nested-name-specifier by another
77  /// nested-name-specifier component of the form 'type::'.
78  ///
79  /// \param Context The AST context in which this nested-name-specifier
80  /// resides.
81  ///
82  /// \param TemplateKWLoc The location of the 'template' keyword, if present.
83  ///
84  /// \param TL The TypeLoc that describes the type preceding the '::'.
85  ///
86  /// \param ColonColonLoc The location of the trailing '::'.
87  void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
88              SourceLocation ColonColonLoc);
89
90  /// \brief Extend the current nested-name-specifier by another
91  /// nested-name-specifier component of the form 'identifier::'.
92  ///
93  /// \param Context The AST context in which this nested-name-specifier
94  /// resides.
95  ///
96  /// \param Identifier The identifier.
97  ///
98  /// \param IdentifierLoc The location of the identifier.
99  ///
100  /// \param ColonColonLoc The location of the trailing '::'.
101  void Extend(ASTContext &Context, IdentifierInfo *Identifier,
102              SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
103
104  /// \brief Extend the current nested-name-specifier by another
105  /// nested-name-specifier component of the form 'namespace::'.
106  ///
107  /// \param Context The AST context in which this nested-name-specifier
108  /// resides.
109  ///
110  /// \param Namespace The namespace.
111  ///
112  /// \param NamespaceLoc The location of the namespace name.
113  ///
114  /// \param ColonColonLoc The location of the trailing '::'.
115  void Extend(ASTContext &Context, NamespaceDecl *Namespace,
116              SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
117
118  /// \brief Extend the current nested-name-specifier by another
119  /// nested-name-specifier component of the form 'namespace-alias::'.
120  ///
121  /// \param Context The AST context in which this nested-name-specifier
122  /// resides.
123  ///
124  /// \param Alias The namespace alias.
125  ///
126  /// \param AliasLoc The location of the namespace alias
127  /// name.
128  ///
129  /// \param ColonColonLoc The location of the trailing '::'.
130  void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
131              SourceLocation AliasLoc, SourceLocation ColonColonLoc);
132
133  /// \brief Turn this (empty) nested-name-specifier into the global
134  /// nested-name-specifier '::'.
135  void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
136
137  /// \brief Make a new nested-name-specifier from incomplete source-location
138  /// information.
139  ///
140  /// FIXME: This routine should be used very, very rarely, in cases where we
141  /// need to synthesize a nested-name-specifier. Most code should instead use
142  /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
143  void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
144                   SourceRange R);
145
146  /// \brief Adopt an existing nested-name-specifier (with source-range
147  /// information).
148  void Adopt(NestedNameSpecifierLoc Other);
149
150  /// \brief Retrieve a nested-name-specifier with location information, copied
151  /// into the given AST context.
152  ///
153  /// \param Context The context into which this nested-name-specifier will be
154  /// copied.
155  NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
156
157  /// No scope specifier.
158  bool isEmpty() const { return !Range.isValid(); }
159  /// A scope specifier is present, but may be valid or invalid.
160  bool isNotEmpty() const { return !isEmpty(); }
161
162  /// An error occurred during parsing of the scope specifier.
163  bool isInvalid() const { return isNotEmpty() && getScopeRep() == 0; }
164  /// A scope specifier is present, and it refers to a real scope.
165  bool isValid() const { return isNotEmpty() && getScopeRep() != 0; }
166
167  /// \brief Indicate that this nested-name-specifier is invalid.
168  void SetInvalid(SourceRange R) {
169    assert(R.isValid() && "Must have a valid source range");
170    if (Range.getBegin().isInvalid())
171      Range.setBegin(R.getBegin());
172    Range.setEnd(R.getEnd());
173    Builder.Clear();
174  }
175
176  /// Deprecated.  Some call sites intend isNotEmpty() while others intend
177  /// isValid().
178  bool isSet() const { return getScopeRep() != 0; }
179
180  void clear() {
181    Range = SourceRange();
182    Builder.Clear();
183  }
184
185  /// \brief Retrieve the data associated with the source-location information.
186  char *location_data() const { return Builder.getBuffer().first; }
187
188  /// \brief Retrieve the size of the data associated with source-location
189  /// information.
190  unsigned location_size() const { return Builder.getBuffer().second; }
191};
192
193/// DeclSpec - This class captures information about "declaration specifiers",
194/// which encompasses storage-class-specifiers, type-specifiers,
195/// type-qualifiers, and function-specifiers.
196class DeclSpec {
197public:
198  // storage-class-specifier
199  // Note: The order of these enumerators is important for diagnostics.
200  enum SCS {
201    SCS_unspecified = 0,
202    SCS_typedef,
203    SCS_extern,
204    SCS_static,
205    SCS_auto,
206    SCS_register,
207    SCS_private_extern,
208    SCS_mutable
209  };
210
211  // Import type specifier width enumeration and constants.
212  typedef TypeSpecifierWidth TSW;
213  static const TSW TSW_unspecified = clang::TSW_unspecified;
214  static const TSW TSW_short = clang::TSW_short;
215  static const TSW TSW_long = clang::TSW_long;
216  static const TSW TSW_longlong = clang::TSW_longlong;
217
218  enum TSC {
219    TSC_unspecified,
220    TSC_imaginary,
221    TSC_complex
222  };
223
224  // Import type specifier sign enumeration and constants.
225  typedef TypeSpecifierSign TSS;
226  static const TSS TSS_unspecified = clang::TSS_unspecified;
227  static const TSS TSS_signed = clang::TSS_signed;
228  static const TSS TSS_unsigned = clang::TSS_unsigned;
229
230  // Import type specifier type enumeration and constants.
231  typedef TypeSpecifierType TST;
232  static const TST TST_unspecified = clang::TST_unspecified;
233  static const TST TST_void = clang::TST_void;
234  static const TST TST_char = clang::TST_char;
235  static const TST TST_wchar = clang::TST_wchar;
236  static const TST TST_char16 = clang::TST_char16;
237  static const TST TST_char32 = clang::TST_char32;
238  static const TST TST_int = clang::TST_int;
239  static const TST TST_float = clang::TST_float;
240  static const TST TST_double = clang::TST_double;
241  static const TST TST_bool = clang::TST_bool;
242  static const TST TST_decimal32 = clang::TST_decimal32;
243  static const TST TST_decimal64 = clang::TST_decimal64;
244  static const TST TST_decimal128 = clang::TST_decimal128;
245  static const TST TST_enum = clang::TST_enum;
246  static const TST TST_union = clang::TST_union;
247  static const TST TST_struct = clang::TST_struct;
248  static const TST TST_class = clang::TST_class;
249  static const TST TST_typename = clang::TST_typename;
250  static const TST TST_typeofType = clang::TST_typeofType;
251  static const TST TST_typeofExpr = clang::TST_typeofExpr;
252  static const TST TST_decltype = clang::TST_decltype;
253  static const TST TST_underlyingType = clang::TST_underlyingType;
254  static const TST TST_auto = clang::TST_auto;
255  static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
256  static const TST TST_error = clang::TST_error;
257
258  // type-qualifiers
259  enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
260    TQ_unspecified = 0,
261    TQ_const       = 1,
262    TQ_restrict    = 2,
263    TQ_volatile    = 4
264  };
265
266  /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
267  /// returned by getParsedSpecifiers.
268  enum ParsedSpecifiers {
269    PQ_None                  = 0,
270    PQ_StorageClassSpecifier = 1,
271    PQ_TypeSpecifier         = 2,
272    PQ_TypeQualifier         = 4,
273    PQ_FunctionSpecifier     = 8
274  };
275
276private:
277  // storage-class-specifier
278  /*SCS*/unsigned StorageClassSpec : 3;
279  unsigned SCS_thread_specified : 1;
280  unsigned SCS_extern_in_linkage_spec : 1;
281
282  // type-specifier
283  /*TSW*/unsigned TypeSpecWidth : 2;
284  /*TSC*/unsigned TypeSpecComplex : 2;
285  /*TSS*/unsigned TypeSpecSign : 2;
286  /*TST*/unsigned TypeSpecType : 5;
287  unsigned TypeAltiVecVector : 1;
288  unsigned TypeAltiVecPixel : 1;
289  unsigned TypeAltiVecBool : 1;
290  unsigned TypeSpecOwned : 1;
291
292  // type-qualifiers
293  unsigned TypeQualifiers : 3;  // Bitwise OR of TQ.
294
295  // function-specifier
296  unsigned FS_inline_specified : 1;
297  unsigned FS_virtual_specified : 1;
298  unsigned FS_explicit_specified : 1;
299
300  // friend-specifier
301  unsigned Friend_specified : 1;
302
303  // constexpr-specifier
304  unsigned Constexpr_specified : 1;
305
306  /*SCS*/unsigned StorageClassSpecAsWritten : 3;
307
308  union {
309    UnionParsedType TypeRep;
310    Decl *DeclRep;
311    Expr *ExprRep;
312  };
313
314  // attributes.
315  ParsedAttributes Attrs;
316
317  // Scope specifier for the type spec, if applicable.
318  CXXScopeSpec TypeScope;
319
320  // List of protocol qualifiers for objective-c classes.  Used for
321  // protocol-qualified interfaces "NString<foo>" and protocol-qualified id
322  // "id<foo>".
323  Decl * const *ProtocolQualifiers;
324  unsigned NumProtocolQualifiers;
325  SourceLocation ProtocolLAngleLoc;
326  SourceLocation *ProtocolLocs;
327
328  // SourceLocation info.  These are null if the item wasn't specified or if
329  // the setting was synthesized.
330  SourceRange Range;
331
332  SourceLocation StorageClassSpecLoc, SCS_threadLoc;
333  SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
334  /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
335  /// typename, then this is the location of the named type (if present);
336  /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
337  /// TSTNameLoc provides source range info for tag types.
338  SourceLocation TSTNameLoc;
339  SourceRange TypeofParensRange;
340  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc;
341  SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc;
342  SourceLocation FriendLoc, ConstexprLoc;
343
344  WrittenBuiltinSpecs writtenBS;
345  void SaveWrittenBuiltinSpecs();
346  void SaveStorageSpecifierAsWritten();
347
348  ObjCDeclSpec *ObjCQualifiers;
349
350  static bool isTypeRep(TST T) {
351    return (T == TST_typename || T == TST_typeofType ||
352            T == TST_underlyingType);
353  }
354  static bool isExprRep(TST T) {
355    return (T == TST_typeofExpr || T == TST_decltype);
356  }
357  static bool isDeclRep(TST T) {
358    return (T == TST_enum || T == TST_struct ||
359            T == TST_union || T == TST_class);
360  }
361
362  DeclSpec(const DeclSpec&);       // DO NOT IMPLEMENT
363  void operator=(const DeclSpec&); // DO NOT IMPLEMENT
364public:
365
366  DeclSpec(AttributeFactory &attrFactory)
367    : StorageClassSpec(SCS_unspecified),
368      SCS_thread_specified(false),
369      SCS_extern_in_linkage_spec(false),
370      TypeSpecWidth(TSW_unspecified),
371      TypeSpecComplex(TSC_unspecified),
372      TypeSpecSign(TSS_unspecified),
373      TypeSpecType(TST_unspecified),
374      TypeAltiVecVector(false),
375      TypeAltiVecPixel(false),
376      TypeAltiVecBool(false),
377      TypeSpecOwned(false),
378      TypeQualifiers(TSS_unspecified),
379      FS_inline_specified(false),
380      FS_virtual_specified(false),
381      FS_explicit_specified(false),
382      Friend_specified(false),
383      Constexpr_specified(false),
384      StorageClassSpecAsWritten(SCS_unspecified),
385      Attrs(attrFactory),
386      ProtocolQualifiers(0),
387      NumProtocolQualifiers(0),
388      ProtocolLocs(0),
389      writtenBS(),
390      ObjCQualifiers(0) {
391  }
392  ~DeclSpec() {
393    delete [] ProtocolQualifiers;
394    delete [] ProtocolLocs;
395  }
396  // storage-class-specifier
397  SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
398  bool isThreadSpecified() const { return SCS_thread_specified; }
399  bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
400  void setExternInLinkageSpec(bool Value) {
401    SCS_extern_in_linkage_spec = Value;
402  }
403
404  SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
405  SourceLocation getThreadSpecLoc() const { return SCS_threadLoc; }
406
407  void ClearStorageClassSpecs() {
408    StorageClassSpec     = DeclSpec::SCS_unspecified;
409    SCS_thread_specified = false;
410    SCS_extern_in_linkage_spec = false;
411    StorageClassSpecLoc  = SourceLocation();
412    SCS_threadLoc        = SourceLocation();
413  }
414
415  // type-specifier
416  TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
417  TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
418  TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
419  TST getTypeSpecType() const { return (TST)TypeSpecType; }
420  bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
421  bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
422  bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
423  bool isTypeSpecOwned() const { return TypeSpecOwned; }
424  ParsedType getRepAsType() const {
425    assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
426    return TypeRep;
427  }
428  Decl *getRepAsDecl() const {
429    assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
430    return DeclRep;
431  }
432  Expr *getRepAsExpr() const {
433    assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
434    return ExprRep;
435  }
436  CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
437  const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
438
439  const SourceRange &getSourceRange() const { return Range; }
440  SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; }
441  SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
442  SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
443  SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
444  SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
445
446  SourceLocation getTypeSpecTypeNameLoc() const {
447    assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
448    return TSTNameLoc;
449  }
450
451  SourceRange getTypeofParensRange() const { return TypeofParensRange; }
452  void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
453
454  /// getSpecifierName - Turn a type-specifier-type into a string like "_Bool"
455  /// or "union".
456  static const char *getSpecifierName(DeclSpec::TST T);
457  static const char *getSpecifierName(DeclSpec::TQ Q);
458  static const char *getSpecifierName(DeclSpec::TSS S);
459  static const char *getSpecifierName(DeclSpec::TSC C);
460  static const char *getSpecifierName(DeclSpec::TSW W);
461  static const char *getSpecifierName(DeclSpec::SCS S);
462
463  // type-qualifiers
464
465  /// getTypeQualifiers - Return a set of TQs.
466  unsigned getTypeQualifiers() const { return TypeQualifiers; }
467  SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
468  SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
469  SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
470
471  /// \brief Clear out all of the type qualifiers.
472  void ClearTypeQualifiers() {
473    TypeQualifiers = 0;
474    TQ_constLoc = SourceLocation();
475    TQ_restrictLoc = SourceLocation();
476    TQ_volatileLoc = SourceLocation();
477  }
478
479  // function-specifier
480  bool isInlineSpecified() const { return FS_inline_specified; }
481  SourceLocation getInlineSpecLoc() const { return FS_inlineLoc; }
482
483  bool isVirtualSpecified() const { return FS_virtual_specified; }
484  SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
485
486  bool isExplicitSpecified() const { return FS_explicit_specified; }
487  SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
488
489  void ClearFunctionSpecs() {
490    FS_inline_specified = false;
491    FS_inlineLoc = SourceLocation();
492    FS_virtual_specified = false;
493    FS_virtualLoc = SourceLocation();
494    FS_explicit_specified = false;
495    FS_explicitLoc = SourceLocation();
496  }
497
498  /// hasTypeSpecifier - Return true if any type-specifier has been found.
499  bool hasTypeSpecifier() const {
500    return getTypeSpecType() != DeclSpec::TST_unspecified ||
501           getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
502           getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
503           getTypeSpecSign() != DeclSpec::TSS_unspecified;
504  }
505
506  /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
507  /// DeclSpec includes.
508  ///
509  unsigned getParsedSpecifiers() const;
510
511  SCS getStorageClassSpecAsWritten() const {
512    return (SCS)StorageClassSpecAsWritten;
513  }
514
515  /// isEmpty - Return true if this declaration specifier is completely empty:
516  /// no tokens were parsed in the production of it.
517  bool isEmpty() const {
518    return getParsedSpecifiers() == DeclSpec::PQ_None;
519  }
520
521  void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
522  void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
523
524  /// These methods set the specified attribute of the DeclSpec and
525  /// return false if there was no error.  If an error occurs (for
526  /// example, if we tried to set "auto" on a spec with "extern"
527  /// already set), they return true and set PrevSpec and DiagID
528  /// such that
529  ///   Diag(Loc, DiagID) << PrevSpec;
530  /// will yield a useful result.
531  ///
532  /// TODO: use a more general approach that still allows these
533  /// diagnostics to be ignored when desired.
534  bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec,
535                           unsigned &DiagID, const LangOptions &Lang);
536  bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
537                                 unsigned &DiagID);
538  bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
539                        unsigned &DiagID);
540  bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
541                          unsigned &DiagID);
542  bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
543                       unsigned &DiagID);
544  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
545                       unsigned &DiagID);
546  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
547                       unsigned &DiagID, ParsedType Rep);
548  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
549                       unsigned &DiagID, Decl *Rep, bool Owned);
550  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
551                       SourceLocation TagNameLoc, const char *&PrevSpec,
552                       unsigned &DiagID, ParsedType Rep);
553  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
554                       SourceLocation TagNameLoc, const char *&PrevSpec,
555                       unsigned &DiagID, Decl *Rep, bool Owned);
556
557  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
558                       unsigned &DiagID, Expr *Rep);
559  bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
560                       const char *&PrevSpec, unsigned &DiagID);
561  bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
562                       const char *&PrevSpec, unsigned &DiagID);
563  bool SetTypeSpecError();
564  void UpdateDeclRep(Decl *Rep) {
565    assert(isDeclRep((TST) TypeSpecType));
566    DeclRep = Rep;
567  }
568  void UpdateTypeRep(ParsedType Rep) {
569    assert(isTypeRep((TST) TypeSpecType));
570    TypeRep = Rep;
571  }
572  void UpdateExprRep(Expr *Rep) {
573    assert(isExprRep((TST) TypeSpecType));
574    ExprRep = Rep;
575  }
576
577  bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
578                   unsigned &DiagID, const LangOptions &Lang);
579
580  bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
581                             unsigned &DiagID);
582  bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
583                              unsigned &DiagID);
584  bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
585                               unsigned &DiagID);
586
587  bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
588                     unsigned &DiagID);
589
590  bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
591                        unsigned &DiagID);
592
593  bool isFriendSpecified() const { return Friend_specified; }
594  SourceLocation getFriendSpecLoc() const { return FriendLoc; }
595
596  bool isConstexprSpecified() const { return Constexpr_specified; }
597  SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
598
599  AttributePool &getAttributePool() const {
600    return Attrs.getPool();
601  }
602
603  /// AddAttributes - contatenates two attribute lists.
604  /// The GCC attribute syntax allows for the following:
605  ///
606  /// short __attribute__(( unused, deprecated ))
607  /// int __attribute__(( may_alias, aligned(16) )) var;
608  ///
609  /// This declares 4 attributes using 2 lists. The following syntax is
610  /// also allowed and equivalent to the previous declaration.
611  ///
612  /// short __attribute__((unused)) __attribute__((deprecated))
613  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
614  ///
615  void addAttributes(AttributeList *AL) {
616    Attrs.addAll(AL);
617  }
618  void setAttributes(AttributeList *AL) {
619    Attrs.set(AL);
620  }
621
622  bool hasAttributes() const { return !Attrs.empty(); }
623
624  ParsedAttributes &getAttributes() { return Attrs; }
625  const ParsedAttributes &getAttributes() const { return Attrs; }
626
627  /// TakeAttributes - Return the current attribute list and remove them from
628  /// the DeclSpec so that it doesn't own them.
629  ParsedAttributes takeAttributes() {
630    // The non-const "copy" constructor clears the operand automatically.
631    return Attrs;
632  }
633
634  void takeAttributesFrom(ParsedAttributes &attrs) {
635    Attrs.takeAllFrom(attrs);
636  }
637
638  typedef Decl * const *ProtocolQualifierListTy;
639  ProtocolQualifierListTy getProtocolQualifiers() const {
640    return ProtocolQualifiers;
641  }
642  SourceLocation *getProtocolLocs() const { return ProtocolLocs; }
643  unsigned getNumProtocolQualifiers() const {
644    return NumProtocolQualifiers;
645  }
646  SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; }
647  void setProtocolQualifiers(Decl * const *Protos, unsigned NP,
648                             SourceLocation *ProtoLocs,
649                             SourceLocation LAngleLoc);
650
651  /// Finish - This does final analysis of the declspec, issuing diagnostics for
652  /// things like "_Imaginary" (lacking an FP type).  After calling this method,
653  /// DeclSpec is guaranteed self-consistent, even if an error occurred.
654  void Finish(Diagnostic &D, Preprocessor &PP);
655
656  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
657    return writtenBS;
658  }
659
660  ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
661  void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
662
663  /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone,
664  /// without a Declarator. Only tag declspecs can stand alone.
665  bool isMissingDeclaratorOk();
666};
667
668/// ObjCDeclSpec - This class captures information about
669/// "declaration specifiers" specific to objective-c
670class ObjCDeclSpec {
671public:
672  /// ObjCDeclQualifier - Qualifier used on types in method
673  /// declarations.  Not all combinations are sensible.  Parameters
674  /// can be one of { in, out, inout } with one of { bycopy, byref }.
675  /// Returns can either be { oneway } or not.
676  ///
677  /// This should be kept in sync with Decl::ObjCDeclQualifier.
678  enum ObjCDeclQualifier {
679    DQ_None = 0x0,
680    DQ_In = 0x1,
681    DQ_Inout = 0x2,
682    DQ_Out = 0x4,
683    DQ_Bycopy = 0x8,
684    DQ_Byref = 0x10,
685    DQ_Oneway = 0x20
686  };
687
688  /// PropertyAttributeKind - list of property attributes.
689  enum ObjCPropertyAttributeKind {
690    DQ_PR_noattr = 0x0,
691    DQ_PR_readonly = 0x01,
692    DQ_PR_getter = 0x02,
693    DQ_PR_assign = 0x04,
694    DQ_PR_readwrite = 0x08,
695    DQ_PR_retain = 0x10,
696    DQ_PR_copy = 0x20,
697    DQ_PR_nonatomic = 0x40,
698    DQ_PR_setter = 0x80,
699    DQ_PR_atomic = 0x100,
700    DQ_PR_weak =   0x200,
701    DQ_PR_strong = 0x400,
702    DQ_PR_unsafe_unretained = 0x800
703  };
704
705
706  ObjCDeclSpec()
707    : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr),
708      GetterName(0), SetterName(0) { }
709  ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; }
710  void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
711    objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
712  }
713
714  ObjCPropertyAttributeKind getPropertyAttributes() const {
715    return ObjCPropertyAttributeKind(PropertyAttributes);
716  }
717  void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) {
718    PropertyAttributes =
719      (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal);
720  }
721
722  const IdentifierInfo *getGetterName() const { return GetterName; }
723  IdentifierInfo *getGetterName() { return GetterName; }
724  void setGetterName(IdentifierInfo *name) { GetterName = name; }
725
726  const IdentifierInfo *getSetterName() const { return SetterName; }
727  IdentifierInfo *getSetterName() { return SetterName; }
728  void setSetterName(IdentifierInfo *name) { SetterName = name; }
729private:
730  // FIXME: These two are unrelated and mutially exclusive. So perhaps
731  // we can put them in a union to reflect their mutual exclusiveness
732  // (space saving is negligible).
733  ObjCDeclQualifier objcDeclQualifier : 6;
734
735  // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind
736  unsigned PropertyAttributes : 12;
737  IdentifierInfo *GetterName;    // getter name of NULL if no getter
738  IdentifierInfo *SetterName;    // setter name of NULL if no setter
739};
740
741/// \brief Represents a C++ unqualified-id that has been parsed.
742class UnqualifiedId {
743private:
744  const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT
745
746public:
747  /// \brief Describes the kind of unqualified-id parsed.
748  enum IdKind {
749    /// \brief An identifier.
750    IK_Identifier,
751    /// \brief An overloaded operator name, e.g., operator+.
752    IK_OperatorFunctionId,
753    /// \brief A conversion function name, e.g., operator int.
754    IK_ConversionFunctionId,
755    /// \brief A user-defined literal name, e.g., operator "" _i.
756    IK_LiteralOperatorId,
757    /// \brief A constructor name.
758    IK_ConstructorName,
759    /// \brief A constructor named via a template-id.
760    IK_ConstructorTemplateId,
761    /// \brief A destructor name.
762    IK_DestructorName,
763    /// \brief A template-id, e.g., f<int>.
764    IK_TemplateId
765  } Kind;
766
767  /// \brief Anonymous union that holds extra data associated with the
768  /// parsed unqualified-id.
769  union {
770    /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind
771    /// == IK_UserLiteralId, the identifier suffix.
772    IdentifierInfo *Identifier;
773
774    /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator
775    /// that we parsed.
776    struct {
777      /// \brief The kind of overloaded operator.
778      OverloadedOperatorKind Operator;
779
780      /// \brief The source locations of the individual tokens that name
781      /// the operator, e.g., the "new", "[", and "]" tokens in
782      /// operator new [].
783      ///
784      /// Different operators have different numbers of tokens in their name,
785      /// up to three. Any remaining source locations in this array will be
786      /// set to an invalid value for operators with fewer than three tokens.
787      unsigned SymbolLocations[3];
788    } OperatorFunctionId;
789
790    /// \brief When Kind == IK_ConversionFunctionId, the type that the
791    /// conversion function names.
792    UnionParsedType ConversionFunctionId;
793
794    /// \brief When Kind == IK_ConstructorName, the class-name of the type
795    /// whose constructor is being referenced.
796    UnionParsedType ConstructorName;
797
798    /// \brief When Kind == IK_DestructorName, the type referred to by the
799    /// class-name.
800    UnionParsedType DestructorName;
801
802    /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId,
803    /// the template-id annotation that contains the template name and
804    /// template arguments.
805    TemplateIdAnnotation *TemplateId;
806  };
807
808  /// \brief The location of the first token that describes this unqualified-id,
809  /// which will be the location of the identifier, "operator" keyword,
810  /// tilde (for a destructor), or the template name of a template-id.
811  SourceLocation StartLocation;
812
813  /// \brief The location of the last token that describes this unqualified-id.
814  SourceLocation EndLocation;
815
816  UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { }
817
818  /// \brief Do not use this copy constructor. It is temporary, and only
819  /// exists because we are holding FieldDeclarators in a SmallVector when we
820  /// don't actually need them.
821  ///
822  /// FIXME: Kill this copy constructor.
823  UnqualifiedId(const UnqualifiedId &Other)
824    : Kind(IK_Identifier), Identifier(Other.Identifier),
825      StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) {
826    assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers");
827  }
828
829  /// \brief Destroy this unqualified-id.
830  ~UnqualifiedId() { clear(); }
831
832  /// \brief Clear out this unqualified-id, setting it to default (invalid)
833  /// state.
834  void clear();
835
836  /// \brief Determine whether this unqualified-id refers to a valid name.
837  bool isValid() const { return StartLocation.isValid(); }
838
839  /// \brief Determine whether this unqualified-id refers to an invalid name.
840  bool isInvalid() const { return !isValid(); }
841
842  /// \brief Determine what kind of name we have.
843  IdKind getKind() const { return Kind; }
844
845  /// \brief Specify that this unqualified-id was parsed as an identifier.
846  ///
847  /// \param Id the parsed identifier.
848  /// \param IdLoc the location of the parsed identifier.
849  void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
850    Kind = IK_Identifier;
851    Identifier = const_cast<IdentifierInfo *>(Id);
852    StartLocation = EndLocation = IdLoc;
853  }
854
855  /// \brief Specify that this unqualified-id was parsed as an
856  /// operator-function-id.
857  ///
858  /// \param OperatorLoc the location of the 'operator' keyword.
859  ///
860  /// \param Op the overloaded operator.
861  ///
862  /// \param SymbolLocations the locations of the individual operator symbols
863  /// in the operator.
864  void setOperatorFunctionId(SourceLocation OperatorLoc,
865                             OverloadedOperatorKind Op,
866                             SourceLocation SymbolLocations[3]);
867
868  /// \brief Specify that this unqualified-id was parsed as a
869  /// conversion-function-id.
870  ///
871  /// \param OperatorLoc the location of the 'operator' keyword.
872  ///
873  /// \param Ty the type to which this conversion function is converting.
874  ///
875  /// \param EndLoc the location of the last token that makes up the type name.
876  void setConversionFunctionId(SourceLocation OperatorLoc,
877                               ParsedType Ty,
878                               SourceLocation EndLoc) {
879    Kind = IK_ConversionFunctionId;
880    StartLocation = OperatorLoc;
881    EndLocation = EndLoc;
882    ConversionFunctionId = Ty;
883  }
884
885  /// \brief Specific that this unqualified-id was parsed as a
886  /// literal-operator-id.
887  ///
888  /// \param Id the parsed identifier.
889  ///
890  /// \param OpLoc the location of the 'operator' keyword.
891  ///
892  /// \param IdLoc the location of the identifier.
893  void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
894                              SourceLocation IdLoc) {
895    Kind = IK_LiteralOperatorId;
896    Identifier = const_cast<IdentifierInfo *>(Id);
897    StartLocation = OpLoc;
898    EndLocation = IdLoc;
899  }
900
901  /// \brief Specify that this unqualified-id was parsed as a constructor name.
902  ///
903  /// \param ClassType the class type referred to by the constructor name.
904  ///
905  /// \param ClassNameLoc the location of the class name.
906  ///
907  /// \param EndLoc the location of the last token that makes up the type name.
908  void setConstructorName(ParsedType ClassType,
909                          SourceLocation ClassNameLoc,
910                          SourceLocation EndLoc) {
911    Kind = IK_ConstructorName;
912    StartLocation = ClassNameLoc;
913    EndLocation = EndLoc;
914    ConstructorName = ClassType;
915  }
916
917  /// \brief Specify that this unqualified-id was parsed as a
918  /// template-id that names a constructor.
919  ///
920  /// \param TemplateId the template-id annotation that describes the parsed
921  /// template-id. This UnqualifiedId instance will take ownership of the
922  /// \p TemplateId and will free it on destruction.
923  void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
924
925  /// \brief Specify that this unqualified-id was parsed as a destructor name.
926  ///
927  /// \param TildeLoc the location of the '~' that introduces the destructor
928  /// name.
929  ///
930  /// \param ClassType the name of the class referred to by the destructor name.
931  void setDestructorName(SourceLocation TildeLoc,
932                         ParsedType ClassType,
933                         SourceLocation EndLoc) {
934    Kind = IK_DestructorName;
935    StartLocation = TildeLoc;
936    EndLocation = EndLoc;
937    DestructorName = ClassType;
938  }
939
940  /// \brief Specify that this unqualified-id was parsed as a template-id.
941  ///
942  /// \param TemplateId the template-id annotation that describes the parsed
943  /// template-id. This UnqualifiedId instance will take ownership of the
944  /// \p TemplateId and will free it on destruction.
945  void setTemplateId(TemplateIdAnnotation *TemplateId);
946
947  /// \brief Return the source range that covers this unqualified-id.
948  SourceRange getSourceRange() const {
949    return SourceRange(StartLocation, EndLocation);
950  }
951};
952
953/// CachedTokens - A set of tokens that has been cached for later
954/// parsing.
955typedef llvm::SmallVector<Token, 4> CachedTokens;
956
957/// DeclaratorChunk - One instance of this struct is used for each type in a
958/// declarator that is parsed.
959///
960/// This is intended to be a small value object.
961struct DeclaratorChunk {
962  enum {
963    Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren
964  } Kind;
965
966  /// Loc - The place where this type was defined.
967  SourceLocation Loc;
968  /// EndLoc - If valid, the place where this chunck ends.
969  SourceLocation EndLoc;
970
971  struct TypeInfoCommon {
972    AttributeList *AttrList;
973  };
974
975  struct PointerTypeInfo : TypeInfoCommon {
976    /// The type qualifiers: const/volatile/restrict.
977    unsigned TypeQuals : 3;
978
979    /// The location of the const-qualifier, if any.
980    unsigned ConstQualLoc;
981
982    /// The location of the volatile-qualifier, if any.
983    unsigned VolatileQualLoc;
984
985    /// The location of the restrict-qualifier, if any.
986    unsigned RestrictQualLoc;
987
988    void destroy() {
989    }
990  };
991
992  struct ReferenceTypeInfo : TypeInfoCommon {
993    /// The type qualifier: restrict. [GNU] C++ extension
994    bool HasRestrict : 1;
995    /// True if this is an lvalue reference, false if it's an rvalue reference.
996    bool LValueRef : 1;
997    void destroy() {
998    }
999  };
1000
1001  struct ArrayTypeInfo : TypeInfoCommon {
1002    /// The type qualifiers for the array: const/volatile/restrict.
1003    unsigned TypeQuals : 3;
1004
1005    /// True if this dimension included the 'static' keyword.
1006    bool hasStatic : 1;
1007
1008    /// True if this dimension was [*].  In this case, NumElts is null.
1009    bool isStar : 1;
1010
1011    /// This is the size of the array, or null if [] or [*] was specified.
1012    /// Since the parser is multi-purpose, and we don't want to impose a root
1013    /// expression class on all clients, NumElts is untyped.
1014    Expr *NumElts;
1015
1016    void destroy() {}
1017  };
1018
1019  /// ParamInfo - An array of paraminfo objects is allocated whenever a function
1020  /// declarator is parsed.  There are two interesting styles of arguments here:
1021  /// K&R-style identifier lists and parameter type lists.  K&R-style identifier
1022  /// lists will have information about the identifier, but no type information.
1023  /// Parameter type lists will have type info (if the actions module provides
1024  /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
1025  struct ParamInfo {
1026    IdentifierInfo *Ident;
1027    SourceLocation IdentLoc;
1028    Decl *Param;
1029
1030    /// DefaultArgTokens - When the parameter's default argument
1031    /// cannot be parsed immediately (because it occurs within the
1032    /// declaration of a member function), it will be stored here as a
1033    /// sequence of tokens to be parsed once the class definition is
1034    /// complete. Non-NULL indicates that there is a default argument.
1035    CachedTokens *DefaultArgTokens;
1036
1037    ParamInfo() {}
1038    ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
1039              Decl *param,
1040              CachedTokens *DefArgTokens = 0)
1041      : Ident(ident), IdentLoc(iloc), Param(param),
1042        DefaultArgTokens(DefArgTokens) {}
1043  };
1044
1045  struct TypeAndRange {
1046    ParsedType Ty;
1047    SourceRange Range;
1048  };
1049
1050  struct FunctionTypeInfo : TypeInfoCommon {
1051    /// hasPrototype - This is true if the function had at least one typed
1052    /// argument.  If the function is () or (a,b,c), then it has no prototype,
1053    /// and is treated as a K&R-style function.
1054    unsigned hasPrototype : 1;
1055
1056    /// isVariadic - If this function has a prototype, and if that
1057    /// proto ends with ',...)', this is true. When true, EllipsisLoc
1058    /// contains the location of the ellipsis.
1059    unsigned isVariadic : 1;
1060
1061    /// \brief Whether the ref-qualifier (if any) is an lvalue reference.
1062    /// Otherwise, it's an rvalue reference.
1063    unsigned RefQualifierIsLValueRef : 1;
1064
1065    /// The type qualifiers: const/volatile/restrict.
1066    /// The qualifier bitmask values are the same as in QualType.
1067    unsigned TypeQuals : 3;
1068
1069    /// ExceptionSpecType - An ExceptionSpecificationType value.
1070    unsigned ExceptionSpecType : 3;
1071
1072    /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo.
1073    unsigned DeleteArgInfo : 1;
1074
1075    /// When isVariadic is true, the location of the ellipsis in the source.
1076    unsigned EllipsisLoc;
1077
1078    /// NumArgs - This is the number of formal arguments provided for the
1079    /// declarator.
1080    unsigned NumArgs;
1081
1082    /// NumExceptions - This is the number of types in the dynamic-exception-
1083    /// decl, if the function has one.
1084    unsigned NumExceptions;
1085
1086    /// \brief The location of the ref-qualifier, if any.
1087    ///
1088    /// If this is an invalid location, there is no ref-qualifier.
1089    unsigned RefQualifierLoc;
1090
1091    /// \brief When ExceptionSpecType isn't EST_None or EST_Delayed, the
1092    /// location of the keyword introducing the spec.
1093    unsigned ExceptionSpecLoc;
1094
1095    /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
1096    /// describe the arguments for this function declarator.  This is null if
1097    /// there are no arguments specified.
1098    ParamInfo *ArgInfo;
1099
1100    union {
1101      /// \brief Pointer to a new[]'d array of TypeAndRange objects that
1102      /// contain the types in the function's dynamic exception specification
1103      /// and their locations, if there is one.
1104      TypeAndRange *Exceptions;
1105
1106      /// \brief Pointer to the expression in the noexcept-specifier of this
1107      /// function, if it has one.
1108      Expr *NoexceptExpr;
1109    };
1110
1111    /// TrailingReturnType - If this isn't null, it's the trailing return type
1112    /// specified. This is actually a ParsedType, but stored as void* to
1113    /// allow union storage.
1114    void *TrailingReturnType;
1115
1116    /// freeArgs - reset the argument list to having zero arguments.  This is
1117    /// used in various places for error recovery.
1118    void freeArgs() {
1119      if (DeleteArgInfo) {
1120        delete[] ArgInfo;
1121        DeleteArgInfo = false;
1122      }
1123      NumArgs = 0;
1124    }
1125
1126    void destroy() {
1127      if (DeleteArgInfo)
1128        delete[] ArgInfo;
1129      if (getExceptionSpecType() == EST_Dynamic)
1130        delete[] Exceptions;
1131    }
1132
1133    /// isKNRPrototype - Return true if this is a K&R style identifier list,
1134    /// like "void foo(a,b,c)".  In a function definition, this will be followed
1135    /// by the argument type definitions.
1136    bool isKNRPrototype() const {
1137      return !hasPrototype && NumArgs != 0;
1138    }
1139
1140    SourceLocation getEllipsisLoc() const {
1141      return SourceLocation::getFromRawEncoding(EllipsisLoc);
1142    }
1143    SourceLocation getExceptionSpecLoc() const {
1144      return SourceLocation::getFromRawEncoding(ExceptionSpecLoc);
1145    }
1146
1147    /// \brief Retrieve the location of the ref-qualifier, if any.
1148    SourceLocation getRefQualifierLoc() const {
1149      return SourceLocation::getFromRawEncoding(RefQualifierLoc);
1150    }
1151
1152    /// \brief Determine whether this function declaration contains a
1153    /// ref-qualifier.
1154    bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
1155
1156    /// \brief Get the type of exception specification this function has.
1157    ExceptionSpecificationType getExceptionSpecType() const {
1158      return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
1159    }
1160  };
1161
1162  struct BlockPointerTypeInfo : TypeInfoCommon {
1163    /// For now, sema will catch these as invalid.
1164    /// The type qualifiers: const/volatile/restrict.
1165    unsigned TypeQuals : 3;
1166
1167    void destroy() {
1168    }
1169  };
1170
1171  struct MemberPointerTypeInfo : TypeInfoCommon {
1172    /// The type qualifiers: const/volatile/restrict.
1173    unsigned TypeQuals : 3;
1174    // CXXScopeSpec has a constructor, so it can't be a direct member.
1175    // So we need some pointer-aligned storage and a bit of trickery.
1176    union {
1177      void *Aligner;
1178      char Mem[sizeof(CXXScopeSpec)];
1179    } ScopeMem;
1180    CXXScopeSpec &Scope() {
1181      return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem);
1182    }
1183    const CXXScopeSpec &Scope() const {
1184      return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem);
1185    }
1186    void destroy() {
1187      Scope().~CXXScopeSpec();
1188    }
1189  };
1190
1191  union {
1192    TypeInfoCommon        Common;
1193    PointerTypeInfo       Ptr;
1194    ReferenceTypeInfo     Ref;
1195    ArrayTypeInfo         Arr;
1196    FunctionTypeInfo      Fun;
1197    BlockPointerTypeInfo  Cls;
1198    MemberPointerTypeInfo Mem;
1199  };
1200
1201  void destroy() {
1202    switch (Kind) {
1203    default: assert(0 && "Unknown decl type!");
1204    case DeclaratorChunk::Function:      return Fun.destroy();
1205    case DeclaratorChunk::Pointer:       return Ptr.destroy();
1206    case DeclaratorChunk::BlockPointer:  return Cls.destroy();
1207    case DeclaratorChunk::Reference:     return Ref.destroy();
1208    case DeclaratorChunk::Array:         return Arr.destroy();
1209    case DeclaratorChunk::MemberPointer: return Mem.destroy();
1210    case DeclaratorChunk::Paren:         return;
1211    }
1212  }
1213
1214  /// getAttrs - If there are attributes applied to this declaratorchunk, return
1215  /// them.
1216  const AttributeList *getAttrs() const {
1217    return Common.AttrList;
1218  }
1219
1220  AttributeList *&getAttrListRef() {
1221    return Common.AttrList;
1222  }
1223
1224  /// getPointer - Return a DeclaratorChunk for a pointer.
1225  ///
1226  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1227                                    SourceLocation ConstQualLoc,
1228                                    SourceLocation VolatileQualLoc,
1229                                    SourceLocation RestrictQualLoc) {
1230    DeclaratorChunk I;
1231    I.Kind                = Pointer;
1232    I.Loc                 = Loc;
1233    I.Ptr.TypeQuals       = TypeQuals;
1234    I.Ptr.ConstQualLoc    = ConstQualLoc.getRawEncoding();
1235    I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
1236    I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
1237    I.Ptr.AttrList        = 0;
1238    return I;
1239  }
1240
1241  /// getReference - Return a DeclaratorChunk for a reference.
1242  ///
1243  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
1244                                      bool lvalue) {
1245    DeclaratorChunk I;
1246    I.Kind            = Reference;
1247    I.Loc             = Loc;
1248    I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
1249    I.Ref.LValueRef   = lvalue;
1250    I.Ref.AttrList    = 0;
1251    return I;
1252  }
1253
1254  /// getArray - Return a DeclaratorChunk for an array.
1255  ///
1256  static DeclaratorChunk getArray(unsigned TypeQuals,
1257                                  bool isStatic, bool isStar, Expr *NumElts,
1258                                  SourceLocation LBLoc, SourceLocation RBLoc) {
1259    DeclaratorChunk I;
1260    I.Kind          = Array;
1261    I.Loc           = LBLoc;
1262    I.EndLoc        = RBLoc;
1263    I.Arr.AttrList  = 0;
1264    I.Arr.TypeQuals = TypeQuals;
1265    I.Arr.hasStatic = isStatic;
1266    I.Arr.isStar    = isStar;
1267    I.Arr.NumElts   = NumElts;
1268    return I;
1269  }
1270
1271  /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1272  /// "TheDeclarator" is the declarator that this will be added to.
1273  static DeclaratorChunk getFunction(bool hasProto, bool isVariadic,
1274                                     SourceLocation EllipsisLoc,
1275                                     ParamInfo *ArgInfo, unsigned NumArgs,
1276                                     unsigned TypeQuals,
1277                                     bool RefQualifierIsLvalueRef,
1278                                     SourceLocation RefQualifierLoc,
1279                                     ExceptionSpecificationType ESpecType,
1280                                     SourceLocation ESpecLoc,
1281                                     ParsedType *Exceptions,
1282                                     SourceRange *ExceptionRanges,
1283                                     unsigned NumExceptions,
1284                                     Expr *NoexceptExpr,
1285                                     SourceLocation LocalRangeBegin,
1286                                     SourceLocation LocalRangeEnd,
1287                                     Declarator &TheDeclarator,
1288                                     ParsedType TrailingReturnType =
1289                                                    ParsedType());
1290
1291  /// getBlockPointer - Return a DeclaratorChunk for a block.
1292  ///
1293  static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
1294                                         SourceLocation Loc) {
1295    DeclaratorChunk I;
1296    I.Kind          = BlockPointer;
1297    I.Loc           = Loc;
1298    I.Cls.TypeQuals = TypeQuals;
1299    I.Cls.AttrList  = 0;
1300    return I;
1301  }
1302
1303  static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
1304                                          unsigned TypeQuals,
1305                                          SourceLocation Loc) {
1306    DeclaratorChunk I;
1307    I.Kind          = MemberPointer;
1308    I.Loc           = Loc;
1309    I.Mem.TypeQuals = TypeQuals;
1310    I.Mem.AttrList  = 0;
1311    new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS);
1312    return I;
1313  }
1314
1315  /// getParen - Return a DeclaratorChunk for a paren.
1316  ///
1317  static DeclaratorChunk getParen(SourceLocation LParenLoc,
1318                                  SourceLocation RParenLoc) {
1319    DeclaratorChunk I;
1320    I.Kind          = Paren;
1321    I.Loc           = LParenLoc;
1322    I.EndLoc        = RParenLoc;
1323    I.Common.AttrList = 0;
1324    return I;
1325  }
1326
1327};
1328
1329/// Declarator - Information about one declarator, including the parsed type
1330/// information and the identifier.  When the declarator is fully formed, this
1331/// is turned into the appropriate Decl object.
1332///
1333/// Declarators come in two types: normal declarators and abstract declarators.
1334/// Abstract declarators are used when parsing types, and don't have an
1335/// identifier.  Normal declarators do have ID's.
1336///
1337/// Instances of this class should be a transient object that lives on the
1338/// stack, not objects that are allocated in large quantities on the heap.
1339class Declarator {
1340public:
1341  enum TheContext {
1342    FileContext,         // File scope declaration.
1343    PrototypeContext,    // Within a function prototype.
1344    ObjCPrototypeContext,// Within a method prototype.
1345    KNRTypeListContext,  // K&R type definition list for formals.
1346    TypeNameContext,     // Abstract declarator for types.
1347    MemberContext,       // Struct/Union field.
1348    BlockContext,        // Declaration within a block in a function.
1349    ForContext,          // Declaration within first part of a for loop.
1350    ConditionContext,    // Condition declaration in a C++ if/switch/while/for.
1351    TemplateParamContext,// Within a template parameter list.
1352    CXXCatchContext,     // C++ catch exception-declaration
1353    BlockLiteralContext,  // Block literal declarator.
1354    TemplateTypeArgContext, // Template type argument.
1355    AliasDeclContext,    // C++0x alias-declaration.
1356    AliasTemplateContext // C++0x alias-declaration template.
1357  };
1358
1359private:
1360  const DeclSpec &DS;
1361  CXXScopeSpec SS;
1362  UnqualifiedId Name;
1363  SourceRange Range;
1364
1365  /// Context - Where we are parsing this declarator.
1366  ///
1367  TheContext Context;
1368
1369  /// DeclTypeInfo - This holds each type that the declarator includes as it is
1370  /// parsed.  This is pushed from the identifier out, which means that element
1371  /// #0 will be the most closely bound to the identifier, and
1372  /// DeclTypeInfo.back() will be the least closely bound.
1373  llvm::SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
1374
1375  /// InvalidType - Set by Sema::GetTypeForDeclarator().
1376  bool InvalidType : 1;
1377
1378  /// GroupingParens - Set by Parser::ParseParenDeclarator().
1379  bool GroupingParens : 1;
1380
1381  /// Attrs - Attributes.
1382  ParsedAttributes Attrs;
1383
1384  /// AsmLabel - The asm label, if specified.
1385  Expr *AsmLabel;
1386
1387  /// InlineParams - This is a local array used for the first function decl
1388  /// chunk to avoid going to the heap for the common case when we have one
1389  /// function chunk in the declarator.
1390  DeclaratorChunk::ParamInfo InlineParams[16];
1391  bool InlineParamsUsed;
1392
1393  /// Extension - true if the declaration is preceded by __extension__.
1394  bool Extension : 1;
1395
1396  /// \brief If provided, the source location of the ellipsis used to describe
1397  /// this declarator as a parameter pack.
1398  SourceLocation EllipsisLoc;
1399
1400  friend struct DeclaratorChunk;
1401
1402public:
1403  Declarator(const DeclSpec &ds, TheContext C)
1404    : DS(ds), Range(ds.getSourceRange()), Context(C),
1405      InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
1406      GroupingParens(false), Attrs(ds.getAttributePool().getFactory()),
1407      AsmLabel(0), InlineParamsUsed(false), Extension(false) {
1408  }
1409
1410  ~Declarator() {
1411    clear();
1412  }
1413
1414  /// getDeclSpec - Return the declaration-specifier that this declarator was
1415  /// declared with.
1416  const DeclSpec &getDeclSpec() const { return DS; }
1417
1418  /// getMutableDeclSpec - Return a non-const version of the DeclSpec.  This
1419  /// should be used with extreme care: declspecs can often be shared between
1420  /// multiple declarators, so mutating the DeclSpec affects all of the
1421  /// Declarators.  This should only be done when the declspec is known to not
1422  /// be shared or when in error recovery etc.
1423  DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
1424
1425  AttributePool &getAttributePool() const {
1426    return Attrs.getPool();
1427  }
1428
1429  /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
1430  /// nested-name-specifier) that is part of the declarator-id.
1431  const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
1432  CXXScopeSpec &getCXXScopeSpec() { return SS; }
1433
1434  /// \brief Retrieve the name specified by this declarator.
1435  UnqualifiedId &getName() { return Name; }
1436
1437  TheContext getContext() const { return Context; }
1438
1439  bool isPrototypeContext() const {
1440    return (Context == PrototypeContext || Context == ObjCPrototypeContext);
1441  }
1442
1443  /// getSourceRange - Get the source range that spans this declarator.
1444  const SourceRange &getSourceRange() const { return Range; }
1445
1446  void SetSourceRange(SourceRange R) { Range = R; }
1447  /// SetRangeBegin - Set the start of the source range to Loc, unless it's
1448  /// invalid.
1449  void SetRangeBegin(SourceLocation Loc) {
1450    if (!Loc.isInvalid())
1451      Range.setBegin(Loc);
1452  }
1453  /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
1454  void SetRangeEnd(SourceLocation Loc) {
1455    if (!Loc.isInvalid())
1456      Range.setEnd(Loc);
1457  }
1458  /// ExtendWithDeclSpec - Extend the declarator source range to include the
1459  /// given declspec, unless its location is invalid. Adopts the range start if
1460  /// the current range start is invalid.
1461  void ExtendWithDeclSpec(const DeclSpec &DS) {
1462    const SourceRange &SR = DS.getSourceRange();
1463    if (Range.getBegin().isInvalid())
1464      Range.setBegin(SR.getBegin());
1465    if (!SR.getEnd().isInvalid())
1466      Range.setEnd(SR.getEnd());
1467  }
1468
1469  /// clear - Reset the contents of this Declarator.
1470  void clear() {
1471    SS.clear();
1472    Name.clear();
1473    Range = DS.getSourceRange();
1474
1475    for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
1476      DeclTypeInfo[i].destroy();
1477    DeclTypeInfo.clear();
1478    Attrs.clear();
1479    AsmLabel = 0;
1480    InlineParamsUsed = false;
1481  }
1482
1483  /// mayOmitIdentifier - Return true if the identifier is either optional or
1484  /// not allowed.  This is true for typenames, prototypes, and template
1485  /// parameter lists.
1486  bool mayOmitIdentifier() const {
1487    switch (Context) {
1488    case FileContext:
1489    case KNRTypeListContext:
1490    case MemberContext:
1491    case BlockContext:
1492    case ForContext:
1493    case ConditionContext:
1494      return false;
1495
1496    case TypeNameContext:
1497    case AliasDeclContext:
1498    case AliasTemplateContext:
1499    case PrototypeContext:
1500    case ObjCPrototypeContext:
1501    case TemplateParamContext:
1502    case CXXCatchContext:
1503    case BlockLiteralContext:
1504    case TemplateTypeArgContext:
1505      return true;
1506    }
1507    llvm_unreachable("unknown context kind!");
1508  }
1509
1510  /// mayHaveIdentifier - Return true if the identifier is either optional or
1511  /// required.  This is true for normal declarators and prototypes, but not
1512  /// typenames.
1513  bool mayHaveIdentifier() const {
1514    switch (Context) {
1515    case FileContext:
1516    case KNRTypeListContext:
1517    case MemberContext:
1518    case BlockContext:
1519    case ForContext:
1520    case ConditionContext:
1521    case PrototypeContext:
1522    case TemplateParamContext:
1523    case CXXCatchContext:
1524      return true;
1525
1526    case TypeNameContext:
1527    case AliasDeclContext:
1528    case AliasTemplateContext:
1529    case ObjCPrototypeContext:
1530    case BlockLiteralContext:
1531    case TemplateTypeArgContext:
1532      return false;
1533    }
1534    llvm_unreachable("unknown context kind!");
1535  }
1536
1537  /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
1538  /// followed by a C++ direct initializer, e.g. "int x(1);".
1539  bool mayBeFollowedByCXXDirectInit() const {
1540    if (hasGroupingParens()) return false;
1541
1542    switch (Context) {
1543    case FileContext:
1544    case BlockContext:
1545    case ForContext:
1546      return true;
1547
1548    case KNRTypeListContext:
1549    case MemberContext:
1550    case ConditionContext:
1551    case PrototypeContext:
1552    case ObjCPrototypeContext:
1553    case TemplateParamContext:
1554    case CXXCatchContext:
1555    case TypeNameContext:
1556    case AliasDeclContext:
1557    case AliasTemplateContext:
1558    case BlockLiteralContext:
1559    case TemplateTypeArgContext:
1560      return false;
1561    }
1562    llvm_unreachable("unknown context kind!");
1563  }
1564
1565  /// isPastIdentifier - Return true if we have parsed beyond the point where
1566  /// the
1567  bool isPastIdentifier() const { return Name.isValid(); }
1568
1569  /// hasName - Whether this declarator has a name, which might be an
1570  /// identifier (accessible via getIdentifier()) or some kind of
1571  /// special C++ name (constructor, destructor, etc.).
1572  bool hasName() const {
1573    return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier;
1574  }
1575
1576  IdentifierInfo *getIdentifier() const {
1577    if (Name.getKind() == UnqualifiedId::IK_Identifier)
1578      return Name.Identifier;
1579
1580    return 0;
1581  }
1582  SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
1583
1584  /// \brief Set the name of this declarator to be the given identifier.
1585  void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) {
1586    Name.setIdentifier(Id, IdLoc);
1587  }
1588
1589  /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
1590  /// EndLoc, which should be the last token of the chunk.
1591  void AddTypeInfo(const DeclaratorChunk &TI,
1592                   ParsedAttributes &attrs,
1593                   SourceLocation EndLoc) {
1594    DeclTypeInfo.push_back(TI);
1595    DeclTypeInfo.back().getAttrListRef() = attrs.getList();
1596    getAttributePool().takeAllFrom(attrs.getPool());
1597
1598    if (!EndLoc.isInvalid())
1599      SetRangeEnd(EndLoc);
1600  }
1601
1602  /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator.
1603  void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
1604    DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
1605  }
1606
1607  /// getNumTypeObjects() - Return the number of types applied to this
1608  /// declarator.
1609  unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
1610
1611  /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
1612  /// closest to the identifier.
1613  const DeclaratorChunk &getTypeObject(unsigned i) const {
1614    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
1615    return DeclTypeInfo[i];
1616  }
1617  DeclaratorChunk &getTypeObject(unsigned i) {
1618    assert(i < DeclTypeInfo.size() && "Invalid type chunk");
1619    return DeclTypeInfo[i];
1620  }
1621
1622  void DropFirstTypeObject()
1623  {
1624    assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
1625    DeclTypeInfo.front().destroy();
1626    DeclTypeInfo.erase(DeclTypeInfo.begin());
1627  }
1628
1629  /// isArrayOfUnknownBound - This method returns true if the declarator
1630  /// is a declarator for an array of unknown bound (looking through
1631  /// parentheses).
1632  bool isArrayOfUnknownBound() const {
1633    for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
1634      switch (DeclTypeInfo[i].Kind) {
1635      case DeclaratorChunk::Paren:
1636        continue;
1637      case DeclaratorChunk::Function:
1638      case DeclaratorChunk::Pointer:
1639      case DeclaratorChunk::Reference:
1640      case DeclaratorChunk::BlockPointer:
1641      case DeclaratorChunk::MemberPointer:
1642        return false;
1643      case DeclaratorChunk::Array:
1644        return !DeclTypeInfo[i].Arr.NumElts;
1645      }
1646      llvm_unreachable("Invalid type chunk");
1647      return false;
1648    }
1649    return false;
1650  }
1651
1652  /// isFunctionDeclarator - This method returns true if the declarator
1653  /// is a function declarator (looking through parentheses).
1654  /// If true is returned, then the reference type parameter idx is
1655  /// assigned with the index of the declaration chunk.
1656  bool isFunctionDeclarator(unsigned& idx) const {
1657    for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
1658      switch (DeclTypeInfo[i].Kind) {
1659      case DeclaratorChunk::Function:
1660        idx = i;
1661        return true;
1662      case DeclaratorChunk::Paren:
1663        continue;
1664      case DeclaratorChunk::Pointer:
1665      case DeclaratorChunk::Reference:
1666      case DeclaratorChunk::Array:
1667      case DeclaratorChunk::BlockPointer:
1668      case DeclaratorChunk::MemberPointer:
1669        return false;
1670      }
1671      llvm_unreachable("Invalid type chunk");
1672      return false;
1673    }
1674    return false;
1675  }
1676
1677  /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
1678  /// this method returns true if the identifier is a function declarator
1679  /// (looking through parentheses).
1680  bool isFunctionDeclarator() const {
1681    unsigned index;
1682    return isFunctionDeclarator(index);
1683  }
1684
1685  /// getFunctionTypeInfo - Retrieves the function type info object
1686  /// (looking through parentheses).
1687  DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
1688    assert(isFunctionDeclarator() && "Not a function declarator!");
1689    unsigned index = 0;
1690    isFunctionDeclarator(index);
1691    return DeclTypeInfo[index].Fun;
1692  }
1693
1694  /// getFunctionTypeInfo - Retrieves the function type info object
1695  /// (looking through parentheses).
1696  const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
1697    return const_cast<Declarator*>(this)->getFunctionTypeInfo();
1698  }
1699
1700  /// \brief Determine whether the declaration that will be produced from
1701  /// this declaration will be a function.
1702  ///
1703  /// A declaration can declare a function even if the declarator itself
1704  /// isn't a function declarator, if the type specifier refers to a function
1705  /// type. This routine checks for both cases.
1706  bool isDeclarationOfFunction() const;
1707
1708  /// takeAttributes - Takes attributes from the given parsed-attributes
1709  /// set and add them to this declarator.
1710  ///
1711  /// These examples both add 3 attributes to "var":
1712  ///  short int var __attribute__((aligned(16),common,deprecated));
1713  ///  short int x, __attribute__((aligned(16)) var
1714  ///                                 __attribute__((common,deprecated));
1715  ///
1716  /// Also extends the range of the declarator.
1717  void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) {
1718    Attrs.takeAllFrom(attrs);
1719
1720    if (!lastLoc.isInvalid())
1721      SetRangeEnd(lastLoc);
1722  }
1723
1724  const AttributeList *getAttributes() const { return Attrs.getList(); }
1725  AttributeList *getAttributes() { return Attrs.getList(); }
1726
1727  AttributeList *&getAttrListRef() { return Attrs.getListRef(); }
1728
1729  /// hasAttributes - do we contain any attributes?
1730  bool hasAttributes() const {
1731    if (getAttributes() || getDeclSpec().hasAttributes()) return true;
1732    for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
1733      if (getTypeObject(i).getAttrs())
1734        return true;
1735    return false;
1736  }
1737
1738  void setAsmLabel(Expr *E) { AsmLabel = E; }
1739  Expr *getAsmLabel() const { return AsmLabel; }
1740
1741  void setExtension(bool Val = true) { Extension = Val; }
1742  bool getExtension() const { return Extension; }
1743
1744  void setInvalidType(bool Val = true) { InvalidType = Val; }
1745  bool isInvalidType() const {
1746    return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
1747  }
1748
1749  void setGroupingParens(bool flag) { GroupingParens = flag; }
1750  bool hasGroupingParens() const { return GroupingParens; }
1751
1752  bool hasEllipsis() const { return EllipsisLoc.isValid(); }
1753  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
1754  void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
1755};
1756
1757/// FieldDeclarator - This little struct is used to capture information about
1758/// structure field declarators, which is basically just a bitfield size.
1759struct FieldDeclarator {
1760  Declarator D;
1761  Expr *BitfieldSize;
1762  explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) {
1763    BitfieldSize = 0;
1764  }
1765};
1766
1767/// VirtSpecifiers - Represents a C++0x virt-specifier-seq.
1768class VirtSpecifiers {
1769public:
1770  enum Specifier {
1771    VS_None = 0,
1772    VS_Override = 1,
1773    VS_Final = 2
1774  };
1775
1776  VirtSpecifiers() : Specifiers(0) { }
1777
1778  bool SetSpecifier(Specifier VS, SourceLocation Loc,
1779                    const char *&PrevSpec);
1780
1781  bool isOverrideSpecified() const { return Specifiers & VS_Override; }
1782  SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
1783
1784  bool isFinalSpecified() const { return Specifiers & VS_Final; }
1785  SourceLocation getFinalLoc() const { return VS_finalLoc; }
1786
1787  void clear() { Specifiers = 0; }
1788
1789  static const char *getSpecifierName(Specifier VS);
1790
1791  SourceLocation getLastLocation() const { return LastLocation; }
1792
1793private:
1794  unsigned Specifiers;
1795
1796  SourceLocation VS_overrideLoc, VS_finalLoc;
1797  SourceLocation LastLocation;
1798};
1799
1800} // end namespace clang
1801
1802#endif
1803