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