aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c124
1 files changed, 57 insertions, 67 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d4adbeb..88164cd 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
+#include "tree-hasher.h"
#include "stringpool.h"
#include "stor-layout.h"
#include "varasm.h"
@@ -88,8 +89,6 @@ static int member_function_or_else (tree, tree, enum overload_flags);
static void bad_specifiers (tree, enum bad_spec_place, int, int, int, int,
int);
static void check_for_uninitialized_const_var (tree);
-static hashval_t typename_hash (const void *);
-static int typename_compare (const void *, const void *);
static tree local_variable_p_walkfn (tree *, int *, void *);
static tree record_builtin_java_type (const char *, int);
static const char *tag_name (enum tag_types);
@@ -210,7 +209,7 @@ struct GTY((chain_next ("%h.next"))) named_label_use_entry {
we can clear out their names' definitions at the end of the
function, and so we can check the validity of jumps to these labels. */
-struct GTY(()) named_label_entry {
+struct GTY((for_user)) named_label_entry {
/* The decl itself. */
tree label_decl;
@@ -394,11 +393,10 @@ pop_label (tree label, tree old_value)
go out of scope. BLOCK is the top-level block for the
function. */
-static int
-pop_labels_1 (void **slot, void *data)
+int
+pop_labels_1 (named_label_entry **slot, tree block)
{
- struct named_label_entry *ent = (struct named_label_entry *) *slot;
- tree block = (tree) data;
+ struct named_label_entry *ent = *slot;
pop_label (ent->label_decl, NULL_TREE);
@@ -407,7 +405,7 @@ pop_labels_1 (void **slot, void *data)
DECL_CHAIN (ent->label_decl) = BLOCK_VARS (block);
BLOCK_VARS (block) = ent->label_decl;
- htab_clear_slot (named_labels, slot);
+ named_labels->clear_slot (slot);
return 1;
}
@@ -417,7 +415,7 @@ pop_labels (tree block)
{
if (named_labels)
{
- htab_traverse (named_labels, pop_labels_1, block);
+ named_labels->traverse<tree, pop_labels_1> (block);
named_labels = NULL;
}
}
@@ -428,13 +426,12 @@ static void
pop_local_label (tree label, tree old_value)
{
struct named_label_entry dummy;
- void **slot;
pop_label (label, old_value);
dummy.label_decl = label;
- slot = htab_find_slot (named_labels, &dummy, NO_INSERT);
- htab_clear_slot (named_labels, slot);
+ named_label_entry **slot = named_labels->find_slot (&dummy, NO_INSERT);
+ named_labels->clear_slot (slot);
}
/* The following two routines are used to interface to Objective-C++.
@@ -474,11 +471,10 @@ objc_mark_locals_volatile (void *enclosing_blk)
/* Update data for defined and undefined labels when leaving a scope. */
-static int
-poplevel_named_label_1 (void **slot, void *data)
+int
+poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
{
- struct named_label_entry *ent = (struct named_label_entry *) *slot;
- cp_binding_level *bl = (cp_binding_level *) data;
+ named_label_entry *ent = *slot;
cp_binding_level *obl = bl->level_chain;
if (ent->binding_level == bl)
@@ -585,8 +581,8 @@ poplevel (int keep, int reverse, int functionbody)
/* Any uses of undefined labels, and any defined labels, now operate
under constraints of next binding contour. */
if (cfun && !functionbody && named_labels)
- htab_traverse (named_labels, poplevel_named_label_1,
- current_binding_level);
+ named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
+ (current_binding_level);
/* Get the decls in the order they were written.
Usually current_binding_level->names is in reverse order.
@@ -2717,19 +2713,16 @@ redeclaration_error_message (tree newdecl, tree olddecl)
/* Hash and equality functions for the named_label table. */
-static hashval_t
-named_label_entry_hash (const void *data)
+hashval_t
+named_label_hasher::hash (named_label_entry *ent)
{
- const struct named_label_entry *ent = (const struct named_label_entry *) data;
return DECL_UID (ent->label_decl);
}
-static int
-named_label_entry_eq (const void *a, const void *b)
+bool
+named_label_hasher::equal (named_label_entry *a, named_label_entry *b)
{
- const struct named_label_entry *ent_a = (const struct named_label_entry *) a;
- const struct named_label_entry *ent_b = (const struct named_label_entry *) b;
- return ent_a->label_decl == ent_b->label_decl;
+ return a->label_decl == b->label_decl;
}
/* Create a new label, named ID. */
@@ -2738,7 +2731,6 @@ static tree
make_label_decl (tree id, int local_p)
{
struct named_label_entry *ent;
- void **slot;
tree decl;
decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
@@ -2756,8 +2748,7 @@ make_label_decl (tree id, int local_p)
/* Create the label htab for the function on demand. */
if (!named_labels)
- named_labels = htab_create_ggc (13, named_label_entry_hash,
- named_label_entry_eq, NULL);
+ named_labels = hash_table<named_label_hasher>::create_ggc (13);
/* Record this label on the list of labels used in this function.
We do this before calling make_label_decl so that we get the
@@ -2765,7 +2756,7 @@ make_label_decl (tree id, int local_p)
ent = ggc_cleared_alloc<named_label_entry> ();
ent->label_decl = decl;
- slot = htab_find_slot (named_labels, ent, INSERT);
+ named_label_entry **slot = named_labels->find_slot (ent, INSERT);
gcc_assert (*slot == NULL);
*slot = ent;
@@ -2979,7 +2970,7 @@ check_goto (tree decl)
return;
dummy.label_decl = decl;
- ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
+ ent = named_labels->find (&dummy);
gcc_assert (ent != NULL);
/* If the label hasn't been defined yet, defer checking. */
@@ -3089,7 +3080,7 @@ define_label_1 (location_t location, tree name)
decl = lookup_label (name);
dummy.label_decl = decl;
- ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
+ ent = named_labels->find (&dummy);
gcc_assert (ent != NULL);
/* After labels, make any new cleanups in the function go into their
@@ -3264,50 +3255,50 @@ finish_case_label (location_t loc, tree low_value, tree high_value)
return r;
}
-/* Hash a TYPENAME_TYPE. K is really of type `tree'. */
-
-static hashval_t
-typename_hash (const void* k)
-{
- hashval_t hash;
- const_tree const t = (const_tree) k;
-
- hash = (htab_hash_pointer (TYPE_CONTEXT (t))
- ^ htab_hash_pointer (TYPE_IDENTIFIER (t)));
-
- return hash;
-}
-
-typedef struct typename_info {
+struct typename_info {
tree scope;
tree name;
tree template_id;
bool enum_p;
bool class_p;
-} typename_info;
-
-/* Compare two TYPENAME_TYPEs. K1 is really of type `tree', K2 is
- really of type `typename_info*' */
+};
-static int
-typename_compare (const void * k1, const void * k2)
+struct typename_hasher : ggc_hasher<tree>
{
- const_tree const t1 = (const_tree) k1;
- const typename_info *const t2 = (const typename_info *) k2;
+ typedef typename_info *compare_type;
- return (TYPE_IDENTIFIER (t1) == t2->name
- && TYPE_CONTEXT (t1) == t2->scope
- && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
- && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
- && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
-}
+ /* Hash a TYPENAME_TYPE. */
+
+ static hashval_t
+ hash (tree t)
+ {
+ hashval_t hash;
+
+ hash = (htab_hash_pointer (TYPE_CONTEXT (t))
+ ^ htab_hash_pointer (TYPE_IDENTIFIER (t)));
+
+ return hash;
+ }
+
+ /* Compare two TYPENAME_TYPEs. */
+
+ static bool
+ equal (tree t1, const typename_info *t2)
+ {
+ return (TYPE_IDENTIFIER (t1) == t2->name
+ && TYPE_CONTEXT (t1) == t2->scope
+ && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
+ && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
+ && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
+ }
+};
/* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
the type of `T', NAME is the IDENTIFIER_NODE for `t'.
Returns the new TYPENAME_TYPE. */
-static GTY ((param_is (union tree_node))) htab_t typename_htab;
+static GTY (()) hash_table<typename_hasher> *typename_htab;
static tree
build_typename_type (tree context, tree name, tree fullname,
@@ -3316,12 +3307,11 @@ build_typename_type (tree context, tree name, tree fullname,
tree t;
tree d;
typename_info ti;
- void **e;
+ tree *e;
hashval_t hash;
if (typename_htab == NULL)
- typename_htab = htab_create_ggc (61, &typename_hash,
- &typename_compare, NULL);
+ typename_htab = hash_table<typename_hasher>::create_ggc (61);
ti.scope = FROB_CONTEXT (context);
ti.name = name;
@@ -3334,9 +3324,9 @@ build_typename_type (tree context, tree name, tree fullname,
^ htab_hash_pointer (ti.name));
/* See if we already have this type. */
- e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
+ e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
if (*e)
- t = (tree) *e;
+ t = *e;
else
{
/* Build the TYPENAME_TYPE. */