1//===--- OperationKinds.def - Operations Database ---------------*- 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// This file enumerates the different kinds of operations that can be
11// performed by various expressions.
12//
13//===----------------------------------------------------------------------===//
14//
15/// @file OperationKinds.def
16///
17/// In this file, each of the C/C++ operations is enumerated CAST_OPERATION,
18/// BINARY_OPERATION or UNARY_OPERATION macro, each of which can be specified by
19/// the code including this file.
20///
21/// Macros had one or two arguments:
22///
23/// Name: The name of the operation. Name (prefixed with CK_, UO_ or BO_) will
24/// be the name of the corresponding enumerator (see OperationsKinds.h).
25///
26/// Spelling: A string that provides a canonical spelling for the operation.
27
28#ifndef CAST_OPERATION
29# define CAST_OPERATION(Name)
30#endif
31
32#ifndef BINARY_OPERATION
33# define BINARY_OPERATION(Name, Spelling)
34#endif
35
36#ifndef UNARY_OPERATION
37# define UNARY_OPERATION(Name, Spelling)
38#endif
39
40//===- Cast Operations ---------------------------------------------------===//
41
42/// CK_Dependent - A conversion which cannot yet be analyzed because
43/// either the expression or target type is dependent. These are
44/// created only for explicit casts; dependent ASTs aren't required
45/// to even approximately type-check.
46/// (T*) malloc(sizeof(T))
47/// reinterpret_cast<intptr_t>(A<T>::alloc());
48CAST_OPERATION(Dependent)
49
50/// CK_BitCast - A conversion which causes a bit pattern of one type
51/// to be reinterpreted as a bit pattern of another type. Generally
52/// the operands must have equivalent size and unrelated types.
53///
54/// The pointer conversion char* -> int* is a bitcast. A conversion
55/// from any pointer type to a C pointer type is a bitcast unless
56/// it's actually BaseToDerived or DerivedToBase. A conversion to a
57/// block pointer or ObjC pointer type is a bitcast only if the
58/// operand has the same type kind; otherwise, it's one of the
59/// specialized casts below.
60///
61/// Vector coercions are bitcasts.
62CAST_OPERATION(BitCast)
63
64/// CK_LValueBitCast - A conversion which reinterprets the address of
65/// an l-value as an l-value of a different kind. Used for
66/// reinterpret_casts of l-value expressions to reference types.
67/// bool b; reinterpret_cast<char&>(b) = 'a';
68CAST_OPERATION(LValueBitCast)
69
70/// CK_LValueToRValue - A conversion which causes the extraction of
71/// an r-value from the operand gl-value. The result of an r-value
72/// conversion is always unqualified.
73CAST_OPERATION(LValueToRValue)
74
75/// CK_NoOp - A conversion which does not affect the type other than
76/// (possibly) adding qualifiers.
77/// int -> int
78/// char** -> const char * const *
79CAST_OPERATION(NoOp)
80
81/// CK_BaseToDerived - A conversion from a C++ class pointer/reference
82/// to a derived class pointer/reference.
83/// B *b = static_cast<B*>(a);
84CAST_OPERATION(BaseToDerived)
85
86/// CK_DerivedToBase - A conversion from a C++ class pointer
87/// to a base class pointer.
88/// A *a = new B();
89CAST_OPERATION(DerivedToBase)
90
91/// CK_UncheckedDerivedToBase - A conversion from a C++ class
92/// pointer/reference to a base class that can assume that the
93/// derived pointer is not null.
94/// const A &a = B();
95/// b->method_from_a();
96CAST_OPERATION(UncheckedDerivedToBase)
97
98/// CK_Dynamic - A C++ dynamic_cast.
99CAST_OPERATION(Dynamic)
100
101/// CK_ToUnion - The GCC cast-to-union extension.
102/// int -> union { int x; float y; }
103/// float -> union { int x; float y; }
104CAST_OPERATION(ToUnion)
105
106/// CK_ArrayToPointerDecay - Array to pointer decay.
107/// int[10] -> int*
108/// char[5][6] -> char(*)[6]
109CAST_OPERATION(ArrayToPointerDecay)
110
111/// CK_FunctionToPointerDecay - Function to pointer decay.
112/// void(int) -> void(*)(int)
113CAST_OPERATION(FunctionToPointerDecay)
114
115/// CK_NullToPointer - Null pointer constant to pointer, ObjC
116/// pointer, or block pointer.
117/// (void*) 0
118/// void (^block)() = 0;
119CAST_OPERATION(NullToPointer)
120
121/// CK_NullToMemberPointer - Null pointer constant to member pointer.
122/// int A::*mptr = 0;
123/// int (A::*fptr)(int) = nullptr;
124CAST_OPERATION(NullToMemberPointer)
125
126/// CK_BaseToDerivedMemberPointer - Member pointer in base class to
127/// member pointer in derived class.
128/// int B::*mptr = &A::member;
129CAST_OPERATION(BaseToDerivedMemberPointer)
130
131/// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
132/// member pointer in base class.
133/// int A::*mptr = static_cast<int A::*>(&B::member);
134CAST_OPERATION(DerivedToBaseMemberPointer)
135
136/// CK_MemberPointerToBoolean - Member pointer to boolean. A check
137/// against the null member pointer.
138CAST_OPERATION(MemberPointerToBoolean)
139
140/// CK_ReinterpretMemberPointer - Reinterpret a member pointer as a
141/// different kind of member pointer. C++ forbids this from
142/// crossing between function and object types, but otherwise does
143/// not restrict it. However, the only operation that is permitted
144/// on a "punned" member pointer is casting it back to the original
145/// type, which is required to be a lossless operation (although
146/// many ABIs do not guarantee this on all possible intermediate types).
147CAST_OPERATION(ReinterpretMemberPointer)
148
149/// CK_UserDefinedConversion - Conversion using a user defined type
150/// conversion function.
151/// struct A { operator int(); }; int i = int(A());
152CAST_OPERATION(UserDefinedConversion)
153
154/// CK_ConstructorConversion - Conversion by constructor.
155/// struct A { A(int); }; A a = A(10);
156CAST_OPERATION(ConstructorConversion)
157
158/// CK_IntegralToPointer - Integral to pointer. A special kind of
159/// reinterpreting conversion. Applies to normal, ObjC, and block
160/// pointers.
161/// (char*) 0x1001aab0
162/// reinterpret_cast<int*>(0)
163CAST_OPERATION(IntegralToPointer)
164
165/// CK_PointerToIntegral - Pointer to integral. A special kind of
166/// reinterpreting conversion. Applies to normal, ObjC, and block
167/// pointers.
168/// (intptr_t) "help!"
169CAST_OPERATION(PointerToIntegral)
170
171/// CK_PointerToBoolean - Pointer to boolean conversion. A check
172/// against null. Applies to normal, ObjC, and block pointers.
173CAST_OPERATION(PointerToBoolean)
174
175/// CK_ToVoid - Cast to void, discarding the computed value.
176/// (void) malloc(2048)
177CAST_OPERATION(ToVoid)
178
179/// CK_VectorSplat - A conversion from an arithmetic type to a
180/// vector of that element type. Fills all elements ("splats") with
181/// the source value.
182/// __attribute__((ext_vector_type(4))) int v = 5;
183CAST_OPERATION(VectorSplat)
184
185/// CK_IntegralCast - A cast between integral types (other than to
186/// boolean). Variously a bitcast, a truncation, a sign-extension,
187/// or a zero-extension.
188/// long l = 5;
189/// (unsigned) i
190CAST_OPERATION(IntegralCast)
191
192/// CK_IntegralToBoolean - Integral to boolean. A check against zero.
193/// (bool) i
194CAST_OPERATION(IntegralToBoolean)
195
196/// CK_IntegralToFloating - Integral to floating point.
197/// float f = i;
198CAST_OPERATION(IntegralToFloating)
199
200/// CK_FloatingToIntegral - Floating point to integral. Rounds
201/// towards zero, discarding any fractional component.
202/// (int) f
203CAST_OPERATION(FloatingToIntegral)
204
205/// CK_FloatingToBoolean - Floating point to boolean.
206/// (bool) f
207CAST_OPERATION(FloatingToBoolean)
208
209// CK_BooleanToSignedIntegral - Convert a boolean to -1 or 0 for true and
210// false, respectively.
211CAST_OPERATION(BooleanToSignedIntegral)
212
213/// CK_FloatingCast - Casting between floating types of different size.
214/// (double) f
215/// (float) ld
216CAST_OPERATION(FloatingCast)
217
218/// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an
219/// Objective-C pointer.
220CAST_OPERATION(CPointerToObjCPointerCast)
221
222/// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an
223/// ObjC pointer.
224CAST_OPERATION(BlockPointerToObjCPointerCast)
225
226/// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer
227/// to a block pointer. Block-to-block casts are bitcasts.
228CAST_OPERATION(AnyPointerToBlockPointerCast)
229
230/// \brief Converting between two Objective-C object types, which
231/// can occur when performing reference binding to an Objective-C
232/// object.
233CAST_OPERATION(ObjCObjectLValueCast)
234
235/// \brief A conversion of a floating point real to a floating point
236/// complex of the original type. Injects the value as the real
237/// component with a zero imaginary component.
238/// float -> _Complex float
239CAST_OPERATION(FloatingRealToComplex)
240
241/// \brief Converts a floating point complex to floating point real
242/// of the source's element type. Just discards the imaginary
243/// component.
244/// _Complex long double -> long double
245CAST_OPERATION(FloatingComplexToReal)
246
247/// \brief Converts a floating point complex to bool by comparing
248/// against 0+0i.
249CAST_OPERATION(FloatingComplexToBoolean)
250
251/// \brief Converts between different floating point complex types.
252/// _Complex float -> _Complex double
253CAST_OPERATION(FloatingComplexCast)
254
255/// \brief Converts from a floating complex to an integral complex.
256/// _Complex float -> _Complex int
257CAST_OPERATION(FloatingComplexToIntegralComplex)
258
259/// \brief Converts from an integral real to an integral complex
260/// whose element type matches the source. Injects the value as
261/// the real component with a zero imaginary component.
262/// long -> _Complex long
263CAST_OPERATION(IntegralRealToComplex)
264
265/// \brief Converts an integral complex to an integral real of the
266/// source's element type by discarding the imaginary component.
267/// _Complex short -> short
268CAST_OPERATION(IntegralComplexToReal)
269
270/// \brief Converts an integral complex to bool by comparing against
271/// 0+0i.
272CAST_OPERATION(IntegralComplexToBoolean)
273
274/// \brief Converts between different integral complex types.
275/// _Complex char -> _Complex long long
276/// _Complex unsigned int -> _Complex signed int
277CAST_OPERATION(IntegralComplexCast)
278
279/// \brief Converts from an integral complex to a floating complex.
280/// _Complex unsigned -> _Complex float
281CAST_OPERATION(IntegralComplexToFloatingComplex)
282
283/// \brief [ARC] Produces a retainable object pointer so that it may
284/// be consumed, e.g. by being passed to a consuming parameter.
285/// Calls objc_retain.
286CAST_OPERATION(ARCProduceObject)
287
288/// \brief [ARC] Consumes a retainable object pointer that has just
289/// been produced, e.g. as the return value of a retaining call.
290/// Enters a cleanup to call objc_release at some indefinite time.
291CAST_OPERATION(ARCConsumeObject)
292
293/// \brief [ARC] Reclaim a retainable object pointer object that may
294/// have been produced and autoreleased as part of a function return
295/// sequence.
296CAST_OPERATION(ARCReclaimReturnedObject)
297
298/// \brief [ARC] Causes a value of block type to be copied to the
299/// heap, if it is not already there. A number of other operations
300/// in ARC cause blocks to be copied; this is for cases where that
301/// would not otherwise be guaranteed, such as when casting to a
302/// non-block pointer type.
303CAST_OPERATION(ARCExtendBlockObject)
304
305/// \brief Converts from _Atomic(T) to T.
306CAST_OPERATION(AtomicToNonAtomic)
307/// \brief Converts from T to _Atomic(T).
308CAST_OPERATION(NonAtomicToAtomic)
309
310/// \brief Causes a block literal to by copied to the heap and then
311/// autoreleased.
312///
313/// This particular cast kind is used for the conversion from a C++11
314/// lambda expression to a block pointer.
315CAST_OPERATION(CopyAndAutoreleaseBlockObject)
316
317// Convert a builtin function to a function pointer; only allowed in the
318// callee of a call expression.
319CAST_OPERATION(BuiltinFnToFnPtr)
320
321// Convert a zero value for OpenCL event_t initialization.
322CAST_OPERATION(ZeroToOCLEvent)
323
324// Convert a zero value for OpenCL queue_t initialization.
325CAST_OPERATION(ZeroToOCLQueue)
326
327// Convert a pointer to a different address space.
328CAST_OPERATION(AddressSpaceConversion)
329
330// Convert an integer initializer to an OpenCL sampler.
331CAST_OPERATION(IntToOCLSampler)
332
333//===- Binary Operations -------------------------------------------------===//
334// Operators listed in order of precedence.
335// Note that additions to this should also update the StmtVisitor class.
336
337// [C++ 5.5] Pointer-to-member operators.
338BINARY_OPERATION(PtrMemD, ".*")
339BINARY_OPERATION(PtrMemI, "->*")
340// [C99 6.5.5] Multiplicative operators.
341BINARY_OPERATION(Mul, "*")
342BINARY_OPERATION(Div, "/")
343BINARY_OPERATION(Rem, "%")
344// [C99 6.5.6] Additive operators.
345BINARY_OPERATION(Add, "+")
346BINARY_OPERATION(Sub, "-")
347// [C99 6.5.7] Bitwise shift operators.
348BINARY_OPERATION(Shl, "<<")
349BINARY_OPERATION(Shr, ">>")
350// [C99 6.5.8] Relational operators.
351BINARY_OPERATION(LT, "<")
352BINARY_OPERATION(GT, ">")
353BINARY_OPERATION(LE, "<=")
354BINARY_OPERATION(GE, ">=")
355// [C99 6.5.9] Equality operators.
356BINARY_OPERATION(EQ, "==")
357BINARY_OPERATION(NE, "!=")
358// [C99 6.5.10] Bitwise AND operator.
359BINARY_OPERATION(And, "&")
360// [C99 6.5.11] Bitwise XOR operator.
361BINARY_OPERATION(Xor, "^")
362// [C99 6.5.12] Bitwise OR operator.
363BINARY_OPERATION(Or, "|")
364// [C99 6.5.13] Logical AND operator.
365BINARY_OPERATION(LAnd, "&&")
366// [C99 6.5.14] Logical OR operator.
367BINARY_OPERATION(LOr, "||")
368// [C99 6.5.16] Assignment operators.
369BINARY_OPERATION(Assign, "=")
370BINARY_OPERATION(MulAssign, "*=")
371BINARY_OPERATION(DivAssign, "/=")
372BINARY_OPERATION(RemAssign, "%=")
373BINARY_OPERATION(AddAssign, "+=")
374BINARY_OPERATION(SubAssign, "-=")
375BINARY_OPERATION(ShlAssign, "<<=")
376BINARY_OPERATION(ShrAssign, ">>=")
377BINARY_OPERATION(AndAssign, "&=")
378BINARY_OPERATION(XorAssign, "^=")
379BINARY_OPERATION(OrAssign, "|=")
380// [C99 6.5.17] Comma operator.
381BINARY_OPERATION(Comma, ",")
382
383
384//===- Unary Operations ---------------------------------------------------===//
385// Note that additions to this should also update the StmtVisitor class.
386
387// [C99 6.5.2.4] Postfix increment and decrement
388UNARY_OPERATION(PostInc, "++")
389UNARY_OPERATION(PostDec, "--")
390// [C99 6.5.3.1] Prefix increment and decrement
391UNARY_OPERATION(PreInc, "++")
392UNARY_OPERATION(PreDec, "--")
393// [C99 6.5.3.2] Address and indirection
394UNARY_OPERATION(AddrOf, "&")
395UNARY_OPERATION(Deref, "*")
396// [C99 6.5.3.3] Unary arithmetic
397UNARY_OPERATION(Plus, "+")
398UNARY_OPERATION(Minus, "-")
399UNARY_OPERATION(Not, "~")
400UNARY_OPERATION(LNot, "!")
401// "__real expr"/"__imag expr" Extension.
402UNARY_OPERATION(Real, "__real")
403UNARY_OPERATION(Imag, "__imag")
404// __extension__ marker.
405UNARY_OPERATION(Extension, "__extension__")
406// [C++ Coroutines] co_await operator
407UNARY_OPERATION(Coawait, "co_await")
408
409#undef CAST_OPERATION
410#undef BINARY_OPERATION
411#undef UNARY_OPERATION
412