1 /* Copyright (C) 2000 by Universitaet Karlsruhe
4 * Author: Goetz Lindenmaier
17 * This file constructs type information for the following pseudo-program.
18 * The procedure code is not constructed.
24 * class C implements I {
25 * void m1 (void) {return};
26 * void m2 (int) {return 0};
33 * class E extends C, D {
34 * void m2 (int) {return 1};
40 int main(int argc, char **argv)
42 ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai, *bi; /* suffix i names identifiers */
43 type *it, *ct, *dt, *et; /* t names types */
46 entity *i_m1e, *c_m1e, *c_m2e, *e_m2e, *d_be, *e_ae; /* e names entities */
48 printf("\nCreating type information for INHERITANCE_EXAMPLE ...\n");
53 /** make idents for all used identifiers in the program. */
54 ii = id_from_str("i", strlen("i"));
55 ci = id_from_str("c", strlen("c"));
56 di = id_from_str("d", strlen("d"));
57 ei = id_from_str("e", strlen("e"));
58 m1i = id_from_str("m1", strlen("m1"));
59 m2i = id_from_str("m2", strlen("m2"));
60 inti= id_from_str("int",strlen("int"));
61 ai = id_from_str("a", strlen("a"));
62 bi = id_from_str("b", strlen("b"));
64 /** make the type information needed */
65 /* Language defined types */
66 intt = new_type_primitive(inti, mode_Iu);
67 /* Program defined types */
68 it = new_type_class(ii); /* The fact that this is an interface is
69 of no interest. It's just a class without
70 fields and implementations. But the
71 implementation will never be needed. */
72 ct = new_type_class(ci);
73 dt = new_type_class(di);
74 et = new_type_class(ei);
75 /* Methods with the same type should use the same
76 method type information! */
77 m1t = new_type_method(m1i, 0, 0); /* 0 parameters, 0 results */
78 m2t = new_type_method(m2i, 1, 0); /* 1 parameter, 0 results */
80 /** add structure to type graph **/
81 /* parameters of methods */
82 set_method_param_type(m2t, 0, intt);
83 /* inheritance. The other direction is added automatically. */
84 add_class_subtype(it, ct);
85 add_class_subtype(ct, et);
86 add_class_subtype(dt, et);
89 i_m1e = new_entity(it, m1i, m1t);
90 c_m1e = new_entity(ct, m1i, m1t);
91 c_m2e = new_entity(ct, m2i, m2t);
92 e_m2e = new_entity(et, m2i, m2t);
93 d_be = new_entity(dt, bi, intt);
94 e_ae = new_entity(et, ai, intt);
96 /** Add overwirtes relation **/
97 /* How these edges are added depends on the source language. */
98 add_entity_overwrites (c_m1e, i_m1e);
99 add_entity_overwrites (e_m2e, c_m2e);
102 printf("Done building the graph. Dumping it.\n");
105 printf("use xvcg to view this graph:\n");
106 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");