Changeset c715e5f
- Timestamp:
- May 25, 2022, 5:51:24 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- c3b9d639
- Parents:
- 5024df4
- Files:
-
- 11 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)) -
src/CodeGen/GenType.cc
r5024df4 rc715e5f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 1 15:24:00 201913 // Update Count : 2 312 // Last Modified On : Fri May 20 11:18:00 2022 13 // Update Count : 24 14 14 // 15 15 #include "GenType.h" … … 50 50 void postvisit( TraitInstType * inst ); 51 51 void postvisit( TypeofType * typeof ); 52 void postvisit( VTableType * vtable ); 52 53 void postvisit( QualifiedType * qualType ); 53 54 … … 259 260 if ( options.genC ) { 260 261 typeString = "enum " + typeString; 261 } 262 } 262 } 263 } 263 264 handleQualifiers( enumInst ); 264 265 } 265 266 266 267 void GenType::postvisit( TypeInstType * typeInst ) { 268 assertf( ! options.genC, "Type instance types should not reach code generation." ); 267 269 typeString = typeInst->name + " " + typeString; 268 270 handleQualifiers( typeInst ); … … 320 322 } 321 323 324 void GenType::postvisit( VTableType * vtable ) { 325 assertf( ! options.genC, "Virtual table types should not reach code generation." ); 326 std::ostringstream os; 327 os << "vtable(" << genType( vtable->base, "", options ) << ") " << typeString; 328 typeString = os.str(); 329 handleQualifiers( vtable ); 330 } 331 322 332 void GenType::postvisit( QualifiedType * qualType ) { 323 333 assertf( ! options.genC, "Qualified types should not reach code generation." ); -
src/ControlStruct/ExceptDecl.cc
r5024df4 rc715e5f 9 9 // Author : Henry Xue 10 10 // Created On : Tue Jul 20 04:10:50 2021 11 // Last Modified By : Henry Xue12 // Last Modified On : Tue Aug 03 10:42:26 202113 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 25 16:43:00 2022 13 // Update Count : 5 14 14 // 15 15 … … 39 39 } 40 40 41 TypeInstType * makeExceptInstType(42 const std::string & exceptionName, 43 const std::list< Expression *> & parameters 44 ) { 45 TypeInstType * exceptInstType = new TypeInstType(41 StructInstType * makeExceptInstType( 42 const std::string & exceptionName, 43 const std::list< Expression *> & parameters 44 ) { 45 StructInstType * exceptInstType = new StructInstType( 46 46 noQualifiers, 47 exceptionName, 48 false 47 exceptionName 49 48 ); 50 49 cloneAll( parameters, exceptInstType->parameters ); … … 151 150 nullptr, 152 151 new PointerType( noQualifiers, 153 new TypeInstType( Type::Const, "__cfavir_type_info", false) ),152 new StructInstType( Type::Const, "__cfavir_type_info" ) ), 154 153 nullptr 155 154 ) ); … … 257 256 const std::string & exceptionName, 258 257 const std::list< TypeDecl *> & forallClause, 259 const std::list< Expression *> & parameters, 258 const std::list< Expression *> & parameters, 260 259 const std::list< Declaration *> & members 261 260 ) { … … 302 301 ObjectDecl * ehmExternVtable( 303 302 const std::string & exceptionName, 304 const std::list< Expression *> & parameters, 303 const std::list< Expression *> & parameters, 305 304 const std::string & tableName 306 305 ) { … … 457 456 } 458 457 458 class VTableCore : public WithDeclsToAdd { 459 public: 460 // Remove any remaining vtable type nodes in the tree. 461 Type * postmutate( VTableType * vtableType ); 462 }; 463 464 Type * VTableCore::postmutate( VTableType * vtableType ) { 465 auto inst = strict_dynamic_cast<ReferenceToType *>( vtableType->base ); 466 467 std::string vtableName = Virtual::vtableTypeName( inst->name ); 468 StructInstType * newType = new StructInstType( noQualifiers, vtableName ); 469 cloneAll( inst->parameters, newType->parameters ); 470 471 delete vtableType; 472 return newType; 473 } 474 459 475 void translateExcept( std::list< Declaration *> & translationUnit ) { 460 476 PassVisitor<ExceptDeclCore> translator; 461 477 mutateAll( translationUnit, translator ); 462 } 463 464 } 478 PassVisitor<VTableCore> typeTranslator; 479 mutateAll( translationUnit, typeTranslator ); 480 } 481 482 } -
tests/.expect/quasiKeyword.txt
r5024df4 rc715e5f 1 quasiKeyword.cfa:5 4:25: warning: Compiled1 quasiKeyword.cfa:52:25: warning: Compiled -
tests/exceptions/defaults.cfa
r5024df4 rc715e5f 2 2 3 3 #include <string.h> 4 #include <exception.hfa>5 4 6 5 exception log_message { … … 8 7 }; 9 8 10 _EHM_DEFINE_COPY(log_message, ) 9 void copy(log_message * this, log_message * that) { 10 *this = *that; 11 } 12 11 13 const char * msg(log_message * this) { 12 14 return this->msg; 13 15 } 14 _EHM_VIRTUAL_TABLE(log_message, , log_vt); 16 17 const struct log_message_vtable log_vt @= { 18 .__cfavir_typeid : &__cfatid_log_message, 19 .size : sizeof(struct log_message), 20 .copy : copy, 21 .^?{} : ^?{}, 22 .msg : msg, 23 }; 15 24 16 25 // Logging messages don't have to be handled. -
tests/linking/exception-nothreads.cfa
r5024df4 rc715e5f 15 15 16 16 #include <stdlib.hfa> 17 #include <exception.hfa>18 17 19 EHM_EXCEPTION(ping)();20 EHM_VIRTUAL_TABLE(ping, ping_vt);18 exception ping {}; 19 vtable(ping) ping_vt; 21 20 22 21 int main(void) { -
tests/linking/exception-withthreads.cfa
r5024df4 rc715e5f 15 15 16 16 #include <stdlib.hfa> 17 #include <exception.hfa>18 17 #include "../exceptions/with-threads.hfa" 19 18 20 EHM_EXCEPTION(ping)();21 EHM_VIRTUAL_TABLE(ping, ping_vt);19 exception ping {}; 20 vtable(ping) ping_vt; 22 21 23 22 int main(void) { -
tests/quasiKeyword.cfa
r5024df4 rc715e5f 4 4 // quasiKeyword.cfa -- test that quasi-keywords can be used for variable and functions names, as well as keywords in 5 5 // control structures. 6 // 6 // 7 7 // Author : Peter A. Buhr 8 8 // Created On : Wed Feb 17 10:33:49 2021 … … 10 10 // Last Modified On : Sat Jun 5 10:07:59 2021 11 11 // Update Count : 8 12 // 12 // 13 13 14 #include <exception.hfa> 15 16 EHM_EXCEPTION( E )(); 14 exception E {}; 17 15 18 16 void catch( int i ) {} … … 49 47 } fixup ( E * ) { 50 48 } finally { 51 } 49 } 52 50 else catch = 3; 53 51
Note: See TracChangeset
for help on using the changeset viewer.