DeclSpec.h revision 683a81f4373cf1fa9d41a751dca6f7c36125b058
119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall//===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 1019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// This file defines the classes used to store parsed information about 1119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// declaration-specifiers and declarators. 1219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// 1319510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// static const int volatile x, *y, *(*(*z)[10])(const void *x); 1419510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// ------------------------- - -- --------------------------- 1519510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// declaration-specifiers \ | / 1619510856727e0e14a3696b2a72c35163bff2a71fJohn McCall// declarators 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#ifndef LLVM_CLANG_SEMA_DECLSPEC_H 2119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#define LLVM_CLANG_SEMA_DECLSPEC_H 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2319510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/AttributeList.h" 24b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall#include "clang/Sema/Ownership.h" 2572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor#include "clang/Lex/Token.h" 268f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner#include "clang/Basic/OperatorKinds.h" 27ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor#include "clang/Basic/Specifiers.h" 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/SmallVector.h" 29075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara#include "llvm/Support/ErrorHandling.h" 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 3243af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl class LangOptions; 33e4858a65a93fb36c099d8dd2ea0a98e33e77687eDaniel Dunbar class Diagnostic; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class IdentifierInfo; 35ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall class NestedNameSpecifier; 368f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner class Preprocessor; 378f823d2d3c557326d22699d66e5d367d0f0e44efChris Lattner class Declarator; 38314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor struct TemplateIdAnnotation; 39595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin 40aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope 41595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// specifier. These can be in 3 states: 42595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 1) Not present, identified by isEmpty() 43595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 2) Present, identified by isNotEmpty() 44595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 2.a) Valid, idenified by isValid() 45595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 2.b) Invalid, identified by isInvalid(). 46595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 47595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// isSet() is deprecated because it mostly corresponded to "valid" but was 48595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// often used as if it meant "present". 49595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// 50595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin/// The actual scope is described by getScopeRep(). 51aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCallclass CXXScopeSpec { 52aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall SourceRange Range; 53ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall NestedNameSpecifier *ScopeRep; 54aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 55aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCallpublic: 56aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec() : Range(), ScopeRep() { } 57aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 58aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall const SourceRange &getRange() const { return Range; } 59aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void setRange(const SourceRange &R) { Range = R; } 60aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } 61aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } 62aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall SourceLocation getBeginLoc() const { return Range.getBegin(); } 63aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall SourceLocation getEndLoc() const { return Range.getEnd(); } 64aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 65ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall NestedNameSpecifier *getScopeRep() const { return ScopeRep; } 66b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setScopeRep(NestedNameSpecifier *S) { ScopeRep = S; } 67aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 68595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// No scope specifier. 69aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall bool isEmpty() const { return !Range.isValid(); } 70595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// A scope specifier is present, but may be valid or invalid. 71aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall bool isNotEmpty() const { return !isEmpty(); } 72aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 73595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// An error occured during parsing of the scope specifier. 74aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall bool isInvalid() const { return isNotEmpty() && ScopeRep == 0; } 75595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// A scope specifier is present, and it refers to a real scope. 76595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin bool isValid() const { return isNotEmpty() && ScopeRep != 0; } 77aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 78595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// Deprecated. Some call sites intend isNotEmpty() while others intend 79595f2698fe000b2c7703de8f6eafcd51366ec14aJeffrey Yasskin /// isValid(). 80aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall bool isSet() const { return ScopeRep != 0; } 81aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 82aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall void clear() { 83aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall Range = SourceRange(); 84aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall ScopeRep = 0; 85aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall } 86aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall}; 87aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclSpec - This class captures information about "declaration specifiers", 897a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek/// which encompasses storage-class-specifiers, type-specifiers, 907a9d49fd2bfac00e905b361ba76d26ab5b6c3b09Ted Kremenek/// type-qualifiers, and function-specifiers. 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclSpec { 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // storage-class-specifier 94160b5630aa781ac348303e1ae088d27016637778Douglas Gregor // Note: The order of these enumerators is important for diagnostics. 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum SCS { 96160b5630aa781ac348303e1ae088d27016637778Douglas Gregor SCS_unspecified = 0, 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_typedef, 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_extern, 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_static, 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_auto, 101d6326c6fe586ba178734c49ba33a2c1af021822cSteve Naroff SCS_register, 102669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl SCS_private_extern, 103669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl SCS_mutable 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Import type specifier width enumeration and constants. 107ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor typedef TypeSpecifierWidth TSW; 108ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_unspecified = clang::TSW_unspecified; 109ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_short = clang::TSW_short; 110ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_long = clang::TSW_long; 111ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSW TSW_longlong = clang::TSW_longlong; 112ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TSC { 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TSC_unspecified, 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TSC_imaginary, 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TSC_complex 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Import type specifier sign enumeration and constants. 120ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor typedef TypeSpecifierSign TSS; 121ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSS TSS_unspecified = clang::TSS_unspecified; 122ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSS TSS_signed = clang::TSS_signed; 123ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TSS TSS_unsigned = clang::TSS_unsigned; 124ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 125ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor // Import type specifier type enumeration and constants. 126ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor typedef TypeSpecifierType TST; 127ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_unspecified = clang::TST_unspecified; 128ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_void = clang::TST_void; 129ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_char = clang::TST_char; 130ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_wchar = clang::TST_wchar; 131ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_char16 = clang::TST_char16; 132ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_char32 = clang::TST_char32; 133ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_int = clang::TST_int; 134ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_float = clang::TST_float; 135ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_double = clang::TST_double; 136ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_bool = clang::TST_bool; 137ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decimal32 = clang::TST_decimal32; 138ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decimal64 = clang::TST_decimal64; 139ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decimal128 = clang::TST_decimal128; 140ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_enum = clang::TST_enum; 141ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_union = clang::TST_union; 142ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_struct = clang::TST_struct; 143ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_class = clang::TST_class; 144ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_typename = clang::TST_typename; 145ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_typeofType = clang::TST_typeofType; 146ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_typeofExpr = clang::TST_typeofExpr; 147ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_decltype = clang::TST_decltype; 148ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_auto = clang::TST_auto; 149ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor static const TST TST_error = clang::TST_error; 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-qualifiers 1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ. 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_unspecified = 0, 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_const = 1, 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_restrict = 2, 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TQ_volatile = 4 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParsedSpecifiers - Flags to query which specifiers were applied. This is 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned by getParsedSpecifiers. 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParsedSpecifiers { 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_None = 0, 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_StorageClassSpecifier = 1, 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_TypeSpecifier = 2, 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_TypeQualifier = 4, 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PQ_FunctionSpecifier = 8 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // storage-class-specifier 1722efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*SCS*/unsigned StorageClassSpec : 3; 1737f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned SCS_thread_specified : 1; 1747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned SCS_extern_in_linkage_spec : 1; 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-specifier 1772efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*TSW*/unsigned TypeSpecWidth : 2; 1782efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*TSC*/unsigned TypeSpecComplex : 2; 1792efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner /*TSS*/unsigned TypeSpecSign : 2; 18099dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner /*TST*/unsigned TypeSpecType : 5; 1817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeAltiVecVector : 1; 1827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeAltiVecPixel : 1; 1837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeAltiVecBool : 1; 1847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned TypeSpecOwned : 1; 185402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-qualifiers 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned TypeQualifiers : 3; // Bitwise OR of TQ. 1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // function-specifier 1907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned FS_inline_specified : 1; 1917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned FS_virtual_specified : 1; 1927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned FS_explicit_specified : 1; 1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 194f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson // friend-specifier 1957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned Friend_specified : 1; 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1972ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl // constexpr-specifier 1987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned Constexpr_specified : 1; 1992ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl 20016573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor /*SCS*/unsigned StorageClassSpecAsWritten : 3; 20116573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor 202b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall union { 203b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType TypeRep; 204b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Decl *DeclRep; 205b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *ExprRep; 206b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall }; 2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // attributes. 2097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes Attrs; 2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 211aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall // Scope specifier for the type spec, if applicable. 212aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec TypeScope; 213aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall 2141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // List of protocol qualifiers for objective-c classes. Used for 21528c0b7df574599d4c19a4c09ca61bb3d70a338ccChris Lattner // protocol-qualified interfaces "NString<foo>" and protocol-qualified id 21628c0b7df574599d4c19a4c09ca61bb3d70a338ccChris Lattner // "id<foo>". 217d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl * const *ProtocolQualifiers; 218ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner unsigned NumProtocolQualifiers; 21971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation ProtocolLAngleLoc; 22071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation *ProtocolLocs; 2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // SourceLocation info. These are null if the item wasn't specified or if 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // the setting was synthesized. 22481c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner SourceRange Range; 2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation StorageClassSpecLoc, SCS_threadLoc; 22782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; 228cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceRange TypeofParensRange; 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc; 230b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc; 2312ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl SourceLocation FriendLoc, ConstexprLoc; 2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 233ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor WrittenBuiltinSpecs writtenBS; 234ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void SaveWrittenBuiltinSpecs(); 23535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara void SaveStorageSpecifierAsWritten(); 236ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 237b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static bool isTypeRep(TST T) { 238b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return (T == TST_typename || T == TST_typeofType); 239b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 240b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static bool isExprRep(TST T) { 241b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return (T == TST_typeofExpr || T == TST_decltype); 242b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 243b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static bool isDeclRep(TST T) { 244b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return (T == TST_enum || T == TST_struct || 245b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall T == TST_union || T == TST_class); 246b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 247b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 248ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner DeclSpec(const DeclSpec&); // DO NOT IMPLEMENT 249ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner void operator=(const DeclSpec&); // DO NOT IMPLEMENT 2501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 2511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclSpec() 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : StorageClassSpec(SCS_unspecified), 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_thread_specified(false), 25535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara SCS_extern_in_linkage_spec(false), 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecWidth(TSW_unspecified), 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecComplex(TSC_unspecified), 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecSign(TSS_unspecified), 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeSpecType(TST_unspecified), 26082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson TypeAltiVecVector(false), 26182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson TypeAltiVecPixel(false), 262788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner TypeAltiVecBool(false), 263402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor TypeSpecOwned(false), 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeQualifiers(TSS_unspecified), 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FS_inline_specified(false), 266b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_virtual_specified(false), 267b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_explicit_specified(false), 268f47f7a1c4082b42b21f1c7dc211ff90f4b38258aAnders Carlsson Friend_specified(false), 2692ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl Constexpr_specified(false), 27016573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor StorageClassSpecAsWritten(SCS_unspecified), 271ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner ProtocolQualifiers(0), 27271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis NumProtocolQualifiers(0), 273b91570a51f9c9583bb27fdfe43ce9c487623999aJohn McCall ProtocolLocs(0), 274b91570a51f9c9583bb27fdfe43ce9c487623999aJohn McCall writtenBS() { 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~DeclSpec() { 277ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner delete [] ProtocolQualifiers; 27871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis delete [] ProtocolLocs; 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // storage-class-specifier 2812efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; } 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isThreadSpecified() const { return SCS_thread_specified; } 28335f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; } 28435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara void setExternInLinkageSpec(bool Value) { 28535f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara SCS_extern_in_linkage_spec = Value; 28635f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara } 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; } 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getThreadSpecLoc() const { return SCS_threadLoc; } 2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ClearStorageClassSpecs() { 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer StorageClassSpec = DeclSpec::SCS_unspecified; 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_thread_specified = false; 29435f9a196ef897b9559de25aaecd957208f0b4f59Abramo Bagnara SCS_extern_in_linkage_spec = false; 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer StorageClassSpecLoc = SourceLocation(); 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SCS_threadLoc = SourceLocation(); 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-specifier 3002efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; } 3012efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; } 3022efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; } 3032efcd2f04e6151ff3144e697529cfa483ad4cb65Chris Lattner TST getTypeSpecType() const { return (TST)TypeSpecType; } 30482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isTypeAltiVecVector() const { return TypeAltiVecVector; } 30582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; } 306788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner bool isTypeAltiVecBool() const { return TypeAltiVecBool; } 307402abb55fc2e0cdda5fb1ac90009b1f5f6774906Douglas Gregor bool isTypeSpecOwned() const { return TypeSpecOwned; } 308b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType getRepAsType() const { 309b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type"); 310b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return TypeRep; 311b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 312b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Decl *getRepAsDecl() const { 313b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl"); 314b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return DeclRep; 315b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 316b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *getRepAsExpr() const { 317b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr"); 318b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ExprRep; 319b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 320aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall CXXScopeSpec &getTypeSpecScope() { return TypeScope; } 321aa87d33309f505b68c3bfc17486c93e4d224b24fJohn McCall const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; } 3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner const SourceRange &getSourceRange() const { return Range; } 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; } 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; } 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecSignLoc() const { return TSSLoc; } 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } 32882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson SourceLocation getAltiVecLoc() const { return AltiVecLoc; } 3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 330cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceRange getTypeofParensRange() const { return TypeofParensRange; } 331cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; } 332cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getSpecifierName - Turn a type-specifier-type into a string like "_Bool" 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// or "union". 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getSpecifierName(DeclSpec::TST T); 33632d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TQ Q); 33732d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TSS S); 33832d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TSC C); 33932d335e63bd287e5c9297532171284cdf4c7888cJohn McCall static const char *getSpecifierName(DeclSpec::TSW W); 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getSpecifierName(DeclSpec::SCS S); 3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type-qualifiers 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getTypeQualifiers - Return a set of TQs. 3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getTypeQualifiers() const { return TypeQualifiers; } 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getConstSpecLoc() const { return TQ_constLoc; } 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; } 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; } 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // function-specifier 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isInlineSpecified() const { return FS_inline_specified; } 3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getInlineSpecLoc() const { return FS_inlineLoc; } 353b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor 354b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor bool isVirtualSpecified() const { return FS_virtual_specified; } 355b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; } 356b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor 357b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor bool isExplicitSpecified() const { return FS_explicit_specified; } 358b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; } 359b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ClearFunctionSpecs() { 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FS_inline_specified = false; 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FS_inlineLoc = SourceLocation(); 363b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_virtual_specified = false; 364b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_virtualLoc = SourceLocation(); 365b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_explicit_specified = false; 366b48fe3812047e84164925c8938ce82be0624c40cDouglas Gregor FS_explicitLoc = SourceLocation(); 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasTypeSpecifier - Return true if any type-specifier has been found. 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool hasTypeSpecifier() const { 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypeSpecType() != DeclSpec::TST_unspecified || 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getTypeSpecWidth() != DeclSpec::TSW_unspecified || 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getTypeSpecComplex() != DeclSpec::TSC_unspecified || 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getTypeSpecSign() != DeclSpec::TSS_unspecified; 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclSpec includes. 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getParsedSpecifiers() const; 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38216573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor SCS getStorageClassSpecAsWritten() const { 38316573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor return (SCS)StorageClassSpecAsWritten; 38416573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor } 38516573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor 3862a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner /// isEmpty - Return true if this declaration specifier is completely empty: 3872a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner /// no tokens were parsed in the production of it. 3882a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner bool isEmpty() const { 3892a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner return getParsedSpecifiers() == DeclSpec::PQ_None; 3902a327d11a07dfbdf20910cebbae38910eda111fdChris Lattner } 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39281c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); } 39381c018d9482e7cc2addadc6202dcf162a01faefdChris Lattner void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); } 3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 395fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// These methods set the specified attribute of the DeclSpec and 396fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// return false if there was no error. If an error occurs (for 397fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// example, if we tried to set "auto" on a spec with "extern" 398fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// already set), they return true and set PrevSpec and DiagID 399fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// such that 400fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// Diag(Loc, DiagID) << PrevSpec; 401fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// will yield a useful result. 402fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// 403fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// TODO: use a more general approach that still allows these 404fec54013fcd0eb72642741584ca04c1bc292bef8John McCall /// diagnostics to be ignored when desired. 405fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec, 406fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 407fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec, 408fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 409fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec, 410fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 411fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, 412fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 413fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, 414fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 416b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall unsigned &DiagID); 417b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 418b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall unsigned &DiagID, ParsedType Rep); 419b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 420b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall unsigned &DiagID, Decl *Rep, bool Owned); 421b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 422b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall unsigned &DiagID, Expr *Rep); 42382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, 42482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson const char *&PrevSpec, unsigned &DiagID); 42582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, 42682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson const char *&PrevSpec, unsigned &DiagID); 427ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor bool SetTypeSpecError(); 428b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void UpdateDeclRep(Decl *Rep) { 429b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isDeclRep((TST) TypeSpecType)); 430b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall DeclRep = Rep; 431b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 432b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void UpdateTypeRep(ParsedType Rep) { 433b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isTypeRep((TST) TypeSpecType)); 434b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall TypeRep = Rep; 435b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 436b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void UpdateExprRep(Expr *Rep) { 437b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall assert(isExprRep((TST) TypeSpecType)); 438b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ExprRep = Rep; 439b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, 442fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, const LangOptions &Lang); 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 444fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, 445fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 446fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, 447fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 448fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, 449fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 451fec54013fcd0eb72642741584ca04c1bc292bef8John McCall bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, 452fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID); 453fec54013fcd0eb72642741584ca04c1bc292bef8John McCall 4542ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, 4552ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl unsigned &DiagID); 4562ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl 457908116859ed8c166c1c0712992e504edd0c5a6e1Anders Carlsson bool isFriendSpecified() const { return Friend_specified; } 45866e9977ddd6b197317d149213b76a9af0d3df4deAnders Carlsson SourceLocation getFriendSpecLoc() const { return FriendLoc; } 459908116859ed8c166c1c0712992e504edd0c5a6e1Anders Carlsson 4602ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl bool isConstexprSpecified() const { return Constexpr_specified; } 4612ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; } 4622ac67239b4ab81c439ffcc56367574c869f87daeSebastian Redl 4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// AddAttributes - contatenates two attribute lists. 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// The GCC attribute syntax allows for the following: 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// short __attribute__(( unused, deprecated )) 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// int __attribute__(( may_alias, aligned(16) )) var; 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This declares 4 attributes using 2 lists. The following syntax is 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// also allowed and equivalent to the previous declaration. 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// short __attribute__((unused)) __attribute__((deprecated)) 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// int __attribute__((may_alias)) __attribute__((aligned(16))) var; 4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 4757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void addAttributes(AttributeList *AL) { 4767f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Attrs.append(AL); 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void aetAttributes(AttributeList *AL) { 4797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Attrs.set(AL); 4807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 4817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 4827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool hasAttributes() const { return !Attrs.empty(); } 4837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 4847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &getAttributes() { return Attrs; } 4857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &getAttributes() const { return Attrs; } 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4877654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner /// TakeAttributes - Return the current attribute list and remove them from 4887654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner /// the DeclSpec so that it doesn't own them. 4897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes takeAttributes() { 4907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes saved = Attrs; 4917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Attrs.clear(); 4927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall return saved; 4937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 4947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 4957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void takeAttributesFrom(ParsedAttributes &attrs) { 4967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall Attrs.append(attrs.getList()); 4977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall attrs.clear(); 4987654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner } 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall typedef Decl * const *ProtocolQualifierListTy; 501ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner ProtocolQualifierListTy getProtocolQualifiers() const { 5024b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return ProtocolQualifiers; 5034b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 50471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation *getProtocolLocs() const { return ProtocolLocs; } 5057654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner unsigned getNumProtocolQualifiers() const { 506ae4da6150bb837311a2f0f958b01a2989066ba90Chris Lattner return NumProtocolQualifiers; 5074b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 50871b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; } 509d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void setProtocolQualifiers(Decl * const *Protos, unsigned NP, 51071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation *ProtoLocs, 511e3a535bb6b39ff721aa3a7177dc427974ca0ff42Argyrios Kyrtzidis SourceLocation LAngleLoc); 5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Finish - This does final analysis of the declspec, issuing diagnostics for 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// things like "_Imaginary" (lacking an FP type). After calling this method, 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclSpec is guaranteed self-consistent, even if an error occurred. 5169b3064b55f3c858923734e8b1c9831777fc22554Douglas Gregor void Finish(Diagnostic &D, Preprocessor &PP); 517a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl 518ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { 519ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return writtenBS; 520ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 521ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 522a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone, 523a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl /// without a Declarator. Only tag declspecs can stand alone. 524a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl bool isMissingDeclaratorOk(); 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCDeclSpec - This class captures information about 52819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian/// "declaration specifiers" specific to objective-c 529a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCDeclSpec { 53019d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanianpublic: 531a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek /// ObjCDeclQualifier - Qualifier used on types in method declarations 532a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek enum ObjCDeclQualifier { 53319d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_None = 0x0, 53419d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_In = 0x1, 53519d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Inout = 0x2, 53619d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Out = 0x4, 53719d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Bycopy = 0x8, 53819d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Byref = 0x10, 53919d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian DQ_Oneway = 0x20 54019d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian }; 5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 542564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian /// PropertyAttributeKind - list of property attributes. 5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump enum ObjCPropertyAttributeKind { DQ_PR_noattr = 0x0, 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_readonly = 0x01, 5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_getter = 0x02, 5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_assign = 0x04, 5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_readwrite = 0x08, 54882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian DQ_PR_retain = 0x10, 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DQ_PR_copy = 0x20, 55082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian DQ_PR_nonatomic = 0x40, 551dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian DQ_PR_setter = 0x80, 552dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian DQ_PR_atomic = 0x100 55382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian }; 5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 556e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner ObjCDeclSpec() 557e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr), 558e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner GetterName(0), SetterName(0) { } 559a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; } 560e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner void setObjCDeclQualifier(ObjCDeclQualifier DQVal) { 561e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal); 562e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner } 5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 564e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner ObjCPropertyAttributeKind getPropertyAttributes() const { 565e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner return ObjCPropertyAttributeKind(PropertyAttributes); 566e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner } 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) { 5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PropertyAttributes = 569e37b3e6d7ed495fdec4067ccc1117a79d2afd450Chris Lattner (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal); 57082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian const IdentifierInfo *getGetterName() const { return GetterName; } 57382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian IdentifierInfo *getGetterName() { return GetterName; } 57482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian void setGetterName(IdentifierInfo *name) { GetterName = name; } 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian const IdentifierInfo *getSetterName() const { return SetterName; } 57782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian IdentifierInfo *getSetterName() { return SetterName; } 57882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian void setSetterName(IdentifierInfo *name) { SetterName = name; } 57919d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanianprivate: 5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: These two are unrelated and mutially exclusive. So perhaps 58182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian // we can put them in a union to reflect their mutual exclusiveness 58282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian // (space saving is negligible). 583a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCDeclQualifier objcDeclQualifier : 6; 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind 586dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian unsigned PropertyAttributes : 9; 58782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian IdentifierInfo *GetterName; // getter name of NULL if no getter 58882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian IdentifierInfo *SetterName; // setter name of NULL if no setter 58919d74e1494fe399f0e2a94e9419c095f8214851bFariborz Jahanian}; 590eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 5913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor/// \brief Represents a C++ unqualified-id that has been parsed. 5923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorclass UnqualifiedId { 5933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorprivate: 5943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT 5953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 5963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregorpublic: 5973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Describes the kind of unqualified-id parsed. 5983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor enum IdKind { 5993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief An identifier. 6003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_Identifier, 6013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief An overloaded operator name, e.g., operator+. 6023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_OperatorFunctionId, 6033f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A conversion function name, e.g., operator int. 6043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_ConversionFunctionId, 6050486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \brief A user-defined literal name, e.g., operator "" _i. 6060486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt IK_LiteralOperatorId, 6073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A constructor name. 6083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_ConstructorName, 6090efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief A constructor named via a template-id. 6100efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor IK_ConstructorTemplateId, 6113f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A destructor name. 6123f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_DestructorName, 6133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief A template-id, e.g., f<int>. 6143f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IK_TemplateId 6153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } Kind; 6163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Anonymous union that holds extra data associated with the 6183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// parsed unqualified-id. 6193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor union { 6200486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind 6210486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// == IK_UserLiteralId, the identifier suffix. 6223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Identifier; 6233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator 6253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// that we parsed. 6263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor struct { 6273f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief The kind of overloaded operator. 6283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor OverloadedOperatorKind Operator; 6293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief The source locations of the individual tokens that name 6313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// the operator, e.g., the "new", "[", and "]" tokens in 6323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// operator new []. 6333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 6343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// Different operators have different numbers of tokens in their name, 6353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// up to three. Any remaining source locations in this array will be 6363f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// set to an invalid value for operators with fewer than three tokens. 6373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor unsigned SymbolLocations[3]; 6383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } OperatorFunctionId; 6393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_ConversionFunctionId, the type that the 6413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// conversion function names. 642b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType ConversionFunctionId; 6433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_ConstructorName, the class-name of the type 6453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// whose constructor is being referenced. 646b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType ConstructorName; 6473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6483f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief When Kind == IK_DestructorName, the type referred to by the 6493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// class-name. 650b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall UnionParsedType DestructorName; 6513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6520efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId, 6530efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// the template-id annotation that contains the template name and 6540efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template arguments. 6553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor TemplateIdAnnotation *TemplateId; 6563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor }; 6573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6583f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief The location of the first token that describes this unqualified-id, 6593f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// which will be the location of the identifier, "operator" keyword, 6603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// tilde (for a destructor), or the template name of a template-id. 6613f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation StartLocation; 6623f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief The location of the last token that describes this unqualified-id. 6643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLocation; 6653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { } 6673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Do not use this copy constructor. It is temporary, and only 6693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// exists because we are holding FieldDeclarators in a SmallVector when we 6703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// don't actually need them. 6713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 6723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// FIXME: Kill this copy constructor. 6733f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId(const UnqualifiedId &Other) 6743f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor : Kind(IK_Identifier), Identifier(Other.Identifier), 6753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) { 6763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers"); 6773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 6783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Destroy this unqualified-id. 6803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ~UnqualifiedId() { clear(); } 6813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6823f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Clear out this unqualified-id, setting it to default (invalid) 6833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// state. 6843f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void clear(); 6853f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6863f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Determine whether this unqualified-id refers to a valid name. 6873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool isValid() const { return StartLocation.isValid(); } 6883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Determine whether this unqualified-id refers to an invalid name. 6903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool isInvalid() const { return !isValid(); } 6913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Determine what kind of name we have. 6933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdKind getKind() const { return Kind; } 6943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 6953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as an identifier. 6963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 6973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param Id the parsed identifier. 6983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param IdLoc the location of the parsed identifier. 699014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { 7003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_Identifier; 701014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor Identifier = const_cast<IdentifierInfo *>(Id); 7023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = EndLocation = IdLoc; 7033f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 7043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 7053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as an 7063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// operator-function-id. 7073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param OperatorLoc the location of the 'operator' keyword. 7093f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7103f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param Op the overloaded operator. 7113f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7123f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param SymbolLocations the locations of the individual operator symbols 7133f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// in the operator. 7143f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void setOperatorFunctionId(SourceLocation OperatorLoc, 7153f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor OverloadedOperatorKind Op, 7163f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation SymbolLocations[3]); 7173f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 7183f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a 7193f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// conversion-function-id. 7203f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7213f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param OperatorLoc the location of the 'operator' keyword. 7223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param Ty the type to which this conversion function is converting. 7243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param EndLoc the location of the last token that makes up the type name. 7263f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void setConversionFunctionId(SourceLocation OperatorLoc, 727b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty, 7283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLoc) { 7293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_ConversionFunctionId; 7303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = OperatorLoc; 7313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor EndLocation = EndLoc; 7323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ConversionFunctionId = Ty; 7333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 7340486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt 7350486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \brief Specific that this unqualified-id was parsed as a 7360486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// literal-operator-id. 7370486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// 7380486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \param Id the parsed identifier. 7390486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// 7400486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \param OpLoc the location of the 'operator' keyword. 7410486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// 7420486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt /// \param IdLoc the location of the identifier. 7430486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, 7440486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt SourceLocation IdLoc) { 7450486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt Kind = IK_LiteralOperatorId; 7460486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt Identifier = const_cast<IdentifierInfo *>(Id); 7470486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt StartLocation = OpLoc; 7480486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt EndLocation = IdLoc; 7490486d746019f8310589b1f0d92edcc4bb3916b33Sean Hunt } 7503f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 7513f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a constructor name. 7523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param ClassType the class type referred to by the constructor name. 7543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param ClassNameLoc the location of the class name. 7563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param EndLoc the location of the last token that makes up the type name. 758b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setConstructorName(ParsedType ClassType, 7593f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation ClassNameLoc, 7603f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLoc) { 7613f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_ConstructorName; 7623f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = ClassNameLoc; 7633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor EndLocation = EndLoc; 7643f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor ConstructorName = ClassType; 7653f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 7663f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 7670efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Specify that this unqualified-id was parsed as a 7680efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that names a constructor. 7690efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// 7700efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \param TemplateId the template-id annotation that describes the parsed 7710efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id. This UnqualifiedId instance will take ownership of the 7720efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \p TemplateId and will free it on destruction. 7730efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor void setConstructorTemplateId(TemplateIdAnnotation *TemplateId); 7740efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 7753f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a destructor name. 7763f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7773f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param TildeLoc the location of the '~' that introduces the destructor 7783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// name. 7793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param ClassType the name of the class referred to by the destructor name. 781b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setDestructorName(SourceLocation TildeLoc, 782b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ClassType, 7833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation EndLoc) { 7843f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Kind = IK_DestructorName; 7853f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor StartLocation = TildeLoc; 7863f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor EndLocation = EndLoc; 7873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor DestructorName = ClassType; 7883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 7893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 7903f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Specify that this unqualified-id was parsed as a template-id. 7913f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// 7923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \param TemplateId the template-id annotation that describes the parsed 7933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// template-id. This UnqualifiedId instance will take ownership of the 7943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \p TemplateId and will free it on destruction. 795314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor void setTemplateId(TemplateIdAnnotation *TemplateId); 7963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 7973f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Return the source range that covers this unqualified-id. 7983f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceRange getSourceRange() const { 7993f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return SourceRange(StartLocation, EndLocation); 8003f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor } 8013f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor}; 8023f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 80372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor/// CachedTokens - A set of tokens that has been cached for later 80472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor/// parsing. 80572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregortypedef llvm::SmallVector<Token, 4> CachedTokens; 80672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclaratorChunk - One instance of this struct is used for each type in a 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// declarator that is parsed. 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This is intended to be a small value object. 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerstruct DeclaratorChunk { 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum { 813075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } Kind; 815f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Loc - The place where this type was defined. 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// EndLoc - If valid, the place where this chunck ends. 8197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation EndLoc; 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct TypeInfoCommon { 8227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall AttributeList *AttrList; 8237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall }; 8247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 8257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct PointerTypeInfo : TypeInfoCommon { 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// The type qualifiers: const/volatile/restrict. 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned TypeQuals : 3; 8287654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner void destroy() { 8297654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner } 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ReferenceTypeInfo : TypeInfoCommon { 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// The type qualifier: restrict. [GNU] C++ extension 83405532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl bool HasRestrict : 1; 83505532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl /// True if this is an lvalue reference, false if it's an rvalue reference. 83605532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl bool LValueRef : 1; 8377654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner void destroy() { 8387654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner } 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ArrayTypeInfo : TypeInfoCommon { 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// The type qualifiers for the array: const/volatile/restrict. 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned TypeQuals : 3; 8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// True if this dimension included the 'static' keyword. 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool hasStatic : 1; 8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// True if this dimension was [*]. In this case, NumElts is null. 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isStar : 1; 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This is the size of the array, or null if [] or [*] was specified. 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Since the parser is multi-purpose, and we don't want to impose a root 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression class on all clients, NumElts is untyped. 854ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *NumElts; 8557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void destroy() {} 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParamInfo - An array of paraminfo objects is allocated whenever a function 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// declarator is parsed. There are two interesting styles of arguments here: 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// K&R-style identifier lists and parameter type lists. K&R-style identifier 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lists will have information about the identifier, but no type information. 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Parameter type lists will have type info (if the actions module provides 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'. 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer struct ParamInfo { 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IdentifierInfo *Ident; 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation IdentLoc; 868d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 86972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 87072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgTokens - When the parameter's default argument 87172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// cannot be parsed immediately (because it occurs within the 87272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// declaration of a member function), it will be stored here as a 87372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// sequence of tokens to be parsed once the class definition is 87472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// complete. Non-NULL indicates that there is a default argument. 8755af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner CachedTokens *DefaultArgTokens; 87672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParamInfo() {} 878b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner ParamInfo(IdentifierInfo *ident, SourceLocation iloc, 879d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *param, 88072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *DefArgTokens = 0) 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ident(ident), IdentLoc(iloc), Param(param), 88272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor DefaultArgTokens(DefArgTokens) {} 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 884ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl 885ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl struct TypeAndRange { 886b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType Ty; 887ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl SourceRange Range; 888ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl }; 889ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl 8907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct FunctionTypeInfo : TypeInfoCommon { 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasPrototype - This is true if the function had at least one typed 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// argument. If the function is () or (a,b,c), then it has no prototype, 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and is treated as a K&R-style function. 8947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned hasPrototype : 1; 8957dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 896965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor /// isVariadic - If this function has a prototype, and if that 897965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor /// proto ends with ',...)', this is true. When true, EllipsisLoc 898965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor /// contains the location of the ellipsis. 8997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned isVariadic : 1; 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 90183f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief Whether the ref-qualifier (if any) is an lvalue reference. 90283f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// Otherwise, it's an rvalue reference. 90383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor unsigned RefQualifierIsLValueRef : 1; 90483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor 905971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// The type qualifiers: const/volatile/restrict. 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// The qualifier bitmask values are the same as in QualType. 907971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 908971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 9097dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl /// hasExceptionSpec - True if the function has an exception specification. 9107f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned hasExceptionSpec : 1; 9117dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 9127dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl /// hasAnyExceptionSpec - True if the function has a throw(...) specifier. 9137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned hasAnyExceptionSpec : 1; 9147dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 9155af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo. 9167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall unsigned DeleteArgInfo : 1; 9175af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner 9187dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl /// When isVariadic is true, the location of the ellipsis in the source. 9197dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl unsigned EllipsisLoc; 9207dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - This is the number of formal arguments provided for the 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// declarator. 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9257dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl /// NumExceptions - This is the number of types in the exception-decl, if 9267dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl /// the function has one. 9277dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl unsigned NumExceptions; 9287dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 92983f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief The location of the ref-qualifier, if any. 93083f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// 93183f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// If this is an invalid location, there is no ref-qualifier. 93283f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor unsigned RefQualifierLoc; 93383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor 9343cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl /// ThrowLoc - When hasExceptionSpec is true, the location of the throw 9353cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl /// keyword introducing the spec. 9363cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl unsigned ThrowLoc; 9373cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// describe the arguments for this function declarator. This is null if 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// there are no arguments specified. 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParamInfo *ArgInfo; 9427dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 943ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl /// Exceptions - This is a pointer to a new[]'d array of TypeAndRange 944ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl /// objects that contain the types in the function's exception 945ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl /// specification and their locations. 946ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeAndRange *Exceptions; 9477dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 948dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor /// TrailingReturnType - If this isn't null, it's the trailing return type 949dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor /// specified. This is actually a ParsedType, but stored as void* to 950dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor /// allow union storage. 951dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor void *TrailingReturnType; 952dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 9531833a83368bda46b76388069e52b27f12e60dc9cChris Lattner /// freeArgs - reset the argument list to having zero arguments. This is 9541833a83368bda46b76388069e52b27f12e60dc9cChris Lattner /// used in various places for error recovery. 9551833a83368bda46b76388069e52b27f12e60dc9cChris Lattner void freeArgs() { 9561833a83368bda46b76388069e52b27f12e60dc9cChris Lattner if (DeleteArgInfo) { 9571833a83368bda46b76388069e52b27f12e60dc9cChris Lattner delete[] ArgInfo; 9581833a83368bda46b76388069e52b27f12e60dc9cChris Lattner DeleteArgInfo = false; 9591833a83368bda46b76388069e52b27f12e60dc9cChris Lattner } 9601833a83368bda46b76388069e52b27f12e60dc9cChris Lattner NumArgs = 0; 9611833a83368bda46b76388069e52b27f12e60dc9cChris Lattner } 9627dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void destroy() { 9645af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner if (DeleteArgInfo) 9655af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner delete[] ArgInfo; 9667dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl delete[] Exceptions; 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 968965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor 969004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner /// isKNRPrototype - Return true if this is a K&R style identifier list, 970004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner /// like "void foo(a,b,c)". In a function definition, this will be followed 971004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner /// by the argument type definitions. 972004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isKNRPrototype() const { 973004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner return !hasPrototype && NumArgs != 0; 974004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner } 975004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner 976965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor SourceLocation getEllipsisLoc() const { 977965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor return SourceLocation::getFromRawEncoding(EllipsisLoc); 978965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor } 9793cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl SourceLocation getThrowLoc() const { 9803cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl return SourceLocation::getFromRawEncoding(ThrowLoc); 9813cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl } 98283f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor 98383f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief Retrieve the location of the ref-qualifier, if any. 98483f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor SourceLocation getRefQualifierLoc() const { 98583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor return SourceLocation::getFromRawEncoding(RefQualifierLoc); 98683f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor } 98783f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor 98883f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// \brief Determine whether this function declaration contains a 98983f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor /// ref-qualifier. 99083f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); } 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 9937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct BlockPointerTypeInfo : TypeInfoCommon { 9945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff /// For now, sema will catch these as invalid. 9955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff /// The type qualifiers: const/volatile/restrict. 9965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff unsigned TypeQuals : 3; 9977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 99875b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump void destroy() { 99975b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump } 10005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff }; 10015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 10027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct MemberPointerTypeInfo : TypeInfoCommon { 1003f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The type qualifiers: const/volatile/restrict. 1004f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl unsigned TypeQuals : 3; 1005f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // CXXScopeSpec has a constructor, so it can't be a direct member. 1006f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // So we need some pointer-aligned storage and a bit of trickery. 1007f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl union { 1008f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *Aligner; 1009f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl char Mem[sizeof(CXXScopeSpec)]; 1010f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } ScopeMem; 1011f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl CXXScopeSpec &Scope() { 1012f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem); 1013f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1014f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const CXXScopeSpec &Scope() const { 1015f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem); 1016f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1017f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void destroy() { 1018f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Scope().~CXXScopeSpec(); 1019f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1020f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl }; 1021f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer union { 1023711c52bb20d0c69063b52a99826fb7d2835501f1John McCall TypeInfoCommon Common; 1024f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointerTypeInfo Ptr; 1025f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ReferenceTypeInfo Ref; 1026f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ArrayTypeInfo Arr; 1027f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl FunctionTypeInfo Fun; 1028f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl BlockPointerTypeInfo Cls; 1029f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypeInfo Mem; 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1031f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 10325af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner void destroy() { 10335af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner switch (Kind) { 10345af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner default: assert(0 && "Unknown decl type!"); 1035f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Function: return Fun.destroy(); 1036f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Pointer: return Ptr.destroy(); 1037f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::BlockPointer: return Cls.destroy(); 1038f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Reference: return Ref.destroy(); 1039f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::Array: return Arr.destroy(); 1040f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case DeclaratorChunk::MemberPointer: return Mem.destroy(); 1041075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Paren: return; 10425af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner } 10435af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner } 1044f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1045e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner /// getAttrs - If there are attributes applied to this declaratorchunk, return 1046e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner /// them. 1047e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner const AttributeList *getAttrs() const { 1048711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return Common.AttrList; 1049e5c5ee1cff9ec084f176fa252774262677857ad2Chris Lattner } 1050f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1051711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&getAttrListRef() { 1052711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return Common.AttrList; 1053711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 1054f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getPointer - Return a DeclaratorChunk for a pointer. 10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 10577654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, 10587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &attrs) { 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk I; 10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Kind = Pointer; 10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Loc = Loc; 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Ptr.TypeQuals = TypeQuals; 10637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall I.Ptr.AttrList = attrs.getList(); 10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return I; 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getReference - Return a DeclaratorChunk for a reference. 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 10697654914fc5c6e2683d9e7358a64b3b53f368a8fcChris Lattner static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, 10707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &attrs, 10717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool lvalue) { 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk I; 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Kind = Reference; 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Loc = Loc; 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0; 107605532f2a88161eb6d9b796614f1b82dca541ff22Sebastian Redl I.Ref.LValueRef = lvalue; 10777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall I.Ref.AttrList = attrs.getList(); 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return I; 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArray - Return a DeclaratorChunk for an array. 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 10837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall static DeclaratorChunk getArray(unsigned TypeQuals, 10847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &attrs, 10857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool isStatic, bool isStar, Expr *NumElts, 10867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation LBLoc, SourceLocation RBLoc) { 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk I; 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Kind = Array; 10897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor I.Loc = LBLoc; 10907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor I.EndLoc = RBLoc; 10917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall I.Arr.AttrList = attrs.getList(); 10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.TypeQuals = TypeQuals; 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.hasStatic = isStatic; 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.isStar = isStar; 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer I.Arr.NumElts = NumElts; 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return I; 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10995af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. 11005af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// "TheDeclarator" is the declarator that this will be added to. 11017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall static DeclaratorChunk getFunction(const ParsedAttributes &attrs, 11027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall bool hasProto, bool isVariadic, 1103965acbb321e94e36aa5365126eee46b97745fdbbDouglas Gregor SourceLocation EllipsisLoc, 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParamInfo *ArgInfo, unsigned NumArgs, 110583f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor unsigned TypeQuals, 110683f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor bool RefQualifierIsLvalueRef, 110783f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor SourceLocation RefQualifierLoc, 110883f51722ed2b8134810cb178f39e44da811de7cdDouglas Gregor bool hasExceptionSpec, 11093cc9726a493d90bd8faf094986a59352fd3461cbSebastian Redl SourceLocation ThrowLoc, 11107dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool hasAnyExceptionSpec, 1111b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType *Exceptions, 1112ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl SourceRange *ExceptionRanges, 111382bf01061b97404fed8c422fc0eda0a380689cc9Argyrios Kyrtzidis unsigned NumExceptions, 111482bf01061b97404fed8c422fc0eda0a380689cc9Argyrios Kyrtzidis SourceLocation LPLoc, SourceLocation RPLoc, 1115dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor Declarator &TheDeclarator, 1116dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ParsedType TrailingReturnType = ParsedType()); 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff /// getBlockPointer - Return a DeclaratorChunk for a block. 11195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff /// 112075b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump static DeclaratorChunk getBlockPointer(unsigned TypeQuals, SourceLocation Loc, 11217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &attrs) { 11225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff DeclaratorChunk I; 11235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff I.Kind = BlockPointer; 11245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff I.Loc = Loc; 11255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff I.Cls.TypeQuals = TypeQuals; 11267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall I.Cls.AttrList = attrs.getList(); 11275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return I; 11285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 1129f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1130f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, 1131f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl unsigned TypeQuals, 1132f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl SourceLocation Loc, 11337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall const ParsedAttributes &attrs) { 1134f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl DeclaratorChunk I; 1135f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl I.Kind = MemberPointer; 1136f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl I.Loc = Loc; 1137f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl I.Mem.TypeQuals = TypeQuals; 11387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall I.Mem.AttrList = attrs.getList(); 1139f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS); 1140f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return I; 1141f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1142075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1143075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// getParen - Return a DeclaratorChunk for a paren. 1144075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 1145075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara static DeclaratorChunk getParen(SourceLocation LParenLoc, 1146075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceLocation RParenLoc) { 1147075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara DeclaratorChunk I; 1148075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara I.Kind = Paren; 1149075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara I.Loc = LParenLoc; 1150075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara I.EndLoc = RParenLoc; 1151711c52bb20d0c69063b52a99826fb7d2835501f1John McCall I.Common.AttrList = 0; 1152075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return I; 1153075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1154075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Declarator - Information about one declarator, including the parsed type 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information and the identifier. When the declarator is fully formed, this 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is turned into the appropriate Decl object. 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Declarators come in two types: normal declarators and abstract declarators. 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Abstract declarators are used when parsing types, and don't have an 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// identifier. Normal declarators do have ID's. 11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1165e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner/// Instances of this class should be a transient object that lives on the 1166e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner/// stack, not objects that are allocated in large quantities on the heap. 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Declarator { 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11692d3dfd70eee48005f253b72d288e0eb4ed754fe0Zhongxing Xu enum TheContext { 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileContext, // File scope declaration. 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PrototypeContext, // Within a function prototype. 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer KNRTypeListContext, // K&R type definition list for formals. 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypeNameContext, // Abstract declarator for types. 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MemberContext, // Struct/Union field. 11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BlockContext, // Declaration within a block in a function. 117671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis ForContext, // Declaration within first part of a for loop. 117726236e8b7507017fded05da3474d842e802a1679Douglas Gregor ConditionContext, // Condition declaration in a C++ if/switch/while/for. 1178a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl TemplateParamContext,// Within a template parameter list. 117998eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump CXXCatchContext, // C++ catch exception-declaration 1180683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor BlockLiteralContext, // Block literal declarator. 1181683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor TemplateTypeArgContext // Template type argument. 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 118342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 11855af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner const DeclSpec &DS; 11865af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner CXXScopeSpec SS; 11873f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId Name; 1188ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl SourceRange Range; 1189ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Context - Where we are parsing this declarator. 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TheContext Context; 119342a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclTypeInfo - This holds each type that the declarator includes as it is 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// parsed. This is pushed from the identifier out, which means that element 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #0 will be the most closely bound to the identifier, and 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// DeclTypeInfo.back() will be the least closely bound. 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<DeclaratorChunk, 8> DeclTypeInfo; 11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1200ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// InvalidType - Set by Sema::GetTypeForDeclarator(). 120173a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool InvalidType : 1; 120273a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis 120373a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis /// GroupingParens - Set by Parser::ParseParenDeclarator(). 120473a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool GroupingParens : 1; 1205e1223f7246c2c297f7b62816fd8c6a0a14151977Steve Naroff 1206914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar /// AttrList - Attributes. 1207e1223f7246c2c297f7b62816fd8c6a0a14151977Steve Naroff AttributeList *AttrList; 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1209914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar /// AsmLabel - The asm label, if specified. 1210b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *AsmLabel; 121142a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 12125af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// InlineParams - This is a local array used for the first function decl 12135af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// chunk to avoid going to the heap for the common case when we have one 12145af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner /// function chunk in the declarator. 12155af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner DeclaratorChunk::ParamInfo InlineParams[16]; 12165af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner bool InlineParamsUsed; 1217ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 121891a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor /// Extension - true if the declaration is preceded by __extension__. 121991a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor bool Extension : 1; 122091a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor 1221a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor /// \brief If provided, the source location of the ellipsis used to describe 1222a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor /// this declarator as a parameter pack. 1223a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor SourceLocation EllipsisLoc; 1224a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor 122543af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl friend struct DeclaratorChunk; 1226ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1228e1449e51016fa7868d241c9e451253929d188bb9Argyrios Kyrtzidis Declarator(const DeclSpec &ds, TheContext C) 12293f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor : DS(ds), Range(ds.getSourceRange()), Context(C), 1230ddc29e116db3c3f4144355e67a0137b38b6bb6d1Douglas Gregor InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), 12313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor GroupingParens(false), AttrList(0), AsmLabel(0), 123291a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor InlineParamsUsed(false), Extension(false) { 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Declarator() { 12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer clear(); 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getDeclSpec - Return the declaration-specifier that this declarator was 12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// declared with. 1241985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner const DeclSpec &getDeclSpec() const { return DS; } 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1243985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This 1244985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// should be used with extreme care: declspecs can often be shared between 1245985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// multiple declarators, so mutating the DeclSpec affects all of the 1246985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// Declarators. This should only be done when the declspec is known to not 1247985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner /// be shared or when in error recovery etc. 1248e1449e51016fa7868d241c9e451253929d188bb9Argyrios Kyrtzidis DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); } 1249985abd958d83e4f109a15451440f1d008ae45f59Chris Lattner 1250eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// getCXXScopeSpec - Return the C++ scope specifier (global scope or 1251eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// nested-name-specifier) that is part of the declarator-id. 1252eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis const CXXScopeSpec &getCXXScopeSpec() const { return SS; } 1253eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis CXXScopeSpec &getCXXScopeSpec() { return SS; } 1254eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 12553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Retrieve the name specified by this declarator. 12563f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &getName() { return Name; } 12573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TheContext getContext() const { return Context; } 125942a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 1260ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// getSourceRange - Get the source range that spans this declarator. 1261ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl const SourceRange &getSourceRange() const { return Range; } 1262ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 1263ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void SetSourceRange(SourceRange R) { Range = R; } 1264ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// SetRangeBegin - Set the start of the source range to Loc, unless it's 1265ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// invalid. 1266ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void SetRangeBegin(SourceLocation Loc) { 1267ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!Loc.isInvalid()) 1268ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setBegin(Loc); 1269ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 1270ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid. 1271ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void SetRangeEnd(SourceLocation Loc) { 1272ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!Loc.isInvalid()) 1273ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setEnd(Loc); 1274ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 1275ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// ExtendWithDeclSpec - Extend the declarator source range to include the 1276ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// given declspec, unless its location is invalid. Adopts the range start if 1277ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// the current range start is invalid. 1278ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void ExtendWithDeclSpec(const DeclSpec &DS) { 1279ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl const SourceRange &SR = DS.getSourceRange(); 1280ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (Range.getBegin().isInvalid()) 1281ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setBegin(SR.getBegin()); 1282ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!SR.getEnd().isInvalid()) 1283ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range.setEnd(SR.getEnd()); 1284ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl } 1285ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clear - Reset the contents of this Declarator. 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void clear() { 1288eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis SS.clear(); 12893f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Name.clear(); 1290ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl Range = DS.getSourceRange(); 1291db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor 12925af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i) 12935af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner DeclTypeInfo[i].destroy(); 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclTypeInfo.clear(); 12951b4a6227f3ee6fca074d0f521757d1ed4f95ef38Steve Naroff AttrList = 0; 1296107450c6d846b2da5ecefbb088942e9478a83de7Argyrios Kyrtzidis AsmLabel = 0; 12975af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner InlineParamsUsed = false; 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// mayOmitIdentifier - Return true if the identifier is either optional or 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// not allowed. This is true for typenames, prototypes, and template 130226236e8b7507017fded05da3474d842e802a1679Douglas Gregor /// parameter lists. 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool mayOmitIdentifier() const { 130426236e8b7507017fded05da3474d842e802a1679Douglas Gregor return Context == TypeNameContext || Context == PrototypeContext || 130598eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump Context == TemplateParamContext || Context == CXXCatchContext || 1306683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Context == BlockLiteralContext || Context == TemplateTypeArgContext; 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// mayHaveIdentifier - Return true if the identifier is either optional or 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// required. This is true for normal declarators and prototypes, but not 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// typenames. 13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool mayHaveIdentifier() const { 1313683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor return Context != TypeNameContext && Context != BlockLiteralContext && 1314683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Context != TemplateTypeArgContext; 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 131673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis 131773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be 131873a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis /// followed by a C++ direct initializer, e.g. "int x(1);". 131973a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool mayBeFollowedByCXXDirectInit() const { 132073a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis return !hasGroupingParens() && 132173a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis (Context == FileContext || 132273a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis Context == BlockContext || 13235af2f35c6ad1cb78b2aed3705d221954d1689b8aChris Lattner Context == ForContext); 132473a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis } 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPastIdentifier - Return true if we have parsed beyond the point where 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the 13283f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool isPastIdentifier() const { return Name.isValid(); } 132910bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor 133010bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// hasName - Whether this declarator has a name, which might be an 133110bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// identifier (accessible via getIdentifier()) or some kind of 133210bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// special C++ name (constructor, destructor, etc.). 13333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool hasName() const { 13343f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier; 133542a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor } 133642a552f8200ba5948661aee0106fce0c04e39818Douglas Gregor 13373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *getIdentifier() const { 13383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor if (Name.getKind() == UnqualifiedId::IK_Identifier) 13393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return Name.Identifier; 13403f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 13413f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor return 0; 1342e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 13433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation getIdentifierLoc() const { return Name.StartLocation; } 1344ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 13453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor /// \brief Set the name of this declarator to be the given identifier. 13463f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) { 13473f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor Name.setIdentifier(Id, IdLoc); 1348db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor } 13493f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 1350ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 1351ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// EndLoc, which should be the last token of the chunk. 1352ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) { 13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclTypeInfo.push_back(TI); 1354ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!EndLoc.isInvalid()) 1355ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl SetRangeEnd(EndLoc); 13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1357ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 1358711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator. 1359711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void AddInnermostTypeInfo(const DeclaratorChunk &TI) { 1360711c52bb20d0c69063b52a99826fb7d2835501f1John McCall DeclTypeInfo.insert(DeclTypeInfo.begin(), TI); 1361711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 1362711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumTypeObjects() - Return the number of types applied to this 13645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// declarator. 13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); } 13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Return the specified TypeInfo from this declarator. TypeInfo #0 is 13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// closest to the identifier. 13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DeclaratorChunk &getTypeObject(unsigned i) const { 13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return DeclTypeInfo[i]; 13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DeclaratorChunk &getTypeObject(unsigned i) { 13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return DeclTypeInfo[i]; 13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13788ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl void DropFirstTypeObject() 13798ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl { 13808ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl assert(!DeclTypeInfo.empty() && "No type chunks to drop."); 13818ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl DeclTypeInfo.front().destroy(); 13828ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl DeclTypeInfo.erase(DeclTypeInfo.begin()); 13838ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl } 13848ce35b095e8fca45e04c1bda14ed0548ce7536adSebastian Redl 1385075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// isFunctionDeclarator - This method returns true if the declarator 1386075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// is a function declarator (looking through parentheses). 1387075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// If true is returned, then the reference type parameter idx is 1388075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// assigned with the index of the declaration chunk. 1389075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara bool isFunctionDeclarator(unsigned& idx) const { 1390075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1391075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara switch (DeclTypeInfo[i].Kind) { 1392075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Function: 1393075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara idx = i; 1394075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return true; 1395075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Paren: 1396075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara continue; 1397075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Pointer: 1398075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Reference: 1399075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::Array: 1400075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::BlockPointer: 1401075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case DeclaratorChunk::MemberPointer: 1402075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return false; 1403075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1404075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara llvm_unreachable("Invalid type chunk"); 1405075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return false; 1406075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1407075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return false; 1408075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1409075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isFunctionDeclarator - Once this declarator is fully parsed and formed, 1411075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// this method returns true if the identifier is a function declarator 1412075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// (looking through parentheses). 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFunctionDeclarator() const { 1414075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara unsigned index; 1415075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return isFunctionDeclarator(index); 1416075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1417075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1418075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// getFunctionTypeInfo - Retrieves the function type info object 1419075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// (looking through parentheses). 1420075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() { 1421075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara assert(isFunctionDeclarator() && "Not a function declarator!"); 14225aea91b09bdb36fba4e36c2766f3d5f9127d1e61Douglas Gregor unsigned index = 0; 1423075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara isFunctionDeclarator(index); 1424075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return DeclTypeInfo[index].Fun; 1425075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 1426075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 1427075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// getFunctionTypeInfo - Retrieves the function type info object 1428075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// (looking through parentheses). 1429075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const { 1430075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return const_cast<Declarator*>(this)->getFunctionTypeInfo(); 14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AddAttributes - simply adds the attribute list to the Declarator. 1434aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// These examples both add 3 attributes to "var": 1435aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// short int var __attribute__((aligned(16),common,deprecated)); 1436aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// short int x, __attribute__((aligned(16)) var 1437aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner /// __attribute__((common,deprecated)); 14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1439ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl /// Also extends the range of the declarator. 14407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void addAttributes(AttributeList *alist, SourceLocation LastLoc) { 1441ac25503714ba1a384d4f1cae05b84bc785eb5fadDouglas Gregor AttrList = addAttributeLists(AttrList, alist); 1442ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl 1443ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl if (!LastLoc.isInvalid()) 1444ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl SetRangeEnd(LastLoc); 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void addAttributes(const ParsedAttributes &attrs) { 14487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall addAttributes(attrs.getList(), SourceLocation()); 14497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 14507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1451e6bec8a6e99bcc9894b3a8bc54434eca4cbe6a6eChris Lattner const AttributeList *getAttributes() const { return AttrList; } 1452e6bec8a6e99bcc9894b3a8bc54434eca4cbe6a6eChris Lattner AttributeList *getAttributes() { return AttrList; } 1453914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar 1454711c52bb20d0c69063b52a99826fb7d2835501f1John McCall AttributeList *&getAttrListRef() { return AttrList; } 1455711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 1456478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn /// hasAttributes - do we contain any attributes? 1457478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn bool hasAttributes() const { 14587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getAttributes() || getDeclSpec().hasAttributes()) return true; 1459478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i) 1460478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn if (getTypeObject(i).getAttrs()) 1461478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn return true; 1462478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn return false; 1463478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn } 1464478fbc68b1873678edfb2a3c420749635db100e6Ryan Flynn 1465b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall void setAsmLabel(Expr *E) { AsmLabel = E; } 1466b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *getAsmLabel() const { return AsmLabel; } 1467914701ed49f31323176a784b49df05a0d177d1adDaniel Dunbar 146891a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor void setExtension(bool Val = true) { Extension = Val; } 146991a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor bool getExtension() const { return Extension; } 147091a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor 1471eaaebc7cf10dc1a2016183a262ad3256bc468759Chris Lattner void setInvalidType(bool Val = true) { InvalidType = Val; } 14721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isInvalidType() const { 14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error; 1474cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor } 147573a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis 147673a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis void setGroupingParens(bool flag) { GroupingParens = flag; } 147773a0d889eda0f000a441319e39540509175b8e81Argyrios Kyrtzidis bool hasGroupingParens() const { return GroupingParens; } 1478a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor 1479a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor bool hasEllipsis() const { return EllipsisLoc.isValid(); } 1480a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 1481a8bc8c9e9ba5bffebde00340786fe8542469c435Douglas Gregor void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1484e13594279a952537ac903325efff57e3edca79d9Chris Lattner/// FieldDeclarator - This little struct is used to capture information about 1485e13594279a952537ac903325efff57e3edca79d9Chris Lattner/// structure field declarators, which is basically just a bitfield size. 1486e13594279a952537ac903325efff57e3edca79d9Chris Lattnerstruct FieldDeclarator { 1487e13594279a952537ac903325efff57e3edca79d9Chris Lattner Declarator D; 1488b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Expr *BitfieldSize; 1489ebe457c3443af253bc14ae77c2013b088370a66bChris Lattner explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) { 1490e13594279a952537ac903325efff57e3edca79d9Chris Lattner BitfieldSize = 0; 1491e13594279a952537ac903325efff57e3edca79d9Chris Lattner } 1492e13594279a952537ac903325efff57e3edca79d9Chris Lattner}; 1493b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1494c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson/// VirtSpecifiers - Represents a C++0x virt-specifier-seq. 1495b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonclass VirtSpecifiers { 1496b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonpublic: 1497cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson enum Specifier { 1498b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VS_None = 0, 1499b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VS_Override = 1, 1500b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VS_Final = 2, 1501b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VS_New = 4 1502b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson }; 1503b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1504b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson VirtSpecifiers() : Specifiers(0) { } 1505b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1506cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson bool SetSpecifier(Specifier VS, SourceLocation Loc, 150746127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson const char *&PrevSpec); 1508b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1509aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson bool isOverrideSpecified() const { return Specifiers & VS_Override; } 1510aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson SourceLocation getOverrideLoc() const { return VS_overrideLoc; } 1511aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson 1512aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson bool isFinalSpecified() const { return Specifiers & VS_Final; } 1513aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson SourceLocation getFinalLoc() const { return VS_finalLoc; } 1514aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson 1515aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson bool isNewSpecified() const { return Specifiers & VS_New; } 1516aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson SourceLocation getNewLoc() const { return VS_newLoc; } 1517aae5af24f031ad5f17872bd8b27ed5c175c0f90cAnders Carlsson 15184867347e82648d3baf09524b98b09c297a5a198fNico Weber void clear() { Specifiers = 0; } 15194867347e82648d3baf09524b98b09c297a5a198fNico Weber 1520ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson static const char *getSpecifierName(Specifier VS); 1521ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson 1522b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlssonprivate: 1523b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson unsigned Specifiers; 1524b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1525b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson SourceLocation VS_overrideLoc, VS_finalLoc, VS_newLoc; 1526b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson}; 1527b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson 1528c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson/// ClassVirtSpecifiers - Represents a C++0x class-virt-specifier-seq. 1529c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlssonclass ClassVirtSpecifiers { 1530c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlssonpublic: 1531cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson enum Specifier { 1532c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson CVS_None = 0, 1533c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson CVS_Final = 1, 1534c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson CVS_Explicit = 2 1535c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson }; 1536c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson 1537c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson ClassVirtSpecifiers() : Specifiers(0) { } 1538c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson 1539cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson bool SetSpecifier(Specifier CVS, SourceLocation Loc, 154046127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson const char *&PrevSpec); 154146127a96b6dd6b93aa18d5f7a55bc2db8b52a2c9Anders Carlsson 1542c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson bool isFinalSpecified() const { return Specifiers & CVS_Final; } 1543c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson SourceLocation getFinalLoc() const { return CVS_finalLoc; } 1544c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson 1545c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson bool isExplicitSpecified() const { return Specifiers & CVS_Explicit; } 1546c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson SourceLocation getExplicitLoc() const { return CVS_explicitLoc; } 1547c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson 1548ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson static const char *getSpecifierName(Specifier CVS); 1549ce93a7cee6c0ea979c12b278771a79c4d6a37fc0Anders Carlsson 1550c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlssonprivate: 1551c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson unsigned Specifiers; 1552c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson 1553c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson SourceLocation CVS_finalLoc, CVS_explicitLoc; 1554c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson}; 1555c46bb7d098bf9e9f0258bf2bb97d8f0f7d382288Anders Carlsson 155637387c932855c6d58d70bdd705cd3a9fdcd2a931Steve Naroff} // end namespace clang 15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1559