platform.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 1997-2016, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. *
  11. * FILE NAME : platform.h
  12. *
  13. * Date Name Description
  14. * 05/13/98 nos Creation (content moved here from ptypes.h).
  15. * 03/02/99 stephen Added AS400 support.
  16. * 03/30/99 stephen Added Linux support.
  17. * 04/13/99 stephen Reworked for autoconf.
  18. ******************************************************************************
  19. */
  20. #ifndef _PLATFORM_H
  21. #define _PLATFORM_H
  22. #include "unicode/uconfig.h"
  23. #include "unicode/uvernum.h"
  24. /**
  25. * \file
  26. * \brief Basic types for the platform.
  27. *
  28. * This file used to be generated by autoconf/configure.
  29. * Starting with ICU 49, platform.h is a normal source file,
  30. * to simplify cross-compiling and working with non-autoconf/make build systems.
  31. *
  32. * When a value in this file does not work on a platform, then please
  33. * try to derive it from the U_PLATFORM value
  34. * (for which we might need a new value constant in rare cases)
  35. * and/or from other macros that are predefined by the compiler
  36. * or defined in standard (POSIX or platform or compiler) headers.
  37. *
  38. * As a temporary workaround, you can add an explicit \#define for some macros
  39. * before it is first tested, or add an equivalent -D macro definition
  40. * to the compiler's command line.
  41. *
  42. * Note: Some compilers provide ways to show the predefined macros.
  43. * For example, with gcc you can compile an empty .c file and have the compiler
  44. * print the predefined macros with
  45. * \code
  46. * gcc -E -dM -x c /dev/null | sort
  47. * \endcode
  48. * (You can provide an actual empty .c file rather than /dev/null.
  49. * <code>-x c++</code> is for C++.)
  50. */
  51. /**
  52. * Define some things so that they can be documented.
  53. * @internal
  54. */
  55. #ifdef U_IN_DOXYGEN
  56. /*
  57. * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented.
  58. * Solution: #define any defines for non @internal API here, so that they are visible in the docs. If you just set PREDEFINED in Doxyfile.in, they won't be documented.
  59. */
  60. /* None for now. */
  61. #endif
  62. /**
  63. * \def U_PLATFORM
  64. * The U_PLATFORM macro defines the platform we're on.
  65. *
  66. * We used to define one different, value-less macro per platform.
  67. * That made it hard to know the set of relevant platforms and macros,
  68. * and hard to deal with variants of platforms.
  69. *
  70. * Starting with ICU 49, we define platforms as numeric macros,
  71. * with ranges of values for related platforms and their variants.
  72. * The U_PLATFORM macro is set to one of these values.
  73. *
  74. * Historical note from the Solaris Wikipedia article:
  75. * AT&T and Sun collaborated on a project to merge the most popular Unix variants
  76. * on the market at that time: BSD, System V, and Xenix.
  77. * This became Unix System V Release 4 (SVR4).
  78. *
  79. * @internal
  80. */
  81. /** Unknown platform. @internal */
  82. #define U_PF_UNKNOWN 0
  83. /** Windows @internal */
  84. #define U_PF_WINDOWS 1000
  85. /** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */
  86. #define U_PF_MINGW 1800
  87. /**
  88. * Cygwin. Windows, calls to cygwin1.dll for Posix functions,
  89. * using MSVC or GNU gcc and binutils.
  90. * @internal
  91. */
  92. #define U_PF_CYGWIN 1900
  93. /* Reserve 2000 for U_PF_UNIX? */
  94. /** HP-UX is based on UNIX System V. @internal */
  95. #define U_PF_HPUX 2100
  96. /** Solaris is a Unix operating system based on SVR4. @internal */
  97. #define U_PF_SOLARIS 2600
  98. /** BSD is a UNIX operating system derivative. @internal */
  99. #define U_PF_BSD 3000
  100. /** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */
  101. #define U_PF_AIX 3100
  102. /** IRIX is based on UNIX System V with BSD extensions. @internal */
  103. #define U_PF_IRIX 3200
  104. /**
  105. * Darwin is a POSIX-compliant operating system, composed of code developed by Apple,
  106. * as well as code derived from NeXTSTEP, BSD, and other projects,
  107. * built around the Mach kernel.
  108. * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based.
  109. * (Original description modified from WikiPedia.)
  110. * @internal
  111. */
  112. #define U_PF_DARWIN 3500
  113. /** iPhone OS (iOS) is a derivative of Mac OS X. @internal */
  114. #define U_PF_IPHONE 3550
  115. /** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */
  116. #define U_PF_QNX 3700
  117. /** Linux is a Unix-like operating system. @internal */
  118. #define U_PF_LINUX 4000
  119. /**
  120. * Native Client is pretty close to Linux.
  121. * See https://developer.chrome.com/native-client and
  122. * http://www.chromium.org/nativeclient
  123. * @internal
  124. */
  125. #define U_PF_BROWSER_NATIVE_CLIENT 4020
  126. /** Android is based on Linux. @internal */
  127. #define U_PF_ANDROID 4050
  128. /** Haiku is a POSIX-ish platform. @internal */
  129. #define U_PF_HAIKU 4080
  130. /** Fuchsia is a POSIX-ish platform. @internal */
  131. #define U_PF_FUCHSIA 4100
  132. /* Maximum value for Linux-based platform is 4499 */
  133. /**
  134. * Emscripten is a C++ transpiler for the Web that can target asm.js or
  135. * WebAssembly. It provides some POSIX-compatible wrappers and stubs and
  136. * some Linux-like functionality, but is not fully compatible with
  137. * either.
  138. * @internal
  139. */
  140. #define U_PF_EMSCRIPTEN 5010
  141. /** z/OS is the successor to OS/390 which was the successor to MVS. @internal */
  142. #define U_PF_OS390 9000
  143. /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */
  144. #define U_PF_OS400 9400
  145. #ifdef U_PLATFORM
  146. /* Use the predefined value. */
  147. #elif defined(__MINGW32__)
  148. # define U_PLATFORM U_PF_MINGW
  149. #elif defined(__CYGWIN__)
  150. # define U_PLATFORM U_PF_CYGWIN
  151. /* Cygwin uchar.h doesn't exist until Cygwin 3.5. */
  152. # include <cygwin/version.h>
  153. #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
  154. # define U_PLATFORM U_PF_WINDOWS
  155. #elif defined(__ANDROID__)
  156. # define U_PLATFORM U_PF_ANDROID
  157. /* Android wchar_t support depends on the API level. */
  158. # include <android/api-level.h>
  159. #elif defined(__pnacl__) || defined(__native_client__)
  160. # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
  161. #elif defined(__Fuchsia__)
  162. # define U_PLATFORM U_PF_FUCHSIA
  163. #elif defined(linux) || defined(__linux__) || defined(__linux)
  164. # define U_PLATFORM U_PF_LINUX
  165. #elif defined(__APPLE__) && defined(__MACH__)
  166. # include <TargetConditionals.h>
  167. # if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && (defined(TARGET_OS_MACCATALYST) && !TARGET_OS_MACCATALYST) /* variant of TARGET_OS_MAC */
  168. # define U_PLATFORM U_PF_IPHONE
  169. # else
  170. # define U_PLATFORM U_PF_DARWIN
  171. # endif
  172. #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
  173. # if defined(__FreeBSD__)
  174. # include <sys/endian.h>
  175. # endif
  176. # define U_PLATFORM U_PF_BSD
  177. #elif defined(sun) || defined(__sun)
  178. /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
  179. # define U_PLATFORM U_PF_SOLARIS
  180. # if defined(__GNUC__)
  181. /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
  182. * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
  183. * is included which does not include this header file.
  184. */
  185. # error #include <sys/isa_defs.h>
  186. # endif
  187. #elif defined(_AIX) || defined(__TOS_AIX__)
  188. # define U_PLATFORM U_PF_AIX
  189. #elif defined(_hpux) || defined(hpux) || defined(__hpux)
  190. # define U_PLATFORM U_PF_HPUX
  191. #elif defined(sgi) || defined(__sgi)
  192. # define U_PLATFORM U_PF_IRIX
  193. #elif defined(__QNX__) || defined(__QNXNTO__)
  194. # define U_PLATFORM U_PF_QNX
  195. #elif defined(__TOS_MVS__)
  196. # define U_PLATFORM U_PF_OS390
  197. #elif defined(__OS400__) || defined(__TOS_OS400__)
  198. # define U_PLATFORM U_PF_OS400
  199. #elif defined(__HAIKU__)
  200. # define U_PLATFORM U_PF_HAIKU
  201. #elif defined(__EMSCRIPTEN__)
  202. # define U_PLATFORM U_PF_EMSCRIPTEN
  203. #else
  204. # define U_PLATFORM U_PF_UNKNOWN
  205. #endif
  206. /**
  207. * \def U_REAL_MSVC
  208. * Defined if the compiler is the real MSVC compiler (and not something like
  209. * Clang setting _MSC_VER in order to compile Windows code that requires it).
  210. * Otherwise undefined.
  211. * @internal
  212. */
  213. #if (defined(_MSC_VER) && !(defined(__clang__) && __clang__)) || defined(U_IN_DOXYGEN)
  214. # define U_REAL_MSVC
  215. #endif
  216. /**
  217. * \def CYGWINMSVC
  218. * Defined if this is Windows with Cygwin, but using MSVC rather than gcc.
  219. * Otherwise undefined.
  220. * @internal
  221. */
  222. /* Commented out because this is already set in mh-cygwin-msvc
  223. #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
  224. # define CYGWINMSVC
  225. #endif
  226. */
  227. #ifdef U_IN_DOXYGEN
  228. # define CYGWINMSVC
  229. #endif
  230. /**
  231. * \def U_PLATFORM_USES_ONLY_WIN32_API
  232. * Defines whether the platform uses only the Win32 API.
  233. * Set to 1 for Windows/MSVC, ClangCL and MinGW but not Cygwin.
  234. * @internal
  235. */
  236. #ifdef U_PLATFORM_USES_ONLY_WIN32_API
  237. /* Use the predefined value. */
  238. #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
  239. # define U_PLATFORM_USES_ONLY_WIN32_API 1
  240. #else
  241. /* Cygwin implements POSIX. */
  242. # define U_PLATFORM_USES_ONLY_WIN32_API 0
  243. #endif
  244. /**
  245. * \def U_PLATFORM_HAS_WIN32_API
  246. * Defines whether the Win32 API is available on the platform.
  247. * Set to 1 for Windows/MSVC, ClangCL, MinGW and Cygwin.
  248. * @internal
  249. */
  250. #ifdef U_PLATFORM_HAS_WIN32_API
  251. /* Use the predefined value. */
  252. #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  253. # define U_PLATFORM_HAS_WIN32_API 1
  254. #else
  255. # define U_PLATFORM_HAS_WIN32_API 0
  256. #endif
  257. /**
  258. * \def U_PLATFORM_HAS_WINUWP_API
  259. * Defines whether target is intended for Universal Windows Platform API
  260. * Set to 1 for Windows10 Release Solution Configuration
  261. * @internal
  262. */
  263. #ifdef U_PLATFORM_HAS_WINUWP_API
  264. /* Use the predefined value. */
  265. #else
  266. # define U_PLATFORM_HAS_WINUWP_API 0
  267. #endif
  268. /**
  269. * \def U_PLATFORM_IMPLEMENTS_POSIX
  270. * Defines whether the platform implements (most of) the POSIX API.
  271. * Set to 1 for Cygwin and most other platforms.
  272. * @internal
  273. */
  274. #ifdef U_PLATFORM_IMPLEMENTS_POSIX
  275. /* Use the predefined value. */
  276. #elif U_PLATFORM_USES_ONLY_WIN32_API
  277. # define U_PLATFORM_IMPLEMENTS_POSIX 0
  278. #else
  279. # define U_PLATFORM_IMPLEMENTS_POSIX 1
  280. #endif
  281. /**
  282. * \def U_PLATFORM_IS_LINUX_BASED
  283. * Defines whether the platform is Linux or one of its derivatives.
  284. * @internal
  285. */
  286. #ifdef U_PLATFORM_IS_LINUX_BASED
  287. /* Use the predefined value. */
  288. #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
  289. # define U_PLATFORM_IS_LINUX_BASED 1
  290. #else
  291. # define U_PLATFORM_IS_LINUX_BASED 0
  292. #endif
  293. /**
  294. * \def U_PLATFORM_IS_DARWIN_BASED
  295. * Defines whether the platform is Darwin or one of its derivatives.
  296. * @internal
  297. */
  298. #ifdef U_PLATFORM_IS_DARWIN_BASED
  299. /* Use the predefined value. */
  300. #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
  301. # define U_PLATFORM_IS_DARWIN_BASED 1
  302. #else
  303. # define U_PLATFORM_IS_DARWIN_BASED 0
  304. #endif
  305. /*===========================================================================*/
  306. /** @{ Compiler and environment features */
  307. /*===========================================================================*/
  308. /**
  309. * \def U_GCC_MAJOR_MINOR
  310. * Indicates whether the compiler is gcc (test for != 0),
  311. * and if so, contains its major (times 100) and minor version numbers.
  312. * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0.
  313. *
  314. * For example, for testing for whether we have gcc, and whether it's 4.6 or higher,
  315. * use "#if U_GCC_MAJOR_MINOR >= 406".
  316. * @internal
  317. */
  318. #ifdef __GNUC__
  319. # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
  320. #else
  321. # define U_GCC_MAJOR_MINOR 0
  322. #endif
  323. /**
  324. * \def U_IS_BIG_ENDIAN
  325. * Determines the endianness of the platform.
  326. * @internal
  327. */
  328. #ifdef U_IS_BIG_ENDIAN
  329. /* Use the predefined value. */
  330. #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
  331. # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
  332. #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
  333. /* gcc */
  334. # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  335. #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
  336. # define U_IS_BIG_ENDIAN 1
  337. #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
  338. # define U_IS_BIG_ENDIAN 0
  339. #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
  340. /* These platforms do not appear to predefine any endianness macros. */
  341. # define U_IS_BIG_ENDIAN 1
  342. #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
  343. /* HPPA do not appear to predefine any endianness macros. */
  344. # define U_IS_BIG_ENDIAN 1
  345. #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
  346. /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
  347. # define U_IS_BIG_ENDIAN 1
  348. #else
  349. # define U_IS_BIG_ENDIAN 0
  350. #endif
  351. /**
  352. * \def U_HAVE_PLACEMENT_NEW
  353. * Determines whether to override placement new and delete for STL.
  354. * @stable ICU 2.6
  355. */
  356. #ifdef U_HAVE_PLACEMENT_NEW
  357. /* Use the predefined value. */
  358. #elif defined(__BORLANDC__)
  359. # define U_HAVE_PLACEMENT_NEW 0
  360. #else
  361. # define U_HAVE_PLACEMENT_NEW 1
  362. #endif
  363. /**
  364. * \def U_HAVE_DEBUG_LOCATION_NEW
  365. * Define this to define the MFC debug version of the operator new.
  366. *
  367. * @stable ICU 3.4
  368. */
  369. #ifdef U_HAVE_DEBUG_LOCATION_NEW
  370. /* Use the predefined value. */
  371. #elif defined(_MSC_VER)
  372. # define U_HAVE_DEBUG_LOCATION_NEW 1
  373. #else
  374. # define U_HAVE_DEBUG_LOCATION_NEW 0
  375. #endif
  376. /* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */
  377. #ifdef __has_attribute
  378. # define UPRV_HAS_ATTRIBUTE(x) __has_attribute(x)
  379. #else
  380. # define UPRV_HAS_ATTRIBUTE(x) 0
  381. #endif
  382. #ifdef __has_cpp_attribute
  383. # define UPRV_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
  384. #else
  385. # define UPRV_HAS_CPP_ATTRIBUTE(x) 0
  386. #endif
  387. #ifdef __has_declspec_attribute
  388. # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) __has_declspec_attribute(x)
  389. #else
  390. # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) 0
  391. #endif
  392. #ifdef __has_builtin
  393. # define UPRV_HAS_BUILTIN(x) __has_builtin(x)
  394. #else
  395. # define UPRV_HAS_BUILTIN(x) 0
  396. #endif
  397. #ifdef __has_feature
  398. # define UPRV_HAS_FEATURE(x) __has_feature(x)
  399. #else
  400. # define UPRV_HAS_FEATURE(x) 0
  401. #endif
  402. #ifdef __has_extension
  403. # define UPRV_HAS_EXTENSION(x) __has_extension(x)
  404. #else
  405. # define UPRV_HAS_EXTENSION(x) 0
  406. #endif
  407. #ifdef __has_warning
  408. # define UPRV_HAS_WARNING(x) __has_warning(x)
  409. #else
  410. # define UPRV_HAS_WARNING(x) 0
  411. #endif
  412. #if defined(__clang__)
  413. #define UPRV_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
  414. #else
  415. #define UPRV_NO_SANITIZE_UNDEFINED
  416. #endif
  417. /**
  418. * \def U_MALLOC_ATTR
  419. * Attribute to mark functions as malloc-like
  420. * @internal
  421. */
  422. #if defined(__GNUC__) && __GNUC__>=3
  423. # define U_MALLOC_ATTR __attribute__ ((__malloc__))
  424. #else
  425. # define U_MALLOC_ATTR
  426. #endif
  427. /**
  428. * \def U_ALLOC_SIZE_ATTR
  429. * Attribute to specify the size of the allocated buffer for malloc-like functions
  430. * @internal
  431. */
  432. #if (defined(__GNUC__) && \
  433. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
  434. UPRV_HAS_ATTRIBUTE(alloc_size)
  435. # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
  436. # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
  437. #else
  438. # define U_ALLOC_SIZE_ATTR(X)
  439. # define U_ALLOC_SIZE_ATTR2(X,Y)
  440. #endif
  441. /**
  442. * \def U_CPLUSPLUS_VERSION
  443. * 0 if no C++; 1, 11, 14, ... if C++.
  444. * Support for specific features cannot always be determined by the C++ version alone.
  445. * @internal
  446. */
  447. #ifdef U_CPLUSPLUS_VERSION
  448. # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
  449. # undef U_CPLUSPLUS_VERSION
  450. # define U_CPLUSPLUS_VERSION 0
  451. # endif
  452. /* Otherwise use the predefined value. */
  453. #elif !defined(__cplusplus)
  454. # define U_CPLUSPLUS_VERSION 0
  455. #elif __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
  456. # define U_CPLUSPLUS_VERSION 17
  457. #elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
  458. # define U_CPLUSPLUS_VERSION 14
  459. #elif __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
  460. # define U_CPLUSPLUS_VERSION 11
  461. #else
  462. // C++98 or C++03
  463. # define U_CPLUSPLUS_VERSION 1
  464. #endif
  465. /**
  466. * \def U_FALLTHROUGH
  467. * Annotate intentional fall-through between switch labels.
  468. * http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
  469. * @internal
  470. */
  471. #ifndef __cplusplus
  472. // Not for C.
  473. #elif defined(U_FALLTHROUGH)
  474. // Use the predefined value.
  475. #elif defined(__clang__)
  476. // Test for compiler vs. feature separately.
  477. // Other compilers might choke on the feature test.
  478. # if UPRV_HAS_CPP_ATTRIBUTE(clang::fallthrough) || \
  479. (UPRV_HAS_FEATURE(cxx_attributes) && \
  480. UPRV_HAS_WARNING("-Wimplicit-fallthrough"))
  481. # define U_FALLTHROUGH [[clang::fallthrough]]
  482. # endif
  483. #elif defined(__GNUC__) && (__GNUC__ >= 7)
  484. # define U_FALLTHROUGH __attribute__((fallthrough))
  485. #endif
  486. #ifndef U_FALLTHROUGH
  487. # define U_FALLTHROUGH
  488. #endif
  489. /** @} */
  490. /*===========================================================================*/
  491. /** @{ Character data types */
  492. /*===========================================================================*/
  493. /**
  494. * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform.
  495. * @stable ICU 2.0
  496. */
  497. #define U_ASCII_FAMILY 0
  498. /**
  499. * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform.
  500. * @stable ICU 2.0
  501. */
  502. #define U_EBCDIC_FAMILY 1
  503. /**
  504. * \def U_CHARSET_FAMILY
  505. *
  506. * <p>These definitions allow to specify the encoding of text
  507. * in the char data type as defined by the platform and the compiler.
  508. * It is enough to determine the code point values of "invariant characters",
  509. * which are the ones shared by all encodings that are in use
  510. * on a given platform.</p>
  511. *
  512. * <p>Those "invariant characters" should be all the uppercase and lowercase
  513. * latin letters, the digits, the space, and "basic punctuation".
  514. * Also, '\\n', '\\r', '\\t' should be available.</p>
  515. *
  516. * <p>The list of "invariant characters" is:<br>
  517. * \code
  518. * A-Z a-z 0-9 SPACE " % &amp; ' ( ) * + , - . / : ; < = > ? _
  519. * \endcode
  520. * <br>
  521. * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p>
  522. *
  523. * <p>This matches the IBM Syntactic Character Set (CS 640).</p>
  524. *
  525. * <p>In other words, all the graphic characters in 7-bit ASCII should
  526. * be safely accessible except the following:</p>
  527. *
  528. * \code
  529. * '\' <backslash>
  530. * '[' <left bracket>
  531. * ']' <right bracket>
  532. * '{' <left brace>
  533. * '}' <right brace>
  534. * '^' <circumflex>
  535. * '~' <tilde>
  536. * '!' <exclamation mark>
  537. * '#' <number sign>
  538. * '|' <vertical line>
  539. * '$' <dollar sign>
  540. * '@' <commercial at>
  541. * '`' <grave accent>
  542. * \endcode
  543. * @stable ICU 2.0
  544. */
  545. #ifdef U_CHARSET_FAMILY
  546. /* Use the predefined value. */
  547. #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
  548. # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
  549. #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
  550. # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
  551. #else
  552. # define U_CHARSET_FAMILY U_ASCII_FAMILY
  553. #endif
  554. /**
  555. * \def U_CHARSET_IS_UTF8
  556. *
  557. * Hardcode the default charset to UTF-8.
  558. *
  559. * If this is set to 1, then
  560. * - ICU will assume that all non-invariant char*, StringPiece, std::string etc.
  561. * contain UTF-8 text, regardless of what the system API uses
  562. * - some ICU code will use fast functions like u_strFromUTF8()
  563. * rather than the more general and more heavy-weight conversion API (ucnv.h)
  564. * - ucnv_getDefaultName() always returns "UTF-8"
  565. * - ucnv_setDefaultName() is disabled and will not change the default charset
  566. * - static builds of ICU are smaller
  567. * - more functionality is available with the UCONFIG_NO_CONVERSION build-time
  568. * configuration option (see unicode/uconfig.h)
  569. * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable
  570. *
  571. * @stable ICU 4.2
  572. * @see UCONFIG_NO_CONVERSION
  573. */
  574. #ifdef U_CHARSET_IS_UTF8
  575. /* Use the predefined value. */
  576. #elif U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED || \
  577. U_PLATFORM == U_PF_EMSCRIPTEN
  578. # define U_CHARSET_IS_UTF8 1
  579. #else
  580. # define U_CHARSET_IS_UTF8 0
  581. #endif
  582. /** @} */
  583. /*===========================================================================*/
  584. /** @{ Information about wchar support */
  585. /*===========================================================================*/
  586. /**
  587. * \def U_HAVE_WCHAR_H
  588. * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
  589. *
  590. * @stable ICU 2.0
  591. */
  592. #ifdef U_HAVE_WCHAR_H
  593. /* Use the predefined value. */
  594. #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
  595. /*
  596. * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
  597. * The type and header existed, but the library functions did not work as expected.
  598. * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
  599. */
  600. # define U_HAVE_WCHAR_H 0
  601. #else
  602. # define U_HAVE_WCHAR_H 1
  603. #endif
  604. /**
  605. * \def U_SIZEOF_WCHAR_T
  606. * U_SIZEOF_WCHAR_T==sizeof(wchar_t)
  607. *
  608. * @stable ICU 2.0
  609. */
  610. #ifdef U_SIZEOF_WCHAR_T
  611. /* Use the predefined value. */
  612. #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
  613. /*
  614. * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
  615. * Newer Mac OS X has size 4.
  616. */
  617. # define U_SIZEOF_WCHAR_T 1
  618. #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
  619. # define U_SIZEOF_WCHAR_T 2
  620. #elif U_PLATFORM == U_PF_AIX
  621. /*
  622. * AIX 6.1 information, section "Wide character data representation":
  623. * "... the wchar_t datatype is 32-bit in the 64-bit environment and
  624. * 16-bit in the 32-bit environment."
  625. * and
  626. * "All locales use Unicode for their wide character code values (process code),
  627. * except the IBM-eucTW codeset."
  628. */
  629. # ifdef __64BIT__
  630. # define U_SIZEOF_WCHAR_T 4
  631. # else
  632. # define U_SIZEOF_WCHAR_T 2
  633. # endif
  634. #elif U_PLATFORM == U_PF_OS390
  635. /*
  636. * z/OS V1R11 information center, section "LP64 | ILP32":
  637. * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
  638. * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
  639. */
  640. # ifdef _LP64
  641. # define U_SIZEOF_WCHAR_T 4
  642. # else
  643. # define U_SIZEOF_WCHAR_T 2
  644. # endif
  645. #elif U_PLATFORM == U_PF_OS400
  646. # if defined(__UTF32__)
  647. /*
  648. * LOCALETYPE(*LOCALEUTF) is specified.
  649. * Wide-character strings are in UTF-32,
  650. * narrow-character strings are in UTF-8.
  651. */
  652. # define U_SIZEOF_WCHAR_T 4
  653. # elif defined(__UCS2__)
  654. /*
  655. * LOCALETYPE(*LOCALEUCS2) is specified.
  656. * Wide-character strings are in UCS-2,
  657. * narrow-character strings are in EBCDIC.
  658. */
  659. # define U_SIZEOF_WCHAR_T 2
  660. # else
  661. /*
  662. * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
  663. * Wide-character strings are in 16-bit EBCDIC,
  664. * narrow-character strings are in EBCDIC.
  665. */
  666. # define U_SIZEOF_WCHAR_T 2
  667. # endif
  668. #else
  669. # define U_SIZEOF_WCHAR_T 4
  670. #endif
  671. #ifndef U_HAVE_WCSCPY
  672. #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
  673. #endif
  674. /** @} */
  675. /**
  676. * \def U_HAVE_CHAR16_T
  677. * Defines whether the char16_t type is available for UTF-16
  678. * and u"abc" UTF-16 string literals are supported.
  679. * This is a new standard type and standard string literal syntax in C++11
  680. * but has been available in some compilers before.
  681. * @internal
  682. */
  683. #ifdef U_HAVE_CHAR16_T
  684. /* Use the predefined value. */
  685. #else
  686. /*
  687. * Notes:
  688. * C++11 and C11 require support for UTF-16 literals
  689. * Doesn't work on Mac C11 (see workaround in ptypes.h)
  690. * or Cygwin less than 3.5.
  691. */
  692. # if defined(__cplusplus)
  693. # define U_HAVE_CHAR16_T 1
  694. # elif U_PLATFORM_IS_DARWIN_BASED || (U_PLATFORM == U_PF_CYGWIN && CYGWIN_VERSION_DLL_MAJOR < 3005)
  695. # define U_HAVE_CHAR16_T 0
  696. # else
  697. // conformant C11
  698. # define U_HAVE_CHAR16_T 1
  699. # endif
  700. #endif
  701. /**
  702. * @{
  703. * \def U_DECLARE_UTF16
  704. * Do not use this macro because it is not defined on all platforms.
  705. * In C++, use std::u16string_view literals, see the UNICODE_STRING docs.
  706. * In C, use u"UTF-16 literals".
  707. * See also the public U_STRING_DECL macro.
  708. * @internal
  709. */
  710. #ifdef U_DECLARE_UTF16
  711. /* Use the predefined value. */
  712. #elif U_HAVE_CHAR16_T \
  713. || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
  714. || (defined(__HP_aCC) && __HP_aCC >= 035000) \
  715. || (defined(__HP_cc) && __HP_cc >= 111106) \
  716. || (defined(U_IN_DOXYGEN))
  717. # define U_DECLARE_UTF16(string) u ## string
  718. #elif U_SIZEOF_WCHAR_T == 2 \
  719. && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
  720. # define U_DECLARE_UTF16(string) L ## string
  721. #else
  722. /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
  723. #endif
  724. /** @} */
  725. /*===========================================================================*/
  726. /** @{ Symbol import-export control */
  727. /*===========================================================================*/
  728. #ifdef U_EXPORT
  729. /* Use the predefined value. */
  730. #elif defined(U_STATIC_IMPLEMENTATION)
  731. # define U_EXPORT
  732. #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
  733. UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
  734. # define U_EXPORT __declspec(dllexport)
  735. #elif defined(__GNUC__) || defined(__open_xl__)
  736. # define U_EXPORT __attribute__((visibility("default")))
  737. #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
  738. || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
  739. # define U_EXPORT __global
  740. /*#elif defined(__HP_aCC) || defined(__HP_cc)
  741. # define U_EXPORT __declspec(dllexport)*/
  742. #else
  743. # define U_EXPORT
  744. #endif
  745. /* U_CALLCONV is related to U_EXPORT2 */
  746. #ifdef U_EXPORT2
  747. /* Use the predefined value. */
  748. #elif defined(_MSC_VER)
  749. # define U_EXPORT2 __cdecl
  750. #else
  751. # define U_EXPORT2
  752. #endif
  753. #ifdef U_IMPORT
  754. /* Use the predefined value. */
  755. #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
  756. UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
  757. /* Windows needs to export/import data. */
  758. # define U_IMPORT __declspec(dllimport)
  759. #else
  760. # define U_IMPORT
  761. #endif
  762. /**
  763. * \def U_HIDDEN
  764. * This is used to mark internal structs declared within external classes,
  765. * to prevent the internal structs from having the same visibility as the
  766. * class within which they are declared.
  767. * @internal
  768. */
  769. #ifdef U_HIDDEN
  770. /* Use the predefined value. */
  771. #elif defined(__GNUC__) || defined(__open_xl__)
  772. # define U_HIDDEN __attribute__((visibility("hidden")))
  773. #else
  774. # define U_HIDDEN
  775. #endif
  776. /**
  777. * \def U_CALLCONV
  778. * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary
  779. * in callback function typedefs to make sure that the calling convention
  780. * is compatible.
  781. *
  782. * This is only used for non-ICU-API functions.
  783. * When a function is a public ICU API,
  784. * you must use the U_CAPI and U_EXPORT2 qualifiers.
  785. *
  786. * Please note, you need to use U_CALLCONV after the *.
  787. *
  788. * NO : "static const char U_CALLCONV *func( . . . )"
  789. * YES: "static const char* U_CALLCONV func( . . . )"
  790. *
  791. * @stable ICU 2.0
  792. */
  793. #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
  794. # define U_CALLCONV __cdecl
  795. #else
  796. # define U_CALLCONV U_EXPORT2
  797. #endif
  798. /**
  799. * \def U_CALLCONV_FPTR
  800. * Similar to U_CALLCONV, but only used on function pointers.
  801. * @internal
  802. */
  803. #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
  804. # define U_CALLCONV_FPTR U_CALLCONV
  805. #else
  806. # define U_CALLCONV_FPTR
  807. #endif
  808. /** @} */
  809. #endif // _PLATFORM_H