source: tests/exceptions/virtual-poly.cfa @ 4e09af2

Last change on this file since 4e09af2 was 3bf9d10, checked in by Peter A. Buhr <pabuhr@…>, 17 months ago

change printf to sout

  • 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
[3bf9d10]8#include <fstream.hfa>
[f19fbbc]9#include <assert.h>
10
[ecfd758]11
12struct __cfatid_struct_mono_base {
[8f910430]13    __cfavir_type_info const * parent;
[ecfd758]14};
15
[8f910430]16__attribute__(( cfa_linkonce ))
[ecfd758]17struct __cfatid_struct_mono_base __cfatid_mono_base = {
[8f910430]18    (__cfavir_type_info *)0,
[ecfd758]19};
20
[f19fbbc]21struct mono_base_vtable {
[ecfd758]22        __cfatid_struct_mono_base const * const __cfavir_typeid;
[f19fbbc]23};
24
25struct mono_base {
26        mono_base_vtable const * virtual_table;
27};
28
[ecfd758]29forall(T)
30struct __cfatid_struct_mono_child {
31    __cfatid_struct_mono_base const * parent;
32};
33
[fd54fef]34forall(T)
[f19fbbc]35struct mono_child_vtable {
[ecfd758]36        __cfatid_struct_mono_child(T) const * const __cfavir_typeid;
[f19fbbc]37};
38
[fd54fef]39forall(T)
[f19fbbc]40struct 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]48mono_child_vtable(int) _mono_child_vtable_instance @= {
[ecfd758]49        &__cfatid_mono_child,
[f19fbbc]50};
51
52void 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
59forall(U)
60struct __cfatid_struct_poly_base {
[8f910430]61    __cfavir_type_info const * parent;
[ecfd758]62};
63
[fd54fef]64forall(U)
[f19fbbc]65struct poly_base_vtable {
[ecfd758]66        __cfatid_struct_poly_base(U) const * const __cfavir_typeid;
[f19fbbc]67};
68
[fd54fef]69forall(U)
[f19fbbc]70struct poly_base {
71        poly_base_vtable(U) const * virtual_table;
72};
73
[ecfd758]74forall(V)
75struct __cfatid_struct_poly_child {
76    __cfatid_struct_poly_base(V) const * parent;
77};
78
[fd54fef]79forall(V)
[f19fbbc]80struct poly_child_vtable {
[ecfd758]81        __cfatid_struct_poly_child(V) const * const __cfavir_typeid;
[f19fbbc]82};
83
[fd54fef]84forall(V)
[f19fbbc]85struct 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};
95poly_child_vtable(int) _poly_child_vtable_instance @= {
96        &__cfatid_poly_child,
[f19fbbc]97};
98
99void 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
105int main(void) {
106        mono_poly_test();
107        poly_poly_test();
[3bf9d10]108        sout | "done";
[f19fbbc]109}
Note: See TracBrowser for help on using the repository browser.