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