1 //===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines various enumerations that describe declaration and
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_BASIC_SPECIFIERS_H
17 #define LLVM_CLANG_BASIC_SPECIFIERS_H
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/DataTypes.h"
21 #include "llvm/Support/ErrorHandling.h"
24 /// Specifies the width of a type, e.g., short, long, or long long.
25 enum TypeSpecifierWidth {
32 /// Specifies the signedness of a type, e.g., signed or unsigned.
33 enum TypeSpecifierSign {
39 enum TypeSpecifiersPipe {
44 /// Specifies the kind of type.
45 enum TypeSpecifierType {
49 TST_wchar, // C++ wchar_t
50 TST_char8, // C++20 char8_t (proposed)
51 TST_char16, // C++11 char16_t
52 TST_char32, // C++11 char32_t
55 TST_half, // OpenCL half, ARM NEON __fp16
56 TST_Float16, // C11 extension ISO/IEC TS 18661-3
57 TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension
63 TST_decimal32, // _Decimal32
64 TST_decimal64, // _Decimal64
65 TST_decimal128, // _Decimal128
69 TST_class, // C++ class type
70 TST_interface, // C++ (Microsoft-specific) __interface type
71 TST_typename, // Typedef, C++ class-name or enum name, etc.
74 TST_decltype, // C++11 decltype
75 TST_underlyingType, // __underlying_type for C++11
76 TST_auto, // C++11 auto
77 TST_decltype_auto, // C++1y decltype(auto)
78 TST_auto_type, // __auto_type extension
79 TST_unknown_anytype, // __unknown_anytype extension
80 TST_atomic, // C11 _Atomic
81 #define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image types
82 #include "clang/Basic/OpenCLImageTypes.def"
83 TST_error // erroneous type
86 /// Structure that packs information about the type specifiers that
87 /// were written in a particular type specifier sequence.
88 struct WrittenBuiltinSpecs {
89 static_assert(TST_error < 1 << 6, "Type bitfield not wide enough for TST");
90 /*DeclSpec::TST*/ unsigned Type : 6;
91 /*DeclSpec::TSS*/ unsigned Sign : 2;
92 /*DeclSpec::TSW*/ unsigned Width : 2;
93 unsigned ModeAttr : 1;
96 /// A C++ access specifier (public, private, protected), plus the
97 /// special value "none" which means different things in different contexts.
98 enum AccessSpecifier {
105 /// The categorization of expression values, currently following the
108 /// An r-value expression (a pr-value in the C++11 taxonomy)
109 /// produces a temporary value.
112 /// An l-value expression is a reference to an object with
113 /// independent storage.
116 /// An x-value expression is a reference to an object with
117 /// independent storage but which can be "moved", i.e.
118 /// efficiently cannibalized for its resources.
122 /// A further classification of the kind of object referenced by an
123 /// l-value or x-value.
124 enum ExprObjectKind {
125 /// An ordinary object is located at an address in memory.
128 /// A bitfield object is a bitfield on a C or C++ record.
131 /// A vector component is an element or range of elements on a vector.
134 /// An Objective-C property is a logical field of an Objective-C
135 /// object which is read and written via Objective-C method calls.
138 /// An Objective-C array/dictionary subscripting which reads an
139 /// object or writes at the subscripted array/dictionary element via
140 /// Objective-C method calls.
144 /// Describes the kind of template specialization that a
145 /// particular template specialization declaration represents.
146 enum TemplateSpecializationKind {
147 /// This template specialization was formed from a template-id but
148 /// has not yet been declared, defined, or instantiated.
150 /// This template specialization was implicitly instantiated from a
151 /// template. (C++ [temp.inst]).
152 TSK_ImplicitInstantiation,
153 /// This template specialization was declared or defined by an
154 /// explicit specialization (C++ [temp.expl.spec]) or partial
155 /// specialization (C++ [temp.class.spec]).
156 TSK_ExplicitSpecialization,
157 /// This template specialization was instantiated from a template
158 /// due to an explicit instantiation declaration request
159 /// (C++11 [temp.explicit]).
160 TSK_ExplicitInstantiationDeclaration,
161 /// This template specialization was instantiated from a template
162 /// due to an explicit instantiation definition request
163 /// (C++ [temp.explicit]).
164 TSK_ExplicitInstantiationDefinition
167 /// Determine whether this template specialization kind refers
168 /// to an instantiation of an entity (as opposed to a non-template or
169 /// an explicit specialization).
170 inline bool isTemplateInstantiation(TemplateSpecializationKind Kind) {
171 return Kind != TSK_Undeclared && Kind != TSK_ExplicitSpecialization;
174 /// True if this template specialization kind is an explicit
175 /// specialization, explicit instantiation declaration, or explicit
176 /// instantiation definition.
177 inline bool isTemplateExplicitInstantiationOrSpecialization(
178 TemplateSpecializationKind Kind) {
180 case TSK_ExplicitSpecialization:
181 case TSK_ExplicitInstantiationDeclaration:
182 case TSK_ExplicitInstantiationDefinition:
186 case TSK_ImplicitInstantiation:
189 llvm_unreachable("bad template specialization kind");
192 /// Thread storage-class-specifier.
193 enum ThreadStorageClassSpecifier {
197 /// C++11 thread_local. Implies 'static' at block scope, but not at
200 /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
201 /// if used at block scope.
207 // These are legal on both functions and variables.
213 // These are only legal on variables.
218 /// Checks whether the given storage class is legal for functions.
219 inline bool isLegalForFunction(StorageClass SC) {
220 return SC <= SC_PrivateExtern;
223 /// Checks whether the given storage class is legal for variables.
224 inline bool isLegalForVariable(StorageClass SC) {
228 /// In-class initialization styles for non-static data members.
229 enum InClassInitStyle {
230 ICIS_NoInit, ///< No in-class initializer.
231 ICIS_CopyInit, ///< Copy initialization.
232 ICIS_ListInit ///< Direct list-initialization.
235 /// CallingConv - Specifies the calling convention that a function uses.
237 CC_C, // __attribute__((cdecl))
238 CC_X86StdCall, // __attribute__((stdcall))
239 CC_X86FastCall, // __attribute__((fastcall))
240 CC_X86ThisCall, // __attribute__((thiscall))
241 CC_X86VectorCall, // __attribute__((vectorcall))
242 CC_X86Pascal, // __attribute__((pascal))
243 CC_Win64, // __attribute__((ms_abi))
244 CC_X86_64SysV, // __attribute__((sysv_abi))
245 CC_X86RegCall, // __attribute__((regcall))
246 CC_AAPCS, // __attribute__((pcs("aapcs")))
247 CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
248 CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
249 CC_SpirFunction, // default for OpenCL functions on SPIR target
250 CC_OpenCLKernel, // inferred for OpenCL kernels
251 CC_Swift, // __attribute__((swiftcall))
252 CC_PreserveMost, // __attribute__((preserve_most))
253 CC_PreserveAll, // __attribute__((preserve_all))
256 /// Checks whether the given calling convention supports variadic
257 /// calls. Unprototyped calls also use the variadic call rules.
258 inline bool supportsVariadicCall(CallingConv CC) {
265 case CC_X86VectorCall:
266 case CC_SpirFunction:
267 case CC_OpenCLKernel:
275 /// The storage duration for an object (per C++ [basic.stc]).
276 enum StorageDuration {
277 SD_FullExpression, ///< Full-expression storage duration (for temporaries).
278 SD_Automatic, ///< Automatic storage duration (most local variables).
279 SD_Thread, ///< Thread storage duration.
280 SD_Static, ///< Static storage duration.
281 SD_Dynamic ///< Dynamic storage duration.
284 /// Describes the nullability of a particular type.
285 enum class NullabilityKind : uint8_t {
286 /// Values of this type can never be null.
288 /// Values of this type can be null.
290 /// Whether values of this type can be null is (explicitly)
291 /// unspecified. This captures a (fairly rare) case where we
292 /// can't conclude anything about the nullability of the type even
293 /// though it has been considered.
297 /// Return true if \p L has a weaker nullability annotation than \p R. The
298 /// ordering is: Unspecified < Nullable < NonNull.
299 inline bool hasWeakerNullability(NullabilityKind L, NullabilityKind R) {
300 return uint8_t(L) > uint8_t(R);
303 /// Retrieve the spelling of the given nullability kind.
304 llvm::StringRef getNullabilitySpelling(NullabilityKind kind,
305 bool isContextSensitive = false);
307 /// Kinds of parameter ABI.
308 enum class ParameterABI {
309 /// This parameter uses ordinary ABI rules for its type.
312 /// This parameter (which must have pointer type) is a Swift
313 /// indirect result parameter.
316 /// This parameter (which must have pointer-to-pointer type) uses
317 /// the special Swift error-result ABI treatment. There can be at
318 /// most one parameter on a given function that uses this treatment.
321 /// This parameter (which must have pointer type) uses the special
322 /// Swift context-pointer ABI treatment. There can be at
323 /// most one parameter on a given function that uses this treatment.
327 llvm::StringRef getParameterABISpelling(ParameterABI kind);
328 } // end namespace clang
330 #endif // LLVM_CLANG_BASIC_SPECIFIERS_H