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:
21 *** class C implements I {
22 *** void m1 (void) {return};
23 *** void m2 (int) {return 0};
30 *** class E extends C, D {
31 *** void m2 (int) {return 1};
37 int main(int argc, char **argv)
39 ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai; /* suffix i names identifiers */
40 type_class *it, *ct, *dt, *et; /* t names types */
41 type_method *m1t, *m2t;
43 entity *c_m1e, *c_m2e, *e_m2e, *d_ae, *e_ae; /* e names entities */
47 printf("\nCreating type information...\n");
52 /** make idents for all used identifiers in the program. */
53 ii = id_from_str("i", strlen("i"));
54 ci = id_from_str("c", strlen("c"));
55 di = id_from_str("d", strlen("d"));
56 ei = id_from_str("e", strlen("e"));
57 m1i = id_from_str("m1", strlen("m1"));
58 m2i = id_from_str("m2", strlen("m2"));
59 inti= id_from_str("int",strlen("int"));
60 ai = id_from_str("a", strlen("a"));
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);
67 ct = new_type_class(ci);
68 dt = new_type_class(di);
69 et = new_type_class(ei);
70 m1t = new_type_method(m1i, 0, 0); /* 0 parameters, 0 results */
71 m2t = new_type_method(m2i, 1, 0); /* 1 parameter, 0 results */
73 /** add structure to type graph **/
74 /* parameters of methods */
75 set_method_param_type(m2t, 0, (type *)intt);
77 add_class_subtype(it, ct);
78 add_class_subtype(ct, et);
79 add_class_subtype(dt, et);
80 add_class_supertype(ct, it);
81 add_class_supertype(et, ct);
82 add_class_supertype(et, dt);
85 c_m1e = new_entity((type *)ct, m1i, (type *)m1t);
86 c_m2e = new_entity((type *)ct, m2i, (type *)m2t);
87 e_m2e = new_entity((type *)et, m2i, (type *)m2t);
88 d_ae = new_entity((type *)dt, ai, (type *)intt);
89 e_ae = new_entity((type *)et, ai, (type *)intt);
91 printf("Done building the graph. Dumping it.\n");
94 printf("use xvcg to view this graph:\n");
95 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");