]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Combine ada_unop_atr and ada_unop_atr_operation::evaluate
authorTom Tromey <tromey@adacore.com>
Fri, 8 May 2026 15:41:54 +0000 (09:41 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 21 May 2026 17:35:29 +0000 (11:35 -0600)
This inlines ada_unop_atr into its sole caller.  This split was an
artifact of the expression type conversion.

gdb/ada-lang.c

index 0600394361ca8db5b59f34587214e4c05904f564..0ecc67126777d23e7c3d428658b774693e7f418f 100644 (file)
@@ -10364,139 +10364,6 @@ ada_binop_in_bounds_operation::evaluate (struct type *expect_type,
 
 } /* namespace expr */
 
-/* A helper function for some attribute operations.  */
-
-static value *
-ada_unop_atr (struct expression *exp, enum noside noside, enum exp_opcode op,
-             struct value *arg1, struct type *type_arg, int tem)
-{
-  const char *attr_name = nullptr;
-  if (op == OP_ATR_FIRST)
-    attr_name = "first";
-  else if (op == OP_ATR_LAST)
-    attr_name = "last";
-
-  if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    {
-      if (type_arg == NULL)
-       type_arg = arg1->type ();
-
-      if (ada_is_constrained_packed_array_type (type_arg))
-       type_arg = decode_constrained_packed_array_type (type_arg);
-
-      if (!discrete_type_p (type_arg))
-       {
-         switch (op)
-           {
-           default:          /* Should never happen.  */
-             error (_("unexpected attribute encountered"));
-           case OP_ATR_FIRST:
-           case OP_ATR_LAST:
-             type_arg = ada_index_type (type_arg, tem,
-                                        attr_name);
-             break;
-           case OP_ATR_LENGTH:
-             type_arg = builtin_type (exp->gdbarch)->builtin_int;
-             break;
-           }
-       }
-
-      return value::zero (type_arg, not_lval);
-    }
-  else if (type_arg == NULL)
-    {
-      arg1 = ada_coerce_ref (arg1);
-
-      if (ada_is_constrained_packed_array_type (arg1->type ()))
-       arg1 = ada_coerce_to_simple_array (arg1);
-
-      struct type *type;
-      if (op == OP_ATR_LENGTH)
-       type = builtin_type (exp->gdbarch)->builtin_int;
-      else
-       {
-         type = ada_index_type (arg1->type (), tem,
-                                attr_name);
-         if (type == NULL)
-           type = builtin_type (exp->gdbarch)->builtin_int;
-       }
-
-      switch (op)
-       {
-       default:          /* Should never happen.  */
-         error (_("unexpected attribute encountered"));
-       case OP_ATR_FIRST:
-         return value_from_longest
-           (type, ada_array_bound (arg1, tem, 0));
-       case OP_ATR_LAST:
-         return value_from_longest
-           (type, ada_array_bound (arg1, tem, 1));
-       case OP_ATR_LENGTH:
-         return value_from_longest
-           (type, ada_array_length (arg1, tem));
-       }
-    }
-  else if (discrete_type_p (type_arg))
-    {
-      struct type *range_type;
-      const char *name = ada_type_name (type_arg);
-
-      range_type = NULL;
-      if (name != NULL && type_arg->code () != TYPE_CODE_ENUM)
-       range_type = to_fixed_range_type (type_arg, NULL);
-      if (range_type == NULL)
-       range_type = type_arg;
-      switch (op)
-       {
-       default:
-         error (_("unexpected attribute encountered"));
-       case OP_ATR_FIRST:
-         return value_from_longest
-           (range_type, ada_discrete_type_low_bound (range_type));
-       case OP_ATR_LAST:
-         return value_from_longest
-           (range_type, ada_discrete_type_high_bound (range_type));
-       case OP_ATR_LENGTH:
-         error (_("the 'length attribute applies only to array types"));
-       }
-    }
-  else if (type_arg->code () == TYPE_CODE_FLT)
-    error (_("unimplemented type attribute"));
-  else
-    {
-      LONGEST low, high;
-
-      if (ada_is_constrained_packed_array_type (type_arg))
-       type_arg = decode_constrained_packed_array_type (type_arg);
-
-      struct type *type;
-      if (op == OP_ATR_LENGTH)
-       type = builtin_type (exp->gdbarch)->builtin_int;
-      else
-       {
-         type = ada_index_type (type_arg, tem, attr_name);
-         if (type == NULL)
-           type = builtin_type (exp->gdbarch)->builtin_int;
-       }
-
-      switch (op)
-       {
-       default:
-         error (_("unexpected attribute encountered"));
-       case OP_ATR_FIRST:
-         low = ada_array_bound_from_type (type_arg, tem, 0);
-         return value_from_longest (type, low);
-       case OP_ATR_LAST:
-         high = ada_array_bound_from_type (type_arg, tem, 1);
-         return value_from_longest (type, high);
-       case OP_ATR_LENGTH:
-         low = ada_array_bound_from_type (type_arg, tem, 0);
-         high = ada_array_bound_from_type (type_arg, tem, 1);
-         return value_from_longest (type, high - low + 1);
-       }
-    }
-}
-
 /* A helper function for OP_ATR_MIN and OP_ATR_MAX.  */
 
 struct value *
@@ -10855,8 +10722,134 @@ ada_unop_atr_operation::evaluate (struct type *expect_type,
   else
     val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
 
-  return ada_unop_atr (exp, noside, std::get<1> (m_storage),
-                      val, type_arg, std::get<2> (m_storage));
+  exp_opcode op = std::get<1> (m_storage);
+  const char *attr_name = nullptr;
+  if (op == OP_ATR_FIRST)
+    attr_name = "first";
+  else if (op == OP_ATR_LAST)
+    attr_name = "last";
+
+  int tem = std::get<2> (m_storage);
+
+  if (noside == EVAL_AVOID_SIDE_EFFECTS)
+    {
+      if (type_arg == NULL)
+       type_arg = val->type ();
+
+      if (ada_is_constrained_packed_array_type (type_arg))
+       type_arg = decode_constrained_packed_array_type (type_arg);
+
+      if (!discrete_type_p (type_arg))
+       {
+         switch (op)
+           {
+           default:            /* Should never happen.  */
+             error (_("unexpected attribute encountered"));
+           case OP_ATR_FIRST:
+           case OP_ATR_LAST:
+             type_arg = ada_index_type (type_arg, tem,
+                                        attr_name);
+             break;
+           case OP_ATR_LENGTH:
+             type_arg = builtin_type (exp->gdbarch)->builtin_int;
+             break;
+           }
+       }
+
+      return value::zero (type_arg, not_lval);
+    }
+  else if (type_arg == NULL)
+    {
+      val = ada_coerce_ref (val);
+
+      if (ada_is_constrained_packed_array_type (val->type ()))
+       val = ada_coerce_to_simple_array (val);
+
+      struct type *type;
+      if (op == OP_ATR_LENGTH)
+       type = builtin_type (exp->gdbarch)->builtin_int;
+      else
+       {
+         type = ada_index_type (val->type (), tem,
+                                attr_name);
+         if (type == NULL)
+           type = builtin_type (exp->gdbarch)->builtin_int;
+       }
+
+      switch (op)
+       {
+       default:                /* Should never happen.  */
+         error (_("unexpected attribute encountered"));
+       case OP_ATR_FIRST:
+         return value_from_longest
+           (type, ada_array_bound (val, tem, 0));
+       case OP_ATR_LAST:
+         return value_from_longest
+           (type, ada_array_bound (val, tem, 1));
+       case OP_ATR_LENGTH:
+         return value_from_longest
+           (type, ada_array_length (val, tem));
+       }
+    }
+  else if (discrete_type_p (type_arg))
+    {
+      struct type *range_type;
+      const char *name = ada_type_name (type_arg);
+
+      range_type = NULL;
+      if (name != NULL && type_arg->code () != TYPE_CODE_ENUM)
+       range_type = to_fixed_range_type (type_arg, NULL);
+      if (range_type == NULL)
+       range_type = type_arg;
+      switch (op)
+       {
+       default:
+         error (_("unexpected attribute encountered"));
+       case OP_ATR_FIRST:
+         return value_from_longest
+           (range_type, ada_discrete_type_low_bound (range_type));
+       case OP_ATR_LAST:
+         return value_from_longest
+           (range_type, ada_discrete_type_high_bound (range_type));
+       case OP_ATR_LENGTH:
+         error (_("the 'length attribute applies only to array types"));
+       }
+    }
+  else if (type_arg->code () == TYPE_CODE_FLT)
+    error (_("unimplemented type attribute"));
+  else
+    {
+      LONGEST low, high;
+
+      if (ada_is_constrained_packed_array_type (type_arg))
+       type_arg = decode_constrained_packed_array_type (type_arg);
+
+      struct type *type;
+      if (op == OP_ATR_LENGTH)
+       type = builtin_type (exp->gdbarch)->builtin_int;
+      else
+       {
+         type = ada_index_type (type_arg, tem, attr_name);
+         if (type == NULL)
+           type = builtin_type (exp->gdbarch)->builtin_int;
+       }
+
+      switch (op)
+       {
+       default:
+         error (_("unexpected attribute encountered"));
+       case OP_ATR_FIRST:
+         low = ada_array_bound_from_type (type_arg, tem, 0);
+         return value_from_longest (type, low);
+       case OP_ATR_LAST:
+         high = ada_array_bound_from_type (type_arg, tem, 1);
+         return value_from_longest (type, high);
+       case OP_ATR_LENGTH:
+         low = ada_array_bound_from_type (type_arg, tem, 0);
+         high = ada_array_bound_from_type (type_arg, tem, 1);
+         return value_from_longest (type, high - low + 1);
+       }
+    }
 }
 
 value *