source: tests/exceptions/virtual-poly.cfa@ 293dc1c

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 293dc1c was 66812dd, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

convert tests to always print output (no empty .expect files)

  • Property mode set to 100644
File size: 1.8 KB
Line 
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
10struct mono_base_vtable {
11 mono_base_vtable const * const parent;
12};
13
14struct mono_base {
15 mono_base_vtable const * virtual_table;
16};
17
18forall(otype T)
19struct mono_child_vtable {
20 mono_base_vtable const * const parent;
21};
22
23forall(otype T)
24struct mono_child {
25 mono_child_vtable(T) const * virtual_table;
26};
27
28mono_base_vtable _mono_base_vtable_instance @= { 0 };
29mono_child_vtable(int) _mono_child_vtable_instance @= {
30 &_mono_base_vtable_instance
31};
32
33void mono_poly_test(void) {
34 mono_child(int) child = { &_mono_child_vtable_instance };
35 mono_base * base = (virtual mono_base *)&child;
36 assert(base);
37}
38
39forall(otype U)
40struct poly_base_vtable {
41 poly_base_vtable(U) const * const parent;
42};
43
44forall(otype U)
45struct poly_base {
46 poly_base_vtable(U) const * virtual_table;
47};
48
49forall(otype V)
50struct poly_child_vtable {
51 poly_base_vtable(V) const * const parent;
52};
53
54forall(otype V)
55struct poly_child {
56 poly_child_vtable(V) const * virtual_table;
57};
58
59poly_base_vtable(int) _poly_base_vtable_instance @= { 0 };
60poly_child_vtable(int) _poly_child_vtable_instance @= {
61 &_poly_base_vtable_instance
62};
63/* Resolver bug keeps me from adding these.
64poly_base_vtable(char) _poly_base_vtable_instance @= { 0 };
65poly_child_vtable(char) _poly_child_vtable_instance @= {
66 &_poly_base_vtable_instance
67};
68*/
69
70void poly_poly_test() {
71 poly_child(int) child = { &_poly_child_vtable_instance };
72 poly_base(int) * base = (virtual poly_base(int) *)&child;
73 assert(base);
74}
75
76int main(void) {
77 mono_poly_test();
78 poly_poly_test();
79 printf( "done\n" ); // non-empty .expect file
80}
Note: See TracBrowser for help on using the repository browser.