PageRenderTime 34ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jstypes.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 490 lines | 206 code | 62 blank | 222 comment | 41 complexity | 87bbce5663fb09b7064fcc52fb8f0f66 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is Mozilla Communicator client code, released
  16. * March 31, 1998.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * Netscape Communications Corporation.
  20. * Portions created by the Initial Developer are Copyright (C) 1998
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. * IBM Corp.
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. /*
  40. ** File: jstypes.h
  41. ** Description: Definitions of NSPR's basic types
  42. **
  43. ** Prototypes and macros used to make up for deficiencies in ANSI environments
  44. ** that we have found.
  45. **
  46. ** Since we do not wrap <stdlib.h> and all the other standard headers, authors
  47. ** of portable code will not know in general that they need these definitions.
  48. ** Instead of requiring these authors to find the dependent uses in their code
  49. ** and take the following steps only in those C files, we take steps once here
  50. ** for all C files.
  51. **/
  52. #ifndef jstypes_h___
  53. #define jstypes_h___
  54. #include <stddef.h>
  55. /***********************************************************************
  56. ** MACROS: JS_EXTERN_API
  57. ** JS_EXPORT_API
  58. ** DESCRIPTION:
  59. ** These are only for externally visible routines and globals. For
  60. ** internal routines, just use "extern" for type checking and that
  61. ** will not export internal cross-file or forward-declared symbols.
  62. ** Define a macro for declaring procedures return types. We use this to
  63. ** deal with windoze specific type hackery for DLL definitions. Use
  64. ** JS_EXTERN_API when the prototype for the method is declared. Use
  65. ** JS_EXPORT_API for the implementation of the method.
  66. **
  67. ** Example:
  68. ** in dowhim.h
  69. ** JS_EXTERN_API( void ) DoWhatIMean( void );
  70. ** in dowhim.c
  71. ** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; }
  72. **
  73. **
  74. ***********************************************************************/
  75. #ifdef WIN32
  76. /* These also work for __MWERKS__ */
  77. # define JS_EXTERN_API(__type) extern __declspec(dllexport) __type
  78. # define JS_EXPORT_API(__type) __declspec(dllexport) __type
  79. # define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
  80. # define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
  81. #elif defined(XP_OS2) && defined(__declspec)
  82. # define JS_EXTERN_API(__type) extern __declspec(dllexport) __type
  83. # define JS_EXPORT_API(__type) __declspec(dllexport) __type
  84. # define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
  85. # define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
  86. #else /* Unix */
  87. # ifdef HAVE_VISIBILITY_ATTRIBUTE
  88. # define JS_EXTERNAL_VIS __attribute__((visibility ("default")))
  89. # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  90. # define JS_EXTERNAL_VIS __global
  91. # else
  92. # define JS_EXTERNAL_VIS
  93. # endif
  94. # define JS_EXTERN_API(__type) extern JS_EXTERNAL_VIS __type
  95. # define JS_EXPORT_API(__type) JS_EXTERNAL_VIS __type
  96. # define JS_EXTERN_DATA(__type) extern JS_EXTERNAL_VIS __type
  97. # define JS_EXPORT_DATA(__type) JS_EXTERNAL_VIS __type
  98. #endif
  99. #ifdef _WIN32
  100. # if defined(__MWERKS__) || defined(__GNUC__)
  101. # define JS_IMPORT_API(__x) __x
  102. # else
  103. # define JS_IMPORT_API(__x) __declspec(dllimport) __x
  104. # endif
  105. #elif defined(XP_OS2) && defined(__declspec)
  106. # define JS_IMPORT_API(__x) __declspec(dllimport) __x
  107. #else
  108. # define JS_IMPORT_API(__x) JS_EXPORT_API (__x)
  109. #endif
  110. #if defined(_WIN32) && !defined(__MWERKS__)
  111. # define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
  112. #elif defined(XP_OS2) && defined(__declspec)
  113. # define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
  114. #else
  115. # define JS_IMPORT_DATA(__x) JS_EXPORT_DATA (__x)
  116. #endif
  117. /*
  118. * The linkage of JS API functions differs depending on whether the file is
  119. * used within the JS library or not. Any source file within the JS
  120. * interpreter should define EXPORT_JS_API whereas any client of the library
  121. * should not. STATIC_JS_API is used to build JS as a static library.
  122. */
  123. #if defined(STATIC_JS_API)
  124. # define JS_PUBLIC_API(t) t
  125. # define JS_PUBLIC_DATA(t) t
  126. #elif defined(EXPORT_JS_API)
  127. # define JS_PUBLIC_API(t) JS_EXPORT_API(t)
  128. # define JS_PUBLIC_DATA(t) JS_EXPORT_DATA(t)
  129. #else
  130. # define JS_PUBLIC_API(t) JS_IMPORT_API(t)
  131. # define JS_PUBLIC_DATA(t) JS_IMPORT_DATA(t)
  132. #endif
  133. #define JS_FRIEND_API(t) JS_PUBLIC_API(t)
  134. #define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t)
  135. #if defined(_MSC_VER) && defined(_M_IX86)
  136. #define JS_FASTCALL __fastcall
  137. #elif defined(__GNUC__) && defined(__i386__) && \
  138. ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  139. #define JS_FASTCALL __attribute__((fastcall))
  140. #else
  141. #define JS_FASTCALL
  142. #define JS_NO_FASTCALL
  143. #endif
  144. #ifndef JS_INLINE
  145. # if defined __cplusplus
  146. # define JS_INLINE inline
  147. # elif defined _MSC_VER
  148. # define JS_INLINE __inline
  149. # elif defined __GNUC__
  150. # define JS_INLINE __inline__
  151. # else
  152. # define JS_INLINE inline
  153. # endif
  154. #endif
  155. #ifndef JS_ALWAYS_INLINE
  156. # if defined DEBUG
  157. # define JS_ALWAYS_INLINE JS_INLINE
  158. # elif defined _MSC_VER
  159. # define JS_ALWAYS_INLINE __forceinline
  160. # elif defined __GNUC__
  161. # define JS_ALWAYS_INLINE __attribute__((always_inline))
  162. # else
  163. # define JS_ALWAYS_INLINE JS_INLINE
  164. # endif
  165. #endif
  166. /***********************************************************************
  167. ** MACROS: JS_BEGIN_MACRO
  168. ** JS_END_MACRO
  169. ** DESCRIPTION:
  170. ** Macro body brackets so that macros with compound statement definitions
  171. ** behave syntactically more like functions when called.
  172. ***********************************************************************/
  173. #define JS_BEGIN_MACRO do {
  174. #if defined(_MSC_VER) && _MSC_VER >= 1400
  175. # define JS_END_MACRO \
  176. } __pragma(warning(push)) __pragma(warning(disable:4127)) \
  177. while (0) __pragma(warning(pop))
  178. #else
  179. # define JS_END_MACRO } while (0)
  180. #endif
  181. /***********************************************************************
  182. ** MACROS: JS_BEGIN_EXTERN_C
  183. ** JS_END_EXTERN_C
  184. ** DESCRIPTION:
  185. ** Macro shorthands for conditional C++ extern block delimiters.
  186. ***********************************************************************/
  187. #ifdef __cplusplus
  188. # define JS_BEGIN_EXTERN_C extern "C" {
  189. # define JS_END_EXTERN_C }
  190. #else
  191. # define JS_BEGIN_EXTERN_C
  192. # define JS_END_EXTERN_C
  193. #endif
  194. /***********************************************************************
  195. ** MACROS: JS_BIT
  196. ** JS_BITMASK
  197. ** DESCRIPTION:
  198. ** Bit masking macros. XXX n must be <= 31 to be portable
  199. ***********************************************************************/
  200. #define JS_BIT(n) ((JSUint32)1 << (n))
  201. #define JS_BITMASK(n) (JS_BIT(n) - 1)
  202. /***********************************************************************
  203. ** MACROS: JS_PTR_TO_INT32
  204. ** JS_PTR_TO_UINT32
  205. ** JS_INT32_TO_PTR
  206. ** JS_UINT32_TO_PTR
  207. ** DESCRIPTION:
  208. ** Integer to pointer and pointer to integer conversion macros.
  209. ***********************************************************************/
  210. #define JS_PTR_TO_INT32(x) ((jsint)((char *)(x) - (char *)0))
  211. #define JS_PTR_TO_UINT32(x) ((jsuint)((char *)(x) - (char *)0))
  212. #define JS_INT32_TO_PTR(x) ((void *)((char *)0 + (jsint)(x)))
  213. #define JS_UINT32_TO_PTR(x) ((void *)((char *)0 + (jsuint)(x)))
  214. /***********************************************************************
  215. ** MACROS: JS_HOWMANY
  216. ** JS_ROUNDUP
  217. ** JS_MIN
  218. ** JS_MAX
  219. ** DESCRIPTION:
  220. ** Commonly used macros for operations on compatible types.
  221. ***********************************************************************/
  222. #define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))
  223. #define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))
  224. #define JS_MIN(x,y) ((x)<(y)?(x):(y))
  225. #define JS_MAX(x,y) ((x)>(y)?(x):(y))
  226. #if (defined(XP_WIN) && !defined(CROSS_COMPILE)) || defined (WINCE)
  227. # include "jscpucfg.h" /* Use standard Mac or Windows configuration */
  228. #elif defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2) || defined(CROSS_COMPILE)
  229. # include "jsautocfg.h" /* Use auto-detected configuration */
  230. #else
  231. # error "Must define one of XP_BEOS, XP_OS2, XP_WIN or XP_UNIX"
  232. #endif
  233. JS_BEGIN_EXTERN_C
  234. /************************************************************************
  235. ** TYPES: JSUint8
  236. ** JSInt8
  237. ** DESCRIPTION:
  238. ** The int8 types are known to be 8 bits each. There is no type that
  239. ** is equivalent to a plain "char".
  240. ************************************************************************/
  241. #if JS_BYTES_PER_BYTE == 1
  242. typedef unsigned char JSUint8;
  243. typedef signed char JSInt8;
  244. #else
  245. # error No suitable type for JSInt8/JSUint8
  246. #endif
  247. /************************************************************************
  248. ** TYPES: JSUint16
  249. ** JSInt16
  250. ** DESCRIPTION:
  251. ** The int16 types are known to be 16 bits each.
  252. ************************************************************************/
  253. #if JS_BYTES_PER_SHORT == 2
  254. typedef unsigned short JSUint16;
  255. typedef short JSInt16;
  256. #else
  257. # error No suitable type for JSInt16/JSUint16
  258. #endif
  259. /************************************************************************
  260. ** TYPES: JSUint32
  261. ** JSInt32
  262. ** DESCRIPTION:
  263. ** The int32 types are known to be 32 bits each.
  264. ************************************************************************/
  265. #if JS_BYTES_PER_INT == 4
  266. typedef unsigned int JSUint32;
  267. typedef int JSInt32;
  268. # define JS_INT32(x) x
  269. # define JS_UINT32(x) x ## U
  270. #elif JS_BYTES_PER_LONG == 4
  271. typedef unsigned long JSUint32;
  272. typedef long JSInt32;
  273. # define JS_INT32(x) x ## L
  274. # define JS_UINT32(x) x ## UL
  275. #else
  276. # error No suitable type for JSInt32/JSUint32
  277. #endif
  278. /************************************************************************
  279. ** TYPES: JSUint64
  280. ** JSInt64
  281. ** DESCRIPTION:
  282. ** The int64 types are known to be 64 bits each. Care must be used when
  283. ** declaring variables of type JSUint64 or JSInt64. Different hardware
  284. ** architectures and even different compilers have varying support for
  285. ** 64 bit values. The only guaranteed portability requires the use of
  286. ** the JSLL_ macros (see jslong.h).
  287. ************************************************************************/
  288. #ifdef JS_HAVE_LONG_LONG
  289. # if JS_BYTES_PER_LONG == 8
  290. typedef long JSInt64;
  291. typedef unsigned long JSUint64;
  292. # elif defined(WIN16)
  293. typedef __int64 JSInt64;
  294. typedef unsigned __int64 JSUint64;
  295. # elif defined(WIN32) && !defined(__GNUC__)
  296. typedef __int64 JSInt64;
  297. typedef unsigned __int64 JSUint64;
  298. # else
  299. typedef long long JSInt64;
  300. typedef unsigned long long JSUint64;
  301. # endif /* JS_BYTES_PER_LONG == 8 */
  302. #else /* !JS_HAVE_LONG_LONG */
  303. typedef struct {
  304. # ifdef IS_LITTLE_ENDIAN
  305. JSUint32 lo, hi;
  306. # else
  307. JSUint32 hi, lo;
  308. #endif
  309. } JSInt64;
  310. typedef JSInt64 JSUint64;
  311. #endif /* !JS_HAVE_LONG_LONG */
  312. /************************************************************************
  313. ** TYPES: JSUintn
  314. ** JSIntn
  315. ** DESCRIPTION:
  316. ** The JSIntn types are most appropriate for automatic variables. They are
  317. ** guaranteed to be at least 16 bits, though various architectures may
  318. ** define them to be wider (e.g., 32 or even 64 bits). These types are
  319. ** never valid for fields of a structure.
  320. ************************************************************************/
  321. #if JS_BYTES_PER_INT >= 2
  322. typedef int JSIntn;
  323. typedef unsigned int JSUintn;
  324. #else
  325. # error 'sizeof(int)' not sufficient for platform use
  326. #endif
  327. /************************************************************************
  328. ** TYPES: JSFloat64
  329. ** DESCRIPTION:
  330. ** NSPR's floating point type is always 64 bits.
  331. ************************************************************************/
  332. typedef double JSFloat64;
  333. /************************************************************************
  334. ** TYPES: JSSize
  335. ** DESCRIPTION:
  336. ** A type for representing the size of objects.
  337. ************************************************************************/
  338. typedef size_t JSSize;
  339. /************************************************************************
  340. ** TYPES: JSPtrDiff
  341. ** DESCRIPTION:
  342. ** A type for pointer difference. Variables of this type are suitable
  343. ** for storing a pointer or pointer sutraction.
  344. ************************************************************************/
  345. typedef ptrdiff_t JSPtrdiff;
  346. /************************************************************************
  347. ** TYPES: JSUptrdiff
  348. ** DESCRIPTION:
  349. ** A type for pointer difference. Variables of this type are suitable
  350. ** for storing a pointer or pointer sutraction.
  351. ************************************************************************/
  352. #if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8
  353. typedef JSUint64 JSUptrdiff;
  354. #else
  355. typedef unsigned long JSUptrdiff;
  356. #endif
  357. /************************************************************************
  358. ** TYPES: JSBool
  359. ** DESCRIPTION:
  360. ** Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE
  361. ** for clarity of target type in assignments and actual arguments. Use
  362. ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
  363. ** just as you would C int-valued conditions.
  364. ************************************************************************/
  365. typedef JSIntn JSBool;
  366. #define JS_TRUE (JSIntn)1
  367. #define JS_FALSE (JSIntn)0
  368. /************************************************************************
  369. ** TYPES: JSPackedBool
  370. ** DESCRIPTION:
  371. ** Use JSPackedBool within structs where bitfields are not desireable
  372. ** but minimum and consistent overhead matters.
  373. ************************************************************************/
  374. typedef JSUint8 JSPackedBool;
  375. /*
  376. ** A JSWord is an integer that is the same size as a void*
  377. */
  378. #if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8
  379. typedef JSInt64 JSWord;
  380. typedef JSUint64 JSUword;
  381. #else
  382. typedef long JSWord;
  383. typedef unsigned long JSUword;
  384. #endif
  385. #include "jsotypes.h"
  386. /***********************************************************************
  387. ** MACROS: JS_LIKELY
  388. ** JS_UNLIKELY
  389. ** DESCRIPTION:
  390. ** These macros allow you to give a hint to the compiler about branch
  391. ** probability so that it can better optimize. Use them like this:
  392. **
  393. ** if (JS_LIKELY(v == 1)) {
  394. ** ... expected code path ...
  395. ** }
  396. **
  397. ** if (JS_UNLIKELY(v == 0)) {
  398. ** ... non-expected code path ...
  399. ** }
  400. **
  401. ***********************************************************************/
  402. #if defined(__GNUC__) && (__GNUC__ > 2)
  403. # define JS_LIKELY(x) (__builtin_expect((x), 1))
  404. # define JS_UNLIKELY(x) (__builtin_expect((x), 0))
  405. #else
  406. # define JS_LIKELY(x) (x)
  407. # define JS_UNLIKELY(x) (x)
  408. #endif
  409. /***********************************************************************
  410. ** MACROS: JS_ARRAY_LENGTH
  411. ** JS_ARRAY_END
  412. ** DESCRIPTION:
  413. ** Macros to get the number of elements and the pointer to one past the
  414. ** last element of a C array. Use them like this:
  415. **
  416. ** jschar buf[10], *s;
  417. ** JSString *str;
  418. ** ...
  419. ** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...;
  420. ** ...
  421. ** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf));
  422. ** ...
  423. **
  424. ***********************************************************************/
  425. #define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
  426. #define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array))
  427. JS_END_EXTERN_C
  428. #endif /* jstypes_h___ */