PageRenderTime 33ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 3ms

/tool/gec/bootstrap/gec.h

http://github.com/gobo-eiffel/gobo
C Header | 18110 lines | 11880 code | 2824 blank | 3406 comment | 47 complexity | 5eea93f4e13c0e4b8197eddc6f7fcccd MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. #define GE_USE_THREADS
  2. /*
  3. description:
  4. "C declarations for the Gobo Eiffel runtime."
  5. system: "Gobo Eiffel Compiler"
  6. copyright: "Copyright (c) 2005-2020, Eric Bezault and others"
  7. license: "MIT License"
  8. date: "$Date$"
  9. revision: "$Revision$"
  10. */
  11. #ifndef GE_EIFFEL_H
  12. #define GE_EIFFEL_H
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  14. #pragma once
  15. #endif
  16. /* Class name mapping as defined in the FreeELKS library. */
  17. #ifndef EIF_INTEGER
  18. #define EIF_INTEGER EIF_INTEGER_32
  19. #endif
  20. #ifndef EIF_CHARACTER
  21. #define EIF_CHARACTER EIF_CHARACTER_8
  22. #endif
  23. #ifndef EIF_REAL
  24. #define EIF_REAL EIF_REAL_32
  25. #endif
  26. #ifndef EIF_DOUBLE
  27. #define EIF_DOUBLE EIF_REAL_64
  28. #endif
  29. #ifndef GE_ms
  30. #if EIF_CHARACTER == EIF_CHARACTER_8
  31. #define GE_ms(s,c) GE_ms8((s),(c))
  32. #else
  33. #define GE_ms(s,c) GE_ms32((s),(c))
  34. #endif
  35. #endif
  36. #if defined(__USE_POSIX) || defined(__unix__) || defined(_POSIX_C_SOURCE)
  37. #include <unistd.h>
  38. #endif
  39. #if !defined(WIN32) && \
  40. (defined(WINVER) || defined(_WIN32_WINNT) || defined(_WIN32) || \
  41. defined(__WIN32__) || defined(__TOS_WIN__) || defined(_MSC_VER) || \
  42. defined(__MINGW32__))
  43. #define WIN32 1
  44. #endif
  45. #ifdef WIN32
  46. #define EIF_WINDOWS 1
  47. #include <windows.h>
  48. #endif
  49. /* See https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
  50. #if (defined(macintosh) || defined(Macintosh))
  51. #define EIF_MAC 1
  52. #define EIF_MACOSX 1
  53. #endif
  54. #if (defined(__APPLE__) && defined(__MACH__))
  55. /* Apparently ISE does not define EIF_MASOSX for Mac OS X >=10.4 (see EXECUTION_ENVIRONMENT.available_cpu_count) */
  56. #define EIF_MAC 1
  57. #endif
  58. #if (defined(VMS) || defined(__VMS))
  59. #define EIF_VMS 1
  60. #endif
  61. #if (defined(__VXWORKS__) || defined(__vxworks))
  62. #define EIF_VXWORKS 1
  63. #endif
  64. #define BYTEORDER 0x1234
  65. #include <stdlib.h>
  66. #include <stdio.h>
  67. #include <stdarg.h>
  68. #include <string.h>
  69. #include <stddef.h>
  70. #define EIF_OS_WINNT 1
  71. #define EIF_OS_LINUX 2
  72. #define EIF_OS_DARWIN 4
  73. #define EIF_OS_VXWORKS 11
  74. #define EIF_OS_VMS 12
  75. /* Platform definition */
  76. /* Unix definition */
  77. #define EIF_IS_UNIX EIF_TRUE
  78. #define EIF_OS EIF_OS_LINUX
  79. /* Windows definition */
  80. #ifdef EIF_WINDOWS
  81. #define EIF_IS_WINDOWS EIF_TRUE
  82. #undef EIF_OS
  83. #define EIF_OS EIF_OS_WINNT
  84. #undef EIF_IS_UNIX
  85. #define EIF_IS_UNIX EIF_FALSE
  86. #else
  87. #define EIF_IS_WINDOWS EIF_FALSE
  88. #endif
  89. /* VMS definition */
  90. #ifdef EIF_VMS
  91. #define EIF_IS_VMS EIF_TRUE
  92. #undef EIF_OS
  93. #define EIF_OS EIF_OS_VMS
  94. #undef EIF_IS_UNIX
  95. #define EIF_IS_UNIX EIF_FALSE
  96. #else
  97. #define EIF_IS_VMS EIF_FALSE
  98. #endif
  99. /* MAC definition */
  100. #ifdef EIF_MAC
  101. #define EIF_IS_MAC EIF_TRUE
  102. #undef EIF_OS
  103. #define EIF_OS EIF_OS_DARWIN
  104. #undef EIF_IS_UNIX
  105. #define EIF_IS_UNIX EIF_FALSE
  106. #else
  107. #define EIF_IS_MAC EIF_FALSE
  108. #endif
  109. /* VxWorks definition */
  110. #ifdef EIF_VXWORKS
  111. #define EIF_IS_VXWORKS EIF_TRUE
  112. #undef EIF_OS
  113. #define EIF_OS EIF_OS_VXWORKS
  114. #undef EIF_IS_UNIX
  115. #define EIF_IS_UNIX EIF_FALSE
  116. #else
  117. #define EIF_IS_VXWORKS EIF_FALSE
  118. #endif
  119. #ifdef __cplusplus
  120. extern "C" {
  121. #endif
  122. #ifdef _MSC_VER /* MSVC */
  123. typedef signed char int8_t;
  124. typedef signed short int16_t;
  125. typedef signed int int32_t;
  126. typedef signed __int64 int64_t;
  127. typedef unsigned char uint8_t;
  128. typedef unsigned short uint16_t;
  129. typedef unsigned int uint32_t;
  130. typedef unsigned __int64 uint64_t;
  131. #else
  132. #if defined (__BORLANDC__) && (__BORLANDC__ < 0x600) /* Borland before 6.0 */
  133. typedef signed char int8_t;
  134. typedef signed short int16_t;
  135. typedef signed long int int32_t;
  136. typedef signed __int64 int64_t;
  137. typedef unsigned char uint8_t;
  138. typedef unsigned short uint16_t;
  139. typedef unsigned long int uint32_t;
  140. typedef unsigned __int64 uint64_t;
  141. #else
  142. #include <inttypes.h>
  143. #endif
  144. #endif
  145. /* Portable integer pointers */
  146. #ifdef EIF_WINDOWS
  147. #ifndef _INTPTR_T_DEFINED
  148. #define _INTPTR_T_DEFINED
  149. #ifdef _WIN64
  150. typedef __int64 intptr_t;
  151. #else
  152. typedef int intptr_t;
  153. #endif
  154. #endif
  155. #ifndef _UINTPTR_T_DEFINED
  156. #define _UINTPTR_T_DEFINED
  157. #ifdef _WIN64
  158. typedef unsigned __int64 uintptr_t;
  159. #else
  160. typedef unsigned int uintptr_t;
  161. #endif
  162. #endif
  163. #endif
  164. /* C type for underlying integer type identifying object's dynamic type. */
  165. typedef uint16_t EIF_TYPE_INDEX;
  166. /*
  167. * Abstraction representing an Eiffel type.
  168. * It is made of a compiler type-id,
  169. * and of some annotations (attached/detachable/separate/variant/frozen).
  170. */
  171. typedef struct eif_type {
  172. EIF_TYPE_INDEX id;
  173. EIF_TYPE_INDEX annotations;
  174. } EIF_TYPE;
  175. /*
  176. * Since EIF_TYPE and EIF_ENCODED_TYPE have the same size, the encoded version
  177. * is basically a memcpy version of the EIF_TYPE representation.
  178. * It is used to provide backward compatibility to most Eiffel and
  179. * C APIs manipulating types as an INTEGER.
  180. */
  181. typedef int32_t EIF_ENCODED_TYPE;
  182. typedef EIF_ENCODED_TYPE EIF_TYPE_ID;
  183. #define EIF_NO_TYPE (EIF_TYPE_ID)(-1)
  184. /* Basic Eiffel types */
  185. typedef char EIF_BOOLEAN;
  186. typedef unsigned char EIF_CHARACTER_8;
  187. typedef uint32_t EIF_CHARACTER_32;
  188. typedef int8_t EIF_INTEGER_8;
  189. typedef int16_t EIF_INTEGER_16;
  190. typedef int32_t EIF_INTEGER_32;
  191. typedef int64_t EIF_INTEGER_64;
  192. typedef uint8_t EIF_NATURAL_8;
  193. typedef uint16_t EIF_NATURAL_16;
  194. typedef uint32_t EIF_NATURAL_32;
  195. typedef uint64_t EIF_NATURAL_64;
  196. typedef void* EIF_POINTER;
  197. typedef float EIF_REAL_32;
  198. typedef double EIF_REAL_64;
  199. typedef struct {EIF_TYPE_INDEX id; uint16_t flags;} EIF_ANY;
  200. typedef EIF_ANY* EIF_REFERENCE;
  201. typedef struct {EIF_TYPE_INDEX id; uint16_t flags; EIF_REFERENCE area; EIF_INTEGER count;} EIF_STRING;
  202. typedef struct {EIF_TYPE_INDEX id; uint16_t flags; uint32_t offset; EIF_INTEGER count; EIF_INTEGER capacity;} EIF_SPECIAL;
  203. #ifdef EIF_WINDOWS
  204. typedef wchar_t EIF_NATIVE_CHAR;
  205. #else
  206. typedef char EIF_NATIVE_CHAR;
  207. #endif
  208. typedef EIF_NATIVE_CHAR* EIF_FILENAME;
  209. #define EIF_VOID ((EIF_REFERENCE)0)
  210. #define EIF_FALSE ((EIF_BOOLEAN)'\0')
  211. #define EIF_TRUE ((EIF_BOOLEAN)'\1')
  212. #define EIF_TEST(x) ((x) ? EIF_TRUE : EIF_FALSE)
  213. #define EIF_IS_WORKBENCH EIF_FALSE
  214. #define EIF_POINTER_DISPLAY "lX"
  215. /* For INTEGER and NATURAL manifest constants */
  216. #define GE_int8(x) x
  217. #define GE_nat8(x) x
  218. #define GE_int16(x) x
  219. #define GE_nat16(x) x
  220. #define GE_int32(x) x##L
  221. #define GE_nat32(x) x##U
  222. #if defined (_MSC_VER) && (_MSC_VER < 1400) /* MSC older than v8 */
  223. #define GE_int64(x) x##i64
  224. #define GE_nat64(x) x##ui64
  225. #elif defined(__BORLANDC__) && (__BORLANDC__ < 0x600) /* Borland before 6.0 */
  226. #define GE_int64(x) x##i64
  227. #define GE_nat64(x) x##ui64
  228. #else /* ISO C 99 */
  229. #define GE_int64(x) x##LL
  230. #define GE_nat64(x) x##ULL
  231. #endif
  232. #ifdef __LCC__
  233. /* lcc-win32 reports a constant overflow for -21474836478. */
  234. #define GE_min_int32 (-GE_int32(2147483647)-GE_int32(1))
  235. #else
  236. #define GE_min_int32 GE_int32(-2147483648)
  237. #endif
  238. #define GE_max_int32 GE_int32(2147483647)
  239. #if defined(__LCC__) || defined(__GNUC__) || defined(__MINGW32__)
  240. /* lcc-win32 reports a constant overflow for -9223372036854775808. */
  241. /* gcc and mingw-win64 warn that integer constant is so large that it is unsigned. */
  242. #define GE_min_int64 (-GE_int64(9223372036854775807)-GE_int64(1))
  243. #else
  244. #define GE_min_int64 GE_int64(-9223372036854775808)
  245. #endif
  246. #if defined(__LCC__) && !defined(_WIN64)
  247. /* lcc-win32 does not consider 64 bit constants as constants in case statement. */
  248. #define GE_case_int64(x) ((int32_t)(x))
  249. #define GE_case_nat64(x) ((uint32_t)(x))
  250. #else
  251. #define GE_case_int64(x) (x)
  252. #define GE_case_nat64(x) (x)
  253. #endif
  254. #ifdef _WIN64
  255. #define GE_IS_64_BITS EIF_TRUE
  256. #else
  257. #define GE_IS_64_BITS EIF_TEST(sizeof(void*)==64)
  258. #endif
  259. /* Posix threads */
  260. #if !defined(EIF_WINDOWS)
  261. #define GE_USE_POSIX_THREADS
  262. #endif
  263. #ifdef _MSC_VER /* MSVC */
  264. /* MSVC does not support ISO C 99's 'snprintf' from stdio.h */
  265. #define snprintf(a,b,c,d) sprintf(a,c,d)
  266. #endif
  267. /*
  268. * Gobo compiler version.
  269. * Starts with 6080 (looks like GOBO) followed by 5 digits.
  270. */
  271. #define GE_compiler_version() 608000001
  272. /*
  273. Interoperability with ISE.
  274. */
  275. #define RTI64C(x) GE_int64(x)
  276. #define EIF_OBJECT EIF_REFERENCE
  277. #define EIF_OBJ EIF_OBJECT
  278. #define OVERHEAD sizeof(EIF_ANY)
  279. /* Function pointer call to make sure all arguments are correctly pushed onto stack. */
  280. /* FUNCTION_CAST is for standard C calls. */
  281. /* FUNCTION_CAST_TYPE is for non-standard C calls. */
  282. #define FUNCTION_CAST(r_type,arg_types) (r_type (*) arg_types)
  283. #define FUNCTION_CAST_TYPE(r_type,call_type,arg_types) (r_type (call_type *) arg_types)
  284. #define SIGBLOCK
  285. #define SIGRESUME
  286. #define rt_public /* default C scope */
  287. #define rt_private static /* static outside a block means private */
  288. #define rt_shared /* data shared between modules, but not public */
  289. typedef intptr_t rt_int_ptr;
  290. typedef uintptr_t rt_uint_ptr;
  291. #define RTMS(s) GE_str8(s)
  292. #define RTMS_EX(s,c) GE_ms8((s),(c))
  293. #ifdef __cplusplus
  294. }
  295. #endif
  296. #endif
  297. /*
  298. description:
  299. "C types used to implement class THREAD and related threading facilities"
  300. system: "Gobo Eiffel Compiler"
  301. copyright: "Copyright (c) 2017, Eric Bezault and others"
  302. license: "MIT License"
  303. date: "$Date$"
  304. revision: "$Revision$"
  305. */
  306. #ifndef GE_THREAD_TYPES_H
  307. #define GE_THREAD_TYPES_H
  308. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  309. #pragma once
  310. #endif
  311. #ifdef GE_USE_THREADS
  312. #define EIF_THREADS
  313. #ifdef GE_USE_POSIX_THREADS
  314. #define EIF_POSIX_THREADS
  315. #endif
  316. #ifndef GE_EIFFEL_H
  317. #include "ge_eiffel.h"
  318. #endif
  319. #ifdef GE_USE_POSIX_THREADS
  320. #include <pthread.h>
  321. #include <semaphore.h>
  322. #elif defined EIF_WINDOWS
  323. #include <windows.h>
  324. #include <process.h>
  325. #endif
  326. #ifdef __cplusplus
  327. extern "C" {
  328. #endif
  329. #ifdef GE_USE_POSIX_THREADS
  330. #define EIF_THR_TYPE pthread_t
  331. #define EIF_CS_TYPE pthread_mutex_t
  332. #define EIF_MUTEX_TYPE pthread_mutex_t
  333. #define EIF_COND_TYPE pthread_cond_t
  334. #define EIF_SEM_TYPE sem_t
  335. #define EIF_RWL_TYPE pthread_rwlock_t
  336. #elif defined EIF_WINDOWS
  337. #define EIF_THR_TYPE HANDLE
  338. #define EIF_CS_TYPE CRITICAL_SECTION
  339. #define EIF_MUTEX_TYPE CRITICAL_SECTION
  340. #define EIF_SEM_TYPE HANDLE
  341. typedef struct {
  342. /* Semaphore used to queue up threads waiting for the condition to become signaled. */
  343. EIF_SEM_TYPE* semaphore;
  344. /* Serialize access to fields of Current. */
  345. EIF_CS_TYPE* csection;
  346. /* Number of waiters. */
  347. unsigned long num_waiting;
  348. /* Number of already awoken. */
  349. unsigned long num_wake;
  350. /* Number of time we signaled/broadcasted for improving fairness.
  351. * This ensures one thread won't steal wakeups from other threads in queue. */
  352. unsigned long generation;
  353. } EIF_COND_TYPE;
  354. typedef struct {
  355. EIF_MUTEX_TYPE* m; /* Internal monitor lock. */
  356. int rwlock; /* >0 = # readers, <0 = writer, 0 = none */
  357. EIF_COND_TYPE* readers_ok; /* Start waiting readers. */
  358. unsigned int waiting_writers; /* Number of waiting writers. */
  359. EIF_COND_TYPE* writers_ok; /* Start a waiting writer. */
  360. } EIF_RWL_TYPE;
  361. #endif
  362. typedef struct {
  363. unsigned int priority;
  364. unsigned int stack_size;
  365. } EIF_THR_ATTR_TYPE;
  366. /* Struct for thread context. */
  367. typedef struct GE_thread_context_struct GE_thread_context;
  368. struct GE_thread_context_struct {
  369. EIF_THR_TYPE thread_id; /* Thread identifier for associated thread. */
  370. EIF_REFERENCE current; /* Eiffel root object. */
  371. void (*routine)(EIF_REFERENCE); /* Eiffel routine. */
  372. void (*set_terminated)(EIF_REFERENCE,EIF_BOOLEAN); /* Eiffel routine to set {THREAD}.terminated. */
  373. unsigned int initial_priority; /* Initial priority. */
  374. EIF_THR_TYPE last_thread_id; /* Last thread created from current thread. */
  375. volatile int n_children; /* Number of direct thread children. */
  376. EIF_MUTEX_TYPE* children_mutex; /* Mutex to wait for thread children. */
  377. EIF_COND_TYPE* children_cond; /* Condition variable to wait for thread children. */
  378. GE_thread_context* parent_context; /* Context of parent thread, NULL if main thread. */
  379. int thread_exiting; /* Has current thread already called GE_thread_exit? */
  380. volatile int is_alive; /* Is Current thread still alive? */
  381. };
  382. #ifdef __cplusplus
  383. }
  384. #endif
  385. #endif
  386. #endif
  387. /*
  388. description:
  389. "C functions used to implement once features"
  390. system: "Gobo Eiffel Compiler"
  391. copyright: "Copyright (c) 2017, Eric Bezault and others"
  392. license: "MIT License"
  393. date: "$Date$"
  394. revision: "$Revision$"
  395. */
  396. #ifndef GE_ONCE_H
  397. #define GE_ONCE_H
  398. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  399. #pragma once
  400. #endif
  401. #ifndef GE_EIFFEL_H
  402. #include "ge_eiffel.h"
  403. #endif
  404. #ifdef __cplusplus
  405. extern "C" {
  406. #endif
  407. /*
  408. * Struct to keep track of the call status
  409. * and results of once features.
  410. */
  411. typedef struct {
  412. EIF_BOOLEAN* boolean_value;
  413. EIF_REFERENCE* boolean_exception;
  414. unsigned char* boolean_status;
  415. unsigned int boolean_count;
  416. EIF_CHARACTER_8* character_8_value;
  417. EIF_REFERENCE* character_8_exception;
  418. unsigned char* character_8_status;
  419. unsigned int character_8_count;
  420. EIF_CHARACTER_32* character_32_value;
  421. EIF_REFERENCE* character_32_exception;
  422. unsigned char* character_32_status;
  423. unsigned int character_32_count;
  424. EIF_INTEGER_8* integer_8_value;
  425. EIF_REFERENCE* integer_8_exception;
  426. unsigned char* integer_8_status;
  427. unsigned int integer_8_count;
  428. EIF_INTEGER_16* integer_16_value;
  429. EIF_REFERENCE* integer_16_exception;
  430. unsigned char* integer_16_status;
  431. unsigned int integer_16_count;
  432. EIF_INTEGER_32* integer_32_value;
  433. EIF_REFERENCE* integer_32_exception;
  434. unsigned char* integer_32_status;
  435. unsigned int integer_32_count;
  436. EIF_INTEGER_64* integer_64_value;
  437. EIF_REFERENCE* integer_64_exception;
  438. unsigned char* integer_64_status;
  439. unsigned int integer_64_count;
  440. EIF_NATURAL_8* natural_8_value;
  441. EIF_REFERENCE* natural_8_exception;
  442. unsigned char* natural_8_status;
  443. unsigned int natural_8_count;
  444. EIF_NATURAL_16* natural_16_value;
  445. EIF_REFERENCE* natural_16_exception;
  446. unsigned char* natural_16_status;
  447. unsigned int natural_16_count;
  448. EIF_NATURAL_32* natural_32_value;
  449. EIF_REFERENCE* natural_32_exception;
  450. unsigned char* natural_32_status;
  451. unsigned int natural_32_count;
  452. EIF_NATURAL_64* natural_64_value;
  453. EIF_REFERENCE* natural_64_exception;
  454. unsigned char* natural_64_status;
  455. unsigned int natural_64_count;
  456. EIF_POINTER* pointer_value;
  457. EIF_REFERENCE* pointer_exception;
  458. unsigned char* pointer_status;
  459. unsigned int pointer_count;
  460. EIF_REAL_32* real_32_value;
  461. EIF_REFERENCE* real_32_exception;
  462. unsigned char* real_32_status;
  463. unsigned int real_32_count;
  464. EIF_REAL_64* real_64_value;
  465. EIF_REFERENCE* real_64_exception;
  466. unsigned char* real_64_status;
  467. unsigned int real_64_count;
  468. EIF_REFERENCE* reference_value;
  469. EIF_REFERENCE* reference_exception;
  470. unsigned char* reference_status;
  471. unsigned int reference_count;
  472. EIF_REFERENCE* procedure_exception;
  473. unsigned char* procedure_status;
  474. unsigned int procedure_count;
  475. } GE_onces;
  476. /*
  477. * Variable to keep track of the call status
  478. * and results of once-per-process features.
  479. */
  480. extern GE_onces* GE_process_onces;
  481. /*
  482. * Initialize `GE_process_onces'.
  483. */
  484. extern void GE_init_onces(
  485. unsigned int a_boolean_count,
  486. unsigned int a_character_8_count,
  487. unsigned int a_character_32_count,
  488. unsigned int a_integer_8_count,
  489. unsigned int a_integer_16_count,
  490. unsigned int a_integer_32_count,
  491. unsigned int a_integer_64_count,
  492. unsigned int a_natural_8_count,
  493. unsigned int a_natural_16_count,
  494. unsigned int a_natural_32_count,
  495. unsigned int a_natural_64_count,
  496. unsigned int a_pointer_count,
  497. unsigned int a_real_32_count,
  498. unsigned int a_real_64_count,
  499. unsigned int a_reference_count,
  500. unsigned int a_procedure_count);
  501. /*
  502. * Create a new 'GE_onces' struct which can deal with the
  503. * numbers of once features passed as argument.
  504. */
  505. extern GE_onces* GE_new_onces(
  506. unsigned int a_boolean_count,
  507. unsigned int a_character_8_count,
  508. unsigned int a_character_32_count,
  509. unsigned int a_integer_8_count,
  510. unsigned int a_integer_16_count,
  511. unsigned int a_integer_32_count,
  512. unsigned int a_integer_64_count,
  513. unsigned int a_natural_8_count,
  514. unsigned int a_natural_16_count,
  515. unsigned int a_natural_32_count,
  516. unsigned int a_natural_64_count,
  517. unsigned int a_pointer_count,
  518. unsigned int a_real_32_count,
  519. unsigned int a_real_64_count,
  520. unsigned int a_reference_count,
  521. unsigned int a_procedure_count);
  522. /*
  523. * Free memory allocated by `a_onces'.
  524. */
  525. extern void GE_free_onces(GE_onces* a_onces);
  526. #ifdef __cplusplus
  527. }
  528. #endif
  529. #endif
  530. /*
  531. description:
  532. "C functions used to implement class EXCEPTION"
  533. system: "Gobo Eiffel Compiler"
  534. copyright: "Copyright (c) 2007-2018, Eric Bezault and others"
  535. license: "MIT License"
  536. date: "$Date$"
  537. revision: "$Revision$"
  538. */
  539. #ifndef GE_EXCEPTION_H
  540. #define GE_EXCEPTION_H
  541. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  542. #pragma once
  543. #endif
  544. #ifndef GE_EIFFEL_H
  545. #include "ge_eiffel.h"
  546. #endif
  547. #ifndef GE_ONCE_H
  548. #include "ge_once.h"
  549. #endif
  550. #ifdef GE_USE_THREADS
  551. #ifndef GE_THREAD_TYPES_H
  552. #include "ge_thread_types.h"
  553. #endif
  554. #endif
  555. #include <setjmp.h>
  556. /*
  557. * On Linux glibc systems, we need to use sig* versions of jmp_buf,
  558. * setjmp and longjmp to preserve the signal handling context.
  559. * One way to detect this is if _SIGSET_H_types has
  560. * been defined in /usr/include/setjmp.h.
  561. * NOTE: ANSI only recognizes the non-sig versions.
  562. */
  563. #if (defined(_SIGSET_H_types) && !defined(__STRICT_ANSI__))
  564. #define GE_jmp_buf sigjmp_buf
  565. #define GE_setjmp(x) sigsetjmp((x),1)
  566. #define GE_longjmp(x,y) siglongjmp((x),(y))
  567. #else
  568. #define GE_jmp_buf jmp_buf
  569. #define GE_setjmp(x) setjmp((x))
  570. #define GE_longjmp(x,y) longjmp((x),(y))
  571. #endif
  572. #ifdef __cplusplus
  573. extern "C" {
  574. #endif
  575. /*
  576. * Predefined exception codes.
  577. */
  578. #define GE_EX_VOID 1 /* Feature applied to void reference */
  579. #define GE_EX_MEM 2 /* No more memory */
  580. #define GE_EX_PRE 3 /* Pre-condition violated */
  581. #define GE_EX_POST 4 /* Post-condition violated */
  582. #define GE_EX_FLOAT 5 /* Floating point exception (signal SIGFPE) */
  583. #define GE_EX_CINV 6 /* Class invariant violated */
  584. #define GE_EX_CHECK 7 /* Check instruction violated */
  585. #define GE_EX_FAIL 8 /* Routine failure */
  586. #define GE_EX_WHEN 9 /* Unmatched inspect value */
  587. #define GE_EX_VAR 10 /* Non-decreasing loop variant */
  588. #define GE_EX_LINV 11 /* Loop invariant violated */
  589. #define GE_EX_SIG 12 /* Operating system signal */
  590. #define GE_EX_BYE 13 /* Eiffel run-time panic */
  591. #define GE_EX_RESC 14 /* Exception in rescue clause */
  592. #define GE_EX_OMEM 15 /* Out of memory (cannot be ignored) */
  593. #define GE_EX_RES 16 /* Resumption failed (retry did not succeed) */
  594. #define GE_EX_CDEF 17 /* Create on deferred */
  595. #define GE_EX_EXT 18 /* External event */
  596. #define GE_EX_VEXP 19 /* Void assigned to expanded */
  597. #define GE_EX_HDLR 20 /* Exception in signal handler */
  598. #define GE_EX_IO 21 /* I/O error */
  599. #define GE_EX_SYS 22 /* Operating system error */
  600. #define GE_EX_RETR 23 /* Retrieval error */
  601. #define GE_EX_PROG 24 /* Developer exception */
  602. #define GE_EX_FATAL 25 /* Eiffel run-time fatal error */
  603. #define GE_EX_DOL 26 /* $ applied to melted feature */
  604. #define GE_EX_ISE_IO 27 /* I/O error raised by the ISE Eiffel runtime */
  605. #define GE_EX_COM 28 /* COM error raised by EiffelCOM runtime */
  606. #define GE_EX_RT_CHECK 29 /* Runtime check error such as out-of-bound array access */
  607. #define GE_EX_OLD 30 /* Old violation */
  608. #define GE_EX_SEL 31 /* Serialization failure */
  609. #define GE_EX_DIRTY 32 /* SCOOP processor dirty exception. */
  610. #define GE_EX_NEX 32 /* Number of internal exceptions */
  611. /*
  612. * String buffer used to build the exception trace.
  613. */
  614. typedef struct GE_exception_trace_buffer_struct GE_exception_trace_buffer;
  615. struct GE_exception_trace_buffer_struct {
  616. char* area;
  617. uint32_t count;
  618. uint32_t capacity;
  619. };
  620. /*
  621. * Information about the feature being executed.
  622. */
  623. typedef struct GE_call_struct GE_call;
  624. struct GE_call_struct {
  625. #ifdef GE_USE_CURRENT_IN_EXCEPTION_TRACE
  626. void* object; /* Current object */
  627. #endif
  628. const char* class_name;
  629. const char* feature_name;
  630. GE_call* caller; /* previous feature in the call chain */
  631. };
  632. /*
  633. * Context of features containing a rescue clause.
  634. */
  635. typedef struct GE_rescue_struct GE_rescue;
  636. struct GE_rescue_struct {
  637. GE_jmp_buf jb;
  638. GE_rescue* previous; /* previous context in the call chain */
  639. };
  640. /*
  641. * Information about the execution context.
  642. * One such struct per thread.
  643. */
  644. typedef struct GE_context_struct GE_context;
  645. struct GE_context_struct {
  646. GE_call* call; /* Call stack */
  647. uint32_t in_assertion; /* Is an assertion evaluated? */
  648. GE_rescue* last_rescue; /* Context of last feature entered containing a rescue clause */
  649. uint32_t in_rescue; /* Number of rescue clauses currently being executed */
  650. EIF_REFERENCE exception_manager; /* Exception manager */
  651. char raising_exception; /* Is an exception currently being raised? */
  652. char exception_trace_enabled; /* Should exception trace be displayed? */
  653. long exception_code; /* Code of the exception currently being raised, 0 otherwise */
  654. const char* exception_tag; /* Tag of the exception currently being raised, NULL otherwise */
  655. GE_exception_trace_buffer exception_trace_buffer; /* String buffer used to build the exception trace */
  656. GE_exception_trace_buffer last_exception_trace; /* Last non-routine-failure exception trace */
  657. int pre_ecma_mapping_status; /* Do we map old names to new name? (i.e. STRING to STRING_8, INTEGER to INTEGER_32, ...). */
  658. #ifdef GE_USE_THREADS
  659. GE_thread_context* thread; /* Thread context */
  660. GE_onces* process_onces; /* Cache for status and results of onces-per-process */
  661. GE_onces* thread_onces; /* Status and results of onces-per-thread */
  662. void* wel_per_thread_data; /* WEL private data */
  663. #endif
  664. };
  665. /*
  666. * Default initialization for `GE_context'.
  667. */
  668. extern GE_context GE_default_context;
  669. /*
  670. * Execution context of main thread.
  671. */
  672. extern GE_context* GE_main_context;
  673. /*
  674. * Execution context of current thread.
  675. */
  676. extern GE_context* GE_current_context(void);
  677. /*
  678. * Initialization of exception handling.
  679. */
  680. extern void GE_init_exception(GE_context* context);
  681. /*
  682. * Free memory allocated in `a_context' for exception handling.
  683. */
  684. extern void GE_free_exception(GE_context* a_context);
  685. /*
  686. * Pointer to function to create a new exception manager object
  687. * (of type ISE_EXCEPTION_MANAGER).
  688. */
  689. extern EIF_REFERENCE (*GE_new_exception_manager)(EIF_BOOLEAN);
  690. /*
  691. * Pointer to Eiffel routine ISE_EXCEPTION_MANAGER.init_exception_manager.
  692. */
  693. extern void (*GE_init_exception_manager)(GE_context*, EIF_REFERENCE);
  694. /*
  695. * Pointer to Eiffel routine ISE_EXCEPTION_MANAGER.last_exception.
  696. */
  697. extern EIF_REFERENCE (*GE_last_exception)(GE_context*, EIF_REFERENCE);
  698. /*
  699. * Pointer to Eiffel routine ISE_EXCEPTION_MANAGER.once_raise.
  700. */
  701. extern void (*GE_once_raise)(GE_context*, EIF_REFERENCE, EIF_REFERENCE);
  702. /*
  703. * Pointer to Eiffel routine ISE_EXCEPTION_MANAGER.set_exception_data.
  704. */
  705. extern void (*GE_set_exception_data)(GE_context*, EIF_REFERENCE, EIF_INTEGER_32, EIF_BOOLEAN, EIF_INTEGER_32, EIF_INTEGER_32, EIF_REFERENCE, EIF_REFERENCE, EIF_REFERENCE, EIF_REFERENCE, EIF_REFERENCE, EIF_REFERENCE, EIF_INTEGER_32, EIF_BOOLEAN);
  706. /*
  707. * Exception tag associated with `a_code'.
  708. */
  709. extern char* GE_exception_tag(long a_code);
  710. /*
  711. * Raise an exception with code `a_code'.
  712. */
  713. extern void GE_raise(long a_code);
  714. /*
  715. * Raise an exception with code `a_code' and message `msg'.
  716. */
  717. extern void GE_raise_with_message(long a_code, const char* msg);
  718. /*
  719. * Raise an exception from EXCEPTION_MANAGER.
  720. */
  721. extern void GE_developer_raise(long a_code, char* a_meaning, char* a_message);
  722. /*
  723. * Raise exception which was raised the first time a once routine
  724. * was executed when executing it again.
  725. */
  726. extern void GE_raise_once_exception(GE_context* a_context, EIF_REFERENCE a_exception);
  727. /*
  728. * Exception, if any, which was last raised in `a_context'.
  729. */
  730. extern EIF_REFERENCE GE_last_exception_raised(GE_context* a_context);
  731. /*
  732. * Jump to execute the rescue of the last routine with a rescue
  733. * in the call stack.
  734. */
  735. extern void GE_jump_to_last_rescue(GE_context* a_context);
  736. /*
  737. * Set `in_assertion' to 'not b'.
  738. * Return the opposite of previous value.
  739. */
  740. extern EIF_BOOLEAN GE_check_assert(EIF_BOOLEAN b);
  741. /*
  742. * Check whether the type id of `obj' is not in `type_ids'.
  743. * If it is, then raise a CAT-call exception. Don't do anything if `obj' is Void.
  744. * `nb' is the number of ids in `type_ids' and is expected to be >0.
  745. * `type_ids' is sorted in increasing order.
  746. * Return `obj'.
  747. */
  748. #define GE_catcall(obj,type_ids,nb) GE_check_catcall((obj),(type_ids),(nb))
  749. extern EIF_REFERENCE GE_check_catcall(EIF_REFERENCE obj, EIF_TYPE_INDEX type_ids[], int nb);
  750. /*
  751. * Check whether `obj' is Void.
  752. * If it is, then raise a call-on-void-target exception.
  753. * Return `obj'.
  754. */
  755. #define GE_void(obj) (!(obj)?GE_check_void(obj):(obj))
  756. extern EIF_REFERENCE GE_check_void(EIF_REFERENCE obj);
  757. /*
  758. * Check whether `ptr' is a null pointer.
  759. * If it is, then raise a no-more-memory exception.
  760. * Return `ptr'.
  761. */
  762. #define GE_null(ptr) GE_check_null(ptr)
  763. extern void* GE_check_null(void* ptr);
  764. #ifdef EIF_WINDOWS
  765. /*
  766. * Set default exception handler.
  767. */
  768. extern void GE_set_windows_exception_filter(void);
  769. #endif
  770. #ifdef __cplusplus
  771. }
  772. #endif
  773. #endif
  774. /*
  775. description:
  776. "C functions used to implement class THREAD and related threading facilities"
  777. system: "Gobo Eiffel Compiler"
  778. copyright: "Copyright (c) 2016-2017, Eric Bezault and others"
  779. license: "MIT License"
  780. date: "$Date$"
  781. revision: "$Revision$"
  782. */
  783. #ifndef GE_THREAD_H
  784. #define GE_THREAD_H
  785. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  786. #pragma once
  787. #endif
  788. #ifdef GE_USE_THREADS
  789. #ifndef GE_EIFFEL_H
  790. #include "ge_eiffel.h"
  791. #endif
  792. #ifndef GE_THREAD_TYPES_H
  793. #include "ge_thread_types.h"
  794. #endif
  795. #ifndef GE_EXCEPTION_H
  796. #include "ge_exception.h"
  797. #endif
  798. #ifdef __cplusplus
  799. extern "C" {
  800. #endif
  801. #ifdef GE_USE_POSIX_THREADS
  802. #include <unistd.h>
  803. #endif
  804. #ifdef GE_USE_POSIX_THREADS
  805. # define EIF_TSD_VAL_TYPE void*
  806. # define EIF_TSD_TYPE pthread_key_t
  807. # define EIF_TSD_CREATE(key,msg) \
  808. if (pthread_key_create(&(key),NULL)) \
  809. GE_raise_with_message(GE_EX_EXT, msg)
  810. # define EIF_TSD_SET(key,val,msg) \
  811. if (pthread_setspecific((key), (EIF_TSD_VAL_TYPE)(val))) \
  812. GE_raise_with_message(GE_EX_EXT, msg)
  813. # define EIF_TSD_GET0(val_type,key,val) (val = pthread_getspecific(key))
  814. # define EIF_TSD_GET(val_type,key,val,msg) \
  815. if (EIF_TSD_GET0(val_type,key,val) == (void*) 0) GE_raise_with_message(GE_EX_EXT, msg)
  816. # define EIF_TSD_DESTROY(key,msg) if (pthread_key_delete(key)) GE_raise_with_message(GE_EX_EXT, msg)
  817. #elif defined EIF_WINDOWS
  818. # define EIF_TSD_VAL_TYPE LPVOID
  819. # define EIF_TSD_TYPE DWORD
  820. # define EIF_TSD_CREATE(key,msg) \
  821. if ((key=TlsAlloc())==TLS_OUT_OF_INDEXES) GE_raise_with_message(GE_EX_EXT, msg)
  822. # define EIF_TSD_SET(key,val,msg) \
  823. if (!TlsSetValue((key),(EIF_TSD_VAL_TYPE)(val))) GE_raise_with_message(GE_EX_EXT, msg)
  824. # define EIF_TSD_GET0(val_type,key,val) \
  825. val=(val_type) TlsGetValue(key)
  826. # define EIF_TSD_GET(val_type,key,val,msg) \
  827. EIF_TSD_GET0(val_type,key,val); \
  828. if (GetLastError() != NO_ERROR) GE_raise_with_message(GE_EX_EXT, msg)
  829. # define EIF_TSD_DESTROY(key,msg) \
  830. if (!TlsFree(key)) GE_raise_with_message(GE_EX_EXT, msg)
  831. #endif
  832. /* Thread priority levels. */
  833. #define EIF_MIN_THR_PRIORITY 0L
  834. #define EIF_BELOW_NORMAL_THR_PRIORITY 100L
  835. #define EIF_DEFAULT_THR_PRIORITY 127L
  836. #define EIF_ABOVE_NORMAL_THR_PRIORITY 154L
  837. #define EIF_MAX_THR_PRIORITY 255L
  838. /*
  839. * Mutexes used to protect the calls to once-per-process features.
  840. */
  841. typedef struct {
  842. EIF_POINTER* boolean_mutex;
  843. EIF_POINTER* character_8_mutex;
  844. EIF_POINTER* character_32_mutex;
  845. EIF_POINTER* integer_8_mutex;
  846. EIF_POINTER* integer_16_mutex;
  847. EIF_POINTER* integer_32_mutex;
  848. EIF_POINTER* integer_64_mutex;
  849. EIF_POINTER* natural_8_mutex;
  850. EIF_POINTER* natural_16_mutex;
  851. EIF_POINTER* natural_32_mutex;
  852. EIF_POINTER* natural_64_mutex;
  853. EIF_POINTER* pointer_mutex;
  854. EIF_POINTER* real_32_mutex;
  855. EIF_POINTER* real_64_mutex;
  856. EIF_POINTER* reference_mutex;
  857. EIF_POINTER* procedure_mutex;
  858. } GE_once_mutexes;
  859. /*
  860. * Mutexes used to protect the calls to once-per-process features.
  861. */
  862. extern GE_once_mutexes* GE_process_once_mutexes;
  863. /*
  864. * Create a new 'GE_once_mutexes' struct which can deal with the
  865. * numbers of once features passed as argument.
  866. */
  867. extern GE_once_mutexes* GE_new_once_mutexes(
  868. unsigned int a_boolean_count,
  869. unsigned int a_character_8_count,
  870. unsigned int a_character_32_count,
  871. unsigned int a_integer_8_count,
  872. unsigned int a_integer_16_count,
  873. unsigned int a_integer_32_count,
  874. unsigned int a_integer_64_count,
  875. unsigned int a_natural_8_count,
  876. unsigned int a_natural_16_count,
  877. unsigned int a_natural_32_count,
  878. unsigned int a_natural_64_count,
  879. unsigned int a_pointer_count,
  880. unsigned int a_real_32_count,
  881. unsigned int a_real_64_count,
  882. unsigned int a_reference_count,
  883. unsigned int a_procedure_count);
  884. /*
  885. * Keep track of the numbers of once-per-thread features.
  886. */
  887. extern void GE_thread_onces_set_counts(
  888. unsigned int a_boolean_count,
  889. unsigned int a_character_8_count,
  890. unsigned int a_character_32_count,
  891. unsigned int a_integer_8_count,
  892. unsigned int a_integer_16_count,
  893. unsigned int a_integer_32_count,
  894. unsigned int a_integer_64_count,
  895. unsigned int a_natural_8_count,
  896. unsigned int a_natural_16_count,
  897. unsigned int a_natural_32_count,
  898. unsigned int a_natural_64_count,
  899. unsigned int a_pointer_count,
  900. unsigned int a_real_32_count,
  901. unsigned int a_real_64_count,
  902. unsigned int a_reference_count,
  903. unsigned int a_procedure_count);
  904. /*
  905. * Initialize data to handle threads.
  906. * To be called at the beginning of the main function
  907. * on the main thread.
  908. */
  909. extern void GE_init_thread(GE_context* a_context);
  910. /*
  911. * Create a new thread with attributes `attr' and execute
  912. * Eiffel routine `routine' on object `current'.
  913. */
  914. extern void GE_thread_create_with_attr(EIF_REFERENCE current, void (*routine)(EIF_REFERENCE), void (*set_terminated)(EIF_REFERENCE,EIF_BOOLEAN), EIF_THR_ATTR_TYPE* attr);
  915. /*
  916. * Execution context of current thread.
  917. */
  918. extern GE_context* GE_thread_current_context(void);
  919. /*
  920. * Thead ID of current thread.
  921. */
  922. extern EIF_POINTER GE_thread_id(void);
  923. /*
  924. * Thread ID of last thread created from current thread.
  925. */
  926. extern EIF_POINTER GE_last_thread_created(void);
  927. #ifdef EIF_WINDOWS
  928. /*
  929. * Support for Windows GUI that requires that all GUI operations are performed in the same thread.
  930. * Allocate new structure of the given size `a_size', assign it to `wel_per_thread_data'.
  931. * Return newly allocated memory block. It will be freed automatically on thread termination.
  932. */
  933. extern void* GE_thread_create_wel_per_thread_data(size_t a_size);
  934. #endif
  935. /*
  936. * Waits until a child thread sets `terminated' from `obj' to True,
  937. * which means it is terminated. The calling thread must be the
  938. * direct parent of the thread, or the function might loop indefinitely.
  939. */
  940. extern void GE_thread_wait(EIF_REFERENCE obj, EIF_BOOLEAN (*get_terminated)(EIF_REFERENCE));
  941. /*
  942. * Waits until a child thread sets `terminated' from `obj' to True,
  943. * which means it is terminated, or reaching `a_timeout_ms'.
  944. * The calling thread must be the direct parent of the thread,
  945. * or the function might loop indefinitely.
  946. */
  947. extern EIF_BOOLEAN GE_thread_wait_with_timeout(EIF_REFERENCE obj, EIF_BOOLEAN (*get_terminated)(EIF_REFERENCE), EIF_NATURAL_64 a_timeout_ms);
  948. /*
  949. * Yields execution to other threads.
  950. */
  951. extern void GE_thread_yield(void);
  952. /*
  953. * The calling thread waits for all other children threads to terminate.
  954. */
  955. extern void GE_thread_join_all(void);
  956. /*
  957. * Function called to terminate a thread launched by Eiffel with `GE_thread_create_with_attr'.
  958. * This function must be called from the thread itself (not the parent).
  959. */
  960. extern void GE_thread_exit(void);
  961. /*
  962. * Default thread priority level.
  963. */
  964. extern EIF_INTEGER GE_thread_default_priority(void);
  965. /*
  966. * Minimum thread priority level.
  967. */
  968. extern EIF_INTEGER GE_thread_min_priority(void);
  969. /*
  970. * Maximum thread priority level.
  971. */
  972. extern EIF_INTEGER GE_thread_max_priority(void);
  973. /*
  974. * Create a new mutex.
  975. */
  976. extern EIF_POINTER GE_mutex_create(void);
  977. /*
  978. * Lock mutex.
  979. */
  980. extern void GE_mutex_lock(EIF_POINTER a_mutex);
  981. /*
  982. * Try to lock mutex. Return True on success.
  983. */
  984. extern EIF_BOOLEAN GE_mutex_try_lock(EIF_POINTER a_mutex);
  985. /*
  986. * Unlock mutex.
  987. */
  988. extern void GE_mutex_unlock(EIF_POINTER a_mutex);
  989. /*
  990. * Destroy and free all resources used by mutex.
  991. */
  992. extern void GE_mutex_destroy(EIF_POINTER a_mutex);
  993. /*
  994. * Create a new semaphore allowing `a_count' threads
  995. * to go into a critical section.
  996. */
  997. extern EIF_POINTER GE_semaphore_create(EIF_INTEGER a_count);
  998. /*
  999. * Decrement semaphore count, waiting if necessary
  1000. * until that becomes possible.
  1001. */
  1002. extern void GE_semaphore_wait(EIF_POINTER a_semaphore);
  1003. /*
  1004. * Has client been successful in decrementing semaphore
  1005. * count without waiting?
  1006. */
  1007. extern EIF_BOOLEAN GE_semaphore_try_wait(EIF_POINTER a_semaphore);
  1008. /*
  1009. * Increment semaphore count.
  1010. */
  1011. extern void GE_semaphore_post(EIF_POINTER a_semaphore);
  1012. /*
  1013. * Destroy and free all resources used by semaphore.
  1014. */
  1015. extern void GE_semaphore_destroy(EIF_POINTER a_semaphore);
  1016. /*
  1017. * Create a new condition variable.
  1018. */
  1019. extern EIF_POINTER GE_condition_variable_create(void);
  1020. /*
  1021. * Unblock all threads blocked on condition variable.
  1022. */
  1023. extern void GE_condition_variable_broadcast(EIF_POINTER a_condition_variable);
  1024. /*
  1025. * Unblock one thread blocked on condition variable.
  1026. */
  1027. extern void GE_condition_variable_signal(EIF_POINTER a_condition_variable);
  1028. /*
  1029. * Block calling thread on condition variable.
  1030. */
  1031. extern void GE_condition_variable_wait(EIF_POINTER a_condition_variable, EIF_POINTER a_mutex);
  1032. /*
  1033. * Block calling thread on condition variable for at most `a_timeout' milliseconds.
  1034. * Return 1 is we got the condition variable on time, otherwise return 0.
  1035. */
  1036. extern EIF_INTEGER GE_condition_variable_wait_with_timeout(EIF_POINTER a_condition_variable, EIF_POINTER a_mutex, EIF_INTEGER a_timeout);
  1037. /*
  1038. * Destroy and free all resources used by condition variable.
  1039. */
  1040. extern void GE_condition_variable_destroy(EIF_POINTER a_condition_variable);
  1041. /*
  1042. * Create a new read-write lock.
  1043. */
  1044. extern EIF_POINTER GE_read_write_lock_create(void);
  1045. /*
  1046. * Acquire a read lock. Multiple readers can go if there are no writer.
  1047. */
  1048. extern void GE_read_write_lock_read_lock(EIF_POINTER a_read_write_lock);
  1049. /*
  1050. * Acquire a write lock. Only a single write can proceed.
  1051. */
  1052. extern void GE_read_write_lock_write_lock(EIF_POINTER a_read_write_lock);
  1053. /*
  1054. * Unlock a read or write lock.
  1055. */
  1056. extern void GE_read_write_lock_unlock(EIF_POINTER a_read_write_lock);
  1057. /*
  1058. * Destroy and free all resources used by read-write lock.
  1059. */
  1060. extern void GE_read_write_lock_destroy(EIF_POINTER a_read_write_lock);
  1061. #ifdef __cplusplus
  1062. }
  1063. #endif
  1064. #endif
  1065. #endif
  1066. /*
  1067. description:
  1068. "C functions used to manipulate native strings"
  1069. system: "Gobo Eiffel Compiler"
  1070. copyright: "Copyright (c) 2013-2018, Eric Bezault and others"
  1071. license: "MIT License"
  1072. date: "$Date$"
  1073. revision: "$Revision$"
  1074. */
  1075. #ifndef GE_NATIVE_STRING_H
  1076. #define GE_NATIVE_STRING_H
  1077. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  1078. #pragma once
  1079. #endif
  1080. #ifndef GE_EIFFEL_H
  1081. #include "ge_eiffel.h"
  1082. #endif
  1083. #include <string.h>
  1084. #ifdef EIF_WINDOWS
  1085. #ifdef __LCC__
  1086. /* With lcc-win32, stat.h should be included before wchar.h. */
  1087. #include <sys/stat.h>
  1088. #endif
  1089. #include <wchar.h>
  1090. #else
  1091. #include <sys/types.h>
  1092. #endif
  1093. #ifdef __cplusplus
  1094. extern "C" {
  1095. #endif
  1096. #ifdef EIF_WINDOWS
  1097. /* Macro used to manipulate native strings, i.e: (wchar_t*) */
  1098. #define GE_nstrlen wcslen /* size of string */
  1099. #define GE_nstrncpy wcsncpy /* Copy n characters of one string to another */
  1100. #define GE_nstrcpy wcscpy /* Copy one string to another */
  1101. #define GE_nstrncat wcsncat /* Append characters of a string */
  1102. #define GE_nstrcat wcscat /* Append a string */
  1103. #define GE_nstrstr wcsstr /* Return a pointer to the first occurrence of a search string in a string. */
  1104. #define GE_nmakestr(quote) L##quote /* Manifest Native string declaration */
  1105. #define GE_nstr_fopen _wfopen /* Open file using native string name */
  1106. #define GE_nstrcmp wcscmp /* Compare two strings. */
  1107. #define GE_nstrdup _wcsdup /* Duplicate string. */
  1108. #define GE_nstr_cat_ascii(dest, src) { \
  1109. int i; \
  1110. size_t dest_len, src_len; \
  1111. dest_len = rt_nstrlen (dest); \
  1112. src_len = strlen (src); \
  1113. for (i = 0; i < src_len; i++) { \
  1114. dest[dest_len + i] = (EIF_NATIVE_CHAR)src[i]; \
  1115. } \
  1116. dest[dest_len + src_len] = (EIF_NATIVE_CHAR)0; \
  1117. }
  1118. #else /* not EIF_WINDOWS */
  1119. /* Macro used to manipulate native strings, i.e: (char*) */
  1120. #define GE_nstrlen strlen /* size of string */
  1121. #define GE_nstrncpy strncpy /* Copy n characters of one string to another */
  1122. #define GE_nstrcpy strcpy /* Copy one string to another */
  1123. #define GE_nstrncat strncat /* Append characters of a string */
  1124. #define GE_nstrcat strcat /* Append a string */
  1125. #define GE_nstrstr strstr /* Return a pointer to the first occurrence of a search string in a string. */
  1126. #define GE_nmakestr(quote) quote /* Manifest Native string declaration */
  1127. #define GE_nstr_fopen fopen /* Open file using native string name */
  1128. #define GE_nstrcmp strcmp /* Compare two strings. */
  1129. #define GE_nstrdup strdup /* Duplicate string. */
  1130. #define GE_nstr_cat_ascii strcat
  1131. #endif
  1132. #ifdef __cplusplus
  1133. }
  1134. #endif
  1135. #endif
  1136. /*
  1137. description:
  1138. "C functions used to implement class ARGUMENTS"
  1139. system: "Gobo Eiffel Compiler"
  1140. copyright: "Copyright (c) 2007-2017, Eric Bezault and others"
  1141. license: "MIT License"
  1142. date: "$Date$"
  1143. revision: "$Revision$"
  1144. */
  1145. #ifndef GE_ARGUMENTS_H
  1146. #define GE_ARGUMENTS_H
  1147. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  1148. #pragma once
  1149. #endif
  1150. #ifndef GE_EIFFEL_H
  1151. #include "ge_eiffel.h"
  1152. #endif
  1153. #ifdef __cplusplus
  1154. extern "C" {
  1155. #endif
  1156. extern int GE_argc;
  1157. extern EIF_NATIVE_CHAR** GE_argv;
  1158. #ifdef __cplusplus
  1159. }
  1160. #endif
  1161. #endif
  1162. /*
  1163. description:
  1164. "C functions used to implement type information"
  1165. system: "Gobo Eiffel Compiler"
  1166. copyright: "Copyright (c) 2016-2018, Eric Bezault and others"
  1167. license: "MIT License"
  1168. date: "$Date$"
  1169. revision: "$Revision$"
  1170. */
  1171. #ifndef GE_TYPES_H
  1172. #define GE_TYPES_H
  1173. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  1174. #pragma once
  1175. #endif
  1176. #ifndef GE_EIFFEL_H
  1177. #include "ge_eiffel.h"
  1178. #endif
  1179. #ifndef GE_EXCEPTION_H
  1180. #include "ge_exception.h"
  1181. #endif
  1182. #ifdef __cplusplus
  1183. extern "C" {
  1184. #endif
  1185. /*
  1186. * Type annotations.
  1187. * When a type has no annotation, it means a detachable, non-separate, variant type.
  1188. * In all other cases, there will be an annotation.
  1189. */
  1190. #define ANNOTATION_MASK 0x007F /* All possible annotations. */
  1191. #define ATTACHED_FLAG 0x0001
  1192. #define DETACHABLE_FLAG 0x0002 /* Only present when overriding an attached type. */
  1193. #define SEPARATE_FLAG 0x0004
  1194. #define VARIANT_FLAG 0x0008 /* Only present when overriding a frozen/poly type. */
  1195. #define UNUSABLE_FLAG 0x0010 /* Reserved for backward compatibility for storables. */
  1196. #define FROZEN_FLAG 0x0020
  1197. #define POLY_FLAG 0x0040
  1198. /*
  1199. * Type flags.
  1200. */
  1201. #define GE_TYPE_FLAG_SPECIAL 0x0010
  1202. #define GE_TYPE_FLAG_TUPLE 0x0020
  1203. #define GE_TYPE_FLAG_EXPANDED 0x0040
  1204. #define GE_TYPE_FLAG_DEFERRED 0x0080
  1205. #define GE_TYPE_FLAG_NONE 0x0100
  1206. #define GE_TYPE_FLAG_BASIC_MASK 0x000F /* One of "BOOLEAN", "CHARACTER_8", "CHARACTER_32", "INTEGER_8", "INTEGER_16", "INTEGER_32", "INTEGER_64", "NATURAL_8", "NATURAL_16", "NATURAL_32", "NATURAL_64", "POINTER", "REAL_32", "REAL_64" */
  1207. #define GE_TYPE_FLAG_BOOLEAN 0x0001
  1208. #define GE_TYPE_FLAG_CHARACTER_8 0x0002
  1209. #define GE_TYPE_FLAG_CHARACTER_32 0x0003
  1210. #define GE_TYPE_FLAG_INTEGER_8 0x0004
  1211. #define GE_TYPE_FLAG_INTEGER_16 0x0005
  1212. #define GE_TYPE_FLAG_INTEGER_32 0x0006
  1213. #define GE_TYPE_FLAG_INTEGER_64 0x0007
  1214. #define GE_TYPE_FLAG_NATURAL_8 0x0008
  1215. #define GE_TYPE_FLAG_NATURAL_16 0x0009
  1216. #define GE_TYPE_FLAG_NATURAL_32 0x000A
  1217. #define GE_TYPE_FLAG_NATURAL_64 0x000B
  1218. #define GE_TYPE_FLAG_POINTER 0x000C
  1219. #define GE_TYPE_FLAG_REAL_32 0x000D
  1220. #define GE_TYPE_FLAG_REAL_64 0x000E
  1221. /*
  1222. * Convention for attribute types.
  1223. * The values are in sync with REFLECTOR_CONSTANTS.
  1224. */
  1225. #define GE_TYPE_KIND_INVALID -1
  1226. #define GE_TYPE_KIND_POINTER 0
  1227. #define GE_TYPE_KIND_REFERENCE 1
  1228. #define GE_TYPE_KIND_CHARACTER_8 2
  1229. #define GE_TYPE_KIND_BOOLEAN 3
  1230. #define GE_TYPE_KIND_INTEGER_32 4
  1231. #define GE_TYPE_KIND_REAL_32 5
  1232. #define GE_TYPE_KIND_REAL_64 6
  1233. #define GE_TYPE_KIND_EXPANDED 7
  1234. #define GE_TYPE_KIND_INTEGER_8 9
  1235. #define GE_TYPE_KIND_INTEGER_16 10
  1236. #define GE_TYPE_KIND_INTEGER_64 11
  1237. #define GE_TYPE_KIND_CHARACTER_32 12
  1238. #define GE_TYPE_KIND_NATURAL_8 13
  1239. #define GE_TYPE_KIND_NATURAL_16 14
  1240. #define GE_TYPE_KIND_NATURAL_32 15
  1241. #define GE_TYPE_KIND_NATURAL_64 16
  1242. /*
  1243. * Object flags.
  1244. */
  1245. #define GE_OBJECT_FLAG_MARKED 0x0001
  1246. /*
  1247. * Ancestor relationship between two types X and Y.
  1248. */
  1249. #ifdef GE_USE_ANCESTORS
  1250. typedef struct {
  1251. EIF_TYPE_INDEX type_id; /* Type id of Y */
  1252. EIF_BOOLEAN conforms; /* Does X conform to Y? */
  1253. void (**qualified_calls)(); /* Function pointers, indexed by call id, when the static type of the target is Y and the dynamic type is X */
  1254. } GE_ancestor;
  1255. #endif
  1256. /*
  1257. * Attribute.
  1258. */
  1259. #ifdef GE_USE_ATTRIBUTES
  1260. typedef struct {
  1261. #ifdef GE_USE_ATTRIBUTE_NAME
  1262. const char* name; /* Attribute name */
  1263. #endif
  1264. #ifdef GE_USE_ATTRIBUTE_TYPE_ID
  1265. EIF_ENCODED_TYPE type_id; /* Static type id */
  1266. #endif
  1267. #ifdef GE_USE_ATTRIBUTE_OFFSET
  1268. uint32_t offset; /* Address offset in object */
  1269. #endif
  1270. } GE_attribute;
  1271. #endif
  1272. /*
  1273. * Type information.
  1274. */
  1275. typedef struct {
  1276. EIF_TYPE_INDEX type_id;
  1277. uint16_t flags;
  1278. #ifdef GE_USE_TYPE_GENERATOR
  1279. const char* generator; /* Generator class name */
  1280. #endif
  1281. #ifdef GE_USE_TYPE_NAME
  1282. const char* name; /* Full type name */
  1283. #endif
  1284. #ifdef GE_USE_TYPE_GENERIC_PARAMETERS
  1285. EIF_ENCODED_TYPE* generic_parameters;
  1286. uint32_t generic_parameter_count;
  1287. #endif
  1288. #ifdef GE_USE_ANCESTORS
  1289. GE_ancestor** ancestors;
  1290. uint32_t ancestor_count;
  1291. #endif
  1292. #ifdef GE_USE_ATTRIBUTES
  1293. GE_attribute** attributes;
  1294. uint32_t attribute_count;
  1295. #endif
  1296. #ifdef GE_USE_TYPE_OBJECT_SIZE
  1297. uint64_t object_size;
  1298. #endif
  1299. EIF_REFERENCE (*new_instance)();
  1300. void (*dispose)(GE_context*, EIF_REFERENCE);
  1301. } GE_type_info;
  1302. typedef struct {
  1303. EIF_TYPE_INDEX id; /* Type id of the "TYPE [X]" object */
  1304. EIF_INTEGER type_id; /* Type id of the type "X" */
  1305. EIF_BOOLEAN is_special;
  1306. void (*dispose)(GE_context*, EIF_REFERENCE);
  1307. EIF_REFERENCE a1; /* internal_name */
  1308. EIF_REFERENCE a2; /* internal_name_32 */
  1309. } EIF_TYPE_OBJ;
  1310. /*
  1311. * Types indexed by type id.
  1312. * Generated by the compiler.
  1313. */
  1314. extern EIF_TYPE_OBJ GE_types[][2];
  1315. extern GE_type_info GE_type_infos[];
  1316. /*
  1317. * Number of type infos in `GE_type_infos'.
  1318. * Do not take into account the fake item at index 0.
  1319. */
  1320. extern int GE_type_info_count;
  1321. /*
  1322. * Encode a EIF_TYPE into a EIF_ENCODED_TYPE.
  1323. * The lower part of EIF_ENCODED_TYPE contains the .id field,
  1324. * and the upper part the .annotations.
  1325. */
  1326. extern EIF_ENCODED_TYPE GE_encoded_type(EIF_TYPE a_type);
  1327. /*
  1328. * Decode a EIF_ENCODED_TYPE into a EIF_TYPE.
  1329. * The lower part of EIF_ENCODED_TYPE contains the .id field,
  1330. * and the upper part the .annotations.
  1331. */
  1332. extern EIF_TYPE GE_decoded_type(EIF_ENCODED_TYPE a_type);
  1333. /*
  1334. * Type with `a_id' and `a_annotations'.
  1335. */
  1336. extern EIF_TYPE GE_new_type(EIF_TYPE_INDEX a_id, EIF_TYPE_INDEX a_annotations);
  1337. /*
  1338. * Type of object `obj'.
  1339. */
  1340. #define GE_object_type(obj) GE_new_type(((EIF_REFERENCE)(obj))->id, 0x0)
  1341. #define GE_object_encoded_type(obj) GE_encoded_type(GE_object_type(obj))
  1342. /*
  1343. * Attachment status of `a_type'.
  1344. */
  1345. #define GE_is_attached_type(a_type) EIF_TEST(((a_type).annotations & ATTACHED_FLAG) || GE_is_expanded_type_index((a_type).id))
  1346. #define GE_is_attached_encoded_type(a_type) GE_is_attached_type(GE_decoded_type(a_type))
  1347. /*
  1348. * Associated detachable type of `a_type' if any,
  1349. * otherwise `a_type'.
  1350. */
  1351. extern EIF_TYPE GE_non_attached_type(EIF_TYPE a_type);
  1352. #define GE_non_attached_encoded_type(a_type) GE_encoded_type(GE_non_attached_type(GE_decoded_type(a_type)))
  1353. /*
  1354. * Associated attached type of `a_type' if any,
  1355. * otherwise `a_type'.
  1356. */
  1357. extern EIF_TYPE GE_attached_type(EIF_TYPE a_type);
  1358. #define GE_attached_encoded_type(t) GE_encoded_type(GE_attached_type(GE_decoded_type(t)))
  1359. /*
  1360. * Is `a_type' a SPECIAL type?
  1361. */
  1362. #define GE_is_special_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_SPECIAL)
  1363. #define GE_is_special_encoded_type(a_type) GE_is_special_type_index(GE_decoded_type(a_type).id)
  1364. #define GE_is_special_object(obj) GE_is_special_type_index(((EIF_REFERENCE)(obj))->id)
  1365. /*
  1366. * Is `a_type' a SPECIAL type of user-defined expanded type?
  1367. */
  1368. extern EIF_BOOLEAN GE_is_special_of_expanded_type_index(EIF_TYPE_INDEX a_type);
  1369. #define GE_is_special_of_expanded_encoded_type(a_type) GE_is_special_of_expanded_type_index(GE_decoded_type(a_type).id)
  1370. #define GE_is_special_of_expanded_object(obj) GE_is_special_of_expanded_type_index(((EIF_REFERENCE)(obj))->id)
  1371. /*
  1372. * Is `a_type' a SPECIAL type of reference type?
  1373. */
  1374. extern EIF_BOOLEAN GE_is_special_of_reference_type_index(EIF_TYPE_INDEX a_type);
  1375. #define GE_is_special_of_reference_encoded_type(a_type) GE_is_special_of_reference_type_index(GE_decoded_type(a_type).id)
  1376. #define GE_is_special_of_reference_object(obj) GE_is_special_of_reference_type_index(((EIF_REFERENCE)(obj))->id)
  1377. /*
  1378. * Is `a_type' a SPECIAL type of reference type or basic expanded type?
  1379. * (Note that user-defined expanded types are excluded.)
  1380. */
  1381. extern EIF_BOOLEAN GE_is_special_of_reference_or_basic_expanded_type_index(EIF_TYPE_INDEX a_type);
  1382. #define GE_is_special_of_reference_or_basic_expanded_encoded_type(a_type) GE_is_special_of_reference_or_basic_expanded_type_index(GE_decoded_type(a_type).id)
  1383. #define GE_is_special_of_reference_or_basic_expanded_object(obj) GE_is_special_of_reference_or_basic_expanded_type_index(((EIF_REFERENCE)(obj))->id)
  1384. /*
  1385. * Is `a_type' a TUPLE type?
  1386. */
  1387. #define GE_is_tuple_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_TUPLE)
  1388. #define GE_is_tuple_encoded_type(a_type) GE_is_tuple_type_index(GE_decoded_type(a_type).id)
  1389. #define GE_is_tuple_object(obj) GE_is_tuple_type_index(((EIF_REFERENCE)(obj))->id)
  1390. /*
  1391. * Is `a_type' an expanded type?
  1392. */
  1393. #define GE_is_expanded_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_EXPANDED)
  1394. #define GE_is_expanded_encoded_type(a_type) GE_is_expanded_type_index(GE_decoded_type(a_type).id)
  1395. #define GE_is_expanded_object(obj) GE_is_expanded_type_index(((EIF_REFERENCE)(obj))->id)
  1396. /*
  1397. * Is `a_type' a type whose base class is deferred?
  1398. */
  1399. #define GE_is_deferred_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_DEFERRED)
  1400. #define GE_is_deferred_encoded_type(a_type) GE_is_deferred_type_index(GE_decoded_type(a_type).id)
  1401. /*
  1402. * Does `i'-th field of `a_object + a_physical_offset' (which is expected to be reference)
  1403. * denote a reference with copy semantics?
  1404. */
  1405. extern EIF_BOOLEAN GE_is_copy_semantics_field(EIF_INTEGER i, EIF_POINTER a_object, EIF_INTEGER a_physical_offset);
  1406. /*
  1407. * Does `i'-th item of special `a_object' (which is expected to be reference)
  1408. * denote a reference with copy semantics?
  1409. */
  1410. extern EIF_BOOLEAN GE_is_special_copy_semantics_item(EIF_INTEGER i, EIF_POINTER a_object);
  1411. /*
  1412. * Generator class name of `a_type'.
  1413. */
  1414. extern EIF_REFERENCE GE_generator_of_type_index(EIF_TYPE_INDEX a_type);
  1415. #define GE_generator_of_encoded_type(a_type) GE_generator_of_type_index(GE_decoded_type(a_type).id)
  1416. extern EIF_REFERENCE GE_generator_8_of_type_index(EIF_TYPE_INDEX a_type);
  1417. #define GE_generator_8_of_encoded_type(a_type) GE_generator_8_of_type_index(GE_decoded_type(a_type).id)
  1418. /*
  1419. * Full name of `a_type'.
  1420. */
  1421. extern EIF_REFERENCE GE_generating_type_of_encoded_type(EIF_ENCODED_TYPE a_type);
  1422. extern EIF_REFERENCE GE_generating_type_8_of_encoded_type(EIF_ENCODED_TYPE a_type);
  1423. /*
  1424. * Encoded type whose name is `a_name'.
  1425. * -1 if no such type.
  1426. */
  1427. extern EIF_ENCODED_TYPE GE_encoded_type_from_name(EIF_POINTER a_name);
  1428. /*
  1429. * Does `a_type_1' conform to `a_type_2'?
  1430. */
  1431. extern EIF_BOOLEAN GE_encoded_type_conforms_to(EIF_ENCODED_TYPE a_type_1, EIF_ENCODED_TYPE a_type_2);
  1432. /*
  1433. * Number of generic parameters.
  1434. */
  1435. extern EIF_INTEGER GE_generic_parameter_count_of_type_index(EIF_TYPE_INDEX a_type);
  1436. #define GE_generic_parameter_count_of_encoded_type(a_type) GE_generic_parameter_count_of_type_index(GE_decoded_type(a_type).id)
  1437. /*
  1438. * Type of `i'-th generic parameter of `a_type'.
  1439. */
  1440. extern EIF_INTEGER GE_generic_parameter_of_type_index(EIF_TYPE_INDEX a_type, EIF_INTEGER i);
  1441. #define GE_generic_parameter_of_encoded_type(a_type,i) GE_generic_parameter_of_type_index(GE_decoded_type(a_type).id, (i))
  1442. /*
  1443. * Number of fields of an object of dynamic type `a_type'.
  1444. */
  1445. extern EIF_INTEGER GE_field_count_of_type_index(EIF_TYPE_INDEX a_type);
  1446. #define GE_field_count_of_encoded_type(a_type) GE_field_count_of_type_index(GE_decoded_type(a_type).id)
  1447. /*
  1448. * Physical offset of the `i'-th field for an object of dynamic type `a_type'.
  1449. */
  1450. extern EIF_INTEGER GE_field_offset_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  1451. #define GE_field_offset_of_encoded_type(i, a_type) GE_field_offset_of_type_index((i), GE_decoded_type(a_type).id)
  1452. /*
  1453. * Name of the `i'-th field for an object of dynamic type `a_type'.
  1454. */
  1455. extern EIF_POINTER GE_field_name_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  1456. #define GE_field_name_of_encoded_type(i, a_type) GE_field_name_of_type_index((i), GE_decoded_type(a_type).id)
  1457. /*
  1458. * Static type of the `i'-th field for an object of dynamic type `a_type'.
  1459. */
  1460. extern EIF_INTEGER GE_field_static_type_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  1461. #define GE_field_static_type_of_encoded_type(i, a_type) GE_field_static_type_of_type_index((i), GE_decoded_type(a_type).id)
  1462. /*
  1463. * Kind of type of the `i'-th field for an object of dynamic type `a_type'.
  1464. */
  1465. extern EIF_INTEGER GE_field_type_kind_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  1466. #define GE_field_type_kind_of_encoded_type(i, a_type) GE_field_type_kind_of_type_index((i), GE_decoded_type(a_type).id)
  1467. /*
  1468. * Physical size of `a_object'.
  1469. */
  1470. extern EIF_NATURAL_64 GE_object_size(EIF_POINTER a_object);
  1471. /*
  1472. * Is `i'-th field of objects of type `a_type' a user-defined expanded attribute?
  1473. */
  1474. extern EIF_BOOLEAN GE_is_field_expanded_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  1475. #define GE_is_field_expanded_of_encoded_type(i, a_type) GE_is_field_expanded_of_type_index((i), GE_decoded_type(a_type).id)
  1476. #define GE_field_address_at(a_field_offset, a_object, a_physical_offset) ((char*)(a_object) + (a_physical_offset) + (a_field_offset))
  1477. #define GE_object_at_offset(a_enclosing, a_physical_offset) (EIF_REFERENCE)(GE_field_address_at(0,

Large files files are truncated, but you can click here to view the full file