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