source: tests/exceptions/virtual-poly.cfa @ 2cf3b87

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 2cf3b87 was 8f910430, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Updated the virtual module to prefix the names with the new convention and change the parent_vtable into type_info.

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[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
8#include <assert.h>
9
[ecfd758]10
11struct __cfatid_struct_mono_base {
[8f910430]12    __cfavir_type_info const * parent;
[ecfd758]13};
14
[8f910430]15__attribute__(( cfa_linkonce ))
[ecfd758]16struct __cfatid_struct_mono_base __cfatid_mono_base = {
[8f910430]17    (__cfavir_type_info *)0,
[ecfd758]18};
19
[f19fbbc]20struct mono_base_vtable {
[ecfd758]21        __cfatid_struct_mono_base const * const __cfavir_typeid;
[f19fbbc]22};
23
24struct mono_base {
25        mono_base_vtable const * virtual_table;
26};
27
[ecfd758]28forall(T)
29struct __cfatid_struct_mono_child {
30    __cfatid_struct_mono_base const * parent;
31};
32
[fd54fef]33forall(T)
[f19fbbc]34struct mono_child_vtable {
[ecfd758]35        __cfatid_struct_mono_child(T) const * const __cfavir_typeid;
[f19fbbc]36};
37
[fd54fef]38forall(T)
[f19fbbc]39struct mono_child {
40        mono_child_vtable(T) const * virtual_table;
41};
42
[ecfd758]43__cfatid_struct_mono_child(int) __cfatid_mono_child @= {
44        &__cfatid_mono_base,
45};
46
[f19fbbc]47mono_child_vtable(int) _mono_child_vtable_instance @= {
[ecfd758]48        &__cfatid_mono_child,
[f19fbbc]49};
50
51void mono_poly_test(void) {
52        mono_child(int) child = { &_mono_child_vtable_instance };
53        mono_base * base = (virtual mono_base *)&child;
54        assert(base);
55}
56
[ecfd758]57
58forall(U)
59struct __cfatid_struct_poly_base {
[8f910430]60    __cfavir_type_info const * parent;
[ecfd758]61};
62
[fd54fef]63forall(U)
[f19fbbc]64struct poly_base_vtable {
[ecfd758]65        __cfatid_struct_poly_base(U) const * const __cfavir_typeid;
[f19fbbc]66};
67
[fd54fef]68forall(U)
[f19fbbc]69struct poly_base {
70        poly_base_vtable(U) const * virtual_table;
71};
72
[ecfd758]73forall(V)
74struct __cfatid_struct_poly_child {
75    __cfatid_struct_poly_base(V) const * parent;
76};
77
[fd54fef]78forall(V)
[f19fbbc]79struct poly_child_vtable {
[ecfd758]80        __cfatid_struct_poly_child(V) const * const __cfavir_typeid;
[f19fbbc]81};
82
[fd54fef]83forall(V)
[f19fbbc]84struct poly_child {
85        poly_child_vtable(V) const * virtual_table;
86};
87
[ecfd758]88__cfatid_struct_poly_base(int) __cfatid_poly_base @= {
[8f910430]89        (__cfavir_type_info *)0,
[f19fbbc]90};
[ecfd758]91__cfatid_struct_poly_child(int) __cfatid_poly_child = {
92    &__cfatid_poly_base,
93};
94poly_child_vtable(int) _poly_child_vtable_instance @= {
95        &__cfatid_poly_child,
[f19fbbc]96};
97
98void poly_poly_test() {
99        poly_child(int) child = { &_poly_child_vtable_instance };
100        poly_base(int) * base = (virtual poly_base(int) *)&child;
101        assert(base);
102}
103
104int main(void) {
105        mono_poly_test();
106        poly_poly_test();
[ecfd758]107        printf( "done\n" );
[f19fbbc]108}
Note: See TracBrowser for help on using the repository browser.