Clang Project

clang_source_code/include/clang/AST/OperationKinds.def
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_FixedPointToIntegral - Fixed point to integral.
204///    (int) 2.0k
205CAST_OPERATION(FixedPointToIntegral)
206
207/// CK_IntegralToFixedPoint - Integral to a fixed point.
208///    (_Accum) 2
209CAST_OPERATION(IntegralToFixedPoint)
210
211/// CK_FixedPointToBoolean - Fixed point to boolean.
212///    (bool) 0.5r
213CAST_OPERATION(FixedPointToBoolean)
214
215/// CK_FloatingToIntegral - Floating point to integral.  Rounds
216/// towards zero, discarding any fractional component.
217///    (int) f
218CAST_OPERATION(FloatingToIntegral)
219
220/// CK_FloatingToBoolean - Floating point to boolean.
221///    (bool) f
222CAST_OPERATION(FloatingToBoolean)
223
224// CK_BooleanToSignedIntegral - Convert a boolean to -1 or 0 for true and
225// false, respectively.
226CAST_OPERATION(BooleanToSignedIntegral)
227
228/// CK_FloatingCast - Casting between floating types of different size.
229///    (double) f
230///    (float) ld
231CAST_OPERATION(FloatingCast)
232
233/// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an
234/// Objective-C pointer.
235CAST_OPERATION(CPointerToObjCPointerCast)
236
237/// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an
238/// ObjC pointer.
239CAST_OPERATION(BlockPointerToObjCPointerCast)
240
241/// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer
242/// to a block pointer.  Block-to-block casts are bitcasts.
243CAST_OPERATION(AnyPointerToBlockPointerCast)
244
245/// Converting between two Objective-C object types, which
246/// can occur when performing reference binding to an Objective-C
247/// object.
248CAST_OPERATION(ObjCObjectLValueCast)
249
250/// A conversion of a floating point real to a floating point
251/// complex of the original type.  Injects the value as the real
252/// component with a zero imaginary component.
253///   float -> _Complex float
254CAST_OPERATION(FloatingRealToComplex)
255
256/// Converts a floating point complex to floating point real
257/// of the source's element type.  Just discards the imaginary
258/// component.
259///   _Complex long double -> long double
260CAST_OPERATION(FloatingComplexToReal)
261
262/// Converts a floating point complex to bool by comparing
263/// against 0+0i.
264CAST_OPERATION(FloatingComplexToBoolean)
265
266/// Converts between different floating point complex types.
267///   _Complex float -> _Complex double
268CAST_OPERATION(FloatingComplexCast)
269
270/// Converts from a floating complex to an integral complex.
271///   _Complex float -> _Complex int
272CAST_OPERATION(FloatingComplexToIntegralComplex)
273
274/// Converts from an integral real to an integral complex
275/// whose element type matches the source.  Injects the value as
276/// the real component with a zero imaginary component.
277///   long -> _Complex long
278CAST_OPERATION(IntegralRealToComplex)
279
280/// Converts an integral complex to an integral real of the
281/// source's element type by discarding the imaginary component.
282///   _Complex short -> short
283CAST_OPERATION(IntegralComplexToReal)
284
285/// Converts an integral complex to bool by comparing against
286/// 0+0i.
287CAST_OPERATION(IntegralComplexToBoolean)
288
289/// Converts between different integral complex types.
290///   _Complex char -> _Complex long long
291///   _Complex unsigned int -> _Complex signed int
292CAST_OPERATION(IntegralComplexCast)
293
294/// Converts from an integral complex to a floating complex.
295///   _Complex unsigned -> _Complex float
296CAST_OPERATION(IntegralComplexToFloatingComplex)
297
298/// [ARC] Produces a retainable object pointer so that it may
299/// be consumed, e.g. by being passed to a consuming parameter.
300/// Calls objc_retain.
301CAST_OPERATION(ARCProduceObject)
302
303/// [ARC] Consumes a retainable object pointer that has just
304/// been produced, e.g. as the return value of a retaining call.
305/// Enters a cleanup to call objc_release at some indefinite time.
306CAST_OPERATION(ARCConsumeObject)
307
308/// [ARC] Reclaim a retainable object pointer object that may
309/// have been produced and autoreleased as part of a function return
310/// sequence.
311CAST_OPERATION(ARCReclaimReturnedObject)
312
313/// [ARC] Causes a value of block type to be copied to the
314/// heap, if it is not already there.  A number of other operations
315/// in ARC cause blocks to be copied; this is for cases where that
316/// would not otherwise be guaranteed, such as when casting to a
317/// non-block pointer type.
318CAST_OPERATION(ARCExtendBlockObject)
319
320/// Converts from _Atomic(T) to T.
321CAST_OPERATION(AtomicToNonAtomic)
322/// Converts from T to _Atomic(T).
323CAST_OPERATION(NonAtomicToAtomic)
324
325/// Causes a block literal to by copied to the heap and then
326/// autoreleased.
327///
328/// This particular cast kind is used for the conversion from a C++11
329/// lambda expression to a block pointer.
330CAST_OPERATION(CopyAndAutoreleaseBlockObject)
331
332// Convert a builtin function to a function pointer; only allowed in the
333// callee of a call expression.
334CAST_OPERATION(BuiltinFnToFnPtr)
335
336// Convert a zero value for OpenCL opaque types initialization (event_t,
337// queue_t, etc.)
338CAST_OPERATION(ZeroToOCLOpaqueType)
339
340// Convert a pointer to a different address space.
341CAST_OPERATION(AddressSpaceConversion)
342
343// Convert an integer initializer to an OpenCL sampler.
344CAST_OPERATION(IntToOCLSampler)
345
346//===- Binary Operations  -------------------------------------------------===//
347// Operators listed in order of precedence.
348// Note that additions to this should also update the StmtVisitor class and
349// BinaryOperator::getOverloadedOperator.
350
351// [C++ 5.5] Pointer-to-member operators.
352BINARY_OPERATION(PtrMemD, ".*")
353BINARY_OPERATION(PtrMemI, "->*")
354// [C99 6.5.5] Multiplicative operators.
355BINARY_OPERATION(Mul, "*")
356BINARY_OPERATION(Div, "/")
357BINARY_OPERATION(Rem, "%")
358// [C99 6.5.6] Additive operators.
359BINARY_OPERATION(Add, "+")
360BINARY_OPERATION(Sub, "-")
361// [C99 6.5.7] Bitwise shift operators.
362BINARY_OPERATION(Shl, "<<")
363BINARY_OPERATION(Shr, ">>")
364// C++20 [expr.spaceship] Three-way comparison operator.
365BINARY_OPERATION(Cmp, "<=>")
366// [C99 6.5.8] Relational operators.
367BINARY_OPERATION(LT, "<")
368BINARY_OPERATION(GT, ">")
369BINARY_OPERATION(LE, "<=")
370BINARY_OPERATION(GE, ">=")
371// [C99 6.5.9] Equality operators.
372BINARY_OPERATION(EQ, "==")
373BINARY_OPERATION(NE, "!=")
374// [C99 6.5.10] Bitwise AND operator.
375BINARY_OPERATION(And, "&")
376// [C99 6.5.11] Bitwise XOR operator.
377BINARY_OPERATION(Xor, "^")
378// [C99 6.5.12] Bitwise OR operator.
379BINARY_OPERATION(Or, "|")
380// [C99 6.5.13] Logical AND operator.
381BINARY_OPERATION(LAnd, "&&")
382// [C99 6.5.14] Logical OR operator.
383BINARY_OPERATION(LOr, "||")
384// [C99 6.5.16] Assignment operators.
385BINARY_OPERATION(Assign, "=")
386BINARY_OPERATION(MulAssign, "*=")
387BINARY_OPERATION(DivAssign, "/=")
388BINARY_OPERATION(RemAssign, "%=")
389BINARY_OPERATION(AddAssign, "+=")
390BINARY_OPERATION(SubAssign, "-=")
391BINARY_OPERATION(ShlAssign, "<<=")
392BINARY_OPERATION(ShrAssign, ">>=")
393BINARY_OPERATION(AndAssign, "&=")
394BINARY_OPERATION(XorAssign, "^=")
395BINARY_OPERATION(OrAssign, "|=")
396// [C99 6.5.17] Comma operator.
397BINARY_OPERATION(Comma, ",")
398
399
400//===- Unary Operations ---------------------------------------------------===//
401// Note that additions to this should also update the StmtVisitor class and
402// UnaryOperator::getOverloadedOperator.
403
404// [C99 6.5.2.4] Postfix increment and decrement
405UNARY_OPERATION(PostInc, "++")
406UNARY_OPERATION(PostDec, "--")
407// [C99 6.5.3.1] Prefix increment and decrement
408UNARY_OPERATION(PreInc, "++")
409UNARY_OPERATION(PreDec, "--")
410// [C99 6.5.3.2] Address and indirection
411UNARY_OPERATION(AddrOf, "&")
412UNARY_OPERATION(Deref, "*")
413// [C99 6.5.3.3] Unary arithmetic
414UNARY_OPERATION(Plus, "+")
415UNARY_OPERATION(Minus, "-")
416UNARY_OPERATION(Not, "~")
417UNARY_OPERATION(LNot, "!")
418// "__real expr"/"__imag expr" Extension.
419UNARY_OPERATION(Real, "__real")
420UNARY_OPERATION(Imag, "__imag")
421// __extension__ marker.
422UNARY_OPERATION(Extension, "__extension__")
423// [C++ Coroutines] co_await operator
424UNARY_OPERATION(Coawait, "co_await")
425
426#undef CAST_OPERATION
427#undef BINARY_OPERATION
428#undef UNARY_OPERATION
429