source: tests/exceptions/virtual-poly.cfa @ dafbde8

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since dafbde8 was fd54fef, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

  • Property mode set to 100644
File size: 1.8 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
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
[fd54fef]18forall(T)
[f19fbbc]19struct mono_child_vtable {
20        mono_base_vtable const * const parent;
21};
22
[fd54fef]23forall(T)
[f19fbbc]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
[fd54fef]39forall(U)
[f19fbbc]40struct poly_base_vtable {
41        poly_base_vtable(U) const * const parent;
42};
43
[fd54fef]44forall(U)
[f19fbbc]45struct poly_base {
46        poly_base_vtable(U) const * virtual_table;
47};
48
[fd54fef]49forall(V)
[f19fbbc]50struct poly_child_vtable {
51        poly_base_vtable(V) const * const parent;
52};
53
[fd54fef]54forall(V)
[f19fbbc]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();
[66812dd]79        printf( "done\n" );                             // non-empty .expect file
[f19fbbc]80}
Note: See TracBrowser for help on using the repository browser.