3 * File name: ir/tr/type.c
4 * Purpose: Representation of types.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 * file type.c - implementation of the datastructure to hold
16 * (C) 2004 by Universitaet Karlsruhe
25 #include "type_identify_t.h"
40 /* The hash set for types. */
41 static pset *type_table = NULL;
43 /* hash and compare types */
44 static hash_types_func_t *hash_types_func;
45 static compare_types_func_t *compare_types_func;
47 int compare_names (const void *tp1, const void *tp2) {
48 type *t1 = (type *) tp1;
49 type *t2 = (type *) tp2;
52 (t1->type_op != t2->type_op ||
53 t1->name != t2->name ) );
56 /* stuff for comparing two types. */
57 int compare_strict (const void *tp1, const void *tp2) {
58 type *t1 = (type *) tp1;
59 type *t2 = (type *) tp2;
63 /* stuff to compute a hash value for a type. */
64 int hash_name (type *tp) {
65 unsigned h = (unsigned)tp->type_op;
66 h = 9*h + (unsigned)tp->name;
70 /* The function that hashes a type. */
71 type *mature_type(type *tp) {
76 o = pset_insert (type_table, tp, hash_types_func(tp) );
78 if (!o || o == tp) return tp;
80 exchange_types(tp, o);
86 /* The function that hashes a type. */
87 type *mature_type_free(type *tp) {
92 o = pset_insert (type_table, tp, hash_types_func(tp) );
94 if (!o || o == tp) return tp;
96 free_type_entities(tp);
102 /* The function that hashes a type. */
103 type *mature_type_free_entities(type *tp) {
108 o = pset_insert (type_table, tp, hash_types_func(tp) );
110 if (!o || o == tp) return tp;
112 free_type_entities(tp);
113 exchange_types(tp, o);
118 /* initialize this module */
119 void init_type_identify(compare_types_func_t *cmp, hash_types_func_t *hash) {
120 compare_types_func = cmp ? cmp : compare_strict;
121 hash_types_func = hash ? hash : hash_name;
123 type_table = new_pset (compare_types_func, 8);