clang 8.0.0

Specifiers.h
Go to the documentation of this file.
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 /// 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 /// 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 /// 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 /// 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_char8, // C++20 char8_t (proposed)
51 TST_char16, // C++11 char16_t
52 TST_char32, // C++11 char32_t
53 TST_int,
54 TST_int128,
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
58 TST_Fract,
59 TST_float,
60 TST_double,
61 TST_float128,
62 TST_bool, // _Bool
63 TST_decimal32, // _Decimal32
64 TST_decimal64, // _Decimal64
65 TST_decimal128, // _Decimal128
66 TST_enum,
67 TST_union,
68 TST_struct,
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.
72 TST_typeofType,
73 TST_typeofExpr,
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
84 };
85
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;
94 };
95
96 /// A C++ access specifier (public, private, protected), plus the
97 /// special value "none" which means different things in different contexts.
98 enum AccessSpecifier {
99 AS_public,
100 AS_protected,
101 AS_private,
102 AS_none
103 };
104
105 /// The categorization of expression values, currently following the
106 /// C++11 scheme.
107 enum ExprValueKind {
108 /// An r-value expression (a pr-value in the C++11 taxonomy)
109 /// produces a temporary value.
110 VK_RValue,
111
112 /// An l-value expression is a reference to an object with
113 /// independent storage.
114 VK_LValue,
115
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.
119 VK_XValue
120 };
121
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.
126 OK_Ordinary,
127
128 /// A bitfield object is a bitfield on a C or C++ record.
129 OK_BitField,
130
131 /// A vector component is an element or range of elements on a vector.
132 OK_VectorComponent,
133
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.
136 OK_ObjCProperty,
137
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.
141 OK_ObjCSubscript
142 };
143
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.
149 TSK_Undeclared = 0,
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
165 };
166
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;
172 }
173
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) {
179 switch (Kind) {
180 case TSK_ExplicitSpecialization:
181 case TSK_ExplicitInstantiationDeclaration:
182 case TSK_ExplicitInstantiationDefinition:
183 return true;
184
185 case TSK_Undeclared:
186 case TSK_ImplicitInstantiation:
187 return false;
188 }
189 llvm_unreachable("bad template specialization kind");
190 }
191
192 /// Thread storage-class-specifier.
193 enum ThreadStorageClassSpecifier {
194 TSCS_unspecified,
195 /// GNU __thread.
196 TSCS___thread,
197 /// C++11 thread_local. Implies 'static' at block scope, but not at
198 /// class scope.
199 TSCS_thread_local,
200 /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
201 /// if used at block scope.
202 TSCS__Thread_local
203 };
204
205 /// Storage classes.
206 enum StorageClass {
207 // These are legal on both functions and variables.
208 SC_None,
209 SC_Extern,
210 SC_Static,
211 SC_PrivateExtern,
212
213 // These are only legal on variables.
214 SC_Auto,
215 SC_Register
216 };
217
218 /// Checks whether the given storage class is legal for functions.
219 inline bool isLegalForFunction(StorageClass SC) {
220 return SC <= SC_PrivateExtern;
221 }
222
223 /// Checks whether the given storage class is legal for variables.
224 inline bool isLegalForVariable(StorageClass SC) {
225 return true;
226 }
227
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.
233 };
234
235 /// CallingConv - Specifies the calling convention that a function uses.
236 enum CallingConv {
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))
254 CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
255 };
256
257 /// Checks whether the given calling convention supports variadic
258 /// calls. Unprototyped calls also use the variadic call rules.
259 inline bool supportsVariadicCall(CallingConv CC) {
260 switch (CC) {
261 case CC_X86StdCall:
262 case CC_X86FastCall:
263 case CC_X86ThisCall:
264 case CC_X86RegCall:
265 case CC_X86Pascal:
266 case CC_X86VectorCall:
267 case CC_SpirFunction:
268 case CC_OpenCLKernel:
269 case CC_Swift:
270 return false;
271 default:
272 return true;
273 }
274 }
275
276 /// The storage duration for an object (per C++ [basic.stc]).
277 enum StorageDuration {
278 SD_FullExpression, ///< Full-expression storage duration (for temporaries).
279 SD_Automatic, ///< Automatic storage duration (most local variables).
280 SD_Thread, ///< Thread storage duration.
281 SD_Static, ///< Static storage duration.
282 SD_Dynamic ///< Dynamic storage duration.
283 };
284
285 /// Describes the nullability of a particular type.
286 enum class NullabilityKind : uint8_t {
287 /// Values of this type can never be null.
288 NonNull = 0,
289 /// Values of this type can be null.
290 Nullable,
291 /// Whether values of this type can be null is (explicitly)
292 /// unspecified. This captures a (fairly rare) case where we
293 /// can't conclude anything about the nullability of the type even
294 /// though it has been considered.
295 Unspecified
296 };
297
298 /// Return true if \p L has a weaker nullability annotation than \p R. The
299 /// ordering is: Unspecified < Nullable < NonNull.
300 inline bool hasWeakerNullability(NullabilityKind L, NullabilityKind R) {
301 return uint8_t(L) > uint8_t(R);
302 }
303
304 /// Retrieve the spelling of the given nullability kind.
305 llvm::StringRef getNullabilitySpelling(NullabilityKind kind,
306 bool isContextSensitive = false);
307
308 /// Kinds of parameter ABI.
309 enum class ParameterABI {
310 /// This parameter uses ordinary ABI rules for its type.
311 Ordinary,
312
313 /// This parameter (which must have pointer type) is a Swift
314 /// indirect result parameter.
315 SwiftIndirectResult,
316
317 /// This parameter (which must have pointer-to-pointer type) uses
318 /// the special Swift error-result ABI treatment. There can be at
319 /// most one parameter on a given function that uses this treatment.
320 SwiftErrorResult,
321
322 /// This parameter (which must have pointer type) uses the special
323 /// Swift context-pointer ABI treatment. There can be at
324 /// most one parameter on a given function that uses this treatment.
325 SwiftContext
326 };
327
328 llvm::StringRef getParameterABISpelling(ParameterABI kind);
329 } // end namespace clang
330
331 #endif // LLVM_CLANG_BASIC_SPECIFIERS_H
clang::CC_OpenCLKernel
Definition: Specifiers.h:250
clang::TST_decltype
Definition: Specifiers.h:74
clang::TST_int
Definition: Specifiers.h:53
clang::CC_X86RegCall
Definition: Specifiers.h:245
clang::ObjCSubstitutionContext::Ordinary
An ordinary type.
clang::CC_X86VectorCall
Definition: Specifiers.h:241
clang::SD_Static
Static storage duration.
Definition: Specifiers.h:281
clang::TST_struct
Definition: Specifiers.h:68
clang::NullabilityKind
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:286
clang::TST_void
Definition: Specifiers.h:47
clang::CC_SpirFunction
Definition: Specifiers.h:249
clang::TSW_unspecified
Definition: Specifiers.h:26
clang::AccessSpecifier
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:98
clang::StorageDuration
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition: Specifiers.h:277
clang::CC_X86StdCall
Definition: Specifiers.h:238
clang::TST_decimal128
Definition: Specifiers.h:65
clang::TSP_unspecified
Definition: Specifiers.h:40
clang::OK_ObjCSubscript
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
Definition: Specifiers.h:141
clang::TST_float
Definition: Specifiers.h:59
clang::SC_Static
Definition: Specifiers.h:210
clang::SC_None
Definition: Specifiers.h:208
clang::TST_bool
Definition: Specifiers.h:62
clang::TypeSpecifierType
TypeSpecifierType
Specifies the kind of type.
Definition: Specifiers.h:45
clang::TST_wchar
Definition: Specifiers.h:49
clang::TST_typename
Definition: Specifiers.h:71
clang::isTemplateExplicitInstantiationOrSpecialization
bool isTemplateExplicitInstantiationOrSpecialization(TemplateSpecializationKind Kind)
True if this template specialization kind is an explicit specialization, explicit instantiation decla...
Definition: Specifiers.h:177
clang::TSCS__Thread_local
C11 _Thread_local.
Definition: Specifiers.h:202
clang::OK_VectorComponent
A vector component is an element or range of elements on a vector.
Definition: Specifiers.h:132
clang::ICIS_CopyInit
Copy initialization.
Definition: Specifiers.h:231
clang::TST_Fract
Definition: Specifiers.h:58
clang::TypeSpecifierSign
TypeSpecifierSign
Specifies the signedness of a type, e.g., signed or unsigned.
Definition: Specifiers.h:33
clang::CC_IntelOclBicc
Definition: Specifiers.h:248
clang::VK_RValue
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:110
clang::NullabilityKind::Nullable
Values of this type can be null.
clang::TSS_unsigned
Definition: Specifiers.h:36
clang::ParameterABI::SwiftContext
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
clang::AS_private
Definition: Specifiers.h:101
clang::CC_Swift
Definition: Specifiers.h:251
clang::CC_AArch64VectorCall
Definition: Specifiers.h:254
clang::NullabilityKind::Unspecified
Whether values of this type can be null is (explicitly) unspecified.
clang::VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved"...
Definition: Specifiers.h:119
clang::TSW_short
Definition: Specifiers.h:27
clang::TST_typeofType
Definition: Specifiers.h:72
clang::CC_X86_64SysV
Definition: Specifiers.h:244
clang::TST_char32
Definition: Specifiers.h:52
clang::TST_auto_type
Definition: Specifiers.h:78
clang::NullabilityKind::NonNull
Values of this type can never be null.
clang::TST_float128
Definition: Specifiers.h:61
clang::TST_interface
Definition: Specifiers.h:70
clang::OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:126
clang::TST_char
Definition: Specifiers.h:48
clang::ParameterABI::SwiftErrorResult
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
clang::AS_none
Definition: Specifiers.h:102
clang::getParameterABISpelling
llvm::StringRef getParameterABISpelling(ParameterABI kind)
Definition: TypePrinter.cpp:759
clang::TST_auto
Definition: Specifiers.h:76
clang::SC_PrivateExtern
Definition: Specifiers.h:211
clang::CC_X86ThisCall
Definition: Specifiers.h:240
clang::TST_char16
Definition: Specifiers.h:51
clang::OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:136
clang::ExprValueKind
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:107
clang::SC_Auto
Definition: Specifiers.h:214
clang::WrittenBuiltinSpecs::Type
unsigned Type
Definition: Specifiers.h:89
clang::supportsVariadicCall
bool supportsVariadicCall(CallingConv CC)
Checks whether the given calling convention supports variadic calls.
Definition: Specifiers.h:259
clang::WrittenBuiltinSpecs::Sign
unsigned Sign
Definition: Specifiers.h:91
clang::StorageClass
StorageClass
Storage classes.
Definition: Specifiers.h:206
clang::isLegalForFunction
bool isLegalForFunction(StorageClass SC)
Checks whether the given storage class is legal for functions.
Definition: Specifiers.h:219
clang::InClassInitStyle
InClassInitStyle
In-class initialization styles for non-static data members.
Definition: Specifiers.h:229
clang::TST_unspecified
Definition: Specifiers.h:46
clang::CC_PreserveMost
Definition: Specifiers.h:252
clang::TSW_long
Definition: Specifiers.h:28
clang::WrittenBuiltinSpecs::Width
unsigned Width
Definition: Specifiers.h:92
clang::TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:152
clang::TypeSpecifiersPipe
TypeSpecifiersPipe
Definition: Specifiers.h:39
clang::isTemplateInstantiation
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:170
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:236
clang::TSS_unspecified
Definition: Specifiers.h:34
clang::SD_Dynamic
Dynamic storage duration.
Definition: Specifiers.h:282
clang::TST_decltype_auto
Definition: Specifiers.h:77
clang::CC_X86Pascal
Definition: Specifiers.h:242
clang::SD_Thread
Thread storage duration.
Definition: Specifiers.h:280
clang::AS_protected
Definition: Specifiers.h:100
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::hasWeakerNullability
bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)
Return true if L has a weaker nullability annotation than R.
Definition: Specifiers.h:300
clang::TST_underlyingType
Definition: Specifiers.h:75
clang::TST_error
Definition: Specifiers.h:83
clang::CC_X86FastCall
Definition: Specifiers.h:239
clang::ExprObjectKind
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:124
clang::isLegalForVariable
bool isLegalForVariable(StorageClass SC)
Checks whether the given storage class is legal for variables.
Definition: Specifiers.h:224
clang::AS_public
Definition: Specifiers.h:99
clang::TSCS___thread
GNU __thread.
Definition: Specifiers.h:196
clang::TST_enum
Definition: Specifiers.h:66
clang::ICIS_ListInit
Direct list-initialization.
Definition: Specifiers.h:232
clang::TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:164
clang::TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:149
clang::TST_double
Definition: Specifiers.h:60
clang::ParameterABI
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:309
clang::TSCS_thread_local
C++11 thread_local.
Definition: Specifiers.h:199
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::SC_Extern
Definition: Specifiers.h:209
clang::TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:160
clang::CC_C
Definition: Specifiers.h:237
clang::TST_Accum
Definition: Specifiers.h:57
clang::WrittenBuiltinSpecs::ModeAttr
unsigned ModeAttr
Definition: Specifiers.h:93
clang::TemplateSpecializationKind
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:146
clang::TSCS_unspecified
Definition: Specifiers.h:194
clang::CC_PreserveAll
Definition: Specifiers.h:253
clang::CC_AAPCS
Definition: Specifiers.h:246
clang::TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:156
clang::TST_atomic
Definition: Specifiers.h:80
clang::TSS_signed
Definition: Specifiers.h:35
clang::CC_Win64
Definition: Specifiers.h:243
clang::OK_BitField
A bitfield object is a bitfield on a C or C++ record.
Definition: Specifiers.h:129
clang::CC_AAPCS_VFP
Definition: Specifiers.h:247
clang::TSP_pipe
Definition: Specifiers.h:41
clang::TST_half
Definition: Specifiers.h:55
clang::WrittenBuiltinSpecs
Structure that packs information about the type specifiers that were written in a particular type spe...
Definition: Specifiers.h:88
clang::ThreadStorageClassSpecifier
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition: Specifiers.h:193
clang::TST_union
Definition: Specifiers.h:67
clang::TypeSpecifierWidth
TypeSpecifierWidth
Specifies the width of a type, e.g., short, long, or long long.
Definition: Specifiers.h:25
clang::TSW_longlong
Definition: Specifiers.h:29
clang::diag::kind
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
clang::SD_FullExpression
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:278
clang::TST_class
Definition: Specifiers.h:69
clang::SC_Register
Definition: Specifiers.h:215
clang::TST_Float16
Definition: Specifiers.h:56
clang::TST_decimal64
Definition: Specifiers.h:64
clang::TST_unknown_anytype
Definition: Specifiers.h:79
clang::TST_char8
Definition: Specifiers.h:50
clang::TST_typeofExpr
Definition: Specifiers.h:73
clang::VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:114
clang::SD_Automatic
Automatic storage duration (most local variables).
Definition: Specifiers.h:279
clang::TST_int128
Definition: Specifiers.h:54
clang::TST_decimal32
Definition: Specifiers.h:63
clang::getNullabilitySpelling
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
Definition: IdentifierTable.cpp:683
clang::ICIS_NoInit
No in-class initializer.
Definition: Specifiers.h:230
clang::ParameterABI::SwiftIndirectResult
This parameter (which must have pointer type) is a Swift indirect result parameter.