Differential D3094 Diff 14018 ps/trunk/libraries/source/spidermonkey/include-win32-debug/mozilla/Char16.h
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/libraries/source/spidermonkey/include-win32-debug/mozilla/Char16.h
Show All 11 Lines | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
/* | /* | ||||
* C++11 introduces a char16_t type and support for UTF-16 string and character | * C++11 introduces a char16_t type and support for UTF-16 string and character | ||||
* literals. C++11's char16_t is a distinct builtin type. Technically, char16_t | * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t | ||||
* is a 16-bit code unit of a Unicode code point, not a "character". | * is a 16-bit code unit of a Unicode code point, not a "character". | ||||
*/ | */ | ||||
#if defined(_MSC_VER) && _MSC_VER < 1900 | |||||
/* | |||||
* C++11 says char16_t is a distinct builtin type, but Windows's yvals.h | |||||
* typedefs char16_t as an unsigned short prior to MSVC 2015, which | |||||
* implemented C++11's distinct char16_t type. We would like to alias | |||||
* char16_t to Windows's 16-bit wchar_t so we can declare UTF-16 literals as | |||||
* constant expressions (and pass char16_t pointers to Windows APIs). We | |||||
* #define _CHAR16T here in order to prevent yvals.h from overriding our | |||||
* char16_t typedefs, which we set to wchar_t for C++ code. | |||||
* | |||||
* In addition, #defining _CHAR16T will prevent yvals.h from defining a | |||||
* char32_t type, so we have to undo that damage here and provide our own, | |||||
* which is identical to the yvals.h type. | |||||
*/ | |||||
# define MOZ_UTF16_HELPER(s) L##s | |||||
# define _CHAR16T | |||||
typedef wchar_t char16_t; | |||||
typedef unsigned int char32_t; | |||||
#else | |||||
/* C++11 has a builtin char16_t type. */ | |||||
# define MOZ_UTF16_HELPER(s) u##s | |||||
/** | |||||
* This macro is used to distinguish when char16_t would be a distinct | |||||
* typedef from wchar_t. | |||||
*/ | |||||
# define MOZ_CHAR16_IS_NOT_WCHAR | |||||
# ifdef WIN32 | #ifdef WIN32 | ||||
# define MOZ_USE_CHAR16_WRAPPER | # define MOZ_USE_CHAR16_WRAPPER | ||||
# endif | |||||
#endif | |||||
#ifdef MOZ_USE_CHAR16_WRAPPER | |||||
# include <cstdint> | # include <cstdint> | ||||
/** | /** | ||||
* Win32 API extensively uses wchar_t, which is represented by a separated | * Win32 API extensively uses wchar_t, which is represented by a separated | ||||
* builtin type than char16_t per spec. It's not the case for MSVC prior to | * builtin type than char16_t per spec. It's not the case for MSVC prior to | ||||
* MSVC 2015, but other compilers follow the spec. We want to mix wchar_t and | * MSVC 2015, but other compilers follow the spec. We want to mix wchar_t and | ||||
* char16_t on Windows builds. This class is supposed to make it easier. It | * char16_t on Windows builds. This class is supposed to make it easier. It | ||||
* stores char16_t const pointer, but provides implicit casts for wchar_t as | * stores char16_t const pointer, but provides implicit casts for wchar_t as | ||||
* well. On other platforms, we simply use | * well. On other platforms, we simply use | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
#else | #else | ||||
typedef const char16_t* char16ptr_t; | typedef const char16_t* char16ptr_t; | ||||
#endif | #endif | ||||
/* | |||||
* Macro arguments used in concatenation or stringification won't be expanded. | |||||
* Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to | |||||
* expand |FOO| before doing whatever |MOZ_UTF16| needs to do to it) a helper | |||||
* macro, |MOZ_UTF16_HELPER| needs to be inserted in between to allow the macro | |||||
* argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the | |||||
* CPP manual for a more accurate and precise explanation. | |||||
*/ | |||||
#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) | |||||
static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); | static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); | ||||
static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); | static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); | ||||
static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); | static_assert(sizeof(u'A') == 2, "Is unicode char literal 16 bits?"); | ||||
static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); | static_assert(sizeof(u""[0]) == 2, "Is unicode string char 16 bits?"); | ||||
#endif | #endif | ||||
#endif /* mozilla_Char16_h */ | #endif /* mozilla_Char16_h */ |
Wildfire Games · Phabricator