2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Hash table to store names.
23 * @author Goetz Lindenmaier
43 /* it's ok to use memcmp here, we check only strings */
44 id_set = new_set(memcmp, 128);
47 ident *new_id_from_chars(const char *str, size_t len)
49 unsigned hash = HASH_STR(str, len);
50 ident *result = (ident*) set_hinsert0(id_set, str, len, hash);
54 ident *new_id_from_str(const char *str)
57 return new_id_from_chars(str, strlen(str));
60 const char *get_id_str(ident *id)
62 struct set_entry *entry = (struct set_entry*) id;
63 return (const char*) entry->dptr;
66 size_t get_id_strlen(ident *id)
68 struct set_entry *entry = (struct set_entry*) id;
72 void finish_ident(void)
78 int id_is_prefix(ident *prefix, ident *id)
80 size_t prefix_len = get_id_strlen(prefix);
81 if (prefix_len > get_id_strlen(id))
83 return 0 == memcmp(get_id_str(prefix), get_id_str(id), prefix_len);
86 int id_is_suffix(ident *suffix, ident *id)
88 size_t suflen = get_id_strlen(suffix);
89 size_t idlen = get_id_strlen(id);
95 part = get_id_str(id);
96 part = part + (idlen - suflen);
98 return 0 == memcmp(get_id_str(suffix), part, suflen);
101 int id_contains_char(ident *id, char c)
103 return strchr(get_id_str(id), c) != NULL;
106 ident *id_unique(const char *tag)
108 static unsigned unique_id = 0;
111 snprintf(buf, sizeof(buf), tag, unique_id);
113 return new_id_from_str(buf);