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