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