diff options
Diffstat (limited to 'gcc/fortran/trans-decl.c')
-rw-r--r-- | gcc/fortran/trans-decl.c | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 92b350e..d168bdc 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -4228,72 +4228,62 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) gfc_add_init_cleanup (block, gfc_finish_block (&tmpblock), NULL_TREE); } -static GTY ((param_is (struct module_htab_entry))) htab_t module_htab; - -/* Hash and equality functions for module_htab. */ - -static hashval_t -module_htab_do_hash (const void *x) +struct module_hasher : ggc_hasher<module_htab_entry *> { - return htab_hash_string (((const struct module_htab_entry *)x)->name); -} + typedef const char *compare_type; -static int -module_htab_eq (const void *x1, const void *x2) -{ - return strcmp ((((const struct module_htab_entry *)x1)->name), - (const char *)x2) == 0; -} + static hashval_t hash (module_htab_entry *s) { return htab_hash_string (s); } + static bool + equal (module_htab_entry *a, const char *b) + { + return !strcmp (a->name, b); + } +}; + +static GTY (()) hash_table<module_hasher> *module_htab; /* Hash and equality functions for module_htab's decls. */ -static hashval_t -module_htab_decls_hash (const void *x) +hashval_t +module_decl_hasher::hash (tree t) { - const_tree t = (const_tree) x; const_tree n = DECL_NAME (t); if (n == NULL_TREE) n = TYPE_NAME (TREE_TYPE (t)); return htab_hash_string (IDENTIFIER_POINTER (n)); } -static int -module_htab_decls_eq (const void *x1, const void *x2) +bool +module_decl_hasher::equal (tree t1, const char *x2) { - const_tree t1 = (const_tree) x1; const_tree n1 = DECL_NAME (t1); if (n1 == NULL_TREE) n1 = TYPE_NAME (TREE_TYPE (t1)); - return strcmp (IDENTIFIER_POINTER (n1), (const char *) x2) == 0; + return strcmp (IDENTIFIER_POINTER (n1), x2) == 0; } struct module_htab_entry * gfc_find_module (const char *name) { - void **slot; - if (! module_htab) - module_htab = htab_create_ggc (10, module_htab_do_hash, - module_htab_eq, NULL); + module_htab = hash_table<module_hasher>::create_ggc (10); - slot = htab_find_slot_with_hash (module_htab, name, - htab_hash_string (name), INSERT); + module_htab_entry **slot + = module_htab->find_slot_with_hash (name, htab_hash_string (name), INSERT); if (*slot == NULL) { module_htab_entry *entry = ggc_cleared_alloc<module_htab_entry> (); entry->name = gfc_get_string (name); - entry->decls = htab_create_ggc (10, module_htab_decls_hash, - module_htab_decls_eq, NULL); - *slot = (void *) entry; + entry->decls = hash_table<module_decl_hasher>::create_ggc (10); + *slot = entry; } - return (struct module_htab_entry *) *slot; + return *slot; } void gfc_module_add_decl (struct module_htab_entry *entry, tree decl) { - void **slot; const char *name; if (DECL_NAME (decl)) @@ -4303,10 +4293,11 @@ gfc_module_add_decl (struct module_htab_entry *entry, tree decl) gcc_assert (TREE_CODE (decl) == TYPE_DECL); name = IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))); } - slot = htab_find_slot_with_hash (entry->decls, name, - htab_hash_string (name), INSERT); + tree *slot + = entry->decls->find_slot_with_hash (name, htab_hash_string (name), + INSERT); if (*slot == NULL) - *slot = (void *) decl; + *slot = decl; } static struct module_htab_entry *cur_module; @@ -4485,14 +4476,13 @@ gfc_trans_use_stmts (gfc_namespace * ns) for (rent = use_stmt->rename; rent; rent = rent->next) { tree decl, local_name; - void **slot; if (rent->op != INTRINSIC_NONE) continue; - slot = htab_find_slot_with_hash (entry->decls, rent->use_name, - htab_hash_string (rent->use_name), - INSERT); + hashval_t hash = htab_hash_string (rent->use_name); + tree *slot = entry->decls->find_slot_with_hash (rent->use_name, hash, + INSERT); if (*slot == NULL) { gfc_symtree *st; @@ -4547,7 +4537,7 @@ gfc_trans_use_stmts (gfc_namespace * ns) else { *slot = error_mark_node; - htab_clear_slot (entry->decls, slot); + entry->decls->clear_slot (slot); continue; } *slot = decl; |