1 //===--- OperationKinds.def - Operations Database ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file enumerates the different kinds of operations that can be
11 // performed by various expressions.
13 //===----------------------------------------------------------------------===//
15 /// @file OperationKinds.def
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.
21 /// Macros had one or two arguments:
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).
26 /// Spelling: A string that provides a canonical spelling for the operation.
28 #ifndef CAST_OPERATION
29 # define CAST_OPERATION(Name)
32 #ifndef BINARY_OPERATION
33 # define BINARY_OPERATION(Name, Spelling)
36 #ifndef UNARY_OPERATION
37 # define UNARY_OPERATION(Name, Spelling)
40 //===- Cast Operations ---------------------------------------------------===//
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());
48 CAST_OPERATION(Dependent)
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.
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.
61 /// Vector coercions are bitcasts.
62 CAST_OPERATION(BitCast)
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';
68 CAST_OPERATION(LValueBitCast)
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.
73 CAST_OPERATION(LValueToRValue)
75 /// CK_NoOp - A conversion which does not affect the type other than
76 /// (possibly) adding qualifiers.
78 /// char** -> const char * const *
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);
84 CAST_OPERATION(BaseToDerived)
86 /// CK_DerivedToBase - A conversion from a C++ class pointer
87 /// to a base class pointer.
89 CAST_OPERATION(DerivedToBase)
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.
95 /// b->method_from_a();
96 CAST_OPERATION(UncheckedDerivedToBase)
98 /// CK_Dynamic - A C++ dynamic_cast.
99 CAST_OPERATION(Dynamic)
101 /// CK_ToUnion - The GCC cast-to-union extension.
102 /// int -> union { int x; float y; }
103 /// float -> union { int x; float y; }
104 CAST_OPERATION(ToUnion)
106 /// CK_ArrayToPointerDecay - Array to pointer decay.
108 /// char[5][6] -> char(*)[6]
109 CAST_OPERATION(ArrayToPointerDecay)
111 /// CK_FunctionToPointerDecay - Function to pointer decay.
112 /// void(int) -> void(*)(int)
113 CAST_OPERATION(FunctionToPointerDecay)
115 /// CK_NullToPointer - Null pointer constant to pointer, ObjC
116 /// pointer, or block pointer.
118 /// void (^block)() = 0;
119 CAST_OPERATION(NullToPointer)
121 /// CK_NullToMemberPointer - Null pointer constant to member pointer.
122 /// int A::*mptr = 0;
123 /// int (A::*fptr)(int) = nullptr;
124 CAST_OPERATION(NullToMemberPointer)
126 /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
127 /// member pointer in derived class.
128 /// int B::*mptr = &A::member;
129 CAST_OPERATION(BaseToDerivedMemberPointer)
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);
134 CAST_OPERATION(DerivedToBaseMemberPointer)
136 /// CK_MemberPointerToBoolean - Member pointer to boolean. A check
137 /// against the null member pointer.
138 CAST_OPERATION(MemberPointerToBoolean)
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).
147 CAST_OPERATION(ReinterpretMemberPointer)
149 /// CK_UserDefinedConversion - Conversion using a user defined type
150 /// conversion function.
151 /// struct A { operator int(); }; int i = int(A());
152 CAST_OPERATION(UserDefinedConversion)
154 /// CK_ConstructorConversion - Conversion by constructor.
155 /// struct A { A(int); }; A a = A(10);
156 CAST_OPERATION(ConstructorConversion)
158 /// CK_IntegralToPointer - Integral to pointer. A special kind of
159 /// reinterpreting conversion. Applies to normal, ObjC, and block
161 /// (char*) 0x1001aab0
162 /// reinterpret_cast<int*>(0)
163 CAST_OPERATION(IntegralToPointer)
165 /// CK_PointerToIntegral - Pointer to integral. A special kind of
166 /// reinterpreting conversion. Applies to normal, ObjC, and block
168 /// (intptr_t) "help!"
169 CAST_OPERATION(PointerToIntegral)
171 /// CK_PointerToBoolean - Pointer to boolean conversion. A check
172 /// against null. Applies to normal, ObjC, and block pointers.
173 CAST_OPERATION(PointerToBoolean)
175 /// CK_ToVoid - Cast to void, discarding the computed value.
176 /// (void) malloc(2048)
177 CAST_OPERATION(ToVoid)
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;
183 CAST_OPERATION(VectorSplat)
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.
190 CAST_OPERATION(IntegralCast)
192 /// CK_IntegralToBoolean - Integral to boolean. A check against zero.
194 CAST_OPERATION(IntegralToBoolean)
196 /// CK_IntegralToFloating - Integral to floating point.
198 CAST_OPERATION(IntegralToFloating)
200 /// CK_FloatingToIntegral - Floating point to integral. Rounds
201 /// towards zero, discarding any fractional component.
203 CAST_OPERATION(FloatingToIntegral)
205 /// CK_FloatingToBoolean - Floating point to boolean.
207 CAST_OPERATION(FloatingToBoolean)
209 // CK_BooleanToSignedIntegral - Convert a boolean to -1 or 0 for true and
210 // false, respectively.
211 CAST_OPERATION(BooleanToSignedIntegral)
213 /// CK_FloatingCast - Casting between floating types of different size.
216 CAST_OPERATION(FloatingCast)
218 /// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an
219 /// Objective-C pointer.
220 CAST_OPERATION(CPointerToObjCPointerCast)
222 /// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an
224 CAST_OPERATION(BlockPointerToObjCPointerCast)
226 /// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer
227 /// to a block pointer. Block-to-block casts are bitcasts.
228 CAST_OPERATION(AnyPointerToBlockPointerCast)
230 /// \brief Converting between two Objective-C object types, which
231 /// can occur when performing reference binding to an Objective-C
233 CAST_OPERATION(ObjCObjectLValueCast)
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
239 CAST_OPERATION(FloatingRealToComplex)
241 /// \brief Converts a floating point complex to floating point real
242 /// of the source's element type. Just discards the imaginary
244 /// _Complex long double -> long double
245 CAST_OPERATION(FloatingComplexToReal)
247 /// \brief Converts a floating point complex to bool by comparing
249 CAST_OPERATION(FloatingComplexToBoolean)
251 /// \brief Converts between different floating point complex types.
252 /// _Complex float -> _Complex double
253 CAST_OPERATION(FloatingComplexCast)
255 /// \brief Converts from a floating complex to an integral complex.
256 /// _Complex float -> _Complex int
257 CAST_OPERATION(FloatingComplexToIntegralComplex)
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
263 CAST_OPERATION(IntegralRealToComplex)
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
268 CAST_OPERATION(IntegralComplexToReal)
270 /// \brief Converts an integral complex to bool by comparing against
272 CAST_OPERATION(IntegralComplexToBoolean)
274 /// \brief Converts between different integral complex types.
275 /// _Complex char -> _Complex long long
276 /// _Complex unsigned int -> _Complex signed int
277 CAST_OPERATION(IntegralComplexCast)
279 /// \brief Converts from an integral complex to a floating complex.
280 /// _Complex unsigned -> _Complex float
281 CAST_OPERATION(IntegralComplexToFloatingComplex)
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.
286 CAST_OPERATION(ARCProduceObject)
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.
291 CAST_OPERATION(ARCConsumeObject)
293 /// \brief [ARC] Reclaim a retainable object pointer object that may
294 /// have been produced and autoreleased as part of a function return
296 CAST_OPERATION(ARCReclaimReturnedObject)
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.
303 CAST_OPERATION(ARCExtendBlockObject)
305 /// \brief Converts from _Atomic(T) to T.
306 CAST_OPERATION(AtomicToNonAtomic)
307 /// \brief Converts from T to _Atomic(T).
308 CAST_OPERATION(NonAtomicToAtomic)
310 /// \brief Causes a block literal to by copied to the heap and then
313 /// This particular cast kind is used for the conversion from a C++11
314 /// lambda expression to a block pointer.
315 CAST_OPERATION(CopyAndAutoreleaseBlockObject)
317 // Convert a builtin function to a function pointer; only allowed in the
318 // callee of a call expression.
319 CAST_OPERATION(BuiltinFnToFnPtr)
321 // Convert a zero value for OpenCL event_t initialization.
322 CAST_OPERATION(ZeroToOCLEvent)
324 // Convert a zero value for OpenCL queue_t initialization.
325 CAST_OPERATION(ZeroToOCLQueue)
327 // Convert a pointer to a different address space.
328 CAST_OPERATION(AddressSpaceConversion)
330 // Convert an integer initializer to an OpenCL sampler.
331 CAST_OPERATION(IntToOCLSampler)
333 //===- Binary Operations -------------------------------------------------===//
334 // Operators listed in order of precedence.
335 // Note that additions to this should also update the StmtVisitor class and
336 // BinaryOperator::getOverloadedOperator.
338 // [C++ 5.5] Pointer-to-member operators.
339 BINARY_OPERATION(PtrMemD, ".*")
340 BINARY_OPERATION(PtrMemI, "->*")
341 // [C99 6.5.5] Multiplicative operators.
342 BINARY_OPERATION(Mul, "*")
343 BINARY_OPERATION(Div, "/")
344 BINARY_OPERATION(Rem, "%")
345 // [C99 6.5.6] Additive operators.
346 BINARY_OPERATION(Add, "+")
347 BINARY_OPERATION(Sub, "-")
348 // [C99 6.5.7] Bitwise shift operators.
349 BINARY_OPERATION(Shl, "<<")
350 BINARY_OPERATION(Shr, ">>")
351 // C++20 [expr.spaceship] Three-way comparison operator.
352 BINARY_OPERATION(Cmp, "<=>")
353 // [C99 6.5.8] Relational operators.
354 BINARY_OPERATION(LT, "<")
355 BINARY_OPERATION(GT, ">")
356 BINARY_OPERATION(LE, "<=")
357 BINARY_OPERATION(GE, ">=")
358 // [C99 6.5.9] Equality operators.
359 BINARY_OPERATION(EQ, "==")
360 BINARY_OPERATION(NE, "!=")
361 // [C99 6.5.10] Bitwise AND operator.
362 BINARY_OPERATION(And, "&")
363 // [C99 6.5.11] Bitwise XOR operator.
364 BINARY_OPERATION(Xor, "^")
365 // [C99 6.5.12] Bitwise OR operator.
366 BINARY_OPERATION(Or, "|")
367 // [C99 6.5.13] Logical AND operator.
368 BINARY_OPERATION(LAnd, "&&")
369 // [C99 6.5.14] Logical OR operator.
370 BINARY_OPERATION(LOr, "||")
371 // [C99 6.5.16] Assignment operators.
372 BINARY_OPERATION(Assign, "=")
373 BINARY_OPERATION(MulAssign, "*=")
374 BINARY_OPERATION(DivAssign, "/=")
375 BINARY_OPERATION(RemAssign, "%=")
376 BINARY_OPERATION(AddAssign, "+=")
377 BINARY_OPERATION(SubAssign, "-=")
378 BINARY_OPERATION(ShlAssign, "<<=")
379 BINARY_OPERATION(ShrAssign, ">>=")
380 BINARY_OPERATION(AndAssign, "&=")
381 BINARY_OPERATION(XorAssign, "^=")
382 BINARY_OPERATION(OrAssign, "|=")
383 // [C99 6.5.17] Comma operator.
384 BINARY_OPERATION(Comma, ",")
387 //===- Unary Operations ---------------------------------------------------===//
388 // Note that additions to this should also update the StmtVisitor class and
389 // UnaryOperator::getOverloadedOperator.
391 // [C99 6.5.2.4] Postfix increment and decrement
392 UNARY_OPERATION(PostInc, "++")
393 UNARY_OPERATION(PostDec, "--")
394 // [C99 6.5.3.1] Prefix increment and decrement
395 UNARY_OPERATION(PreInc, "++")
396 UNARY_OPERATION(PreDec, "--")
397 // [C99 6.5.3.2] Address and indirection
398 UNARY_OPERATION(AddrOf, "&")
399 UNARY_OPERATION(Deref, "*")
400 // [C99 6.5.3.3] Unary arithmetic
401 UNARY_OPERATION(Plus, "+")
402 UNARY_OPERATION(Minus, "-")
403 UNARY_OPERATION(Not, "~")
404 UNARY_OPERATION(LNot, "!")
405 // "__real expr"/"__imag expr" Extension.
406 UNARY_OPERATION(Real, "__real")
407 UNARY_OPERATION(Imag, "__imag")
408 // __extension__ marker.
409 UNARY_OPERATION(Extension, "__extension__")
410 // [C++ Coroutines] co_await operator
411 UNARY_OPERATION(Coawait, "co_await")
413 #undef CAST_OPERATION
414 #undef BINARY_OPERATION
415 #undef UNARY_OPERATION