clang API Documentation

DeclSpec.h
Go to the documentation of this file.
00001 //===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the classes used to store parsed information about
00011 // declaration-specifiers and declarators.
00012 //
00013 //   static const int volatile x, *y, *(*(*z)[10])(const void *x);
00014 //   ------------------------- -  --  ---------------------------
00015 //     declaration-specifiers  \  |   /
00016 //                            declarators
00017 //
00018 //===----------------------------------------------------------------------===//
00019 
00020 #ifndef LLVM_CLANG_SEMA_DECLSPEC_H
00021 #define LLVM_CLANG_SEMA_DECLSPEC_H
00022 
00023 #include "clang/Sema/AttributeList.h"
00024 #include "clang/Sema/Ownership.h"
00025 #include "clang/AST/NestedNameSpecifier.h"
00026 #include "clang/Lex/Token.h"
00027 #include "clang/Basic/ExceptionSpecificationType.h"
00028 #include "clang/Basic/Lambda.h"
00029 #include "clang/Basic/OperatorKinds.h"
00030 #include "clang/Basic/Specifiers.h"
00031 #include "llvm/ADT/SmallVector.h"
00032 #include "llvm/Support/Compiler.h"
00033 #include "llvm/Support/ErrorHandling.h"
00034 
00035 namespace clang {
00036   class ASTContext;
00037   class TypeLoc;
00038   class LangOptions;
00039   class DiagnosticsEngine;
00040   class IdentifierInfo;
00041   class NamespaceAliasDecl;
00042   class NamespaceDecl;
00043   class NestedNameSpecifier;
00044   class NestedNameSpecifierLoc;
00045   class ObjCDeclSpec;
00046   class Preprocessor;
00047   class Sema;
00048   class Declarator;
00049   struct TemplateIdAnnotation;
00050 
00051 /// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope
00052 /// specifier.  These can be in 3 states:
00053 ///   1) Not present, identified by isEmpty()
00054 ///   2) Present, identified by isNotEmpty()
00055 ///      2.a) Valid, idenified by isValid()
00056 ///      2.b) Invalid, identified by isInvalid().
00057 ///
00058 /// isSet() is deprecated because it mostly corresponded to "valid" but was
00059 /// often used as if it meant "present".
00060 ///
00061 /// The actual scope is described by getScopeRep().
00062 class CXXScopeSpec {
00063   SourceRange Range;  
00064   NestedNameSpecifierLocBuilder Builder;
00065 
00066 public:
00067   const SourceRange &getRange() const { return Range; }
00068   void setRange(const SourceRange &R) { Range = R; }
00069   void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
00070   void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
00071   SourceLocation getBeginLoc() const { return Range.getBegin(); }
00072   SourceLocation getEndLoc() const { return Range.getEnd(); }
00073 
00074   /// \brief Retrieve the representation of the nested-name-specifier.
00075   NestedNameSpecifier *getScopeRep() const { 
00076     return Builder.getRepresentation(); 
00077   }
00078 
00079   /// \brief Extend the current nested-name-specifier by another
00080   /// nested-name-specifier component of the form 'type::'.
00081   ///
00082   /// \param Context The AST context in which this nested-name-specifier
00083   /// resides.
00084   ///
00085   /// \param TemplateKWLoc The location of the 'template' keyword, if present.
00086   ///
00087   /// \param TL The TypeLoc that describes the type preceding the '::'.
00088   ///
00089   /// \param ColonColonLoc The location of the trailing '::'.
00090   void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
00091               SourceLocation ColonColonLoc);
00092 
00093   /// \brief Extend the current nested-name-specifier by another 
00094   /// nested-name-specifier component of the form 'identifier::'.
00095   ///
00096   /// \param Context The AST context in which this nested-name-specifier
00097   /// resides.
00098   ///
00099   /// \param Identifier The identifier.
00100   ///
00101   /// \param IdentifierLoc The location of the identifier.
00102   ///
00103   /// \param ColonColonLoc The location of the trailing '::'.
00104   void Extend(ASTContext &Context, IdentifierInfo *Identifier,
00105               SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
00106 
00107   /// \brief Extend the current nested-name-specifier by another 
00108   /// nested-name-specifier component of the form 'namespace::'.
00109   ///
00110   /// \param Context The AST context in which this nested-name-specifier
00111   /// resides.
00112   ///
00113   /// \param Namespace The namespace.
00114   ///
00115   /// \param NamespaceLoc The location of the namespace name.
00116   ///
00117   /// \param ColonColonLoc The location of the trailing '::'.
00118   void Extend(ASTContext &Context, NamespaceDecl *Namespace,
00119               SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
00120 
00121   /// \brief Extend the current nested-name-specifier by another 
00122   /// nested-name-specifier component of the form 'namespace-alias::'.
00123   ///
00124   /// \param Context The AST context in which this nested-name-specifier
00125   /// resides.
00126   ///
00127   /// \param Alias The namespace alias.
00128   ///
00129   /// \param AliasLoc The location of the namespace alias 
00130   /// name.
00131   ///
00132   /// \param ColonColonLoc The location of the trailing '::'.
00133   void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
00134               SourceLocation AliasLoc, SourceLocation ColonColonLoc);
00135 
00136   /// \brief Turn this (empty) nested-name-specifier into the global
00137   /// nested-name-specifier '::'.
00138   void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
00139   
00140   /// \brief Make a new nested-name-specifier from incomplete source-location
00141   /// information.
00142   ///
00143   /// FIXME: This routine should be used very, very rarely, in cases where we
00144   /// need to synthesize a nested-name-specifier. Most code should instead use
00145   /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
00146   void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, 
00147                    SourceRange R);
00148   
00149   /// \brief Adopt an existing nested-name-specifier (with source-range 
00150   /// information).
00151   void Adopt(NestedNameSpecifierLoc Other);
00152   
00153   /// \brief Retrieve a nested-name-specifier with location information, copied
00154   /// into the given AST context.
00155   ///
00156   /// \param Context The context into which this nested-name-specifier will be
00157   /// copied.
00158   NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
00159 
00160   /// \brief Retrieve the location of the name in the last qualifier
00161   /// in this nested name specifier.  For example:
00162   ///   ::foo::bar<0>::
00163   ///          ^~~
00164   SourceLocation getLastQualifierNameLoc() const;
00165 
00166   /// No scope specifier.
00167   bool isEmpty() const { return !Range.isValid(); }
00168   /// A scope specifier is present, but may be valid or invalid.
00169   bool isNotEmpty() const { return !isEmpty(); }
00170 
00171   /// An error occurred during parsing of the scope specifier.
00172   bool isInvalid() const { return isNotEmpty() && getScopeRep() == 0; }
00173   /// A scope specifier is present, and it refers to a real scope.
00174   bool isValid() const { return isNotEmpty() && getScopeRep() != 0; }
00175 
00176   /// \brief Indicate that this nested-name-specifier is invalid.
00177   void SetInvalid(SourceRange R) { 
00178     assert(R.isValid() && "Must have a valid source range");
00179     if (Range.getBegin().isInvalid())
00180       Range.setBegin(R.getBegin());
00181     Range.setEnd(R.getEnd());
00182     Builder.Clear();
00183   }
00184   
00185   /// Deprecated.  Some call sites intend isNotEmpty() while others intend
00186   /// isValid().
00187   bool isSet() const { return getScopeRep() != 0; }
00188 
00189   void clear() {
00190     Range = SourceRange();
00191     Builder.Clear();
00192   }
00193 
00194   /// \brief Retrieve the data associated with the source-location information.
00195   char *location_data() const { return Builder.getBuffer().first; }
00196   
00197   /// \brief Retrieve the size of the data associated with source-location 
00198   /// information.
00199   unsigned location_size() const { return Builder.getBuffer().second; }
00200 };
00201 
00202 /// DeclSpec - This class captures information about "declaration specifiers",
00203 /// which encompasses storage-class-specifiers, type-specifiers,
00204 /// type-qualifiers, and function-specifiers.
00205 class DeclSpec {
00206 public:
00207   // storage-class-specifier
00208   // Note: The order of these enumerators is important for diagnostics.
00209   enum SCS {
00210     SCS_unspecified = 0,
00211     SCS_typedef,
00212     SCS_extern,
00213     SCS_static,
00214     SCS_auto,
00215     SCS_register,
00216     SCS_private_extern,
00217     SCS_mutable
00218   };
00219 
00220   // Import type specifier width enumeration and constants.
00221   typedef TypeSpecifierWidth TSW;
00222   static const TSW TSW_unspecified = clang::TSW_unspecified;
00223   static const TSW TSW_short = clang::TSW_short;
00224   static const TSW TSW_long = clang::TSW_long;
00225   static const TSW TSW_longlong = clang::TSW_longlong;
00226   
00227   enum TSC {
00228     TSC_unspecified,
00229     TSC_imaginary,
00230     TSC_complex
00231   };
00232 
00233   // Import type specifier sign enumeration and constants.
00234   typedef TypeSpecifierSign TSS;
00235   static const TSS TSS_unspecified = clang::TSS_unspecified;
00236   static const TSS TSS_signed = clang::TSS_signed;
00237   static const TSS TSS_unsigned = clang::TSS_unsigned;
00238 
00239   // Import type specifier type enumeration and constants.
00240   typedef TypeSpecifierType TST;
00241   static const TST TST_unspecified = clang::TST_unspecified;
00242   static const TST TST_void = clang::TST_void;
00243   static const TST TST_char = clang::TST_char;
00244   static const TST TST_wchar = clang::TST_wchar;
00245   static const TST TST_char16 = clang::TST_char16;
00246   static const TST TST_char32 = clang::TST_char32;
00247   static const TST TST_int = clang::TST_int;
00248   static const TST TST_int128 = clang::TST_int128;
00249   static const TST TST_half = clang::TST_half;
00250   static const TST TST_float = clang::TST_float;
00251   static const TST TST_double = clang::TST_double;
00252   static const TST TST_bool = clang::TST_bool;
00253   static const TST TST_decimal32 = clang::TST_decimal32;
00254   static const TST TST_decimal64 = clang::TST_decimal64;
00255   static const TST TST_decimal128 = clang::TST_decimal128;
00256   static const TST TST_enum = clang::TST_enum;
00257   static const TST TST_union = clang::TST_union;
00258   static const TST TST_struct = clang::TST_struct;
00259   static const TST TST_class = clang::TST_class;
00260   static const TST TST_typename = clang::TST_typename;
00261   static const TST TST_typeofType = clang::TST_typeofType;
00262   static const TST TST_typeofExpr = clang::TST_typeofExpr;
00263   static const TST TST_decltype = clang::TST_decltype;
00264   static const TST TST_underlyingType = clang::TST_underlyingType;
00265   static const TST TST_auto = clang::TST_auto;
00266   static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
00267   static const TST TST_atomic = clang::TST_atomic;
00268   static const TST TST_error = clang::TST_error;
00269 
00270   // type-qualifiers
00271   enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
00272     TQ_unspecified = 0,
00273     TQ_const       = 1,
00274     TQ_restrict    = 2,
00275     TQ_volatile    = 4
00276   };
00277 
00278   /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
00279   /// returned by getParsedSpecifiers.
00280   enum ParsedSpecifiers {
00281     PQ_None                  = 0,
00282     PQ_StorageClassSpecifier = 1,
00283     PQ_TypeSpecifier         = 2,
00284     PQ_TypeQualifier         = 4,
00285     PQ_FunctionSpecifier     = 8
00286   };
00287 
00288 private:
00289   // storage-class-specifier
00290   /*SCS*/unsigned StorageClassSpec : 3;
00291   unsigned SCS_thread_specified : 1;
00292   unsigned SCS_extern_in_linkage_spec : 1;
00293 
00294   // type-specifier
00295   /*TSW*/unsigned TypeSpecWidth : 2;
00296   /*TSC*/unsigned TypeSpecComplex : 2;
00297   /*TSS*/unsigned TypeSpecSign : 2;
00298   /*TST*/unsigned TypeSpecType : 5;
00299   unsigned TypeAltiVecVector : 1;
00300   unsigned TypeAltiVecPixel : 1;
00301   unsigned TypeAltiVecBool : 1;
00302   unsigned TypeSpecOwned : 1;
00303 
00304   // type-qualifiers
00305   unsigned TypeQualifiers : 3;  // Bitwise OR of TQ.
00306 
00307   // function-specifier
00308   unsigned FS_inline_specified : 1;
00309   unsigned FS_virtual_specified : 1;
00310   unsigned FS_explicit_specified : 1;
00311 
00312   // friend-specifier
00313   unsigned Friend_specified : 1;
00314 
00315   // constexpr-specifier
00316   unsigned Constexpr_specified : 1;
00317 
00318   /*SCS*/unsigned StorageClassSpecAsWritten : 3;
00319 
00320   union {
00321     UnionParsedType TypeRep;
00322     Decl *DeclRep;
00323     Expr *ExprRep;
00324   };
00325 
00326   // attributes.
00327   ParsedAttributes Attrs;
00328 
00329   // Scope specifier for the type spec, if applicable.
00330   CXXScopeSpec TypeScope;
00331 
00332   // List of protocol qualifiers for objective-c classes.  Used for
00333   // protocol-qualified interfaces "NString<foo>" and protocol-qualified id
00334   // "id<foo>".
00335   Decl * const *ProtocolQualifiers;
00336   unsigned NumProtocolQualifiers;
00337   SourceLocation ProtocolLAngleLoc;
00338   SourceLocation *ProtocolLocs;
00339 
00340   // SourceLocation info.  These are null if the item wasn't specified or if
00341   // the setting was synthesized.
00342   SourceRange Range;
00343 
00344   SourceLocation StorageClassSpecLoc, SCS_threadLoc;
00345   SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
00346   /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
00347   /// typename, then this is the location of the named type (if present);
00348   /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
00349   /// TSTNameLoc provides source range info for tag types.
00350   SourceLocation TSTNameLoc;
00351   SourceRange TypeofParensRange;
00352   SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc;
00353   SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc;
00354   SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
00355 
00356   WrittenBuiltinSpecs writtenBS;
00357   void SaveWrittenBuiltinSpecs();
00358   void SaveStorageSpecifierAsWritten();
00359 
00360   ObjCDeclSpec *ObjCQualifiers;
00361 
00362   static bool isTypeRep(TST T) {
00363     return (T == TST_typename || T == TST_typeofType ||
00364             T == TST_underlyingType || T == TST_atomic);
00365   }
00366   static bool isExprRep(TST T) {
00367     return (T == TST_typeofExpr || T == TST_decltype);
00368   }
00369   static bool isDeclRep(TST T) {
00370     return (T == TST_enum || T == TST_struct ||
00371             T == TST_union || T == TST_class);
00372   }
00373 
00374   DeclSpec(const DeclSpec&);       // DO NOT IMPLEMENT
00375   void operator=(const DeclSpec&); // DO NOT IMPLEMENT
00376 public:
00377 
00378   DeclSpec(AttributeFactory &attrFactory)
00379     : StorageClassSpec(SCS_unspecified),
00380       SCS_thread_specified(false),
00381       SCS_extern_in_linkage_spec(false),
00382       TypeSpecWidth(TSW_unspecified),
00383       TypeSpecComplex(TSC_unspecified),
00384       TypeSpecSign(TSS_unspecified),
00385       TypeSpecType(TST_unspecified),
00386       TypeAltiVecVector(false),
00387       TypeAltiVecPixel(false),
00388       TypeAltiVecBool(false),
00389       TypeSpecOwned(false),
00390       TypeQualifiers(TQ_unspecified),
00391       FS_inline_specified(false),
00392       FS_virtual_specified(false),
00393       FS_explicit_specified(false),
00394       Friend_specified(false),
00395       Constexpr_specified(false),
00396       StorageClassSpecAsWritten(SCS_unspecified),
00397       Attrs(attrFactory),
00398       ProtocolQualifiers(0),
00399       NumProtocolQualifiers(0),
00400       ProtocolLocs(0),
00401       writtenBS(),
00402       ObjCQualifiers(0) {
00403   }
00404   ~DeclSpec() {
00405     delete [] ProtocolQualifiers;
00406     delete [] ProtocolLocs;
00407   }
00408   // storage-class-specifier
00409   SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
00410   bool isThreadSpecified() const { return SCS_thread_specified; }
00411   bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
00412   void setExternInLinkageSpec(bool Value) {
00413     SCS_extern_in_linkage_spec = Value;
00414   }
00415 
00416   SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
00417   SourceLocation getThreadSpecLoc() const { return SCS_threadLoc; }
00418 
00419   void ClearStorageClassSpecs() {
00420     StorageClassSpec     = DeclSpec::SCS_unspecified;
00421     SCS_thread_specified = false;
00422     SCS_extern_in_linkage_spec = false;
00423     StorageClassSpecLoc  = SourceLocation();
00424     SCS_threadLoc        = SourceLocation();
00425   }
00426 
00427   // type-specifier
00428   TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
00429   TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
00430   TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
00431   TST getTypeSpecType() const { return (TST)TypeSpecType; }
00432   bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
00433   bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
00434   bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
00435   bool isTypeSpecOwned() const { return TypeSpecOwned; }
00436   ParsedType getRepAsType() const {
00437     assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
00438     return TypeRep;
00439   }
00440   Decl *getRepAsDecl() const {
00441     assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
00442     return DeclRep;
00443   }
00444   Expr *getRepAsExpr() const {
00445     assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
00446     return ExprRep;
00447   }
00448   CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
00449   const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
00450 
00451   const SourceRange &getSourceRange() const LLVM_READONLY { return Range; }
00452   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00453   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00454 
00455   SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; }
00456   SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
00457   SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
00458   SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
00459   SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
00460 
00461   SourceLocation getTypeSpecTypeNameLoc() const {
00462     assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
00463     return TSTNameLoc;
00464   }
00465 
00466   SourceRange getTypeofParensRange() const { return TypeofParensRange; }
00467   void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
00468 
00469   /// getSpecifierName - Turn a type-specifier-type into a string like "_Bool"
00470   /// or "union".
00471   static const char *getSpecifierName(DeclSpec::TST T);
00472   static const char *getSpecifierName(DeclSpec::TQ Q);
00473   static const char *getSpecifierName(DeclSpec::TSS S);
00474   static const char *getSpecifierName(DeclSpec::TSC C);
00475   static const char *getSpecifierName(DeclSpec::TSW W);
00476   static const char *getSpecifierName(DeclSpec::SCS S);
00477 
00478   // type-qualifiers
00479 
00480   /// getTypeQualifiers - Return a set of TQs.
00481   unsigned getTypeQualifiers() const { return TypeQualifiers; }
00482   SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
00483   SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
00484   SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
00485 
00486   /// \brief Clear out all of the type qualifiers.
00487   void ClearTypeQualifiers() {
00488     TypeQualifiers = 0;
00489     TQ_constLoc = SourceLocation();
00490     TQ_restrictLoc = SourceLocation();
00491     TQ_volatileLoc = SourceLocation();
00492   }
00493 
00494   // function-specifier
00495   bool isInlineSpecified() const { return FS_inline_specified; }
00496   SourceLocation getInlineSpecLoc() const { return FS_inlineLoc; }
00497 
00498   bool isVirtualSpecified() const { return FS_virtual_specified; }
00499   SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
00500 
00501   bool isExplicitSpecified() const { return FS_explicit_specified; }
00502   SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
00503 
00504   void ClearFunctionSpecs() {
00505     FS_inline_specified = false;
00506     FS_inlineLoc = SourceLocation();
00507     FS_virtual_specified = false;
00508     FS_virtualLoc = SourceLocation();
00509     FS_explicit_specified = false;
00510     FS_explicitLoc = SourceLocation();
00511   }
00512 
00513   /// hasTypeSpecifier - Return true if any type-specifier has been found.
00514   bool hasTypeSpecifier() const {
00515     return getTypeSpecType() != DeclSpec::TST_unspecified ||
00516            getTypeSpecWidth() != DeclSpec::TSW_unspecified ||
00517            getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
00518            getTypeSpecSign() != DeclSpec::TSS_unspecified;
00519   }
00520 
00521   /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
00522   /// DeclSpec includes.
00523   ///
00524   unsigned getParsedSpecifiers() const;
00525 
00526   SCS getStorageClassSpecAsWritten() const {
00527     return (SCS)StorageClassSpecAsWritten;
00528   }
00529 
00530   /// isEmpty - Return true if this declaration specifier is completely empty:
00531   /// no tokens were parsed in the production of it.
00532   bool isEmpty() const {
00533     return getParsedSpecifiers() == DeclSpec::PQ_None;
00534   }
00535 
00536   void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
00537   void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
00538 
00539   /// These methods set the specified attribute of the DeclSpec and
00540   /// return false if there was no error.  If an error occurs (for
00541   /// example, if we tried to set "auto" on a spec with "extern"
00542   /// already set), they return true and set PrevSpec and DiagID
00543   /// such that
00544   ///   Diag(Loc, DiagID) << PrevSpec;
00545   /// will yield a useful result.
00546   ///
00547   /// TODO: use a more general approach that still allows these
00548   /// diagnostics to be ignored when desired.
00549   bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
00550                            const char *&PrevSpec, unsigned &DiagID);
00551   bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
00552                                  unsigned &DiagID);
00553   bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
00554                         unsigned &DiagID);
00555   bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
00556                           unsigned &DiagID);
00557   bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec,
00558                        unsigned &DiagID);
00559   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
00560                        unsigned &DiagID);
00561   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
00562                        unsigned &DiagID, ParsedType Rep);
00563   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
00564                        unsigned &DiagID, Decl *Rep, bool Owned);
00565   bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
00566                        SourceLocation TagNameLoc, const char *&PrevSpec,
00567                        unsigned &DiagID, ParsedType Rep);
00568   bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
00569                        SourceLocation TagNameLoc, const char *&PrevSpec,
00570                        unsigned &DiagID, Decl *Rep, bool Owned);
00571 
00572   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
00573                        unsigned &DiagID, Expr *Rep);
00574   bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
00575                        const char *&PrevSpec, unsigned &DiagID);
00576   bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
00577                        const char *&PrevSpec, unsigned &DiagID);
00578   bool SetTypeSpecError();
00579   void UpdateDeclRep(Decl *Rep) {
00580     assert(isDeclRep((TST) TypeSpecType));
00581     DeclRep = Rep;
00582   }
00583   void UpdateTypeRep(ParsedType Rep) {
00584     assert(isTypeRep((TST) TypeSpecType));
00585     TypeRep = Rep;
00586   }
00587   void UpdateExprRep(Expr *Rep) {
00588     assert(isExprRep((TST) TypeSpecType));
00589     ExprRep = Rep;
00590   }
00591 
00592   bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
00593                    unsigned &DiagID, const LangOptions &Lang);
00594 
00595   bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
00596                              unsigned &DiagID);
00597   bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
00598                               unsigned &DiagID);
00599   bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
00600                                unsigned &DiagID);
00601 
00602   bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
00603                      unsigned &DiagID);
00604   bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
00605                             unsigned &DiagID);
00606   bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
00607                         unsigned &DiagID);
00608 
00609   bool isFriendSpecified() const { return Friend_specified; }
00610   SourceLocation getFriendSpecLoc() const { return FriendLoc; }
00611 
00612   bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
00613   SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
00614   
00615   bool isConstexprSpecified() const { return Constexpr_specified; }
00616   SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
00617 
00618   void ClearConstexprSpec() {
00619     Constexpr_specified = false;
00620     ConstexprLoc = SourceLocation();
00621   }
00622 
00623   AttributePool &getAttributePool() const {
00624     return Attrs.getPool();
00625   }
00626 
00627   /// AddAttributes - contatenates two attribute lists.
00628   /// The GCC attribute syntax allows for the following:
00629   ///
00630   /// short __attribute__(( unused, deprecated ))
00631   /// int __attribute__(( may_alias, aligned(16) )) var;
00632   ///
00633   /// This declares 4 attributes using 2 lists. The following syntax is
00634   /// also allowed and equivalent to the previous declaration.
00635   ///
00636   /// short __attribute__((unused)) __attribute__((deprecated))
00637   /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
00638   ///
00639   void addAttributes(AttributeList *AL) {
00640     Attrs.addAll(AL);
00641   }
00642   void setAttributes(AttributeList *AL) {
00643     Attrs.set(AL);
00644   }
00645 
00646   bool hasAttributes() const { return !Attrs.empty(); }
00647 
00648   ParsedAttributes &getAttributes() { return Attrs; }
00649   const ParsedAttributes &getAttributes() const { return Attrs; }
00650 
00651   /// TakeAttributes - Return the current attribute list and remove them from
00652   /// the DeclSpec so that it doesn't own them.
00653   ParsedAttributes takeAttributes() {
00654     // The non-const "copy" constructor clears the operand automatically.
00655     return Attrs;
00656   }
00657 
00658   void takeAttributesFrom(ParsedAttributes &attrs) {
00659     Attrs.takeAllFrom(attrs);
00660   }
00661 
00662   typedef Decl * const *ProtocolQualifierListTy;
00663   ProtocolQualifierListTy getProtocolQualifiers() const {
00664     return ProtocolQualifiers;
00665   }
00666   SourceLocation *getProtocolLocs() const { return ProtocolLocs; }
00667   unsigned getNumProtocolQualifiers() const {
00668     return NumProtocolQualifiers;
00669   }
00670   SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; }
00671   void setProtocolQualifiers(Decl * const *Protos, unsigned NP,
00672                              SourceLocation *ProtoLocs,
00673                              SourceLocation LAngleLoc);
00674 
00675   /// Finish - This does final analysis of the declspec, issuing diagnostics for
00676   /// things like "_Imaginary" (lacking an FP type).  After calling this method,
00677   /// DeclSpec is guaranteed self-consistent, even if an error occurred.
00678   void Finish(DiagnosticsEngine &D, Preprocessor &PP);
00679 
00680   const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
00681     return writtenBS;
00682   }
00683 
00684   ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
00685   void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
00686 
00687   /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone,
00688   /// without a Declarator. Only tag declspecs can stand alone.
00689   bool isMissingDeclaratorOk();
00690 };
00691 
00692 /// ObjCDeclSpec - This class captures information about
00693 /// "declaration specifiers" specific to objective-c
00694 class ObjCDeclSpec {
00695 public:
00696   /// ObjCDeclQualifier - Qualifier used on types in method
00697   /// declarations.  Not all combinations are sensible.  Parameters
00698   /// can be one of { in, out, inout } with one of { bycopy, byref }.
00699   /// Returns can either be { oneway } or not.
00700   ///
00701   /// This should be kept in sync with Decl::ObjCDeclQualifier.
00702   enum ObjCDeclQualifier {
00703     DQ_None = 0x0,
00704     DQ_In = 0x1,
00705     DQ_Inout = 0x2,
00706     DQ_Out = 0x4,
00707     DQ_Bycopy = 0x8,
00708     DQ_Byref = 0x10,
00709     DQ_Oneway = 0x20
00710   };
00711 
00712   /// PropertyAttributeKind - list of property attributes.
00713   enum ObjCPropertyAttributeKind {
00714     DQ_PR_noattr = 0x0,
00715     DQ_PR_readonly = 0x01,
00716     DQ_PR_getter = 0x02,
00717     DQ_PR_assign = 0x04,
00718     DQ_PR_readwrite = 0x08,
00719     DQ_PR_retain = 0x10,
00720     DQ_PR_copy = 0x20,
00721     DQ_PR_nonatomic = 0x40,
00722     DQ_PR_setter = 0x80,
00723     DQ_PR_atomic = 0x100,
00724     DQ_PR_weak =   0x200,
00725     DQ_PR_strong = 0x400,
00726     DQ_PR_unsafe_unretained = 0x800
00727   };
00728 
00729 
00730   ObjCDeclSpec()
00731     : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr),
00732       GetterName(0), SetterName(0) { }
00733   ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; }
00734   void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
00735     objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
00736   }
00737 
00738   ObjCPropertyAttributeKind getPropertyAttributes() const {
00739     return ObjCPropertyAttributeKind(PropertyAttributes);
00740   }
00741   void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) {
00742     PropertyAttributes =
00743       (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal);
00744   }
00745 
00746   const IdentifierInfo *getGetterName() const { return GetterName; }
00747   IdentifierInfo *getGetterName() { return GetterName; }
00748   void setGetterName(IdentifierInfo *name) { GetterName = name; }
00749 
00750   const IdentifierInfo *getSetterName() const { return SetterName; }
00751   IdentifierInfo *getSetterName() { return SetterName; }
00752   void setSetterName(IdentifierInfo *name) { SetterName = name; }
00753 
00754 private:
00755   // FIXME: These two are unrelated and mutially exclusive. So perhaps
00756   // we can put them in a union to reflect their mutual exclusiveness
00757   // (space saving is negligible).
00758   ObjCDeclQualifier objcDeclQualifier : 6;
00759 
00760   // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind
00761   unsigned PropertyAttributes : 12;
00762   IdentifierInfo *GetterName;    // getter name of NULL if no getter
00763   IdentifierInfo *SetterName;    // setter name of NULL if no setter
00764 };
00765 
00766 /// \brief Represents a C++ unqualified-id that has been parsed. 
00767 class UnqualifiedId {
00768 private:
00769   const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT
00770   
00771 public:
00772   /// \brief Describes the kind of unqualified-id parsed.
00773   enum IdKind {
00774     /// \brief An identifier.
00775     IK_Identifier,
00776     /// \brief An overloaded operator name, e.g., operator+.
00777     IK_OperatorFunctionId,
00778     /// \brief A conversion function name, e.g., operator int.
00779     IK_ConversionFunctionId,
00780     /// \brief A user-defined literal name, e.g., operator "" _i.
00781     IK_LiteralOperatorId,
00782     /// \brief A constructor name.
00783     IK_ConstructorName,
00784     /// \brief A constructor named via a template-id.
00785     IK_ConstructorTemplateId,
00786     /// \brief A destructor name.
00787     IK_DestructorName,
00788     /// \brief A template-id, e.g., f<int>.
00789     IK_TemplateId,
00790     /// \brief An implicit 'self' parameter
00791     IK_ImplicitSelfParam
00792   } Kind;
00793 
00794   /// \brief Anonymous union that holds extra data associated with the
00795   /// parsed unqualified-id.
00796   union {
00797     /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind
00798     /// == IK_UserLiteralId, the identifier suffix.
00799     IdentifierInfo *Identifier;
00800     
00801     /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator
00802     /// that we parsed.
00803     struct {
00804       /// \brief The kind of overloaded operator.
00805       OverloadedOperatorKind Operator;
00806       
00807       /// \brief The source locations of the individual tokens that name
00808       /// the operator, e.g., the "new", "[", and "]" tokens in 
00809       /// operator new []. 
00810       ///
00811       /// Different operators have different numbers of tokens in their name,
00812       /// up to three. Any remaining source locations in this array will be
00813       /// set to an invalid value for operators with fewer than three tokens.
00814       unsigned SymbolLocations[3];
00815     } OperatorFunctionId;
00816     
00817     /// \brief When Kind == IK_ConversionFunctionId, the type that the 
00818     /// conversion function names.
00819     UnionParsedType ConversionFunctionId;
00820 
00821     /// \brief When Kind == IK_ConstructorName, the class-name of the type
00822     /// whose constructor is being referenced.
00823     UnionParsedType ConstructorName;
00824     
00825     /// \brief When Kind == IK_DestructorName, the type referred to by the
00826     /// class-name.
00827     UnionParsedType DestructorName;
00828     
00829     /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId,
00830     /// the template-id annotation that contains the template name and
00831     /// template arguments.
00832     TemplateIdAnnotation *TemplateId;
00833   };
00834   
00835   /// \brief The location of the first token that describes this unqualified-id,
00836   /// which will be the location of the identifier, "operator" keyword,
00837   /// tilde (for a destructor), or the template name of a template-id.
00838   SourceLocation StartLocation;
00839   
00840   /// \brief The location of the last token that describes this unqualified-id.
00841   SourceLocation EndLocation;
00842   
00843   UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { }
00844 
00845   /// \brief Do not use this copy constructor. It is temporary, and only
00846   /// exists because we are holding FieldDeclarators in a SmallVector when we
00847   /// don't actually need them.
00848   ///
00849   /// FIXME: Kill this copy constructor.
00850   UnqualifiedId(const UnqualifiedId &Other) 
00851     : Kind(IK_Identifier), Identifier(Other.Identifier), 
00852       StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) {
00853     assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers");
00854   }
00855 
00856   /// \brief Clear out this unqualified-id, setting it to default (invalid) 
00857   /// state.
00858   void clear() {
00859     Kind = IK_Identifier;
00860     Identifier = 0;
00861     StartLocation = SourceLocation();
00862     EndLocation = SourceLocation();
00863   }
00864   
00865   /// \brief Determine whether this unqualified-id refers to a valid name.
00866   bool isValid() const { return StartLocation.isValid(); }
00867 
00868   /// \brief Determine whether this unqualified-id refers to an invalid name.
00869   bool isInvalid() const { return !isValid(); }
00870   
00871   /// \brief Determine what kind of name we have.
00872   IdKind getKind() const { return Kind; }
00873   void setKind(IdKind kind) { Kind = kind; } 
00874   
00875   /// \brief Specify that this unqualified-id was parsed as an identifier.
00876   ///
00877   /// \param Id the parsed identifier.
00878   /// \param IdLoc the location of the parsed identifier.
00879   void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
00880     Kind = IK_Identifier;
00881     Identifier = const_cast<IdentifierInfo *>(Id);
00882     StartLocation = EndLocation = IdLoc;
00883   }
00884   
00885   /// \brief Specify that this unqualified-id was parsed as an 
00886   /// operator-function-id.
00887   ///
00888   /// \param OperatorLoc the location of the 'operator' keyword.
00889   ///
00890   /// \param Op the overloaded operator.
00891   ///
00892   /// \param SymbolLocations the locations of the individual operator symbols
00893   /// in the operator.
00894   void setOperatorFunctionId(SourceLocation OperatorLoc, 
00895                              OverloadedOperatorKind Op,
00896                              SourceLocation SymbolLocations[3]);
00897   
00898   /// \brief Specify that this unqualified-id was parsed as a 
00899   /// conversion-function-id.
00900   ///
00901   /// \param OperatorLoc the location of the 'operator' keyword.
00902   ///
00903   /// \param Ty the type to which this conversion function is converting.
00904   ///
00905   /// \param EndLoc the location of the last token that makes up the type name.
00906   void setConversionFunctionId(SourceLocation OperatorLoc, 
00907                                ParsedType Ty,
00908                                SourceLocation EndLoc) {
00909     Kind = IK_ConversionFunctionId;
00910     StartLocation = OperatorLoc;
00911     EndLocation = EndLoc;
00912     ConversionFunctionId = Ty;
00913   }
00914 
00915   /// \brief Specific that this unqualified-id was parsed as a
00916   /// literal-operator-id.
00917   ///
00918   /// \param Id the parsed identifier.
00919   ///
00920   /// \param OpLoc the location of the 'operator' keyword.
00921   ///
00922   /// \param IdLoc the location of the identifier.
00923   void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
00924                               SourceLocation IdLoc) {
00925     Kind = IK_LiteralOperatorId;
00926     Identifier = const_cast<IdentifierInfo *>(Id);
00927     StartLocation = OpLoc;
00928     EndLocation = IdLoc;
00929   }
00930   
00931   /// \brief Specify that this unqualified-id was parsed as a constructor name.
00932   ///
00933   /// \param ClassType the class type referred to by the constructor name.
00934   ///
00935   /// \param ClassNameLoc the location of the class name.
00936   ///
00937   /// \param EndLoc the location of the last token that makes up the type name.
00938   void setConstructorName(ParsedType ClassType, 
00939                           SourceLocation ClassNameLoc,
00940                           SourceLocation EndLoc) {
00941     Kind = IK_ConstructorName;
00942     StartLocation = ClassNameLoc;
00943     EndLocation = EndLoc;
00944     ConstructorName = ClassType;
00945   }
00946 
00947   /// \brief Specify that this unqualified-id was parsed as a
00948   /// template-id that names a constructor.
00949   ///
00950   /// \param TemplateId the template-id annotation that describes the parsed
00951   /// template-id. This UnqualifiedId instance will take ownership of the
00952   /// \p TemplateId and will free it on destruction.
00953   void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
00954 
00955   /// \brief Specify that this unqualified-id was parsed as a destructor name.
00956   ///
00957   /// \param TildeLoc the location of the '~' that introduces the destructor
00958   /// name.
00959   ///
00960   /// \param ClassType the name of the class referred to by the destructor name.
00961   void setDestructorName(SourceLocation TildeLoc,
00962                          ParsedType ClassType,
00963                          SourceLocation EndLoc) {
00964     Kind = IK_DestructorName;
00965     StartLocation = TildeLoc;
00966     EndLocation = EndLoc;
00967     DestructorName = ClassType;
00968   }
00969   
00970   /// \brief Specify that this unqualified-id was parsed as a template-id.
00971   ///
00972   /// \param TemplateId the template-id annotation that describes the parsed
00973   /// template-id. This UnqualifiedId instance will take ownership of the
00974   /// \p TemplateId and will free it on destruction.
00975   void setTemplateId(TemplateIdAnnotation *TemplateId);
00976 
00977   /// \brief Return the source range that covers this unqualified-id.
00978   SourceRange getSourceRange() const LLVM_READONLY { 
00979     return SourceRange(StartLocation, EndLocation); 
00980   }
00981   SourceLocation getLocStart() const LLVM_READONLY { return StartLocation; }
00982   SourceLocation getLocEnd() const LLVM_READONLY { return EndLocation; }
00983 };
00984   
00985 /// CachedTokens - A set of tokens that has been cached for later
00986 /// parsing.
00987 typedef SmallVector<Token, 4> CachedTokens;
00988 
00989 /// DeclaratorChunk - One instance of this struct is used for each type in a
00990 /// declarator that is parsed.
00991 ///
00992 /// This is intended to be a small value object.
00993 struct DeclaratorChunk {
00994   enum {
00995     Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren
00996   } Kind;
00997 
00998   /// Loc - The place where this type was defined.
00999   SourceLocation Loc;
01000   /// EndLoc - If valid, the place where this chunck ends.
01001   SourceLocation EndLoc;
01002 
01003   struct TypeInfoCommon {
01004     AttributeList *AttrList;
01005   };
01006 
01007   struct PointerTypeInfo : TypeInfoCommon {
01008     /// The type qualifiers: const/volatile/restrict.
01009     unsigned TypeQuals : 3;
01010 
01011     /// The location of the const-qualifier, if any.
01012     unsigned ConstQualLoc;
01013 
01014     /// The location of the volatile-qualifier, if any.
01015     unsigned VolatileQualLoc;
01016 
01017     /// The location of the restrict-qualifier, if any.
01018     unsigned RestrictQualLoc;
01019 
01020     void destroy() {
01021     }
01022   };
01023 
01024   struct ReferenceTypeInfo : TypeInfoCommon {
01025     /// The type qualifier: restrict. [GNU] C++ extension
01026     bool HasRestrict : 1;
01027     /// True if this is an lvalue reference, false if it's an rvalue reference.
01028     bool LValueRef : 1;
01029     void destroy() {
01030     }
01031   };
01032 
01033   struct ArrayTypeInfo : TypeInfoCommon {
01034     /// The type qualifiers for the array: const/volatile/restrict.
01035     unsigned TypeQuals : 3;
01036 
01037     /// True if this dimension included the 'static' keyword.
01038     bool hasStatic : 1;
01039 
01040     /// True if this dimension was [*].  In this case, NumElts is null.
01041     bool isStar : 1;
01042 
01043     /// This is the size of the array, or null if [] or [*] was specified.
01044     /// Since the parser is multi-purpose, and we don't want to impose a root
01045     /// expression class on all clients, NumElts is untyped.
01046     Expr *NumElts;
01047 
01048     void destroy() {}
01049   };
01050 
01051   /// ParamInfo - An array of paraminfo objects is allocated whenever a function
01052   /// declarator is parsed.  There are two interesting styles of arguments here:
01053   /// K&R-style identifier lists and parameter type lists.  K&R-style identifier
01054   /// lists will have information about the identifier, but no type information.
01055   /// Parameter type lists will have type info (if the actions module provides
01056   /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
01057   struct ParamInfo {
01058     IdentifierInfo *Ident;
01059     SourceLocation IdentLoc;
01060     Decl *Param;
01061 
01062     /// DefaultArgTokens - When the parameter's default argument
01063     /// cannot be parsed immediately (because it occurs within the
01064     /// declaration of a member function), it will be stored here as a
01065     /// sequence of tokens to be parsed once the class definition is
01066     /// complete. Non-NULL indicates that there is a default argument.
01067     CachedTokens *DefaultArgTokens;
01068 
01069     ParamInfo() {}
01070     ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
01071               Decl *param,
01072               CachedTokens *DefArgTokens = 0)
01073       : Ident(ident), IdentLoc(iloc), Param(param),
01074         DefaultArgTokens(DefArgTokens) {}
01075   };
01076 
01077   struct TypeAndRange {
01078     ParsedType Ty;
01079     SourceRange Range;
01080   };
01081 
01082   struct FunctionTypeInfo : TypeInfoCommon {
01083     /// hasPrototype - This is true if the function had at least one typed
01084     /// argument.  If the function is () or (a,b,c), then it has no prototype,
01085     /// and is treated as a K&R-style function.
01086     unsigned hasPrototype : 1;
01087 
01088     /// isVariadic - If this function has a prototype, and if that
01089     /// proto ends with ',...)', this is true. When true, EllipsisLoc
01090     /// contains the location of the ellipsis.
01091     unsigned isVariadic : 1;
01092 
01093     /// \brief Whether the ref-qualifier (if any) is an lvalue reference.
01094     /// Otherwise, it's an rvalue reference.
01095     unsigned RefQualifierIsLValueRef : 1;
01096     
01097     /// The type qualifiers: const/volatile/restrict.
01098     /// The qualifier bitmask values are the same as in QualType.
01099     unsigned TypeQuals : 3;
01100 
01101     /// ExceptionSpecType - An ExceptionSpecificationType value.
01102     unsigned ExceptionSpecType : 3;
01103 
01104     /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo.
01105     unsigned DeleteArgInfo : 1;
01106 
01107     /// When isVariadic is true, the location of the ellipsis in the source.
01108     unsigned EllipsisLoc;
01109 
01110     /// NumArgs - This is the number of formal arguments provided for the
01111     /// declarator.
01112     unsigned NumArgs;
01113 
01114     /// NumExceptions - This is the number of types in the dynamic-exception-
01115     /// decl, if the function has one.
01116     unsigned NumExceptions;
01117 
01118     /// \brief The location of the ref-qualifier, if any.
01119     ///
01120     /// If this is an invalid location, there is no ref-qualifier.
01121     unsigned RefQualifierLoc;
01122 
01123     /// \brief The location of the const-qualifier, if any.
01124     ///
01125     /// If this is an invalid location, there is no const-qualifier.
01126     unsigned ConstQualifierLoc;
01127 
01128     /// \brief The location of the volatile-qualifier, if any.
01129     ///
01130     /// If this is an invalid location, there is no volatile-qualifier.
01131     unsigned VolatileQualifierLoc;
01132 
01133     /// \brief The location of the 'mutable' qualifer in a lambda-declarator, if
01134     /// any.
01135     unsigned MutableLoc;
01136 
01137     /// \brief When ExceptionSpecType isn't EST_None or EST_Delayed, the
01138     /// location of the keyword introducing the spec.
01139     unsigned ExceptionSpecLoc;
01140 
01141     /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
01142     /// describe the arguments for this function declarator.  This is null if
01143     /// there are no arguments specified.
01144     ParamInfo *ArgInfo;
01145 
01146     union {
01147       /// \brief Pointer to a new[]'d array of TypeAndRange objects that
01148       /// contain the types in the function's dynamic exception specification
01149       /// and their locations, if there is one.
01150       TypeAndRange *Exceptions;
01151 
01152       /// \brief Pointer to the expression in the noexcept-specifier of this
01153       /// function, if it has one.
01154       Expr *NoexceptExpr;
01155     };
01156 
01157     /// TrailingReturnType - If this isn't null, it's the trailing return type
01158     /// specified. This is actually a ParsedType, but stored as void* to
01159     /// allow union storage.
01160     void *TrailingReturnType;
01161 
01162     /// freeArgs - reset the argument list to having zero arguments.  This is
01163     /// used in various places for error recovery.
01164     void freeArgs() {
01165       if (DeleteArgInfo) {
01166         delete[] ArgInfo;
01167         DeleteArgInfo = false;
01168       }
01169       NumArgs = 0;
01170     }
01171 
01172     void destroy() {
01173       if (DeleteArgInfo)
01174         delete[] ArgInfo;
01175       if (getExceptionSpecType() == EST_Dynamic)
01176         delete[] Exceptions;
01177     }
01178 
01179     /// isKNRPrototype - Return true if this is a K&R style identifier list,
01180     /// like "void foo(a,b,c)".  In a function definition, this will be followed
01181     /// by the argument type definitions.
01182     bool isKNRPrototype() const {
01183       return !hasPrototype && NumArgs != 0;
01184     }
01185     
01186     SourceLocation getEllipsisLoc() const {
01187       return SourceLocation::getFromRawEncoding(EllipsisLoc);
01188     }
01189     SourceLocation getExceptionSpecLoc() const {
01190       return SourceLocation::getFromRawEncoding(ExceptionSpecLoc);
01191     }
01192 
01193     /// \brief Retrieve the location of the ref-qualifier, if any.
01194     SourceLocation getRefQualifierLoc() const {
01195       return SourceLocation::getFromRawEncoding(RefQualifierLoc);
01196     }
01197 
01198     /// \brief Retrieve the location of the ref-qualifier, if any.
01199     SourceLocation getConstQualifierLoc() const {
01200       return SourceLocation::getFromRawEncoding(ConstQualifierLoc);
01201     }
01202 
01203     /// \brief Retrieve the location of the ref-qualifier, if any.
01204     SourceLocation getVolatileQualifierLoc() const {
01205       return SourceLocation::getFromRawEncoding(VolatileQualifierLoc);
01206     }
01207 
01208     /// \brief Retrieve the location of the 'mutable' qualifier, if any.
01209     SourceLocation getMutableLoc() const {
01210       return SourceLocation::getFromRawEncoding(MutableLoc);
01211     }
01212 
01213     /// \brief Determine whether this function declaration contains a 
01214     /// ref-qualifier.
01215     bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
01216 
01217     /// \brief Determine whether this lambda-declarator contains a 'mutable'
01218     /// qualifier.
01219     bool hasMutableQualifier() const { return getMutableLoc().isValid(); }
01220 
01221     /// \brief Get the type of exception specification this function has.
01222     ExceptionSpecificationType getExceptionSpecType() const {
01223       return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
01224     }
01225   };
01226 
01227   struct BlockPointerTypeInfo : TypeInfoCommon {
01228     /// For now, sema will catch these as invalid.
01229     /// The type qualifiers: const/volatile/restrict.
01230     unsigned TypeQuals : 3;
01231 
01232     void destroy() {
01233     }
01234   };
01235 
01236   struct MemberPointerTypeInfo : TypeInfoCommon {
01237     /// The type qualifiers: const/volatile/restrict.
01238     unsigned TypeQuals : 3;
01239     // CXXScopeSpec has a constructor, so it can't be a direct member.
01240     // So we need some pointer-aligned storage and a bit of trickery.
01241     union {
01242       void *Aligner;
01243       char Mem[sizeof(CXXScopeSpec)];
01244     } ScopeMem;
01245     CXXScopeSpec &Scope() {
01246       return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem);
01247     }
01248     const CXXScopeSpec &Scope() const {
01249       return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem);
01250     }
01251     void destroy() {
01252       Scope().~CXXScopeSpec();
01253     }
01254   };
01255 
01256   union {
01257     TypeInfoCommon        Common;
01258     PointerTypeInfo       Ptr;
01259     ReferenceTypeInfo     Ref;
01260     ArrayTypeInfo         Arr;
01261     FunctionTypeInfo      Fun;
01262     BlockPointerTypeInfo  Cls;
01263     MemberPointerTypeInfo Mem;
01264   };
01265 
01266   void destroy() {
01267     switch (Kind) {
01268     case DeclaratorChunk::Function:      return Fun.destroy();
01269     case DeclaratorChunk::Pointer:       return Ptr.destroy();
01270     case DeclaratorChunk::BlockPointer:  return Cls.destroy();
01271     case DeclaratorChunk::Reference:     return Ref.destroy();
01272     case DeclaratorChunk::Array:         return Arr.destroy();
01273     case DeclaratorChunk::MemberPointer: return Mem.destroy();
01274     case DeclaratorChunk::Paren:         return;
01275     }
01276   }
01277 
01278   /// getAttrs - If there are attributes applied to this declaratorchunk, return
01279   /// them.
01280   const AttributeList *getAttrs() const {
01281     return Common.AttrList;
01282   }
01283 
01284   AttributeList *&getAttrListRef() {
01285     return Common.AttrList;
01286   }
01287 
01288   /// getPointer - Return a DeclaratorChunk for a pointer.
01289   ///
01290   static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
01291                                     SourceLocation ConstQualLoc,
01292                                     SourceLocation VolatileQualLoc,
01293                                     SourceLocation RestrictQualLoc) {
01294     DeclaratorChunk I;
01295     I.Kind                = Pointer;
01296     I.Loc                 = Loc;
01297     I.Ptr.TypeQuals       = TypeQuals;
01298     I.Ptr.ConstQualLoc    = ConstQualLoc.getRawEncoding();
01299     I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
01300     I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
01301     I.Ptr.AttrList        = 0;
01302     return I;
01303   }
01304 
01305   /// getReference - Return a DeclaratorChunk for a reference.
01306   ///
01307   static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
01308                                       bool lvalue) {
01309     DeclaratorChunk I;
01310     I.Kind            = Reference;
01311     I.Loc             = Loc;
01312     I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
01313     I.Ref.LValueRef   = lvalue;
01314     I.Ref.AttrList    = 0;
01315     return I;
01316   }
01317 
01318   /// getArray - Return a DeclaratorChunk for an array.
01319   ///
01320   static DeclaratorChunk getArray(unsigned TypeQuals,
01321                                   bool isStatic, bool isStar, Expr *NumElts,
01322                                   SourceLocation LBLoc, SourceLocation RBLoc) {
01323     DeclaratorChunk I;
01324     I.Kind          = Array;
01325     I.Loc           = LBLoc;
01326     I.EndLoc        = RBLoc;
01327     I.Arr.AttrList  = 0;
01328     I.Arr.TypeQuals = TypeQuals;
01329     I.Arr.hasStatic = isStatic;
01330     I.Arr.isStar    = isStar;
01331     I.Arr.NumElts   = NumElts;
01332     return I;
01333   }
01334 
01335   /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
01336   /// "TheDeclarator" is the declarator that this will be added to.
01337   static DeclaratorChunk getFunction(bool hasProto, bool isVariadic,
01338                                      SourceLocation EllipsisLoc,
01339                                      ParamInfo *ArgInfo, unsigned NumArgs,
01340                                      unsigned TypeQuals, 
01341                                      bool RefQualifierIsLvalueRef,
01342                                      SourceLocation RefQualifierLoc,
01343                                      SourceLocation ConstQualifierLoc,
01344                                      SourceLocation VolatileQualifierLoc,
01345                                      SourceLocation MutableLoc,
01346                                      ExceptionSpecificationType ESpecType,
01347                                      SourceLocation ESpecLoc,
01348                                      ParsedType *Exceptions,
01349                                      SourceRange *ExceptionRanges,
01350                                      unsigned NumExceptions,
01351                                      Expr *NoexceptExpr,
01352                                      SourceLocation LocalRangeBegin,
01353                                      SourceLocation LocalRangeEnd,
01354                                      Declarator &TheDeclarator,
01355                                      ParsedType TrailingReturnType =
01356                                                     ParsedType());
01357 
01358   /// getBlockPointer - Return a DeclaratorChunk for a block.
01359   ///
01360   static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
01361                                          SourceLocation Loc) {
01362     DeclaratorChunk I;
01363     I.Kind          = BlockPointer;
01364     I.Loc           = Loc;
01365     I.Cls.TypeQuals = TypeQuals;
01366     I.Cls.AttrList  = 0;
01367     return I;
01368   }
01369 
01370   static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
01371                                           unsigned TypeQuals,
01372                                           SourceLocation Loc) {
01373     DeclaratorChunk I;
01374     I.Kind          = MemberPointer;
01375     I.Loc           = Loc;
01376     I.Mem.TypeQuals = TypeQuals;
01377     I.Mem.AttrList  = 0;
01378     new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS);
01379     return I;
01380   }
01381 
01382   /// getParen - Return a DeclaratorChunk for a paren.
01383   ///
01384   static DeclaratorChunk getParen(SourceLocation LParenLoc,
01385                                   SourceLocation RParenLoc) {
01386     DeclaratorChunk I;
01387     I.Kind          = Paren;
01388     I.Loc           = LParenLoc;
01389     I.EndLoc        = RParenLoc;
01390     I.Common.AttrList = 0;
01391     return I;
01392   }
01393 
01394 };
01395 
01396 /// \brief Described the kind of function definition (if any) provided for
01397 /// a function.
01398 enum FunctionDefinitionKind {
01399   FDK_Declaration,
01400   FDK_Definition,
01401   FDK_Defaulted,
01402   FDK_Deleted
01403 };
01404   
01405 /// Declarator - Information about one declarator, including the parsed type
01406 /// information and the identifier.  When the declarator is fully formed, this
01407 /// is turned into the appropriate Decl object.
01408 ///
01409 /// Declarators come in two types: normal declarators and abstract declarators.
01410 /// Abstract declarators are used when parsing types, and don't have an
01411 /// identifier.  Normal declarators do have ID's.
01412 ///
01413 /// Instances of this class should be a transient object that lives on the
01414 /// stack, not objects that are allocated in large quantities on the heap.
01415 class Declarator {
01416 public:
01417   enum TheContext {
01418     FileContext,         // File scope declaration.
01419     PrototypeContext,    // Within a function prototype.
01420     ObjCResultContext,   // An ObjC method result type.
01421     ObjCParameterContext,// An ObjC method parameter type.
01422     KNRTypeListContext,  // K&R type definition list for formals.
01423     TypeNameContext,     // Abstract declarator for types.
01424     MemberContext,       // Struct/Union field.
01425     BlockContext,        // Declaration within a block in a function.
01426     ForContext,          // Declaration within first part of a for loop.
01427     ConditionContext,    // Condition declaration in a C++ if/switch/while/for.
01428     TemplateParamContext,// Within a template parameter list.
01429     CXXNewContext,       // C++ new-expression.
01430     CXXCatchContext,     // C++ catch exception-declaration
01431     ObjCCatchContext,    // Objective-C catch exception-declaration
01432     BlockLiteralContext,  // Block literal declarator.
01433     LambdaExprContext,   // Lambda-expression declarator.
01434     TrailingReturnContext, // C++11 trailing-type-specifier.
01435     TemplateTypeArgContext, // Template type argument.
01436     AliasDeclContext,    // C++11 alias-declaration.
01437     AliasTemplateContext // C++11 alias-declaration template.
01438   };
01439 
01440 private:
01441   const DeclSpec &DS;
01442   CXXScopeSpec SS;
01443   UnqualifiedId Name;
01444   SourceRange Range;
01445 
01446   /// Context - Where we are parsing this declarator.
01447   ///
01448   TheContext Context;
01449 
01450   /// DeclTypeInfo - This holds each type that the declarator includes as it is
01451   /// parsed.  This is pushed from the identifier out, which means that element
01452   /// #0 will be the most closely bound to the identifier, and
01453   /// DeclTypeInfo.back() will be the least closely bound.
01454   SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
01455 
01456   /// InvalidType - Set by Sema::GetTypeForDeclarator().
01457   bool InvalidType : 1;
01458 
01459   /// GroupingParens - Set by Parser::ParseParenDeclarator().
01460   bool GroupingParens : 1;
01461 
01462   /// FunctionDefinition - Is this Declarator for a function or member 
01463   /// definition and, if so, what kind?
01464   ///
01465   /// Actually a FunctionDefinitionKind.
01466   unsigned FunctionDefinition : 2;
01467 
01468   // Redeclaration - Is this Declarator is a redeclaration.
01469   bool Redeclaration : 1;
01470 
01471   /// Attrs - Attributes.
01472   ParsedAttributes Attrs;
01473 
01474   /// AsmLabel - The asm label, if specified.
01475   Expr *AsmLabel;
01476 
01477   /// InlineParams - This is a local array used for the first function decl
01478   /// chunk to avoid going to the heap for the common case when we have one
01479   /// function chunk in the declarator.
01480   DeclaratorChunk::ParamInfo InlineParams[16];
01481   bool InlineParamsUsed;
01482 
01483   /// Extension - true if the declaration is preceded by __extension__.
01484   bool Extension : 1;
01485 
01486   /// \brief If this is the second or subsequent declarator in this declaration,
01487   /// the location of the comma before this declarator.
01488   SourceLocation CommaLoc;
01489 
01490   /// \brief If provided, the source location of the ellipsis used to describe
01491   /// this declarator as a parameter pack.
01492   SourceLocation EllipsisLoc;
01493   
01494   friend struct DeclaratorChunk;
01495 
01496 public:
01497   Declarator(const DeclSpec &ds, TheContext C)
01498     : DS(ds), Range(ds.getSourceRange()), Context(C),
01499       InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
01500       GroupingParens(false), FunctionDefinition(FDK_Declaration), 
01501       Redeclaration(false),
01502       Attrs(ds.getAttributePool().getFactory()), AsmLabel(0),
01503       InlineParamsUsed(false), Extension(false) {
01504   }
01505 
01506   ~Declarator() {
01507     clear();
01508   }
01509 
01510   /// getDeclSpec - Return the declaration-specifier that this declarator was
01511   /// declared with.
01512   const DeclSpec &getDeclSpec() const { return DS; }
01513 
01514   /// getMutableDeclSpec - Return a non-const version of the DeclSpec.  This
01515   /// should be used with extreme care: declspecs can often be shared between
01516   /// multiple declarators, so mutating the DeclSpec affects all of the
01517   /// Declarators.  This should only be done when the declspec is known to not
01518   /// be shared or when in error recovery etc.
01519   DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
01520 
01521   AttributePool &getAttributePool() const {
01522     return Attrs.getPool();
01523   }
01524 
01525   /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
01526   /// nested-name-specifier) that is part of the declarator-id.
01527   const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
01528   CXXScopeSpec &getCXXScopeSpec() { return SS; }
01529 
01530   /// \brief Retrieve the name specified by this declarator.
01531   UnqualifiedId &getName() { return Name; }
01532   
01533   TheContext getContext() const { return Context; }
01534 
01535   bool isPrototypeContext() const {
01536     return (Context == PrototypeContext ||
01537             Context == ObjCParameterContext ||
01538             Context == ObjCResultContext);
01539   }
01540 
01541   /// getSourceRange - Get the source range that spans this declarator.
01542   const SourceRange &getSourceRange() const LLVM_READONLY { return Range; }
01543   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
01544   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
01545 
01546   void SetSourceRange(SourceRange R) { Range = R; }
01547   /// SetRangeBegin - Set the start of the source range to Loc, unless it's
01548   /// invalid.
01549   void SetRangeBegin(SourceLocation Loc) {
01550     if (!Loc.isInvalid())
01551       Range.setBegin(Loc);
01552   }
01553   /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
01554   void SetRangeEnd(SourceLocation Loc) {
01555     if (!Loc.isInvalid())
01556       Range.setEnd(Loc);
01557   }
01558   /// ExtendWithDeclSpec - Extend the declarator source range to include the
01559   /// given declspec, unless its location is invalid. Adopts the range start if
01560   /// the current range start is invalid.
01561   void ExtendWithDeclSpec(const DeclSpec &DS) {
01562     const SourceRange &SR = DS.getSourceRange();
01563     if (Range.getBegin().isInvalid())
01564       Range.setBegin(SR.getBegin());
01565     if (!SR.getEnd().isInvalid())
01566       Range.setEnd(SR.getEnd());
01567   }
01568 
01569   /// clear - Reset the contents of this Declarator.
01570   void clear() {
01571     SS.clear();
01572     Name.clear();
01573     Range = DS.getSourceRange();
01574     
01575     for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
01576       DeclTypeInfo[i].destroy();
01577     DeclTypeInfo.clear();
01578     Attrs.clear();
01579     AsmLabel = 0;
01580     InlineParamsUsed = false;
01581     CommaLoc = SourceLocation();
01582     EllipsisLoc = SourceLocation();
01583   }
01584 
01585   /// mayOmitIdentifier - Return true if the identifier is either optional or
01586   /// not allowed.  This is true for typenames, prototypes, and template
01587   /// parameter lists.
01588   bool mayOmitIdentifier() const {
01589     switch (Context) {
01590     case FileContext:
01591     case KNRTypeListContext:
01592     case MemberContext:
01593     case BlockContext:
01594     case ForContext:
01595     case ConditionContext:
01596       return false;
01597 
01598     case TypeNameContext:
01599     case AliasDeclContext:
01600     case AliasTemplateContext:
01601     case PrototypeContext:
01602     case ObjCParameterContext:
01603     case ObjCResultContext:
01604     case TemplateParamContext:
01605     case CXXNewContext:
01606     case CXXCatchContext:
01607     case ObjCCatchContext:
01608     case BlockLiteralContext:
01609     case LambdaExprContext:
01610     case TemplateTypeArgContext:
01611     case TrailingReturnContext:
01612       return true;
01613     }
01614     llvm_unreachable("unknown context kind!");
01615   }
01616 
01617   /// mayHaveIdentifier - Return true if the identifier is either optional or
01618   /// required.  This is true for normal declarators and prototypes, but not
01619   /// typenames.
01620   bool mayHaveIdentifier() const {
01621     switch (Context) {
01622     case FileContext:
01623     case KNRTypeListContext:
01624     case MemberContext:
01625     case BlockContext:
01626     case ForContext:
01627     case ConditionContext:
01628     case PrototypeContext:
01629     case TemplateParamContext:
01630     case CXXCatchContext:
01631     case ObjCCatchContext:
01632       return true;
01633 
01634     case TypeNameContext:
01635     case CXXNewContext:
01636     case AliasDeclContext:
01637     case AliasTemplateContext:
01638     case ObjCParameterContext:
01639     case ObjCResultContext:
01640     case BlockLiteralContext:
01641     case LambdaExprContext:
01642     case TemplateTypeArgContext:
01643     case TrailingReturnContext:
01644       return false;
01645     }
01646     llvm_unreachable("unknown context kind!");
01647   }
01648 
01649   /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
01650   /// followed by a C++ direct initializer, e.g. "int x(1);".
01651   bool mayBeFollowedByCXXDirectInit() const {
01652     if (hasGroupingParens()) return false;
01653 
01654     if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
01655       return false;
01656 
01657     if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern &&
01658         Context != FileContext)
01659       return false;
01660 
01661     // Special names can't have direct initializers.
01662     if (Name.getKind() != UnqualifiedId::IK_Identifier)
01663       return false;
01664 
01665     switch (Context) {
01666     case FileContext:
01667     case BlockContext:
01668     case ForContext:
01669       return true;
01670 
01671     case ConditionContext:
01672       // This may not be followed by a direct initializer, but it can't be a
01673       // function declaration either, and we'd prefer to perform a tentative
01674       // parse in order to produce the right diagnostic.
01675       return true;
01676 
01677     case KNRTypeListContext:
01678     case MemberContext:
01679     case PrototypeContext:
01680     case ObjCParameterContext:
01681     case ObjCResultContext:
01682     case TemplateParamContext:
01683     case CXXCatchContext:
01684     case ObjCCatchContext:
01685     case TypeNameContext:
01686     case CXXNewContext:
01687     case AliasDeclContext:
01688     case AliasTemplateContext:
01689     case BlockLiteralContext:
01690     case LambdaExprContext:
01691     case TemplateTypeArgContext:
01692     case TrailingReturnContext:
01693       return false;
01694     }
01695     llvm_unreachable("unknown context kind!");
01696   }
01697 
01698   /// isPastIdentifier - Return true if we have parsed beyond the point where
01699   /// the
01700   bool isPastIdentifier() const { return Name.isValid(); }
01701 
01702   /// hasName - Whether this declarator has a name, which might be an
01703   /// identifier (accessible via getIdentifier()) or some kind of
01704   /// special C++ name (constructor, destructor, etc.).
01705   bool hasName() const { 
01706     return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier;
01707   }
01708 
01709   IdentifierInfo *getIdentifier() const { 
01710     if (Name.getKind() == UnqualifiedId::IK_Identifier)
01711       return Name.Identifier;
01712     
01713     return 0;
01714   }
01715   SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
01716 
01717   /// \brief Set the name of this declarator to be the given identifier.
01718   void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) {
01719     Name.setIdentifier(Id, IdLoc);
01720   }
01721   
01722   /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
01723   /// EndLoc, which should be the last token of the chunk.
01724   void AddTypeInfo(const DeclaratorChunk &TI,
01725                    ParsedAttributes &attrs,
01726                    SourceLocation EndLoc) {
01727     DeclTypeInfo.push_back(TI);
01728     DeclTypeInfo.back().getAttrListRef() = attrs.getList();
01729     getAttributePool().takeAllFrom(attrs.getPool());
01730 
01731     if (!EndLoc.isInvalid())
01732       SetRangeEnd(EndLoc);
01733   }
01734 
01735   /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator.
01736   void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
01737     DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
01738   }
01739 
01740   /// getNumTypeObjects() - Return the number of types applied to this
01741   /// declarator.
01742   unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
01743 
01744   /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
01745   /// closest to the identifier.
01746   const DeclaratorChunk &getTypeObject(unsigned i) const {
01747     assert(i < DeclTypeInfo.size() && "Invalid type chunk");
01748     return DeclTypeInfo[i];
01749   }
01750   DeclaratorChunk &getTypeObject(unsigned i) {
01751     assert(i < DeclTypeInfo.size() && "Invalid type chunk");
01752     return DeclTypeInfo[i];
01753   }
01754 
01755   void DropFirstTypeObject()
01756   {
01757     assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
01758     DeclTypeInfo.front().destroy();
01759     DeclTypeInfo.erase(DeclTypeInfo.begin());
01760   }
01761 
01762   /// isArrayOfUnknownBound - This method returns true if the declarator
01763   /// is a declarator for an array of unknown bound (looking through
01764   /// parentheses).
01765   bool isArrayOfUnknownBound() const {
01766     for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
01767       switch (DeclTypeInfo[i].Kind) {
01768       case DeclaratorChunk::Paren:
01769         continue;
01770       case DeclaratorChunk::Function:
01771       case DeclaratorChunk::Pointer:
01772       case DeclaratorChunk::Reference:
01773       case DeclaratorChunk::BlockPointer:
01774       case DeclaratorChunk::MemberPointer:
01775         return false;
01776       case DeclaratorChunk::Array:
01777         return !DeclTypeInfo[i].Arr.NumElts;
01778       }
01779       llvm_unreachable("Invalid type chunk");
01780     }
01781     return false;
01782   }
01783 
01784   /// isFunctionDeclarator - This method returns true if the declarator
01785   /// is a function declarator (looking through parentheses).
01786   /// If true is returned, then the reference type parameter idx is
01787   /// assigned with the index of the declaration chunk.
01788   bool isFunctionDeclarator(unsigned& idx) const {
01789     for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
01790       switch (DeclTypeInfo[i].Kind) {
01791       case DeclaratorChunk::Function:
01792         idx = i;
01793         return true;
01794       case DeclaratorChunk::Paren:
01795         continue;
01796       case DeclaratorChunk::Pointer:
01797       case DeclaratorChunk::Reference:
01798       case DeclaratorChunk::Array:
01799       case DeclaratorChunk::BlockPointer:
01800       case DeclaratorChunk::MemberPointer:
01801         return false;
01802       }
01803       llvm_unreachable("Invalid type chunk");
01804     }
01805     return false;
01806   }
01807 
01808   /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
01809   /// this method returns true if the identifier is a function declarator
01810   /// (looking through parentheses).
01811   bool isFunctionDeclarator() const {
01812     unsigned index;
01813     return isFunctionDeclarator(index);
01814   }
01815 
01816   /// getFunctionTypeInfo - Retrieves the function type info object
01817   /// (looking through parentheses).
01818   DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
01819     assert(isFunctionDeclarator() && "Not a function declarator!");
01820     unsigned index = 0;
01821     isFunctionDeclarator(index);
01822     return DeclTypeInfo[index].Fun;
01823   }
01824 
01825   /// getFunctionTypeInfo - Retrieves the function type info object
01826   /// (looking through parentheses).
01827   const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
01828     return const_cast<Declarator*>(this)->getFunctionTypeInfo();
01829   }
01830 
01831   /// \brief Determine whether the declaration that will be produced from 
01832   /// this declaration will be a function.
01833   /// 
01834   /// A declaration can declare a function even if the declarator itself
01835   /// isn't a function declarator, if the type specifier refers to a function
01836   /// type. This routine checks for both cases.
01837   bool isDeclarationOfFunction() const;
01838   
01839   /// takeAttributes - Takes attributes from the given parsed-attributes
01840   /// set and add them to this declarator.
01841   ///
01842   /// These examples both add 3 attributes to "var":
01843   ///  short int var __attribute__((aligned(16),common,deprecated));
01844   ///  short int x, __attribute__((aligned(16)) var
01845   ///                                 __attribute__((common,deprecated));
01846   ///
01847   /// Also extends the range of the declarator.
01848   void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) {
01849     Attrs.takeAllFrom(attrs);
01850 
01851     if (!lastLoc.isInvalid())
01852       SetRangeEnd(lastLoc);
01853   }
01854 
01855   const AttributeList *getAttributes() const { return Attrs.getList(); }
01856   AttributeList *getAttributes() { return Attrs.getList(); }
01857 
01858   AttributeList *&getAttrListRef() { return Attrs.getListRef(); }
01859 
01860   /// hasAttributes - do we contain any attributes?
01861   bool hasAttributes() const {
01862     if (getAttributes() || getDeclSpec().hasAttributes()) return true;
01863     for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
01864       if (getTypeObject(i).getAttrs())
01865         return true;
01866     return false;
01867   }
01868 
01869   void setAsmLabel(Expr *E) { AsmLabel = E; }
01870   Expr *getAsmLabel() const { return AsmLabel; }
01871 
01872   void setExtension(bool Val = true) { Extension = Val; }
01873   bool getExtension() const { return Extension; }
01874 
01875   void setInvalidType(bool Val = true) { InvalidType = Val; }
01876   bool isInvalidType() const {
01877     return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
01878   }
01879 
01880   void setGroupingParens(bool flag) { GroupingParens = flag; }
01881   bool hasGroupingParens() const { return GroupingParens; }
01882 
01883   bool isFirstDeclarator() const { return !CommaLoc.isValid(); }
01884   SourceLocation getCommaLoc() const { return CommaLoc; }
01885   void setCommaLoc(SourceLocation CL) { CommaLoc = CL; }
01886 
01887   bool hasEllipsis() const { return EllipsisLoc.isValid(); }
01888   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
01889   void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
01890 
01891   void setFunctionDefinitionKind(FunctionDefinitionKind Val) { 
01892     FunctionDefinition = Val; 
01893   }
01894   
01895   bool isFunctionDefinition() const {
01896     return getFunctionDefinitionKind() != FDK_Declaration;
01897   }
01898   
01899   FunctionDefinitionKind getFunctionDefinitionKind() const { 
01900     return (FunctionDefinitionKind)FunctionDefinition; 
01901   }
01902 
01903   void setRedeclaration(bool Val) { Redeclaration = Val; }
01904   bool isRedeclaration() const { return Redeclaration; }
01905 };
01906 
01907 /// FieldDeclarator - This little struct is used to capture information about
01908 /// structure field declarators, which is basically just a bitfield size.
01909 struct FieldDeclarator {
01910   Declarator D;
01911   Expr *BitfieldSize;
01912   explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) {
01913     BitfieldSize = 0;
01914   }
01915 };
01916 
01917 /// VirtSpecifiers - Represents a C++0x virt-specifier-seq.
01918 class VirtSpecifiers {
01919 public:
01920   enum Specifier {
01921     VS_None = 0,
01922     VS_Override = 1,
01923     VS_Final = 2
01924   };
01925 
01926   VirtSpecifiers() : Specifiers(0) { }
01927 
01928   bool SetSpecifier(Specifier VS, SourceLocation Loc,
01929                     const char *&PrevSpec);
01930 
01931   bool isOverrideSpecified() const { return Specifiers & VS_Override; }
01932   SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
01933 
01934   bool isFinalSpecified() const { return Specifiers & VS_Final; }
01935   SourceLocation getFinalLoc() const { return VS_finalLoc; }
01936 
01937   void clear() { Specifiers = 0; }
01938 
01939   static const char *getSpecifierName(Specifier VS);
01940 
01941   SourceLocation getLastLocation() const { return LastLocation; }
01942   
01943 private:
01944   unsigned Specifiers;
01945 
01946   SourceLocation VS_overrideLoc, VS_finalLoc;
01947   SourceLocation LastLocation;
01948 };
01949 
01950 /// LambdaCapture - An individual capture in a lambda introducer.
01951 struct LambdaCapture {
01952   LambdaCaptureKind Kind;
01953   SourceLocation Loc;
01954   IdentifierInfo* Id;
01955   SourceLocation EllipsisLoc;
01956   
01957   LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc,
01958                 IdentifierInfo* Id = 0,
01959                 SourceLocation EllipsisLoc = SourceLocation())
01960     : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc)
01961   {}
01962 };
01963 
01964 /// LambdaIntroducer - Represents a complete lambda introducer.
01965 struct LambdaIntroducer {
01966   SourceRange Range;
01967   SourceLocation DefaultLoc;
01968   LambdaCaptureDefault Default;
01969   llvm::SmallVector<LambdaCapture, 4> Captures;
01970 
01971   LambdaIntroducer()
01972     : Default(LCD_None) {}
01973 
01974   /// addCapture - Append a capture in a lambda introducer.
01975   void addCapture(LambdaCaptureKind Kind,
01976                   SourceLocation Loc,
01977                   IdentifierInfo* Id = 0, 
01978                   SourceLocation EllipsisLoc = SourceLocation()) {
01979     Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc));
01980   }
01981 
01982 };
01983 
01984 } // end namespace clang
01985 
01986 #endif