source: tests/exceptions/virtual-poly.cfa @ 0336e83

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0336e83 was ecfd758, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Major exception update, seperating type-ids from virtual tables. The major interface changes are done. There is a regression of ?Cancelled(T) to Some?Cancelled. There is some bits of code for the new verion of the ?Cancelled(T) interface already there. Not connected yet but I just reached the limit of what I wanted to do in one commit and then spent over a day cleaning up, so it will replace Some?Cancelled in a future commit.

  • Property mode set to 100644
File size: 2.3 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 {
12    __cfa__parent_vtable const * parent;
13};
14
15__attribute__(( section(".gnu.linkonce.__cfatid_mono_base") ))
16struct __cfatid_struct_mono_base __cfatid_mono_base = {
17    (__cfa__parent_vtable *)0,
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 {
60    __cfa__parent_vtable const * parent;
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 @= {
89        (__cfa__parent_vtable *)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.