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