Home | History | Annotate | Download | only in Basic
      1 //===--- Specifiers.h - Declaration and Type Specifiers ---------*- 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 /// \file
     11 /// \brief Defines various enumerations that describe declaration and
     12 /// type specifiers.
     13 ///
     14 //===----------------------------------------------------------------------===//
     15 
     16 #ifndef LLVM_CLANG_BASIC_SPECIFIERS_H
     17 #define LLVM_CLANG_BASIC_SPECIFIERS_H
     18 
     19 #include "llvm/ADT/StringRef.h"
     20 #include "llvm/Support/DataTypes.h"
     21 #include "llvm/Support/ErrorHandling.h"
     22 
     23 namespace clang {
     24   /// \brief Specifies the width of a type, e.g., short, long, or long long.
     25   enum TypeSpecifierWidth {
     26     TSW_unspecified,
     27     TSW_short,
     28     TSW_long,
     29     TSW_longlong
     30   };
     31 
     32   /// \brief Specifies the signedness of a type, e.g., signed or unsigned.
     33   enum TypeSpecifierSign {
     34     TSS_unspecified,
     35     TSS_signed,
     36     TSS_unsigned
     37   };
     38 
     39   /// \brief Specifies the kind of type.
     40   enum TypeSpecifierType {
     41     TST_unspecified,
     42     TST_void,
     43     TST_char,
     44     TST_wchar,        // C++ wchar_t
     45     TST_char16,       // C++11 char16_t
     46     TST_char32,       // C++11 char32_t
     47     TST_int,
     48     TST_int128,
     49     TST_half,         // OpenCL half, ARM NEON __fp16
     50     TST_float,
     51     TST_double,
     52     TST_bool,         // _Bool
     53     TST_decimal32,    // _Decimal32
     54     TST_decimal64,    // _Decimal64
     55     TST_decimal128,   // _Decimal128
     56     TST_enum,
     57     TST_union,
     58     TST_struct,
     59     TST_class,        // C++ class type
     60     TST_interface,    // C++ (Microsoft-specific) __interface type
     61     TST_typename,     // Typedef, C++ class-name or enum name, etc.
     62     TST_typeofType,
     63     TST_typeofExpr,
     64     TST_decltype,         // C++11 decltype
     65     TST_underlyingType,   // __underlying_type for C++11
     66     TST_auto,             // C++11 auto
     67     TST_decltype_auto,    // C++1y decltype(auto)
     68     TST_auto_type,        // __auto_type extension
     69     TST_unknown_anytype,  // __unknown_anytype extension
     70     TST_atomic,           // C11 _Atomic
     71     TST_error         // erroneous type
     72   };
     73 
     74   /// \brief Structure that packs information about the type specifiers that
     75   /// were written in a particular type specifier sequence.
     76   struct WrittenBuiltinSpecs {
     77     /*DeclSpec::TST*/ unsigned Type  : 5;
     78     /*DeclSpec::TSS*/ unsigned Sign  : 2;
     79     /*DeclSpec::TSW*/ unsigned Width : 2;
     80     bool ModeAttr : 1;
     81   };
     82 
     83   /// \brief A C++ access specifier (public, private, protected), plus the
     84   /// special value "none" which means different things in different contexts.
     85   enum AccessSpecifier {
     86     AS_public,
     87     AS_protected,
     88     AS_private,
     89     AS_none
     90   };
     91 
     92   /// \brief The categorization of expression values, currently following the
     93   /// C++11 scheme.
     94   enum ExprValueKind {
     95     /// \brief An r-value expression (a pr-value in the C++11 taxonomy)
     96     /// produces a temporary value.
     97     VK_RValue,
     98 
     99     /// \brief An l-value expression is a reference to an object with
    100     /// independent storage.
    101     VK_LValue,
    102 
    103     /// \brief An x-value expression is a reference to an object with
    104     /// independent storage but which can be "moved", i.e.
    105     /// efficiently cannibalized for its resources.
    106     VK_XValue
    107   };
    108 
    109   /// \brief A further classification of the kind of object referenced by an
    110   /// l-value or x-value.
    111   enum ExprObjectKind {
    112     /// An ordinary object is located at an address in memory.
    113     OK_Ordinary,
    114 
    115     /// A bitfield object is a bitfield on a C or C++ record.
    116     OK_BitField,
    117 
    118     /// A vector component is an element or range of elements on a vector.
    119     OK_VectorComponent,
    120 
    121     /// An Objective-C property is a logical field of an Objective-C
    122     /// object which is read and written via Objective-C method calls.
    123     OK_ObjCProperty,
    124 
    125     /// An Objective-C array/dictionary subscripting which reads an
    126     /// object or writes at the subscripted array/dictionary element via
    127     /// Objective-C method calls.
    128     OK_ObjCSubscript
    129   };
    130 
    131   /// \brief Describes the kind of template specialization that a
    132   /// particular template specialization declaration represents.
    133   enum TemplateSpecializationKind {
    134     /// This template specialization was formed from a template-id but
    135     /// has not yet been declared, defined, or instantiated.
    136     TSK_Undeclared = 0,
    137     /// This template specialization was implicitly instantiated from a
    138     /// template. (C++ [temp.inst]).
    139     TSK_ImplicitInstantiation,
    140     /// This template specialization was declared or defined by an
    141     /// explicit specialization (C++ [temp.expl.spec]) or partial
    142     /// specialization (C++ [temp.class.spec]).
    143     TSK_ExplicitSpecialization,
    144     /// This template specialization was instantiated from a template
    145     /// due to an explicit instantiation declaration request
    146     /// (C++11 [temp.explicit]).
    147     TSK_ExplicitInstantiationDeclaration,
    148     /// This template specialization was instantiated from a template
    149     /// due to an explicit instantiation definition request
    150     /// (C++ [temp.explicit]).
    151     TSK_ExplicitInstantiationDefinition
    152   };
    153 
    154   /// \brief Determine whether this template specialization kind refers
    155   /// to an instantiation of an entity (as opposed to a non-template or
    156   /// an explicit specialization).
    157   inline bool isTemplateInstantiation(TemplateSpecializationKind Kind) {
    158     return Kind != TSK_Undeclared && Kind != TSK_ExplicitSpecialization;
    159   }
    160 
    161   /// \brief True if this template specialization kind is an explicit
    162   /// specialization, explicit instantiation declaration, or explicit
    163   /// instantiation definition.
    164   inline bool isTemplateExplicitInstantiationOrSpecialization(
    165       TemplateSpecializationKind Kind) {
    166     switch (Kind) {
    167     case TSK_ExplicitSpecialization:
    168     case TSK_ExplicitInstantiationDeclaration:
    169     case TSK_ExplicitInstantiationDefinition:
    170       return true;
    171 
    172     case TSK_Undeclared:
    173     case TSK_ImplicitInstantiation:
    174       return false;
    175     }
    176     llvm_unreachable("bad template specialization kind");
    177   }
    178 
    179   /// \brief Thread storage-class-specifier.
    180   enum ThreadStorageClassSpecifier {
    181     TSCS_unspecified,
    182     /// GNU __thread.
    183     TSCS___thread,
    184     /// C++11 thread_local. Implies 'static' at block scope, but not at
    185     /// class scope.
    186     TSCS_thread_local,
    187     /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
    188     /// if used at block scope.
    189     TSCS__Thread_local
    190   };
    191 
    192   /// \brief Storage classes.
    193   enum StorageClass {
    194     // These are legal on both functions and variables.
    195     SC_None,
    196     SC_Extern,
    197     SC_Static,
    198     SC_PrivateExtern,
    199 
    200     // These are only legal on variables.
    201     SC_Auto,
    202     SC_Register
    203   };
    204 
    205   /// \brief Checks whether the given storage class is legal for functions.
    206   inline bool isLegalForFunction(StorageClass SC) {
    207     return SC <= SC_PrivateExtern;
    208   }
    209 
    210   /// \brief Checks whether the given storage class is legal for variables.
    211   inline bool isLegalForVariable(StorageClass SC) {
    212     return true;
    213   }
    214 
    215   /// \brief In-class initialization styles for non-static data members.
    216   enum InClassInitStyle {
    217     ICIS_NoInit,   ///< No in-class initializer.
    218     ICIS_CopyInit, ///< Copy initialization.
    219     ICIS_ListInit  ///< Direct list-initialization.
    220   };
    221 
    222   /// \brief CallingConv - Specifies the calling convention that a function uses.
    223   enum CallingConv {
    224     CC_C,           // __attribute__((cdecl))
    225     CC_X86StdCall,  // __attribute__((stdcall))
    226     CC_X86FastCall, // __attribute__((fastcall))
    227     CC_X86ThisCall, // __attribute__((thiscall))
    228     CC_X86VectorCall, // __attribute__((vectorcall))
    229     CC_X86Pascal,   // __attribute__((pascal))
    230     CC_X86_64Win64, // __attribute__((ms_abi))
    231     CC_X86_64SysV,  // __attribute__((sysv_abi))
    232     CC_AAPCS,       // __attribute__((pcs("aapcs")))
    233     CC_AAPCS_VFP,   // __attribute__((pcs("aapcs-vfp")))
    234     CC_IntelOclBicc, // __attribute__((intel_ocl_bicc))
    235     CC_SpirFunction, // default for OpenCL functions on SPIR target
    236     CC_SpirKernel    // inferred for OpenCL kernels on SPIR target
    237   };
    238 
    239   /// \brief Checks whether the given calling convention supports variadic
    240   /// calls. Unprototyped calls also use the variadic call rules.
    241   inline bool supportsVariadicCall(CallingConv CC) {
    242     switch (CC) {
    243     case CC_X86StdCall:
    244     case CC_X86FastCall:
    245     case CC_X86ThisCall:
    246     case CC_X86Pascal:
    247     case CC_X86VectorCall:
    248     case CC_SpirFunction:
    249     case CC_SpirKernel:
    250       return false;
    251     default:
    252       return true;
    253     }
    254   }
    255 
    256   /// \brief The storage duration for an object (per C++ [basic.stc]).
    257   enum StorageDuration {
    258     SD_FullExpression, ///< Full-expression storage duration (for temporaries).
    259     SD_Automatic,      ///< Automatic storage duration (most local variables).
    260     SD_Thread,         ///< Thread storage duration.
    261     SD_Static,         ///< Static storage duration.
    262     SD_Dynamic         ///< Dynamic storage duration.
    263   };
    264 
    265   /// Describes the nullability of a particular type.
    266   enum class NullabilityKind : uint8_t {
    267     /// Values of this type can never be null.
    268     NonNull = 0,
    269     /// Values of this type can be null.
    270     Nullable,
    271     /// Whether values of this type can be null is (explicitly)
    272     /// unspecified. This captures a (fairly rare) case where we
    273     /// can't conclude anything about the nullability of the type even
    274     /// though it has been considered.
    275     Unspecified
    276   };
    277 
    278   /// Retrieve the spelling of the given nullability kind.
    279   llvm::StringRef getNullabilitySpelling(NullabilityKind kind,
    280                                          bool isContextSensitive = false);
    281 } // end namespace clang
    282 
    283 #endif // LLVM_CLANG_BASIC_SPECIFIERS_H
    284