]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Move enum size check into ada_identical_enum_types_p
authorTom Tromey <tromey@adacore.com>
Mon, 26 Aug 2024 17:30:01 +0000 (11:30 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 9 Sep 2024 17:47:17 +0000 (11:47 -0600)
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>
gdb/ada-lang.c

index 57f2b2bb9a792b379c16066ffe092ededf8f66ee..0f7100dfc949df9e90913858ffa8d084b3eed1bc 100644 (file)
@@ -3814,8 +3814,6 @@ ada_resolve_enum (std::vector<struct block_symbol> &syms,
   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 @@ is_nondebugging_type (struct type *type)
    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 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
      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 @@ symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
     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.  */