Specifiers.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// Defines various enumerations that describe declaration and
  16. /// type specifiers.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CLANG_BASIC_SPECIFIERS_H
  20. #define LLVM_CLANG_BASIC_SPECIFIERS_H
  21. #include "llvm/ADT/StringRef.h"
  22. #include "llvm/Support/DataTypes.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. namespace clang {
  25. /// Define the meaning of possible values of the kind in ExplicitSpecifier.
  26. enum class ExplicitSpecKind : unsigned {
  27. ResolvedFalse,
  28. ResolvedTrue,
  29. Unresolved,
  30. };
  31. /// Define the kind of constexpr specifier.
  32. enum class ConstexprSpecKind { Unspecified, Constexpr, Consteval, Constinit };
  33. /// In an if statement, this denotes whether the the statement is
  34. /// a constexpr or consteval if statement.
  35. enum class IfStatementKind : unsigned {
  36. Ordinary,
  37. Constexpr,
  38. ConstevalNonNegated,
  39. ConstevalNegated
  40. };
  41. /// Specifies the width of a type, e.g., short, long, or long long.
  42. enum class TypeSpecifierWidth { Unspecified, Short, Long, LongLong };
  43. /// Specifies the signedness of a type, e.g., signed or unsigned.
  44. enum class TypeSpecifierSign { Unspecified, Signed, Unsigned };
  45. enum class TypeSpecifiersPipe { Unspecified, Pipe };
  46. /// Specifies the kind of type.
  47. enum TypeSpecifierType {
  48. TST_unspecified,
  49. TST_void,
  50. TST_char,
  51. TST_wchar, // C++ wchar_t
  52. TST_char8, // C++20 char8_t (proposed)
  53. TST_char16, // C++11 char16_t
  54. TST_char32, // C++11 char32_t
  55. TST_int,
  56. TST_int128,
  57. TST_bitint, // Bit-precise integer types.
  58. TST_half, // OpenCL half, ARM NEON __fp16
  59. TST_Float16, // C11 extension ISO/IEC TS 18661-3
  60. TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension
  61. TST_Fract,
  62. TST_BFloat16,
  63. TST_float,
  64. TST_double,
  65. TST_float128,
  66. TST_ibm128,
  67. TST_bool, // _Bool
  68. TST_decimal32, // _Decimal32
  69. TST_decimal64, // _Decimal64
  70. TST_decimal128, // _Decimal128
  71. TST_enum,
  72. TST_union,
  73. TST_struct,
  74. TST_class, // C++ class type
  75. TST_interface, // C++ (Microsoft-specific) __interface type
  76. TST_typename, // Typedef, C++ class-name or enum name, etc.
  77. TST_typeofType,
  78. TST_typeofExpr,
  79. TST_decltype, // C++11 decltype
  80. TST_underlyingType, // __underlying_type for C++11
  81. TST_auto, // C++11 auto
  82. TST_decltype_auto, // C++1y decltype(auto)
  83. TST_auto_type, // __auto_type extension
  84. TST_unknown_anytype, // __unknown_anytype extension
  85. TST_atomic, // C11 _Atomic
  86. #define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image types
  87. #include "clang/Basic/OpenCLImageTypes.def"
  88. TST_error // erroneous type
  89. };
  90. /// Structure that packs information about the type specifiers that
  91. /// were written in a particular type specifier sequence.
  92. struct WrittenBuiltinSpecs {
  93. static_assert(TST_error < 1 << 6, "Type bitfield not wide enough for TST");
  94. /*DeclSpec::TST*/ unsigned Type : 6;
  95. /*DeclSpec::TSS*/ unsigned Sign : 2;
  96. /*TypeSpecifierWidth*/ unsigned Width : 2;
  97. unsigned ModeAttr : 1;
  98. };
  99. /// A C++ access specifier (public, private, protected), plus the
  100. /// special value "none" which means different things in different contexts.
  101. enum AccessSpecifier {
  102. AS_public,
  103. AS_protected,
  104. AS_private,
  105. AS_none
  106. };
  107. /// The categorization of expression values, currently following the
  108. /// C++11 scheme.
  109. enum ExprValueKind {
  110. /// A pr-value expression (in the C++11 taxonomy)
  111. /// produces a temporary value.
  112. VK_PRValue,
  113. /// An l-value expression is a reference to an object with
  114. /// independent storage.
  115. VK_LValue,
  116. /// An x-value expression is a reference to an object with
  117. /// independent storage but which can be "moved", i.e.
  118. /// efficiently cannibalized for its resources.
  119. VK_XValue
  120. };
  121. /// A further classification of the kind of object referenced by an
  122. /// l-value or x-value.
  123. enum ExprObjectKind {
  124. /// An ordinary object is located at an address in memory.
  125. OK_Ordinary,
  126. /// A bitfield object is a bitfield on a C or C++ record.
  127. OK_BitField,
  128. /// A vector component is an element or range of elements on a vector.
  129. OK_VectorComponent,
  130. /// An Objective-C property is a logical field of an Objective-C
  131. /// object which is read and written via Objective-C method calls.
  132. OK_ObjCProperty,
  133. /// An Objective-C array/dictionary subscripting which reads an
  134. /// object or writes at the subscripted array/dictionary element via
  135. /// Objective-C method calls.
  136. OK_ObjCSubscript,
  137. /// A matrix component is a single element of a matrix.
  138. OK_MatrixComponent
  139. };
  140. /// The reason why a DeclRefExpr does not constitute an odr-use.
  141. enum NonOdrUseReason {
  142. /// This is an odr-use.
  143. NOUR_None = 0,
  144. /// This name appears in an unevaluated operand.
  145. NOUR_Unevaluated,
  146. /// This name appears as a potential result of an lvalue-to-rvalue
  147. /// conversion that is a constant expression.
  148. NOUR_Constant,
  149. /// This name appears as a potential result of a discarded value
  150. /// expression.
  151. NOUR_Discarded,
  152. };
  153. /// Describes the kind of template specialization that a
  154. /// particular template specialization declaration represents.
  155. enum TemplateSpecializationKind {
  156. /// This template specialization was formed from a template-id but
  157. /// has not yet been declared, defined, or instantiated.
  158. TSK_Undeclared = 0,
  159. /// This template specialization was implicitly instantiated from a
  160. /// template. (C++ [temp.inst]).
  161. TSK_ImplicitInstantiation,
  162. /// This template specialization was declared or defined by an
  163. /// explicit specialization (C++ [temp.expl.spec]) or partial
  164. /// specialization (C++ [temp.class.spec]).
  165. TSK_ExplicitSpecialization,
  166. /// This template specialization was instantiated from a template
  167. /// due to an explicit instantiation declaration request
  168. /// (C++11 [temp.explicit]).
  169. TSK_ExplicitInstantiationDeclaration,
  170. /// This template specialization was instantiated from a template
  171. /// due to an explicit instantiation definition request
  172. /// (C++ [temp.explicit]).
  173. TSK_ExplicitInstantiationDefinition
  174. };
  175. /// Determine whether this template specialization kind refers
  176. /// to an instantiation of an entity (as opposed to a non-template or
  177. /// an explicit specialization).
  178. inline bool isTemplateInstantiation(TemplateSpecializationKind Kind) {
  179. return Kind != TSK_Undeclared && Kind != TSK_ExplicitSpecialization;
  180. }
  181. /// True if this template specialization kind is an explicit
  182. /// specialization, explicit instantiation declaration, or explicit
  183. /// instantiation definition.
  184. inline bool isTemplateExplicitInstantiationOrSpecialization(
  185. TemplateSpecializationKind Kind) {
  186. switch (Kind) {
  187. case TSK_ExplicitSpecialization:
  188. case TSK_ExplicitInstantiationDeclaration:
  189. case TSK_ExplicitInstantiationDefinition:
  190. return true;
  191. case TSK_Undeclared:
  192. case TSK_ImplicitInstantiation:
  193. return false;
  194. }
  195. llvm_unreachable("bad template specialization kind");
  196. }
  197. /// Thread storage-class-specifier.
  198. enum ThreadStorageClassSpecifier {
  199. TSCS_unspecified,
  200. /// GNU __thread.
  201. TSCS___thread,
  202. /// C++11 thread_local. Implies 'static' at block scope, but not at
  203. /// class scope.
  204. TSCS_thread_local,
  205. /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
  206. /// if used at block scope.
  207. TSCS__Thread_local
  208. };
  209. /// Storage classes.
  210. enum StorageClass {
  211. // These are legal on both functions and variables.
  212. SC_None,
  213. SC_Extern,
  214. SC_Static,
  215. SC_PrivateExtern,
  216. // These are only legal on variables.
  217. SC_Auto,
  218. SC_Register
  219. };
  220. /// Checks whether the given storage class is legal for functions.
  221. inline bool isLegalForFunction(StorageClass SC) {
  222. return SC <= SC_PrivateExtern;
  223. }
  224. /// Checks whether the given storage class is legal for variables.
  225. inline bool isLegalForVariable(StorageClass SC) {
  226. return true;
  227. }
  228. /// In-class initialization styles for non-static data members.
  229. enum InClassInitStyle {
  230. ICIS_NoInit, ///< No in-class initializer.
  231. ICIS_CopyInit, ///< Copy initialization.
  232. ICIS_ListInit ///< Direct list-initialization.
  233. };
  234. /// CallingConv - Specifies the calling convention that a function uses.
  235. enum CallingConv {
  236. CC_C, // __attribute__((cdecl))
  237. CC_X86StdCall, // __attribute__((stdcall))
  238. CC_X86FastCall, // __attribute__((fastcall))
  239. CC_X86ThisCall, // __attribute__((thiscall))
  240. CC_X86VectorCall, // __attribute__((vectorcall))
  241. CC_X86Pascal, // __attribute__((pascal))
  242. CC_Win64, // __attribute__((ms_abi))
  243. CC_X86_64SysV, // __attribute__((sysv_abi))
  244. CC_X86RegCall, // __attribute__((regcall))
  245. CC_AAPCS, // __attribute__((pcs("aapcs")))
  246. CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
  247. CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
  248. CC_SpirFunction, // default for OpenCL functions on SPIR target
  249. CC_OpenCLKernel, // inferred for OpenCL kernels
  250. CC_Swift, // __attribute__((swiftcall))
  251. CC_SwiftAsync, // __attribute__((swiftasynccall))
  252. CC_PreserveMost, // __attribute__((preserve_most))
  253. CC_PreserveAll, // __attribute__((preserve_all))
  254. CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
  255. };
  256. /// Checks whether the given calling convention supports variadic
  257. /// calls. Unprototyped calls also use the variadic call rules.
  258. inline bool supportsVariadicCall(CallingConv CC) {
  259. switch (CC) {
  260. case CC_X86StdCall:
  261. case CC_X86FastCall:
  262. case CC_X86ThisCall:
  263. case CC_X86RegCall:
  264. case CC_X86Pascal:
  265. case CC_X86VectorCall:
  266. case CC_SpirFunction:
  267. case CC_OpenCLKernel:
  268. case CC_Swift:
  269. case CC_SwiftAsync:
  270. return false;
  271. default:
  272. return true;
  273. }
  274. }
  275. /// The storage duration for an object (per C++ [basic.stc]).
  276. enum StorageDuration {
  277. SD_FullExpression, ///< Full-expression storage duration (for temporaries).
  278. SD_Automatic, ///< Automatic storage duration (most local variables).
  279. SD_Thread, ///< Thread storage duration.
  280. SD_Static, ///< Static storage duration.
  281. SD_Dynamic ///< Dynamic storage duration.
  282. };
  283. /// Describes the nullability of a particular type.
  284. enum class NullabilityKind : uint8_t {
  285. /// Values of this type can never be null.
  286. NonNull = 0,
  287. /// Values of this type can be null.
  288. Nullable,
  289. /// Whether values of this type can be null is (explicitly)
  290. /// unspecified. This captures a (fairly rare) case where we
  291. /// can't conclude anything about the nullability of the type even
  292. /// though it has been considered.
  293. Unspecified,
  294. // Generally behaves like Nullable, except when used in a block parameter
  295. // that was imported into a swift async method. There, swift will assume
  296. // that the parameter can get null even if no error occured. _Nullable
  297. // parameters are assumed to only get null on error.
  298. NullableResult,
  299. };
  300. /// Return true if \p L has a weaker nullability annotation than \p R. The
  301. /// ordering is: Unspecified < Nullable < NonNull.
  302. inline bool hasWeakerNullability(NullabilityKind L, NullabilityKind R) {
  303. return uint8_t(L) > uint8_t(R);
  304. }
  305. /// Retrieve the spelling of the given nullability kind.
  306. llvm::StringRef getNullabilitySpelling(NullabilityKind kind,
  307. bool isContextSensitive = false);
  308. /// Kinds of parameter ABI.
  309. enum class ParameterABI {
  310. /// This parameter uses ordinary ABI rules for its type.
  311. Ordinary,
  312. /// This parameter (which must have pointer type) is a Swift
  313. /// indirect result parameter.
  314. SwiftIndirectResult,
  315. /// This parameter (which must have pointer-to-pointer type) uses
  316. /// the special Swift error-result ABI treatment. There can be at
  317. /// most one parameter on a given function that uses this treatment.
  318. SwiftErrorResult,
  319. /// This parameter (which must have pointer type) uses the special
  320. /// Swift context-pointer ABI treatment. There can be at
  321. /// most one parameter on a given function that uses this treatment.
  322. SwiftContext,
  323. /// This parameter (which must have pointer type) uses the special
  324. /// Swift asynchronous context-pointer ABI treatment. There can be at
  325. /// most one parameter on a given function that uses this treatment.
  326. SwiftAsyncContext,
  327. };
  328. /// Assigned inheritance model for a class in the MS C++ ABI. Must match order
  329. /// of spellings in MSInheritanceAttr.
  330. enum class MSInheritanceModel {
  331. Single = 0,
  332. Multiple = 1,
  333. Virtual = 2,
  334. Unspecified = 3,
  335. };
  336. llvm::StringRef getParameterABISpelling(ParameterABI kind);
  337. inline llvm::StringRef getAccessSpelling(AccessSpecifier AS) {
  338. switch (AS) {
  339. case AccessSpecifier::AS_public:
  340. return "public";
  341. case AccessSpecifier::AS_protected:
  342. return "protected";
  343. case AccessSpecifier::AS_private:
  344. return "private";
  345. case AccessSpecifier::AS_none:
  346. return {};
  347. }
  348. llvm_unreachable("Unknown AccessSpecifier");
  349. }
  350. } // end namespace clang
  351. #endif // LLVM_CLANG_BASIC_SPECIFIERS_H
  352. #ifdef __GNUC__
  353. #pragma GCC diagnostic pop
  354. #endif