Commit 1887fb46 by Nathan Sidwell Committed by Nathan Sidwell

name-lookup.c (count_fields): Rename to ...

	* name-lookup.c (count_fields): Rename to ...
	(count_class_fields): ... here.  Take a class, don't count
	NULL-named fields.
	(add_fields_to_record_type): Rename to ...
	(field_vec_append_class_fields): ... here.  Take a class, don't
	add NULL-named fields.
	(add_enum_fields_to_record_type): Rename to ...
	(field_vec_append_enum_values): ... here.
	(set_class_bindings): Adjust, assert we added expected number.
	(insert_late_enum_def_bindings): Reimplement.  Create vector if
	there are now sufficient entries.

From-SVN: r251794
parent 4269edf0
2017-09-06 Nathan Sidwell <nathan@acm.org> 2017-09-06 Nathan Sidwell <nathan@acm.org>
* name-lookup.c (count_fields): Rename to ...
(count_class_fields): ... here. Take a class, don't count
NULL-named fields.
(add_fields_to_record_type): Rename to ...
(field_vec_append_class_fields): ... here. Take a class, don't
add NULL-named fields.
(add_enum_fields_to_record_type): Rename to ...
(field_vec_append_enum_values): ... here.
(set_class_bindings): Adjust, assert we added expected number.
(insert_late_enum_def_bindings): Reimplement. Create vector if
there are now sufficient entries.
* name-lookup.h (lookup_fnfields_slot_nolazy, * name-lookup.h (lookup_fnfields_slot_nolazy,
lookup_fnfields_slot): Rename to ... lookup_fnfields_slot): Rename to ...
(get_class_binding_direct, get_class_binding): ... here. (get_class_binding_direct, get_class_binding): ... here.
......
...@@ -1452,59 +1452,57 @@ sorted_fields_type_new (int n) ...@@ -1452,59 +1452,57 @@ sorted_fields_type_new (int n)
return sft; return sft;
} }
/* Subroutine of insert_into_classtype_sorted_fields. Recursively /* Recursively count the number of fields in KLASS, including anonymous
count the number of fields in TYPE, including anonymous union union members. */
members. */
static int static unsigned
count_fields (tree fields) count_class_fields (tree klass)
{ {
tree x; unsigned n_fields = 0;
int n_fields = 0;
for (x = fields; x; x = DECL_CHAIN (x)) for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
{ if (DECL_DECLARES_FUNCTION_P (fields))
if (DECL_DECLARES_FUNCTION_P (x)) /* Functions are dealt with separately. */;
/* Functions are dealt with separately. */; else if (TREE_CODE (fields) == FIELD_DECL
else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x))) && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x))); n_fields += count_class_fields (TREE_TYPE (fields));
else else if (DECL_NAME (fields))
n_fields += 1; n_fields += 1;
}
return n_fields; return n_fields;
} }
/* Subroutine of insert_into_classtype_sorted_fields. Recursively add /* Append all the nonfunction members fields of KLASS to FIELD_VEC
all the fields in the TREE_LIST FIELDS to the SORTED_FIELDS_TYPE starting at IDX. Recurse for anonymous members. The array must
elts, starting at offset IDX. */ have space. Returns the next available index. */
static int static unsigned
add_fields_to_record_type (tree fields, struct sorted_fields_type *field_vec, field_vec_append_class_fields (struct sorted_fields_type *field_vec,
int idx) tree klass, unsigned idx)
{ {
tree x; for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
for (x = fields; x; x = DECL_CHAIN (x)) if (DECL_DECLARES_FUNCTION_P (fields))
{ /* Functions are handled separately. */;
if (DECL_DECLARES_FUNCTION_P (x)) else if (TREE_CODE (fields) == FIELD_DECL
/* Functions are handled separately. */; && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x))) idx = field_vec_append_class_fields (field_vec, TREE_TYPE (fields), idx);
idx = add_fields_to_record_type (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx); else if (DECL_NAME (fields))
else field_vec->elts[idx++] = fields;
field_vec->elts[idx++] = x;
}
return idx; return idx;
} }
/* Add all of the enum values of ENUMTYPE, to the FIELD_VEC elts, /* Append all of the enum values of ENUMTYPE to FIELD_VEC starting at IDX.
starting at offset IDX. */ FIELD_VEC must have space. */
static int static unsigned
add_enum_fields_to_record_type (tree enumtype, field_vec_append_enum_values (struct sorted_fields_type *field_vec,
struct sorted_fields_type *field_vec, tree enumtype, unsigned idx)
int idx)
{ {
tree values; for (tree values = TYPE_VALUES (enumtype);
for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values)) values; values = TREE_CHAIN (values))
field_vec->elts[idx++] = TREE_VALUE (values); field_vec->elts[idx++] = TREE_VALUE (values);
return idx; return idx;
} }
...@@ -1518,12 +1516,12 @@ set_class_bindings (tree klass) ...@@ -1518,12 +1516,12 @@ set_class_bindings (tree klass)
qsort (method_vec->address (), method_vec->length (), qsort (method_vec->address (), method_vec->length (),
sizeof (tree), method_name_cmp); sizeof (tree), method_name_cmp);
tree fields = TYPE_FIELDS (klass); int n_fields = count_class_fields (klass);
int n_fields = count_fields (fields);
if (n_fields >= 8) if (n_fields >= 8)
{ {
struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields);
add_fields_to_record_type (fields, field_vec, 0); unsigned idx = field_vec_append_class_fields (field_vec, klass, 0);
gcc_assert (idx == unsigned (field_vec->len));
qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp); qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp);
CLASSTYPE_SORTED_FIELDS (klass) = field_vec; CLASSTYPE_SORTED_FIELDS (klass) = field_vec;
} }
...@@ -1534,19 +1532,31 @@ set_class_bindings (tree klass) ...@@ -1534,19 +1532,31 @@ set_class_bindings (tree klass)
void void
insert_late_enum_def_bindings (tree klass, tree enumtype) insert_late_enum_def_bindings (tree klass, tree enumtype)
{ {
unsigned n_fields;
struct sorted_fields_type *sorted_fields = CLASSTYPE_SORTED_FIELDS (klass); struct sorted_fields_type *sorted_fields = CLASSTYPE_SORTED_FIELDS (klass);
/* The enum values will already be on the TYPE_FIELDS, so don't
count them twice. */
if (sorted_fields) if (sorted_fields)
n_fields = list_length (TYPE_VALUES (enumtype)) + sorted_fields->len;
else
n_fields = count_class_fields (klass);
if (n_fields >= 8)
{ {
int i;
int n_fields
= list_length (TYPE_VALUES (enumtype)) + sorted_fields->len;
struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields);
unsigned idx;
for (i = 0; i < sorted_fields->len; ++i)
field_vec->elts[i] = sorted_fields->elts[i]; if (sorted_fields)
{
for (idx = 0; idx < unsigned (sorted_fields->len); ++idx)
field_vec->elts[idx] = sorted_fields->elts[idx];
add_enum_fields_to_record_type (enumtype, field_vec, idx = field_vec_append_enum_values (field_vec, enumtype, idx);
sorted_fields->len); }
else
idx = field_vec_append_class_fields (field_vec, klass, 0);
gcc_assert (idx == unsigned (field_vec->len));
qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp); qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp);
CLASSTYPE_SORTED_FIELDS (klass) = field_vec; CLASSTYPE_SORTED_FIELDS (klass) = field_vec;
} }
......
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