return sft;
}
-/* Subroutine of insert_into_classtype_sorted_fields. Recursively
- count the number of fields in TYPE, including anonymous union
- members. */
+/* Recursively count the number of fields in KLASS, including anonymous
+ union members. */
-static int
-count_fields (tree fields)
+static unsigned
+count_class_fields (tree klass)
{
- tree x;
- int n_fields = 0;
- for (x = fields; x; x = DECL_CHAIN (x))
- {
- if (DECL_DECLARES_FUNCTION_P (x))
- /* Functions are dealt with separately. */;
- else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
- n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x)));
- else
- n_fields += 1;
- }
+ unsigned n_fields = 0;
+
+ for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
+ if (DECL_DECLARES_FUNCTION_P (fields))
+ /* Functions are dealt with separately. */;
+ else if (TREE_CODE (fields) == FIELD_DECL
+ && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
+ n_fields += count_class_fields (TREE_TYPE (fields));
+ else if (DECL_NAME (fields))
+ n_fields += 1;
+
return n_fields;
}
-/* Subroutine of insert_into_classtype_sorted_fields. Recursively add
- all the fields in the TREE_LIST FIELDS to the SORTED_FIELDS_TYPE
- elts, starting at offset IDX. */
+/* Append all the nonfunction members fields of KLASS to FIELD_VEC
+ starting at IDX. Recurse for anonymous members. The array must
+ have space. Returns the next available index. */
-static int
-add_fields_to_record_type (tree fields, struct sorted_fields_type *field_vec,
- int idx)
+static unsigned
+field_vec_append_class_fields (struct sorted_fields_type *field_vec,
+ tree klass, unsigned idx)
{
- tree x;
- for (x = fields; x; x = DECL_CHAIN (x))
- {
- if (DECL_DECLARES_FUNCTION_P (x))
- /* Functions are handled separately. */;
- else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
- idx = add_fields_to_record_type (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx);
- else
- field_vec->elts[idx++] = x;
- }
+ for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
+ if (DECL_DECLARES_FUNCTION_P (fields))
+ /* Functions are handled separately. */;
+ else if (TREE_CODE (fields) == FIELD_DECL
+ && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
+ idx = field_vec_append_class_fields (field_vec, TREE_TYPE (fields), idx);
+ else if (DECL_NAME (fields))
+ field_vec->elts[idx++] = fields;
+
return idx;
}
-/* Add all of the enum values of ENUMTYPE, to the FIELD_VEC elts,
- starting at offset IDX. */
+/* Append all of the enum values of ENUMTYPE to FIELD_VEC starting at IDX.
+ FIELD_VEC must have space. */
-static int
-add_enum_fields_to_record_type (tree enumtype,
- struct sorted_fields_type *field_vec,
- int idx)
+static unsigned
+field_vec_append_enum_values (struct sorted_fields_type *field_vec,
+ tree enumtype, unsigned idx)
{
- tree values;
- for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
+ for (tree values = TYPE_VALUES (enumtype);
+ values; values = TREE_CHAIN (values))
field_vec->elts[idx++] = TREE_VALUE (values);
+
return idx;
}
qsort (method_vec->address (), method_vec->length (),
sizeof (tree), method_name_cmp);
- tree fields = TYPE_FIELDS (klass);
- int n_fields = count_fields (fields);
+ int n_fields = count_class_fields (klass);
if (n_fields >= 8)
{
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);
CLASSTYPE_SORTED_FIELDS (klass) = field_vec;
}
void
insert_late_enum_def_bindings (tree klass, tree enumtype)
{
+ unsigned n_fields;
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)
+ 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);
-
- for (i = 0; i < sorted_fields->len; ++i)
- field_vec->elts[i] = sorted_fields->elts[i];
+ unsigned idx;
+
+ 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,
- sorted_fields->len);
+ idx = field_vec_append_enum_values (field_vec, enumtype, idx);
+ }
+ 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);
CLASSTYPE_SORTED_FIELDS (klass) = field_vec;
}