Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qtypes.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2022 The Qt Company Ltd.
0002 // Copyright (C) 2022 Intel Corporation.
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 
0005 #ifndef QTYPES_H
0006 #define QTYPES_H
0007 
0008 #include <QtCore/qprocessordetection.h>
0009 #include <QtCore/qtconfigmacros.h>
0010 #include <QtCore/qassert.h>
0011 
0012 #ifdef __cplusplus
0013 #  include <cstddef>
0014 #  include <cstdint>
0015 #  if defined(__STDCPP_FLOAT16_T__) && __has_include(<stdfloat>)
0016 // P1467 implementation - https://wg21.link/p1467
0017 #    include <stdfloat>
0018 #  endif // defined(__STDCPP_FLOAT16_T__) && __has_include(<stdfloat>)
0019 #else
0020 #  include <assert.h>
0021 #endif
0022 
0023 #if 0
0024 #pragma qt_class(QtTypes)
0025 #pragma qt_class(QIntegerForSize)
0026 #pragma qt_sync_stop_processing
0027 #endif
0028 
0029 /*
0030    Useful type definitions for Qt
0031 */
0032 typedef unsigned char uchar;
0033 typedef unsigned short ushort;
0034 typedef unsigned int uint;
0035 typedef unsigned long ulong;
0036 
0037 QT_BEGIN_NAMESPACE
0038 
0039 /*
0040    Size-dependent types (architecture-dependent byte order)
0041 
0042    Make sure to update QMetaType when changing these typedefs
0043 */
0044 
0045 typedef signed char qint8;         /* 8 bit signed */
0046 typedef unsigned char quint8;      /* 8 bit unsigned */
0047 typedef short qint16;              /* 16 bit signed */
0048 typedef unsigned short quint16;    /* 16 bit unsigned */
0049 typedef int qint32;                /* 32 bit signed */
0050 typedef unsigned int quint32;      /* 32 bit unsigned */
0051 // Unlike LL / ULL in C++, for historical reasons, we force the
0052 // result to be of the requested type.
0053 #ifdef __cplusplus
0054 #  define Q_INT64_C(c) static_cast<long long>(c ## LL)     /* signed 64 bit constant */
0055 #  define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
0056 #else
0057 #  define Q_INT64_C(c) ((long long)(c ## LL))               /* signed 64 bit constant */
0058 #  define Q_UINT64_C(c) ((unsigned long long)(c ## ULL))    /* unsigned 64 bit constant */
0059 #endif
0060 typedef long long qint64;           /* 64 bit signed */
0061 typedef unsigned long long quint64; /* 64 bit unsigned */
0062 
0063 typedef qint64 qlonglong;
0064 typedef quint64 qulonglong;
0065 
0066 #if defined(__SIZEOF_INT128__) && !defined(QT_NO_INT128)
0067 #  define QT_SUPPORTS_INT128 __SIZEOF_INT128__
0068 #else
0069 #  undef QT_SUPPORTS_INT128
0070 #endif
0071 
0072 #if defined(QT_SUPPORTS_INT128)
0073 __extension__ typedef __int128_t qint128;
0074 __extension__ typedef __uint128_t quint128;
0075 
0076 // limits:
0077 #  ifdef __cplusplus /* need to avoid c-style-casts in C++ mode */
0078 #    define QT_C_STYLE_CAST(type, x) static_cast<type>(x)
0079 #  else /* but C doesn't have constructor-style casts */
0080 #    define QT_C_STYLE_CAST(type, x) ((type)(x))
0081 #  endif
0082 #  ifndef Q_UINT128_MAX /* allow qcompilerdetection.h/user override */
0083 #    define Q_UINT128_MAX QT_C_STYLE_CAST(quint128, -1)
0084 #  endif
0085 #  define Q_INT128_MAX QT_C_STYLE_CAST(qint128, Q_UINT128_MAX / 2)
0086 #  define Q_INT128_MIN (-Q_INT128_MAX - 1)
0087 
0088 #  ifdef __cplusplus
0089     namespace QtPrivate::NumberLiterals {
0090     namespace detail {
0091         template <quint128 accu, int base>
0092         constexpr quint128 construct() { return accu; }
0093 
0094         template <quint128 accu, int base, char C, char...Cs>
0095         constexpr quint128 construct()
0096         {
0097             if constexpr (C != '\'') { // ignore digit separators
0098                 const int digitValue = '0' <= C && C <= '9' ? C - '0'      :
0099                                        'a' <= C && C <= 'z' ? C - 'a' + 10 :
0100                                        'A' <= C && C <= 'Z' ? C - 'A' + 10 :
0101                                        /* else */        -1 ;
0102                 static_assert(digitValue >= 0 && digitValue < base,
0103                               "Invalid character");
0104                 // accu * base + digitValue <= MAX, but without overflow:
0105                 static_assert(accu <= (Q_UINT128_MAX - digitValue) / base,
0106                               "Overflow occurred");
0107                 return construct<accu * base + digitValue, base, Cs...>();
0108             } else {
0109                 return construct<accu, base, Cs...>();
0110             }
0111         }
0112 
0113         template <char C, char...Cs>
0114         constexpr quint128 parse0xb()
0115         {
0116             constexpr quint128 accu = 0;
0117             if constexpr (C == 'x' || C == 'X')
0118                 return construct<accu, 16,   Cs...>(); // base 16, skip 'x'
0119             else if constexpr (C == 'b' || C == 'B')
0120                 return construct<accu, 2,    Cs...>(); // base 2, skip 'b'
0121             else
0122                 return construct<accu, 8, C, Cs...>(); // base 8, include C
0123         }
0124 
0125         template <char...Cs>
0126         constexpr quint128 parse0()
0127         {
0128             if constexpr (sizeof...(Cs) == 0) // this was just a literal 0
0129                 return 0;
0130             else
0131                 return parse0xb<Cs...>();
0132         }
0133 
0134         template <char C, char...Cs>
0135         constexpr quint128 parse()
0136         {
0137             if constexpr (C == '0')
0138                 return parse0<Cs...>(); // base 2, 8, or 16 (or just a literal 0), skip '0'
0139             else
0140                 return construct<0, 10, C, Cs...>(); // initial accu 0, base 10, include C
0141         }
0142     } // namespace detail
0143     template <char...Cs>
0144     constexpr quint128 operator""_quint128() noexcept
0145     { return QtPrivate::NumberLiterals::detail::parse<Cs...>(); }
0146     template <char...Cs>
0147     constexpr qint128 operator""_qint128() noexcept
0148     { return qint128(QtPrivate::NumberLiterals::detail::parse<Cs...>()); }
0149 
0150     #ifndef Q_UINT128_C // allow qcompilerdetection.h/user override
0151     #  define Q_UINT128_C(c) ([]{ using namespace QtPrivate::NumberLiterals; return c ## _quint128; }())
0152     #endif
0153     #ifndef Q_INT128_C // allow qcompilerdetection.h/user override
0154     #  define Q_INT128_C(c)  ([]{ using namespace QtPrivate::NumberLiterals; return c ## _qint128;  }())
0155     #endif
0156 
0157     } // namespace QtPrivate::NumberLiterals
0158 #  endif // __cplusplus
0159 #endif // QT_SUPPORTS_INT128
0160 
0161 #ifndef __cplusplus
0162 // In C++ mode, we define below using QIntegerForSize template
0163 static_assert(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions");
0164 typedef ptrdiff_t qptrdiff;
0165 typedef ptrdiff_t qsizetype;
0166 typedef ptrdiff_t qintptr;
0167 typedef size_t quintptr;
0168 
0169 #define PRIdQPTRDIFF "td"
0170 #define PRIiQPTRDIFF "ti"
0171 
0172 #define PRIdQSIZETYPE "td"
0173 #define PRIiQSIZETYPE "ti"
0174 
0175 #define PRIdQINTPTR "td"
0176 #define PRIiQINTPTR "ti"
0177 
0178 #define PRIuQUINTPTR "zu"
0179 #define PRIoQUINTPTR "zo"
0180 #define PRIxQUINTPTR "zx"
0181 #define PRIXQUINTPTR "zX"
0182 #endif
0183 
0184 #if defined(QT_COORD_TYPE)
0185 typedef QT_COORD_TYPE qreal;
0186 #else
0187 typedef double qreal;
0188 #endif
0189 
0190 #if defined(__cplusplus)
0191 /*
0192   quintptr are qptrdiff is guaranteed to be the same size as a pointer, i.e.
0193 
0194       sizeof(void *) == sizeof(quintptr)
0195       && sizeof(void *) == sizeof(qptrdiff)
0196 
0197   While size_t and qsizetype are not guaranteed to be the same size as a pointer,
0198   they usually are and we do check for that in qtypes.cpp, just to be sure.
0199 */
0200 template <int> struct QIntegerForSize;
0201 template <>    struct QIntegerForSize<1> { typedef quint8  Unsigned; typedef qint8  Signed; };
0202 template <>    struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
0203 template <>    struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
0204 template <>    struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
0205 #if defined(QT_SUPPORTS_INT128)
0206 template <>    struct QIntegerForSize<16> { typedef quint128 Unsigned; typedef qint128 Signed; };
0207 #endif
0208 template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
0209 typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
0210 typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
0211 typedef QIntegerForSizeof<void *>::Unsigned quintptr;
0212 typedef QIntegerForSizeof<void *>::Signed qptrdiff;
0213 typedef qptrdiff qintptr;
0214 using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
0215 
0216 // These custom definitions are necessary as we're not defining our
0217 // datatypes in terms of the language ones, but in terms of integer
0218 // types that have the sime size. For instance, on a 32-bit platform,
0219 // qptrdiff is int, while ptrdiff_t may be aliased to long; therefore
0220 // using %td to print a qptrdiff would be wrong (and raise -Wformat
0221 // warnings), although both int and long have same bit size on that
0222 // platform.
0223 //
0224 // We know that sizeof(size_t) == sizeof(void *) == sizeof(qptrdiff).
0225 #if SIZE_MAX == 0xffffffffULL
0226 #define PRIuQUINTPTR "u"
0227 #define PRIoQUINTPTR "o"
0228 #define PRIxQUINTPTR "x"
0229 #define PRIXQUINTPTR "X"
0230 
0231 #define PRIdQPTRDIFF "d"
0232 #define PRIiQPTRDIFF "i"
0233 
0234 #define PRIdQINTPTR "d"
0235 #define PRIiQINTPTR "i"
0236 
0237 #define PRIdQSIZETYPE "d"
0238 #define PRIiQSIZETYPE "i"
0239 #elif SIZE_MAX == 0xffffffffffffffffULL
0240 #define PRIuQUINTPTR "llu"
0241 #define PRIoQUINTPTR "llo"
0242 #define PRIxQUINTPTR "llx"
0243 #define PRIXQUINTPTR "llX"
0244 
0245 #define PRIdQPTRDIFF "lld"
0246 #define PRIiQPTRDIFF "lli"
0247 
0248 #define PRIdQINTPTR "lld"
0249 #define PRIiQINTPTR "lli"
0250 
0251 #define PRIdQSIZETYPE "lld"
0252 #define PRIiQSIZETYPE "lli"
0253 #else
0254 #error Unsupported platform (unknown value for SIZE_MAX)
0255 #endif
0256 
0257 // Define a native float16 type
0258 namespace QtPrivate {
0259 #if defined(__STDCPP_FLOAT16_T__)
0260 #  define QFLOAT16_IS_NATIVE        1
0261 using NativeFloat16Type = std::float16_t;
0262 #elif defined(Q_CC_CLANG) && defined(__FLT16_MAX__) && 0
0263 // disabled due to https://github.com/llvm/llvm-project/issues/56963
0264 #  define QFLOAT16_IS_NATIVE        1
0265 using NativeFloat16Type = decltype(__FLT16_MAX__);
0266 #elif defined(Q_CC_GNU_ONLY) && defined(__FLT16_MAX__)
0267 #  define QFLOAT16_IS_NATIVE        1
0268 #  ifdef __ARM_FP16_FORMAT_IEEE
0269 using NativeFloat16Type = __fp16;
0270 #  else
0271 using NativeFloat16Type = _Float16;
0272 #  endif
0273 #else
0274 #  define QFLOAT16_IS_NATIVE        0
0275 using NativeFloat16Type = void;
0276 #endif
0277 } // QtPrivate
0278 
0279 #endif // __cplusplus
0280 
0281 QT_END_NAMESPACE
0282 
0283 #endif // QTYPES_H