Debian Codegraph @

terps/tads/tads3/test/data/inh_next.t

raw
1 #include <tads.h>
2
3 /*
4 * Define a class with a property that inherits from its superclass
5 */
6 #define DEF_CLASS_PROP1(classname, superclasses...) \
7 class classname: ##superclasses \
8 prop1() \
9 { \
10 #classname ## ".prop1\n"; \
11 inherited(); \
12 }
13
14 /* simple linear inheritance pattern */
15 DEF_CLASS_PROP1(A, object);
16 DEF_CLASS_PROP1(B, A);
17 DEF_CLASS_PROP1(C, B);
18
19 /*
20 * diamond-shaped inheritance pattern
21 */
22 DEF_CLASS_PROP1(A1, object);
23 DEF_CLASS_PROP1(B1, A1);
24 DEF_CLASS_PROP1(C1, A1);
25 DEF_CLASS_PROP1(D1, B1, C1);
26
27 /*
28 * diamond-shaped inheritance, with only the middle level defining prop1
29 */
30 class A2: object;
31 DEF_CLASS_PROP1(B2, A2);
32 DEF_CLASS_PROP1(C2, A2);
33 class D2: B2, C2;
34
35 /*
36 * diamond with double-deep left leg
37 */
38 DEF_CLASS_PROP1(A3, object);
39 DEF_CLASS_PROP1(B3, A3);
40 DEF_CLASS_PROP1(C3, B3);
41 DEF_CLASS_PROP1(D3, A3);
42 DEF_CLASS_PROP1(E3, C3, D3);
43
44 /*
45 * complex pattern
46 */
47 class G4: object;
48 DEF_CLASS_PROP1(F4, G4);
49 DEF_CLASS_PROP1(E4, G4);
50 DEF_CLASS_PROP1(C4, E4);
51 DEF_CLASS_PROP1(B4, C4);
52 DEF_CLASS_PROP1(D4, E4);
53 DEF_CLASS_PROP1(A4, B4, D4, F4);
54
55 main(args)
56 {
57 /* call the various subclass methods */
58 "C.prop1:\n"; C.prop1();
59 "\bD1.prop1:\n"; D1.prop1();
60 "\bD2.prop1:\n"; D2.prop1();
61 "\bE3.prop1:\n"; E3.prop1();
62 "\bA4.prop1:\n"; A4.prop1();
63 }
64