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