]> granicus.if.org Git - clang/blob - include/clang/AST/OperationKinds.h
Kill CK_Unknown and flesh out the documentation for the existing CastKinds.
[clang] / include / clang / AST / OperationKinds.h
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
18 namespace clang {
19   
20 /// CastKind - The kind of operation required for a conversion.
21 enum 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.  Many other
35   /// pointer conversions which are "physically" bitcasts are given
36   /// special cast kinds.
37   ///
38   /// Vector coercions are bitcasts.
39   CK_BitCast,
40
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';
45   CK_LValueBitCast,
46     
47   /// CK_NoOp - A conversion which does not affect the type other than
48   /// (possibly) adding qualifiers.
49   ///   int    -> int
50   ///   char** -> const char * const *
51   CK_NoOp,
52
53   /// CK_BaseToDerived - A conversion from a C++ class pointer/reference
54   /// to a derived class pointer/reference.
55   ///   B *b = static_cast<B*>(a);
56   CK_BaseToDerived,
57
58   /// CK_DerivedToBase - A conversion from a C++ class pointer
59   /// to a base class pointer.
60   ///   A *a = new B();
61   CK_DerivedToBase,
62
63   /// CK_UncheckedDerivedToBase - A conversion from a C++ class
64   /// pointer/reference to a base class that can assume that the
65   /// derived pointer is not null.
66   ///   const A &a = B();
67   ///   b->method_from_a();
68   CK_UncheckedDerivedToBase,
69
70   /// CK_Dynamic - A C++ dynamic_cast.
71   CK_Dynamic,
72
73   /// CK_ToUnion - The GCC cast-to-union extension.
74   ///   int   -> union { int x; float y; }
75   ///   float -> union { int x; float y; }
76   CK_ToUnion,
77
78   /// CK_ArrayToPointerDecay - Array to pointer decay.
79   ///   int[10] -> int*
80   ///   char[5][6] -> char(*)[6]
81   CK_ArrayToPointerDecay,
82
83   /// CK_FunctionToPointerDecay - Function to pointer decay.
84   ///   void(int) -> void(*)(int)
85   CK_FunctionToPointerDecay,
86
87   /// CK_NullToPointer - Null pointer constant to pointer, ObjC
88   /// pointer, or block pointer.
89   ///   (void*) 0
90   ///   void (^block)() = 0;
91   CK_NullToPointer,
92
93   /// CK_NullToMemberPointer - Null pointer constant to member pointer.
94   ///   int A::*mptr = 0;
95   ///   int (A::*fptr)(int) = nullptr;
96   CK_NullToMemberPointer,
97
98   /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
99   /// member pointer in derived class.
100   ///   int B::*mptr = &A::member;
101   CK_BaseToDerivedMemberPointer,
102
103   /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
104   /// member pointer in base class.
105   ///   int A::*mptr = static_cast<int A::*>(&B::member);
106   CK_DerivedToBaseMemberPointer,
107     
108   /// CK_MemberPointerToBoolean - Member pointer to boolean.  A check
109   /// against the null member pointer.
110   CK_MemberPointerToBoolean,
111
112   /// CK_UserDefinedConversion - Conversion using a user defined type
113   /// conversion function.
114   ///    struct A { operator int(); }; int i = int(A());
115   CK_UserDefinedConversion,
116
117   /// CK_ConstructorConversion - Conversion by constructor.
118   ///    struct A { A(int); }; A a = A(10);
119   CK_ConstructorConversion,
120     
121   /// CK_IntegralToPointer - Integral to pointer.  A special kind of
122   /// reinterpreting conversion.  Applies to normal, ObjC, and block
123   /// pointers.
124   ///    (char*) 0x1001aab0
125   ///    reinterpret_cast<int*>(0)
126   CK_IntegralToPointer,
127     
128   /// CK_PointerToIntegral - Pointer to integral.  A special kind of
129   /// reinterpreting conversion.  Applies to normal, ObjC, and block
130   /// pointers.
131   ///    (intptr_t) "help!"
132   CK_PointerToIntegral,
133
134   /// CK_PointerToBoolean - Pointer to boolean conversion.  A check
135   /// against null.  Applies to normal, ObjC, and block pointers.
136   CK_PointerToBoolean,
137     
138   /// CK_ToVoid - Cast to void, discarding the computed value.
139   ///    (void) malloc(2048)
140   CK_ToVoid,
141     
142   /// CK_VectorSplat - A conversion from an arithmetic type to a
143   /// vector of that element type.  Fills all elements ("splats") with
144   /// the source value.
145   ///    __attribute__((ext_vector_type(4))) int v = 5;
146   CK_VectorSplat,
147     
148   /// CK_IntegralCast - A cast between integral types (other than to
149   /// boolean).  Variously a bitcast, a truncation, a sign-extension,
150   /// or a zero-extension.
151   ///    long l = 5;
152   ///    (unsigned) i
153   CK_IntegralCast,
154
155   /// CK_IntegralToBoolean - Integral to boolean.  A check against zero.
156   ///    (bool) i
157   CK_IntegralToBoolean,
158
159   /// CK_IntegralToFloating - Integral to floating point.
160   ///    float f = i;
161   CK_IntegralToFloating,
162     
163   /// CK_FloatingToIntegral - Floating point to integral.  Rounds
164   /// towards zero, discarding any fractional component.
165   ///    (int) f
166   CK_FloatingToIntegral,
167
168   /// CK_FloatingToBoolean - Floating point to boolean.
169   ///    (bool) f
170   CK_FloatingToBoolean,
171     
172   /// CK_FloatingCast - Casting between floating types of different size.
173   ///    (double) f
174   ///    (float) ld
175   CK_FloatingCast,
176     
177   /// CK_AnyPointerToObjCPointerCast - Casting any other pointer kind
178   /// to an Objective-C pointer.
179   CK_AnyPointerToObjCPointerCast,
180
181   /// CK_AnyPointerToBlockPointerCast - Casting any other pointer kind
182   /// to a block pointer.
183   CK_AnyPointerToBlockPointerCast,
184
185   /// \brief Converting between two Objective-C object types, which
186   /// can occur when performing reference binding to an Objective-C
187   /// object.
188   CK_ObjCObjectLValueCast,
189
190   /// \brief A conversion of a floating point real to a floating point
191   /// complex of the original type.  Injects the value as the real
192   /// component with a zero imaginary component.
193   ///   float -> _Complex float
194   CK_FloatingRealToComplex,
195
196   /// \brief Converts a floating point complex to floating point real
197   /// of the source's element type.  Just discards the imaginary
198   /// component.
199   ///   _Complex long double -> long double
200   CK_FloatingComplexToReal,
201
202   /// \brief Converts a floating point complex to bool by comparing
203   /// against 0+0i.
204   CK_FloatingComplexToBoolean,
205
206   /// \brief Converts between different floating point complex types.
207   ///   _Complex float -> _Complex double
208   CK_FloatingComplexCast,
209
210   /// \brief Converts from a floating complex to an integral complex.
211   ///   _Complex float -> _Complex int
212   CK_FloatingComplexToIntegralComplex,
213
214   /// \brief Converts from an integral real to an integral complex
215   /// whose element type matches the source.  Injects the value as
216   /// the real component with a zero imaginary component.
217   ///   long -> _Complex long
218   CK_IntegralRealToComplex,
219
220   /// \brief Converts an integral complex to an integral real of the
221   /// source's element type by discarding the imaginary component.
222   ///   _Complex short -> short
223   CK_IntegralComplexToReal,
224
225   /// \brief Converts an integral complex to bool by comparing against
226   /// 0+0i.
227   CK_IntegralComplexToBoolean,
228
229   /// \brief Converts between different integral complex types.
230   ///   _Complex char -> _Complex long long
231   ///   _Complex unsigned int -> _Complex signed int
232   CK_IntegralComplexCast,
233
234   /// \brief Converts from an integral complex to a floating complex.
235   ///   _Complex unsigned -> _Complex float
236   CK_IntegralComplexToFloatingComplex
237 };
238
239 #define CK_Invalid ((CastKind) -1)
240
241 enum BinaryOperatorKind {
242   // Operators listed in order of precedence.
243   // Note that additions to this should also update the StmtVisitor class.
244   BO_PtrMemD, BO_PtrMemI,       // [C++ 5.5] Pointer-to-member operators.
245   BO_Mul, BO_Div, BO_Rem,       // [C99 6.5.5] Multiplicative operators.
246   BO_Add, BO_Sub,               // [C99 6.5.6] Additive operators.
247   BO_Shl, BO_Shr,               // [C99 6.5.7] Bitwise shift operators.
248   BO_LT, BO_GT, BO_LE, BO_GE,   // [C99 6.5.8] Relational operators.
249   BO_EQ, BO_NE,                 // [C99 6.5.9] Equality operators.
250   BO_And,                       // [C99 6.5.10] Bitwise AND operator.
251   BO_Xor,                       // [C99 6.5.11] Bitwise XOR operator.
252   BO_Or,                        // [C99 6.5.12] Bitwise OR operator.
253   BO_LAnd,                      // [C99 6.5.13] Logical AND operator.
254   BO_LOr,                       // [C99 6.5.14] Logical OR operator.
255   BO_Assign, BO_MulAssign,      // [C99 6.5.16] Assignment operators.
256   BO_DivAssign, BO_RemAssign,
257   BO_AddAssign, BO_SubAssign,
258   BO_ShlAssign, BO_ShrAssign,
259   BO_AndAssign, BO_XorAssign,
260   BO_OrAssign,
261   BO_Comma                      // [C99 6.5.17] Comma operator.
262 };
263
264 enum UnaryOperatorKind {
265   // Note that additions to this should also update the StmtVisitor class.
266   UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
267   UO_PreInc, UO_PreDec,   // [C99 6.5.3.1] Prefix increment and decrement
268   UO_AddrOf, UO_Deref,    // [C99 6.5.3.2] Address and indirection
269   UO_Plus, UO_Minus,      // [C99 6.5.3.3] Unary arithmetic
270   UO_Not, UO_LNot,        // [C99 6.5.3.3] Unary arithmetic
271   UO_Real, UO_Imag,       // "__real expr"/"__imag expr" Extension.
272   UO_Extension            // __extension__ marker.
273 };
274
275 }
276
277 #endif