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
22namespace llvm {
23class raw_ostream;
24} // namespace llvm
25namespace 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 TST_typename_pack_indexing,
98#define GENERIC_IMAGE_TYPE(ImgType, Id) \
99 TST_##ImgType##_t, // OpenCL image types
100#include "clang/Basic/OpenCLImageTypes.def"
101#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
102 TST_##Name, // HLSL Intangible Types
103#include "clang/Basic/HLSLIntangibleTypes.def"
104 TST_error // erroneous type
105 };
106
107 /// Structure that packs information about the type specifiers that
108 /// were written in a particular type specifier sequence.
109 struct WrittenBuiltinSpecs {
110 static_assert(TST_error < 1 << 7, "Type bitfield not wide enough for TST");
111 LLVM_PREFERRED_TYPE(TypeSpecifierType)
112 unsigned Type : 7;
113 LLVM_PREFERRED_TYPE(TypeSpecifierSign)
114 unsigned Sign : 2;
115 LLVM_PREFERRED_TYPE(TypeSpecifierWidth)
116 unsigned Width : 2;
117 LLVM_PREFERRED_TYPE(bool)
118 unsigned ModeAttr : 1;
119 };
120
121 /// A C++ access specifier (public, private, protected), plus the
122 /// special value "none" which means different things in different contexts.
123 enum AccessSpecifier {
124 AS_public,
125 AS_protected,
126 AS_private,
127 AS_none
128 };
129
130 /// The categorization of expression values, currently following the
131 /// C++11 scheme.
132 enum ExprValueKind {
133 /// A pr-value expression (in the C++11 taxonomy)
134 /// produces a temporary value.
135 VK_PRValue,
136
137 /// An l-value expression is a reference to an object with
138 /// independent storage.
139 VK_LValue,
140
141 /// An x-value expression is a reference to an object with
142 /// independent storage but which can be "moved", i.e.
143 /// efficiently cannibalized for its resources.
144 VK_XValue
145 };
146
147 /// A further classification of the kind of object referenced by an
148 /// l-value or x-value.
149 enum ExprObjectKind {
150 /// An ordinary object is located at an address in memory.
151 OK_Ordinary,
152
153 /// A bitfield object is a bitfield on a C or C++ record.
154 OK_BitField,
155
156 /// A vector component is an element or range of elements on a vector.
157 OK_VectorComponent,
158
159 /// An Objective-C property is a logical field of an Objective-C
160 /// object which is read and written via Objective-C method calls.
161 OK_ObjCProperty,
162
163 /// An Objective-C array/dictionary subscripting which reads an
164 /// object or writes at the subscripted array/dictionary element via
165 /// Objective-C method calls.
166 OK_ObjCSubscript,
167
168 /// A matrix component is a single element of a matrix.
169 OK_MatrixComponent
170 };
171
172 /// The reason why a DeclRefExpr does not constitute an odr-use.
173 enum NonOdrUseReason {
174 /// This is an odr-use.
175 NOUR_None = 0,
176 /// This name appears in an unevaluated operand.
177 NOUR_Unevaluated,
178 /// This name appears as a potential result of an lvalue-to-rvalue
179 /// conversion that is a constant expression.
180 NOUR_Constant,
181 /// This name appears as a potential result of a discarded value
182 /// expression.
183 NOUR_Discarded,
184 };
185
186 /// Describes the kind of template specialization that a
187 /// particular template specialization declaration represents.
188 enum TemplateSpecializationKind {
189 /// This template specialization was formed from a template-id but
190 /// has not yet been declared, defined, or instantiated.
191 TSK_Undeclared = 0,
192 /// This template specialization was implicitly instantiated from a
193 /// template. (C++ [temp.inst]).
194 TSK_ImplicitInstantiation,
195 /// This template specialization was declared or defined by an
196 /// explicit specialization (C++ [temp.expl.spec]) or partial
197 /// specialization (C++ [temp.class.spec]).
198 TSK_ExplicitSpecialization,
199 /// This template specialization was instantiated from a template
200 /// due to an explicit instantiation declaration request
201 /// (C++11 [temp.explicit]).
202 TSK_ExplicitInstantiationDeclaration,
203 /// This template specialization was instantiated from a template
204 /// due to an explicit instantiation definition request
205 /// (C++ [temp.explicit]).
206 TSK_ExplicitInstantiationDefinition
207 };
208
209 /// Determine whether this template specialization kind refers
210 /// to an instantiation of an entity (as opposed to a non-template or
211 /// an explicit specialization).
212 inline bool isTemplateInstantiation(TemplateSpecializationKind Kind) {
213 return Kind != TSK_Undeclared && Kind != TSK_ExplicitSpecialization;
214 }
215
216 /// True if this template specialization kind is an explicit
217 /// specialization, explicit instantiation declaration, or explicit
218 /// instantiation definition.
219 inline bool isTemplateExplicitInstantiationOrSpecialization(
220 TemplateSpecializationKind Kind) {
221 switch (Kind) {
222 case TSK_ExplicitSpecialization:
223 case TSK_ExplicitInstantiationDeclaration:
224 case TSK_ExplicitInstantiationDefinition:
225 return true;
226
227 case TSK_Undeclared:
228 case TSK_ImplicitInstantiation:
229 return false;
230 }
231 llvm_unreachable("bad template specialization kind");
232 }
233
234 /// Thread storage-class-specifier.
235 enum ThreadStorageClassSpecifier {
236 TSCS_unspecified,
237 /// GNU __thread.
238 TSCS___thread,
239 /// C++11 thread_local. Implies 'static' at block scope, but not at
240 /// class scope.
241 TSCS_thread_local,
242 /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
243 /// if used at block scope.
244 TSCS__Thread_local
245 };
246
247 /// Storage classes.
248 enum StorageClass {
249 // These are legal on both functions and variables.
250 SC_None,
251 SC_Extern,
252 SC_Static,
253 SC_PrivateExtern,
254
255 // These are only legal on variables.
256 SC_Auto,
257 SC_Register
258 };
259
260 /// Checks whether the given storage class is legal for functions.
261 inline bool isLegalForFunction(StorageClass SC) {
262 return SC <= SC_PrivateExtern;
263 }
264
265 /// Checks whether the given storage class is legal for variables.
266 inline bool isLegalForVariable(StorageClass SC) {
267 return true;
268 }
269
270 /// In-class initialization styles for non-static data members.
271 enum InClassInitStyle {
272 ICIS_NoInit, ///< No in-class initializer.
273 ICIS_CopyInit, ///< Copy initialization.
274 ICIS_ListInit ///< Direct list-initialization.
275 };
276
277 /// CallingConv - Specifies the calling convention that a function uses.
278 enum CallingConv {
279 CC_C, // __attribute__((cdecl))
280 CC_X86StdCall, // __attribute__((stdcall))
281 CC_X86FastCall, // __attribute__((fastcall))
282 CC_X86ThisCall, // __attribute__((thiscall))
283 CC_X86VectorCall, // __attribute__((vectorcall))
284 CC_X86Pascal, // __attribute__((pascal))
285 CC_Win64, // __attribute__((ms_abi))
286 CC_X86_64SysV, // __attribute__((sysv_abi))
287 CC_X86RegCall, // __attribute__((regcall))
288 CC_AAPCS, // __attribute__((pcs("aapcs")))
289 CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
290 CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
291 CC_SpirFunction, // default for OpenCL functions on SPIR target
292 CC_DeviceKernel, // __attribute__((device_kernel))
293 CC_Swift, // __attribute__((swiftcall))
294 CC_SwiftAsync, // __attribute__((swiftasynccall))
295 CC_PreserveMost, // __attribute__((preserve_most))
296 CC_PreserveAll, // __attribute__((preserve_all))
297 CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
298 CC_AArch64SVEPCS, // __attribute__((aarch64_sve_pcs))
299 CC_M68kRTD, // __attribute__((m68k_rtd))
300 CC_PreserveNone, // __attribute__((preserve_none))
301 CC_RISCVVectorCall, // __attribute__((riscv_vector_cc))
302 CC_RISCVVLSCall_32, // __attribute__((riscv_vls_cc(32)))
303 CC_RISCVVLSCall_64, // __attribute__((riscv_vls_cc(64)))
304 CC_RISCVVLSCall_128, // __attribute__((riscv_vls_cc)) or
305 // __attribute__((riscv_vls_cc(128)))
306 CC_RISCVVLSCall_256, // __attribute__((riscv_vls_cc(256)))
307 CC_RISCVVLSCall_512, // __attribute__((riscv_vls_cc(512)))
308 CC_RISCVVLSCall_1024, // __attribute__((riscv_vls_cc(1024)))
309 CC_RISCVVLSCall_2048, // __attribute__((riscv_vls_cc(2048)))
310 CC_RISCVVLSCall_4096, // __attribute__((riscv_vls_cc(4096)))
311 CC_RISCVVLSCall_8192, // __attribute__((riscv_vls_cc(8192)))
312 CC_RISCVVLSCall_16384, // __attribute__((riscv_vls_cc(16384)))
313 CC_RISCVVLSCall_32768, // __attribute__((riscv_vls_cc(32768)))
314 CC_RISCVVLSCall_65536, // __attribute__((riscv_vls_cc(65536)))
315 };
316
317 /// Checks whether the given calling convention supports variadic
318 /// calls. Unprototyped calls also use the variadic call rules.
319 inline bool supportsVariadicCall(CallingConv CC) {
320 switch (CC) {
321 case CC_X86StdCall:
322 case CC_X86FastCall:
323 case CC_X86ThisCall:
324 case CC_X86RegCall:
325 case CC_X86Pascal:
326 case CC_X86VectorCall:
327 case CC_SpirFunction:
328 case CC_DeviceKernel:
329 case CC_Swift:
330 case CC_SwiftAsync:
331 case CC_M68kRTD:
332 return false;
333 default:
334 return true;
335 }
336 }
337
338 /// The storage duration for an object (per C++ [basic.stc]).
339 enum StorageDuration {
340 SD_FullExpression, ///< Full-expression storage duration (for temporaries).
341 SD_Automatic, ///< Automatic storage duration (most local variables).
342 SD_Thread, ///< Thread storage duration.
343 SD_Static, ///< Static storage duration.
344 SD_Dynamic ///< Dynamic storage duration.
345 };
346
347 /// Describes the nullability of a particular type.
348 enum class NullabilityKind : uint8_t {
349 /// Values of this type can never be null.
350 NonNull = 0,
351 /// Values of this type can be null.
352 Nullable,
353 /// Whether values of this type can be null is (explicitly)
354 /// unspecified. This captures a (fairly rare) case where we
355 /// can't conclude anything about the nullability of the type even
356 /// though it has been considered.
357 Unspecified,
358 // Generally behaves like Nullable, except when used in a block parameter
359 // that was imported into a swift async method. There, swift will assume
360 // that the parameter can get null even if no error occurred. _Nullable
361 // parameters are assumed to only get null on error.
362 NullableResult,
363 };
364 /// Prints human-readable debug representation.
365 llvm::raw_ostream &operator<<(llvm::raw_ostream&, NullabilityKind);
366
367 /// Return true if \p L has a weaker nullability annotation than \p R. The
368 /// ordering is: Unspecified < Nullable < NonNull.
369 inline bool hasWeakerNullability(NullabilityKind L, NullabilityKind R) {
370 return uint8_t(L) > uint8_t(R);
371 }
372
373 /// Retrieve the spelling of the given nullability kind.
374 llvm::StringRef getNullabilitySpelling(NullabilityKind kind,
375 bool isContextSensitive = false);
376
377 /// Kinds of parameter ABI.
378 enum class ParameterABI {
379 /// This parameter uses ordinary ABI rules for its type.
380 Ordinary,
381
382 /// This parameter (which must have pointer type) is a Swift
383 /// indirect result parameter.
384 SwiftIndirectResult,
385
386 /// This parameter (which must have pointer-to-pointer type) uses
387 /// the special Swift error-result ABI treatment. There can be at
388 /// most one parameter on a given function that uses this treatment.
389 SwiftErrorResult,
390
391 /// This parameter (which must have pointer type) uses the special
392 /// Swift context-pointer ABI treatment. There can be at
393 /// most one parameter on a given function that uses this treatment.
394 SwiftContext,
395
396 /// This parameter (which must have pointer type) uses the special
397 /// Swift asynchronous context-pointer ABI treatment. There can be at
398 /// most one parameter on a given function that uses this treatment.
399 SwiftAsyncContext,
400
401 // This parameter is a copy-out HLSL parameter.
402 HLSLOut,
403
404 // This parameter is a copy-in/copy-out HLSL parameter.
405 HLSLInOut,
406 };
407
408 /// Assigned inheritance model for a class in the MS C++ ABI. Must match order
409 /// of spellings in MSInheritanceAttr.
410 enum class MSInheritanceModel {
411 Single = 0,
412 Multiple = 1,
413 Virtual = 2,
414 Unspecified = 3,
415 };
416
417 llvm::StringRef getParameterABISpelling(ParameterABI kind);
418
419 inline llvm::StringRef getAccessSpelling(AccessSpecifier AS) {
420 switch (AS) {
421 case AccessSpecifier::AS_public:
422 return "public";
423 case AccessSpecifier::AS_protected:
424 return "protected";
425 case AccessSpecifier::AS_private:
426 return "private";
427 case AccessSpecifier::AS_none:
428 return {};
429 }
430 llvm_unreachable("Unknown AccessSpecifier");
431 }
432} // end namespace clang
433
434#endif // LLVM_CLANG_BASIC_SPECIFIERS_H
435

source code of clang/include/clang/Basic/Specifiers.h