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