OperationKinds.h revision 7a7ee3033e44b45630981355460ef89efa0bdcc4
1//===- OperationKinds.h - Operation enums -----------------------*- 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#ifndef LLVM_CLANG_AST_OPERATION_KINDS_H 16#define LLVM_CLANG_AST_OPERATION_KINDS_H 17 18namespace clang { 19 20/// CastKind - The kind of operation required for a conversion. 21enum CastKind { 22 /// CK_Dependent - A conversion which cannot yet be analyzed because 23 /// either the expression or target type is dependent. These are 24 /// created only for explicit casts; dependent ASTs aren't required 25 /// to even approximately type-check. 26 /// (T*) malloc(sizeof(T)) 27 /// reinterpret_cast<intptr_t>(A<T>::alloc()); 28 CK_Dependent, 29 30 /// CK_BitCast - A conversion which causes a bit pattern of one type 31 /// to be reinterpreted as a bit pattern of another type. Generally 32 /// the operands must have equivalent size and unrelated types. 33 /// 34 /// The pointer conversion char* -> int* is a bitcast. A conversion 35 /// from any pointer type to a C pointer type is a bitcast unless 36 /// it's actually BaseToDerived or DerivedToBase. A conversion to a 37 /// block pointer or ObjC pointer type is a bitcast only if the 38 /// operand has the same type kind; otherwise, it's one of the 39 /// specialized casts below. 40 /// 41 /// Vector coercions are bitcasts. 42 CK_BitCast, 43 44 /// CK_LValueBitCast - A conversion which reinterprets the address of 45 /// an l-value as an l-value of a different kind. Used for 46 /// reinterpret_casts of l-value expressions to reference types. 47 /// bool b; reinterpret_cast<char&>(b) = 'a'; 48 CK_LValueBitCast, 49 50 /// CK_LValueToRValue - A conversion which causes the extraction of 51 /// an r-value from the operand gl-value. The result of an r-value 52 /// conversion is always unqualified. 53 CK_LValueToRValue, 54 55 /// CK_NoOp - A conversion which does not affect the type other than 56 /// (possibly) adding qualifiers. 57 /// int -> int 58 /// char** -> const char * const * 59 CK_NoOp, 60 61 /// CK_BaseToDerived - A conversion from a C++ class pointer/reference 62 /// to a derived class pointer/reference. 63 /// B *b = static_cast<B*>(a); 64 CK_BaseToDerived, 65 66 /// CK_DerivedToBase - A conversion from a C++ class pointer 67 /// to a base class pointer. 68 /// A *a = new B(); 69 CK_DerivedToBase, 70 71 /// CK_UncheckedDerivedToBase - A conversion from a C++ class 72 /// pointer/reference to a base class that can assume that the 73 /// derived pointer is not null. 74 /// const A &a = B(); 75 /// b->method_from_a(); 76 CK_UncheckedDerivedToBase, 77 78 /// CK_Dynamic - A C++ dynamic_cast. 79 CK_Dynamic, 80 81 /// CK_ToUnion - The GCC cast-to-union extension. 82 /// int -> union { int x; float y; } 83 /// float -> union { int x; float y; } 84 CK_ToUnion, 85 86 /// CK_ArrayToPointerDecay - Array to pointer decay. 87 /// int[10] -> int* 88 /// char[5][6] -> char(*)[6] 89 CK_ArrayToPointerDecay, 90 91 /// CK_FunctionToPointerDecay - Function to pointer decay. 92 /// void(int) -> void(*)(int) 93 CK_FunctionToPointerDecay, 94 95 /// CK_NullToPointer - Null pointer constant to pointer, ObjC 96 /// pointer, or block pointer. 97 /// (void*) 0 98 /// void (^block)() = 0; 99 CK_NullToPointer, 100 101 /// CK_NullToMemberPointer - Null pointer constant to member pointer. 102 /// int A::*mptr = 0; 103 /// int (A::*fptr)(int) = nullptr; 104 CK_NullToMemberPointer, 105 106 /// CK_BaseToDerivedMemberPointer - Member pointer in base class to 107 /// member pointer in derived class. 108 /// int B::*mptr = &A::member; 109 CK_BaseToDerivedMemberPointer, 110 111 /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to 112 /// member pointer in base class. 113 /// int A::*mptr = static_cast<int A::*>(&B::member); 114 CK_DerivedToBaseMemberPointer, 115 116 /// CK_MemberPointerToBoolean - Member pointer to boolean. A check 117 /// against the null member pointer. 118 CK_MemberPointerToBoolean, 119 120 /// CK_UserDefinedConversion - Conversion using a user defined type 121 /// conversion function. 122 /// struct A { operator int(); }; int i = int(A()); 123 CK_UserDefinedConversion, 124 125 /// CK_ConstructorConversion - Conversion by constructor. 126 /// struct A { A(int); }; A a = A(10); 127 CK_ConstructorConversion, 128 129 /// CK_IntegralToPointer - Integral to pointer. A special kind of 130 /// reinterpreting conversion. Applies to normal, ObjC, and block 131 /// pointers. 132 /// (char*) 0x1001aab0 133 /// reinterpret_cast<int*>(0) 134 CK_IntegralToPointer, 135 136 /// CK_PointerToIntegral - Pointer to integral. A special kind of 137 /// reinterpreting conversion. Applies to normal, ObjC, and block 138 /// pointers. 139 /// (intptr_t) "help!" 140 CK_PointerToIntegral, 141 142 /// CK_PointerToBoolean - Pointer to boolean conversion. A check 143 /// against null. Applies to normal, ObjC, and block pointers. 144 CK_PointerToBoolean, 145 146 /// CK_ToVoid - Cast to void, discarding the computed value. 147 /// (void) malloc(2048) 148 CK_ToVoid, 149 150 /// CK_VectorSplat - A conversion from an arithmetic type to a 151 /// vector of that element type. Fills all elements ("splats") with 152 /// the source value. 153 /// __attribute__((ext_vector_type(4))) int v = 5; 154 CK_VectorSplat, 155 156 /// CK_IntegralCast - A cast between integral types (other than to 157 /// boolean). Variously a bitcast, a truncation, a sign-extension, 158 /// or a zero-extension. 159 /// long l = 5; 160 /// (unsigned) i 161 CK_IntegralCast, 162 163 /// CK_IntegralToBoolean - Integral to boolean. A check against zero. 164 /// (bool) i 165 CK_IntegralToBoolean, 166 167 /// CK_IntegralToFloating - Integral to floating point. 168 /// float f = i; 169 CK_IntegralToFloating, 170 171 /// CK_FloatingToIntegral - Floating point to integral. Rounds 172 /// towards zero, discarding any fractional component. 173 /// (int) f 174 CK_FloatingToIntegral, 175 176 /// CK_FloatingToBoolean - Floating point to boolean. 177 /// (bool) f 178 CK_FloatingToBoolean, 179 180 /// CK_FloatingCast - Casting between floating types of different size. 181 /// (double) f 182 /// (float) ld 183 CK_FloatingCast, 184 185 /// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an 186 /// Objective-C pointer. 187 CK_CPointerToObjCPointerCast, 188 189 /// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an 190 /// ObjC pointer. 191 CK_BlockPointerToObjCPointerCast, 192 193 /// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer 194 /// to a block pointer. Block-to-block casts are bitcasts. 195 CK_AnyPointerToBlockPointerCast, 196 197 /// \brief Converting between two Objective-C object types, which 198 /// can occur when performing reference binding to an Objective-C 199 /// object. 200 CK_ObjCObjectLValueCast, 201 202 /// \brief A conversion of a floating point real to a floating point 203 /// complex of the original type. Injects the value as the real 204 /// component with a zero imaginary component. 205 /// float -> _Complex float 206 CK_FloatingRealToComplex, 207 208 /// \brief Converts a floating point complex to floating point real 209 /// of the source's element type. Just discards the imaginary 210 /// component. 211 /// _Complex long double -> long double 212 CK_FloatingComplexToReal, 213 214 /// \brief Converts a floating point complex to bool by comparing 215 /// against 0+0i. 216 CK_FloatingComplexToBoolean, 217 218 /// \brief Converts between different floating point complex types. 219 /// _Complex float -> _Complex double 220 CK_FloatingComplexCast, 221 222 /// \brief Converts from a floating complex to an integral complex. 223 /// _Complex float -> _Complex int 224 CK_FloatingComplexToIntegralComplex, 225 226 /// \brief Converts from an integral real to an integral complex 227 /// whose element type matches the source. Injects the value as 228 /// the real component with a zero imaginary component. 229 /// long -> _Complex long 230 CK_IntegralRealToComplex, 231 232 /// \brief Converts an integral complex to an integral real of the 233 /// source's element type by discarding the imaginary component. 234 /// _Complex short -> short 235 CK_IntegralComplexToReal, 236 237 /// \brief Converts an integral complex to bool by comparing against 238 /// 0+0i. 239 CK_IntegralComplexToBoolean, 240 241 /// \brief Converts between different integral complex types. 242 /// _Complex char -> _Complex long long 243 /// _Complex unsigned int -> _Complex signed int 244 CK_IntegralComplexCast, 245 246 /// \brief Converts from an integral complex to a floating complex. 247 /// _Complex unsigned -> _Complex float 248 CK_IntegralComplexToFloatingComplex, 249 250 /// \brief [ARC] Produces a retainable object pointer so that it may 251 /// be consumed, e.g. by being passed to a consuming parameter. 252 /// Calls objc_retain. 253 CK_ARCProduceObject, 254 255 /// \brief [ARC] Consumes a retainable object pointer that has just 256 /// been produced, e.g. as the return value of a retaining call. 257 /// Enters a cleanup to call objc_release at some indefinite time. 258 CK_ARCConsumeObject, 259 260 /// \brief [ARC] Reclaim a retainable object pointer object that may 261 /// have been produced and autoreleased as part of a function return 262 /// sequence. 263 CK_ARCReclaimReturnedObject, 264 265 /// \brief [ARC] Causes a value of block type to be copied to the 266 /// heap, if it is not already there. A number of other operations 267 /// in ARC cause blocks to be copied; this is for cases where that 268 /// would not otherwise be guaranteed, such as when casting to a 269 /// non-block pointer type. 270 CK_ARCExtendBlockObject, 271 272 /// \brief Converts from _Atomic(T) to T. 273 CK_AtomicToNonAtomic, 274 /// \brief Converts from T to _Atomic(T). 275 CK_NonAtomicToAtomic 276}; 277 278#define CK_Invalid ((CastKind) -1) 279 280enum BinaryOperatorKind { 281 // Operators listed in order of precedence. 282 // Note that additions to this should also update the StmtVisitor class. 283 BO_PtrMemD, BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators. 284 BO_Mul, BO_Div, BO_Rem, // [C99 6.5.5] Multiplicative operators. 285 BO_Add, BO_Sub, // [C99 6.5.6] Additive operators. 286 BO_Shl, BO_Shr, // [C99 6.5.7] Bitwise shift operators. 287 BO_LT, BO_GT, BO_LE, BO_GE, // [C99 6.5.8] Relational operators. 288 BO_EQ, BO_NE, // [C99 6.5.9] Equality operators. 289 BO_And, // [C99 6.5.10] Bitwise AND operator. 290 BO_Xor, // [C99 6.5.11] Bitwise XOR operator. 291 BO_Or, // [C99 6.5.12] Bitwise OR operator. 292 BO_LAnd, // [C99 6.5.13] Logical AND operator. 293 BO_LOr, // [C99 6.5.14] Logical OR operator. 294 BO_Assign, BO_MulAssign, // [C99 6.5.16] Assignment operators. 295 BO_DivAssign, BO_RemAssign, 296 BO_AddAssign, BO_SubAssign, 297 BO_ShlAssign, BO_ShrAssign, 298 BO_AndAssign, BO_XorAssign, 299 BO_OrAssign, 300 BO_Comma // [C99 6.5.17] Comma operator. 301}; 302 303enum UnaryOperatorKind { 304 // Note that additions to this should also update the StmtVisitor class. 305 UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement 306 UO_PreInc, UO_PreDec, // [C99 6.5.3.1] Prefix increment and decrement 307 UO_AddrOf, UO_Deref, // [C99 6.5.3.2] Address and indirection 308 UO_Plus, UO_Minus, // [C99 6.5.3.3] Unary arithmetic 309 UO_Not, UO_LNot, // [C99 6.5.3.3] Unary arithmetic 310 UO_Real, UO_Imag, // "__real expr"/"__imag expr" Extension. 311 UO_Extension // __extension__ marker. 312}; 313 314/// \brief The kind of bridging performed by the Objective-C bridge cast. 315enum ObjCBridgeCastKind { 316 /// \brief Bridging via __bridge, which does nothing but reinterpret 317 /// the bits. 318 OBC_Bridge, 319 /// \brief Bridging via __bridge_transfer, which transfers ownership of an 320 /// Objective-C pointer into ARC. 321 OBC_BridgeTransfer, 322 /// \brief Bridging via __bridge_retain, which makes an ARC object available 323 /// as a +1 C pointer. 324 OBC_BridgeRetained 325}; 326 327} 328 329#endif 330