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