/test/language/ace/cecil.h
C++ Header | 585 lines | 385 code | 59 blank | 141 comment | 99 complexity | 7a3e5ed75e2c77e6f33fe10f88229fcf MD5 | raw file
1#ifdef _BASE_H 2#define _HAD_BASE_H 3#endif 4/* 5-- ------------------------------------------------------------------------------------------------------------ 6-- Copyright notice below. Please read. 7-- 8-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 9-- Copyright(C) 2003-2005: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 10-- 11-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 12-- 13-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 14-- documentation files (the "Software"), to deal in the Software without restriction, including without 15-- limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 16-- the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 17-- conditions: 18-- 19-- The above copyright notice and this permission notice shall be included in all copies or substantial 20-- portions of the Software. 21-- 22-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 23-- LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 24-- EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 25-- AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 26-- OR OTHER DEALINGS IN THE SOFTWARE. 27-- 28-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 29-- ------------------------------------------------------------------------------------------------------------ 30*/ 31/* 32 This file (SmartEiffel/sys/runtime/base.h) contains all basic Eiffel 33 type definitions. 34 This file is automatically included in the header for all modes of 35 compilation: -boost, -no_check, -require_check, -ensure_check, ... 36 This file is also included in the header of any cecil file (when the 37 -cecil option is used). 38 This file is also included in the header file of C++ wrappers (when 39 using the external "C++" clause). 40*/ 41 42#ifndef _BASE_H 43#define _BASE_H 44 45#if defined(_MSC_VER) && (_MSC_VER >= 1400) /* VC8+ */ 46# ifndef _CRT_SECURE_NO_DEPRECATE 47# define _CRT_SECURE_NO_DEPRECATE 48# endif 49# ifndef _CRT_NONSTDC_NO_DEPRECATE 50# define _CRT_NONSTDC_NO_DEPRECATE 51# endif 52#endif /* VC8+ */ 53 54#include <stdio.h> 55#include <string.h> 56#include <math.h> 57#include <stdlib.h> 58#include <signal.h> 59#include <stddef.h> 60#include <stdarg.h> 61#include <limits.h> 62#include <float.h> 63#include <setjmp.h> 64#include <sys/types.h> 65#include <sys/stat.h> 66#include <fcntl.h> 67#if defined __USE_POSIX || defined __unix__ || defined _POSIX_C_SOURCE 68# include <unistd.h> 69#endif 70#if !defined(WIN32) && \ 71 (defined(WINVER) || defined(_WIN32_WINNT) || defined(_WIN32) || \ 72 defined(__WIN32__) || defined(__TOS_WIN__) || defined(_MSC_VER)) 73# define WIN32 1 74#endif 75#ifdef WIN32 76# include <windows.h> 77#else 78# ifndef O_RDONLY 79# include <sys/file.h> 80# endif 81# ifndef O_RDONLY 82# define O_RDONLY 0000 83# endif 84#endif 85 86#if defined(_MSC_VER) && (_MSC_VER < 1600) /* MSVC older than v10 */ 87typedef signed char int8_t; 88typedef signed short int16_t; 89typedef signed int int32_t; 90typedef signed __int64 int64_t; 91typedef unsigned char uint8_t; 92typedef unsigned short uint16_t; 93typedef unsigned int uint32_t; 94typedef unsigned __int64 uint64_t; 95# define PRId8 "d" 96# define PRId16 "d" 97# define PRId32 "d" 98# define PRId64 "I64d" 99# define INT8_C(c) c 100# define INT16_C(c) c 101# define INT32_C(c) c 102# define INT64_C(c) c ## i64 103#elif defined(__WATCOMC__) && (__WATCOMC__ <= 1220) /* WATCOM 12.2 or lower */ 104typedef signed char int8_t; 105typedef signed short int16_t; 106typedef signed long int int32_t; 107typedef signed __int64 int64_t; 108typedef unsigned char uint8_t; 109typedef unsigned short uint16_t; 110typedef unsigned long int uint32_t; 111typedef unsigned __int64 uint64_t; 112# define PRId8 "d" 113# define PRId16 "d" 114# define PRId32 "d" 115# define PRId64 "Ld" 116# define INT8_C(c) c 117# define INT16_C(c) c 118# define INT32_C(c) c ## L 119# define INT64_C(c) c ## i64 120#elif defined(__BORLANDC__) && (__BORLANDC__ < 0x600) /* Borland before 6.0 */ 121typedef signed char int8_t; 122typedef signed short int16_t; 123typedef signed long int int32_t; 124typedef signed __int64 int64_t; 125typedef unsigned char uint8_t; 126typedef unsigned short uint16_t; 127typedef unsigned long int uint32_t; 128typedef unsigned __int64 uint64_t; 129# define PRId8 "d" 130# define PRId16 "d" 131# define PRId32 "ld" 132# define PRId64 "I64Ld" 133# define INT8_C(c) c 134# define INT16_C(c) c 135# define INT32_C(c) c ## L 136# define INT64_C(c) c ## i64 137#elif defined(__FreeBSD__) && (__FreeBSD__ < 5) /* FreeBSD before 5.0 */ && !defined (_SYS_INTTYPES_H_) 138typedef signed char int8_t; 139typedef signed short int16_t; 140typedef signed long int int32_t; 141typedef signed long long int int64_t; 142typedef unsigned char uint8_t; 143typedef unsigned short uint16_t; 144typedef unsigned long int uint32_t; 145typedef unsigned long long int uint64_t; 146#elif defined(__CYGWIN__) && defined(__BIT_TYPES_DEFINED__) /* Cygwin defines intxx_t in sys/types.h instead of inttypes.h */ 147# include <cygwin/version.h> 148# if defined(CYGWIN_VERSION_DLL_MAJOR) && (CYGWIN_VERSION_DLL_MAJOR<1005) 149typedef unsigned char uint8_t; 150typedef __uint16_t uint16_t; 151typedef __uint32_t uint32_t; 152typedef __uint64_t uint64_t; 153# endif 154#elif defined(SASC) 155# error("Too old SAS/C compiler, sorry."); 156#elif defined(__SASC__) 157# if (__SASC__ < 750 ) /* SAS/C before 7.50 */ 158typedef signed char int8_t; 159typedef signed short int16_t; 160typedef signed long int int32_t; 161typedef signed long long int int64_t; 162typedef unsigned char uint8_t; 163typedef unsigned short uint16_t; 164typedef unsigned long int uint32_t; 165typedef unsigned long long int uint64_t; 166# endif 167#else 168# include <inttypes.h> 169# if !defined(INT8_MAX) && defined(INT16_MAX) 170/* int8_t is not mandatory */ 171typedef int_least8_t int8_t; 172# endif 173#endif 174 175#if !defined(PRId16) 176# define PRId8 "d" 177# define PRId16 "d" 178# define PRId32 "ld" 179# define PRId64 "lld" 180#elif !defined(PRId8) 181# define PRId8 "d" 182#endif 183#if !defined(INT16_C) 184# define INT8_C(c) c 185# define INT16_C(c) c 186# define INT32_C(c) c ## L 187# define INT64_C(c) c ## LL 188#elif !defined(INT8_C) 189# define INT8_C(c) c 190#endif 191#if !defined(INT16_MIN) 192# define INT8_MIN (-INT8_C(127)-1) 193# define INT8_MAX (INT8_C(127)) 194# define INT16_MIN (-INT16_C(32767)-1) 195# define INT16_MAX (INT16_C(32767)) 196# define INT32_MIN (-INT32_C(2147483647)-1) 197# define INT32_MAX (INT32_C(2147483647)) 198# define INT64_MIN (-INT64_C(9223372036854775807)-1) 199# define INT64_MAX (INT64_C(9223372036854775807)) 200#elif !defined(INT8_MIN) 201# define INT8_MIN (-INT8_C(127)-1) 202#endif 203 204 205/* 206 Endian stuff 207*/ 208#if defined(BSD) && (BSD >= 199103) 209# include <machine/endian.h> 210#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) 211/* bi-endian processor, current mode should be find in machine/endian.h file */ 212# include <machine/endian.h> 213#elif defined(linux) 214# include <endian.h> 215#endif 216 217 218 219#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER) 220# define BYTE_ORDER __BYTE_ORDER 221#endif 222 223#if !defined(LITTLE_ENDIAN) && defined(__LITTLE_ENDIAN) 224# define LITTLE_ENDIAN __LITTLE_ENDIAN 225#endif 226 227#if !defined(BIG_ENDIAN) && defined(__BIG_ENDIAN) 228# define BIG_ENDIAN __BIG_ENDIAN 229#endif 230 231#if !defined(LITTLE_ENDIAN) 232# define LITTLE_ENDIAN 1234 /* LSB first (vax, pc) */ 233#endif 234#if !defined(BIG_ENDIAN) 235# define BIG_ENDIAN 4321 /* MSB first (IBM, net) */ 236#endif 237#if !defined(PDP_ENDIAN) 238# define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ 239#endif 240 241#if !defined(BYTE_ORDER) && defined(BIT_ZERO_ON_RIGHT) 242# define BYTE_ORDER LITTLE_ENDIAN 243#elif !defined(BYTE_ORDER) && defined(BIT_ZERO_ON_LEFT) 244# define BYTE_ORDER BIG_ENDIAN 245#elif !defined(BYTE_ORDER) 246 247/* ARM */ 248# if defined(__ARMEL__) 249# define BYTE_ORDER LITTLE_ENDIAN 250# elif defined(__ARMEB__) 251# define BYTE_ORDER BIG_ENDIAN 252# elif defined(__arm__) 253# error "ARMs are bi-endian processors. Endianness is unknown for this system, please drop an e-mail to SmartEiffel@loria.fr" 254# endif 255 256/* HP RISC */ 257# if defined(__hppa__) || defined(__hppa) || defined(__hp9000) || \ 258 defined(__hp9000s300) || defined(hp9000s300) || \ 259 defined(__hp9000s700) || defined(hp9000s700) || \ 260 defined(__hp9000s800) || defined(hp9000s800) || defined(hp9000s820) 261# define BYTE_ORDER BIG_ENDIAN 262# endif 263 264/* IBM */ 265# if defined(ibm032) || defined(ibm370) || defined(_IBMR2) || \ 266 defined(IBM370) || defined(__MVS__) 267# define BYTE_ORDER BIG_ENDIAN 268# endif 269 270/* Intel x86 */ 271# if defined(i386) || defined(__i386__) || defined(__i386) || \ 272 defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL) || \ 273 defined(sun386) 274# define BYTE_ORDER LITTLE_ENDIAN 275# endif 276 277/* Intel Itanium */ 278# if defined(__ia64__) || defined(_IA64) || defined(__IA64__) || \ 279 defined(_M_IA64) 280# define BYTE_ORDER LITTLE_ENDIAN 281# endif 282 283/* Nationnal Semiconductor 32000 serie */ 284# if defined(ns32000) 285# define BYTE_ORDER LITTLE_ENDIAN 286# endif 287 288/* Motorola 68000 */ 289# if defined(mc68000) || defined(is68k) || defined(macII) || defined(m68k) 290# define BYTE_ORDER BIG_ENDIAN 291# endif 292 293/* MIPS */ 294# if defined(MIPSEL) || defined(_MIPSEL) 295# define BYTE_ORDER LITTLE_ENDIAN 296# elif defined(MIPSEB) || defined(_MIPSEB) 297# define BYTE_ORDER BIG_ENDIAN 298# elif defined(__mips__) || defined(__mips) || defined(__MIPS__) 299# error "MIPS are bi-endian processors. Endianness is unknown for this system, please drop an e-mail to SmartEiffel@loria.fr" 300# endif 301 302/* Power PC */ 303/* this processor is bi-endian, how to know if little-endian is set? */ 304# if defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || \ 305 defined(__ppc__) || defined(__ppc) || defined(_M_PPC) || \ 306 defined(__PPC) || defined(__PPC__) 307# define BYTE_ORDER BIG_ENDIAN 308# endif 309 310/* Pyramid 9810 */ 311# if defined(pyr) 312# define BYTE_ORDER BIG_ENDIAN 313# endif 314 315/* RS/6000 */ 316# if defined(__THW_RS6000) || defined(_IBMR2) || defined(_POWER) || \ 317 defined(_ARCH_PWR) || defined(_ARCH_PWR2) 318# define BYTE_ORDER BIG_ENDIAN 319# endif 320 321/* SPARC */ 322# if defined(__sparc__) || defined(sparc) || defined(__sparc) 323# define BYTE_ORDER BIG_ENDIAN 324# endif 325 326/* CCI Tahoe */ 327# if defined(tahoe) 328# define BYTE_ORDER BIG_ENDIAN 329# endif 330 331/* VAX */ 332# if defined(vax) || defined(VAX) || defined(__vax__) || defined(_vax_) || \ 333 defined(__vax) || defined(__VAX) 334# define BYTE_ORDER LITTLE_ENDIAN 335# endif 336 337/* ELATE is a virtual OS with a little endian Virtual Processor */ 338# if defined(__ELATE__) 339# define BYTE_ORDER LITTLE_ENDIAN 340# endif 341 342/* Miscellaneous little endian */ 343# if defined(wrltitan) 344# define BYTE_ORDER LITTLE_ENDIAN 345# endif 346 347/* Miscellaneous big endian */ 348# if defined(apollo) || defined(__convex__) || defined(_CRAY) || defined(sel) 349# define BYTE_ORDER BIG_ENDIAN 350# endif 351#endif 352 353 354#if !defined(BYTE_ORDER) 355# error "Unknown byte order. Add your system in above macros once you know your system type. Please drop an e-mail to SmartEiffel@loria.fr" 356#endif 357#if (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN) 358# error "Only little-endian and big-endian are valid at this time. Please drop an e-mail to SmartEiffel@loria.fr" 359#endif 360 361 362/* 363 Byte swapping stuff 364*/ 365extern void copy_swap_16(const uint16_t *src, uint16_t *dest, int count); 366 367 368/* Because ANSI C EXIT_* are not always defined: */ 369#ifndef EXIT_FAILURE 370# define EXIT_FAILURE 1 371#endif 372#ifndef EXIT_SUCCESS 373# define EXIT_SUCCESS 0 374#endif 375 376/* 377 On Linux glibc systems, we need to use sig.* versions of jmp_buf, 378 setjmp and longjmp to preserve the signal handling context. 379 Currently, the way I figured to detect this is if _SIGSET_H_types has 380 been defined in /usr/include/setjmp.h. 381 382 NOTE: with gcc, -ansi is used for SmartEiffel generated files EXCEPT in 383 -no_split mode. ANSI only recognizes the non-sig versions. 384*/ 385#if (defined(_SIGSET_H_types) && !defined(__STRICT_ANSI__)) 386# define JMP_BUF sigjmp_buf 387# define SETJMP(x) sigsetjmp( (x), 1) 388# define LONGJMP siglongjmp 389#else 390# define JMP_BUF jmp_buf 391# define SETJMP(x) setjmp( (x) ) 392# define LONGJMP longjmp 393#endif 394 395/* 396 Type to store reference objects Id: 397 */ 398typedef int Tid; 399typedef struct S0 T0; 400struct S0{Tid id;}; 401 402/* 403 The default channel used to print runtime error messages: 404*/ 405#define SE_ERR stderr 406 407/* 408 Eiffel type INTEGER_8 is #1: 409*/ 410typedef int8_t T1; 411#define EIF_INTEGER_8 T1 412#define M1 (INT8_C(0)) 413#define EIF_INTEGER_8_BITS (CHAR_BIT) 414#define EIF_MINIMUM_INTEGER_8 (INT8_MIN) 415#define EIF_MAXIMUM_INTEGER_8 (INT8_MAX) 416 417/* 418 Eiffel type INTEGER_16 is #10: 419*/ 420typedef int16_t T10; 421#define EIF_INTEGER_16 T10 422#define M10 (INT16_C(0)) 423#define EIF_INTEGER_16_BITS (CHAR_BIT*sizeof(T10t)) 424#define EIF_MINIMUM_INTEGER_16 (INT16_MIN) /*-32768*/ 425#define EIF_MAXIMUM_INTEGER_16 (INT16_MAX) /*+32767*/ 426 427/* 428 Eiffel type INTEGER or INTEGER_32 is #2: 429*/ 430typedef int32_t T2; 431#define EIF_INTEGER T2 432#define EIF_INTEGER_32 T2 433#define M2 (INT32_C(0)) 434#define EIF_INTEGER_BITS ((T2)(CHAR_BIT*sizeof(T2))) 435#define EIF_INTEGER_32_BITS EIF_INTEGER_BITS 436#define EIF_MINIMUM_INTEGER (INT32_MIN) 437#define EIF_MAXIMUM_INTEGER (INT32_MAX) 438 439/* 440 Eiffel type INTEGER_64 is #11: 441*/ 442typedef int64_t T11; 443#define EIF_INTEGER_64 T11 444#define M11 (INT64_C(0)) 445#define EIF_INTEGER_64_BITS (CHAR_BIT*sizeof(T11)) 446#define EIF_MINIMUM_INTEGER_64 (INT64_MIN) 447#define EIF_MAXIMUM_INTEGER_64 (INT64_MAX) 448 449/* 450 Eiffel type CHARACTER is #3: 451*/ 452typedef unsigned char T3; 453#define EIF_CHARACTER T3 454#define M3 (0) 455#define EIF_CHARACTER_BITS (CHAR_BIT) 456#define EIF_MINIMUM_CHARACTER_CODE (0) 457#define EIF_MAXIMUM_CHARACTER_CODE (255) 458#define T3code(x) ((T10)(x)) 459#define T3to_integer(x) ((signed char)(x)) 460#define T3to_integer_8(x) ((signed char)(x)) 461#define T3to_bit(x) (x) 462 463/* 464 Eiffel type REAL_32 is #4: 465*/ 466typedef float T4; 467typedef T4 real32_t; 468#define EIF_REAL_32 T4 469#define M4 (0.0) 470#define EIF_MINIMUM_REAL_32 (-(FLT_MAX)) 471#define EIF_MAXIMUM_REAL_32 (FLT_MAX) 472 473/* 474 Eiffel type REAL or REAL_64 is #5: 475*/ 476typedef double T5; 477typedef T5 real64_t; 478#define EIF_REAL_64 T5 479#define M5 (0.0) 480#define EIF_MINIMUM_REAL_64 (-(DBL_MAX)) 481#define EIF_MINIMUM_REAL (EIF_MINIMUM_REAL_64) 482#define EIF_MAXIMUM_REAL_64 (DBL_MAX) 483#define EIF_MAXIMUM_REAL (EIF_MAXIMUM_REAL_64) 484 485/* 486 Eiffel type REAL_EXTENDED is #12: 487*/ 488typedef long double T12; 489typedef T12 real_extended_t; 490#define EIF_REAL_EXTENDED T12 491#define M12 (0.0) 492#define EIF_MINIMUM_REAL_EXTENDED (-(DBL_MAX)) 493#define EIF_MAXIMUM_REAL_EXTENDED (DBL_MAX) 494 495/* 496 Eiffel type BOOLEAN is #6: 497*/ 498typedef char T6; 499#define EIF_BOOLEAN T6 500#define M6 (0) 501#define EIF_BOOLEAN_BITS (CHAR_BIT) 502 503/* 504 Eiffel type POINTER is #8: 505*/ 506typedef void* T8; 507#define EIF_POINTER T8 508/* Sometimes, NULL is defined as 0 */ 509#define M8 ((void*)NULL) 510#define EIF_POINTER_BITS (CHAR_BIT*sizeof(void*)) 511 512/* 513 To use type STRING on the C side: 514*/ 515#define EIF_STRING T7* 516 517/* 518 Some Other EIF_* defined in ETL: 519*/ 520#define eif_access(x) ((char*)(x)) 521#define EIF_REFERENCE T0* 522#define EIF_OBJ T0* 523#define EIF_OBJECT EIF_OBJ 524 525/* 526 Wrappers for `malloc' and `calloc': 527*/ 528void* se_malloc(size_t size); 529void* se_calloc(size_t nmemb, size_t size); 530void* se_realloc(void* src, size_t size); 531 532/* 533 die method. 534 */ 535void se_die(int code); 536 537/* 538 Runtime hooks. They allow different runtime modules to be quite independant. In time, they will also allow 539 thread-safe operations. 540 541 Currently known modules: 542 - boost 543 - no_check 544 - sedb 545 - gc 546 - print stack 547 - profile 548 - plugins 549 550 However, currently only profile uses this method. It will be extended to other modules later. 551 552 The currently defined hooks are described in the enum below (the names should be self-explanatory). 553 */ 554typedef enum { 555 SE_HANDLE_EXCEPTION_SET, /* called when an exception handler is set, prior to SETJMP */ 556 SE_HANDLE_EXCEPTION_CLEAR, /* called when a feature with an exception handler normally returns */ 557 SE_HANDLE_EXCEPTION_THROWN, /* called when an exception is thrown, prior to the LONGJMP */ 558 SE_HANDLE_ENTER_GC, /* called when gc_start() begins */ 559 SE_HANDLE_EXIT_GC, /* called when gc_start() ends */ 560 SE_HANDLE_ENTER_PRINT_STACK, /* called when se_print_run_time_stack() begins */ 561 SE_HANDLE_EXIT_PRINT_STACK, /* called when se_print_run_time_stack() ends */ 562 SE_HANDLE_NO_MORE_MEMORY, /* called by se_alloc() and co */ 563 SE_HANDLE_SEDB_BREAK, /* called when sedb stops the program */ 564 SE_HANDLE_SEDB_CONTINUE, /* called when sedb continues the program */ 565 SE_HANDLE_RUNTIME_ERROR, /* called when a runtime error is raised and not caught by an exception. Cannot be raised in boost mode. */ 566 SE_HANDLE_DIE_WITH_CODE, /* called when the program is stopped by the die_with_code feature. The data points to the int code. */ 567 SE_HANDLE_NORMAL_EXIT /* called when the program correctly terminates. The data is null. */ 568} se_handler_action_t; 569 570extern int handlers_count; 571typedef void se_runtime_handler_t(se_handler_action_t action, void*data); 572void register_handler(se_runtime_handler_t*handler); 573void _handle(se_handler_action_t action, void*data); 574 575#define handle(action,data) do{if(handlers_count>0)_handle(action,data);}while(0) 576 577#endif /* #ifndef _BASE_H */ 578#ifndef _HAD_BASE_H 579extern void*eiffel_root_object; 580 581typedef T3*T9; 582#endif 583/* Available Eiffel routines via -cecil: 584*/ 585T2 se_call(void* C);