1 //===- OperationKinds.h - Operation enums -----------------------*- 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 #ifndef LLVM_CLANG_AST_OPERATION_KINDS_H
16 #define LLVM_CLANG_AST_OPERATION_KINDS_H
20 /// CastKind - The kind of operation required for a conversion.
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());
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.
34 /// The pointer conversion char* -> int* is a bitcast. Many other
35 /// pointer conversions which are "physically" bitcasts are given
36 /// special cast kinds.
38 /// Vector coercions are bitcasts.
41 /// CK_LValueBitCast - A conversion which reinterprets the address of
42 /// an l-value as an l-value of a different kind. Used for
43 /// reinterpret_casts of l-value expressions to reference types.
44 /// bool b; reinterpret_cast<char&>(b) = 'a';
47 /// CK_LValueToRValue - A conversion which causes the extraction of
48 /// an r-value from the operand gl-value. The result of an r-value
49 /// conversion is always unqualified.
52 /// CK_GetObjCProperty - A conversion which calls an Objective-C
53 /// property getter. The operand is an OK_ObjCProperty l-value; the
54 /// result will generally be an r-value, but could be an ordinary
55 /// gl-value if the property reference is to an implicit property
56 /// for a method that returns a reference type.
59 /// CK_NoOp - A conversion which does not affect the type other than
60 /// (possibly) adding qualifiers.
62 /// char** -> const char * const *
65 /// CK_BaseToDerived - A conversion from a C++ class pointer/reference
66 /// to a derived class pointer/reference.
67 /// B *b = static_cast<B*>(a);
70 /// CK_DerivedToBase - A conversion from a C++ class pointer
71 /// to a base class pointer.
75 /// CK_UncheckedDerivedToBase - A conversion from a C++ class
76 /// pointer/reference to a base class that can assume that the
77 /// derived pointer is not null.
79 /// b->method_from_a();
80 CK_UncheckedDerivedToBase,
82 /// CK_Dynamic - A C++ dynamic_cast.
85 /// CK_DynamicToNull - A C++ dynamic_cast that can be proven to
86 /// always yield a null result.
89 /// CK_ToUnion - The GCC cast-to-union extension.
90 /// int -> union { int x; float y; }
91 /// float -> union { int x; float y; }
94 /// CK_ArrayToPointerDecay - Array to pointer decay.
96 /// char[5][6] -> char(*)[6]
97 CK_ArrayToPointerDecay,
99 /// CK_FunctionToPointerDecay - Function to pointer decay.
100 /// void(int) -> void(*)(int)
101 CK_FunctionToPointerDecay,
103 /// CK_NullToPointer - Null pointer constant to pointer, ObjC
104 /// pointer, or block pointer.
106 /// void (^block)() = 0;
109 /// CK_NullToMemberPointer - Null pointer constant to member pointer.
110 /// int A::*mptr = 0;
111 /// int (A::*fptr)(int) = nullptr;
112 CK_NullToMemberPointer,
114 /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
115 /// member pointer in derived class.
116 /// int B::*mptr = &A::member;
117 CK_BaseToDerivedMemberPointer,
119 /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
120 /// member pointer in base class.
121 /// int A::*mptr = static_cast<int A::*>(&B::member);
122 CK_DerivedToBaseMemberPointer,
124 /// CK_MemberPointerToBoolean - Member pointer to boolean. A check
125 /// against the null member pointer.
126 CK_MemberPointerToBoolean,
128 /// CK_UserDefinedConversion - Conversion using a user defined type
129 /// conversion function.
130 /// struct A { operator int(); }; int i = int(A());
131 CK_UserDefinedConversion,
133 /// CK_ConstructorConversion - Conversion by constructor.
134 /// struct A { A(int); }; A a = A(10);
135 CK_ConstructorConversion,
137 /// CK_IntegralToPointer - Integral to pointer. A special kind of
138 /// reinterpreting conversion. Applies to normal, ObjC, and block
140 /// (char*) 0x1001aab0
141 /// reinterpret_cast<int*>(0)
142 CK_IntegralToPointer,
144 /// CK_PointerToIntegral - Pointer to integral. A special kind of
145 /// reinterpreting conversion. Applies to normal, ObjC, and block
147 /// (intptr_t) "help!"
148 CK_PointerToIntegral,
150 /// CK_PointerToBoolean - Pointer to boolean conversion. A check
151 /// against null. Applies to normal, ObjC, and block pointers.
154 /// CK_ToVoid - Cast to void, discarding the computed value.
155 /// (void) malloc(2048)
158 /// CK_VectorSplat - A conversion from an arithmetic type to a
159 /// vector of that element type. Fills all elements ("splats") with
160 /// the source value.
161 /// __attribute__((ext_vector_type(4))) int v = 5;
164 /// CK_IntegralCast - A cast between integral types (other than to
165 /// boolean). Variously a bitcast, a truncation, a sign-extension,
166 /// or a zero-extension.
171 /// CK_IntegralToBoolean - Integral to boolean. A check against zero.
173 CK_IntegralToBoolean,
175 /// CK_IntegralToFloating - Integral to floating point.
177 CK_IntegralToFloating,
179 /// CK_FloatingToIntegral - Floating point to integral. Rounds
180 /// towards zero, discarding any fractional component.
182 CK_FloatingToIntegral,
184 /// CK_FloatingToBoolean - Floating point to boolean.
186 CK_FloatingToBoolean,
188 /// CK_FloatingCast - Casting between floating types of different size.
193 /// CK_AnyPointerToObjCPointerCast - Casting any other pointer kind
194 /// to an Objective-C pointer.
195 CK_AnyPointerToObjCPointerCast,
197 /// CK_AnyPointerToBlockPointerCast - Casting any other pointer kind
198 /// to a block pointer.
199 CK_AnyPointerToBlockPointerCast,
201 /// \brief Converting between two Objective-C object types, which
202 /// can occur when performing reference binding to an Objective-C
204 CK_ObjCObjectLValueCast,
206 /// \brief A conversion of a floating point real to a floating point
207 /// complex of the original type. Injects the value as the real
208 /// component with a zero imaginary component.
209 /// float -> _Complex float
210 CK_FloatingRealToComplex,
212 /// \brief Converts a floating point complex to floating point real
213 /// of the source's element type. Just discards the imaginary
215 /// _Complex long double -> long double
216 CK_FloatingComplexToReal,
218 /// \brief Converts a floating point complex to bool by comparing
220 CK_FloatingComplexToBoolean,
222 /// \brief Converts between different floating point complex types.
223 /// _Complex float -> _Complex double
224 CK_FloatingComplexCast,
226 /// \brief Converts from a floating complex to an integral complex.
227 /// _Complex float -> _Complex int
228 CK_FloatingComplexToIntegralComplex,
230 /// \brief Converts from an integral real to an integral complex
231 /// whose element type matches the source. Injects the value as
232 /// the real component with a zero imaginary component.
233 /// long -> _Complex long
234 CK_IntegralRealToComplex,
236 /// \brief Converts an integral complex to an integral real of the
237 /// source's element type by discarding the imaginary component.
238 /// _Complex short -> short
239 CK_IntegralComplexToReal,
241 /// \brief Converts an integral complex to bool by comparing against
243 CK_IntegralComplexToBoolean,
245 /// \brief Converts between different integral complex types.
246 /// _Complex char -> _Complex long long
247 /// _Complex unsigned int -> _Complex signed int
248 CK_IntegralComplexCast,
250 /// \brief Converts from an integral complex to a floating complex.
251 /// _Complex unsigned -> _Complex float
252 CK_IntegralComplexToFloatingComplex,
254 /// \brief Assign an unknown-any declaration a type.
255 CK_ResolveUnknownAnyType
258 #define CK_Invalid ((CastKind) -1)
260 enum BinaryOperatorKind {
261 // Operators listed in order of precedence.
262 // Note that additions to this should also update the StmtVisitor class.
263 BO_PtrMemD, BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators.
264 BO_Mul, BO_Div, BO_Rem, // [C99 6.5.5] Multiplicative operators.
265 BO_Add, BO_Sub, // [C99 6.5.6] Additive operators.
266 BO_Shl, BO_Shr, // [C99 6.5.7] Bitwise shift operators.
267 BO_LT, BO_GT, BO_LE, BO_GE, // [C99 6.5.8] Relational operators.
268 BO_EQ, BO_NE, // [C99 6.5.9] Equality operators.
269 BO_And, // [C99 6.5.10] Bitwise AND operator.
270 BO_Xor, // [C99 6.5.11] Bitwise XOR operator.
271 BO_Or, // [C99 6.5.12] Bitwise OR operator.
272 BO_LAnd, // [C99 6.5.13] Logical AND operator.
273 BO_LOr, // [C99 6.5.14] Logical OR operator.
274 BO_Assign, BO_MulAssign, // [C99 6.5.16] Assignment operators.
275 BO_DivAssign, BO_RemAssign,
276 BO_AddAssign, BO_SubAssign,
277 BO_ShlAssign, BO_ShrAssign,
278 BO_AndAssign, BO_XorAssign,
280 BO_Comma // [C99 6.5.17] Comma operator.
283 enum UnaryOperatorKind {
284 // Note that additions to this should also update the StmtVisitor class.
285 UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
286 UO_PreInc, UO_PreDec, // [C99 6.5.3.1] Prefix increment and decrement
287 UO_AddrOf, UO_Deref, // [C99 6.5.3.2] Address and indirection
288 UO_Plus, UO_Minus, // [C99 6.5.3.3] Unary arithmetic
289 UO_Not, UO_LNot, // [C99 6.5.3.3] Unary arithmetic
290 UO_Real, UO_Imag, // "__real expr"/"__imag expr" Extension.
291 UO_Extension // __extension__ marker.