Changeset e9145a3 for src/tests/except-2.c
- Timestamp:
- Aug 17, 2017, 4:13:42 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 8f6dfe7
- Parents:
- 21f0aa8
- File:
-
- 1 edited
-
src/tests/except-2.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/except-2.c
r21f0aa8 re9145a3 2 2 3 3 4 #include <string.h> 4 #include <stdlib> 5 #include "except-mac.h" 5 6 6 // Local Exception Types and manual vtable types.7 #define GLUE2(left, right) left##right8 #define GLUE3(left, middle, right) left##middle##right9 #define BASE_EXCEPT __cfaehm__base_exception_t10 #define TABLE(name) GLUE2(name,_vtable)11 #define INSTANCE(name) GLUE3(_,name,_vtable_instance)12 #define TRIVIAL_EXCEPTION(name) \13 struct name; \14 struct TABLE(name) { \15 struct TABLE(BASE_EXCEPT) const * parent; \16 size_t size; \17 void (*copy)(name *this, name * other); \18 void (*free)(name *this); \19 const char * (*msg)(name *this); \20 }; \21 extern TABLE(name) INSTANCE(name); \22 struct name { \23 struct TABLE(name) const * virtual_table; \24 }; \25 const char * name##_msg(name * this) { \26 return #name; \27 } \28 void name##_copy(name * this, name * other) { \29 this->virtual_table = other->virtual_table; \30 } \31 TABLE(name) INSTANCE(name) @= { \32 .parent : &INSTANCE(BASE_EXCEPT), \33 .size : sizeof(name), .copy : name##_copy, \34 .free : ^?{}, .msg : name##_msg \35 }; \36 void ?{}(name * this) { \37 this->virtual_table = &INSTANCE(name); \38 }39 7 TRIVIAL_EXCEPTION(yin) 40 8 TRIVIAL_EXCEPTION(yang) … … 50 18 }; 51 19 extern num_error_vtable INSTANCE(num_error); 20 52 21 struct num_error { 53 22 struct num_error_vtable const * virtual_table; … … 55 24 int num; 56 25 }; 26 57 27 void num_error_msg(num_error * this) { 58 28 if ( ! this->msg ) { 59 const char * base = "Num Error with code: X"; 60 this->msg = strdup( base ); 29 static const char * base = "Num Error with code: X"; 30 this->msg = malloc(22); 31 for (int i = 0 ; (this->msg[i] = base[i]) ; ++i); 61 32 } 62 33 this->msg[21] = '0' + this->num; … … 90 61 try { 91 62 yin black; 92 throw (BASE_EXCEPT *)&black;63 THROW(&black); 93 64 } catch ( yin * error ) { 94 65 printf("throw yin caught.\n"); … … 97 68 try { 98 69 yang white; 99 throwResume (BASE_EXCEPT *)&white;70 THROW_RESUME(&white); 100 71 printf("> throwResume returned.\n"); 101 72 } catchResume ( yang * error ) { … … 105 76 try { 106 77 num_error x = { 2 }; 107 throw (BASE_EXCEPT *)&x;78 THROW(&x); 108 79 } 109 80 catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.