summaryrefslogtreecommitdiffhomepage
path: root/ir/ident
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2013-02-19 10:05:38 +0100
committerMatthias Braun <matze@braunis.de>2013-02-19 10:09:50 +0100
commit01bea684656d0253a3a54258ecb16e3d081a3260 (patch)
tree819fe531b181f70d633933df9f391c1fa67c2105 /ir/ident
parentfb350c510d90f77c08db513c296ca8ca67ab525f (diff)
Simplify ident implementation
Remove some unnecessary/unused functions. Simplify the implementation to pass around const char* (which is a little bit faster and also nicer in gdb)
Diffstat (limited to 'ir/ident')
-rw-r--r--ir/ident/ident.c45
-rw-r--r--ir/ident/ident_t.h7
-rw-r--r--ir/ident/mangle.c57
3 files changed, 37 insertions, 72 deletions
diff --git a/ir/ident/ident.c b/ir/ident/ident.c
index fbfe388..5838982 100644
--- a/ir/ident/ident.c
+++ b/ir/ident/ident.c
@@ -32,9 +32,9 @@ void init_ident(void)
ident *new_id_from_chars(const char *str, size_t len)
{
- unsigned hash = hash_data((const unsigned char*)str, len);
- ident *result = (ident*) set_hinsert0(id_set, str, len, hash);
- return result;
+ unsigned hash = hash_data((const unsigned char*)str, len);
+ set_entry *result = set_hinsert0(id_set, str, len, hash);
+ return (ident*)result->dptr;
}
ident *new_id_from_str(const char *str)
@@ -43,16 +43,9 @@ ident *new_id_from_str(const char *str)
return new_id_from_chars(str, strlen(str));
}
-const char *get_id_str(ident *id)
+const char *(get_id_str)(ident *id)
{
- struct set_entry *entry = (struct set_entry*) id;
- return (const char*) entry->dptr;
-}
-
-size_t get_id_strlen(ident *id)
-{
- struct set_entry *entry = (struct set_entry*) id;
- return entry->size;
+ return get_id_str_(id);
}
void finish_ident(void)
@@ -61,34 +54,6 @@ void finish_ident(void)
id_set = NULL;
}
-int id_is_prefix(ident *prefix, ident *id)
-{
- size_t prefix_len = get_id_strlen(prefix);
- if (prefix_len > get_id_strlen(id))
- return 0;
- return 0 == memcmp(get_id_str(prefix), get_id_str(id), prefix_len);
-}
-
-int id_is_suffix(ident *suffix, ident *id)
-{
- size_t suflen = get_id_strlen(suffix);
- size_t idlen = get_id_strlen(id);
- const char *part;
-
- if (suflen > idlen)
- return 0;
-
- part = get_id_str(id);
- part = part + (idlen - suflen);
-
- return 0 == memcmp(get_id_str(suffix), part, suflen);
-}
-
-int id_contains_char(ident *id, char c)
-{
- return strchr(get_id_str(id), c) != NULL;
-}
-
ident *id_unique(const char *tag)
{
static unsigned unique_id = 0;
diff --git a/ir/ident/ident_t.h b/ir/ident/ident_t.h
index 3b72e30..9f0143c 100644
--- a/ir/ident/ident_t.h
+++ b/ir/ident/ident_t.h
@@ -13,6 +13,13 @@
#include "ident.h"
+#define get_id_str(x) get_id_str_(x)
+
+static inline const char *get_id_str_(ident *ident)
+{
+ return ident;
+}
+
/**
* Initialize the ident module.
*/
diff --git a/ir/ident/mangle.c b/ir/ident/mangle.c
index ad1b0ac..c86f83f 100644
--- a/ir/ident/mangle.c
+++ b/ir/ident/mangle.c
@@ -30,54 +30,47 @@ static inline ident *mangle_type(const ir_type *tp)
return tp->name;
}
-/* Returns a new ident that represents 'firstscnd'. */
-ident *id_mangle(ident *first, ident *scnd)
+static void obstack_grow_ident(struct obstack *obst, ident *id)
{
- char *cp;
- int len;
- ident *res;
+ const char *c = get_id_str(id);
+ for ( ; *c != '\0'; ++c) {
+ obstack_1grow(obst, *c);
+ }
+}
- obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
- obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
- len = obstack_object_size(&mangle_obst);
- cp = (char*)obstack_finish(&mangle_obst);
- res = new_id_from_chars(cp, len);
- obstack_free(&mangle_obst, cp);
+static ident *new_ident_from_obst(struct obstack *obst)
+{
+ size_t len = obstack_object_size(obst);
+ char *string = (char*)obstack_finish(obst);
+ ident *res = new_id_from_chars(string, len);
+ obstack_free(obst, string);
return res;
}
+/* Returns a new ident that represents 'firstscnd'. */
+ident *id_mangle(ident *first, ident *scnd)
+{
+ obstack_grow_ident(&mangle_obst, first);
+ obstack_grow_ident(&mangle_obst, scnd);
+ return new_ident_from_obst(&mangle_obst);
+}
+
/** Returns a new ident that represents 'prefixscndsuffix'. */
ident *id_mangle3(const char *prefix, ident *scnd, const char *suffix)
{
- char *cp;
- int len;
- ident *res;
-
obstack_grow(&mangle_obst, prefix, strlen(prefix));
- obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
+ obstack_grow_ident(&mangle_obst, scnd);
obstack_grow(&mangle_obst, suffix, strlen(suffix));
- len = obstack_object_size(&mangle_obst);
- cp = (char*)obstack_finish(&mangle_obst);
- res = new_id_from_chars(cp, len);
- obstack_free(&mangle_obst, cp);
- return res;
+ return new_ident_from_obst(&mangle_obst);
}
/** Returns a new ident that represents first<c>scnd. */
static ident *id_mangle_3(ident *first, char c, ident *scnd)
{
- char *cp;
- int len;
- ident *res;
-
- obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
+ obstack_grow_ident(&mangle_obst, first);
obstack_1grow(&mangle_obst, c);
- obstack_grow(&mangle_obst,get_id_str(scnd),get_id_strlen(scnd));
- len = obstack_object_size(&mangle_obst);
- cp = (char*)obstack_finish(&mangle_obst);
- res = new_id_from_chars(cp, len);
- obstack_free(&mangle_obst, cp);
- return res;
+ obstack_grow_ident(&mangle_obst, scnd);
+ return new_ident_from_obst(&mangle_obst);
}
/* Returns a new ident that represents first_scnd. */