| [f19fbbc] | 1 | // Test virtual casts with polymorphic types. | 
|---|
|  | 2 |  | 
|---|
|  | 3 | /* IMPORTANT: The virtual system has not been finalized. However the | 
|---|
|  | 4 | * exception system does depend on the work-in-progress version currently | 
|---|
|  | 5 | * supported. That is also why the tests under the exception directory. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [3bf9d10] | 8 | #include <fstream.hfa> | 
|---|
| [f19fbbc] | 9 | #include <assert.h> | 
|---|
|  | 10 |  | 
|---|
| [ecfd758] | 11 |  | 
|---|
|  | 12 | struct __cfatid_struct_mono_base { | 
|---|
| [8f910430] | 13 | __cfavir_type_info const * parent; | 
|---|
| [ecfd758] | 14 | }; | 
|---|
|  | 15 |  | 
|---|
| [8f910430] | 16 | __attribute__(( cfa_linkonce )) | 
|---|
| [ecfd758] | 17 | struct __cfatid_struct_mono_base __cfatid_mono_base = { | 
|---|
| [8f910430] | 18 | (__cfavir_type_info *)0, | 
|---|
| [ecfd758] | 19 | }; | 
|---|
|  | 20 |  | 
|---|
| [f19fbbc] | 21 | struct mono_base_vtable { | 
|---|
| [ecfd758] | 22 | __cfatid_struct_mono_base const * const __cfavir_typeid; | 
|---|
| [f19fbbc] | 23 | }; | 
|---|
|  | 24 |  | 
|---|
|  | 25 | struct mono_base { | 
|---|
|  | 26 | mono_base_vtable const * virtual_table; | 
|---|
|  | 27 | }; | 
|---|
|  | 28 |  | 
|---|
| [ecfd758] | 29 | forall(T) | 
|---|
|  | 30 | struct __cfatid_struct_mono_child { | 
|---|
|  | 31 | __cfatid_struct_mono_base const * parent; | 
|---|
|  | 32 | }; | 
|---|
|  | 33 |  | 
|---|
| [fd54fef] | 34 | forall(T) | 
|---|
| [f19fbbc] | 35 | struct mono_child_vtable { | 
|---|
| [ecfd758] | 36 | __cfatid_struct_mono_child(T) const * const __cfavir_typeid; | 
|---|
| [f19fbbc] | 37 | }; | 
|---|
|  | 38 |  | 
|---|
| [fd54fef] | 39 | forall(T) | 
|---|
| [f19fbbc] | 40 | struct mono_child { | 
|---|
|  | 41 | mono_child_vtable(T) const * virtual_table; | 
|---|
|  | 42 | }; | 
|---|
|  | 43 |  | 
|---|
| [ecfd758] | 44 | __cfatid_struct_mono_child(int) __cfatid_mono_child @= { | 
|---|
|  | 45 | &__cfatid_mono_base, | 
|---|
|  | 46 | }; | 
|---|
|  | 47 |  | 
|---|
| [f19fbbc] | 48 | mono_child_vtable(int) _mono_child_vtable_instance @= { | 
|---|
| [ecfd758] | 49 | &__cfatid_mono_child, | 
|---|
| [f19fbbc] | 50 | }; | 
|---|
|  | 51 |  | 
|---|
|  | 52 | void mono_poly_test(void) { | 
|---|
|  | 53 | mono_child(int) child = { &_mono_child_vtable_instance }; | 
|---|
|  | 54 | mono_base * base = (virtual mono_base *)&child; | 
|---|
|  | 55 | assert(base); | 
|---|
|  | 56 | } | 
|---|
|  | 57 |  | 
|---|
| [ecfd758] | 58 |  | 
|---|
|  | 59 | forall(U) | 
|---|
|  | 60 | struct __cfatid_struct_poly_base { | 
|---|
| [8f910430] | 61 | __cfavir_type_info const * parent; | 
|---|
| [ecfd758] | 62 | }; | 
|---|
|  | 63 |  | 
|---|
| [fd54fef] | 64 | forall(U) | 
|---|
| [f19fbbc] | 65 | struct poly_base_vtable { | 
|---|
| [ecfd758] | 66 | __cfatid_struct_poly_base(U) const * const __cfavir_typeid; | 
|---|
| [f19fbbc] | 67 | }; | 
|---|
|  | 68 |  | 
|---|
| [fd54fef] | 69 | forall(U) | 
|---|
| [f19fbbc] | 70 | struct poly_base { | 
|---|
|  | 71 | poly_base_vtable(U) const * virtual_table; | 
|---|
|  | 72 | }; | 
|---|
|  | 73 |  | 
|---|
| [ecfd758] | 74 | forall(V) | 
|---|
|  | 75 | struct __cfatid_struct_poly_child { | 
|---|
|  | 76 | __cfatid_struct_poly_base(V) const * parent; | 
|---|
|  | 77 | }; | 
|---|
|  | 78 |  | 
|---|
| [fd54fef] | 79 | forall(V) | 
|---|
| [f19fbbc] | 80 | struct poly_child_vtable { | 
|---|
| [ecfd758] | 81 | __cfatid_struct_poly_child(V) const * const __cfavir_typeid; | 
|---|
| [f19fbbc] | 82 | }; | 
|---|
|  | 83 |  | 
|---|
| [fd54fef] | 84 | forall(V) | 
|---|
| [f19fbbc] | 85 | struct poly_child { | 
|---|
|  | 86 | poly_child_vtable(V) const * virtual_table; | 
|---|
|  | 87 | }; | 
|---|
|  | 88 |  | 
|---|
| [ecfd758] | 89 | __cfatid_struct_poly_base(int) __cfatid_poly_base @= { | 
|---|
| [8f910430] | 90 | (__cfavir_type_info *)0, | 
|---|
| [f19fbbc] | 91 | }; | 
|---|
| [ecfd758] | 92 | __cfatid_struct_poly_child(int) __cfatid_poly_child = { | 
|---|
|  | 93 | &__cfatid_poly_base, | 
|---|
|  | 94 | }; | 
|---|
|  | 95 | poly_child_vtable(int) _poly_child_vtable_instance @= { | 
|---|
|  | 96 | &__cfatid_poly_child, | 
|---|
| [f19fbbc] | 97 | }; | 
|---|
|  | 98 |  | 
|---|
|  | 99 | void poly_poly_test() { | 
|---|
|  | 100 | poly_child(int) child = { &_poly_child_vtable_instance }; | 
|---|
|  | 101 | poly_base(int) * base = (virtual poly_base(int) *)&child; | 
|---|
|  | 102 | assert(base); | 
|---|
|  | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | int main(void) { | 
|---|
|  | 106 | mono_poly_test(); | 
|---|
|  | 107 | poly_poly_test(); | 
|---|
| [3bf9d10] | 108 | sout | "done"; | 
|---|
| [f19fbbc] | 109 | } | 
|---|