Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:59

0001 //===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// This file defines the classes used to store parsed information about
0011 /// declaration-specifiers and declarators.
0012 ///
0013 /// \verbatim
0014 ///   static const int volatile x, *y, *(*(*z)[10])(const void *x);
0015 ///   ------------------------- -  --  ---------------------------
0016 ///     declaration-specifiers  \  |   /
0017 ///                            declarators
0018 /// \endverbatim
0019 ///
0020 //===----------------------------------------------------------------------===//
0021 
0022 #ifndef LLVM_CLANG_SEMA_DECLSPEC_H
0023 #define LLVM_CLANG_SEMA_DECLSPEC_H
0024 
0025 #include "clang/AST/DeclCXX.h"
0026 #include "clang/AST/DeclObjCCommon.h"
0027 #include "clang/AST/NestedNameSpecifier.h"
0028 #include "clang/Basic/ExceptionSpecificationType.h"
0029 #include "clang/Basic/Lambda.h"
0030 #include "clang/Basic/OperatorKinds.h"
0031 #include "clang/Basic/Specifiers.h"
0032 #include "clang/Lex/Token.h"
0033 #include "clang/Sema/Ownership.h"
0034 #include "clang/Sema/ParsedAttr.h"
0035 #include "llvm/ADT/STLExtras.h"
0036 #include "llvm/ADT/SmallVector.h"
0037 #include "llvm/Support/Compiler.h"
0038 #include "llvm/Support/ErrorHandling.h"
0039 #include <optional>
0040 
0041 namespace clang {
0042   class ASTContext;
0043   class CXXRecordDecl;
0044   class TypeLoc;
0045   class LangOptions;
0046   class IdentifierInfo;
0047   class NamespaceAliasDecl;
0048   class NamespaceDecl;
0049   class ObjCDeclSpec;
0050   class Sema;
0051   class Declarator;
0052   struct TemplateIdAnnotation;
0053 
0054 /// Represents a C++ nested-name-specifier or a global scope specifier.
0055 ///
0056 /// These can be in 3 states:
0057 ///   1) Not present, identified by isEmpty()
0058 ///   2) Present, identified by isNotEmpty()
0059 ///      2.a) Valid, identified by isValid()
0060 ///      2.b) Invalid, identified by isInvalid().
0061 ///
0062 /// isSet() is deprecated because it mostly corresponded to "valid" but was
0063 /// often used as if it meant "present".
0064 ///
0065 /// The actual scope is described by getScopeRep().
0066 ///
0067 /// If the kind of getScopeRep() is TypeSpec then TemplateParamLists may be empty
0068 /// or contain the template parameter lists attached to the current declaration.
0069 /// Consider the following example:
0070 /// template <class T> void SomeType<T>::some_method() {}
0071 /// If CXXScopeSpec refers to SomeType<T> then TemplateParamLists will contain
0072 /// a single element referring to template <class T>.
0073 
0074 class CXXScopeSpec {
0075   SourceRange Range;
0076   NestedNameSpecifierLocBuilder Builder;
0077   ArrayRef<TemplateParameterList *> TemplateParamLists;
0078 
0079 public:
0080   SourceRange getRange() const { return Range; }
0081   void setRange(SourceRange R) { Range = R; }
0082   void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
0083   void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
0084   SourceLocation getBeginLoc() const { return Range.getBegin(); }
0085   SourceLocation getEndLoc() const { return Range.getEnd(); }
0086 
0087   void setTemplateParamLists(ArrayRef<TemplateParameterList *> L) {
0088     TemplateParamLists = L;
0089   }
0090   ArrayRef<TemplateParameterList *> getTemplateParamLists() const {
0091     return TemplateParamLists;
0092   }
0093 
0094   /// Retrieve the representation of the nested-name-specifier.
0095   NestedNameSpecifier *getScopeRep() const {
0096     return Builder.getRepresentation();
0097   }
0098 
0099   /// Extend the current nested-name-specifier by another
0100   /// nested-name-specifier component of the form 'type::'.
0101   ///
0102   /// \param Context The AST context in which this nested-name-specifier
0103   /// resides.
0104   ///
0105   /// \param TemplateKWLoc The location of the 'template' keyword, if present.
0106   ///
0107   /// \param TL The TypeLoc that describes the type preceding the '::'.
0108   ///
0109   /// \param ColonColonLoc The location of the trailing '::'.
0110   void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
0111               SourceLocation ColonColonLoc);
0112 
0113   /// Extend the current nested-name-specifier by another
0114   /// nested-name-specifier component of the form 'identifier::'.
0115   ///
0116   /// \param Context The AST context in which this nested-name-specifier
0117   /// resides.
0118   ///
0119   /// \param Identifier The identifier.
0120   ///
0121   /// \param IdentifierLoc The location of the identifier.
0122   ///
0123   /// \param ColonColonLoc The location of the trailing '::'.
0124   void Extend(ASTContext &Context, IdentifierInfo *Identifier,
0125               SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
0126 
0127   /// Extend the current nested-name-specifier by another
0128   /// nested-name-specifier component of the form 'namespace::'.
0129   ///
0130   /// \param Context The AST context in which this nested-name-specifier
0131   /// resides.
0132   ///
0133   /// \param Namespace The namespace.
0134   ///
0135   /// \param NamespaceLoc The location of the namespace name.
0136   ///
0137   /// \param ColonColonLoc The location of the trailing '::'.
0138   void Extend(ASTContext &Context, NamespaceDecl *Namespace,
0139               SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
0140 
0141   /// Extend the current nested-name-specifier by another
0142   /// nested-name-specifier component of the form 'namespace-alias::'.
0143   ///
0144   /// \param Context The AST context in which this nested-name-specifier
0145   /// resides.
0146   ///
0147   /// \param Alias The namespace alias.
0148   ///
0149   /// \param AliasLoc The location of the namespace alias
0150   /// name.
0151   ///
0152   /// \param ColonColonLoc The location of the trailing '::'.
0153   void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
0154               SourceLocation AliasLoc, SourceLocation ColonColonLoc);
0155 
0156   /// Turn this (empty) nested-name-specifier into the global
0157   /// nested-name-specifier '::'.
0158   void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
0159 
0160   /// Turns this (empty) nested-name-specifier into '__super'
0161   /// nested-name-specifier.
0162   ///
0163   /// \param Context The AST context in which this nested-name-specifier
0164   /// resides.
0165   ///
0166   /// \param RD The declaration of the class in which nested-name-specifier
0167   /// appeared.
0168   ///
0169   /// \param SuperLoc The location of the '__super' keyword.
0170   /// name.
0171   ///
0172   /// \param ColonColonLoc The location of the trailing '::'.
0173   void MakeSuper(ASTContext &Context, CXXRecordDecl *RD,
0174                  SourceLocation SuperLoc, SourceLocation ColonColonLoc);
0175 
0176   /// Make a new nested-name-specifier from incomplete source-location
0177   /// information.
0178   ///
0179   /// FIXME: This routine should be used very, very rarely, in cases where we
0180   /// need to synthesize a nested-name-specifier. Most code should instead use
0181   /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
0182   void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
0183                    SourceRange R);
0184 
0185   /// Adopt an existing nested-name-specifier (with source-range
0186   /// information).
0187   void Adopt(NestedNameSpecifierLoc Other);
0188 
0189   /// Retrieve a nested-name-specifier with location information, copied
0190   /// into the given AST context.
0191   ///
0192   /// \param Context The context into which this nested-name-specifier will be
0193   /// copied.
0194   NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
0195 
0196   /// Retrieve the location of the name in the last qualifier
0197   /// in this nested name specifier.
0198   ///
0199   /// For example, the location of \c bar
0200   /// in
0201   /// \verbatim
0202   ///   \::foo::bar<0>::
0203   ///           ^~~
0204   /// \endverbatim
0205   SourceLocation getLastQualifierNameLoc() const;
0206 
0207   /// No scope specifier.
0208   bool isEmpty() const { return Range.isInvalid() && getScopeRep() == nullptr; }
0209   /// A scope specifier is present, but may be valid or invalid.
0210   bool isNotEmpty() const { return !isEmpty(); }
0211 
0212   /// An error occurred during parsing of the scope specifier.
0213   bool isInvalid() const { return Range.isValid() && getScopeRep() == nullptr; }
0214   /// A scope specifier is present, and it refers to a real scope.
0215   bool isValid() const { return getScopeRep() != nullptr; }
0216 
0217   /// Indicate that this nested-name-specifier is invalid.
0218   void SetInvalid(SourceRange R) {
0219     assert(R.isValid() && "Must have a valid source range");
0220     if (Range.getBegin().isInvalid())
0221       Range.setBegin(R.getBegin());
0222     Range.setEnd(R.getEnd());
0223     Builder.Clear();
0224   }
0225 
0226   /// Deprecated.  Some call sites intend isNotEmpty() while others intend
0227   /// isValid().
0228   bool isSet() const { return getScopeRep() != nullptr; }
0229 
0230   void clear() {
0231     Range = SourceRange();
0232     Builder.Clear();
0233   }
0234 
0235   /// Retrieve the data associated with the source-location information.
0236   char *location_data() const { return Builder.getBuffer().first; }
0237 
0238   /// Retrieve the size of the data associated with source-location
0239   /// information.
0240   unsigned location_size() const { return Builder.getBuffer().second; }
0241 };
0242 
0243 /// Captures information about "declaration specifiers".
0244 ///
0245 /// "Declaration specifiers" encompasses storage-class-specifiers,
0246 /// type-specifiers, type-qualifiers, and function-specifiers.
0247 class DeclSpec {
0248 public:
0249   /// storage-class-specifier
0250   /// \note The order of these enumerators is important for diagnostics.
0251   enum SCS {
0252     SCS_unspecified = 0,
0253     SCS_typedef,
0254     SCS_extern,
0255     SCS_static,
0256     SCS_auto,
0257     SCS_register,
0258     SCS_private_extern,
0259     SCS_mutable
0260   };
0261 
0262   // Import thread storage class specifier enumeration and constants.
0263   // These can be combined with SCS_extern and SCS_static.
0264   typedef ThreadStorageClassSpecifier TSCS;
0265   static const TSCS TSCS_unspecified = clang::TSCS_unspecified;
0266   static const TSCS TSCS___thread = clang::TSCS___thread;
0267   static const TSCS TSCS_thread_local = clang::TSCS_thread_local;
0268   static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local;
0269 
0270   enum TSC {
0271     TSC_unspecified,
0272     TSC_imaginary, // Unsupported
0273     TSC_complex
0274   };
0275 
0276   // Import type specifier type enumeration and constants.
0277   typedef TypeSpecifierType TST;
0278   static const TST TST_unspecified = clang::TST_unspecified;
0279   static const TST TST_void = clang::TST_void;
0280   static const TST TST_char = clang::TST_char;
0281   static const TST TST_wchar = clang::TST_wchar;
0282   static const TST TST_char8 = clang::TST_char8;
0283   static const TST TST_char16 = clang::TST_char16;
0284   static const TST TST_char32 = clang::TST_char32;
0285   static const TST TST_int = clang::TST_int;
0286   static const TST TST_int128 = clang::TST_int128;
0287   static const TST TST_bitint = clang::TST_bitint;
0288   static const TST TST_half = clang::TST_half;
0289   static const TST TST_BFloat16 = clang::TST_BFloat16;
0290   static const TST TST_float = clang::TST_float;
0291   static const TST TST_double = clang::TST_double;
0292   static const TST TST_float16 = clang::TST_Float16;
0293   static const TST TST_accum = clang::TST_Accum;
0294   static const TST TST_fract = clang::TST_Fract;
0295   static const TST TST_float128 = clang::TST_float128;
0296   static const TST TST_ibm128 = clang::TST_ibm128;
0297   static const TST TST_bool = clang::TST_bool;
0298   static const TST TST_decimal32 = clang::TST_decimal32;
0299   static const TST TST_decimal64 = clang::TST_decimal64;
0300   static const TST TST_decimal128 = clang::TST_decimal128;
0301   static const TST TST_enum = clang::TST_enum;
0302   static const TST TST_union = clang::TST_union;
0303   static const TST TST_struct = clang::TST_struct;
0304   static const TST TST_interface = clang::TST_interface;
0305   static const TST TST_class = clang::TST_class;
0306   static const TST TST_typename = clang::TST_typename;
0307   static const TST TST_typeofType = clang::TST_typeofType;
0308   static const TST TST_typeofExpr = clang::TST_typeofExpr;
0309   static const TST TST_typeof_unqualType = clang::TST_typeof_unqualType;
0310   static const TST TST_typeof_unqualExpr = clang::TST_typeof_unqualExpr;
0311   static const TST TST_decltype = clang::TST_decltype;
0312   static const TST TST_decltype_auto = clang::TST_decltype_auto;
0313   static const TST TST_typename_pack_indexing =
0314       clang::TST_typename_pack_indexing;
0315 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait)                                     \
0316   static const TST TST_##Trait = clang::TST_##Trait;
0317 #include "clang/Basic/TransformTypeTraits.def"
0318   static const TST TST_auto = clang::TST_auto;
0319   static const TST TST_auto_type = clang::TST_auto_type;
0320   static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
0321   static const TST TST_atomic = clang::TST_atomic;
0322 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
0323   static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
0324 #include "clang/Basic/OpenCLImageTypes.def"
0325 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
0326   static const TST TST_##Name = clang::TST_##Name;
0327 #include "clang/Basic/HLSLIntangibleTypes.def"
0328   static const TST TST_error = clang::TST_error;
0329 
0330   // type-qualifiers
0331   enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
0332     TQ_unspecified = 0,
0333     TQ_const       = 1,
0334     TQ_restrict    = 2,
0335     TQ_volatile    = 4,
0336     TQ_unaligned   = 8,
0337     // This has no corresponding Qualifiers::TQ value, because it's not treated
0338     // as a qualifier in our type system.
0339     TQ_atomic      = 16
0340   };
0341 
0342   /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
0343   /// returned by getParsedSpecifiers.
0344   enum ParsedSpecifiers {
0345     PQ_None                  = 0,
0346     PQ_StorageClassSpecifier = 1,
0347     PQ_TypeSpecifier         = 2,
0348     PQ_TypeQualifier         = 4,
0349     PQ_FunctionSpecifier     = 8
0350     // FIXME: Attributes should be included here.
0351   };
0352 
0353   enum FriendSpecified : bool { No, Yes };
0354 
0355 private:
0356   // storage-class-specifier
0357   LLVM_PREFERRED_TYPE(SCS)
0358   unsigned StorageClassSpec : 3;
0359   LLVM_PREFERRED_TYPE(TSCS)
0360   unsigned ThreadStorageClassSpec : 2;
0361   LLVM_PREFERRED_TYPE(bool)
0362   unsigned SCS_extern_in_linkage_spec : 1;
0363 
0364   // type-specifier
0365   LLVM_PREFERRED_TYPE(TypeSpecifierWidth)
0366   unsigned TypeSpecWidth : 2;
0367   LLVM_PREFERRED_TYPE(TSC)
0368   unsigned TypeSpecComplex : 2;
0369   LLVM_PREFERRED_TYPE(TypeSpecifierSign)
0370   unsigned TypeSpecSign : 2;
0371   LLVM_PREFERRED_TYPE(TST)
0372   unsigned TypeSpecType : 7;
0373   LLVM_PREFERRED_TYPE(bool)
0374   unsigned TypeAltiVecVector : 1;
0375   LLVM_PREFERRED_TYPE(bool)
0376   unsigned TypeAltiVecPixel : 1;
0377   LLVM_PREFERRED_TYPE(bool)
0378   unsigned TypeAltiVecBool : 1;
0379   LLVM_PREFERRED_TYPE(bool)
0380   unsigned TypeSpecOwned : 1;
0381   LLVM_PREFERRED_TYPE(bool)
0382   unsigned TypeSpecPipe : 1;
0383   LLVM_PREFERRED_TYPE(bool)
0384   unsigned TypeSpecSat : 1;
0385   LLVM_PREFERRED_TYPE(bool)
0386   unsigned ConstrainedAuto : 1;
0387 
0388   // type-qualifiers
0389   LLVM_PREFERRED_TYPE(TQ)
0390   unsigned TypeQualifiers : 5;  // Bitwise OR of TQ.
0391 
0392   // function-specifier
0393   LLVM_PREFERRED_TYPE(bool)
0394   unsigned FS_inline_specified : 1;
0395   LLVM_PREFERRED_TYPE(bool)
0396   unsigned FS_forceinline_specified: 1;
0397   LLVM_PREFERRED_TYPE(bool)
0398   unsigned FS_virtual_specified : 1;
0399   LLVM_PREFERRED_TYPE(bool)
0400   unsigned FS_noreturn_specified : 1;
0401 
0402   // friend-specifier
0403   LLVM_PREFERRED_TYPE(bool)
0404   unsigned FriendSpecifiedFirst : 1;
0405 
0406   // constexpr-specifier
0407   LLVM_PREFERRED_TYPE(ConstexprSpecKind)
0408   unsigned ConstexprSpecifier : 2;
0409 
0410   union {
0411     UnionParsedType TypeRep;
0412     Decl *DeclRep;
0413     Expr *ExprRep;
0414     TemplateIdAnnotation *TemplateIdRep;
0415   };
0416   Expr *PackIndexingExpr = nullptr;
0417 
0418   /// ExplicitSpecifier - Store information about explicit spicifer.
0419   ExplicitSpecifier FS_explicit_specifier;
0420 
0421   // attributes.
0422   ParsedAttributes Attrs;
0423 
0424   // Scope specifier for the type spec, if applicable.
0425   CXXScopeSpec TypeScope;
0426 
0427   // SourceLocation info.  These are null if the item wasn't specified or if
0428   // the setting was synthesized.
0429   SourceRange Range;
0430 
0431   SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
0432   SourceRange TSWRange;
0433   SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc, EllipsisLoc;
0434   /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
0435   /// typename, then this is the location of the named type (if present);
0436   /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
0437   /// TSTNameLoc provides source range info for tag types.
0438   SourceLocation TSTNameLoc;
0439   SourceRange TypeofParensRange;
0440   SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
0441       TQ_unalignedLoc;
0442   SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;
0443   SourceLocation FS_explicitCloseParenLoc;
0444   SourceLocation FS_forceinlineLoc;
0445   SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
0446   SourceLocation TQ_pipeLoc;
0447 
0448   WrittenBuiltinSpecs writtenBS;
0449   void SaveWrittenBuiltinSpecs();
0450 
0451   ObjCDeclSpec *ObjCQualifiers;
0452 
0453   static bool isTypeRep(TST T) {
0454     return T == TST_atomic || T == TST_typename || T == TST_typeofType ||
0455            T == TST_typeof_unqualType || isTransformTypeTrait(T) ||
0456            T == TST_typename_pack_indexing;
0457   }
0458   static bool isExprRep(TST T) {
0459     return T == TST_typeofExpr || T == TST_typeof_unqualExpr ||
0460            T == TST_decltype || T == TST_bitint;
0461   }
0462   static bool isTemplateIdRep(TST T) {
0463     return (T == TST_auto || T == TST_decltype_auto);
0464   }
0465 
0466   DeclSpec(const DeclSpec &) = delete;
0467   void operator=(const DeclSpec &) = delete;
0468 public:
0469   static bool isDeclRep(TST T) {
0470     return (T == TST_enum || T == TST_struct ||
0471             T == TST_interface || T == TST_union ||
0472             T == TST_class);
0473   }
0474   static bool isTransformTypeTrait(TST T) {
0475     constexpr std::array<TST, 16> Traits = {
0476 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait,
0477 #include "clang/Basic/TransformTypeTraits.def"
0478     };
0479 
0480     return T >= Traits.front() && T <= Traits.back();
0481   }
0482 
0483   DeclSpec(AttributeFactory &attrFactory)
0484       : StorageClassSpec(SCS_unspecified),
0485         ThreadStorageClassSpec(TSCS_unspecified),
0486         SCS_extern_in_linkage_spec(false),
0487         TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)),
0488         TypeSpecComplex(TSC_unspecified),
0489         TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)),
0490         TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
0491         TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
0492         TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false),
0493         TypeQualifiers(TQ_unspecified), FS_inline_specified(false),
0494         FS_forceinline_specified(false), FS_virtual_specified(false),
0495         FS_noreturn_specified(false), FriendSpecifiedFirst(false),
0496         ConstexprSpecifier(
0497             static_cast<unsigned>(ConstexprSpecKind::Unspecified)),
0498         Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
0499 
0500   // storage-class-specifier
0501   SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
0502   TSCS getThreadStorageClassSpec() const {
0503     return (TSCS)ThreadStorageClassSpec;
0504   }
0505   bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
0506   void setExternInLinkageSpec(bool Value) {
0507     SCS_extern_in_linkage_spec = Value;
0508   }
0509 
0510   SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
0511   SourceLocation getThreadStorageClassSpecLoc() const {
0512     return ThreadStorageClassSpecLoc;
0513   }
0514 
0515   void ClearStorageClassSpecs() {
0516     StorageClassSpec           = DeclSpec::SCS_unspecified;
0517     ThreadStorageClassSpec     = DeclSpec::TSCS_unspecified;
0518     SCS_extern_in_linkage_spec = false;
0519     StorageClassSpecLoc        = SourceLocation();
0520     ThreadStorageClassSpecLoc  = SourceLocation();
0521   }
0522 
0523   void ClearTypeSpecType() {
0524     TypeSpecType = DeclSpec::TST_unspecified;
0525     TypeSpecOwned = false;
0526     TSTLoc = SourceLocation();
0527   }
0528 
0529   // type-specifier
0530   TypeSpecifierWidth getTypeSpecWidth() const {
0531     return static_cast<TypeSpecifierWidth>(TypeSpecWidth);
0532   }
0533   TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
0534   TypeSpecifierSign getTypeSpecSign() const {
0535     return static_cast<TypeSpecifierSign>(TypeSpecSign);
0536   }
0537   TST getTypeSpecType() const { return (TST)TypeSpecType; }
0538   bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
0539   bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
0540   bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
0541   bool isTypeSpecOwned() const { return TypeSpecOwned; }
0542   bool isTypeRep() const { return isTypeRep((TST) TypeSpecType); }
0543   bool isTypeSpecPipe() const { return TypeSpecPipe; }
0544   bool isTypeSpecSat() const { return TypeSpecSat; }
0545   bool isConstrainedAuto() const { return ConstrainedAuto; }
0546 
0547   ParsedType getRepAsType() const {
0548     assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
0549     return TypeRep;
0550   }
0551   Decl *getRepAsDecl() const {
0552     assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
0553     return DeclRep;
0554   }
0555   Expr *getRepAsExpr() const {
0556     assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
0557     return ExprRep;
0558   }
0559 
0560   Expr *getPackIndexingExpr() const {
0561     assert(TypeSpecType == TST_typename_pack_indexing &&
0562            "DeclSpec is not a pack indexing expr");
0563     return PackIndexingExpr;
0564   }
0565 
0566   TemplateIdAnnotation *getRepAsTemplateId() const {
0567     assert(isTemplateIdRep((TST) TypeSpecType) &&
0568            "DeclSpec does not store a template id");
0569     return TemplateIdRep;
0570   }
0571   CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
0572   const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
0573 
0574   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
0575   SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
0576   SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
0577 
0578   SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
0579   SourceRange getTypeSpecWidthRange() const { return TSWRange; }
0580   SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
0581   SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
0582   SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
0583   SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
0584   SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
0585 
0586   SourceLocation getTypeSpecTypeNameLoc() const {
0587     assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) ||
0588            isExprRep((TST)TypeSpecType));
0589     return TSTNameLoc;
0590   }
0591 
0592   SourceRange getTypeofParensRange() const { return TypeofParensRange; }
0593   void setTypeArgumentRange(SourceRange range) { TypeofParensRange = range; }
0594 
0595   bool hasAutoTypeSpec() const {
0596     return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type ||
0597             TypeSpecType == TST_decltype_auto);
0598   }
0599 
0600   bool hasTagDefinition() const;
0601 
0602   /// Turn a type-specifier-type into a string like "_Bool" or "union".
0603   static const char *getSpecifierName(DeclSpec::TST T,
0604                                       const PrintingPolicy &Policy);
0605   static const char *getSpecifierName(DeclSpec::TQ Q);
0606   static const char *getSpecifierName(TypeSpecifierSign S);
0607   static const char *getSpecifierName(DeclSpec::TSC C);
0608   static const char *getSpecifierName(TypeSpecifierWidth W);
0609   static const char *getSpecifierName(DeclSpec::SCS S);
0610   static const char *getSpecifierName(DeclSpec::TSCS S);
0611   static const char *getSpecifierName(ConstexprSpecKind C);
0612 
0613   // type-qualifiers
0614 
0615   /// getTypeQualifiers - Return a set of TQs.
0616   unsigned getTypeQualifiers() const { return TypeQualifiers; }
0617   SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
0618   SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
0619   SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
0620   SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
0621   SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
0622   SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
0623   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
0624 
0625   /// Clear out all of the type qualifiers.
0626   void ClearTypeQualifiers() {
0627     TypeQualifiers = 0;
0628     TQ_constLoc = SourceLocation();
0629     TQ_restrictLoc = SourceLocation();
0630     TQ_volatileLoc = SourceLocation();
0631     TQ_atomicLoc = SourceLocation();
0632     TQ_unalignedLoc = SourceLocation();
0633     TQ_pipeLoc = SourceLocation();
0634   }
0635 
0636   // function-specifier
0637   bool isInlineSpecified() const {
0638     return FS_inline_specified | FS_forceinline_specified;
0639   }
0640   SourceLocation getInlineSpecLoc() const {
0641     return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc;
0642   }
0643 
0644   ExplicitSpecifier getExplicitSpecifier() const {
0645     return FS_explicit_specifier;
0646   }
0647 
0648   bool isVirtualSpecified() const { return FS_virtual_specified; }
0649   SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
0650 
0651   bool hasExplicitSpecifier() const {
0652     return FS_explicit_specifier.isSpecified();
0653   }
0654   SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
0655   SourceRange getExplicitSpecRange() const {
0656     return FS_explicit_specifier.getExpr()
0657                ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc)
0658                : SourceRange(FS_explicitLoc);
0659   }
0660 
0661   bool isNoreturnSpecified() const { return FS_noreturn_specified; }
0662   SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; }
0663 
0664   void ClearFunctionSpecs() {
0665     FS_inline_specified = false;
0666     FS_inlineLoc = SourceLocation();
0667     FS_forceinline_specified = false;
0668     FS_forceinlineLoc = SourceLocation();
0669     FS_virtual_specified = false;
0670     FS_virtualLoc = SourceLocation();
0671     FS_explicit_specifier = ExplicitSpecifier();
0672     FS_explicitLoc = SourceLocation();
0673     FS_explicitCloseParenLoc = SourceLocation();
0674     FS_noreturn_specified = false;
0675     FS_noreturnLoc = SourceLocation();
0676   }
0677 
0678   /// This method calls the passed in handler on each CVRU qual being
0679   /// set.
0680   /// Handle - a handler to be invoked.
0681   void forEachCVRUQualifier(
0682       llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
0683 
0684   /// This method calls the passed in handler on each qual being
0685   /// set.
0686   /// Handle - a handler to be invoked.
0687   void forEachQualifier(
0688       llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
0689 
0690   /// Return true if any type-specifier has been found.
0691   bool hasTypeSpecifier() const {
0692     return getTypeSpecType() != DeclSpec::TST_unspecified ||
0693            getTypeSpecWidth() != TypeSpecifierWidth::Unspecified ||
0694            getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
0695            getTypeSpecSign() != TypeSpecifierSign::Unspecified;
0696   }
0697 
0698   /// Return a bitmask of which flavors of specifiers this
0699   /// DeclSpec includes.
0700   unsigned getParsedSpecifiers() const;
0701 
0702   /// isEmpty - Return true if this declaration specifier is completely empty:
0703   /// no tokens were parsed in the production of it.
0704   bool isEmpty() const {
0705     return getParsedSpecifiers() == DeclSpec::PQ_None;
0706   }
0707 
0708   void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
0709   void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
0710 
0711   /// These methods set the specified attribute of the DeclSpec and
0712   /// return false if there was no error.  If an error occurs (for
0713   /// example, if we tried to set "auto" on a spec with "extern"
0714   /// already set), they return true and set PrevSpec and DiagID
0715   /// such that
0716   ///   Diag(Loc, DiagID) << PrevSpec;
0717   /// will yield a useful result.
0718   ///
0719   /// TODO: use a more general approach that still allows these
0720   /// diagnostics to be ignored when desired.
0721   bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
0722                            const char *&PrevSpec, unsigned &DiagID,
0723                            const PrintingPolicy &Policy);
0724   bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
0725                                  const char *&PrevSpec, unsigned &DiagID);
0726   bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc,
0727                         const char *&PrevSpec, unsigned &DiagID,
0728                         const PrintingPolicy &Policy);
0729   bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
0730                           unsigned &DiagID);
0731   bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc,
0732                        const char *&PrevSpec, unsigned &DiagID);
0733   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
0734                        unsigned &DiagID, const PrintingPolicy &Policy);
0735   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
0736                        unsigned &DiagID, ParsedType Rep,
0737                        const PrintingPolicy &Policy);
0738   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
0739                        unsigned &DiagID, TypeResult Rep,
0740                        const PrintingPolicy &Policy) {
0741     if (Rep.isInvalid())
0742       return SetTypeSpecError();
0743     return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep.get(), Policy);
0744   }
0745   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
0746                        unsigned &DiagID, Decl *Rep, bool Owned,
0747                        const PrintingPolicy &Policy);
0748   bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
0749                        SourceLocation TagNameLoc, const char *&PrevSpec,
0750                        unsigned &DiagID, ParsedType Rep,
0751                        const PrintingPolicy &Policy);
0752   bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
0753                        SourceLocation TagNameLoc, const char *&PrevSpec,
0754                        unsigned &DiagID, Decl *Rep, bool Owned,
0755                        const PrintingPolicy &Policy);
0756   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
0757                        unsigned &DiagID, TemplateIdAnnotation *Rep,
0758                        const PrintingPolicy &Policy);
0759 
0760   bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
0761                        unsigned &DiagID, Expr *Rep,
0762                        const PrintingPolicy &policy);
0763   bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
0764                        const char *&PrevSpec, unsigned &DiagID,
0765                        const PrintingPolicy &Policy);
0766   bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
0767                        const char *&PrevSpec, unsigned &DiagID,
0768                        const PrintingPolicy &Policy);
0769   bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
0770                        const char *&PrevSpec, unsigned &DiagID,
0771                        const PrintingPolicy &Policy);
0772   bool SetTypePipe(bool isPipe, SourceLocation Loc,
0773                        const char *&PrevSpec, unsigned &DiagID,
0774                        const PrintingPolicy &Policy);
0775   bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth,
0776                      const char *&PrevSpec, unsigned &DiagID,
0777                      const PrintingPolicy &Policy);
0778   bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
0779                       unsigned &DiagID);
0780 
0781   void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack);
0782 
0783   bool SetTypeSpecError();
0784   void UpdateDeclRep(Decl *Rep) {
0785     assert(isDeclRep((TST) TypeSpecType));
0786     DeclRep = Rep;
0787   }
0788   void UpdateTypeRep(ParsedType Rep) {
0789     assert(isTypeRep((TST) TypeSpecType));
0790     TypeRep = Rep;
0791   }
0792   void UpdateExprRep(Expr *Rep) {
0793     assert(isExprRep((TST) TypeSpecType));
0794     ExprRep = Rep;
0795   }
0796 
0797   bool SetTypeQual(TQ T, SourceLocation Loc);
0798 
0799   bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
0800                    unsigned &DiagID, const LangOptions &Lang);
0801 
0802   bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
0803                              unsigned &DiagID);
0804   bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
0805                                   unsigned &DiagID);
0806   bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
0807                               unsigned &DiagID);
0808   bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
0809                                unsigned &DiagID, ExplicitSpecifier ExplicitSpec,
0810                                SourceLocation CloseParenLoc);
0811   bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec,
0812                                unsigned &DiagID);
0813 
0814   bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
0815                      unsigned &DiagID);
0816   bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
0817                             unsigned &DiagID);
0818   bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc,
0819                         const char *&PrevSpec, unsigned &DiagID);
0820 
0821   FriendSpecified isFriendSpecified() const {
0822     return static_cast<FriendSpecified>(FriendLoc.isValid());
0823   }
0824 
0825   bool isFriendSpecifiedFirst() const { return FriendSpecifiedFirst; }
0826 
0827   SourceLocation getFriendSpecLoc() const { return FriendLoc; }
0828 
0829   bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
0830   SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
0831 
0832   ConstexprSpecKind getConstexprSpecifier() const {
0833     return ConstexprSpecKind(ConstexprSpecifier);
0834   }
0835 
0836   SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
0837   bool hasConstexprSpecifier() const {
0838     return getConstexprSpecifier() != ConstexprSpecKind::Unspecified;
0839   }
0840 
0841   void ClearConstexprSpec() {
0842     ConstexprSpecifier = static_cast<unsigned>(ConstexprSpecKind::Unspecified);
0843     ConstexprLoc = SourceLocation();
0844   }
0845 
0846   AttributePool &getAttributePool() const {
0847     return Attrs.getPool();
0848   }
0849 
0850   /// Concatenates two attribute lists.
0851   ///
0852   /// The GCC attribute syntax allows for the following:
0853   ///
0854   /// \code
0855   /// short __attribute__(( unused, deprecated ))
0856   /// int __attribute__(( may_alias, aligned(16) )) var;
0857   /// \endcode
0858   ///
0859   /// This declares 4 attributes using 2 lists. The following syntax is
0860   /// also allowed and equivalent to the previous declaration.
0861   ///
0862   /// \code
0863   /// short __attribute__((unused)) __attribute__((deprecated))
0864   /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
0865   /// \endcode
0866   ///
0867   void addAttributes(const ParsedAttributesView &AL) {
0868     Attrs.addAll(AL.begin(), AL.end());
0869   }
0870 
0871   bool hasAttributes() const { return !Attrs.empty(); }
0872 
0873   ParsedAttributes &getAttributes() { return Attrs; }
0874   const ParsedAttributes &getAttributes() const { return Attrs; }
0875 
0876   void takeAttributesFrom(ParsedAttributes &attrs) {
0877     Attrs.takeAllFrom(attrs);
0878   }
0879 
0880   /// Finish - This does final analysis of the declspec, issuing diagnostics for
0881   /// things like "_Complex" (lacking an FP type).  After calling this method,
0882   /// DeclSpec is guaranteed self-consistent, even if an error occurred.
0883   void Finish(Sema &S, const PrintingPolicy &Policy);
0884 
0885   const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
0886     return writtenBS;
0887   }
0888 
0889   ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
0890   void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
0891 
0892   /// Checks if this DeclSpec can stand alone, without a Declarator.
0893   ///
0894   /// Only tag declspecs can stand alone.
0895   bool isMissingDeclaratorOk();
0896 };
0897 
0898 /// Captures information about "declaration specifiers" specific to
0899 /// Objective-C.
0900 class ObjCDeclSpec {
0901 public:
0902   /// ObjCDeclQualifier - Qualifier used on types in method
0903   /// declarations.  Not all combinations are sensible.  Parameters
0904   /// can be one of { in, out, inout } with one of { bycopy, byref }.
0905   /// Returns can either be { oneway } or not.
0906   ///
0907   /// This should be kept in sync with Decl::ObjCDeclQualifier.
0908   enum ObjCDeclQualifier {
0909     DQ_None = 0x0,
0910     DQ_In = 0x1,
0911     DQ_Inout = 0x2,
0912     DQ_Out = 0x4,
0913     DQ_Bycopy = 0x8,
0914     DQ_Byref = 0x10,
0915     DQ_Oneway = 0x20,
0916     DQ_CSNullability = 0x40
0917   };
0918 
0919   ObjCDeclSpec()
0920       : objcDeclQualifier(DQ_None),
0921         PropertyAttributes(ObjCPropertyAttribute::kind_noattr), Nullability(0),
0922         GetterName(nullptr), SetterName(nullptr) {}
0923 
0924   ObjCDeclQualifier getObjCDeclQualifier() const {
0925     return (ObjCDeclQualifier)objcDeclQualifier;
0926   }
0927   void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
0928     objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
0929   }
0930   void clearObjCDeclQualifier(ObjCDeclQualifier DQVal) {
0931     objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier & ~DQVal);
0932   }
0933 
0934   ObjCPropertyAttribute::Kind getPropertyAttributes() const {
0935     return ObjCPropertyAttribute::Kind(PropertyAttributes);
0936   }
0937   void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) {
0938     PropertyAttributes =
0939         (ObjCPropertyAttribute::Kind)(PropertyAttributes | PRVal);
0940   }
0941 
0942   NullabilityKind getNullability() const {
0943     assert(
0944         ((getObjCDeclQualifier() & DQ_CSNullability) ||
0945          (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
0946         "Objective-C declspec doesn't have nullability");
0947     return static_cast<NullabilityKind>(Nullability);
0948   }
0949 
0950   SourceLocation getNullabilityLoc() const {
0951     assert(
0952         ((getObjCDeclQualifier() & DQ_CSNullability) ||
0953          (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
0954         "Objective-C declspec doesn't have nullability");
0955     return NullabilityLoc;
0956   }
0957 
0958   void setNullability(SourceLocation loc, NullabilityKind kind) {
0959     assert(
0960         ((getObjCDeclQualifier() & DQ_CSNullability) ||
0961          (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
0962         "Set the nullability declspec or property attribute first");
0963     Nullability = static_cast<unsigned>(kind);
0964     NullabilityLoc = loc;
0965   }
0966 
0967   const IdentifierInfo *getGetterName() const { return GetterName; }
0968   IdentifierInfo *getGetterName() { return GetterName; }
0969   SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
0970   void setGetterName(IdentifierInfo *name, SourceLocation loc) {
0971     GetterName = name;
0972     GetterNameLoc = loc;
0973   }
0974 
0975   const IdentifierInfo *getSetterName() const { return SetterName; }
0976   IdentifierInfo *getSetterName() { return SetterName; }
0977   SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
0978   void setSetterName(IdentifierInfo *name, SourceLocation loc) {
0979     SetterName = name;
0980     SetterNameLoc = loc;
0981   }
0982 
0983 private:
0984   // FIXME: These two are unrelated and mutually exclusive. So perhaps
0985   // we can put them in a union to reflect their mutual exclusivity
0986   // (space saving is negligible).
0987   unsigned objcDeclQualifier : 7;
0988 
0989   // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttribute::Kind
0990   unsigned PropertyAttributes : NumObjCPropertyAttrsBits;
0991 
0992   unsigned Nullability : 2;
0993 
0994   SourceLocation NullabilityLoc;
0995 
0996   IdentifierInfo *GetterName;    // getter name or NULL if no getter
0997   IdentifierInfo *SetterName;    // setter name or NULL if no setter
0998   SourceLocation GetterNameLoc; // location of the getter attribute's value
0999   SourceLocation SetterNameLoc; // location of the setter attribute's value
1000 
1001 };
1002 
1003 /// Describes the kind of unqualified-id parsed.
1004 enum class UnqualifiedIdKind {
1005   /// An identifier.
1006   IK_Identifier,
1007   /// An overloaded operator name, e.g., operator+.
1008   IK_OperatorFunctionId,
1009   /// A conversion function name, e.g., operator int.
1010   IK_ConversionFunctionId,
1011   /// A user-defined literal name, e.g., operator "" _i.
1012   IK_LiteralOperatorId,
1013   /// A constructor name.
1014   IK_ConstructorName,
1015   /// A constructor named via a template-id.
1016   IK_ConstructorTemplateId,
1017   /// A destructor name.
1018   IK_DestructorName,
1019   /// A template-id, e.g., f<int>.
1020   IK_TemplateId,
1021   /// An implicit 'self' parameter
1022   IK_ImplicitSelfParam,
1023   /// A deduction-guide name (a template-name)
1024   IK_DeductionGuideName
1025 };
1026 
1027 /// Represents a C++ unqualified-id that has been parsed.
1028 class UnqualifiedId {
1029 private:
1030   UnqualifiedId(const UnqualifiedId &Other) = delete;
1031   const UnqualifiedId &operator=(const UnqualifiedId &) = delete;
1032 
1033   /// Describes the kind of unqualified-id parsed.
1034   UnqualifiedIdKind Kind;
1035 
1036 public:
1037   struct OFI {
1038     /// The kind of overloaded operator.
1039     OverloadedOperatorKind Operator;
1040 
1041     /// The source locations of the individual tokens that name
1042     /// the operator, e.g., the "new", "[", and "]" tokens in
1043     /// operator new [].
1044     ///
1045     /// Different operators have different numbers of tokens in their name,
1046     /// up to three. Any remaining source locations in this array will be
1047     /// set to an invalid value for operators with fewer than three tokens.
1048     SourceLocation SymbolLocations[3];
1049   };
1050 
1051   /// Anonymous union that holds extra data associated with the
1052   /// parsed unqualified-id.
1053   union {
1054     /// When Kind == IK_Identifier, the parsed identifier, or when
1055     /// Kind == IK_UserLiteralId, the identifier suffix.
1056     const IdentifierInfo *Identifier;
1057 
1058     /// When Kind == IK_OperatorFunctionId, the overloaded operator
1059     /// that we parsed.
1060     struct OFI OperatorFunctionId;
1061 
1062     /// When Kind == IK_ConversionFunctionId, the type that the
1063     /// conversion function names.
1064     UnionParsedType ConversionFunctionId;
1065 
1066     /// When Kind == IK_ConstructorName, the class-name of the type
1067     /// whose constructor is being referenced.
1068     UnionParsedType ConstructorName;
1069 
1070     /// When Kind == IK_DestructorName, the type referred to by the
1071     /// class-name.
1072     UnionParsedType DestructorName;
1073 
1074     /// When Kind == IK_DeductionGuideName, the parsed template-name.
1075     UnionParsedTemplateTy TemplateName;
1076 
1077     /// When Kind == IK_TemplateId or IK_ConstructorTemplateId,
1078     /// the template-id annotation that contains the template name and
1079     /// template arguments.
1080     TemplateIdAnnotation *TemplateId;
1081   };
1082 
1083   /// The location of the first token that describes this unqualified-id,
1084   /// which will be the location of the identifier, "operator" keyword,
1085   /// tilde (for a destructor), or the template name of a template-id.
1086   SourceLocation StartLocation;
1087 
1088   /// The location of the last token that describes this unqualified-id.
1089   SourceLocation EndLocation;
1090 
1091   UnqualifiedId()
1092       : Kind(UnqualifiedIdKind::IK_Identifier), Identifier(nullptr) {}
1093 
1094   /// Clear out this unqualified-id, setting it to default (invalid)
1095   /// state.
1096   void clear() {
1097     Kind = UnqualifiedIdKind::IK_Identifier;
1098     Identifier = nullptr;
1099     StartLocation = SourceLocation();
1100     EndLocation = SourceLocation();
1101   }
1102 
1103   /// Determine whether this unqualified-id refers to a valid name.
1104   bool isValid() const { return StartLocation.isValid(); }
1105 
1106   /// Determine whether this unqualified-id refers to an invalid name.
1107   bool isInvalid() const { return !isValid(); }
1108 
1109   /// Determine what kind of name we have.
1110   UnqualifiedIdKind getKind() const { return Kind; }
1111 
1112   /// Specify that this unqualified-id was parsed as an identifier.
1113   ///
1114   /// \param Id the parsed identifier.
1115   /// \param IdLoc the location of the parsed identifier.
1116   void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
1117     Kind = UnqualifiedIdKind::IK_Identifier;
1118     Identifier = Id;
1119     StartLocation = EndLocation = IdLoc;
1120   }
1121 
1122   /// Specify that this unqualified-id was parsed as an
1123   /// operator-function-id.
1124   ///
1125   /// \param OperatorLoc the location of the 'operator' keyword.
1126   ///
1127   /// \param Op the overloaded operator.
1128   ///
1129   /// \param SymbolLocations the locations of the individual operator symbols
1130   /// in the operator.
1131   void setOperatorFunctionId(SourceLocation OperatorLoc,
1132                              OverloadedOperatorKind Op,
1133                              SourceLocation SymbolLocations[3]);
1134 
1135   /// Specify that this unqualified-id was parsed as a
1136   /// conversion-function-id.
1137   ///
1138   /// \param OperatorLoc the location of the 'operator' keyword.
1139   ///
1140   /// \param Ty the type to which this conversion function is converting.
1141   ///
1142   /// \param EndLoc the location of the last token that makes up the type name.
1143   void setConversionFunctionId(SourceLocation OperatorLoc,
1144                                ParsedType Ty,
1145                                SourceLocation EndLoc) {
1146     Kind = UnqualifiedIdKind::IK_ConversionFunctionId;
1147     StartLocation = OperatorLoc;
1148     EndLocation = EndLoc;
1149     ConversionFunctionId = Ty;
1150   }
1151 
1152   /// Specific that this unqualified-id was parsed as a
1153   /// literal-operator-id.
1154   ///
1155   /// \param Id the parsed identifier.
1156   ///
1157   /// \param OpLoc the location of the 'operator' keyword.
1158   ///
1159   /// \param IdLoc the location of the identifier.
1160   void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
1161                             SourceLocation IdLoc) {
1162     Kind = UnqualifiedIdKind::IK_LiteralOperatorId;
1163     Identifier = Id;
1164     StartLocation = OpLoc;
1165     EndLocation = IdLoc;
1166   }
1167 
1168   /// Specify that this unqualified-id was parsed as a constructor name.
1169   ///
1170   /// \param ClassType the class type referred to by the constructor name.
1171   ///
1172   /// \param ClassNameLoc the location of the class name.
1173   ///
1174   /// \param EndLoc the location of the last token that makes up the type name.
1175   void setConstructorName(ParsedType ClassType,
1176                           SourceLocation ClassNameLoc,
1177                           SourceLocation EndLoc) {
1178     Kind = UnqualifiedIdKind::IK_ConstructorName;
1179     StartLocation = ClassNameLoc;
1180     EndLocation = EndLoc;
1181     ConstructorName = ClassType;
1182   }
1183 
1184   /// Specify that this unqualified-id was parsed as a
1185   /// template-id that names a constructor.
1186   ///
1187   /// \param TemplateId the template-id annotation that describes the parsed
1188   /// template-id. This UnqualifiedId instance will take ownership of the
1189   /// \p TemplateId and will free it on destruction.
1190   void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
1191 
1192   /// Specify that this unqualified-id was parsed as a destructor name.
1193   ///
1194   /// \param TildeLoc the location of the '~' that introduces the destructor
1195   /// name.
1196   ///
1197   /// \param ClassType the name of the class referred to by the destructor name.
1198   void setDestructorName(SourceLocation TildeLoc,
1199                          ParsedType ClassType,
1200                          SourceLocation EndLoc) {
1201     Kind = UnqualifiedIdKind::IK_DestructorName;
1202     StartLocation = TildeLoc;
1203     EndLocation = EndLoc;
1204     DestructorName = ClassType;
1205   }
1206 
1207   /// Specify that this unqualified-id was parsed as a template-id.
1208   ///
1209   /// \param TemplateId the template-id annotation that describes the parsed
1210   /// template-id. This UnqualifiedId instance will take ownership of the
1211   /// \p TemplateId and will free it on destruction.
1212   void setTemplateId(TemplateIdAnnotation *TemplateId);
1213 
1214   /// Specify that this unqualified-id was parsed as a template-name for
1215   /// a deduction-guide.
1216   ///
1217   /// \param Template The parsed template-name.
1218   /// \param TemplateLoc The location of the parsed template-name.
1219   void setDeductionGuideName(ParsedTemplateTy Template,
1220                              SourceLocation TemplateLoc) {
1221     Kind = UnqualifiedIdKind::IK_DeductionGuideName;
1222     TemplateName = Template;
1223     StartLocation = EndLocation = TemplateLoc;
1224   }
1225 
1226   /// Specify that this unqualified-id is an implicit 'self'
1227   /// parameter.
1228   ///
1229   /// \param Id the identifier.
1230   void setImplicitSelfParam(const IdentifierInfo *Id) {
1231     Kind = UnqualifiedIdKind::IK_ImplicitSelfParam;
1232     Identifier = Id;
1233     StartLocation = EndLocation = SourceLocation();
1234   }
1235 
1236   /// Return the source range that covers this unqualified-id.
1237   SourceRange getSourceRange() const LLVM_READONLY {
1238     return SourceRange(StartLocation, EndLocation);
1239   }
1240   SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; }
1241   SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; }
1242 };
1243 
1244 /// A set of tokens that has been cached for later parsing.
1245 typedef SmallVector<Token, 4> CachedTokens;
1246 
1247 /// One instance of this struct is used for each type in a
1248 /// declarator that is parsed.
1249 ///
1250 /// This is intended to be a small value object.
1251 struct DeclaratorChunk {
1252   DeclaratorChunk() {};
1253 
1254   enum {
1255     Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe
1256   } Kind;
1257 
1258   /// Loc - The place where this type was defined.
1259   SourceLocation Loc;
1260   /// EndLoc - If valid, the place where this chunck ends.
1261   SourceLocation EndLoc;
1262 
1263   SourceRange getSourceRange() const {
1264     if (EndLoc.isInvalid())
1265       return SourceRange(Loc, Loc);
1266     return SourceRange(Loc, EndLoc);
1267   }
1268 
1269   ParsedAttributesView AttrList;
1270 
1271   struct PointerTypeInfo {
1272     /// The type qualifiers: const/volatile/restrict/unaligned/atomic.
1273     LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1274     unsigned TypeQuals : 5;
1275 
1276     /// The location of the const-qualifier, if any.
1277     SourceLocation ConstQualLoc;
1278 
1279     /// The location of the volatile-qualifier, if any.
1280     SourceLocation VolatileQualLoc;
1281 
1282     /// The location of the restrict-qualifier, if any.
1283     SourceLocation RestrictQualLoc;
1284 
1285     /// The location of the _Atomic-qualifier, if any.
1286     SourceLocation AtomicQualLoc;
1287 
1288     /// The location of the __unaligned-qualifier, if any.
1289     SourceLocation UnalignedQualLoc;
1290 
1291     void destroy() {
1292     }
1293   };
1294 
1295   struct ReferenceTypeInfo {
1296     /// The type qualifier: restrict. [GNU] C++ extension
1297     bool HasRestrict : 1;
1298     /// True if this is an lvalue reference, false if it's an rvalue reference.
1299     bool LValueRef : 1;
1300     void destroy() {
1301     }
1302   };
1303 
1304   struct ArrayTypeInfo {
1305     /// The type qualifiers for the array:
1306     /// const/volatile/restrict/__unaligned/_Atomic.
1307     LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1308     unsigned TypeQuals : 5;
1309 
1310     /// True if this dimension included the 'static' keyword.
1311     LLVM_PREFERRED_TYPE(bool)
1312     unsigned hasStatic : 1;
1313 
1314     /// True if this dimension was [*].  In this case, NumElts is null.
1315     LLVM_PREFERRED_TYPE(bool)
1316     unsigned isStar : 1;
1317 
1318     /// This is the size of the array, or null if [] or [*] was specified.
1319     /// Since the parser is multi-purpose, and we don't want to impose a root
1320     /// expression class on all clients, NumElts is untyped.
1321     Expr *NumElts;
1322 
1323     void destroy() {}
1324   };
1325 
1326   /// ParamInfo - An array of paraminfo objects is allocated whenever a function
1327   /// declarator is parsed.  There are two interesting styles of parameters
1328   /// here:
1329   /// K&R-style identifier lists and parameter type lists.  K&R-style identifier
1330   /// lists will have information about the identifier, but no type information.
1331   /// Parameter type lists will have type info (if the actions module provides
1332   /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
1333   struct ParamInfo {
1334     const IdentifierInfo *Ident;
1335     SourceLocation IdentLoc;
1336     Decl *Param;
1337 
1338     /// DefaultArgTokens - When the parameter's default argument
1339     /// cannot be parsed immediately (because it occurs within the
1340     /// declaration of a member function), it will be stored here as a
1341     /// sequence of tokens to be parsed once the class definition is
1342     /// complete. Non-NULL indicates that there is a default argument.
1343     std::unique_ptr<CachedTokens> DefaultArgTokens;
1344 
1345     ParamInfo() = default;
1346     ParamInfo(const IdentifierInfo *ident, SourceLocation iloc, Decl *param,
1347               std::unique_ptr<CachedTokens> DefArgTokens = nullptr)
1348         : Ident(ident), IdentLoc(iloc), Param(param),
1349           DefaultArgTokens(std::move(DefArgTokens)) {}
1350   };
1351 
1352   struct TypeAndRange {
1353     ParsedType Ty;
1354     SourceRange Range;
1355   };
1356 
1357   struct FunctionTypeInfo {
1358     /// hasPrototype - This is true if the function had at least one typed
1359     /// parameter.  If the function is () or (a,b,c), then it has no prototype,
1360     /// and is treated as a K&R-style function.
1361     LLVM_PREFERRED_TYPE(bool)
1362     unsigned hasPrototype : 1;
1363 
1364     /// isVariadic - If this function has a prototype, and if that
1365     /// proto ends with ',...)', this is true. When true, EllipsisLoc
1366     /// contains the location of the ellipsis.
1367     LLVM_PREFERRED_TYPE(bool)
1368     unsigned isVariadic : 1;
1369 
1370     /// Can this declaration be a constructor-style initializer?
1371     LLVM_PREFERRED_TYPE(bool)
1372     unsigned isAmbiguous : 1;
1373 
1374     /// Whether the ref-qualifier (if any) is an lvalue reference.
1375     /// Otherwise, it's an rvalue reference.
1376     LLVM_PREFERRED_TYPE(bool)
1377     unsigned RefQualifierIsLValueRef : 1;
1378 
1379     /// ExceptionSpecType - An ExceptionSpecificationType value.
1380     LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
1381     unsigned ExceptionSpecType : 4;
1382 
1383     /// DeleteParams - If this is true, we need to delete[] Params.
1384     LLVM_PREFERRED_TYPE(bool)
1385     unsigned DeleteParams : 1;
1386 
1387     /// HasTrailingReturnType - If this is true, a trailing return type was
1388     /// specified.
1389     LLVM_PREFERRED_TYPE(bool)
1390     unsigned HasTrailingReturnType : 1;
1391 
1392     /// The location of the left parenthesis in the source.
1393     SourceLocation LParenLoc;
1394 
1395     /// When isVariadic is true, the location of the ellipsis in the source.
1396     SourceLocation EllipsisLoc;
1397 
1398     /// The location of the right parenthesis in the source.
1399     SourceLocation RParenLoc;
1400 
1401     /// NumParams - This is the number of formal parameters specified by the
1402     /// declarator.
1403     unsigned NumParams;
1404 
1405     /// NumExceptionsOrDecls - This is the number of types in the
1406     /// dynamic-exception-decl, if the function has one. In C, this is the
1407     /// number of declarations in the function prototype.
1408     unsigned NumExceptionsOrDecls;
1409 
1410     /// The location of the ref-qualifier, if any.
1411     ///
1412     /// If this is an invalid location, there is no ref-qualifier.
1413     SourceLocation RefQualifierLoc;
1414 
1415     /// The location of the 'mutable' qualifer in a lambda-declarator, if
1416     /// any.
1417     SourceLocation MutableLoc;
1418 
1419     /// The beginning location of the exception specification, if any.
1420     SourceLocation ExceptionSpecLocBeg;
1421 
1422     /// The end location of the exception specification, if any.
1423     SourceLocation ExceptionSpecLocEnd;
1424 
1425     /// Params - This is a pointer to a new[]'d array of ParamInfo objects that
1426     /// describe the parameters specified by this function declarator.  null if
1427     /// there are no parameters specified.
1428     ParamInfo *Params;
1429 
1430     /// DeclSpec for the function with the qualifier related info.
1431     DeclSpec *MethodQualifiers;
1432 
1433     /// AttributeFactory for the MethodQualifiers.
1434     AttributeFactory *QualAttrFactory;
1435 
1436     union {
1437       /// Pointer to a new[]'d array of TypeAndRange objects that
1438       /// contain the types in the function's dynamic exception specification
1439       /// and their locations, if there is one.
1440       TypeAndRange *Exceptions;
1441 
1442       /// Pointer to the expression in the noexcept-specifier of this
1443       /// function, if it has one.
1444       Expr *NoexceptExpr;
1445 
1446       /// Pointer to the cached tokens for an exception-specification
1447       /// that has not yet been parsed.
1448       CachedTokens *ExceptionSpecTokens;
1449 
1450       /// Pointer to a new[]'d array of declarations that need to be available
1451       /// for lookup inside the function body, if one exists. Does not exist in
1452       /// C++.
1453       NamedDecl **DeclsInPrototype;
1454     };
1455 
1456     /// If HasTrailingReturnType is true, this is the trailing return
1457     /// type specified.
1458     UnionParsedType TrailingReturnType;
1459 
1460     /// If HasTrailingReturnType is true, this is the location of the trailing
1461     /// return type.
1462     SourceLocation TrailingReturnTypeLoc;
1463 
1464     /// Reset the parameter list to having zero parameters.
1465     ///
1466     /// This is used in various places for error recovery.
1467     void freeParams() {
1468       for (unsigned I = 0; I < NumParams; ++I)
1469         Params[I].DefaultArgTokens.reset();
1470       if (DeleteParams) {
1471         delete[] Params;
1472         DeleteParams = false;
1473       }
1474       NumParams = 0;
1475     }
1476 
1477     void destroy() {
1478       freeParams();
1479       delete QualAttrFactory;
1480       delete MethodQualifiers;
1481       switch (getExceptionSpecType()) {
1482       default:
1483         break;
1484       case EST_Dynamic:
1485         delete[] Exceptions;
1486         break;
1487       case EST_Unparsed:
1488         delete ExceptionSpecTokens;
1489         break;
1490       case EST_None:
1491         if (NumExceptionsOrDecls != 0)
1492           delete[] DeclsInPrototype;
1493         break;
1494       }
1495     }
1496 
1497     DeclSpec &getOrCreateMethodQualifiers() {
1498       if (!MethodQualifiers) {
1499         QualAttrFactory = new AttributeFactory();
1500         MethodQualifiers = new DeclSpec(*QualAttrFactory);
1501       }
1502       return *MethodQualifiers;
1503     }
1504 
1505     /// isKNRPrototype - Return true if this is a K&R style identifier list,
1506     /// like "void foo(a,b,c)".  In a function definition, this will be followed
1507     /// by the parameter type definitions.
1508     bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; }
1509 
1510     SourceLocation getLParenLoc() const { return LParenLoc; }
1511 
1512     SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
1513 
1514     SourceLocation getRParenLoc() const { return RParenLoc; }
1515 
1516     SourceLocation getExceptionSpecLocBeg() const {
1517       return ExceptionSpecLocBeg;
1518     }
1519 
1520     SourceLocation getExceptionSpecLocEnd() const {
1521       return ExceptionSpecLocEnd;
1522     }
1523 
1524     SourceRange getExceptionSpecRange() const {
1525       return SourceRange(getExceptionSpecLocBeg(), getExceptionSpecLocEnd());
1526     }
1527 
1528     /// Retrieve the location of the ref-qualifier, if any.
1529     SourceLocation getRefQualifierLoc() const { return RefQualifierLoc; }
1530 
1531     /// Retrieve the location of the 'const' qualifier.
1532     SourceLocation getConstQualifierLoc() const {
1533       assert(MethodQualifiers);
1534       return MethodQualifiers->getConstSpecLoc();
1535     }
1536 
1537     /// Retrieve the location of the 'volatile' qualifier.
1538     SourceLocation getVolatileQualifierLoc() const {
1539       assert(MethodQualifiers);
1540       return MethodQualifiers->getVolatileSpecLoc();
1541     }
1542 
1543     /// Retrieve the location of the 'restrict' qualifier.
1544     SourceLocation getRestrictQualifierLoc() const {
1545       assert(MethodQualifiers);
1546       return MethodQualifiers->getRestrictSpecLoc();
1547     }
1548 
1549     /// Retrieve the location of the 'mutable' qualifier, if any.
1550     SourceLocation getMutableLoc() const { return MutableLoc; }
1551 
1552     /// Determine whether this function declaration contains a
1553     /// ref-qualifier.
1554     bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
1555 
1556     /// Determine whether this lambda-declarator contains a 'mutable'
1557     /// qualifier.
1558     bool hasMutableQualifier() const { return getMutableLoc().isValid(); }
1559 
1560     /// Determine whether this method has qualifiers.
1561     bool hasMethodTypeQualifiers() const {
1562       return MethodQualifiers && (MethodQualifiers->getTypeQualifiers() ||
1563                                   MethodQualifiers->getAttributes().size());
1564     }
1565 
1566     /// Get the type of exception specification this function has.
1567     ExceptionSpecificationType getExceptionSpecType() const {
1568       return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
1569     }
1570 
1571     /// Get the number of dynamic exception specifications.
1572     unsigned getNumExceptions() const {
1573       assert(ExceptionSpecType != EST_None);
1574       return NumExceptionsOrDecls;
1575     }
1576 
1577     /// Get the non-parameter decls defined within this function
1578     /// prototype. Typically these are tag declarations.
1579     ArrayRef<NamedDecl *> getDeclsInPrototype() const {
1580       assert(ExceptionSpecType == EST_None);
1581       return llvm::ArrayRef(DeclsInPrototype, NumExceptionsOrDecls);
1582     }
1583 
1584     /// Determine whether this function declarator had a
1585     /// trailing-return-type.
1586     bool hasTrailingReturnType() const { return HasTrailingReturnType; }
1587 
1588     /// Get the trailing-return-type for this function declarator.
1589     ParsedType getTrailingReturnType() const {
1590       assert(HasTrailingReturnType);
1591       return TrailingReturnType;
1592     }
1593 
1594     /// Get the trailing-return-type location for this function declarator.
1595     SourceLocation getTrailingReturnTypeLoc() const {
1596       assert(HasTrailingReturnType);
1597       return TrailingReturnTypeLoc;
1598     }
1599   };
1600 
1601   struct BlockPointerTypeInfo {
1602     /// For now, sema will catch these as invalid.
1603     /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
1604     LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1605     unsigned TypeQuals : 5;
1606 
1607     void destroy() {
1608     }
1609   };
1610 
1611   struct MemberPointerTypeInfo {
1612     /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
1613     LLVM_PREFERRED_TYPE(DeclSpec::TQ)
1614     unsigned TypeQuals : 5;
1615     /// Location of the '*' token.
1616     SourceLocation StarLoc;
1617     // CXXScopeSpec has a constructor, so it can't be a direct member.
1618     // So we need some pointer-aligned storage and a bit of trickery.
1619     alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)];
1620     CXXScopeSpec &Scope() {
1621       return *reinterpret_cast<CXXScopeSpec *>(ScopeMem);
1622     }
1623     const CXXScopeSpec &Scope() const {
1624       return *reinterpret_cast<const CXXScopeSpec *>(ScopeMem);
1625     }
1626     void destroy() {
1627       Scope().~CXXScopeSpec();
1628     }
1629   };
1630 
1631   struct PipeTypeInfo {
1632     /// The access writes.
1633     unsigned AccessWrites : 3;
1634 
1635     void destroy() {}
1636   };
1637 
1638   union {
1639     PointerTypeInfo       Ptr;
1640     ReferenceTypeInfo     Ref;
1641     ArrayTypeInfo         Arr;
1642     FunctionTypeInfo      Fun;
1643     BlockPointerTypeInfo  Cls;
1644     MemberPointerTypeInfo Mem;
1645     PipeTypeInfo          PipeInfo;
1646   };
1647 
1648   void destroy() {
1649     switch (Kind) {
1650     case DeclaratorChunk::Function:      return Fun.destroy();
1651     case DeclaratorChunk::Pointer:       return Ptr.destroy();
1652     case DeclaratorChunk::BlockPointer:  return Cls.destroy();
1653     case DeclaratorChunk::Reference:     return Ref.destroy();
1654     case DeclaratorChunk::Array:         return Arr.destroy();
1655     case DeclaratorChunk::MemberPointer: return Mem.destroy();
1656     case DeclaratorChunk::Paren:         return;
1657     case DeclaratorChunk::Pipe:          return PipeInfo.destroy();
1658     }
1659   }
1660 
1661   /// If there are attributes applied to this declaratorchunk, return
1662   /// them.
1663   const ParsedAttributesView &getAttrs() const { return AttrList; }
1664   ParsedAttributesView &getAttrs() { return AttrList; }
1665 
1666   /// Return a DeclaratorChunk for a pointer.
1667   static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
1668                                     SourceLocation ConstQualLoc,
1669                                     SourceLocation VolatileQualLoc,
1670                                     SourceLocation RestrictQualLoc,
1671                                     SourceLocation AtomicQualLoc,
1672                                     SourceLocation UnalignedQualLoc) {
1673     DeclaratorChunk I;
1674     I.Kind                = Pointer;
1675     I.Loc                 = Loc;
1676     new (&I.Ptr) PointerTypeInfo;
1677     I.Ptr.TypeQuals       = TypeQuals;
1678     I.Ptr.ConstQualLoc    = ConstQualLoc;
1679     I.Ptr.VolatileQualLoc = VolatileQualLoc;
1680     I.Ptr.RestrictQualLoc = RestrictQualLoc;
1681     I.Ptr.AtomicQualLoc   = AtomicQualLoc;
1682     I.Ptr.UnalignedQualLoc = UnalignedQualLoc;
1683     return I;
1684   }
1685 
1686   /// Return a DeclaratorChunk for a reference.
1687   static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
1688                                       bool lvalue) {
1689     DeclaratorChunk I;
1690     I.Kind            = Reference;
1691     I.Loc             = Loc;
1692     I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
1693     I.Ref.LValueRef   = lvalue;
1694     return I;
1695   }
1696 
1697   /// Return a DeclaratorChunk for an array.
1698   static DeclaratorChunk getArray(unsigned TypeQuals,
1699                                   bool isStatic, bool isStar, Expr *NumElts,
1700                                   SourceLocation LBLoc, SourceLocation RBLoc) {
1701     DeclaratorChunk I;
1702     I.Kind          = Array;
1703     I.Loc           = LBLoc;
1704     I.EndLoc        = RBLoc;
1705     I.Arr.TypeQuals = TypeQuals;
1706     I.Arr.hasStatic = isStatic;
1707     I.Arr.isStar    = isStar;
1708     I.Arr.NumElts   = NumElts;
1709     return I;
1710   }
1711 
1712   /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
1713   /// "TheDeclarator" is the declarator that this will be added to.
1714   static DeclaratorChunk getFunction(bool HasProto,
1715                                      bool IsAmbiguous,
1716                                      SourceLocation LParenLoc,
1717                                      ParamInfo *Params, unsigned NumParams,
1718                                      SourceLocation EllipsisLoc,
1719                                      SourceLocation RParenLoc,
1720                                      bool RefQualifierIsLvalueRef,
1721                                      SourceLocation RefQualifierLoc,
1722                                      SourceLocation MutableLoc,
1723                                      ExceptionSpecificationType ESpecType,
1724                                      SourceRange ESpecRange,
1725                                      ParsedType *Exceptions,
1726                                      SourceRange *ExceptionRanges,
1727                                      unsigned NumExceptions,
1728                                      Expr *NoexceptExpr,
1729                                      CachedTokens *ExceptionSpecTokens,
1730                                      ArrayRef<NamedDecl *> DeclsInPrototype,
1731                                      SourceLocation LocalRangeBegin,
1732                                      SourceLocation LocalRangeEnd,
1733                                      Declarator &TheDeclarator,
1734                                      TypeResult TrailingReturnType =
1735                                                     TypeResult(),
1736                                      SourceLocation TrailingReturnTypeLoc =
1737                                                     SourceLocation(),
1738                                      DeclSpec *MethodQualifiers = nullptr);
1739 
1740   /// Return a DeclaratorChunk for a block.
1741   static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
1742                                          SourceLocation Loc) {
1743     DeclaratorChunk I;
1744     I.Kind          = BlockPointer;
1745     I.Loc           = Loc;
1746     I.Cls.TypeQuals = TypeQuals;
1747     return I;
1748   }
1749 
1750   /// Return a DeclaratorChunk for a block.
1751   static DeclaratorChunk getPipe(unsigned TypeQuals,
1752                                  SourceLocation Loc) {
1753     DeclaratorChunk I;
1754     I.Kind          = Pipe;
1755     I.Loc           = Loc;
1756     I.Cls.TypeQuals = TypeQuals;
1757     return I;
1758   }
1759 
1760   static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
1761                                           unsigned TypeQuals,
1762                                           SourceLocation StarLoc,
1763                                           SourceLocation EndLoc) {
1764     DeclaratorChunk I;
1765     I.Kind          = MemberPointer;
1766     I.Loc           = SS.getBeginLoc();
1767     I.EndLoc = EndLoc;
1768     new (&I.Mem) MemberPointerTypeInfo;
1769     I.Mem.StarLoc = StarLoc;
1770     I.Mem.TypeQuals = TypeQuals;
1771     new (I.Mem.ScopeMem) CXXScopeSpec(SS);
1772     return I;
1773   }
1774 
1775   /// Return a DeclaratorChunk for a paren.
1776   static DeclaratorChunk getParen(SourceLocation LParenLoc,
1777                                   SourceLocation RParenLoc) {
1778     DeclaratorChunk I;
1779     I.Kind          = Paren;
1780     I.Loc           = LParenLoc;
1781     I.EndLoc        = RParenLoc;
1782     return I;
1783   }
1784 
1785   bool isParen() const {
1786     return Kind == Paren;
1787   }
1788 };
1789 
1790 /// A parsed C++17 decomposition declarator of the form
1791 ///   '[' identifier-list ']'
1792 class DecompositionDeclarator {
1793 public:
1794   struct Binding {
1795     IdentifierInfo *Name;
1796     SourceLocation NameLoc;
1797     std::optional<ParsedAttributes> Attrs;
1798   };
1799 
1800 private:
1801   /// The locations of the '[' and ']' tokens.
1802   SourceLocation LSquareLoc, RSquareLoc;
1803 
1804   /// The bindings.
1805   Binding *Bindings;
1806   unsigned NumBindings : 31;
1807   LLVM_PREFERRED_TYPE(bool)
1808   unsigned DeleteBindings : 1;
1809 
1810   friend class Declarator;
1811 
1812 public:
1813   DecompositionDeclarator()
1814       : Bindings(nullptr), NumBindings(0), DeleteBindings(false) {}
1815   DecompositionDeclarator(const DecompositionDeclarator &G) = delete;
1816   DecompositionDeclarator &operator=(const DecompositionDeclarator &G) = delete;
1817   ~DecompositionDeclarator() { clear(); }
1818 
1819   void clear() {
1820     LSquareLoc = RSquareLoc = SourceLocation();
1821     if (DeleteBindings)
1822       delete[] Bindings;
1823     else
1824       llvm::for_each(llvm::MutableArrayRef(Bindings, NumBindings),
1825                      [](Binding &B) { B.Attrs.reset(); });
1826     Bindings = nullptr;
1827     NumBindings = 0;
1828     DeleteBindings = false;
1829   }
1830 
1831   ArrayRef<Binding> bindings() const {
1832     return llvm::ArrayRef(Bindings, NumBindings);
1833   }
1834 
1835   bool isSet() const { return LSquareLoc.isValid(); }
1836 
1837   SourceLocation getLSquareLoc() const { return LSquareLoc; }
1838   SourceLocation getRSquareLoc() const { return RSquareLoc; }
1839   SourceRange getSourceRange() const {
1840     return SourceRange(LSquareLoc, RSquareLoc);
1841   }
1842 };
1843 
1844 /// Described the kind of function definition (if any) provided for
1845 /// a function.
1846 enum class FunctionDefinitionKind {
1847   Declaration,
1848   Definition,
1849   Defaulted,
1850   Deleted
1851 };
1852 
1853 enum class DeclaratorContext {
1854   File,                // File scope declaration.
1855   Prototype,           // Within a function prototype.
1856   ObjCResult,          // An ObjC method result type.
1857   ObjCParameter,       // An ObjC method parameter type.
1858   KNRTypeList,         // K&R type definition list for formals.
1859   TypeName,            // Abstract declarator for types.
1860   FunctionalCast,      // Type in a C++ functional cast expression.
1861   Member,              // Struct/Union field.
1862   Block,               // Declaration within a block in a function.
1863   ForInit,             // Declaration within first part of a for loop.
1864   SelectionInit,       // Declaration within optional init stmt of if/switch.
1865   Condition,           // Condition declaration in a C++ if/switch/while/for.
1866   TemplateParam,       // Within a template parameter list.
1867   CXXNew,              // C++ new-expression.
1868   CXXCatch,            // C++ catch exception-declaration
1869   ObjCCatch,           // Objective-C catch exception-declaration
1870   BlockLiteral,        // Block literal declarator.
1871   LambdaExpr,          // Lambda-expression declarator.
1872   LambdaExprParameter, // Lambda-expression parameter declarator.
1873   ConversionId,        // C++ conversion-type-id.
1874   TrailingReturn,      // C++11 trailing-type-specifier.
1875   TrailingReturnVar,   // C++11 trailing-type-specifier for variable.
1876   TemplateArg,         // Any template argument (in template argument list).
1877   TemplateTypeArg,     // Template type argument (in default argument).
1878   AliasDecl,           // C++11 alias-declaration.
1879   AliasTemplate,       // C++11 alias-declaration template.
1880   RequiresExpr,        // C++2a requires-expression.
1881   Association          // C11 _Generic selection expression association.
1882 };
1883 
1884 // Describes whether the current context is a context where an implicit
1885 // typename is allowed (C++2a [temp.res]p5]).
1886 enum class ImplicitTypenameContext {
1887   No,
1888   Yes,
1889 };
1890 
1891 /// Information about one declarator, including the parsed type
1892 /// information and the identifier.
1893 ///
1894 /// When the declarator is fully formed, this is turned into the appropriate
1895 /// Decl object.
1896 ///
1897 /// Declarators come in two types: normal declarators and abstract declarators.
1898 /// Abstract declarators are used when parsing types, and don't have an
1899 /// identifier.  Normal declarators do have ID's.
1900 ///
1901 /// Instances of this class should be a transient object that lives on the
1902 /// stack, not objects that are allocated in large quantities on the heap.
1903 class Declarator {
1904 
1905 private:
1906   const DeclSpec &DS;
1907   CXXScopeSpec SS;
1908   UnqualifiedId Name;
1909   SourceRange Range;
1910 
1911   /// Where we are parsing this declarator.
1912   DeclaratorContext Context;
1913 
1914   /// The C++17 structured binding, if any. This is an alternative to a Name.
1915   DecompositionDeclarator BindingGroup;
1916 
1917   /// DeclTypeInfo - This holds each type that the declarator includes as it is
1918   /// parsed.  This is pushed from the identifier out, which means that element
1919   /// #0 will be the most closely bound to the identifier, and
1920   /// DeclTypeInfo.back() will be the least closely bound.
1921   SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
1922 
1923   /// InvalidType - Set by Sema::GetTypeForDeclarator().
1924   LLVM_PREFERRED_TYPE(bool)
1925   unsigned InvalidType : 1;
1926 
1927   /// GroupingParens - Set by Parser::ParseParenDeclarator().
1928   LLVM_PREFERRED_TYPE(bool)
1929   unsigned GroupingParens : 1;
1930 
1931   /// FunctionDefinition - Is this Declarator for a function or member
1932   /// definition and, if so, what kind?
1933   ///
1934   /// Actually a FunctionDefinitionKind.
1935   LLVM_PREFERRED_TYPE(FunctionDefinitionKind)
1936   unsigned FunctionDefinition : 2;
1937 
1938   /// Is this Declarator a redeclaration?
1939   LLVM_PREFERRED_TYPE(bool)
1940   unsigned Redeclaration : 1;
1941 
1942   /// true if the declaration is preceded by \c __extension__.
1943   LLVM_PREFERRED_TYPE(bool)
1944   unsigned Extension : 1;
1945 
1946   /// Indicates whether this is an Objective-C instance variable.
1947   LLVM_PREFERRED_TYPE(bool)
1948   unsigned ObjCIvar : 1;
1949 
1950   /// Indicates whether this is an Objective-C 'weak' property.
1951   LLVM_PREFERRED_TYPE(bool)
1952   unsigned ObjCWeakProperty : 1;
1953 
1954   /// Indicates whether the InlineParams / InlineBindings storage has been used.
1955   LLVM_PREFERRED_TYPE(bool)
1956   unsigned InlineStorageUsed : 1;
1957 
1958   /// Indicates whether this declarator has an initializer.
1959   LLVM_PREFERRED_TYPE(bool)
1960   unsigned HasInitializer : 1;
1961 
1962   /// Attributes attached to the declarator.
1963   ParsedAttributes Attrs;
1964 
1965   /// Attributes attached to the declaration. See also documentation for the
1966   /// corresponding constructor parameter.
1967   const ParsedAttributesView &DeclarationAttrs;
1968 
1969   /// The asm label, if specified.
1970   Expr *AsmLabel;
1971 
1972   /// \brief The constraint-expression specified by the trailing
1973   /// requires-clause, or null if no such clause was specified.
1974   Expr *TrailingRequiresClause;
1975 
1976   /// If this declarator declares a template, its template parameter lists.
1977   ArrayRef<TemplateParameterList *> TemplateParameterLists;
1978 
1979   /// If the declarator declares an abbreviated function template, the innermost
1980   /// template parameter list containing the invented and explicit template
1981   /// parameters (if any).
1982   TemplateParameterList *InventedTemplateParameterList;
1983 
1984 #ifndef _MSC_VER
1985   union {
1986 #endif
1987     /// InlineParams - This is a local array used for the first function decl
1988     /// chunk to avoid going to the heap for the common case when we have one
1989     /// function chunk in the declarator.
1990     DeclaratorChunk::ParamInfo InlineParams[16];
1991     DecompositionDeclarator::Binding InlineBindings[16];
1992 #ifndef _MSC_VER
1993   };
1994 #endif
1995 
1996   /// If this is the second or subsequent declarator in this declaration,
1997   /// the location of the comma before this declarator.
1998   SourceLocation CommaLoc;
1999 
2000   /// If provided, the source location of the ellipsis used to describe
2001   /// this declarator as a parameter pack.
2002   SourceLocation EllipsisLoc;
2003 
2004   Expr *PackIndexingExpr;
2005 
2006   friend struct DeclaratorChunk;
2007 
2008 public:
2009   /// `DS` and `DeclarationAttrs` must outlive the `Declarator`. In particular,
2010   /// take care not to pass temporary objects for these parameters.
2011   ///
2012   /// `DeclarationAttrs` contains [[]] attributes from the
2013   /// attribute-specifier-seq at the beginning of a declaration, which appertain
2014   /// to the declared entity itself. Attributes with other syntax (e.g. GNU)
2015   /// should not be placed in this attribute list; if they occur at the
2016   /// beginning of a declaration, they apply to the `DeclSpec` and should be
2017   /// attached to that instead.
2018   ///
2019   /// Here is an example of an attribute associated with a declaration:
2020   ///
2021   ///  [[deprecated]] int x, y;
2022   ///
2023   /// This attribute appertains to all of the entities declared in the
2024   /// declaration, i.e. `x` and `y` in this case.
2025   Declarator(const DeclSpec &DS, const ParsedAttributesView &DeclarationAttrs,
2026              DeclaratorContext C)
2027       : DS(DS), Range(DS.getSourceRange()), Context(C),
2028         InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
2029         GroupingParens(false), FunctionDefinition(static_cast<unsigned>(
2030                                    FunctionDefinitionKind::Declaration)),
2031         Redeclaration(false), Extension(false), ObjCIvar(false),
2032         ObjCWeakProperty(false), InlineStorageUsed(false),
2033         HasInitializer(false), Attrs(DS.getAttributePool().getFactory()),
2034         DeclarationAttrs(DeclarationAttrs), AsmLabel(nullptr),
2035         TrailingRequiresClause(nullptr),
2036         InventedTemplateParameterList(nullptr) {
2037     assert(llvm::all_of(DeclarationAttrs,
2038                         [](const ParsedAttr &AL) {
2039                           return (AL.isStandardAttributeSyntax() ||
2040                                   AL.isRegularKeywordAttribute());
2041                         }) &&
2042            "DeclarationAttrs may only contain [[]] and keyword attributes");
2043   }
2044 
2045   ~Declarator() {
2046     clear();
2047   }
2048   /// getDeclSpec - Return the declaration-specifier that this declarator was
2049   /// declared with.
2050   const DeclSpec &getDeclSpec() const { return DS; }
2051 
2052   /// getMutableDeclSpec - Return a non-const version of the DeclSpec.  This
2053   /// should be used with extreme care: declspecs can often be shared between
2054   /// multiple declarators, so mutating the DeclSpec affects all of the
2055   /// Declarators.  This should only be done when the declspec is known to not
2056   /// be shared or when in error recovery etc.
2057   DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
2058 
2059   AttributePool &getAttributePool() const {
2060     return Attrs.getPool();
2061   }
2062 
2063   /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
2064   /// nested-name-specifier) that is part of the declarator-id.
2065   const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
2066   CXXScopeSpec &getCXXScopeSpec() { return SS; }
2067 
2068   /// Retrieve the name specified by this declarator.
2069   UnqualifiedId &getName() { return Name; }
2070 
2071   const DecompositionDeclarator &getDecompositionDeclarator() const {
2072     return BindingGroup;
2073   }
2074 
2075   DeclaratorContext getContext() const { return Context; }
2076 
2077   bool isPrototypeContext() const {
2078     return (Context == DeclaratorContext::Prototype ||
2079             Context == DeclaratorContext::ObjCParameter ||
2080             Context == DeclaratorContext::ObjCResult ||
2081             Context == DeclaratorContext::LambdaExprParameter);
2082   }
2083 
2084   /// Get the source range that spans this declarator.
2085   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2086   SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2087   SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2088 
2089   void SetSourceRange(SourceRange R) { Range = R; }
2090   /// SetRangeBegin - Set the start of the source range to Loc, unless it's
2091   /// invalid.
2092   void SetRangeBegin(SourceLocation Loc) {
2093     if (!Loc.isInvalid())
2094       Range.setBegin(Loc);
2095   }
2096   /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
2097   void SetRangeEnd(SourceLocation Loc) {
2098     if (!Loc.isInvalid())
2099       Range.setEnd(Loc);
2100   }
2101   /// ExtendWithDeclSpec - Extend the declarator source range to include the
2102   /// given declspec, unless its location is invalid. Adopts the range start if
2103   /// the current range start is invalid.
2104   void ExtendWithDeclSpec(const DeclSpec &DS) {
2105     SourceRange SR = DS.getSourceRange();
2106     if (Range.getBegin().isInvalid())
2107       Range.setBegin(SR.getBegin());
2108     if (!SR.getEnd().isInvalid())
2109       Range.setEnd(SR.getEnd());
2110   }
2111 
2112   /// Reset the contents of this Declarator.
2113   void clear() {
2114     SS.clear();
2115     Name.clear();
2116     Range = DS.getSourceRange();
2117     BindingGroup.clear();
2118 
2119     for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
2120       DeclTypeInfo[i].destroy();
2121     DeclTypeInfo.clear();
2122     Attrs.clear();
2123     AsmLabel = nullptr;
2124     InlineStorageUsed = false;
2125     HasInitializer = false;
2126     ObjCIvar = false;
2127     ObjCWeakProperty = false;
2128     CommaLoc = SourceLocation();
2129     EllipsisLoc = SourceLocation();
2130     PackIndexingExpr = nullptr;
2131   }
2132 
2133   /// mayOmitIdentifier - Return true if the identifier is either optional or
2134   /// not allowed.  This is true for typenames, prototypes, and template
2135   /// parameter lists.
2136   bool mayOmitIdentifier() const {
2137     switch (Context) {
2138     case DeclaratorContext::File:
2139     case DeclaratorContext::KNRTypeList:
2140     case DeclaratorContext::Member:
2141     case DeclaratorContext::Block:
2142     case DeclaratorContext::ForInit:
2143     case DeclaratorContext::SelectionInit:
2144     case DeclaratorContext::Condition:
2145       return false;
2146 
2147     case DeclaratorContext::TypeName:
2148     case DeclaratorContext::FunctionalCast:
2149     case DeclaratorContext::AliasDecl:
2150     case DeclaratorContext::AliasTemplate:
2151     case DeclaratorContext::Prototype:
2152     case DeclaratorContext::LambdaExprParameter:
2153     case DeclaratorContext::ObjCParameter:
2154     case DeclaratorContext::ObjCResult:
2155     case DeclaratorContext::TemplateParam:
2156     case DeclaratorContext::CXXNew:
2157     case DeclaratorContext::CXXCatch:
2158     case DeclaratorContext::ObjCCatch:
2159     case DeclaratorContext::BlockLiteral:
2160     case DeclaratorContext::LambdaExpr:
2161     case DeclaratorContext::ConversionId:
2162     case DeclaratorContext::TemplateArg:
2163     case DeclaratorContext::TemplateTypeArg:
2164     case DeclaratorContext::TrailingReturn:
2165     case DeclaratorContext::TrailingReturnVar:
2166     case DeclaratorContext::RequiresExpr:
2167     case DeclaratorContext::Association:
2168       return true;
2169     }
2170     llvm_unreachable("unknown context kind!");
2171   }
2172 
2173   /// mayHaveIdentifier - Return true if the identifier is either optional or
2174   /// required.  This is true for normal declarators and prototypes, but not
2175   /// typenames.
2176   bool mayHaveIdentifier() const {
2177     switch (Context) {
2178     case DeclaratorContext::File:
2179     case DeclaratorContext::KNRTypeList:
2180     case DeclaratorContext::Member:
2181     case DeclaratorContext::Block:
2182     case DeclaratorContext::ForInit:
2183     case DeclaratorContext::SelectionInit:
2184     case DeclaratorContext::Condition:
2185     case DeclaratorContext::Prototype:
2186     case DeclaratorContext::LambdaExprParameter:
2187     case DeclaratorContext::TemplateParam:
2188     case DeclaratorContext::CXXCatch:
2189     case DeclaratorContext::ObjCCatch:
2190     case DeclaratorContext::RequiresExpr:
2191       return true;
2192 
2193     case DeclaratorContext::TypeName:
2194     case DeclaratorContext::FunctionalCast:
2195     case DeclaratorContext::CXXNew:
2196     case DeclaratorContext::AliasDecl:
2197     case DeclaratorContext::AliasTemplate:
2198     case DeclaratorContext::ObjCParameter:
2199     case DeclaratorContext::ObjCResult:
2200     case DeclaratorContext::BlockLiteral:
2201     case DeclaratorContext::LambdaExpr:
2202     case DeclaratorContext::ConversionId:
2203     case DeclaratorContext::TemplateArg:
2204     case DeclaratorContext::TemplateTypeArg:
2205     case DeclaratorContext::TrailingReturn:
2206     case DeclaratorContext::TrailingReturnVar:
2207     case DeclaratorContext::Association:
2208       return false;
2209     }
2210     llvm_unreachable("unknown context kind!");
2211   }
2212 
2213   /// Return true if the context permits a C++17 decomposition declarator.
2214   bool mayHaveDecompositionDeclarator() const {
2215     switch (Context) {
2216     case DeclaratorContext::File:
2217       // FIXME: It's not clear that the proposal meant to allow file-scope
2218       // structured bindings, but it does.
2219     case DeclaratorContext::Block:
2220     case DeclaratorContext::ForInit:
2221     case DeclaratorContext::SelectionInit:
2222     case DeclaratorContext::Condition:
2223       return true;
2224 
2225     case DeclaratorContext::Member:
2226     case DeclaratorContext::Prototype:
2227     case DeclaratorContext::TemplateParam:
2228     case DeclaratorContext::RequiresExpr:
2229       // Maybe one day...
2230       return false;
2231 
2232     // These contexts don't allow any kind of non-abstract declarator.
2233     case DeclaratorContext::KNRTypeList:
2234     case DeclaratorContext::TypeName:
2235     case DeclaratorContext::FunctionalCast:
2236     case DeclaratorContext::AliasDecl:
2237     case DeclaratorContext::AliasTemplate:
2238     case DeclaratorContext::LambdaExprParameter:
2239     case DeclaratorContext::ObjCParameter:
2240     case DeclaratorContext::ObjCResult:
2241     case DeclaratorContext::CXXNew:
2242     case DeclaratorContext::CXXCatch:
2243     case DeclaratorContext::ObjCCatch:
2244     case DeclaratorContext::BlockLiteral:
2245     case DeclaratorContext::LambdaExpr:
2246     case DeclaratorContext::ConversionId:
2247     case DeclaratorContext::TemplateArg:
2248     case DeclaratorContext::TemplateTypeArg:
2249     case DeclaratorContext::TrailingReturn:
2250     case DeclaratorContext::TrailingReturnVar:
2251     case DeclaratorContext::Association:
2252       return false;
2253     }
2254     llvm_unreachable("unknown context kind!");
2255   }
2256 
2257   /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
2258   /// followed by a C++ direct initializer, e.g. "int x(1);".
2259   bool mayBeFollowedByCXXDirectInit() const {
2260     if (hasGroupingParens()) return false;
2261 
2262     if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
2263       return false;
2264 
2265     if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern &&
2266         Context != DeclaratorContext::File)
2267       return false;
2268 
2269     // Special names can't have direct initializers.
2270     if (Name.getKind() != UnqualifiedIdKind::IK_Identifier)
2271       return false;
2272 
2273     switch (Context) {
2274     case DeclaratorContext::File:
2275     case DeclaratorContext::Block:
2276     case DeclaratorContext::ForInit:
2277     case DeclaratorContext::SelectionInit:
2278     case DeclaratorContext::TrailingReturnVar:
2279       return true;
2280 
2281     case DeclaratorContext::Condition:
2282       // This may not be followed by a direct initializer, but it can't be a
2283       // function declaration either, and we'd prefer to perform a tentative
2284       // parse in order to produce the right diagnostic.
2285       return true;
2286 
2287     case DeclaratorContext::KNRTypeList:
2288     case DeclaratorContext::Member:
2289     case DeclaratorContext::Prototype:
2290     case DeclaratorContext::LambdaExprParameter:
2291     case DeclaratorContext::ObjCParameter:
2292     case DeclaratorContext::ObjCResult:
2293     case DeclaratorContext::TemplateParam:
2294     case DeclaratorContext::CXXCatch:
2295     case DeclaratorContext::ObjCCatch:
2296     case DeclaratorContext::TypeName:
2297     case DeclaratorContext::FunctionalCast: // FIXME
2298     case DeclaratorContext::CXXNew:
2299     case DeclaratorContext::AliasDecl:
2300     case DeclaratorContext::AliasTemplate:
2301     case DeclaratorContext::BlockLiteral:
2302     case DeclaratorContext::LambdaExpr:
2303     case DeclaratorContext::ConversionId:
2304     case DeclaratorContext::TemplateArg:
2305     case DeclaratorContext::TemplateTypeArg:
2306     case DeclaratorContext::TrailingReturn:
2307     case DeclaratorContext::RequiresExpr:
2308     case DeclaratorContext::Association:
2309       return false;
2310     }
2311     llvm_unreachable("unknown context kind!");
2312   }
2313 
2314   /// isPastIdentifier - Return true if we have parsed beyond the point where
2315   /// the name would appear. (This may happen even if we haven't actually parsed
2316   /// a name, perhaps because this context doesn't require one.)
2317   bool isPastIdentifier() const { return Name.isValid(); }
2318 
2319   /// hasName - Whether this declarator has a name, which might be an
2320   /// identifier (accessible via getIdentifier()) or some kind of
2321   /// special C++ name (constructor, destructor, etc.), or a structured
2322   /// binding (which is not exactly a name, but occupies the same position).
2323   bool hasName() const {
2324     return Name.getKind() != UnqualifiedIdKind::IK_Identifier ||
2325            Name.Identifier || isDecompositionDeclarator();
2326   }
2327 
2328   /// Return whether this declarator is a decomposition declarator.
2329   bool isDecompositionDeclarator() const {
2330     return BindingGroup.isSet();
2331   }
2332 
2333   const IdentifierInfo *getIdentifier() const {
2334     if (Name.getKind() == UnqualifiedIdKind::IK_Identifier)
2335       return Name.Identifier;
2336 
2337     return nullptr;
2338   }
2339   SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
2340 
2341   /// Set the name of this declarator to be the given identifier.
2342   void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
2343     Name.setIdentifier(Id, IdLoc);
2344   }
2345 
2346   /// Set the decomposition bindings for this declarator.
2347   void setDecompositionBindings(
2348       SourceLocation LSquareLoc,
2349       MutableArrayRef<DecompositionDeclarator::Binding> Bindings,
2350       SourceLocation RSquareLoc);
2351 
2352   /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2353   /// EndLoc, which should be the last token of the chunk.
2354   /// This function takes attrs by R-Value reference because it takes ownership
2355   /// of those attributes from the parameter.
2356   void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs,
2357                    SourceLocation EndLoc) {
2358     DeclTypeInfo.push_back(TI);
2359     DeclTypeInfo.back().getAttrs().addAll(attrs.begin(), attrs.end());
2360     getAttributePool().takeAllFrom(attrs.getPool());
2361 
2362     if (!EndLoc.isInvalid())
2363       SetRangeEnd(EndLoc);
2364   }
2365 
2366   /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2367   /// EndLoc, which should be the last token of the chunk. This overload is for
2368   /// copying a 'chunk' from another declarator, so it takes the pool that the
2369   /// other Declarator owns so that it can 'take' the attributes from it.
2370   void AddTypeInfo(const DeclaratorChunk &TI, AttributePool &OtherPool,
2371                    SourceLocation EndLoc) {
2372     DeclTypeInfo.push_back(TI);
2373     getAttributePool().takeFrom(DeclTypeInfo.back().getAttrs(), OtherPool);
2374 
2375     if (!EndLoc.isInvalid())
2376       SetRangeEnd(EndLoc);
2377   }
2378 
2379   /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
2380   /// EndLoc, which should be the last token of the chunk.
2381   void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) {
2382     DeclTypeInfo.push_back(TI);
2383 
2384     assert(TI.AttrList.empty() &&
2385            "Cannot add a declarator chunk with attributes with this overload");
2386 
2387     if (!EndLoc.isInvalid())
2388       SetRangeEnd(EndLoc);
2389   }
2390 
2391   /// Add a new innermost chunk to this declarator.
2392   void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
2393     DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
2394   }
2395 
2396   /// Return the number of types applied to this declarator.
2397   unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
2398 
2399   /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
2400   /// closest to the identifier.
2401   const DeclaratorChunk &getTypeObject(unsigned i) const {
2402     assert(i < DeclTypeInfo.size() && "Invalid type chunk");
2403     return DeclTypeInfo[i];
2404   }
2405   DeclaratorChunk &getTypeObject(unsigned i) {
2406     assert(i < DeclTypeInfo.size() && "Invalid type chunk");
2407     return DeclTypeInfo[i];
2408   }
2409 
2410   typedef SmallVectorImpl<DeclaratorChunk>::const_iterator type_object_iterator;
2411   typedef llvm::iterator_range<type_object_iterator> type_object_range;
2412 
2413   /// Returns the range of type objects, from the identifier outwards.
2414   type_object_range type_objects() const {
2415     return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end());
2416   }
2417 
2418   void DropFirstTypeObject() {
2419     assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
2420     DeclTypeInfo.front().destroy();
2421     DeclTypeInfo.erase(DeclTypeInfo.begin());
2422   }
2423 
2424   /// Return the innermost (closest to the declarator) chunk of this
2425   /// declarator that is not a parens chunk, or null if there are no
2426   /// non-parens chunks.
2427   const DeclaratorChunk *getInnermostNonParenChunk() const {
2428     for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2429       if (!DeclTypeInfo[i].isParen())
2430         return &DeclTypeInfo[i];
2431     }
2432     return nullptr;
2433   }
2434 
2435   /// Return the outermost (furthest from the declarator) chunk of
2436   /// this declarator that is not a parens chunk, or null if there are
2437   /// no non-parens chunks.
2438   const DeclaratorChunk *getOutermostNonParenChunk() const {
2439     for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) {
2440       if (!DeclTypeInfo[i-1].isParen())
2441         return &DeclTypeInfo[i-1];
2442     }
2443     return nullptr;
2444   }
2445 
2446   /// isArrayOfUnknownBound - This method returns true if the declarator
2447   /// is a declarator for an array of unknown bound (looking through
2448   /// parentheses).
2449   bool isArrayOfUnknownBound() const {
2450     const DeclaratorChunk *chunk = getInnermostNonParenChunk();
2451     return (chunk && chunk->Kind == DeclaratorChunk::Array &&
2452             !chunk->Arr.NumElts);
2453   }
2454 
2455   /// isFunctionDeclarator - This method returns true if the declarator
2456   /// is a function declarator (looking through parentheses).
2457   /// If true is returned, then the reference type parameter idx is
2458   /// assigned with the index of the declaration chunk.
2459   bool isFunctionDeclarator(unsigned& idx) const {
2460     for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
2461       switch (DeclTypeInfo[i].Kind) {
2462       case DeclaratorChunk::Function:
2463         idx = i;
2464         return true;
2465       case DeclaratorChunk::Paren:
2466         continue;
2467       case DeclaratorChunk::Pointer:
2468       case DeclaratorChunk::Reference:
2469       case DeclaratorChunk::Array:
2470       case DeclaratorChunk::BlockPointer:
2471       case DeclaratorChunk::MemberPointer:
2472       case DeclaratorChunk::Pipe:
2473         return false;
2474       }
2475       llvm_unreachable("Invalid type chunk");
2476     }
2477     return false;
2478   }
2479 
2480   /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
2481   /// this method returns true if the identifier is a function declarator
2482   /// (looking through parentheses).
2483   bool isFunctionDeclarator() const {
2484     unsigned index;
2485     return isFunctionDeclarator(index);
2486   }
2487 
2488   /// getFunctionTypeInfo - Retrieves the function type info object
2489   /// (looking through parentheses).
2490   DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
2491     assert(isFunctionDeclarator() && "Not a function declarator!");
2492     unsigned index = 0;
2493     isFunctionDeclarator(index);
2494     return DeclTypeInfo[index].Fun;
2495   }
2496 
2497   /// getFunctionTypeInfo - Retrieves the function type info object
2498   /// (looking through parentheses).
2499   const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
2500     return const_cast<Declarator*>(this)->getFunctionTypeInfo();
2501   }
2502 
2503   /// Determine whether the declaration that will be produced from
2504   /// this declaration will be a function.
2505   ///
2506   /// A declaration can declare a function even if the declarator itself
2507   /// isn't a function declarator, if the type specifier refers to a function
2508   /// type. This routine checks for both cases.
2509   bool isDeclarationOfFunction() const;
2510 
2511   /// Return true if this declaration appears in a context where a
2512   /// function declarator would be a function declaration.
2513   bool isFunctionDeclarationContext() const {
2514     if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
2515       return false;
2516 
2517     switch (Context) {
2518     case DeclaratorContext::File:
2519     case DeclaratorContext::Member:
2520     case DeclaratorContext::Block:
2521     case DeclaratorContext::ForInit:
2522     case DeclaratorContext::SelectionInit:
2523       return true;
2524 
2525     case DeclaratorContext::Condition:
2526     case DeclaratorContext::KNRTypeList:
2527     case DeclaratorContext::TypeName:
2528     case DeclaratorContext::FunctionalCast:
2529     case DeclaratorContext::AliasDecl:
2530     case DeclaratorContext::AliasTemplate:
2531     case DeclaratorContext::Prototype:
2532     case DeclaratorContext::LambdaExprParameter:
2533     case DeclaratorContext::ObjCParameter:
2534     case DeclaratorContext::ObjCResult:
2535     case DeclaratorContext::TemplateParam:
2536     case DeclaratorContext::CXXNew:
2537     case DeclaratorContext::CXXCatch:
2538     case DeclaratorContext::ObjCCatch:
2539     case DeclaratorContext::BlockLiteral:
2540     case DeclaratorContext::LambdaExpr:
2541     case DeclaratorContext::ConversionId:
2542     case DeclaratorContext::TemplateArg:
2543     case DeclaratorContext::TemplateTypeArg:
2544     case DeclaratorContext::TrailingReturn:
2545     case DeclaratorContext::TrailingReturnVar:
2546     case DeclaratorContext::RequiresExpr:
2547     case DeclaratorContext::Association:
2548       return false;
2549     }
2550     llvm_unreachable("unknown context kind!");
2551   }
2552 
2553   /// Determine whether this declaration appears in a context where an
2554   /// expression could appear.
2555   bool isExpressionContext() const {
2556     switch (Context) {
2557     case DeclaratorContext::File:
2558     case DeclaratorContext::KNRTypeList:
2559     case DeclaratorContext::Member:
2560 
2561     // FIXME: sizeof(...) permits an expression.
2562     case DeclaratorContext::TypeName:
2563 
2564     case DeclaratorContext::FunctionalCast:
2565     case DeclaratorContext::AliasDecl:
2566     case DeclaratorContext::AliasTemplate:
2567     case DeclaratorContext::Prototype:
2568     case DeclaratorContext::LambdaExprParameter:
2569     case DeclaratorContext::ObjCParameter:
2570     case DeclaratorContext::ObjCResult:
2571     case DeclaratorContext::TemplateParam:
2572     case DeclaratorContext::CXXNew:
2573     case DeclaratorContext::CXXCatch:
2574     case DeclaratorContext::ObjCCatch:
2575     case DeclaratorContext::BlockLiteral:
2576     case DeclaratorContext::LambdaExpr:
2577     case DeclaratorContext::ConversionId:
2578     case DeclaratorContext::TrailingReturn:
2579     case DeclaratorContext::TrailingReturnVar:
2580     case DeclaratorContext::TemplateTypeArg:
2581     case DeclaratorContext::RequiresExpr:
2582     case DeclaratorContext::Association:
2583       return false;
2584 
2585     case DeclaratorContext::Block:
2586     case DeclaratorContext::ForInit:
2587     case DeclaratorContext::SelectionInit:
2588     case DeclaratorContext::Condition:
2589     case DeclaratorContext::TemplateArg:
2590       return true;
2591     }
2592 
2593     llvm_unreachable("unknown context kind!");
2594   }
2595 
2596   /// Return true if a function declarator at this position would be a
2597   /// function declaration.
2598   bool isFunctionDeclaratorAFunctionDeclaration() const {
2599     if (!isFunctionDeclarationContext())
2600       return false;
2601 
2602     for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I)
2603       if (getTypeObject(I).Kind != DeclaratorChunk::Paren)
2604         return false;
2605 
2606     return true;
2607   }
2608 
2609   /// Determine whether a trailing return type was written (at any
2610   /// level) within this declarator.
2611   bool hasTrailingReturnType() const {
2612     for (const auto &Chunk : type_objects())
2613       if (Chunk.Kind == DeclaratorChunk::Function &&
2614           Chunk.Fun.hasTrailingReturnType())
2615         return true;
2616     return false;
2617   }
2618   /// Get the trailing return type appearing (at any level) within this
2619   /// declarator.
2620   ParsedType getTrailingReturnType() const {
2621     for (const auto &Chunk : type_objects())
2622       if (Chunk.Kind == DeclaratorChunk::Function &&
2623           Chunk.Fun.hasTrailingReturnType())
2624         return Chunk.Fun.getTrailingReturnType();
2625     return ParsedType();
2626   }
2627 
2628   /// \brief Sets a trailing requires clause for this declarator.
2629   void setTrailingRequiresClause(Expr *TRC) {
2630     TrailingRequiresClause = TRC;
2631 
2632     SetRangeEnd(TRC->getEndLoc());
2633   }
2634 
2635   /// \brief Sets a trailing requires clause for this declarator.
2636   Expr *getTrailingRequiresClause() {
2637     return TrailingRequiresClause;
2638   }
2639 
2640   /// \brief Determine whether a trailing requires clause was written in this
2641   /// declarator.
2642   bool hasTrailingRequiresClause() const {
2643     return TrailingRequiresClause != nullptr;
2644   }
2645 
2646   /// Sets the template parameter lists that preceded the declarator.
2647   void setTemplateParameterLists(ArrayRef<TemplateParameterList *> TPLs) {
2648     TemplateParameterLists = TPLs;
2649   }
2650 
2651   /// The template parameter lists that preceded the declarator.
2652   ArrayRef<TemplateParameterList *> getTemplateParameterLists() const {
2653     return TemplateParameterLists;
2654   }
2655 
2656   /// Sets the template parameter list generated from the explicit template
2657   /// parameters along with any invented template parameters from
2658   /// placeholder-typed parameters.
2659   void setInventedTemplateParameterList(TemplateParameterList *Invented) {
2660     InventedTemplateParameterList = Invented;
2661   }
2662 
2663   /// The template parameter list generated from the explicit template
2664   /// parameters along with any invented template parameters from
2665   /// placeholder-typed parameters, if there were any such parameters.
2666   TemplateParameterList * getInventedTemplateParameterList() const {
2667     return InventedTemplateParameterList;
2668   }
2669 
2670   /// takeAttributes - Takes attributes from the given parsed-attributes
2671   /// set and add them to this declarator.
2672   ///
2673   /// These examples both add 3 attributes to "var":
2674   ///  short int var __attribute__((aligned(16),common,deprecated));
2675   ///  short int x, __attribute__((aligned(16)) var
2676   ///                                 __attribute__((common,deprecated));
2677   ///
2678   /// Also extends the range of the declarator.
2679   void takeAttributes(ParsedAttributes &attrs) {
2680     Attrs.takeAllFrom(attrs);
2681 
2682     if (attrs.Range.getEnd().isValid())
2683       SetRangeEnd(attrs.Range.getEnd());
2684   }
2685 
2686   const ParsedAttributes &getAttributes() const { return Attrs; }
2687   ParsedAttributes &getAttributes() { return Attrs; }
2688 
2689   const ParsedAttributesView &getDeclarationAttributes() const {
2690     return DeclarationAttrs;
2691   }
2692 
2693   /// hasAttributes - do we contain any attributes?
2694   bool hasAttributes() const {
2695     if (!getAttributes().empty() || !getDeclarationAttributes().empty() ||
2696         getDeclSpec().hasAttributes())
2697       return true;
2698     for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
2699       if (!getTypeObject(i).getAttrs().empty())
2700         return true;
2701     return false;
2702   }
2703 
2704   void setAsmLabel(Expr *E) { AsmLabel = E; }
2705   Expr *getAsmLabel() const { return AsmLabel; }
2706 
2707   void setExtension(bool Val = true) { Extension = Val; }
2708   bool getExtension() const { return Extension; }
2709 
2710   void setObjCIvar(bool Val = true) { ObjCIvar = Val; }
2711   bool isObjCIvar() const { return ObjCIvar; }
2712 
2713   void setObjCWeakProperty(bool Val = true) { ObjCWeakProperty = Val; }
2714   bool isObjCWeakProperty() const { return ObjCWeakProperty; }
2715 
2716   void setInvalidType(bool Val = true) { InvalidType = Val; }
2717   bool isInvalidType() const {
2718     return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
2719   }
2720 
2721   void setGroupingParens(bool flag) { GroupingParens = flag; }
2722   bool hasGroupingParens() const { return GroupingParens; }
2723 
2724   bool isFirstDeclarator() const { return !CommaLoc.isValid(); }
2725   SourceLocation getCommaLoc() const { return CommaLoc; }
2726   void setCommaLoc(SourceLocation CL) { CommaLoc = CL; }
2727 
2728   bool hasEllipsis() const { return EllipsisLoc.isValid(); }
2729   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2730   void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
2731 
2732   bool hasPackIndexing() const { return PackIndexingExpr != nullptr; }
2733   Expr *getPackIndexingExpr() const { return PackIndexingExpr; }
2734   void setPackIndexingExpr(Expr *PI) { PackIndexingExpr = PI; }
2735 
2736   void setFunctionDefinitionKind(FunctionDefinitionKind Val) {
2737     FunctionDefinition = static_cast<unsigned>(Val);
2738   }
2739 
2740   bool isFunctionDefinition() const {
2741     return getFunctionDefinitionKind() != FunctionDefinitionKind::Declaration;
2742   }
2743 
2744   FunctionDefinitionKind getFunctionDefinitionKind() const {
2745     return (FunctionDefinitionKind)FunctionDefinition;
2746   }
2747 
2748   void setHasInitializer(bool Val = true) { HasInitializer = Val; }
2749   bool hasInitializer() const { return HasInitializer; }
2750 
2751   /// Returns true if this declares a real member and not a friend.
2752   bool isFirstDeclarationOfMember() {
2753     return getContext() == DeclaratorContext::Member &&
2754            !getDeclSpec().isFriendSpecified();
2755   }
2756 
2757   /// Returns true if this declares a static member.  This cannot be called on a
2758   /// declarator outside of a MemberContext because we won't know until
2759   /// redeclaration time if the decl is static.
2760   bool isStaticMember();
2761 
2762   bool isExplicitObjectMemberFunction();
2763 
2764   /// Returns true if this declares a constructor or a destructor.
2765   bool isCtorOrDtor();
2766 
2767   void setRedeclaration(bool Val) { Redeclaration = Val; }
2768   bool isRedeclaration() const { return Redeclaration; }
2769 };
2770 
2771 /// This little struct is used to capture information about
2772 /// structure field declarators, which is basically just a bitfield size.
2773 struct FieldDeclarator {
2774   Declarator D;
2775   Expr *BitfieldSize;
2776   explicit FieldDeclarator(const DeclSpec &DS,
2777                            const ParsedAttributes &DeclarationAttrs)
2778       : D(DS, DeclarationAttrs, DeclaratorContext::Member),
2779         BitfieldSize(nullptr) {}
2780 };
2781 
2782 /// Represents a C++11 virt-specifier-seq.
2783 class VirtSpecifiers {
2784 public:
2785   enum Specifier {
2786     VS_None = 0,
2787     VS_Override = 1,
2788     VS_Final = 2,
2789     VS_Sealed = 4,
2790     // Represents the __final keyword, which is legal for gcc in pre-C++11 mode.
2791     VS_GNU_Final = 8,
2792     VS_Abstract = 16
2793   };
2794 
2795   VirtSpecifiers() = default;
2796 
2797   bool SetSpecifier(Specifier VS, SourceLocation Loc,
2798                     const char *&PrevSpec);
2799 
2800   bool isUnset() const { return Specifiers == 0; }
2801 
2802   bool isOverrideSpecified() const { return Specifiers & VS_Override; }
2803   SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
2804 
2805   bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed | VS_GNU_Final); }
2806   bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; }
2807   SourceLocation getFinalLoc() const { return VS_finalLoc; }
2808   SourceLocation getAbstractLoc() const { return VS_abstractLoc; }
2809 
2810   void clear() { Specifiers = 0; }
2811 
2812   static const char *getSpecifierName(Specifier VS);
2813 
2814   SourceLocation getFirstLocation() const { return FirstLocation; }
2815   SourceLocation getLastLocation() const { return LastLocation; }
2816   Specifier getLastSpecifier() const { return LastSpecifier; }
2817 
2818 private:
2819   unsigned Specifiers = 0;
2820   Specifier LastSpecifier = VS_None;
2821 
2822   SourceLocation VS_overrideLoc, VS_finalLoc, VS_abstractLoc;
2823   SourceLocation FirstLocation;
2824   SourceLocation LastLocation;
2825 };
2826 
2827 enum class LambdaCaptureInitKind {
2828   NoInit,     //!< [a]
2829   CopyInit,   //!< [a = b], [a = {b}]
2830   DirectInit, //!< [a(b)]
2831   ListInit    //!< [a{b}]
2832 };
2833 
2834 /// Represents a complete lambda introducer.
2835 struct LambdaIntroducer {
2836   /// An individual capture in a lambda introducer.
2837   struct LambdaCapture {
2838     LambdaCaptureKind Kind;
2839     SourceLocation Loc;
2840     IdentifierInfo *Id;
2841     SourceLocation EllipsisLoc;
2842     LambdaCaptureInitKind InitKind;
2843     ExprResult Init;
2844     ParsedType InitCaptureType;
2845     SourceRange ExplicitRange;
2846 
2847     LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc,
2848                   IdentifierInfo *Id, SourceLocation EllipsisLoc,
2849                   LambdaCaptureInitKind InitKind, ExprResult Init,
2850                   ParsedType InitCaptureType,
2851                   SourceRange ExplicitRange)
2852         : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc),
2853           InitKind(InitKind), Init(Init), InitCaptureType(InitCaptureType),
2854           ExplicitRange(ExplicitRange) {}
2855   };
2856 
2857   SourceRange Range;
2858   SourceLocation DefaultLoc;
2859   LambdaCaptureDefault Default = LCD_None;
2860   SmallVector<LambdaCapture, 4> Captures;
2861 
2862   LambdaIntroducer() = default;
2863 
2864   bool hasLambdaCapture() const {
2865     return Captures.size() > 0 || Default != LCD_None;
2866   }
2867 
2868   /// Append a capture in a lambda introducer.
2869   void addCapture(LambdaCaptureKind Kind,
2870                   SourceLocation Loc,
2871                   IdentifierInfo* Id,
2872                   SourceLocation EllipsisLoc,
2873                   LambdaCaptureInitKind InitKind,
2874                   ExprResult Init,
2875                   ParsedType InitCaptureType,
2876                   SourceRange ExplicitRange) {
2877     Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
2878                                      InitCaptureType, ExplicitRange));
2879   }
2880 };
2881 
2882 struct InventedTemplateParameterInfo {
2883   /// The number of parameters in the template parameter list that were
2884   /// explicitly specified by the user, as opposed to being invented by use
2885   /// of an auto parameter.
2886   unsigned NumExplicitTemplateParams = 0;
2887 
2888   /// If this is a generic lambda or abbreviated function template, use this
2889   /// as the depth of each 'auto' parameter, during initial AST construction.
2890   unsigned AutoTemplateParameterDepth = 0;
2891 
2892   /// Store the list of the template parameters for a generic lambda or an
2893   /// abbreviated function template.
2894   /// If this is a generic lambda or abbreviated function template, this holds
2895   /// the explicit template parameters followed by the auto parameters
2896   /// converted into TemplateTypeParmDecls.
2897   /// It can be used to construct the generic lambda or abbreviated template's
2898   /// template parameter list during initial AST construction.
2899   SmallVector<NamedDecl*, 4> TemplateParams;
2900 };
2901 
2902 } // end namespace clang
2903 
2904 #endif // LLVM_CLANG_SEMA_DECLSPEC_H