- Timestamp:
- May 25, 2022, 5:51:24 PM (22 months ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- c3b9d639
- Parents:
- 5024df4
- Location:
- libcfa/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/clib/cfathread.cfa
r5024df4 rc715e5f 237 237 238 238 typedef ThreadCancelled(cfathread_object) cfathread_exception; 239 typedef ThreadCancelled_vtable(cfathread_object) cfathread_vtable;239 typedef vtable(ThreadCancelled(cfathread_object)) cfathread_vtable; 240 240 241 241 void defaultResumptionHandler(ThreadCancelled(cfathread_object) & except) { … … 283 283 284 284 typedef ThreadCancelled(__cfainit) __cfainit_exception; 285 typedef ThreadCancelled_vtable(__cfainit) __cfainit_vtable;285 typedef vtable(ThreadCancelled(__cfainit)) __cfainit_vtable; 286 286 287 287 void defaultResumptionHandler(ThreadCancelled(__cfainit) & except) { -
libcfa/src/concurrency/coroutine.hfa
r5024df4 rc715e5f 22 22 //----------------------------------------------------------------------------- 23 23 // Exception thrown from resume when a coroutine stack is cancelled. 24 EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) ( 24 forall(coroutine_t &) 25 exception CoroutineCancelled { 25 26 coroutine_t * the_coroutine; 26 27 exception_t * the_exception; 27 );28 }; 28 29 29 30 forall(T &) -
libcfa/src/concurrency/thread.hfa
r5024df4 rc715e5f 32 32 }; 33 33 34 EHM_FORALL_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) ( 34 forall(thread_t &) 35 exception ThreadCancelled { 35 36 thread_t * the_thread; 36 37 exception_t * the_exception; 37 );38 }; 38 39 39 40 forall(T &) -
libcfa/src/exception.hfa
r5024df4 rc715e5f 10 10 // Created On : Thu Apr 7 10:25:00 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Apr 8 15:16:00 202113 // Update Count : 412 // Last Modified On : Wed May 25 17:20:00 2022 13 // Update Count : 5 14 14 // 15 15 … … 18 18 // ----------------------------------------------------------------------------------------------- 19 19 20 // EHM_EXCEPTION(exception_name)(fields...);21 // Create an exception (a virtual structure that inherits from exception_t)22 // with the given name and fields.23 #define EHM_EXCEPTION(exception_name) \24 _EHM_TYPE_ID_STRUCT(exception_name, ); \25 _EHM_TYPE_ID_VALUE(exception_name, ); \26 _EHM_VIRTUAL_TABLE_STRUCT(exception_name, , ); \27 _EHM_EXCEPTION_STRUCT(exception_name, , )28 29 // EHM_EXTERN_VTABLE(exception_name, table_name);30 // Forward declare a virtual table called table_name for exception_name type.31 #define EHM_EXTERN_VTABLE(exception_name, table_name) \32 _EHM_EXTERN_VTABLE(exception_name, , table_name)33 34 // EHM_VIRTUAL_TABLE(exception_name, table_name);35 // Define a virtual table called table_name for exception_name type.36 #define EHM_VIRTUAL_TABLE(exception_name, table_name) \37 _EHM_DEFINE_COPY(exception_name, ) \38 _EHM_DEFINE_MSG(exception_name, ) \39 _EHM_VIRTUAL_TABLE(exception_name, , table_name)40 41 // EHM_FORALL_EXCEPTION(exception_name, (assertions), (parameters))(fields...);42 // As EHM_EXCEPTION but for polymorphic types instead of monomorphic ones.43 // The assertions list should include all polymorphic parameters and44 // assertions inside a parentisized list. Parameters should include all the45 // polymorphic parameter names inside a parentisized list (same order).46 #define EHM_FORALL_EXCEPTION(exception_name, assertions, parameters) \47 _EHM_TYPE_ID_STRUCT(exception_name, forall assertions); \48 _EHM_VIRTUAL_TABLE_STRUCT(exception_name, forall assertions, parameters); \49 _EHM_EXCEPTION_STRUCT(exception_name, forall assertions, parameters)50 51 // EHM_FORALL_EXTERN_VTABLE(exception_name, (arguments), table_name);52 // As EHM_EXTERN_VTABLE but for polymorphic types instead of monomorphic ones.53 // Arguments should be the parentisized list of polymorphic arguments.54 #define EHM_FORALL_EXTERN_VTABLE(exception_name, arguments, table_name) \55 _EHM_EXTERN_VTABLE(exception_name, arguments, table_name)56 57 // EHM_FORALL_VIRTUAL_TABLE(exception_name, (arguments), table_name);58 // As EHM_VIRTUAL_TABLE but for polymorphic types instead of monomorphic ones.59 // Arguments should be the parentisized list of polymorphic arguments.60 #define EHM_FORALL_VIRTUAL_TABLE(exception_name, arguments, table_name) \61 _EHM_TYPE_ID_VALUE(exception_name, arguments); \62 _EHM_DEFINE_COPY(exception_name, arguments) \63 _EHM_DEFINE_MSG(exception_name, arguments) \64 _EHM_VIRTUAL_TABLE(exception_name, arguments, table_name)65 66 20 // EHM_DEFAULT_VTABLE(exception_name, (arguments)) 67 21 // Create a declaration for a (possibly polymorphic) default vtable. 68 22 #define EHM_DEFAULT_VTABLE(exception_name, arguments) \ 69 _EHM_VTABLE_TYPE(exception_name) arguments& const _default_vtable23 vtable(exception_name arguments) & const _default_vtable 70 24 71 25 // IS_EXCEPTION(exception_name [, (...parameters)]) … … 77 31 #define IS_RESUMPTION_EXCEPTION(...) _IS_EXCEPTION(is_resumption_exception, __VA_ARGS__, , ~) 78 32 #define IS_TERMINATION_EXCEPTION(...) _IS_EXCEPTION(is_termination_exception, __VA_ARGS__, , ~) 79 80 // Macros starting with a leading underscore are internal.81 82 // Create an exception type definition. must be tailing, can be polymorphic.83 #define _EHM_EXCEPTION_STRUCT(exception_name, forall_clause, parameters) \84 forall_clause struct exception_name { \85 _EHM_VTABLE_TYPE(exception_name) parameters const * virtual_table; \86 _CLOSE87 88 // Create a (possibly polymorphic) virtual table forward declaration.89 #define _EHM_EXTERN_VTABLE(exception_name, arguments, table_name) \90 extern const _EHM_VTABLE_TYPE(exception_name) arguments table_name91 92 // Create a (possibly polymorphic) virtual table definition.93 #define _EHM_VIRTUAL_TABLE(exception_type, arguments, table_name) \94 const _EHM_VTABLE_TYPE(exception_type) arguments table_name @= { \95 .__cfavir_typeid : &_EHM_TYPE_ID_NAME(exception_type), \96 .size : sizeof(struct exception_type arguments), \97 .copy : copy, \98 .^?{} : ^?{}, \99 .msg : msg, \100 }101 102 // Create a (possibly polymorphic) copy function from an assignment operator.103 #define _EHM_DEFINE_FORALL_COPY(exception_name, forall_clause, parameters) \104 forall_clause void copy(exception_name parameters * this, \105 exception_name parameters * that) { \106 *this = *that; \107 }108 109 #define _EHM_DEFINE_COPY(exception_name, arguments) \110 void copy(exception_name arguments * this, exception_name arguments * that) { \111 *this = *that; \112 }113 114 // Create a (possibly polymorphic) msg function115 #define _EHM_DEFINE_FORALL_MSG(exception_name, forall_clause, parameters) \116 forall_clause const char * msg(exception_name parameters * this) { \117 return #exception_name #parameters; \118 }119 120 #define _EHM_DEFINE_MSG(exception_name, arguments) \121 const char * msg(exception_name arguments * this) { \122 return #exception_name #arguments; \123 }124 125 // Produces the C compatable name of the virtual table type for a virtual type.126 #define _EHM_VTABLE_TYPE(type_name) struct _GLUE2(type_name,_vtable)127 128 // Create the vtable type for exception name.129 #define _EHM_VIRTUAL_TABLE_STRUCT(exception_name, forall_clause, parameters) \130 forall_clause struct exception_name; \131 forall_clause _EHM_VTABLE_TYPE(exception_name) { \132 _EHM_TYPE_ID_TYPE(exception_name) parameters const * __cfavir_typeid; \133 size_t size; \134 void (*copy)(exception_name parameters * this, exception_name parameters * other); \135 void (*^?{})(exception_name parameters & this); \136 const char * (*msg)(exception_name parameters * this); \137 }138 139 // Define the function required to satify the trait for exceptions.140 #define _EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \141 forall_clause inline void mark_exception( \142 exception_name parameters const &, \143 _EHM_VTABLE_TYPE(exception_name) parameters const &) {} \144 145 #define __EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \146 forall_clause inline _EHM_VTABLE_TYPE(exception_name) parameters const & \147 get_exception_vtable(exception_name parameters const & this) { \148 /* This comes before the structure definition, but we know the offset. */ \149 /* return (_EHM_VTABLE_TYPE(exception_name) parameters const &)this; */ \150 assert(false); \151 }152 153 // Generates a new type-id structure. This is used to mangle the name of the154 // type-id instance so it also includes polymorphic information. Must be the155 // direct decendent of exception_t.156 // The second field is used to recover type information about the exception.157 #define _EHM_TYPE_ID_STRUCT(exception_name, forall_clause) \158 forall_clause _EHM_TYPE_ID_TYPE(exception_name) { \159 __cfavir_type_info const * parent; \160 }161 162 // Generate a new type-id value.163 #define _EHM_TYPE_ID_VALUE(exception_name, arguments) \164 __attribute__((cfa_linkonce)) \165 _EHM_TYPE_ID_TYPE(exception_name) arguments const \166 _EHM_TYPE_ID_NAME(exception_name) = { \167 &__cfatid_exception_t, \168 }169 170 // _EHM_TYPE_ID_STRUCT and _EHM_TYPE_ID_VALUE are the two that would need to171 // be updated to extend the hierarchy if we are still using macros when that172 // is added.173 174 // Produce the C compatable name of the type-id type for an exception type.175 #define _EHM_TYPE_ID_TYPE(exception_name) \176 struct _GLUE2(__cfatid_struct_, exception_name)177 178 // Produce the name of the instance of the type-id for an exception type.179 #define _EHM_TYPE_ID_NAME(exception_name) _GLUE2(__cfatid_,exception_name)180 181 33 #define _IS_EXCEPTION(kind, exception_name, parameters, ...) \ 182 kind(exception_name parameters, _EHM_VTABLE_TYPE(exception_name) parameters) 183 184 // Internal helper macros: 185 #define _CLOSE(...) __VA_ARGS__ } 186 #define _GLUE2(left, right) left##right 34 kind(exception_name parameters, vtable(exception_name parameters))
Note: See TracChangeset
for help on using the changeset viewer.