clang API Documentation

OperationKinds.h
Go to the documentation of this file.
00001 //===- OperationKinds.h - Operation enums -----------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file enumerates the different kinds of operations that can be
00011 // performed by various expressions.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_AST_OPERATIONKINDS_H
00016 #define LLVM_CLANG_AST_OPERATIONKINDS_H
00017 
00018 namespace clang {
00019   
00020 /// CastKind - The kind of operation required for a conversion.
00021 enum CastKind {
00022   /// CK_Dependent - A conversion which cannot yet be analyzed because
00023   /// either the expression or target type is dependent.  These are
00024   /// created only for explicit casts; dependent ASTs aren't required
00025   /// to even approximately type-check.
00026   ///   (T*) malloc(sizeof(T))
00027   ///   reinterpret_cast<intptr_t>(A<T>::alloc());
00028   CK_Dependent,
00029 
00030   /// CK_BitCast - A conversion which causes a bit pattern of one type
00031   /// to be reinterpreted as a bit pattern of another type.  Generally
00032   /// the operands must have equivalent size and unrelated types.
00033   ///
00034   /// The pointer conversion char* -> int* is a bitcast.  A conversion
00035   /// from any pointer type to a C pointer type is a bitcast unless
00036   /// it's actually BaseToDerived or DerivedToBase.  A conversion to a
00037   /// block pointer or ObjC pointer type is a bitcast only if the
00038   /// operand has the same type kind; otherwise, it's one of the
00039   /// specialized casts below.
00040   ///
00041   /// Vector coercions are bitcasts.
00042   CK_BitCast,
00043 
00044   /// CK_LValueBitCast - A conversion which reinterprets the address of
00045   /// an l-value as an l-value of a different kind.  Used for
00046   /// reinterpret_casts of l-value expressions to reference types.
00047   ///    bool b; reinterpret_cast<char&>(b) = 'a';
00048   CK_LValueBitCast,
00049   
00050   /// CK_LValueToRValue - A conversion which causes the extraction of
00051   /// an r-value from the operand gl-value.  The result of an r-value
00052   /// conversion is always unqualified.
00053   CK_LValueToRValue,
00054 
00055   /// CK_NoOp - A conversion which does not affect the type other than
00056   /// (possibly) adding qualifiers.
00057   ///   int    -> int
00058   ///   char** -> const char * const *
00059   CK_NoOp,
00060 
00061   /// CK_BaseToDerived - A conversion from a C++ class pointer/reference
00062   /// to a derived class pointer/reference.
00063   ///   B *b = static_cast<B*>(a);
00064   CK_BaseToDerived,
00065 
00066   /// CK_DerivedToBase - A conversion from a C++ class pointer
00067   /// to a base class pointer.
00068   ///   A *a = new B();
00069   CK_DerivedToBase,
00070 
00071   /// CK_UncheckedDerivedToBase - A conversion from a C++ class
00072   /// pointer/reference to a base class that can assume that the
00073   /// derived pointer is not null.
00074   ///   const A &a = B();
00075   ///   b->method_from_a();
00076   CK_UncheckedDerivedToBase,
00077 
00078   /// CK_Dynamic - A C++ dynamic_cast.
00079   CK_Dynamic,
00080 
00081   /// CK_ToUnion - The GCC cast-to-union extension.
00082   ///   int   -> union { int x; float y; }
00083   ///   float -> union { int x; float y; }
00084   CK_ToUnion,
00085 
00086   /// CK_ArrayToPointerDecay - Array to pointer decay.
00087   ///   int[10] -> int*
00088   ///   char[5][6] -> char(*)[6]
00089   CK_ArrayToPointerDecay,
00090 
00091   /// CK_FunctionToPointerDecay - Function to pointer decay.
00092   ///   void(int) -> void(*)(int)
00093   CK_FunctionToPointerDecay,
00094 
00095   /// CK_NullToPointer - Null pointer constant to pointer, ObjC
00096   /// pointer, or block pointer.
00097   ///   (void*) 0
00098   ///   void (^block)() = 0;
00099   CK_NullToPointer,
00100 
00101   /// CK_NullToMemberPointer - Null pointer constant to member pointer.
00102   ///   int A::*mptr = 0;
00103   ///   int (A::*fptr)(int) = nullptr;
00104   CK_NullToMemberPointer,
00105 
00106   /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
00107   /// member pointer in derived class.
00108   ///   int B::*mptr = &A::member;
00109   CK_BaseToDerivedMemberPointer,
00110 
00111   /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
00112   /// member pointer in base class.
00113   ///   int A::*mptr = static_cast<int A::*>(&B::member);
00114   CK_DerivedToBaseMemberPointer,
00115     
00116   /// CK_MemberPointerToBoolean - Member pointer to boolean.  A check
00117   /// against the null member pointer.
00118   CK_MemberPointerToBoolean,
00119 
00120   /// CK_ReinterpretMemberPointer - Reinterpret a member pointer as a
00121   /// different kind of member pointer.  C++ forbids this from
00122   /// crossing between function and object types, but otherwise does
00123   /// not restrict it.  However, the only operation that is permitted
00124   /// on a "punned" member pointer is casting it back to the original
00125   /// type, which is required to be a lossless operation (although
00126   /// many ABIs do not guarantee this on all possible intermediate types).
00127   CK_ReinterpretMemberPointer,
00128 
00129   /// CK_UserDefinedConversion - Conversion using a user defined type
00130   /// conversion function.
00131   ///    struct A { operator int(); }; int i = int(A());
00132   CK_UserDefinedConversion,
00133 
00134   /// CK_ConstructorConversion - Conversion by constructor.
00135   ///    struct A { A(int); }; A a = A(10);
00136   CK_ConstructorConversion,
00137     
00138   /// CK_IntegralToPointer - Integral to pointer.  A special kind of
00139   /// reinterpreting conversion.  Applies to normal, ObjC, and block
00140   /// pointers.
00141   ///    (char*) 0x1001aab0
00142   ///    reinterpret_cast<int*>(0)
00143   CK_IntegralToPointer,
00144     
00145   /// CK_PointerToIntegral - Pointer to integral.  A special kind of
00146   /// reinterpreting conversion.  Applies to normal, ObjC, and block
00147   /// pointers.
00148   ///    (intptr_t) "help!"
00149   CK_PointerToIntegral,
00150 
00151   /// CK_PointerToBoolean - Pointer to boolean conversion.  A check
00152   /// against null.  Applies to normal, ObjC, and block pointers.
00153   CK_PointerToBoolean,
00154     
00155   /// CK_ToVoid - Cast to void, discarding the computed value.
00156   ///    (void) malloc(2048)
00157   CK_ToVoid,
00158     
00159   /// CK_VectorSplat - A conversion from an arithmetic type to a
00160   /// vector of that element type.  Fills all elements ("splats") with
00161   /// the source value.
00162   ///    __attribute__((ext_vector_type(4))) int v = 5;
00163   CK_VectorSplat,
00164     
00165   /// CK_IntegralCast - A cast between integral types (other than to
00166   /// boolean).  Variously a bitcast, a truncation, a sign-extension,
00167   /// or a zero-extension.
00168   ///    long l = 5;
00169   ///    (unsigned) i
00170   CK_IntegralCast,
00171 
00172   /// CK_IntegralToBoolean - Integral to boolean.  A check against zero.
00173   ///    (bool) i
00174   CK_IntegralToBoolean,
00175 
00176   /// CK_IntegralToFloating - Integral to floating point.
00177   ///    float f = i;
00178   CK_IntegralToFloating,
00179     
00180   /// CK_FloatingToIntegral - Floating point to integral.  Rounds
00181   /// towards zero, discarding any fractional component.
00182   ///    (int) f
00183   CK_FloatingToIntegral,
00184 
00185   /// CK_FloatingToBoolean - Floating point to boolean.
00186   ///    (bool) f
00187   CK_FloatingToBoolean,
00188     
00189   /// CK_FloatingCast - Casting between floating types of different size.
00190   ///    (double) f
00191   ///    (float) ld
00192   CK_FloatingCast,
00193     
00194   /// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an
00195   /// Objective-C pointer.
00196   CK_CPointerToObjCPointerCast,
00197 
00198   /// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an
00199   /// ObjC pointer.
00200   CK_BlockPointerToObjCPointerCast,
00201 
00202   /// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer
00203   /// to a block pointer.  Block-to-block casts are bitcasts.
00204   CK_AnyPointerToBlockPointerCast,
00205 
00206   /// \brief Converting between two Objective-C object types, which
00207   /// can occur when performing reference binding to an Objective-C
00208   /// object.
00209   CK_ObjCObjectLValueCast,
00210 
00211   /// \brief A conversion of a floating point real to a floating point
00212   /// complex of the original type.  Injects the value as the real
00213   /// component with a zero imaginary component.
00214   ///   float -> _Complex float
00215   CK_FloatingRealToComplex,
00216 
00217   /// \brief Converts a floating point complex to floating point real
00218   /// of the source's element type.  Just discards the imaginary
00219   /// component.
00220   ///   _Complex long double -> long double
00221   CK_FloatingComplexToReal,
00222 
00223   /// \brief Converts a floating point complex to bool by comparing
00224   /// against 0+0i.
00225   CK_FloatingComplexToBoolean,
00226 
00227   /// \brief Converts between different floating point complex types.
00228   ///   _Complex float -> _Complex double
00229   CK_FloatingComplexCast,
00230 
00231   /// \brief Converts from a floating complex to an integral complex.
00232   ///   _Complex float -> _Complex int
00233   CK_FloatingComplexToIntegralComplex,
00234 
00235   /// \brief Converts from an integral real to an integral complex
00236   /// whose element type matches the source.  Injects the value as
00237   /// the real component with a zero imaginary component.
00238   ///   long -> _Complex long
00239   CK_IntegralRealToComplex,
00240 
00241   /// \brief Converts an integral complex to an integral real of the
00242   /// source's element type by discarding the imaginary component.
00243   ///   _Complex short -> short
00244   CK_IntegralComplexToReal,
00245 
00246   /// \brief Converts an integral complex to bool by comparing against
00247   /// 0+0i.
00248   CK_IntegralComplexToBoolean,
00249 
00250   /// \brief Converts between different integral complex types.
00251   ///   _Complex char -> _Complex long long
00252   ///   _Complex unsigned int -> _Complex signed int
00253   CK_IntegralComplexCast,
00254 
00255   /// \brief Converts from an integral complex to a floating complex.
00256   ///   _Complex unsigned -> _Complex float
00257   CK_IntegralComplexToFloatingComplex,
00258 
00259   /// \brief [ARC] Produces a retainable object pointer so that it may
00260   /// be consumed, e.g. by being passed to a consuming parameter.
00261   /// Calls objc_retain.
00262   CK_ARCProduceObject,
00263 
00264   /// \brief [ARC] Consumes a retainable object pointer that has just
00265   /// been produced, e.g. as the return value of a retaining call.
00266   /// Enters a cleanup to call objc_release at some indefinite time.
00267   CK_ARCConsumeObject,
00268 
00269   /// \brief [ARC] Reclaim a retainable object pointer object that may
00270   /// have been produced and autoreleased as part of a function return
00271   /// sequence.
00272   CK_ARCReclaimReturnedObject,
00273 
00274   /// \brief [ARC] Causes a value of block type to be copied to the
00275   /// heap, if it is not already there.  A number of other operations
00276   /// in ARC cause blocks to be copied; this is for cases where that
00277   /// would not otherwise be guaranteed, such as when casting to a
00278   /// non-block pointer type.
00279   CK_ARCExtendBlockObject,
00280 
00281   /// \brief Converts from _Atomic(T) to T.
00282   CK_AtomicToNonAtomic,
00283   /// \brief Converts from T to _Atomic(T).
00284   CK_NonAtomicToAtomic,
00285   
00286   /// \brief Causes a block literal to by copied to the heap and then 
00287   /// autoreleased.
00288   ///
00289   /// This particular cast kind is used for the conversion from a C++11
00290   /// lambda expression to a block pointer.
00291   CK_CopyAndAutoreleaseBlockObject,
00292 
00293   // Convert a builtin function to a function pointer; only allowed in the
00294   // callee of a call expression.
00295   CK_BuiltinFnToFnPtr,
00296 
00297   // Convert a zero value for OpenCL event_t initialization.
00298   CK_ZeroToOCLEvent,
00299 
00300   // Convert a pointer to a different address space.
00301   CK_AddressSpaceConversion
00302 };
00303 
00304 static const CastKind CK_Invalid = static_cast<CastKind>(-1);
00305 
00306 enum BinaryOperatorKind {
00307   // Operators listed in order of precedence.
00308   // Note that additions to this should also update the StmtVisitor class.
00309   BO_PtrMemD, BO_PtrMemI,       // [C++ 5.5] Pointer-to-member operators.
00310   BO_Mul, BO_Div, BO_Rem,       // [C99 6.5.5] Multiplicative operators.
00311   BO_Add, BO_Sub,               // [C99 6.5.6] Additive operators.
00312   BO_Shl, BO_Shr,               // [C99 6.5.7] Bitwise shift operators.
00313   BO_LT, BO_GT, BO_LE, BO_GE,   // [C99 6.5.8] Relational operators.
00314   BO_EQ, BO_NE,                 // [C99 6.5.9] Equality operators.
00315   BO_And,                       // [C99 6.5.10] Bitwise AND operator.
00316   BO_Xor,                       // [C99 6.5.11] Bitwise XOR operator.
00317   BO_Or,                        // [C99 6.5.12] Bitwise OR operator.
00318   BO_LAnd,                      // [C99 6.5.13] Logical AND operator.
00319   BO_LOr,                       // [C99 6.5.14] Logical OR operator.
00320   BO_Assign, BO_MulAssign,      // [C99 6.5.16] Assignment operators.
00321   BO_DivAssign, BO_RemAssign,
00322   BO_AddAssign, BO_SubAssign,
00323   BO_ShlAssign, BO_ShrAssign,
00324   BO_AndAssign, BO_XorAssign,
00325   BO_OrAssign,
00326   BO_Comma                      // [C99 6.5.17] Comma operator.
00327 };
00328 
00329 enum UnaryOperatorKind {
00330   // Note that additions to this should also update the StmtVisitor class.
00331   UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
00332   UO_PreInc, UO_PreDec,   // [C99 6.5.3.1] Prefix increment and decrement
00333   UO_AddrOf, UO_Deref,    // [C99 6.5.3.2] Address and indirection
00334   UO_Plus, UO_Minus,      // [C99 6.5.3.3] Unary arithmetic
00335   UO_Not, UO_LNot,        // [C99 6.5.3.3] Unary arithmetic
00336   UO_Real, UO_Imag,       // "__real expr"/"__imag expr" Extension.
00337   UO_Extension            // __extension__ marker.
00338 };
00339 
00340 /// \brief The kind of bridging performed by the Objective-C bridge cast.
00341 enum ObjCBridgeCastKind {
00342   /// \brief Bridging via __bridge, which does nothing but reinterpret
00343   /// the bits.
00344   OBC_Bridge,
00345   /// \brief Bridging via __bridge_transfer, which transfers ownership of an
00346   /// Objective-C pointer into ARC.
00347   OBC_BridgeTransfer,
00348   /// \brief Bridging via __bridge_retain, which makes an ARC object available
00349   /// as a +1 C pointer.
00350   OBC_BridgeRetained
00351 };
00352 
00353 }
00354 
00355 #endif