PageRenderTime 65ms CodeModel.GetById 31ms app.highlight 10ms RepoModel.GetById 20ms 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
  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/*
 41** File:                jstypes.h
 42** Description: Definitions of NSPR's basic types
 43**
 44** Prototypes and macros used to make up for deficiencies in ANSI environments
 45** that we have found.
 46**
 47** Since we do not wrap <stdlib.h> and all the other standard headers, authors
 48** of portable code will not know in general that they need these definitions.
 49** Instead of requiring these authors to find the dependent uses in their code
 50** and take the following steps only in those C files, we take steps once here
 51** for all C files.
 52**/
 53
 54#ifndef jstypes_h___
 55#define jstypes_h___
 56
 57#include <stddef.h>
 58
 59/***********************************************************************
 60** MACROS:      JS_EXTERN_API
 61**              JS_EXPORT_API
 62** DESCRIPTION:
 63**      These are only for externally visible routines and globals.  For
 64**      internal routines, just use "extern" for type checking and that
 65**      will not export internal cross-file or forward-declared symbols.
 66**      Define a macro for declaring procedures return types. We use this to
 67**      deal with windoze specific type hackery for DLL definitions. Use
 68**      JS_EXTERN_API when the prototype for the method is declared. Use
 69**      JS_EXPORT_API for the implementation of the method.
 70**
 71** Example:
 72**   in dowhim.h
 73**     JS_EXTERN_API( void ) DoWhatIMean( void );
 74**   in dowhim.c
 75**     JS_EXPORT_API( void ) DoWhatIMean( void ) { return; }
 76**
 77**
 78***********************************************************************/
 79#ifdef WIN32
 80
 81/* These also work for __MWERKS__ */
 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
 87#elif defined(XP_OS2) && defined(__declspec)
 88
 89# define JS_EXTERN_API(__type)  extern __declspec(dllexport) __type
 90# define JS_EXPORT_API(__type)  __declspec(dllexport) __type
 91# define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
 92# define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
 93
 94#else /* Unix */
 95
 96# ifdef HAVE_VISIBILITY_ATTRIBUTE
 97#  define JS_EXTERNAL_VIS __attribute__((visibility ("default")))
 98# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
 99#  define JS_EXTERNAL_VIS __global
100# else
101#  define JS_EXTERNAL_VIS
102# endif
103
104# define JS_EXTERN_API(__type)  extern JS_EXTERNAL_VIS __type
105# define JS_EXPORT_API(__type)  JS_EXTERNAL_VIS __type
106# define JS_EXTERN_DATA(__type) extern JS_EXTERNAL_VIS __type
107# define JS_EXPORT_DATA(__type) JS_EXTERNAL_VIS __type
108
109#endif
110
111#ifdef _WIN32
112# if defined(__MWERKS__) || defined(__GNUC__)
113#  define JS_IMPORT_API(__x)    __x
114# else
115#  define JS_IMPORT_API(__x)    __declspec(dllimport) __x
116# endif
117#elif defined(XP_OS2) && defined(__declspec)
118# define JS_IMPORT_API(__x)     __declspec(dllimport) __x
119#else
120# define JS_IMPORT_API(__x)     JS_EXPORT_API (__x)
121#endif
122
123#if defined(_WIN32) && !defined(__MWERKS__)
124# define JS_IMPORT_DATA(__x)      __declspec(dllimport) __x
125#elif defined(XP_OS2) && defined(__declspec)
126# define JS_IMPORT_DATA(__x)      __declspec(dllimport) __x
127#else
128# define JS_IMPORT_DATA(__x)     JS_EXPORT_DATA (__x)
129#endif
130
131/*
132 * The linkage of JS API functions differs depending on whether the file is
133 * used within the JS library or not. Any source file within the JS
134 * interpreter should define EXPORT_JS_API whereas any client of the library
135 * should not. STATIC_JS_API is used to build JS as a static library.
136 */
137#if defined(STATIC_JS_API)
138
139# define JS_PUBLIC_API(t)   t
140# define JS_PUBLIC_DATA(t)  t
141
142#elif defined(EXPORT_JS_API)
143
144# define JS_PUBLIC_API(t)   JS_EXPORT_API(t)
145# define JS_PUBLIC_DATA(t)  JS_EXPORT_DATA(t)
146
147#else
148
149# define JS_PUBLIC_API(t)   JS_IMPORT_API(t)
150# define JS_PUBLIC_DATA(t)  JS_IMPORT_DATA(t)
151
152#endif
153
154#define JS_FRIEND_API(t)    JS_PUBLIC_API(t)
155#define JS_FRIEND_DATA(t)   JS_PUBLIC_DATA(t)
156
157#if defined(_MSC_VER) && defined(_M_IX86)
158#define JS_FASTCALL __fastcall
159#elif defined(__GNUC__) && defined(__i386__) &&                         \
160  ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
161#define JS_FASTCALL __attribute__((fastcall))
162#else
163#define JS_FASTCALL
164#define JS_NO_FASTCALL
165#endif
166
167#ifndef JS_INLINE
168# if defined __cplusplus
169#  define JS_INLINE          inline
170# elif defined _MSC_VER
171#  define JS_INLINE          __inline
172# elif defined __GNUC__
173#  define JS_INLINE          __inline__
174# else
175#  define JS_INLINE          inline
176# endif
177#endif
178
179#ifndef JS_ALWAYS_INLINE
180# if defined DEBUG
181#  define JS_ALWAYS_INLINE   JS_INLINE
182# elif defined _MSC_VER
183#  define JS_ALWAYS_INLINE   __forceinline
184# elif defined __GNUC__
185#  define JS_ALWAYS_INLINE   __attribute__((always_inline))
186# else
187#  define JS_ALWAYS_INLINE   JS_INLINE
188# endif
189#endif
190
191/***********************************************************************
192** MACROS:      JS_BEGIN_MACRO
193**              JS_END_MACRO
194** DESCRIPTION:
195**      Macro body brackets so that macros with compound statement definitions
196**      behave syntactically more like functions when called.
197***********************************************************************/
198#define JS_BEGIN_MACRO  do {
199
200#if defined(_MSC_VER) && _MSC_VER >= 1400
201# define JS_END_MACRO                                                         \
202    } __pragma(warning(push)) __pragma(warning(disable:4127))                 \
203    while (0) __pragma(warning(pop))
204#else
205# define JS_END_MACRO   } while (0)
206#endif
207
208/***********************************************************************
209** MACROS:      JS_BEGIN_EXTERN_C
210**              JS_END_EXTERN_C
211** DESCRIPTION:
212**      Macro shorthands for conditional C++ extern block delimiters.
213***********************************************************************/
214#ifdef __cplusplus
215
216# define JS_BEGIN_EXTERN_C      extern "C" {
217# define JS_END_EXTERN_C        }
218
219#else
220
221# define JS_BEGIN_EXTERN_C
222# define JS_END_EXTERN_C
223
224#endif
225
226/***********************************************************************
227** MACROS:      JS_BIT
228**              JS_BITMASK
229** DESCRIPTION:
230** Bit masking macros.  XXX n must be <= 31 to be portable
231***********************************************************************/
232#define JS_BIT(n)       ((JSUint32)1 << (n))
233#define JS_BITMASK(n)   (JS_BIT(n) - 1)
234
235/***********************************************************************
236** MACROS:      JS_PTR_TO_INT32
237**              JS_PTR_TO_UINT32
238**              JS_INT32_TO_PTR
239**              JS_UINT32_TO_PTR
240** DESCRIPTION:
241** Integer to pointer and pointer to integer conversion macros.
242***********************************************************************/
243#define JS_PTR_TO_INT32(x)  ((jsint)((char *)(x) - (char *)0))
244#define JS_PTR_TO_UINT32(x) ((jsuint)((char *)(x) - (char *)0))
245#define JS_INT32_TO_PTR(x)  ((void *)((char *)0 + (jsint)(x)))
246#define JS_UINT32_TO_PTR(x) ((void *)((char *)0 + (jsuint)(x)))
247
248/***********************************************************************
249** MACROS:      JS_HOWMANY
250**              JS_ROUNDUP
251**              JS_MIN
252**              JS_MAX
253** DESCRIPTION:
254**      Commonly used macros for operations on compatible types.
255***********************************************************************/
256#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))
257#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))
258#define JS_MIN(x,y)     ((x)<(y)?(x):(y))
259#define JS_MAX(x,y)     ((x)>(y)?(x):(y))
260
261#if (defined(XP_WIN) && !defined(CROSS_COMPILE)) || defined (WINCE)
262# include "jscpucfg.h"      /* Use standard Mac or Windows configuration */
263#elif defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2) || defined(CROSS_COMPILE)
264# include "jsautocfg.h"     /* Use auto-detected configuration */
265#else
266# error "Must define one of XP_BEOS, XP_OS2, XP_WIN or XP_UNIX"
267#endif
268
269JS_BEGIN_EXTERN_C
270
271/************************************************************************
272** TYPES:       JSUint8
273**              JSInt8
274** DESCRIPTION:
275**  The int8 types are known to be 8 bits each. There is no type that
276**      is equivalent to a plain "char".
277************************************************************************/
278#if JS_BYTES_PER_BYTE == 1
279typedef unsigned char JSUint8;
280typedef signed char JSInt8;
281#else
282# error No suitable type for JSInt8/JSUint8
283#endif
284
285/************************************************************************
286** TYPES:       JSUint16
287**              JSInt16
288** DESCRIPTION:
289**  The int16 types are known to be 16 bits each.
290************************************************************************/
291#if JS_BYTES_PER_SHORT == 2
292typedef unsigned short JSUint16;
293typedef short JSInt16;
294#else
295# error No suitable type for JSInt16/JSUint16
296#endif
297
298/************************************************************************
299** TYPES:       JSUint32
300**              JSInt32
301** DESCRIPTION:
302**  The int32 types are known to be 32 bits each.
303************************************************************************/
304#if JS_BYTES_PER_INT == 4
305typedef unsigned int JSUint32;
306typedef int JSInt32;
307# define JS_INT32(x)    x
308# define JS_UINT32(x)   x ## U
309#elif JS_BYTES_PER_LONG == 4
310typedef unsigned long JSUint32;
311typedef long JSInt32;
312# define JS_INT32(x)    x ## L
313# define JS_UINT32(x)   x ## UL
314#else
315# error No suitable type for JSInt32/JSUint32
316#endif
317
318/************************************************************************
319** TYPES:       JSUint64
320**              JSInt64
321** DESCRIPTION:
322**  The int64 types are known to be 64 bits each. Care must be used when
323**      declaring variables of type JSUint64 or JSInt64. Different hardware
324**      architectures and even different compilers have varying support for
325**      64 bit values. The only guaranteed portability requires the use of
326**      the JSLL_ macros (see jslong.h).
327************************************************************************/
328#ifdef JS_HAVE_LONG_LONG
329
330# if JS_BYTES_PER_LONG == 8
331typedef long JSInt64;
332typedef unsigned long JSUint64;
333# elif defined(WIN16)
334typedef __int64 JSInt64;
335typedef unsigned __int64 JSUint64;
336# elif defined(WIN32) && !defined(__GNUC__)
337typedef __int64  JSInt64;
338typedef unsigned __int64 JSUint64;
339# else
340typedef long long JSInt64;
341typedef unsigned long long JSUint64;
342# endif /* JS_BYTES_PER_LONG == 8 */
343
344#else  /* !JS_HAVE_LONG_LONG */
345
346typedef struct {
347# ifdef IS_LITTLE_ENDIAN
348    JSUint32 lo, hi;
349# else
350    JSUint32 hi, lo;
351#endif
352} JSInt64;
353typedef JSInt64 JSUint64;
354
355#endif /* !JS_HAVE_LONG_LONG */
356
357/************************************************************************
358** TYPES:       JSUintn
359**              JSIntn
360** DESCRIPTION:
361**  The JSIntn types are most appropriate for automatic variables. They are
362**      guaranteed to be at least 16 bits, though various architectures may
363**      define them to be wider (e.g., 32 or even 64 bits). These types are
364**      never valid for fields of a structure.
365************************************************************************/
366#if JS_BYTES_PER_INT >= 2
367typedef int JSIntn;
368typedef unsigned int JSUintn;
369#else
370# error 'sizeof(int)' not sufficient for platform use
371#endif
372
373/************************************************************************
374** TYPES:       JSFloat64
375** DESCRIPTION:
376**  NSPR's floating point type is always 64 bits.
377************************************************************************/
378typedef double          JSFloat64;
379
380/************************************************************************
381** TYPES:       JSSize
382** DESCRIPTION:
383**  A type for representing the size of objects.
384************************************************************************/
385typedef size_t JSSize;
386
387/************************************************************************
388** TYPES:       JSPtrDiff
389** DESCRIPTION:
390**  A type for pointer difference. Variables of this type are suitable
391**      for storing a pointer or pointer sutraction.
392************************************************************************/
393typedef ptrdiff_t JSPtrdiff;
394
395/************************************************************************
396** TYPES:       JSUptrdiff
397** DESCRIPTION:
398**  A type for pointer difference. Variables of this type are suitable
399**      for storing a pointer or pointer sutraction.
400************************************************************************/
401#if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8
402typedef JSUint64 JSUptrdiff;
403#else
404typedef unsigned long JSUptrdiff;
405#endif
406
407/************************************************************************
408** TYPES:       JSBool
409** DESCRIPTION:
410**  Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE
411**      for clarity of target type in assignments and actual arguments. Use
412**      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
413**      just as you would C int-valued conditions.
414************************************************************************/
415typedef JSIntn JSBool;
416#define JS_TRUE (JSIntn)1
417#define JS_FALSE (JSIntn)0
418
419/************************************************************************
420** TYPES:       JSPackedBool
421** DESCRIPTION:
422**  Use JSPackedBool within structs where bitfields are not desireable
423**      but minimum and consistent overhead matters.
424************************************************************************/
425typedef JSUint8 JSPackedBool;
426
427/*
428** A JSWord is an integer that is the same size as a void*
429*/
430#if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8
431typedef JSInt64 JSWord;
432typedef JSUint64 JSUword;
433#else
434typedef long JSWord;
435typedef unsigned long JSUword;
436#endif
437
438#include "jsotypes.h"
439
440/***********************************************************************
441** MACROS:      JS_LIKELY
442**              JS_UNLIKELY
443** DESCRIPTION:
444**      These macros allow you to give a hint to the compiler about branch
445**      probability so that it can better optimize.  Use them like this:
446**
447**      if (JS_LIKELY(v == 1)) {
448**          ... expected code path ...
449**      }
450**
451**      if (JS_UNLIKELY(v == 0)) {
452**          ... non-expected code path ...
453**      }
454**
455***********************************************************************/
456#if defined(__GNUC__) && (__GNUC__ > 2)
457
458# define JS_LIKELY(x)   (__builtin_expect((x), 1))
459# define JS_UNLIKELY(x) (__builtin_expect((x), 0))
460
461#else
462
463# define JS_LIKELY(x)   (x)
464# define JS_UNLIKELY(x) (x)
465
466#endif
467
468/***********************************************************************
469** MACROS:      JS_ARRAY_LENGTH
470**              JS_ARRAY_END
471** DESCRIPTION:
472**      Macros to get the number of elements and the pointer to one past the
473**      last element of a C array. Use them like this:
474**
475**      jschar buf[10], *s;
476**      JSString *str;
477**      ...
478**      for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...;
479**      ...
480**      str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf));
481**      ...
482**
483***********************************************************************/
484
485#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
486#define JS_ARRAY_END(array)    ((array) + JS_ARRAY_LENGTH(array))
487
488JS_END_EXTERN_C
489
490#endif /* jstypes_h___ */