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