|
|
|||
File indexing completed on 2026-05-10 08:36:51
0001 //===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// 0009 /// \file 0010 /// Defines various enumerations that describe declaration and 0011 /// type specifiers. 0012 /// 0013 //===----------------------------------------------------------------------===// 0014 0015 #ifndef LLVM_CLANG_BASIC_SPECIFIERS_H 0016 #define LLVM_CLANG_BASIC_SPECIFIERS_H 0017 0018 #include "llvm/ADT/StringRef.h" 0019 #include "llvm/Support/DataTypes.h" 0020 #include "llvm/Support/ErrorHandling.h" 0021 0022 namespace llvm { 0023 class raw_ostream; 0024 } // namespace llvm 0025 namespace clang { 0026 0027 /// Define the meaning of possible values of the kind in ExplicitSpecifier. 0028 enum class ExplicitSpecKind : unsigned { 0029 ResolvedFalse, 0030 ResolvedTrue, 0031 Unresolved, 0032 }; 0033 0034 /// Define the kind of constexpr specifier. 0035 enum class ConstexprSpecKind { Unspecified, Constexpr, Consteval, Constinit }; 0036 0037 /// In an if statement, this denotes whether the statement is 0038 /// a constexpr or consteval if statement. 0039 enum class IfStatementKind : unsigned { 0040 Ordinary, 0041 Constexpr, 0042 ConstevalNonNegated, 0043 ConstevalNegated 0044 }; 0045 0046 /// Specifies the width of a type, e.g., short, long, or long long. 0047 enum class TypeSpecifierWidth { Unspecified, Short, Long, LongLong }; 0048 0049 /// Specifies the signedness of a type, e.g., signed or unsigned. 0050 enum class TypeSpecifierSign { Unspecified, Signed, Unsigned }; 0051 0052 enum class TypeSpecifiersPipe { Unspecified, Pipe }; 0053 0054 /// Specifies the kind of type. 0055 enum TypeSpecifierType { 0056 TST_unspecified, 0057 TST_void, 0058 TST_char, 0059 TST_wchar, // C++ wchar_t 0060 TST_char8, // C++20 char8_t (proposed) 0061 TST_char16, // C++11 char16_t 0062 TST_char32, // C++11 char32_t 0063 TST_int, 0064 TST_int128, 0065 TST_bitint, // Bit-precise integer types. 0066 TST_half, // OpenCL half, ARM NEON __fp16 0067 TST_Float16, // C11 extension ISO/IEC TS 18661-3 0068 TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension 0069 TST_Fract, 0070 TST_BFloat16, 0071 TST_float, 0072 TST_double, 0073 TST_float128, 0074 TST_ibm128, 0075 TST_bool, // _Bool 0076 TST_decimal32, // _Decimal32 0077 TST_decimal64, // _Decimal64 0078 TST_decimal128, // _Decimal128 0079 TST_enum, 0080 TST_union, 0081 TST_struct, 0082 TST_class, // C++ class type 0083 TST_interface, // C++ (Microsoft-specific) __interface type 0084 TST_typename, // Typedef, C++ class-name or enum name, etc. 0085 TST_typeofType, // C23 (and GNU extension) typeof(type-name) 0086 TST_typeofExpr, // C23 (and GNU extension) typeof(expression) 0087 TST_typeof_unqualType, // C23 typeof_unqual(type-name) 0088 TST_typeof_unqualExpr, // C23 typeof_unqual(expression) 0089 TST_decltype, // C++11 decltype 0090 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait, 0091 #include "clang/Basic/TransformTypeTraits.def" 0092 TST_auto, // C++11 auto 0093 TST_decltype_auto, // C++1y decltype(auto) 0094 TST_auto_type, // __auto_type extension 0095 TST_unknown_anytype, // __unknown_anytype extension 0096 TST_atomic, // C11 _Atomic 0097 TST_typename_pack_indexing, 0098 #define GENERIC_IMAGE_TYPE(ImgType, Id) \ 0099 TST_##ImgType##_t, // OpenCL image types 0100 #include "clang/Basic/OpenCLImageTypes.def" 0101 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \ 0102 TST_##Name, // HLSL Intangible Types 0103 #include "clang/Basic/HLSLIntangibleTypes.def" 0104 TST_error // erroneous type 0105 }; 0106 0107 /// Structure that packs information about the type specifiers that 0108 /// were written in a particular type specifier sequence. 0109 struct WrittenBuiltinSpecs { 0110 static_assert(TST_error < 1 << 7, "Type bitfield not wide enough for TST"); 0111 LLVM_PREFERRED_TYPE(TypeSpecifierType) 0112 unsigned Type : 7; 0113 LLVM_PREFERRED_TYPE(TypeSpecifierSign) 0114 unsigned Sign : 2; 0115 LLVM_PREFERRED_TYPE(TypeSpecifierWidth) 0116 unsigned Width : 2; 0117 LLVM_PREFERRED_TYPE(bool) 0118 unsigned ModeAttr : 1; 0119 }; 0120 0121 /// A C++ access specifier (public, private, protected), plus the 0122 /// special value "none" which means different things in different contexts. 0123 enum AccessSpecifier { 0124 AS_public, 0125 AS_protected, 0126 AS_private, 0127 AS_none 0128 }; 0129 0130 /// The categorization of expression values, currently following the 0131 /// C++11 scheme. 0132 enum ExprValueKind { 0133 /// A pr-value expression (in the C++11 taxonomy) 0134 /// produces a temporary value. 0135 VK_PRValue, 0136 0137 /// An l-value expression is a reference to an object with 0138 /// independent storage. 0139 VK_LValue, 0140 0141 /// An x-value expression is a reference to an object with 0142 /// independent storage but which can be "moved", i.e. 0143 /// efficiently cannibalized for its resources. 0144 VK_XValue 0145 }; 0146 0147 /// A further classification of the kind of object referenced by an 0148 /// l-value or x-value. 0149 enum ExprObjectKind { 0150 /// An ordinary object is located at an address in memory. 0151 OK_Ordinary, 0152 0153 /// A bitfield object is a bitfield on a C or C++ record. 0154 OK_BitField, 0155 0156 /// A vector component is an element or range of elements on a vector. 0157 OK_VectorComponent, 0158 0159 /// An Objective-C property is a logical field of an Objective-C 0160 /// object which is read and written via Objective-C method calls. 0161 OK_ObjCProperty, 0162 0163 /// An Objective-C array/dictionary subscripting which reads an 0164 /// object or writes at the subscripted array/dictionary element via 0165 /// Objective-C method calls. 0166 OK_ObjCSubscript, 0167 0168 /// A matrix component is a single element of a matrix. 0169 OK_MatrixComponent 0170 }; 0171 0172 /// The reason why a DeclRefExpr does not constitute an odr-use. 0173 enum NonOdrUseReason { 0174 /// This is an odr-use. 0175 NOUR_None = 0, 0176 /// This name appears in an unevaluated operand. 0177 NOUR_Unevaluated, 0178 /// This name appears as a potential result of an lvalue-to-rvalue 0179 /// conversion that is a constant expression. 0180 NOUR_Constant, 0181 /// This name appears as a potential result of a discarded value 0182 /// expression. 0183 NOUR_Discarded, 0184 }; 0185 0186 /// Describes the kind of template specialization that a 0187 /// particular template specialization declaration represents. 0188 enum TemplateSpecializationKind { 0189 /// This template specialization was formed from a template-id but 0190 /// has not yet been declared, defined, or instantiated. 0191 TSK_Undeclared = 0, 0192 /// This template specialization was implicitly instantiated from a 0193 /// template. (C++ [temp.inst]). 0194 TSK_ImplicitInstantiation, 0195 /// This template specialization was declared or defined by an 0196 /// explicit specialization (C++ [temp.expl.spec]) or partial 0197 /// specialization (C++ [temp.class.spec]). 0198 TSK_ExplicitSpecialization, 0199 /// This template specialization was instantiated from a template 0200 /// due to an explicit instantiation declaration request 0201 /// (C++11 [temp.explicit]). 0202 TSK_ExplicitInstantiationDeclaration, 0203 /// This template specialization was instantiated from a template 0204 /// due to an explicit instantiation definition request 0205 /// (C++ [temp.explicit]). 0206 TSK_ExplicitInstantiationDefinition 0207 }; 0208 0209 /// Determine whether this template specialization kind refers 0210 /// to an instantiation of an entity (as opposed to a non-template or 0211 /// an explicit specialization). 0212 inline bool isTemplateInstantiation(TemplateSpecializationKind Kind) { 0213 return Kind != TSK_Undeclared && Kind != TSK_ExplicitSpecialization; 0214 } 0215 0216 /// True if this template specialization kind is an explicit 0217 /// specialization, explicit instantiation declaration, or explicit 0218 /// instantiation definition. 0219 inline bool isTemplateExplicitInstantiationOrSpecialization( 0220 TemplateSpecializationKind Kind) { 0221 switch (Kind) { 0222 case TSK_ExplicitSpecialization: 0223 case TSK_ExplicitInstantiationDeclaration: 0224 case TSK_ExplicitInstantiationDefinition: 0225 return true; 0226 0227 case TSK_Undeclared: 0228 case TSK_ImplicitInstantiation: 0229 return false; 0230 } 0231 llvm_unreachable("bad template specialization kind"); 0232 } 0233 0234 /// Thread storage-class-specifier. 0235 enum ThreadStorageClassSpecifier { 0236 TSCS_unspecified, 0237 /// GNU __thread. 0238 TSCS___thread, 0239 /// C++11 thread_local. Implies 'static' at block scope, but not at 0240 /// class scope. 0241 TSCS_thread_local, 0242 /// C11 _Thread_local. Must be combined with either 'static' or 'extern' 0243 /// if used at block scope. 0244 TSCS__Thread_local 0245 }; 0246 0247 /// Storage classes. 0248 enum StorageClass { 0249 // These are legal on both functions and variables. 0250 SC_None, 0251 SC_Extern, 0252 SC_Static, 0253 SC_PrivateExtern, 0254 0255 // These are only legal on variables. 0256 SC_Auto, 0257 SC_Register 0258 }; 0259 0260 /// Checks whether the given storage class is legal for functions. 0261 inline bool isLegalForFunction(StorageClass SC) { 0262 return SC <= SC_PrivateExtern; 0263 } 0264 0265 /// Checks whether the given storage class is legal for variables. 0266 inline bool isLegalForVariable(StorageClass SC) { 0267 return true; 0268 } 0269 0270 /// In-class initialization styles for non-static data members. 0271 enum InClassInitStyle { 0272 ICIS_NoInit, ///< No in-class initializer. 0273 ICIS_CopyInit, ///< Copy initialization. 0274 ICIS_ListInit ///< Direct list-initialization. 0275 }; 0276 0277 /// CallingConv - Specifies the calling convention that a function uses. 0278 enum CallingConv { 0279 CC_C, // __attribute__((cdecl)) 0280 CC_X86StdCall, // __attribute__((stdcall)) 0281 CC_X86FastCall, // __attribute__((fastcall)) 0282 CC_X86ThisCall, // __attribute__((thiscall)) 0283 CC_X86VectorCall, // __attribute__((vectorcall)) 0284 CC_X86Pascal, // __attribute__((pascal)) 0285 CC_Win64, // __attribute__((ms_abi)) 0286 CC_X86_64SysV, // __attribute__((sysv_abi)) 0287 CC_X86RegCall, // __attribute__((regcall)) 0288 CC_AAPCS, // __attribute__((pcs("aapcs"))) 0289 CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp"))) 0290 CC_IntelOclBicc, // __attribute__((intel_ocl_bicc)) 0291 CC_SpirFunction, // default for OpenCL functions on SPIR target 0292 CC_OpenCLKernel, // inferred for OpenCL kernels 0293 CC_Swift, // __attribute__((swiftcall)) 0294 CC_SwiftAsync, // __attribute__((swiftasynccall)) 0295 CC_PreserveMost, // __attribute__((preserve_most)) 0296 CC_PreserveAll, // __attribute__((preserve_all)) 0297 CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs)) 0298 CC_AArch64SVEPCS, // __attribute__((aarch64_sve_pcs)) 0299 CC_AMDGPUKernelCall, // __attribute__((amdgpu_kernel)) 0300 CC_M68kRTD, // __attribute__((m68k_rtd)) 0301 CC_PreserveNone, // __attribute__((preserve_none)) 0302 CC_RISCVVectorCall, // __attribute__((riscv_vector_cc)) 0303 }; 0304 0305 /// Checks whether the given calling convention supports variadic 0306 /// calls. Unprototyped calls also use the variadic call rules. 0307 inline bool supportsVariadicCall(CallingConv CC) { 0308 switch (CC) { 0309 case CC_X86StdCall: 0310 case CC_X86FastCall: 0311 case CC_X86ThisCall: 0312 case CC_X86RegCall: 0313 case CC_X86Pascal: 0314 case CC_X86VectorCall: 0315 case CC_SpirFunction: 0316 case CC_OpenCLKernel: 0317 case CC_Swift: 0318 case CC_SwiftAsync: 0319 case CC_M68kRTD: 0320 return false; 0321 default: 0322 return true; 0323 } 0324 } 0325 0326 /// The storage duration for an object (per C++ [basic.stc]). 0327 enum StorageDuration { 0328 SD_FullExpression, ///< Full-expression storage duration (for temporaries). 0329 SD_Automatic, ///< Automatic storage duration (most local variables). 0330 SD_Thread, ///< Thread storage duration. 0331 SD_Static, ///< Static storage duration. 0332 SD_Dynamic ///< Dynamic storage duration. 0333 }; 0334 0335 /// Describes the nullability of a particular type. 0336 enum class NullabilityKind : uint8_t { 0337 /// Values of this type can never be null. 0338 NonNull = 0, 0339 /// Values of this type can be null. 0340 Nullable, 0341 /// Whether values of this type can be null is (explicitly) 0342 /// unspecified. This captures a (fairly rare) case where we 0343 /// can't conclude anything about the nullability of the type even 0344 /// though it has been considered. 0345 Unspecified, 0346 // Generally behaves like Nullable, except when used in a block parameter 0347 // that was imported into a swift async method. There, swift will assume 0348 // that the parameter can get null even if no error occurred. _Nullable 0349 // parameters are assumed to only get null on error. 0350 NullableResult, 0351 }; 0352 /// Prints human-readable debug representation. 0353 llvm::raw_ostream &operator<<(llvm::raw_ostream&, NullabilityKind); 0354 0355 /// Return true if \p L has a weaker nullability annotation than \p R. The 0356 /// ordering is: Unspecified < Nullable < NonNull. 0357 inline bool hasWeakerNullability(NullabilityKind L, NullabilityKind R) { 0358 return uint8_t(L) > uint8_t(R); 0359 } 0360 0361 /// Retrieve the spelling of the given nullability kind. 0362 llvm::StringRef getNullabilitySpelling(NullabilityKind kind, 0363 bool isContextSensitive = false); 0364 0365 /// Kinds of parameter ABI. 0366 enum class ParameterABI { 0367 /// This parameter uses ordinary ABI rules for its type. 0368 Ordinary, 0369 0370 /// This parameter (which must have pointer type) is a Swift 0371 /// indirect result parameter. 0372 SwiftIndirectResult, 0373 0374 /// This parameter (which must have pointer-to-pointer type) uses 0375 /// the special Swift error-result ABI treatment. There can be at 0376 /// most one parameter on a given function that uses this treatment. 0377 SwiftErrorResult, 0378 0379 /// This parameter (which must have pointer type) uses the special 0380 /// Swift context-pointer ABI treatment. There can be at 0381 /// most one parameter on a given function that uses this treatment. 0382 SwiftContext, 0383 0384 /// This parameter (which must have pointer type) uses the special 0385 /// Swift asynchronous context-pointer ABI treatment. There can be at 0386 /// most one parameter on a given function that uses this treatment. 0387 SwiftAsyncContext, 0388 0389 // This parameter is a copy-out HLSL parameter. 0390 HLSLOut, 0391 0392 // This parameter is a copy-in/copy-out HLSL parameter. 0393 HLSLInOut, 0394 }; 0395 0396 /// Assigned inheritance model for a class in the MS C++ ABI. Must match order 0397 /// of spellings in MSInheritanceAttr. 0398 enum class MSInheritanceModel { 0399 Single = 0, 0400 Multiple = 1, 0401 Virtual = 2, 0402 Unspecified = 3, 0403 }; 0404 0405 llvm::StringRef getParameterABISpelling(ParameterABI kind); 0406 0407 inline llvm::StringRef getAccessSpelling(AccessSpecifier AS) { 0408 switch (AS) { 0409 case AccessSpecifier::AS_public: 0410 return "public"; 0411 case AccessSpecifier::AS_protected: 0412 return "protected"; 0413 case AccessSpecifier::AS_private: 0414 return "private"; 0415 case AccessSpecifier::AS_none: 0416 return {}; 0417 } 0418 llvm_unreachable("Unknown AccessSpecifier"); 0419 } 0420 } // end namespace clang 0421 0422 #endif // LLVM_CLANG_BASIC_SPECIFIERS_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|