Home | History | Annotate | Download | only in AST
      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.  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_ReinterpretMemberPointer - Reinterpret a member pointer as a
    121   /// different kind of member pointer.  C++ forbids this from
    122   /// crossing between function and object types, but otherwise does
    123   /// not restrict it.  However, the only operation that is permitted
    124   /// on a "punned" member pointer is casting it back to the original
    125   /// type, which is required to be a lossless operation (although
    126   /// many ABIs do not guarantee this on all possible intermediate types).
    127   CK_ReinterpretMemberPointer,
    128 
    129   /// CK_UserDefinedConversion - Conversion using a user defined type
    130   /// conversion function.
    131   ///    struct A { operator int(); }; int i = int(A());
    132   CK_UserDefinedConversion,
    133 
    134   /// CK_ConstructorConversion - Conversion by constructor.
    135   ///    struct A { A(int); }; A a = A(10);
    136   CK_ConstructorConversion,
    137 
    138   /// CK_IntegralToPointer - Integral to pointer.  A special kind of
    139   /// reinterpreting conversion.  Applies to normal, ObjC, and block
    140   /// pointers.
    141   ///    (char*) 0x1001aab0
    142   ///    reinterpret_cast<int*>(0)
    143   CK_IntegralToPointer,
    144 
    145   /// CK_PointerToIntegral - Pointer to integral.  A special kind of
    146   /// reinterpreting conversion.  Applies to normal, ObjC, and block
    147   /// pointers.
    148   ///    (intptr_t) "help!"
    149   CK_PointerToIntegral,
    150 
    151   /// CK_PointerToBoolean - Pointer to boolean conversion.  A check
    152   /// against null.  Applies to normal, ObjC, and block pointers.
    153   CK_PointerToBoolean,
    154 
    155   /// CK_ToVoid - Cast to void, discarding the computed value.
    156   ///    (void) malloc(2048)
    157   CK_ToVoid,
    158 
    159   /// CK_VectorSplat - A conversion from an arithmetic type to a
    160   /// vector of that element type.  Fills all elements ("splats") with
    161   /// the source value.
    162   ///    __attribute__((ext_vector_type(4))) int v = 5;
    163   CK_VectorSplat,
    164 
    165   /// CK_IntegralCast - A cast between integral types (other than to
    166   /// boolean).  Variously a bitcast, a truncation, a sign-extension,
    167   /// or a zero-extension.
    168   ///    long l = 5;
    169   ///    (unsigned) i
    170   CK_IntegralCast,
    171 
    172   /// CK_IntegralToBoolean - Integral to boolean.  A check against zero.
    173   ///    (bool) i
    174   CK_IntegralToBoolean,
    175 
    176   /// CK_IntegralToFloating - Integral to floating point.
    177   ///    float f = i;
    178   CK_IntegralToFloating,
    179 
    180   /// CK_FloatingToIntegral - Floating point to integral.  Rounds
    181   /// towards zero, discarding any fractional component.
    182   ///    (int) f
    183   CK_FloatingToIntegral,
    184 
    185   /// CK_FloatingToBoolean - Floating point to boolean.
    186   ///    (bool) f
    187   CK_FloatingToBoolean,
    188 
    189   /// CK_FloatingCast - Casting between floating types of different size.
    190   ///    (double) f
    191   ///    (float) ld
    192   CK_FloatingCast,
    193 
    194   /// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an
    195   /// Objective-C pointer.
    196   CK_CPointerToObjCPointerCast,
    197 
    198   /// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an
    199   /// ObjC pointer.
    200   CK_BlockPointerToObjCPointerCast,
    201 
    202   /// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer
    203   /// to a block pointer.  Block-to-block casts are bitcasts.
    204   CK_AnyPointerToBlockPointerCast,
    205 
    206   /// \brief Converting between two Objective-C object types, which
    207   /// can occur when performing reference binding to an Objective-C
    208   /// object.
    209   CK_ObjCObjectLValueCast,
    210 
    211   /// \brief A conversion of a floating point real to a floating point
    212   /// complex of the original type.  Injects the value as the real
    213   /// component with a zero imaginary component.
    214   ///   float -> _Complex float
    215   CK_FloatingRealToComplex,
    216 
    217   /// \brief Converts a floating point complex to floating point real
    218   /// of the source's element type.  Just discards the imaginary
    219   /// component.
    220   ///   _Complex long double -> long double
    221   CK_FloatingComplexToReal,
    222 
    223   /// \brief Converts a floating point complex to bool by comparing
    224   /// against 0+0i.
    225   CK_FloatingComplexToBoolean,
    226 
    227   /// \brief Converts between different floating point complex types.
    228   ///   _Complex float -> _Complex double
    229   CK_FloatingComplexCast,
    230 
    231   /// \brief Converts from a floating complex to an integral complex.
    232   ///   _Complex float -> _Complex int
    233   CK_FloatingComplexToIntegralComplex,
    234 
    235   /// \brief Converts from an integral real to an integral complex
    236   /// whose element type matches the source.  Injects the value as
    237   /// the real component with a zero imaginary component.
    238   ///   long -> _Complex long
    239   CK_IntegralRealToComplex,
    240 
    241   /// \brief Converts an integral complex to an integral real of the
    242   /// source's element type by discarding the imaginary component.
    243   ///   _Complex short -> short
    244   CK_IntegralComplexToReal,
    245 
    246   /// \brief Converts an integral complex to bool by comparing against
    247   /// 0+0i.
    248   CK_IntegralComplexToBoolean,
    249 
    250   /// \brief Converts between different integral complex types.
    251   ///   _Complex char -> _Complex long long
    252   ///   _Complex unsigned int -> _Complex signed int
    253   CK_IntegralComplexCast,
    254 
    255   /// \brief Converts from an integral complex to a floating complex.
    256   ///   _Complex unsigned -> _Complex float
    257   CK_IntegralComplexToFloatingComplex,
    258 
    259   /// \brief [ARC] Produces a retainable object pointer so that it may
    260   /// be consumed, e.g. by being passed to a consuming parameter.
    261   /// Calls objc_retain.
    262   CK_ARCProduceObject,
    263 
    264   /// \brief [ARC] Consumes a retainable object pointer that has just
    265   /// been produced, e.g. as the return value of a retaining call.
    266   /// Enters a cleanup to call objc_release at some indefinite time.
    267   CK_ARCConsumeObject,
    268 
    269   /// \brief [ARC] Reclaim a retainable object pointer object that may
    270   /// have been produced and autoreleased as part of a function return
    271   /// sequence.
    272   CK_ARCReclaimReturnedObject,
    273 
    274   /// \brief [ARC] Causes a value of block type to be copied to the
    275   /// heap, if it is not already there.  A number of other operations
    276   /// in ARC cause blocks to be copied; this is for cases where that
    277   /// would not otherwise be guaranteed, such as when casting to a
    278   /// non-block pointer type.
    279   CK_ARCExtendBlockObject,
    280 
    281   /// \brief Converts from _Atomic(T) to T.
    282   CK_AtomicToNonAtomic,
    283   /// \brief Converts from T to _Atomic(T).
    284   CK_NonAtomicToAtomic,
    285 
    286   /// \brief Causes a block literal to by copied to the heap and then
    287   /// autoreleased.
    288   ///
    289   /// This particular cast kind is used for the conversion from a C++11
    290   /// lambda expression to a block pointer.
    291   CK_CopyAndAutoreleaseBlockObject,
    292 
    293   // Convert a builtin function to a function pointer; only allowed in the
    294   // callee of a call expression.
    295   CK_BuiltinFnToFnPtr,
    296 
    297   // Convert a zero value for OpenCL event_t initialization.
    298   CK_ZeroToOCLEvent
    299 };
    300 
    301 static const CastKind CK_Invalid = static_cast<CastKind>(-1);
    302 
    303 enum BinaryOperatorKind {
    304   // Operators listed in order of precedence.
    305   // Note that additions to this should also update the StmtVisitor class.
    306   BO_PtrMemD, BO_PtrMemI,       // [C++ 5.5] Pointer-to-member operators.
    307   BO_Mul, BO_Div, BO_Rem,       // [C99 6.5.5] Multiplicative operators.
    308   BO_Add, BO_Sub,               // [C99 6.5.6] Additive operators.
    309   BO_Shl, BO_Shr,               // [C99 6.5.7] Bitwise shift operators.
    310   BO_LT, BO_GT, BO_LE, BO_GE,   // [C99 6.5.8] Relational operators.
    311   BO_EQ, BO_NE,                 // [C99 6.5.9] Equality operators.
    312   BO_And,                       // [C99 6.5.10] Bitwise AND operator.
    313   BO_Xor,                       // [C99 6.5.11] Bitwise XOR operator.
    314   BO_Or,                        // [C99 6.5.12] Bitwise OR operator.
    315   BO_LAnd,                      // [C99 6.5.13] Logical AND operator.
    316   BO_LOr,                       // [C99 6.5.14] Logical OR operator.
    317   BO_Assign, BO_MulAssign,      // [C99 6.5.16] Assignment operators.
    318   BO_DivAssign, BO_RemAssign,
    319   BO_AddAssign, BO_SubAssign,
    320   BO_ShlAssign, BO_ShrAssign,
    321   BO_AndAssign, BO_XorAssign,
    322   BO_OrAssign,
    323   BO_Comma                      // [C99 6.5.17] Comma operator.
    324 };
    325 
    326 enum UnaryOperatorKind {
    327   // Note that additions to this should also update the StmtVisitor class.
    328   UO_PostInc, UO_PostDec, // [C99 6.5.2.4] Postfix increment and decrement
    329   UO_PreInc, UO_PreDec,   // [C99 6.5.3.1] Prefix increment and decrement
    330   UO_AddrOf, UO_Deref,    // [C99 6.5.3.2] Address and indirection
    331   UO_Plus, UO_Minus,      // [C99 6.5.3.3] Unary arithmetic
    332   UO_Not, UO_LNot,        // [C99 6.5.3.3] Unary arithmetic
    333   UO_Real, UO_Imag,       // "__real expr"/"__imag expr" Extension.
    334   UO_Extension            // __extension__ marker.
    335 };
    336 
    337 /// \brief The kind of bridging performed by the Objective-C bridge cast.
    338 enum ObjCBridgeCastKind {
    339   /// \brief Bridging via __bridge, which does nothing but reinterpret
    340   /// the bits.
    341   OBC_Bridge,
    342   /// \brief Bridging via __bridge_transfer, which transfers ownership of an
    343   /// Objective-C pointer into ARC.
    344   OBC_BridgeTransfer,
    345   /// \brief Bridging via __bridge_retain, which makes an ARC object available
    346   /// as a +1 C pointer.
    347   OBC_BridgeRetained
    348 };
    349 
    350 }
    351 
    352 #endif
    353