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 <fstream.hfa>
|
---|
9 | #include <assert.h>
|
---|
10 |
|
---|
11 |
|
---|
12 | struct __cfatid_struct_mono_base {
|
---|
13 | __cfavir_type_info const * parent;
|
---|
14 | };
|
---|
15 |
|
---|
16 | __attribute__(( cfa_linkonce ))
|
---|
17 | struct __cfatid_struct_mono_base __cfatid_mono_base = {
|
---|
18 | (__cfavir_type_info *)0,
|
---|
19 | };
|
---|
20 |
|
---|
21 | struct mono_base_vtable {
|
---|
22 | __cfatid_struct_mono_base const * const __cfavir_typeid;
|
---|
23 | };
|
---|
24 |
|
---|
25 | struct mono_base {
|
---|
26 | mono_base_vtable const * virtual_table;
|
---|
27 | };
|
---|
28 |
|
---|
29 | forall(T)
|
---|
30 | struct __cfatid_struct_mono_child {
|
---|
31 | __cfatid_struct_mono_base const * parent;
|
---|
32 | };
|
---|
33 |
|
---|
34 | forall(T)
|
---|
35 | struct mono_child_vtable {
|
---|
36 | __cfatid_struct_mono_child(T) const * const __cfavir_typeid;
|
---|
37 | };
|
---|
38 |
|
---|
39 | forall(T)
|
---|
40 | struct mono_child {
|
---|
41 | mono_child_vtable(T) const * virtual_table;
|
---|
42 | };
|
---|
43 |
|
---|
44 | __cfatid_struct_mono_child(int) __cfatid_mono_child @= {
|
---|
45 | &__cfatid_mono_base,
|
---|
46 | };
|
---|
47 |
|
---|
48 | mono_child_vtable(int) _mono_child_vtable_instance @= {
|
---|
49 | &__cfatid_mono_child,
|
---|
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 |
|
---|
58 |
|
---|
59 | forall(U)
|
---|
60 | struct __cfatid_struct_poly_base {
|
---|
61 | __cfavir_type_info const * parent;
|
---|
62 | };
|
---|
63 |
|
---|
64 | forall(U)
|
---|
65 | struct poly_base_vtable {
|
---|
66 | __cfatid_struct_poly_base(U) const * const __cfavir_typeid;
|
---|
67 | };
|
---|
68 |
|
---|
69 | forall(U)
|
---|
70 | struct poly_base {
|
---|
71 | poly_base_vtable(U) const * virtual_table;
|
---|
72 | };
|
---|
73 |
|
---|
74 | forall(V)
|
---|
75 | struct __cfatid_struct_poly_child {
|
---|
76 | __cfatid_struct_poly_base(V) const * parent;
|
---|
77 | };
|
---|
78 |
|
---|
79 | forall(V)
|
---|
80 | struct poly_child_vtable {
|
---|
81 | __cfatid_struct_poly_child(V) const * const __cfavir_typeid;
|
---|
82 | };
|
---|
83 |
|
---|
84 | forall(V)
|
---|
85 | struct poly_child {
|
---|
86 | poly_child_vtable(V) const * virtual_table;
|
---|
87 | };
|
---|
88 |
|
---|
89 | __cfatid_struct_poly_base(int) __cfatid_poly_base @= {
|
---|
90 | (__cfavir_type_info *)0,
|
---|
91 | };
|
---|
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,
|
---|
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();
|
---|
108 | sout | "done";
|
---|
109 | }
|
---|