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