2003-06-11 David Carlton <carlton@bactrian.org>
[deliverable/binutils-gdb.git] / gdb / jv-lang.c
index a2a44f0543ee518fb3ad5f9b9fd9fba79e07f0be..e3ae1882dfccb51c6da0dab23eeb59e5259a3bfc 100644 (file)
@@ -35,6 +35,7 @@
 #include "gdbcore.h"
 #include "block.h"
 #include "demangle.h"
+#include "dictionary.h"
 #include <ctype.h>
 
 struct type *java_int_type;
@@ -91,9 +92,7 @@ get_dynamics_objfile (void)
 
 static struct symtab *class_symtab = NULL;
 
-/* Maximum number of class in class_symtab before relocation is needed. */
-
-static int class_symtab_space;
+static void free_class_block (struct symtab *symtab);
 
 static struct symtab *
 get_java_class_symtab (void)
@@ -106,15 +105,16 @@ get_java_class_symtab (void)
       class_symtab = allocate_symtab ("<java-classes>", objfile);
       class_symtab->language = language_java;
       bv = (struct blockvector *)
-       obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector));
+       obstack_alloc (&objfile->symbol_obstack,
+                      sizeof (struct blockvector) + sizeof (struct block *));
       BLOCKVECTOR_NBLOCKS (bv) = 1;
       BLOCKVECTOR (class_symtab) = bv;
 
       /* Allocate dummy STATIC_BLOCK. */
       bl = (struct block *)
        obstack_alloc (&objfile->symbol_obstack, sizeof (struct block));
-      BLOCK_NSYMS (bl) = 0;
-      BLOCK_HASHTABLE (bl) = 0;
+      BLOCK_DICT (bl) = dict_create_linear (&objfile->symbol_obstack,
+                                           NULL);
       BLOCK_START (bl) = 0;
       BLOCK_END (bl) = 0;
       BLOCK_FUNCTION (bl) = NULL;
@@ -124,13 +124,12 @@ get_java_class_symtab (void)
       BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
 
       /* Allocate GLOBAL_BLOCK.  This has to be relocatable. */
-      class_symtab_space = 128;
-      bl = xmmalloc (objfile->md,
-                    sizeof (struct block)
-                    + ((class_symtab_space - 1) * sizeof (struct symbol *)));
+      bl = (struct block *)
+       obstack_alloc (&objfile->symbol_obstack, sizeof (struct block));
       *bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+      BLOCK_DICT (bl) = dict_create_hashed_expandable ();
       BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
-      class_symtab->free_ptr = (char *) bl;
+      class_symtab->free_func = free_class_block;
     }
   return class_symtab;
 }
@@ -140,20 +139,7 @@ add_class_symtab_symbol (struct symbol *sym)
 {
   struct symtab *symtab = get_java_class_symtab ();
   struct blockvector *bv = BLOCKVECTOR (symtab);
-  struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
-  if (BLOCK_NSYMS (bl) >= class_symtab_space)
-    {
-      /* Need to re-allocate. */
-      class_symtab_space *= 2;
-      bl = xmrealloc (symtab->objfile->md, bl,
-                     sizeof (struct block)
-                     + ((class_symtab_space - 1) * sizeof (struct symbol *)));
-      class_symtab->free_ptr = (char *) bl;
-      BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
-    }
-
-  BLOCK_SYM (bl, BLOCK_NSYMS (bl)) = sym;
-  BLOCK_NSYMS (bl) = BLOCK_NSYMS (bl) + 1;
+  dict_add_symbol (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)), sym);
 }
 
 static struct symbol *add_class_symbol (struct type *type, CORE_ADDR addr);
@@ -174,6 +160,16 @@ add_class_symbol (struct type *type, CORE_ADDR addr)
   SYMBOL_VALUE_ADDRESS (sym) = addr;
   return sym;
 }
+
+/* Free the dynamic symbols block.  */
+static void
+free_class_block (struct symtab *symtab)
+{
+  struct blockvector *bv = BLOCKVECTOR (symtab);
+  struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+
+  dict_free (BLOCK_DICT (bl));
+}
 #endif
 
 struct type *
@@ -268,7 +264,7 @@ type_from_class (struct value *clas)
   char *nptr;
   CORE_ADDR addr;
   struct block *bl;
-  int i;
+  struct dict_iterator iter;
   int is_array = 0;
 
   type = check_typedef (VALUE_TYPE (clas));
@@ -283,9 +279,8 @@ type_from_class (struct value *clas)
 #if 0
   get_java_class_symtab ();
   bl = BLOCKVECTOR_BLOCK (BLOCKVECTOR (class_symtab), GLOBAL_BLOCK);
-  for (i = BLOCK_NSYMS (bl); --i >= 0;)
+  ALL_BLOCK_SYMBOLS (block, iter, sym)
     {
-      struct symbol *sym = BLOCK_SYM (bl, i);
       if (SYMBOL_VALUE_ADDRESS (sym) == addr)
        return SYMBOL_TYPE (sym);
     }
This page took 0.084069 seconds and 4 git commands to generate.