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