3 * File name: testprograms/inheritance_example.c
4 * Purpose: Shows type graph with inheritance.
5 * Author: Christian Schaefer, Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
21 * This file constructs type information for the following pseudo-program.
22 * The procedure code is not constructed.
28 * class C implements I {
29 * void m1 (void) {return};
30 * void m2 (int) {return 0};
37 * class E extends C, D {
38 * void m2 (int) {return 1};
44 int main(int argc, char **argv)
46 ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai, *bi; /* suffix i names identifiers */
47 type *it, *ct, *dt, *et; /* t names types */
50 entity *i_m1e, *c_m1e, *c_m2e, *e_m2e, *d_be, *e_ae; /* e names entities */
52 printf("\nCreating type information for INHERITANCE_EXAMPLE ...\n");
57 /** make idents for all used identifiers in the program. */
58 ii = new_id_from_chars("i", strlen("i"));
59 ci = new_id_from_chars("c", strlen("c"));
60 di = new_id_from_chars("d", strlen("d"));
61 ei = new_id_from_chars("e", strlen("e"));
62 m1i = new_id_from_chars("m1", strlen("m1"));
63 m2i = new_id_from_chars("m2", strlen("m2"));
64 inti= new_id_from_chars("int",strlen("int"));
65 ai = new_id_from_chars("a", strlen("a"));
66 bi = new_id_from_chars("b", strlen("b"));
68 /** make the type information needed */
69 /* Language defined types */
70 intt = new_type_primitive(inti, mode_Iu);
71 /* Program defined types */
72 it = new_type_class(ii); /* The fact that this is an interface is
73 of no interest. It's just a class without
74 fields and implementations. But the
75 implementation will never be needed. */
76 ct = new_type_class(ci);
77 dt = new_type_class(di);
78 et = new_type_class(ei);
79 /* Methods with the same type should use the same
80 method type information! */
81 m1t = new_type_method(m1i, 0, 0); /* 0 parameters, 0 results */
82 m2t = new_type_method(m2i, 1, 0); /* 1 parameter, 0 results */
84 /** add structure to type graph **/
85 /* parameters of methods */
86 set_method_param_type(m2t, 0, intt);
87 /* inheritance. The other direction is added automatically. */
88 add_class_subtype(it, ct);
89 add_class_subtype(ct, et);
90 add_class_subtype(dt, et);
93 i_m1e = new_entity(it, m1i, m1t);
94 c_m1e = new_entity(ct, m1i, m1t);
95 c_m2e = new_entity(ct, m2i, m2t);
96 e_m2e = new_entity(et, m2i, m2t);
97 d_be = new_entity(dt, bi, intt);
98 e_ae = new_entity(et, ai, intt);
100 /** Add overwirtes relation **/
101 /* How these edges are added depends on the source language. */
102 add_entity_overwrites (c_m1e, i_m1e);
103 add_entity_overwrites (e_m2e, c_m2e);
106 printf("Done building the graph. Dumping it.\n");
109 printf("use xvcg to view this graph:\n");
110 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");