OperationKinds.def 15 KB

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