This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc][10/37] Eliminate builtin_type_ macros: Use expression arch for argument promotion


Hello,

this patch now moves the calls to unop_promote and binop_promote up
to the respective callers.  Note that a number of GDB-internal call
sites not involved with expression parsing do not need to perform
any argument promotion; they're happy with the new default behaviour
of value_binop et. al.

Note also that value_equal and value_less call value_binop; this patch
pushes the binop_promote call right through to *their* callers.

This patch adds a number of _promote calls to ada-lang.c; while these
should simply preserve the status quo, someone familiar with the Ada
type promotion rules should probably have a look at those, maybe this
code can now be simplified a bit ...

Bye,
Ulrich


ChangeLog:


	* eval.c (evaluate_subexp_standard): Add calls to binop_promote
	and unop_promote before calling value_binop et. al.
	* ada-lang.c (ada_evaluate_subexp): Add calls to binop_promote
	and unop_promote before calling value_binop et. al.

	* valarith.c (value_binop): Do not call binop_promote or unop_promote.
	(value_pos): Do not call unop_promote.
	(value_neg, value_complement): Likewise.


Index: gdb-head/gdb/ada-lang.c
===================================================================
--- gdb-head.orig/gdb/ada-lang.c
+++ gdb-head/gdb/ada-lang.c
@@ -8521,6 +8521,7 @@ ada_evaluate_subexp (struct type *expect
       type = value_type (arg1);
       while (TYPE_CODE (type) == TYPE_CODE_REF)
         type = TYPE_TARGET_TYPE (type);
+      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
       return value_cast (type, value_binop (arg1, arg2, BINOP_ADD));
 
     case BINOP_SUB:
@@ -8538,6 +8539,7 @@ ada_evaluate_subexp (struct type *expect
       type = value_type (arg1);
       while (TYPE_CODE (type) == TYPE_CODE_REF)
         type = TYPE_TARGET_TYPE (type);
+      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
       return value_cast (type, value_binop (arg1, arg2, BINOP_SUB));
 
     case BINOP_MUL:
@@ -8555,6 +8557,7 @@ ada_evaluate_subexp (struct type *expect
             arg1 = cast_from_fixed_to_double (arg1);
           if (ada_is_fixed_point_type (value_type (arg2)))
             arg2 = cast_from_fixed_to_double (arg2);
+          binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
           return ada_value_binop (arg1, arg2, op);
         }
 
@@ -8568,7 +8571,10 @@ ada_evaluate_subexp (struct type *expect
                && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
         return value_zero (value_type (arg1), not_lval);
       else
-        return ada_value_binop (arg1, arg2, op);
+	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+	  return ada_value_binop (arg1, arg2, op);
+	}
 
     case BINOP_EQUAL:
     case BINOP_NOTEQUAL:
@@ -8579,7 +8585,10 @@ ada_evaluate_subexp (struct type *expect
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
         tem = 0;
       else
-        tem = ada_value_equal (arg1, arg2);
+	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+	  tem = ada_value_equal (arg1, arg2);
+	}
       if (op == BINOP_NOTEQUAL)
         tem = !tem;
       type = language_bool_type (exp->language_defn, exp->gdbarch);
@@ -8592,7 +8601,10 @@ ada_evaluate_subexp (struct type *expect
       else if (ada_is_fixed_point_type (value_type (arg1)))
         return value_cast (value_type (arg1), value_neg (arg1));
       else
-        return value_neg (arg1);
+	{
+	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+	  return value_neg (arg1);
+	}
 
     case BINOP_LOGICAL_AND:
     case BINOP_LOGICAL_OR:
@@ -8862,6 +8874,8 @@ ada_evaluate_subexp (struct type *expect
           arg2 = value_from_longest (builtin_type_int, TYPE_LOW_BOUND (type));
           arg3 = value_from_longest (builtin_type_int,
                                      TYPE_HIGH_BOUND (type));
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
           type = language_bool_type (exp->language_defn, exp->gdbarch);
           return
             value_from_longest (type,
@@ -8893,6 +8907,8 @@ ada_evaluate_subexp (struct type *expect
       arg3 = ada_array_bound (arg2, tem, 1);
       arg2 = ada_array_bound (arg2, tem, 0);
 
+      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
       type = language_bool_type (exp->language_defn, exp->gdbarch);
       return
         value_from_longest (type,
@@ -8909,6 +8925,8 @@ ada_evaluate_subexp (struct type *expect
       if (noside == EVAL_SKIP)
         goto nosideret;
 
+      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
       type = language_bool_type (exp->language_defn, exp->gdbarch);
       return
         value_from_longest (type,
@@ -9056,8 +9074,11 @@ ada_evaluate_subexp (struct type *expect
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
         return value_zero (value_type (arg1), not_lval);
       else
-        return value_binop (arg1, arg2,
-                            op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX);
+	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+	  return value_binop (arg1, arg2,
+			      op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX);
+	}
 
     case OP_ATR_MODULUS:
       {
@@ -9115,7 +9136,16 @@ ada_evaluate_subexp (struct type *expect
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
         return value_zero (value_type (arg1), not_lval);
       else
-        return value_binop (arg1, arg2, op);
+	{
+	  /* For integer exponentiation operations,
+	     only promote the first argument.  */
+	  if (is_integral_type (value_type (arg2)))
+	    unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+	  else
+	    binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+
+	  return value_binop (arg1, arg2, op);
+	}
 
     case UNOP_PLUS:
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
@@ -9128,6 +9158,7 @@ ada_evaluate_subexp (struct type *expect
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
       if (noside == EVAL_SKIP)
         goto nosideret;
+      unop_promote (exp->language_defn, exp->gdbarch, &arg1);
       if (value_less (arg1, value_zero (value_type (arg1), not_lval)))
         return value_neg (arg1);
       else
Index: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -1725,7 +1725,19 @@ evaluate_subexp_standard (struct type *e
       else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1)))
 	arg2 = value_ptrsub (arg1, arg2);
       else
-	arg2 = value_binop (arg1, arg2, op);
+	{
+	  struct value *tmp = arg1;
+
+	  /* For shift and integer exponentiation operations,
+	     only promote the first argument.  */
+	  if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
+	      && is_integral_type (value_type (arg2)))
+	    unop_promote (exp->language_defn, exp->gdbarch, &tmp);
+	  else
+	    binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+
+	  arg2 = value_binop (tmp, arg2, op);
+	}
       return value_assign (arg1, arg2);
 
     case BINOP_ADD:
@@ -1740,7 +1752,10 @@ evaluate_subexp_standard (struct type *e
       else if (ptrmath_type_p (value_type (arg2)))
 	return value_ptradd (arg2, arg1);
       else
-	return value_binop (arg1, arg2, BINOP_ADD);
+	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+	  return value_binop (arg1, arg2, BINOP_ADD);
+	}
 
     case BINOP_SUB:
       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
@@ -1761,7 +1776,10 @@ evaluate_subexp_standard (struct type *e
       else if (ptrmath_type_p (value_type (arg2)))
 	return value_ptrsub (arg2, arg1);
       else
-	return value_binop (arg1, arg2, BINOP_SUB);
+	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+	  return value_binop (arg1, arg2, BINOP_SUB);
+	}
 
     case BINOP_EXP:
     case BINOP_MUL:
@@ -1798,11 +1816,22 @@ evaluate_subexp_standard (struct type *e
 	      struct value *v_one, *retval;
 
 	      v_one = value_one (value_type (arg2), not_lval);
+	      binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one);
 	      retval = value_binop (arg1, v_one, op);
 	      return retval;
 	    }
 	  else
-	    return value_binop (arg1, arg2, op);
+	    {
+	      /* For shift and integer exponentiation operations,
+		 only promote the first argument.  */
+	      if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
+		  && is_integral_type (value_type (arg2)))
+		unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+	      else
+		binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+
+	      return value_binop (arg1, arg2, op);
+	    }
 	}
 
     case BINOP_RANGE:
@@ -2073,6 +2102,7 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  tem = value_equal (arg1, arg2);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
 	  return value_from_longest (type, (LONGEST) tem);
@@ -2089,6 +2119,7 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  tem = value_equal (arg1, arg2);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
 	  return value_from_longest (type, (LONGEST) ! tem);
@@ -2105,6 +2136,7 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  tem = value_less (arg1, arg2);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
 	  return value_from_longest (type, (LONGEST) tem);
@@ -2121,6 +2153,7 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  tem = value_less (arg2, arg1);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
 	  return value_from_longest (type, (LONGEST) tem);
@@ -2137,6 +2170,7 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
 	  return value_from_longest (type, (LONGEST) tem);
@@ -2153,6 +2187,7 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
+	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
 	  return value_from_longest (type, (LONGEST) tem);
@@ -2185,7 +2220,10 @@ evaluate_subexp_standard (struct type *e
       if (unop_user_defined_p (op, arg1))
 	return value_x_unop (arg1, op, noside);
       else
-	return value_pos (arg1);
+	{
+	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+	  return value_pos (arg1);
+	}
       
     case UNOP_NEG:
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
@@ -2194,7 +2232,10 @@ evaluate_subexp_standard (struct type *e
       if (unop_user_defined_p (op, arg1))
 	return value_x_unop (arg1, op, noside);
       else
-	return value_neg (arg1);
+	{
+	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+	  return value_neg (arg1);
+	}
 
     case UNOP_COMPLEMENT:
       /* C++: check for and handle destructor names.  */
@@ -2206,7 +2247,10 @@ evaluate_subexp_standard (struct type *e
       if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
 	return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
       else
-	return value_complement (arg1);
+	{
+	  unop_promote (exp->language_defn, exp->gdbarch, &arg1);
+	  return value_complement (arg1);
+	}
 
     case UNOP_LOGICAL_NOT:
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
@@ -2324,7 +2368,11 @@ evaluate_subexp_standard (struct type *e
 	  if (ptrmath_type_p (value_type (arg1)))
 	    arg2 = value_ptradd (arg1, arg2);
 	  else
-	    arg2 = value_binop (arg1, arg2, BINOP_ADD);
+	    {
+	      struct value *tmp = arg1;
+	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+	      arg2 = value_binop (tmp, arg2, BINOP_ADD);
+	    }
 
 	  return value_assign (arg1, arg2);
 	}
@@ -2343,7 +2391,11 @@ evaluate_subexp_standard (struct type *e
 	  if (ptrmath_type_p (value_type (arg1)))
 	    arg2 = value_ptrsub (arg1, arg2);
 	  else
-	    arg2 = value_binop (arg1, arg2, BINOP_SUB);
+	    {
+	      struct value *tmp = arg1;
+	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+	      arg2 = value_binop (tmp, arg2, BINOP_SUB);
+	    }
 
 	  return value_assign (arg1, arg2);
 	}
@@ -2362,7 +2414,11 @@ evaluate_subexp_standard (struct type *e
 	  if (ptrmath_type_p (value_type (arg1)))
 	    arg2 = value_ptradd (arg1, arg2);
 	  else
-	    arg2 = value_binop (arg1, arg2, BINOP_ADD);
+	    {
+	      struct value *tmp = arg1;
+	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+	      arg2 = value_binop (tmp, arg2, BINOP_ADD);
+	    }
 
 	  value_assign (arg1, arg2);
 	  return arg1;
@@ -2382,7 +2438,11 @@ evaluate_subexp_standard (struct type *e
 	  if (ptrmath_type_p (value_type (arg1)))
 	    arg2 = value_ptrsub (arg1, arg2);
 	  else
-	    arg2 = value_binop (arg1, arg2, BINOP_SUB);
+	    {
+	      struct value *tmp = arg1;
+	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+	      arg2 = value_binop (tmp, arg2, BINOP_SUB);
+	    }
 
 	  value_assign (arg1, arg2);
 	  return arg1;
Index: gdb-head/gdb/valarith.c
===================================================================
--- gdb-head.orig/gdb/valarith.c
+++ gdb-head/gdb/valarith.c
@@ -871,14 +871,6 @@ value_binop (struct value *arg1, struct 
   struct value *val;
   struct type *type1, *type2, *result_type;
 
-  /* For shift and integer exponentiation operations,
-     only promote the first argument.  */
-  if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
-      && is_integral_type (value_type (arg2)))
-    unop_promote (current_language, current_gdbarch, &arg1);
-  else
-    binop_promote (current_language, current_gdbarch, &arg1, &arg2);
-
   arg1 = coerce_ref (arg1);
   arg2 = coerce_ref (arg2);
 
@@ -1484,8 +1476,6 @@ value_pos (struct value *arg1)
 {
   struct type *type;
 
-  unop_promote (current_language, current_gdbarch, &arg1);
-
   arg1 = coerce_ref (arg1);
   type = check_typedef (value_type (arg1));
 
@@ -1509,8 +1499,6 @@ value_neg (struct value *arg1)
 {
   struct type *type;
 
-  unop_promote (current_language, current_gdbarch, &arg1);
-
   arg1 = coerce_ref (arg1);
   type = check_typedef (value_type (arg1));
 
@@ -1548,8 +1536,6 @@ value_complement (struct value *arg1)
 {
   struct type *type;
 
-  unop_promote (current_language, current_gdbarch, &arg1);
-
   arg1 = coerce_ref (arg1);
   type = check_typedef (value_type (arg1));
 

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]