Bug 469739 - Add support for displaying Vista UAC shield icon; r=joe sr=vladimir
[wine-gecko.git] / js / src / jstypes.h
blob4cdd921d9ce565554477394636ca89d9bc5ac92b
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
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/
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.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
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.
23 * Contributor(s):
24 * IBM Corp.
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.
38 * ***** END LICENSE BLOCK ***** */
41 ** File: jstypes.h
42 ** Description: Definitions of NSPR's basic types
44 ** Prototypes and macros used to make up for deficiencies in ANSI environments
45 ** that we have found.
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 **/
54 #ifndef jstypes_h___
55 #define jstypes_h___
57 #include <stddef.h>
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.
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; }
78 ***********************************************************************/
79 #ifdef WIN32
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
87 #elif defined(XP_OS2) && defined(__declspec)
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
94 #else /* Unix */
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
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
109 #endif
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
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
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.
137 #if defined(STATIC_JS_API)
139 # define JS_PUBLIC_API(t) t
140 # define JS_PUBLIC_DATA(t) t
142 #elif defined(EXPORT_JS_API)
144 # define JS_PUBLIC_API(t) JS_EXPORT_API(t)
145 # define JS_PUBLIC_DATA(t) JS_EXPORT_DATA(t)
147 #else
149 # define JS_PUBLIC_API(t) JS_IMPORT_API(t)
150 # define JS_PUBLIC_DATA(t) JS_IMPORT_DATA(t)
152 #endif
154 #define JS_FRIEND_API(t) JS_PUBLIC_API(t)
155 #define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t)
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
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
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
191 #ifdef NS_STATIC_CHECKING
193 * Attributes for static analysis. Functions declared with JS_REQUIRES_STACK
194 * always have a valid cx->fp and can access it freely. Other functions can
195 * access cx->fp only after calling a function that "forces" the stack
196 * (i.e. lazily instantiates it as needed).
198 # define JS_REQUIRES_STACK __attribute__((user("JS_REQUIRES_STACK")))
199 # define JS_FORCES_STACK __attribute__((user("JS_FORCES_STACK")))
200 #else
201 # define JS_REQUIRES_STACK
202 # define JS_FORCES_STACK
203 #endif
205 /***********************************************************************
206 ** MACROS: JS_BEGIN_MACRO
207 ** JS_END_MACRO
208 ** DESCRIPTION:
209 ** Macro body brackets so that macros with compound statement definitions
210 ** behave syntactically more like functions when called.
211 ***********************************************************************/
212 #define JS_BEGIN_MACRO do {
214 #if defined(_MSC_VER) && _MSC_VER >= 1400
215 # define JS_END_MACRO \
216 } __pragma(warning(push)) __pragma(warning(disable:4127)) \
217 while (0) __pragma(warning(pop))
218 #else
219 # define JS_END_MACRO } while (0)
220 #endif
222 /***********************************************************************
223 ** MACROS: JS_BEGIN_EXTERN_C
224 ** JS_END_EXTERN_C
225 ** DESCRIPTION:
226 ** Macro shorthands for conditional C++ extern block delimiters.
227 ***********************************************************************/
228 #ifdef __cplusplus
230 # define JS_BEGIN_EXTERN_C extern "C" {
231 # define JS_END_EXTERN_C }
233 #else
235 # define JS_BEGIN_EXTERN_C
236 # define JS_END_EXTERN_C
238 #endif
240 /***********************************************************************
241 ** MACROS: JS_BIT
242 ** JS_BITMASK
243 ** DESCRIPTION:
244 ** Bit masking macros. XXX n must be <= 31 to be portable
245 ***********************************************************************/
246 #define JS_BIT(n) ((JSUint32)1 << (n))
247 #define JS_BITMASK(n) (JS_BIT(n) - 1)
249 /***********************************************************************
250 ** MACROS: JS_PTR_TO_INT32
251 ** JS_PTR_TO_UINT32
252 ** JS_INT32_TO_PTR
253 ** JS_UINT32_TO_PTR
254 ** DESCRIPTION:
255 ** Integer to pointer and pointer to integer conversion macros.
256 ***********************************************************************/
257 #define JS_PTR_TO_INT32(x) ((jsint)((char *)(x) - (char *)0))
258 #define JS_PTR_TO_UINT32(x) ((jsuint)((char *)(x) - (char *)0))
259 #define JS_INT32_TO_PTR(x) ((void *)((char *)0 + (jsint)(x)))
260 #define JS_UINT32_TO_PTR(x) ((void *)((char *)0 + (jsuint)(x)))
262 /***********************************************************************
263 ** MACROS: JS_HOWMANY
264 ** JS_ROUNDUP
265 ** JS_MIN
266 ** JS_MAX
267 ** DESCRIPTION:
268 ** Commonly used macros for operations on compatible types.
269 ***********************************************************************/
270 #define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))
271 #define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))
272 #define JS_MIN(x,y) ((x)<(y)?(x):(y))
273 #define JS_MAX(x,y) ((x)>(y)?(x):(y))
275 #if (defined(XP_WIN) && !defined(CROSS_COMPILE)) || defined (WINCE)
276 # include "jscpucfg.h" /* Use standard Mac or Windows configuration */
277 #elif defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2) || defined(CROSS_COMPILE)
278 # include "jsautocfg.h" /* Use auto-detected configuration */
279 #else
280 # error "Must define one of XP_BEOS, XP_OS2, XP_WIN or XP_UNIX"
281 #endif
283 JS_BEGIN_EXTERN_C
285 /************************************************************************
286 ** TYPES: JSUint8
287 ** JSInt8
288 ** DESCRIPTION:
289 ** The int8 types are known to be 8 bits each. There is no type that
290 ** is equivalent to a plain "char".
291 ************************************************************************/
292 #if JS_BYTES_PER_BYTE == 1
293 typedef unsigned char JSUint8;
294 typedef signed char JSInt8;
295 #else
296 # error No suitable type for JSInt8/JSUint8
297 #endif
299 /************************************************************************
300 ** TYPES: JSUint16
301 ** JSInt16
302 ** DESCRIPTION:
303 ** The int16 types are known to be 16 bits each.
304 ************************************************************************/
305 #if JS_BYTES_PER_SHORT == 2
306 typedef unsigned short JSUint16;
307 typedef short JSInt16;
308 #else
309 # error No suitable type for JSInt16/JSUint16
310 #endif
312 /************************************************************************
313 ** TYPES: JSUint32
314 ** JSInt32
315 ** DESCRIPTION:
316 ** The int32 types are known to be 32 bits each.
317 ************************************************************************/
318 #if JS_BYTES_PER_INT == 4
319 typedef unsigned int JSUint32;
320 typedef int JSInt32;
321 # define JS_INT32(x) x
322 # define JS_UINT32(x) x ## U
323 #elif JS_BYTES_PER_LONG == 4
324 typedef unsigned long JSUint32;
325 typedef long JSInt32;
326 # define JS_INT32(x) x ## L
327 # define JS_UINT32(x) x ## UL
328 #else
329 # error No suitable type for JSInt32/JSUint32
330 #endif
332 /************************************************************************
333 ** TYPES: JSUint64
334 ** JSInt64
335 ** DESCRIPTION:
336 ** The int64 types are known to be 64 bits each. Care must be used when
337 ** declaring variables of type JSUint64 or JSInt64. Different hardware
338 ** architectures and even different compilers have varying support for
339 ** 64 bit values. The only guaranteed portability requires the use of
340 ** the JSLL_ macros (see jslong.h).
341 ************************************************************************/
342 #ifdef JS_HAVE_LONG_LONG
344 # if JS_BYTES_PER_LONG == 8
345 typedef long JSInt64;
346 typedef unsigned long JSUint64;
347 # elif defined(WIN16)
348 typedef __int64 JSInt64;
349 typedef unsigned __int64 JSUint64;
350 # elif defined(WIN32) && !defined(__GNUC__)
351 typedef __int64 JSInt64;
352 typedef unsigned __int64 JSUint64;
353 # else
354 typedef long long JSInt64;
355 typedef unsigned long long JSUint64;
356 # endif /* JS_BYTES_PER_LONG == 8 */
358 #else /* !JS_HAVE_LONG_LONG */
360 typedef struct {
361 # ifdef IS_LITTLE_ENDIAN
362 JSUint32 lo, hi;
363 # else
364 JSUint32 hi, lo;
365 #endif
366 } JSInt64;
367 typedef JSInt64 JSUint64;
369 #endif /* !JS_HAVE_LONG_LONG */
371 /************************************************************************
372 ** TYPES: JSUintn
373 ** JSIntn
374 ** DESCRIPTION:
375 ** The JSIntn types are most appropriate for automatic variables. They are
376 ** guaranteed to be at least 16 bits, though various architectures may
377 ** define them to be wider (e.g., 32 or even 64 bits). These types are
378 ** never valid for fields of a structure.
379 ************************************************************************/
380 #if JS_BYTES_PER_INT >= 2
381 typedef int JSIntn;
382 typedef unsigned int JSUintn;
383 #else
384 # error 'sizeof(int)' not sufficient for platform use
385 #endif
387 /************************************************************************
388 ** TYPES: JSFloat64
389 ** DESCRIPTION:
390 ** NSPR's floating point type is always 64 bits.
391 ************************************************************************/
392 typedef double JSFloat64;
394 /************************************************************************
395 ** TYPES: JSSize
396 ** DESCRIPTION:
397 ** A type for representing the size of objects.
398 ************************************************************************/
399 typedef size_t JSSize;
401 /************************************************************************
402 ** TYPES: JSPtrDiff
403 ** DESCRIPTION:
404 ** A type for pointer difference. Variables of this type are suitable
405 ** for storing a pointer or pointer sutraction.
406 ************************************************************************/
407 typedef ptrdiff_t JSPtrdiff;
409 /************************************************************************
410 ** TYPES: JSUptrdiff
411 ** DESCRIPTION:
412 ** A type for pointer difference. Variables of this type are suitable
413 ** for storing a pointer or pointer sutraction.
414 ************************************************************************/
415 #if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8
416 typedef JSUint64 JSUptrdiff;
417 #else
418 typedef unsigned long JSUptrdiff;
419 #endif
421 /************************************************************************
422 ** TYPES: JSBool
423 ** DESCRIPTION:
424 ** Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE
425 ** for clarity of target type in assignments and actual arguments. Use
426 ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
427 ** just as you would C int-valued conditions.
428 ************************************************************************/
429 typedef JSIntn JSBool;
430 #define JS_TRUE (JSIntn)1
431 #define JS_FALSE (JSIntn)0
433 /************************************************************************
434 ** TYPES: JSPackedBool
435 ** DESCRIPTION:
436 ** Use JSPackedBool within structs where bitfields are not desireable
437 ** but minimum and consistent overhead matters.
438 ************************************************************************/
439 typedef JSUint8 JSPackedBool;
442 ** A JSWord is an integer that is the same size as a void*
444 #if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8
445 typedef JSInt64 JSWord;
446 typedef JSUint64 JSUword;
447 #else
448 typedef long JSWord;
449 typedef unsigned long JSUword;
450 #endif
452 #include "jsotypes.h"
454 /***********************************************************************
455 ** MACROS: JS_LIKELY
456 ** JS_UNLIKELY
457 ** DESCRIPTION:
458 ** These macros allow you to give a hint to the compiler about branch
459 ** probability so that it can better optimize. Use them like this:
461 ** if (JS_LIKELY(v == 1)) {
462 ** ... expected code path ...
463 ** }
465 ** if (JS_UNLIKELY(v == 0)) {
466 ** ... non-expected code path ...
467 ** }
469 ***********************************************************************/
470 #if defined(__GNUC__) && (__GNUC__ > 2)
472 # define JS_LIKELY(x) (__builtin_expect((x), 1))
473 # define JS_UNLIKELY(x) (__builtin_expect((x), 0))
475 #else
477 # define JS_LIKELY(x) (x)
478 # define JS_UNLIKELY(x) (x)
480 #endif
482 /***********************************************************************
483 ** MACROS: JS_ARRAY_LENGTH
484 ** JS_ARRAY_END
485 ** DESCRIPTION:
486 ** Macros to get the number of elements and the pointer to one past the
487 ** last element of a C array. Use them like this:
489 ** jschar buf[10], *s;
490 ** JSString *str;
491 ** ...
492 ** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...;
493 ** ...
494 ** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf));
495 ** ...
497 ***********************************************************************/
499 #define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
500 #define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array))
502 JS_END_EXTERN_C
504 #endif /* jstypes_h___ */