clang  9.0.0svn
Specifiers.h
Go to the documentation of this file.
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 
22 namespace clang {
23 
24  /// Define the meaning of possible values of the kind in ExplicitSpecifier.
25  enum class ExplicitSpecKind : unsigned {
28  Unresolved,
29  };
30 
31  /// Specifies the width of a type, e.g., short, long, or long long.
37  };
38 
39  /// Specifies the signedness of a type, e.g., signed or unsigned.
44  };
45 
49  };
50 
51  /// Specifies the kind of type.
56  TST_wchar, // C++ wchar_t
57  TST_char8, // C++20 char8_t (proposed)
58  TST_char16, // C++11 char16_t
59  TST_char32, // C++11 char32_t
62  TST_half, // OpenCL half, ARM NEON __fp16
63  TST_Float16, // C11 extension ISO/IEC TS 18661-3
64  TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension
69  TST_bool, // _Bool
70  TST_decimal32, // _Decimal32
71  TST_decimal64, // _Decimal64
72  TST_decimal128, // _Decimal128
76  TST_class, // C++ class type
77  TST_interface, // C++ (Microsoft-specific) __interface type
78  TST_typename, // Typedef, C++ class-name or enum name, etc.
81  TST_decltype, // C++11 decltype
82  TST_underlyingType, // __underlying_type for C++11
83  TST_auto, // C++11 auto
84  TST_decltype_auto, // C++1y decltype(auto)
85  TST_auto_type, // __auto_type extension
86  TST_unknown_anytype, // __unknown_anytype extension
87  TST_atomic, // C11 _Atomic
88 #define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image types
89 #include "clang/Basic/OpenCLImageTypes.def"
90  TST_error // erroneous type
91  };
92 
93  /// Structure that packs information about the type specifiers that
94  /// were written in a particular type specifier sequence.
96  static_assert(TST_error < 1 << 6, "Type bitfield not wide enough for TST");
97  /*DeclSpec::TST*/ unsigned Type : 6;
98  /*DeclSpec::TSS*/ unsigned Sign : 2;
99  /*DeclSpec::TSW*/ unsigned Width : 2;
100  unsigned ModeAttr : 1;
101  };
102 
103  /// A C++ access specifier (public, private, protected), plus the
104  /// special value "none" which means different things in different contexts.
110  };
111 
112  /// The categorization of expression values, currently following the
113  /// C++11 scheme.
115  /// An r-value expression (a pr-value in the C++11 taxonomy)
116  /// produces a temporary value.
118 
119  /// An l-value expression is a reference to an object with
120  /// independent storage.
122 
123  /// An x-value expression is a reference to an object with
124  /// independent storage but which can be "moved", i.e.
125  /// efficiently cannibalized for its resources.
127  };
128 
129  /// A further classification of the kind of object referenced by an
130  /// l-value or x-value.
132  /// An ordinary object is located at an address in memory.
134 
135  /// A bitfield object is a bitfield on a C or C++ record.
137 
138  /// A vector component is an element or range of elements on a vector.
140 
141  /// An Objective-C property is a logical field of an Objective-C
142  /// object which is read and written via Objective-C method calls.
144 
145  /// An Objective-C array/dictionary subscripting which reads an
146  /// object or writes at the subscripted array/dictionary element via
147  /// Objective-C method calls.
149  };
150 
151  /// Describes the kind of template specialization that a
152  /// particular template specialization declaration represents.
154  /// This template specialization was formed from a template-id but
155  /// has not yet been declared, defined, or instantiated.
157  /// This template specialization was implicitly instantiated from a
158  /// template. (C++ [temp.inst]).
160  /// This template specialization was declared or defined by an
161  /// explicit specialization (C++ [temp.expl.spec]) or partial
162  /// specialization (C++ [temp.class.spec]).
164  /// This template specialization was instantiated from a template
165  /// due to an explicit instantiation declaration request
166  /// (C++11 [temp.explicit]).
168  /// This template specialization was instantiated from a template
169  /// due to an explicit instantiation definition request
170  /// (C++ [temp.explicit]).
172  };
173 
174  /// Determine whether this template specialization kind refers
175  /// to an instantiation of an entity (as opposed to a non-template or
176  /// an explicit specialization).
178  return Kind != TSK_Undeclared && Kind != TSK_ExplicitSpecialization;
179  }
180 
181  /// True if this template specialization kind is an explicit
182  /// specialization, explicit instantiation declaration, or explicit
183  /// instantiation definition.
186  switch (Kind) {
190  return true;
191 
192  case TSK_Undeclared:
194  return false;
195  }
196  llvm_unreachable("bad template specialization kind");
197  }
198 
199  /// Thread storage-class-specifier.
202  /// GNU __thread.
204  /// C++11 thread_local. Implies 'static' at block scope, but not at
205  /// class scope.
207  /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
208  /// if used at block scope.
210  };
211 
212  /// Storage classes.
214  // These are legal on both functions and variables.
219 
220  // These are only legal on variables.
223  };
224 
225  /// Checks whether the given storage class is legal for functions.
227  return SC <= SC_PrivateExtern;
228  }
229 
230  /// Checks whether the given storage class is legal for variables.
232  return true;
233  }
234 
235  /// In-class initialization styles for non-static data members.
237  ICIS_NoInit, ///< No in-class initializer.
238  ICIS_CopyInit, ///< Copy initialization.
239  ICIS_ListInit ///< Direct list-initialization.
240  };
241 
242  /// CallingConv - Specifies the calling convention that a function uses.
243  enum CallingConv {
244  CC_C, // __attribute__((cdecl))
245  CC_X86StdCall, // __attribute__((stdcall))
246  CC_X86FastCall, // __attribute__((fastcall))
247  CC_X86ThisCall, // __attribute__((thiscall))
248  CC_X86VectorCall, // __attribute__((vectorcall))
249  CC_X86Pascal, // __attribute__((pascal))
250  CC_Win64, // __attribute__((ms_abi))
251  CC_X86_64SysV, // __attribute__((sysv_abi))
252  CC_X86RegCall, // __attribute__((regcall))
253  CC_AAPCS, // __attribute__((pcs("aapcs")))
254  CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp")))
255  CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
256  CC_SpirFunction, // default for OpenCL functions on SPIR target
257  CC_OpenCLKernel, // inferred for OpenCL kernels
258  CC_Swift, // __attribute__((swiftcall))
259  CC_PreserveMost, // __attribute__((preserve_most))
260  CC_PreserveAll, // __attribute__((preserve_all))
261  CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
262  };
263 
264  /// Checks whether the given calling convention supports variadic
265  /// calls. Unprototyped calls also use the variadic call rules.
267  switch (CC) {
268  case CC_X86StdCall:
269  case CC_X86FastCall:
270  case CC_X86ThisCall:
271  case CC_X86RegCall:
272  case CC_X86Pascal:
273  case CC_X86VectorCall:
274  case CC_SpirFunction:
275  case CC_OpenCLKernel:
276  case CC_Swift:
277  return false;
278  default:
279  return true;
280  }
281  }
282 
283  /// The storage duration for an object (per C++ [basic.stc]).
285  SD_FullExpression, ///< Full-expression storage duration (for temporaries).
286  SD_Automatic, ///< Automatic storage duration (most local variables).
287  SD_Thread, ///< Thread storage duration.
288  SD_Static, ///< Static storage duration.
289  SD_Dynamic ///< Dynamic storage duration.
290  };
291 
292  /// Describes the nullability of a particular type.
293  enum class NullabilityKind : uint8_t {
294  /// Values of this type can never be null.
295  NonNull = 0,
296  /// Values of this type can be null.
297  Nullable,
298  /// Whether values of this type can be null is (explicitly)
299  /// unspecified. This captures a (fairly rare) case where we
300  /// can't conclude anything about the nullability of the type even
301  /// though it has been considered.
303  };
304 
305  /// Return true if \p L has a weaker nullability annotation than \p R. The
306  /// ordering is: Unspecified < Nullable < NonNull.
308  return uint8_t(L) > uint8_t(R);
309  }
310 
311  /// Retrieve the spelling of the given nullability kind.
313  bool isContextSensitive = false);
314 
315  /// Kinds of parameter ABI.
316  enum class ParameterABI {
317  /// This parameter uses ordinary ABI rules for its type.
318  Ordinary,
319 
320  /// This parameter (which must have pointer type) is a Swift
321  /// indirect result parameter.
323 
324  /// This parameter (which must have pointer-to-pointer type) uses
325  /// the special Swift error-result ABI treatment. There can be at
326  /// most one parameter on a given function that uses this treatment.
328 
329  /// This parameter (which must have pointer type) uses the special
330  /// Swift context-pointer ABI treatment. There can be at
331  /// most one parameter on a given function that uses this treatment.
333  };
334 
335  llvm::StringRef getParameterABISpelling(ParameterABI kind);
336 } // end namespace clang
337 
338 #endif // LLVM_CLANG_BASIC_SPECIFIERS_H
Static storage duration.
Definition: Specifiers.h:288
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:293
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:105
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition: Specifiers.h:284
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
Definition: Specifiers.h:148
TypeSpecifierType
Specifies the kind of type.
Definition: Specifiers.h:52
bool isTemplateExplicitInstantiationOrSpecialization(TemplateSpecializationKind Kind)
True if this template specialization kind is an explicit specialization, explicit instantiation decla...
Definition: Specifiers.h:184
C11 _Thread_local.
Definition: Specifiers.h:209
A vector component is an element or range of elements on a vector.
Definition: Specifiers.h:139
Copy initialization.
Definition: Specifiers.h:238
TypeSpecifierSign
Specifies the signedness of a type, e.g., signed or unsigned.
Definition: Specifiers.h:40
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:117
Values of this type can be null.
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
Whether values of this type can be null is (explicitly) unspecified.
An x-value expression is a reference to an object with independent storage but which can be "moved"...
Definition: Specifiers.h:126
Values of this type can never be null.
An ordinary object is located at an address in memory.
Definition: Specifiers.h:133
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
llvm::StringRef getParameterABISpelling(ParameterABI kind)
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:143
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:114
bool supportsVariadicCall(CallingConv CC)
Checks whether the given calling convention supports variadic calls.
Definition: Specifiers.h:266
StorageClass
Storage classes.
Definition: Specifiers.h:213
bool isLegalForFunction(StorageClass SC)
Checks whether the given storage class is legal for functions.
Definition: Specifiers.h:226
InClassInitStyle
In-class initialization styles for non-static data members.
Definition: Specifiers.h:236
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:159
TypeSpecifiersPipe
Definition: Specifiers.h:46
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:177
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:243
Dynamic storage duration.
Definition: Specifiers.h:289
Thread storage duration.
Definition: Specifiers.h:287
Kind
bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)
Return true if L has a weaker nullability annotation than R.
Definition: Specifiers.h:307
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:131
bool isLegalForVariable(StorageClass SC)
Checks whether the given storage class is legal for variables.
Definition: Specifiers.h:231
GNU __thread.
Definition: Specifiers.h:203
Direct list-initialization.
Definition: Specifiers.h:239
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:171
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:156
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:316
C++11 thread_local.
Definition: Specifiers.h:206
Dataflow Directional Tag Classes.
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:167
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:153
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:163
A bitfield object is a bitfield on a C or C++ record.
Definition: Specifiers.h:136
Structure that packs information about the type specifiers that were written in a particular type spe...
Definition: Specifiers.h:95
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition: Specifiers.h:200
TypeSpecifierWidth
Specifies the width of a type, e.g., short, long, or long long.
Definition: Specifiers.h:32
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:60
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:285
ExplicitSpecKind
Define the meaning of possible values of the kind in ExplicitSpecifier.
Definition: Specifiers.h:25
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:121
Automatic storage duration (most local variables).
Definition: Specifiers.h:286
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
No in-class initializer.
Definition: Specifiers.h:237
This parameter (which must have pointer type) is a Swift indirect result parameter.