Move enum size check into ada_identical_enum_types_p
Currently, the callers of ada_identical_enum_types_p must check that
both enum types have the same number of members. In another series
I'm working on, it was convenient to move this check into the callee
instead; and I broke this patch out to make that series a little
simpler.
Approved-By: Tom de Vries <tdevries@suse.de>
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 57f2b2b..0f7100d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3814,8 +3814,6 @@
for (int i = 0; i < syms.size (); ++i)
{
struct type *type2 = ada_check_typedef (syms[i].symbol->type ());
- if (type1->num_fields () != type2->num_fields ())
- continue;
if (strcmp (type1->name (), type2->name ()) != 0)
continue;
if (ada_identical_enum_types_p (type1, type2))
@@ -4970,8 +4968,7 @@
that are deemed "identical" for practical purposes.
This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
- types and that their number of enumerals is identical (in other
- words, type1->num_fields () == type2->num_fields ()). */
+ types. */
static bool
ada_identical_enum_types_p (struct type *type1, struct type *type2)
@@ -4981,6 +4978,9 @@
number of enumerals and that all enumerals have the same
underlying value and name. */
+ if (type1->num_fields () != type2->num_fields ())
+ return false;
+
/* All enums in the type should have an identical underlying value. */
for (int i = 0; i < type1->num_fields (); i++)
if (type1->field (i).loc_enumval () != type2->field (i).loc_enumval ())
@@ -5046,12 +5046,6 @@
if (syms[i].symbol->value_longest () != syms[0].symbol->value_longest ())
return 0;
- /* Quick check: They should all have the same number of enumerals. */
- for (i = 1; i < syms.size (); i++)
- if (syms[i].symbol->type ()->num_fields ()
- != syms[0].symbol->type ()->num_fields ())
- return 0;
-
/* All the sanity checks passed, so we might have a set of
identical enumeration types. Perform a more complete
comparison of the type of each symbol. */