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