Commit 5e0c54e5 by Gabriel Dos Reis Committed by Gabriel Dos Reis

hashtable.h (struct ht_identifier): Add data member "hash_value".

	* hashtable.h (struct ht_identifier): Add data member "hash_value".
	* hashtable.c (ht_lookup): Use it when searching, remember.
	(ht_expand): Do not recompute.
	* tree.h (IDENTIFIER_HASH_VALUE): New macro.

cp/
	* cp-tree.h (struct lang_type_class): Replace data member tags
	with hash-table nested_udts.
	(CLASSTYPE_NESTED_UTDS): Rename from CLASSTYPE_TAGS.
	* class.c (unreverse_member_declarations): Don't touch
	CLASSTYPE_TAGS.
	(pushclass): Use cxx_remember_type_decls.
	* decl.c (struct cp_binding_level): Replace data member tags with
	hash-table type_decls.
	(pop_binding_level): Handle level->type_decls.
	(kept_level_p): Adjust.
	(poplevel): Remove unused local variable.
	(bt_print_entry): New function.
	(print_binding_level): Use it.
	(push_namespace): Build current_binding_level->type_decls.
	(maybe_process_template_type_declaration): Adjust.
	(pushtag): Likewise.
	(clear_anon_tags): Use binding_table_remove_anonymous_types.
	(gettags): Remove.
	(cxx_remember_type_decls):  Rename from storetags.  Adjust.
	(lookup_tag): Use binding_table_find_anon_type.  Tidy.
	(lookup_tag_reverse): Use binding_table_reverse_maybe_remap.
	(cxx_init_decl_processing): Build global_binding_level->type_decls.
	(store_parm_decls): Remove pointless code.
	* name-lookup.c (free_binding_entry): New variable.
	(ENTRY_INDEX): New macro.
	(struct binding_table_s): New datatype.
	(binding_entry_make): New function.
	(binding_entry_free): Likewise.
	(binding_table_construct): Likewise.
	(binding_table_free): Likewise.
	(binding_table_new): Likewise.
	(binding_table_expand): Likewise.
	(binding_table_insert): Likewise.
	(binding_table_find): Likewise.
	(binding_table_find_anon_type): Likewise.
	(binding_table_reverse_maybe_remap): Likewise.
	(binding_table_remove_anonymous_types): Likewise.
	(binding_table_foreach): Likewise.
	* name-lookup.h (binding_table): New type.
	(binding_entry): Likewise.
	(bt_foreach_proc): Likewise.
	(struct binding_entry_s): New datatype.
	(SCOPE_DEFAULT_HT_SIZE): New macro.
	(CLASS_SCOPE_HT_SIZE): Likewise.
	(NAMESPACE_ORDINARY_HT_SIZE): Likewise.
	(NAMESPACE_STD_HT_SIZE): Likewise.
	(GLOBAL_SCOPE_HT_SIZE): Likewise.
	(binding_table_new): Declare.
	(binding_table_free): Likewise.
	(binding_table_insert): Likewise.
	(binding_table_find_anon_type): Likewise.
	(binding_table_reverse_maybe_remap): Likewise.
	(binding_table_remove_anonymous_types): Likewise.
	(binding_table_foreach): Likewise.
	(binding_table_find): Likewise.
	(cxx_remember_type_decls): Likewise.
	* pt.c (bt_instantiate_type_proc): New function.
	(do_type_instantiation): Use it.
	* search.c (lookup_field_r): Use binding_table_find.

From-SVN: r66930
parent 5c9acdf7
2003-05-18 Gabriel Dos Reis <gdr@integrable-solutions.net>
* hashtable.h (struct ht_identifier): Add data member "hash_value".
* hashtable.c (ht_lookup): Use it when searching, remember.
(ht_expand): Do not recompute.
* tree.h (IDENTIFIER_HASH_VALUE): New macro.
2003-05-18 Nathan Sidwell <nathan@codesourcery.com>
* gcov-io.c (gcov_read_bytes): Fix fread thinko.
......
2003-05-18 Gabriel Dos Reis <gdr@integrable-solutions.net>
* cp-tree.h (struct lang_type_class): Replace data member tags
with hash-table nested_udts.
(CLASSTYPE_NESTED_UTDS): Rename from CLASSTYPE_TAGS.
* class.c (unreverse_member_declarations): Don't touch
CLASSTYPE_TAGS.
(pushclass): Use cxx_remember_type_decls.
* decl.c (struct cp_binding_level): Replace data member tags with
hash-table type_decls.
(pop_binding_level): Handle level->type_decls.
(kept_level_p): Adjust.
(poplevel): Remove unused local variable.
(bt_print_entry): New function.
(print_binding_level): Use it.
(push_namespace): Build current_binding_level->type_decls.
(maybe_process_template_type_declaration): Adjust.
(pushtag): Likewise.
(clear_anon_tags): Use binding_table_remove_anonymous_types.
(gettags): Remove.
(cxx_remember_type_decls): Rename from storetags. Adjust.
(lookup_tag): Use binding_table_find_anon_type. Tidy.
(lookup_tag_reverse): Use binding_table_reverse_maybe_remap.
(cxx_init_decl_processing): Build global_binding_level->type_decls.
(store_parm_decls): Remove pointless code.
* name-lookup.c (free_binding_entry): New variable.
(ENTRY_INDEX): New macro.
(struct binding_table_s): New datatype.
(binding_entry_make): New function.
(binding_entry_free): Likewise.
(binding_table_construct): Likewise.
(binding_table_free): Likewise.
(binding_table_new): Likewise.
(binding_table_expand): Likewise.
(binding_table_insert): Likewise.
(binding_table_find): Likewise.
(binding_table_find_anon_type): Likewise.
(binding_table_reverse_maybe_remap): Likewise.
(binding_table_remove_anonymous_types): Likewise.
(binding_table_foreach): Likewise.
* name-lookup.h (binding_table): New type.
(binding_entry): Likewise.
(bt_foreach_proc): Likewise.
(struct binding_entry_s): New datatype.
(SCOPE_DEFAULT_HT_SIZE): New macro.
(CLASS_SCOPE_HT_SIZE): Likewise.
(NAMESPACE_ORDINARY_HT_SIZE): Likewise.
(NAMESPACE_STD_HT_SIZE): Likewise.
(GLOBAL_SCOPE_HT_SIZE): Likewise.
(binding_table_new): Declare.
(binding_table_free): Likewise.
(binding_table_insert): Likewise.
(binding_table_find_anon_type): Likewise.
(binding_table_reverse_maybe_remap): Likewise.
(binding_table_remove_anonymous_types): Likewise.
(binding_table_foreach): Likewise.
(binding_table_find): Likewise.
(cxx_remember_type_decls): Likewise.
* pt.c (bt_instantiate_type_proc): New function.
(do_type_instantiation): Use it.
* search.c (lookup_field_r): Use binding_table_find.
2003-05-18 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* semantics.c (perform_deferred_access_checks): Don't discard
......
......@@ -5226,7 +5226,6 @@ unreverse_member_declarations (tree t)
/* The following lists are all in reverse order. Put them in
declaration order now. */
TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
CLASSTYPE_TAGS (t) = nreverse (CLASSTYPE_TAGS (t));
CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
/* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
......@@ -5561,7 +5560,7 @@ pushclass (tree type, bool modify)
unuse_fields (type);
}
storetags (CLASSTYPE_TAGS (type));
cxx_remember_type_decls (CLASSTYPE_NESTED_UTDS (type));
}
}
......
......@@ -1098,7 +1098,7 @@ struct lang_type_class GTY(())
tree vtables;
tree typeinfo_var;
tree vbases;
tree tags;
binding_table nested_udts;
tree as_base;
tree pure_virtuals;
tree friend_classes;
......@@ -1310,11 +1310,11 @@ struct lang_type GTY(())
#define SET_CLASSTYPE_MARKED6(NODE) SET_CLASSTYPE_MARKED_N (NODE, 5)
#define CLEAR_CLASSTYPE_MARKED6(NODE) CLEAR_CLASSTYPE_MARKED_N (NODE, 5)
/* A list of the nested tag-types (class, struct, union, or enum)
found within this class. The TREE_PURPOSE of each node is the name
of the type; the TREE_VALUE is the type itself. This list includes
nested member class templates. */
#define CLASSTYPE_TAGS(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->tags)
/* A dictionary of the nested user-defined-types (class-types, or enums)
found within this class. This table includes nested member class
templates. */
#define CLASSTYPE_NESTED_UTDS(NODE) \
(LANG_TYPE_CLASS_CHECK (NODE)->nested_udts)
/* Nonzero if NODE has a primary base class, i.e., a base class with
which it shares the virtual function table pointer. */
......
......@@ -28,6 +28,241 @@ Boston, MA 02111-1307, USA. */
#include "name-lookup.h"
#include "timevar.h"
/* Compute the chain index of a binding_entry given the HASH value of its
name and the total COUNT of chains. COUNT is assumed to be a power
of 2. */
#define ENTRY_INDEX(HASH, COUNT) (((HASH) >> 3) & ((COUNT) - 1))
/* A free list of "binding_entry"s awaiting for re-use. */
static binding_entry GTY((deletable(""))) free_binding_entry;
/* Create a binding_entry object for (NAME, TYPE). */
static inline binding_entry
binding_entry_make (tree name, tree type)
{
binding_entry entry;
if (free_binding_entry)
{
entry = free_binding_entry;
free_binding_entry = entry->chain;
}
else
entry = ggc_alloc (sizeof (struct binding_entry_s));
entry->name = name;
entry->type = type;
return entry;
}
/* Put ENTRY back on the free list. */
static inline void
binding_entry_free (binding_entry entry)
{
entry->chain = free_binding_entry;
free_binding_entry = entry;
}
/* The datatype used to implement the mapping from names to types at
a given scope. */
struct binding_table_s GTY(())
{
/* Array of chains of "binding_entry"s */
binding_entry * GTY((length ("%h.chain_count"))) chain;
/* The number of chains in this table. This is the length of the
the member "chaiin" considered as an array. */
size_t chain_count;
/* Number of "binding_entry"s in this table. */
size_t entry_count;
};
/* Construct TABLE with an initial CHAIN_COUNT. */
static inline void
binding_table_construct (binding_table table, size_t chain_count)
{
table->chain_count = chain_count;
table->entry_count = 0;
table->chain = ggc_alloc_cleared
(table->chain_count * sizeof (binding_entry));
}
/* Free TABLE by making its entries ready for reuse. */
void
binding_table_free (binding_table table)
{
size_t i;
if (table == NULL)
return;
for (i = 0; i < table->chain_count; ++i)
{
while (table->chain[i] != NULL)
{
binding_entry entry = table->chain[i];
table->chain[i] = entry->chain;
binding_entry_free (entry);
}
}
table->entry_count = 0;
}
/* Allocate a table with CHAIN_COUNT, assumed to be a power of two. */
binding_table
binding_table_new (size_t chain_count)
{
binding_table table = ggc_alloc (sizeof (struct binding_table_s));
binding_table_construct (table, chain_count);
return table;
}
/* Expand TABLE to twice its current chain_count. */
static void
binding_table_expand (binding_table table)
{
const size_t old_chain_count = table->chain_count;
const size_t old_entry_count = table->entry_count;
const size_t new_chain_count = 2 * old_chain_count;
binding_entry *old_chains = table->chain;
size_t i;
binding_table_construct (table, new_chain_count);
for (i = 0; i < old_chain_count; ++i)
{
binding_entry entry = old_chains[i];
for (; entry != NULL; entry = old_chains[i])
{
const unsigned int hash = IDENTIFIER_HASH_VALUE (entry->name);
const size_t j = ENTRY_INDEX (hash, new_chain_count);
old_chains[i] = entry->chain;
entry->chain = table->chain[j];
table->chain[j] = entry;
}
}
table->entry_count = old_entry_count;
}
/* Insert a binding for NAME to TYPe into TABLE. */
void
binding_table_insert (binding_table table, tree name, tree type)
{
const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
const size_t i = ENTRY_INDEX (hash, table->chain_count);
binding_entry entry = binding_entry_make (name, type);
entry->chain = table->chain[i];
table->chain[i] = entry;
++table->entry_count;
if (3 * table->chain_count < 5 * table->entry_count)
binding_table_expand (table);
}
/* Return the binding_entry, if any, that maps NAME. */
binding_entry
binding_table_find (binding_table table, tree name)
{
const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
binding_entry entry = table->chain[ENTRY_INDEX (hash, table->chain_count)];
while (entry != NULL && entry->name != name)
entry = entry->chain;
return entry;
}
/* Return the binding_entry, if any, that maps name to an anonymous type. */
tree
binding_table_find_anon_type (binding_table table, tree name)
{
const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
binding_entry entry = table->chain[ENTRY_INDEX (hash, table->chain_count)];
while (entry != NULL && TYPE_IDENTIFIER (entry->type) != name)
entry = entry->chain;
return entry ? entry->type : NULL;
}
/* Return the binding_entry, if any, that has TYPE as target. If NAME
is non-null, then set the domain and rehash that entry. */
binding_entry
binding_table_reverse_maybe_remap (binding_table table, tree type, tree name)
{
const size_t chain_count = table->chain_count;
binding_entry entry = NULL;
binding_entry *p = NULL;
size_t i;
for (i = 0; i < chain_count && entry == NULL; ++i)
{
p = &table->chain[i];
while (*p != NULL && entry == NULL)
if ((*p)->type == type)
entry = *p;
else
p = &(*p)->chain;
}
if (entry != NULL && name != NULL && entry->name != name)
{
/* Remove the bucket from the previous chain. */
*p = (*p)->chain;
/* Remap the name type to type. */
i = ENTRY_INDEX (IDENTIFIER_HASH_VALUE (name), chain_count);
entry->chain = table->chain[i];
entry->name = name;
table->chain[i] = entry;
}
return entry;
}
/* Remove from TABLE all entries that map to anonymous enums or
class-types. */
void
binding_table_remove_anonymous_types (binding_table table)
{
const size_t chain_count = table->chain_count;
size_t i;
for (i = 0; i < chain_count; ++i)
{
binding_entry *p = &table->chain[i];
while (*p != NULL)
if (ANON_AGGRNAME_P ((*p)->name))
{
binding_entry e = *p;
*p = (*p)->chain;
--table->entry_count;
binding_entry_free (e);
}
else
p = &(*p)->chain;
}
}
/* Apply PROC -- with DATA -- to all entries in TABLE. */
void
binding_table_foreach (binding_table table, bt_foreach_proc proc, void *data)
{
const size_t chain_count = table->chain_count;
size_t i;
for (i = 0; i < chain_count; ++i)
{
binding_entry entry = table->chain[i];
for (; entry != NULL; entry = entry->chain)
proc (entry, data);
}
}
/* A free list of "cxx_binding"s, connected by their PREVIOUS. */
static GTY((deletable (""))) cxx_binding *free_bindings;
......
......@@ -24,6 +24,39 @@ Boston, MA 02111-1307, USA. */
#include "c-common.h"
/* The type of dictionary used to map names to types declared at
a given scope. */
typedef struct binding_table_s *binding_table;
typedef struct binding_entry_s *binding_entry;
/* The type of a routine repeatedly called by binding_table_foreach. */
typedef void (*bt_foreach_proc) (binding_entry, void *);
struct binding_entry_s GTY(())
{
binding_entry chain;
tree name;
tree type;
};
/* These macros indicate the initial chains count for binding_table. */
#define SCOPE_DEFAULT_HT_SIZE (1 << 3)
#define CLASS_SCOPE_HT_SIZE (1 << 3)
#define NAMESPACE_ORDINARY_HT_SIZE (1 << 5)
#define NAMESPACE_STD_HT_SIZE (1 << 8)
#define GLOBAL_SCOPE_HT_SIZE (1 << 8)
extern binding_table binding_table_new (size_t);
extern void binding_table_free (binding_table);
extern void binding_table_insert (binding_table, tree, tree);
extern tree binding_table_find_anon_type (binding_table, tree);
extern binding_entry binding_table_reverse_maybe_remap (binding_table,
tree, tree);
extern void binding_table_remove_anonymous_types (binding_table);
extern void binding_table_foreach (binding_table, bt_foreach_proc, void *);
extern binding_entry binding_table_find (binding_table, tree);
extern void cxx_remember_type_decls (binding_table);
/* Datatype used to temporarily save C++ bindings (for implicit
instantiations purposes and like). Implemented in decl.c. */
typedef struct cxx_saved_binding cxx_saved_binding;
......
......@@ -5393,7 +5393,7 @@ instantiate_class_template (type)
{
if (TYPE_P (t))
{
/* Build new CLASSTYPE_TAGS. */
/* Build new CLASSTYPE_NESTED_UTDS. */
tree tag = t;
tree name = TYPE_IDENTIFIER (tag);
......@@ -5486,7 +5486,7 @@ instantiate_class_template (type)
/* If it is a TYPE_DECL for a class-scoped ENUMERAL_TYPE,
such a thing will already have been added to the field
list by tsubst_enum in finish_member_declaration in the
CLASSTYPE_TAGS case above. */
CLASSTYPE_NESTED_UTDS case above. */
if (!(TREE_CODE (r) == TYPE_DECL
&& TREE_CODE (TREE_TYPE (r)) == ENUMERAL_TYPE
&& TYPE_CONTEXT (TREE_TYPE (r)) == type))
......@@ -10470,6 +10470,18 @@ mark_class_instantiated (t, extern_p)
}
}
/* Called from do_type_instantiation through binding_table_foreach to
do recursive instantiation for the type bound in ENTRY. */
static void
bt_instantiate_type_proc (binding_entry entry, void *data)
{
tree storage = *(tree *) data;
if (IS_AGGR_TYPE (entry->type)
&& !uses_template_parms (CLASSTYPE_TI_ARGS (entry->type)))
do_type_instantiation (TYPE_MAIN_DECL (entry->type), storage, 0);
}
/* Perform an explicit instantiation of template class T. STORAGE, if
non-null, is the RID for extern, inline or static. COMPLAIN is
nonzero if this is called from the parser, zero if called recursively,
......@@ -10610,10 +10622,9 @@ do_type_instantiation (t, storage, complain)
instantiate_decl (tmp, /*defer_ok=*/1);
}
for (tmp = CLASSTYPE_TAGS (t); tmp; tmp = TREE_CHAIN (tmp))
if (IS_AGGR_TYPE (TREE_VALUE (tmp))
&& !uses_template_parms (CLASSTYPE_TI_ARGS (TREE_VALUE (tmp))))
do_type_instantiation (TYPE_MAIN_DECL (TREE_VALUE (tmp)), storage, 0);
if (CLASSTYPE_NESTED_UTDS (t))
binding_table_foreach (CLASSTYPE_NESTED_UTDS (t),
bt_instantiate_type_proc, &storage);
}
}
......
......@@ -1117,11 +1117,12 @@ lookup_field_r (tree binfo, void *data)
}
else
nval = NULL_TREE;
if (!nval)
if (!nval && CLASSTYPE_NESTED_UTDS (type) != NULL)
{
nval = purpose_member (lfi->name, CLASSTYPE_TAGS (type));
if (nval)
nval = TYPE_MAIN_DECL (TREE_VALUE (nval));
binding_entry e = binding_table_find (CLASSTYPE_NESTED_UTDS (type),
lfi->name);
if (e != NULL)
nval = TYPE_MAIN_DECL (e->type);
else
return NULL_TREE;
}
......
......@@ -121,7 +121,8 @@ ht_lookup (table, str, len, insert)
if (node == NULL)
break;
if (HT_LEN (node) == len && !memcmp (HT_STR (node), str, len))
if (node->hash_value == hash && HT_LEN (node) == len
&& !memcmp (HT_STR (node), str, len))
{
if (insert == HT_ALLOCED)
/* The string we search for was placed at the end of the
......@@ -141,6 +142,7 @@ ht_lookup (table, str, len, insert)
table->entries[index] = node;
HT_LEN (node) = len;
node->hash_value = hash;
if (insert == HT_ALLOC)
HT_STR (node) = obstack_copy0 (&table->stack, str, len);
else
......@@ -173,7 +175,7 @@ ht_expand (table)
{
unsigned int index, hash, hash2;
hash = calc_hash (HT_STR (*p), HT_LEN (*p));
hash = (*p)->hash_value;
hash2 = ((hash * 17) & sizemask) | 1;
index = hash & sizemask;
......
......@@ -27,6 +27,7 @@ struct ht_identifier GTY(())
{
const unsigned char *str;
unsigned int len;
unsigned int hash_value;
};
#define HT_LEN(NODE) ((NODE)->len)
......
......@@ -813,6 +813,8 @@ struct tree_vector GTY(())
(IDENTIFIER_NODE_CHECK (NODE)->identifier.id.len)
#define IDENTIFIER_POINTER(NODE) \
((const char *) IDENTIFIER_NODE_CHECK (NODE)->identifier.id.str)
#define IDENTIFIER_HASH_VALUE(NODE) \
(IDENTIFIER_NODE_CHECK (NODE)->identifier.id.hash_value)
/* Translate a hash table identifier pointer to a tree_identifier
pointer, and vice versa. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment