/[jscoverage]/trunk/js/jstypes.h
ViewVC logotype

Annotation of /trunk/js/jstypes.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 460 - (hide annotations)
Sat Sep 26 23:15:22 2009 UTC (12 years, 9 months ago) by siliconforks
File MIME type: text/plain
File size: 17031 byte(s)
Upgrade to SpiderMonkey from Firefox 3.5.3.

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

  ViewVC Help
Powered by ViewVC 1.1.24