1212795Sdim//===- OperationKinds.h - Operation enums -----------------------*- C++ -*-===//
2212795Sdim//
3212795Sdim//                     The LLVM Compiler Infrastructure
4212795Sdim//
5212795Sdim// This file is distributed under the University of Illinois Open Source
6212795Sdim// License. See LICENSE.TXT for details.
7212795Sdim//
8212795Sdim//===----------------------------------------------------------------------===//
9212795Sdim//
10212795Sdim// This file enumerates the different kinds of operations that can be
11212795Sdim// performed by various expressions.
12212795Sdim//
13212795Sdim//===----------------------------------------------------------------------===//
14212795Sdim
15212795Sdim#ifndef LLVM_CLANG_AST_OPERATION_KINDS_H
16212795Sdim#define LLVM_CLANG_AST_OPERATION_KINDS_H
17212795Sdim
18212795Sdimnamespace clang {
19212795Sdim
20218893Sdim/// CastKind - The kind of operation required for a conversion.
21212795Sdimenum CastKind {
22218893Sdim  /// CK_Dependent - A conversion which cannot yet be analyzed because
23218893Sdim  /// either the expression or target type is dependent.  These are
24218893Sdim  /// created only for explicit casts; dependent ASTs aren't required
25218893Sdim  /// to even approximately type-check.
26218893Sdim  ///   (T*) malloc(sizeof(T))
27218893Sdim  ///   reinterpret_cast<intptr_t>(A<T>::alloc());
28218893Sdim  CK_Dependent,
29212795Sdim
30218893Sdim  /// CK_BitCast - A conversion which causes a bit pattern of one type
31218893Sdim  /// to be reinterpreted as a bit pattern of another type.  Generally
32218893Sdim  /// the operands must have equivalent size and unrelated types.
33218893Sdim  ///
34226633Sdim  /// The pointer conversion char* -> int* is a bitcast.  A conversion
35226633Sdim  /// from any pointer type to a C pointer type is a bitcast unless
36226633Sdim  /// it's actually BaseToDerived or DerivedToBase.  A conversion to a
37226633Sdim  /// block pointer or ObjC pointer type is a bitcast only if the
38226633Sdim  /// operand has the same type kind; otherwise, it's one of the
39226633Sdim  /// specialized casts below.
40218893Sdim  ///
41218893Sdim  /// Vector coercions are bitcasts.
42212795Sdim  CK_BitCast,
43212795Sdim
44218893Sdim  /// CK_LValueBitCast - A conversion which reinterprets the address of
45218893Sdim  /// an l-value as an l-value of a different kind.  Used for
46218893Sdim  /// reinterpret_casts of l-value expressions to reference types.
47218893Sdim  ///    bool b; reinterpret_cast<char&>(b) = 'a';
48212795Sdim  CK_LValueBitCast,
49218893Sdim
50218893Sdim  /// CK_LValueToRValue - A conversion which causes the extraction of
51218893Sdim  /// an r-value from the operand gl-value.  The result of an r-value
52218893Sdim  /// conversion is always unqualified.
53218893Sdim  CK_LValueToRValue,
54218893Sdim
55218893Sdim  /// CK_NoOp - A conversion which does not affect the type other than
56218893Sdim  /// (possibly) adding qualifiers.
57218893Sdim  ///   int    -> int
58218893Sdim  ///   char** -> const char * const *
59212795Sdim  CK_NoOp,
60212795Sdim
61218893Sdim  /// CK_BaseToDerived - A conversion from a C++ class pointer/reference
62218893Sdim  /// to a derived class pointer/reference.
63218893Sdim  ///   B *b = static_cast<B*>(a);
64212795Sdim  CK_BaseToDerived,
65212795Sdim
66218893Sdim  /// CK_DerivedToBase - A conversion from a C++ class pointer
67218893Sdim  /// to a base class pointer.
68218893Sdim  ///   A *a = new B();
69212795Sdim  CK_DerivedToBase,
70212795Sdim
71218893Sdim  /// CK_UncheckedDerivedToBase - A conversion from a C++ class
72218893Sdim  /// pointer/reference to a base class that can assume that the
73218893Sdim  /// derived pointer is not null.
74218893Sdim  ///   const A &a = B();
75218893Sdim  ///   b->method_from_a();
76212795Sdim  CK_UncheckedDerivedToBase,
77212795Sdim
78218893Sdim  /// CK_Dynamic - A C++ dynamic_cast.
79212795Sdim  CK_Dynamic,
80212795Sdim
81218893Sdim  /// CK_ToUnion - The GCC cast-to-union extension.
82218893Sdim  ///   int   -> union { int x; float y; }
83218893Sdim  ///   float -> union { int x; float y; }
84212795Sdim  CK_ToUnion,
85212795Sdim
86212795Sdim  /// CK_ArrayToPointerDecay - Array to pointer decay.
87218893Sdim  ///   int[10] -> int*
88218893Sdim  ///   char[5][6] -> char(*)[6]
89212795Sdim  CK_ArrayToPointerDecay,
90212795Sdim
91218893Sdim  /// CK_FunctionToPointerDecay - Function to pointer decay.
92218893Sdim  ///   void(int) -> void(*)(int)
93212795Sdim  CK_FunctionToPointerDecay,
94212795Sdim
95218893Sdim  /// CK_NullToPointer - Null pointer constant to pointer, ObjC
96218893Sdim  /// pointer, or block pointer.
97218893Sdim  ///   (void*) 0
98218893Sdim  ///   void (^block)() = 0;
99218893Sdim  CK_NullToPointer,
100218893Sdim
101218893Sdim  /// CK_NullToMemberPointer - Null pointer constant to member pointer.
102218893Sdim  ///   int A::*mptr = 0;
103218893Sdim  ///   int (A::*fptr)(int) = nullptr;
104212795Sdim  CK_NullToMemberPointer,
105212795Sdim
106212795Sdim  /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
107212795Sdim  /// member pointer in derived class.
108218893Sdim  ///   int B::*mptr = &A::member;
109212795Sdim  CK_BaseToDerivedMemberPointer,
110212795Sdim
111212795Sdim  /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
112212795Sdim  /// member pointer in base class.
113218893Sdim  ///   int A::*mptr = static_cast<int A::*>(&B::member);
114212795Sdim  CK_DerivedToBaseMemberPointer,
115212795Sdim
116218893Sdim  /// CK_MemberPointerToBoolean - Member pointer to boolean.  A check
117218893Sdim  /// against the null member pointer.
118218893Sdim  CK_MemberPointerToBoolean,
119218893Sdim
120234353Sdim  /// CK_ReinterpretMemberPointer - Reinterpret a member pointer as a
121234353Sdim  /// different kind of member pointer.  C++ forbids this from
122234353Sdim  /// crossing between function and object types, but otherwise does
123234353Sdim  /// not restrict it.  However, the only operation that is permitted
124234353Sdim  /// on a "punned" member pointer is casting it back to the original
125234353Sdim  /// type, which is required to be a lossless operation (although
126234353Sdim  /// many ABIs do not guarantee this on all possible intermediate types).
127234353Sdim  CK_ReinterpretMemberPointer,
128234353Sdim
129212795Sdim  /// CK_UserDefinedConversion - Conversion using a user defined type
130212795Sdim  /// conversion function.
131218893Sdim  ///    struct A { operator int(); }; int i = int(A());
132212795Sdim  CK_UserDefinedConversion,
133212795Sdim
134218893Sdim  /// CK_ConstructorConversion - Conversion by constructor.
135218893Sdim  ///    struct A { A(int); }; A a = A(10);
136212795Sdim  CK_ConstructorConversion,
137212795Sdim
138218893Sdim  /// CK_IntegralToPointer - Integral to pointer.  A special kind of
139218893Sdim  /// reinterpreting conversion.  Applies to normal, ObjC, and block
140218893Sdim  /// pointers.
141218893Sdim  ///    (char*) 0x1001aab0
142218893Sdim  ///    reinterpret_cast<int*>(0)
143212795Sdim  CK_IntegralToPointer,
144212795Sdim
145218893Sdim  /// CK_PointerToIntegral - Pointer to integral.  A special kind of
146218893Sdim  /// reinterpreting conversion.  Applies to normal, ObjC, and block
147218893Sdim  /// pointers.
148218893Sdim  ///    (intptr_t) "help!"
149212795Sdim  CK_PointerToIntegral,
150218893Sdim
151218893Sdim  /// CK_PointerToBoolean - Pointer to boolean conversion.  A check
152218893Sdim  /// against null.  Applies to normal, ObjC, and block pointers.
153218893Sdim  CK_PointerToBoolean,
154212795Sdim
155218893Sdim  /// CK_ToVoid - Cast to void, discarding the computed value.
156218893Sdim  ///    (void) malloc(2048)
157212795Sdim  CK_ToVoid,
158212795Sdim
159218893Sdim  /// CK_VectorSplat - A conversion from an arithmetic type to a
160218893Sdim  /// vector of that element type.  Fills all elements ("splats") with
161218893Sdim  /// the source value.
162218893Sdim  ///    __attribute__((ext_vector_type(4))) int v = 5;
163212795Sdim  CK_VectorSplat,
164212795Sdim
165218893Sdim  /// CK_IntegralCast - A cast between integral types (other than to
166218893Sdim  /// boolean).  Variously a bitcast, a truncation, a sign-extension,
167218893Sdim  /// or a zero-extension.
168218893Sdim  ///    long l = 5;
169218893Sdim  ///    (unsigned) i
170212795Sdim  CK_IntegralCast,
171212795Sdim
172218893Sdim  /// CK_IntegralToBoolean - Integral to boolean.  A check against zero.
173218893Sdim  ///    (bool) i
174218893Sdim  CK_IntegralToBoolean,
175218893Sdim
176212795Sdim  /// CK_IntegralToFloating - Integral to floating point.
177218893Sdim  ///    float f = i;
178212795Sdim  CK_IntegralToFloating,
179212795Sdim
180218893Sdim  /// CK_FloatingToIntegral - Floating point to integral.  Rounds
181218893Sdim  /// towards zero, discarding any fractional component.
182218893Sdim  ///    (int) f
183212795Sdim  CK_FloatingToIntegral,
184218893Sdim
185218893Sdim  /// CK_FloatingToBoolean - Floating point to boolean.
186218893Sdim  ///    (bool) f
187218893Sdim  CK_FloatingToBoolean,
188212795Sdim
189212795Sdim  /// CK_FloatingCast - Casting between floating types of different size.
190218893Sdim  ///    (double) f
191218893Sdim  ///    (float) ld
192212795Sdim  CK_FloatingCast,
193212795Sdim
194226633Sdim  /// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an
195226633Sdim  /// Objective-C pointer.
196226633Sdim  CK_CPointerToObjCPointerCast,
197212795Sdim
198226633Sdim  /// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an
199226633Sdim  /// ObjC pointer.
200226633Sdim  CK_BlockPointerToObjCPointerCast,
201226633Sdim
202226633Sdim  /// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer
203226633Sdim  /// to a block pointer.  Block-to-block casts are bitcasts.
204212795Sdim  CK_AnyPointerToBlockPointerCast,
205212795Sdim
206212795Sdim  /// \brief Converting between two Objective-C object types, which
207212795Sdim  /// can occur when performing reference binding to an Objective-C
208212795Sdim  /// object.
209218893Sdim  CK_ObjCObjectLValueCast,
210218893Sdim
211218893Sdim  /// \brief A conversion of a floating point real to a floating point
212218893Sdim  /// complex of the original type.  Injects the value as the real
213218893Sdim  /// component with a zero imaginary component.
214218893Sdim  ///   float -> _Complex float
215218893Sdim  CK_FloatingRealToComplex,
216218893Sdim
217218893Sdim  /// \brief Converts a floating point complex to floating point real
218218893Sdim  /// of the source's element type.  Just discards the imaginary
219218893Sdim  /// component.
220218893Sdim  ///   _Complex long double -> long double
221218893Sdim  CK_FloatingComplexToReal,
222218893Sdim
223218893Sdim  /// \brief Converts a floating point complex to bool by comparing
224218893Sdim  /// against 0+0i.
225218893Sdim  CK_FloatingComplexToBoolean,
226218893Sdim
227218893Sdim  /// \brief Converts between different floating point complex types.
228218893Sdim  ///   _Complex float -> _Complex double
229218893Sdim  CK_FloatingComplexCast,
230218893Sdim
231218893Sdim  /// \brief Converts from a floating complex to an integral complex.
232218893Sdim  ///   _Complex float -> _Complex int
233218893Sdim  CK_FloatingComplexToIntegralComplex,
234218893Sdim
235218893Sdim  /// \brief Converts from an integral real to an integral complex
236218893Sdim  /// whose element type matches the source.  Injects the value as
237218893Sdim  /// the real component with a zero imaginary component.
238218893Sdim  ///   long -> _Complex long
239218893Sdim  CK_IntegralRealToComplex,
240218893Sdim
241218893Sdim  /// \brief Converts an integral complex to an integral real of the
242218893Sdim  /// source's element type by discarding the imaginary component.
243218893Sdim  ///   _Complex short -> short
244218893Sdim  CK_IntegralComplexToReal,
245218893Sdim
246218893Sdim  /// \brief Converts an integral complex to bool by comparing against
247218893Sdim  /// 0+0i.
248218893Sdim  CK_IntegralComplexToBoolean,
249218893Sdim
250218893Sdim  /// \brief Converts between different integral complex types.
251218893Sdim  ///   _Complex char -> _Complex long long
252218893Sdim  ///   _Complex unsigned int -> _Complex signed int
253218893Sdim  CK_IntegralComplexCast,
254218893Sdim
255218893Sdim  /// \brief Converts from an integral complex to a floating complex.
256218893Sdim  ///   _Complex unsigned -> _Complex float
257224145Sdim  CK_IntegralComplexToFloatingComplex,
258224145Sdim
259226633Sdim  /// \brief [ARC] Produces a retainable object pointer so that it may
260226633Sdim  /// be consumed, e.g. by being passed to a consuming parameter.
261226633Sdim  /// Calls objc_retain.
262226633Sdim  CK_ARCProduceObject,
263224145Sdim
264226633Sdim  /// \brief [ARC] Consumes a retainable object pointer that has just
265226633Sdim  /// been produced, e.g. as the return value of a retaining call.
266226633Sdim  /// Enters a cleanup to call objc_release at some indefinite time.
267226633Sdim  CK_ARCConsumeObject,
268224145Sdim
269226633Sdim  /// \brief [ARC] Reclaim a retainable object pointer object that may
270226633Sdim  /// have been produced and autoreleased as part of a function return
271224145Sdim  /// sequence.
272226633Sdim  CK_ARCReclaimReturnedObject,
273226633Sdim
274226633Sdim  /// \brief [ARC] Causes a value of block type to be copied to the
275226633Sdim  /// heap, if it is not already there.  A number of other operations
276226633Sdim  /// in ARC cause blocks to be copied; this is for cases where that
277226633Sdim  /// would not otherwise be guaranteed, such as when casting to a
278226633Sdim  /// non-block pointer type.
279234353Sdim  CK_ARCExtendBlockObject,
280234353Sdim
281234353Sdim  /// \brief Converts from _Atomic(T) to T.
282234353Sdim  CK_AtomicToNonAtomic,
283234353Sdim  /// \brief Converts from T to _Atomic(T).
284234353Sdim  CK_NonAtomicToAtomic,
285234353Sdim
286234353Sdim  /// \brief Causes a block literal to by copied to the heap and then
287234353Sdim  /// autoreleased.
288234353Sdim  ///
289234353Sdim  /// This particular cast kind is used for the conversion from a C++11
290234353Sdim  /// lambda expression to a block pointer.
291243830Sdim  CK_CopyAndAutoreleaseBlockObject,
292243830Sdim
293243830Sdim  // Convert a builtin function to a function pointer; only allowed in the
294243830Sdim  // callee of a call expression.
295249423Sdim  CK_BuiltinFnToFnPtr,
296249423Sdim
297249423Sdim  // Convert a zero value for OpenCL event_t initialization.
298249423Sdim  CK_ZeroToOCLEvent
299212795Sdim};
300212795Sdim
301239462Sdimstatic const CastKind CK_Invalid = static_cast<CastKind>(-1);
302212795Sdim
303212795Sdimenum BinaryOperatorKind {
304212795Sdim  // Operators listed in order of precedence.
305212795Sdim  // Note that additions to this should also update the StmtVisitor class.
306212795Sdim  BO_PtrMemD, BO_PtrMemI,       // [C++ 5.5] Pointer-to-member operators.
307212795Sdim  BO_Mul, BO_Div, BO_Rem,       // [C99 6.5.5] Multiplicative operators.
308212795Sdim  BO_Add, BO_Sub,               // [C99 6.5.6] Additive operators.
309212795Sdim  BO_Shl, BO_Shr,               // [C99 6.5.7] Bitwise shift operators.
310212795Sdim  BO_LT, BO_GT, BO_LE, BO_GE,   // [C99 6.5.8] Relational operators.
311212795Sdim  BO_EQ, BO_NE,                 // [C99 6.5.9] Equality operators.
312212795Sdim  BO_And,                       // [C99 6.5.10] Bitwise AND operator.
313212795Sdim  BO_Xor,                       // [C99 6.5.11] Bitwise XOR operator.
314212795Sdim  BO_Or,                        // [C99 6.5.12] Bitwise OR operator.
315212795Sdim  BO_LAnd,                      // [C99 6.5.13] Logical AND operator.
316212795Sdim  BO_LOr,                       // [C99 6.5.14] Logical OR operator.
317212795Sdim  BO_Assign, BO_MulAssign,      // [C99 6.5.16] Assignment operators.
318212795Sdim  BO_DivAssign, BO_RemAssign,
319212795Sdim  BO_AddAssign, BO_SubAssign,
320212795Sdim  BO_ShlAssign, BO_ShrAssign,
321212795Sdim  BO_AndAssign, BO_XorAssign,
322212795Sdim  BO_OrAssign,
323212795Sdim  BO_Comma                      // [C99 6.5.17] Comma operator.
324212795Sdim};
325212795Sdim
326212795Sdimenum UnaryOperatorKind {
327212795Sdim  // Note that additions to this should also update the StmtVisitor class.
328212795Sdim  UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
329212795Sdim  UO_PreInc, UO_PreDec,   // [C99 6.5.3.1] Prefix increment and decrement
330212795Sdim  UO_AddrOf, UO_Deref,    // [C99 6.5.3.2] Address and indirection
331212795Sdim  UO_Plus, UO_Minus,      // [C99 6.5.3.3] Unary arithmetic
332212795Sdim  UO_Not, UO_LNot,        // [C99 6.5.3.3] Unary arithmetic
333212795Sdim  UO_Real, UO_Imag,       // "__real expr"/"__imag expr" Extension.
334212795Sdim  UO_Extension            // __extension__ marker.
335212795Sdim};
336212795Sdim
337224145Sdim/// \brief The kind of bridging performed by the Objective-C bridge cast.
338224145Sdimenum ObjCBridgeCastKind {
339224145Sdim  /// \brief Bridging via __bridge, which does nothing but reinterpret
340224145Sdim  /// the bits.
341224145Sdim  OBC_Bridge,
342224145Sdim  /// \brief Bridging via __bridge_transfer, which transfers ownership of an
343224145Sdim  /// Objective-C pointer into ARC.
344224145Sdim  OBC_BridgeTransfer,
345224145Sdim  /// \brief Bridging via __bridge_retain, which makes an ARC object available
346224145Sdim  /// as a +1 C pointer.
347224145Sdim  OBC_BridgeRetained
348224145Sdim};
349224145Sdim
350212795Sdim}
351212795Sdim
352212795Sdim#endif
353