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

Contents of /trunk/js/jstypes.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 507 - (show annotations)
Sun Jan 10 07:23:34 2010 UTC (9 years, 9 months ago) by siliconforks
File MIME type: text/plain
File size: 16167 byte(s)
Update SpiderMonkey from Firefox 3.6rc1.

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

  ViewVC Help
Powered by ViewVC 1.1.24