js/src/jstypes.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jstypes.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,226 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/*
    1.11 +** File:                jstypes.h
    1.12 +** Description: Definitions of NSPR's basic types
    1.13 +**
    1.14 +** Prototypes and macros used to make up for deficiencies in ANSI environments
    1.15 +** that we have found.
    1.16 +**
    1.17 +** Since we do not wrap <stdlib.h> and all the other standard headers, authors
    1.18 +** of portable code will not know in general that they need these definitions.
    1.19 +** Instead of requiring these authors to find the dependent uses in their code
    1.20 +** and take the following steps only in those C files, we take steps once here
    1.21 +** for all C files.
    1.22 +**/
    1.23 +
    1.24 +#ifndef jstypes_h
    1.25 +#define jstypes_h
    1.26 +
    1.27 +#include "mozilla/Attributes.h"
    1.28 +#include "mozilla/Types.h"
    1.29 +
    1.30 +// jstypes.h is (or should be!) included by every file in SpiderMonkey.
    1.31 +// js-config.h and jsversion.h also should be included by every file.
    1.32 +// So include them here.
    1.33 +// XXX: including them in js/RequiredDefines.h should be a better option, since
    1.34 +// that is by definition the header file that should be included in all
    1.35 +// SpiderMonkey code.  However, Gecko doesn't do this!  See bug 909576.
    1.36 +#include "js-config.h"
    1.37 +#include "jsversion.h"
    1.38 +
    1.39 +/***********************************************************************
    1.40 +** MACROS:      JS_EXTERN_API
    1.41 +**              JS_EXPORT_API
    1.42 +** DESCRIPTION:
    1.43 +**      These are only for externally visible routines and globals.  For
    1.44 +**      internal routines, just use "extern" for type checking and that
    1.45 +**      will not export internal cross-file or forward-declared symbols.
    1.46 +**      Define a macro for declaring procedures return types. We use this to
    1.47 +**      deal with windoze specific type hackery for DLL definitions. Use
    1.48 +**      JS_EXTERN_API when the prototype for the method is declared. Use
    1.49 +**      JS_EXPORT_API for the implementation of the method.
    1.50 +**
    1.51 +** Example:
    1.52 +**   in dowhim.h
    1.53 +**     JS_EXTERN_API( void ) DoWhatIMean( void );
    1.54 +**   in dowhim.c
    1.55 +**     JS_EXPORT_API( void ) DoWhatIMean( void ) { return; }
    1.56 +**
    1.57 +**
    1.58 +***********************************************************************/
    1.59 +
    1.60 +#define JS_EXTERN_API(type)  extern MOZ_EXPORT type
    1.61 +#define JS_EXPORT_API(type)  MOZ_EXPORT type
    1.62 +#define JS_EXPORT_DATA(type) MOZ_EXPORT type
    1.63 +#define JS_IMPORT_API(type)  MOZ_IMPORT_API type
    1.64 +#define JS_IMPORT_DATA(type) MOZ_IMPORT_DATA type
    1.65 +
    1.66 +/*
    1.67 + * The linkage of JS API functions differs depending on whether the file is
    1.68 + * used within the JS library or not. Any source file within the JS
    1.69 + * interpreter should define EXPORT_JS_API whereas any client of the library
    1.70 + * should not. STATIC_JS_API is used to build JS as a static library.
    1.71 + */
    1.72 +#if defined(STATIC_JS_API)
    1.73 +#  define JS_PUBLIC_API(t)   t
    1.74 +#  define JS_PUBLIC_DATA(t)  t
    1.75 +#elif defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API)
    1.76 +#  define JS_PUBLIC_API(t)   MOZ_EXPORT t
    1.77 +#  define JS_PUBLIC_DATA(t)  MOZ_EXPORT t
    1.78 +#else
    1.79 +#  define JS_PUBLIC_API(t)   MOZ_IMPORT_API t
    1.80 +#  define JS_PUBLIC_DATA(t)  MOZ_IMPORT_DATA t
    1.81 +#endif
    1.82 +
    1.83 +#if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API)
    1.84 +#  define JS_FRIEND_API(t)    MOZ_EXPORT t
    1.85 +#  define JS_FRIEND_DATA(t)   MOZ_EXPORT t
    1.86 +#else
    1.87 +#  define JS_FRIEND_API(t)   MOZ_IMPORT_API t
    1.88 +#  define JS_FRIEND_DATA(t)  MOZ_IMPORT_DATA t
    1.89 +#endif
    1.90 +
    1.91 +#if defined(_MSC_VER) && defined(_M_IX86)
    1.92 +#define JS_FASTCALL __fastcall
    1.93 +#elif defined(__GNUC__) && defined(__i386__)
    1.94 +#define JS_FASTCALL __attribute__((fastcall))
    1.95 +#else
    1.96 +#define JS_FASTCALL
    1.97 +#define JS_NO_FASTCALL
    1.98 +#endif
    1.99 +
   1.100 +/***********************************************************************
   1.101 +** MACROS:      JS_BEGIN_MACRO
   1.102 +**              JS_END_MACRO
   1.103 +** DESCRIPTION:
   1.104 +**      Macro body brackets so that macros with compound statement definitions
   1.105 +**      behave syntactically more like functions when called.
   1.106 +***********************************************************************/
   1.107 +#define JS_BEGIN_MACRO  do {
   1.108 +
   1.109 +#if defined(_MSC_VER) && _MSC_VER >= 1400
   1.110 +# define JS_END_MACRO                                                         \
   1.111 +    } __pragma(warning(push)) __pragma(warning(disable:4127))                 \
   1.112 +    while (0) __pragma(warning(pop))
   1.113 +#else
   1.114 +# define JS_END_MACRO   } while (0)
   1.115 +#endif
   1.116 +
   1.117 +/***********************************************************************
   1.118 +** MACROS:      JS_BIT
   1.119 +**              JS_BITMASK
   1.120 +** DESCRIPTION:
   1.121 +** Bit masking macros.  XXX n must be <= 31 to be portable
   1.122 +***********************************************************************/
   1.123 +#define JS_BIT(n)       ((uint32_t)1 << (n))
   1.124 +#define JS_BITMASK(n)   (JS_BIT(n) - 1)
   1.125 +
   1.126 +/***********************************************************************
   1.127 +** MACROS:      JS_HOWMANY
   1.128 +**              JS_ROUNDUP
   1.129 +** DESCRIPTION:
   1.130 +**      Commonly used macros for operations on compatible types.
   1.131 +***********************************************************************/
   1.132 +#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))
   1.133 +#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))
   1.134 +
   1.135 +#include "jscpucfg.h"
   1.136 +
   1.137 +/*
   1.138 + * Define JS_64BIT iff we are building in an environment with 64-bit
   1.139 + * addresses.
   1.140 + */
   1.141 +#ifdef _MSC_VER
   1.142 +# if defined(_M_X64) || defined(_M_AMD64)
   1.143 +#  define JS_64BIT
   1.144 +# endif
   1.145 +#elif defined(__GNUC__)
   1.146 +/* Additional GCC defines are when running on Solaris, AIX, and HPUX */
   1.147 +# if defined(__x86_64__) || defined(__sparcv9) || \
   1.148 +        defined(__64BIT__) || defined(__LP64__)
   1.149 +#  define JS_64BIT
   1.150 +# endif
   1.151 +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Sun Studio C/C++ */
   1.152 +# if defined(__x86_64) || defined(__sparcv9)
   1.153 +#  define JS_64BIT
   1.154 +# endif
   1.155 +#elif defined(__xlc__) || defined(__xlC__)        /* IBM XL C/C++ */
   1.156 +# if defined(__64BIT__)
   1.157 +#  define JS_64BIT
   1.158 +# endif
   1.159 +#elif defined(__HP_cc) || defined(__HP_aCC)       /* HP-UX cc/aCC */
   1.160 +# if defined(__LP64__)
   1.161 +#  define JS_64BIT
   1.162 +# endif
   1.163 +#else
   1.164 +# error "Implement me"
   1.165 +#endif
   1.166 +
   1.167 +/***********************************************************************
   1.168 +** MACROS:      JS_ARRAY_LENGTH
   1.169 +**              JS_ARRAY_END
   1.170 +** DESCRIPTION:
   1.171 +**      Macros to get the number of elements and the pointer to one past the
   1.172 +**      last element of a C array. Use them like this:
   1.173 +**
   1.174 +**      jschar buf[10], *s;
   1.175 +**      JSString *str;
   1.176 +**      ...
   1.177 +**      for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...;
   1.178 +**      ...
   1.179 +**      str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf));
   1.180 +**      ...
   1.181 +**
   1.182 +***********************************************************************/
   1.183 +
   1.184 +#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
   1.185 +#define JS_ARRAY_END(array)    ((array) + JS_ARRAY_LENGTH(array))
   1.186 +
   1.187 +#define JS_BITS_PER_BYTE 8
   1.188 +#define JS_BITS_PER_BYTE_LOG2 3
   1.189 +
   1.190 +#if defined(JS_64BIT)
   1.191 +# define JS_BITS_PER_WORD 64
   1.192 +#else
   1.193 +# define JS_BITS_PER_WORD 32
   1.194 +#endif
   1.195 +
   1.196 +/***********************************************************************
   1.197 +** MACROS:      JS_FUNC_TO_DATA_PTR
   1.198 +**              JS_DATA_TO_FUNC_PTR
   1.199 +** DESCRIPTION:
   1.200 +**      Macros to convert between function and data pointers assuming that
   1.201 +**      they have the same size. Use them like this:
   1.202 +**
   1.203 +**      JSPropertyOp nativeGetter;
   1.204 +**      JSObject *scriptedGetter;
   1.205 +**      ...
   1.206 +**      scriptedGetter = JS_FUNC_TO_DATA_PTR(JSObject *, nativeGetter);
   1.207 +**      ...
   1.208 +**      nativeGetter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, scriptedGetter);
   1.209 +**
   1.210 +***********************************************************************/
   1.211 +
   1.212 +#ifdef __GNUC__
   1.213 +# define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (size_t) (fun))
   1.214 +# define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (size_t) (ptr))
   1.215 +#else
   1.216 +/* Use an extra (void *) cast for MSVC. */
   1.217 +# define JS_FUNC_TO_DATA_PTR(type, fun) ((type) (void *) (fun))
   1.218 +# define JS_DATA_TO_FUNC_PTR(type, ptr) ((type) (void *) (ptr))
   1.219 +#endif
   1.220 +
   1.221 +#ifdef __GNUC__
   1.222 +# define JS_EXTENSION __extension__
   1.223 +# define JS_EXTENSION_(s) __extension__ ({ s; })
   1.224 +#else
   1.225 +# define JS_EXTENSION
   1.226 +# define JS_EXTENSION_(s) s
   1.227 +#endif
   1.228 +
   1.229 +#endif /* jstypes_h */

mercurial