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