used ircons_t.h now
[libfirm] / ir / ident / ident.c
index e01d0b7..5d63240 100644 (file)
@@ -1,6 +1,14 @@
-/* Ident --- unique handles for identifiers
-   Copyright (C) 1995, 1996 Markus Armbruster
-   All rights reserved. */
+/*
+ * Project:     libFIRM
+ * File name:   ir/common/ident.c
+ * Purpose:     Hash table to store names.
+ * Author:      Goetz Lindenmaier
+ * Modified by:
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1999-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
-#include "array.h"
-#include "tune.h"
-#include "ident.h"
-#include "xprintf.h"
+#include <stddef.h>
+#include <stdlib.h>
 
-#define XX_USER(name) ident *id_##name;
-#define XX_INTERNAL(name, str) XX_USER(name)
-#undef XX_USER
-#undef XX_INTERNAL
+#include "ident_t.h"
 
-set *id_set;
+set *__id_set;
 
-
-ident *
-new_id_derived (const char *pfx, ident *id)
+void id_init(int initial_n_idents)
 {
-  int pfx_len = strlen (pfx);
-  int len = pfx_len + ID_TO_STRLEN (id);
-  char *str = alloca (len);
-
-  memcpy (str, pfx, pfx_len);
-  memcpy (str+pfx_len, ID_TO_STR (id), ID_TO_STRLEN (id));
-  return ID_FROM_STR (str, pfx_len + ID_TO_STRLEN (id));
+  __id_set = new_set(memcmp, initial_n_idents);
 }
 
+void id_finish (void) {
+  del_set(__id_set);
+  __id_set = NULL;
+}
 
-ident *
-new_id_internal (void)
+ident *(id_from_str)(const char *str, int len)
 {
-  static char str[] = "_0000000";
-  int i;
-
-  i = sizeof (str) - 2;
-  while (++str[i] == '9'+1) {
-    str[i--] = '0';
-    /* if following assertion fails, we get called far too often ;-) */
-    assert (i >= 0);
-  }
-  assert (('0' <= str[i]) && (str[i] <= '9'));
-
-  return ID_FROM_STR (str, sizeof (str) - 1);
+  return __id_from_str(str, len);
 }
 
+ident *new_id_from_str(const char *str)
+{
+  assert(str);
+  return id_from_str(str, strlen(str));
+}
 
-bool
-id_is_internal (ident *id)
+const char *(get_id_str)(ident *id)
 {
-  assert (ID_TO_STRLEN (id));
-  return !!ispunct (ID_TO_STR(id)[0]);
+  return __get_id_str(id);
 }
 
+int (get_id_strlen)(ident *id)
+{
+  return __get_id_strlen(id);
+}
 
-#ifndef NDEBUG
+int id_is_prefix(ident *prefix, ident *id)
+{
+  if (get_id_strlen(prefix) > get_id_strlen(id)) return 0;
+  return 0 == memcmp(prefix->dptr, id->dptr, get_id_strlen(prefix));
+}
 
-void
-ids_vrfy (ident **id)
+int id_is_suffix(ident *suffix, ident *id)
 {
-  int i;
+  int suflen = get_id_strlen(suffix);
+  int idlen  = get_id_strlen(id);
+  char *part;
 
-  for (i = 0;  i < ARR_LEN (id);  ++i) {
-    ID_VRFY (id[i]);
-  }
-}
+  if (suflen > idlen) return 0;
 
-#endif
+  part = (char *)id->dptr;
+  part = part + (idlen - suflen);
 
-int
-ident_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
-{
-  ident *id = XP_GETARG (ident *, 0);
-  return XPMR (ID_TO_STR (id), ID_TO_STRLEN (id));
+  return 0 == memcmp(suffix->dptr, part, suflen);
 }
 
+int id_contains_char(ident *id, char c)
+{
+  return strchr(get_id_str(id), c) != NULL;
+}
 
-void
-id_init (void)
+int print_id (ident *id)
 {
-  id_set = new_set (memcmp, TUNE_NIDENTS);
+  return printf("%s", get_id_str(id));
+}
 
-#define XX_USER(name) id_##name = ID_FROM_STR(#name, sizeof(#name)- 1);
-#define XX_INTERNAL(name, str) id_##name = ID_FROM_STR((str), sizeof((str))-1);
-#undef XX_USER
-#undef XX_INTERNAL
+int fprint_id (FILE *F, ident *id)
+{
+  return fprintf(F, "%s", get_id_str(id));
 }