This is the mail archive of the gdb-patches@sources.redhat.com 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]

[commit] Wrap value->type = ...; code


There are a number of places where the code, instead of creating a new value with a new type, directly modifies an existing value's type. That's just plain weird. I've replaced that code with a call to deprecated_set_value_type().

Andrew
2005-02-07  Andrew Cagney  <cagney@gnu.org>

	* value.h (deprecated_set_value_type): Declare.
	* value.c (deprecated_set_value_type): Define.
	* hpacc-abi.c, gnu-v2-abi.c, cp-valprint.c: Update.
	* c-valprint.c, jv-lang.c, objc-lang.c, ada-lang.c: Update.
	* infcall.c, printcmd.c, valops.c, eval.c, p-exp.y: Update.
	* ax-gdb.c, tracepoint.c: Update.

Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.72
diff -p -u -r1.72 ada-lang.c
--- ada-lang.c	7 Feb 2005 15:04:42 -0000	1.72
+++ ada-lang.c	7 Feb 2005 23:35:30 -0000
@@ -1547,7 +1547,7 @@ ada_coerce_to_simple_array_type (struct 
   struct value *mark = value_mark ();
   struct value *dummy = value_from_longest (builtin_type_long, 0);
   struct type *result;
-  dummy->type = type;
+  deprecated_set_value_type (dummy, type);
   result = ada_type_of_array (dummy, 0);
   value_free_to_mark (mark);
   return result;
@@ -2041,7 +2041,7 @@ ada_value_assign (struct value *toval, s
       val = value_copy (toval);
       memcpy (value_contents_raw (val), value_contents (fromval),
               TYPE_LENGTH (type));
-      val->type = type;
+      deprecated_set_value_type (val, type);
 
       return val;
     }
@@ -7047,7 +7047,7 @@ coerce_for_assign (struct type *type, st
           || TYPE_LENGTH (TYPE_TARGET_TYPE (type2))
           != TYPE_LENGTH (TYPE_TARGET_TYPE (type2)))
         error (_("Incompatible types in assignment"));
-      val->type = type;
+      deprecated_set_value_type (val, type);
     }
   return val;
 }
Index: ax-gdb.c
===================================================================
RCS file: /cvs/src/src/gdb/ax-gdb.c,v
retrieving revision 1.27
diff -p -u -r1.27 ax-gdb.c
--- ax-gdb.c	29 Jan 2005 17:53:25 -0000	1.27
+++ ax-gdb.c	7 Feb 2005 23:35:30 -0000
@@ -1424,7 +1424,7 @@ gen_repeat (union exp_element **pc, stru
 
     if (!v)
       error (_("Right operand of `@' must be a constant, in agent expressions."));
-    if (TYPE_CODE (v->type) != TYPE_CODE_INT)
+    if (TYPE_CODE (value_type (v)) != TYPE_CODE_INT)
       error (_("Right operand of `@' must be an integer."));
     length = value_as_long (v);
     if (length <= 0)
Index: c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.31
diff -p -u -r1.31 c-valprint.c
--- c-valprint.c	7 Feb 2005 17:06:29 -0000	1.31
+++ c-valprint.c	7 Feb 2005 23:35:30 -0000
@@ -531,7 +531,7 @@ c_value_print (struct value *val, struct
 	       */
 	      struct value *temparg;
 	      temparg=value_copy(val);
-	      temparg->type = lookup_pointer_type (TYPE_TARGET_TYPE(type));
+	      deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
 	      val=temparg;
 	    }
 	  /* Pointer to class, check real type of object */
Index: cp-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-valprint.c,v
retrieving revision 1.33
diff -p -u -r1.33 cp-valprint.c
--- cp-valprint.c	7 Feb 2005 17:06:29 -0000	1.33
+++ cp-valprint.c	7 Feb 2005 23:35:30 -0000
@@ -786,7 +786,8 @@ cp_print_hpacc_virtual_table_entries (st
 	  /* adjust by offset */
 	  vf->aligner.contents[0] += 4 * (HP_ACC_VFUNC_START + vx);
 	  vf = value_ind (vf);	/* get the entry */
-	  vf->type = value_type (v);	/* make it a pointer */
+	  /* make it a pointer */
+	  deprecated_set_value_type (vf, value_type (v));
 
 	  /* print out the entry */
 	  val_print (value_type (vf), value_contents (vf), 0, 0,
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.50
diff -p -u -r1.50 eval.c
--- eval.c	7 Feb 2005 17:06:29 -0000	1.50
+++ eval.c	7 Feb 2005 23:35:30 -0000
@@ -945,8 +945,8 @@ evaluate_subexp_standard (struct type *e
 	if (gnu_runtime && (method != NULL))
 	  {
 	    /* Function objc_msg_lookup returns a pointer.  */
-	    argvec[0]->type
-	      = lookup_function_type (lookup_pointer_type (value_type (argvec[0])));
+	    deprecated_set_value_type (argvec[0],
+				       lookup_function_type (lookup_pointer_type (value_type (argvec[0]))));
 	    argvec[0] = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
 	  }
 
@@ -1030,7 +1030,7 @@ evaluate_subexp_standard (struct type *e
 	    }
 	  else
 	    {
-	      arg1->type = lookup_pointer_type (TYPE_TARGET_TYPE (value_type (arg1)));
+	      deprecated_set_value_type (arg1, lookup_pointer_type (TYPE_TARGET_TYPE (value_type (arg1))));
 	    }
 	got_it:
 
@@ -1688,7 +1688,7 @@ evaluate_subexp_standard (struct type *e
 	   type, this will ensure that value_subscript()
 	   returns the correct type value */
 
-	arg1->type = tmp_type;
+	deprecated_set_value_type (arg1, tmp_type);
 	return value_ind (value_add (value_coerce_array (arg1), arg2));
       }
 
Index: gnu-v2-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-v2-abi.c,v
retrieving revision 1.19
diff -p -u -r1.19 gnu-v2-abi.c
--- gnu-v2-abi.c	7 Feb 2005 15:04:42 -0000	1.19
+++ gnu-v2-abi.c	7 Feb 2005 23:35:30 -0000
@@ -177,7 +177,7 @@ gnuv2_virtual_fn_field (struct value **a
   else
     error ("I'm confused:  virtual function table has bad type");
   /* Reinstantiate the function pointer with the correct type.  */
-  vfn->type = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j));
+  deprecated_set_value_type (vfn, lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j)));
 
   *arg1p = arg1;
   return vfn;
Index: hpacc-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/hpacc-abi.c,v
retrieving revision 1.12
diff -p -u -r1.12 hpacc-abi.c
--- hpacc-abi.c	7 Feb 2005 17:06:29 -0000	1.12
+++ hpacc-abi.c	7 Feb 2005 23:35:30 -0000
@@ -168,7 +168,7 @@ hpacc_virtual_fn_field (struct value **a
 
   /* Wrap this addr in a value and return pointer */
   vp = allocate_value (ftype);
-  vp->type = ftype;
+  deprecated_set_value_type (vp, ftype);
   VALUE_ADDRESS (vp) = coreptr;
 
   /* pai: (temp) do we need the value_ind stuff in value_fn_field? */
Index: infcall.c
===================================================================
RCS file: /cvs/src/src/gdb/infcall.c,v
retrieving revision 1.63
diff -p -u -r1.63 infcall.c
--- infcall.c	2 Feb 2005 21:36:13 -0000	1.63
+++ infcall.c	7 Feb 2005 23:35:30 -0000
@@ -96,7 +96,7 @@ value_arg_coerce (struct value *arg, str
 	  && TYPE_CODE (arg_type) != TYPE_CODE_PTR)
 	{
 	  arg = value_addr (arg);
-	  arg->type = param_type;
+	  deprecated_set_value_type (arg, param_type);
 	  return arg;
 	}
       break;
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.39
diff -p -u -r1.39 jv-lang.c
--- jv-lang.c	7 Feb 2005 15:04:43 -0000	1.39
+++ jv-lang.c	7 Feb 2005 23:35:30 -0000
@@ -320,7 +320,7 @@ type_from_class (struct value *clas)
       temp = clas;
       /* Set array element type. */
       temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure");
-      temp->type = lookup_pointer_type (value_type (clas));
+      deprecated_set_value_type (temp, lookup_pointer_type (value_type (clas)));
       TYPE_TARGET_TYPE (type) = type_from_class (temp);
     }
 
@@ -890,7 +890,7 @@ evaluate_subexp_java (struct type *expec
 	  /* Get CLASS_ELEMENT_TYPE of the array type. */
 	  temp = value_struct_elt (&temp, NULL, "methods",
 				   NULL, "structure");
-	  temp->type = value_type (clas);
+	  deprecated_set_value_type (temp, value_type (clas));
 	  el_type = type_from_class (temp);
 	  if (TYPE_CODE (el_type) == TYPE_CODE_STRUCT)
 	    el_type = lookup_pointer_type (el_type);
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.42
diff -p -u -r1.42 objc-lang.c
--- objc-lang.c	29 Jan 2005 00:11:12 -0000	1.42
+++ objc-lang.c	7 Feb 2005 23:35:30 -0000
@@ -204,7 +204,7 @@ value_nsstring (char *ptr, int len)
   else
     error ("NSString: internal error -- no way to create new NSString");
 
-  nsstringValue->type = type;
+  deprecated_set_value_type (nsstringValue, type);
   return nsstringValue;
 }
 
Index: p-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/p-exp.y,v
retrieving revision 1.27
diff -p -u -r1.27 p-exp.y
--- p-exp.y	28 Jul 2004 15:49:04 -0000	1.27
+++ p-exp.y	7 Feb 2005 23:35:30 -0000
@@ -521,7 +521,7 @@ exp	:	THIS
 			  /* we need type of this */
 			  this_val = value_of_this (0); 
 			  if (this_val)
-			    this_type = this_val->type;
+			    this_type = value_type (this_val);
 			  else
 			    this_type = NULL;
 			  if (this_type)
@@ -672,7 +672,7 @@ variable:	name_not_typename
 			      /* we need type of this */
 			      this_val = value_of_this (0); 
 			      if (this_val)
-				this_type = this_val->type;
+				this_type = value_type (this_val);
 			      else
 				this_type = NULL;
 			      if (this_type)
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.84
diff -p -u -r1.84 printcmd.c
--- printcmd.c	7 Feb 2005 00:09:54 -0000	1.84
+++ printcmd.c	7 Feb 2005 23:35:31 -0000
@@ -1904,9 +1904,9 @@ printf_command (char *arg, int from_tty)
 	  {
 	    struct type *type = value_type (val_args[nargs]);
 	    if (TYPE_LENGTH (type) == sizeof (float))
-	      val_args[nargs]->type = builtin_type_float;
+	      deprecated_set_value_type (val_args[nargs], builtin_type_float);
 	    if (TYPE_LENGTH (type) == sizeof (double))
-	      val_args[nargs]->type = builtin_type_double;
+	      deprecated_set_value_type (val_args[nargs], builtin_type_double);
 	  }
 	nargs++;
 	s = s1;
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.68
diff -p -u -r1.68 tracepoint.c
--- tracepoint.c	2 Feb 2005 00:20:05 -0000	1.68
+++ tracepoint.c	7 Feb 2005 23:35:31 -0000
@@ -296,7 +296,7 @@ set_traceframe_context (CORE_ADDR trace_
       func_string = create_array_type (func_string,
 				       builtin_type_char, func_range);
       func_val = allocate_value (func_string);
-      func_val->type = func_string;
+      deprecated_set_value_type (func_val, func_string);
       memcpy (value_contents_raw (func_val),
 	      DEPRECATED_SYMBOL_NAME (traceframe_fun),
 	      len);
@@ -318,7 +318,7 @@ set_traceframe_context (CORE_ADDR trace_
       file_string = create_array_type (file_string,
 				       builtin_type_char, file_range);
       file_val = allocate_value (file_string);
-      file_val->type = file_string;
+      deprecated_set_value_type (file_val, file_string);
       memcpy (value_contents_raw (file_val),
 	      traceframe_sal.symtab->filename,
 	      len);
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.148
diff -p -u -r1.148 valops.c
--- valops.c	7 Feb 2005 20:17:28 -0000	1.148
+++ valops.c	7 Feb 2005 23:35:31 -0000
@@ -240,8 +240,8 @@ value_cast (struct type *type, struct va
 					  TYPE_TARGET_TYPE (range_type),
 					  low_bound,
 					  new_length + low_bound - 1);
-	  arg2->type = create_array_type ((struct type *) NULL,
-					  element_type, range_type);
+	  deprecated_set_value_type (arg2, create_array_type ((struct type *) NULL,
+							      element_type, range_type));
 	  return arg2;
 	}
     }
@@ -282,7 +282,7 @@ value_cast (struct type *type, struct va
 					 arg2, 0, type2, 1);
       if (v)
 	{
-	  v->type = type;
+	  deprecated_set_value_type (v, type);
 	  return v;
 	}
     }
@@ -380,7 +380,7 @@ value_cast (struct type *type, struct va
 		  if (v)
 		    {
 		      v = value_addr (v);
-		      v->type = type;
+		      deprecated_set_value_type (v, type);
 		      return v;
 		    }
 		}
@@ -405,7 +405,7 @@ value_cast (struct type *type, struct va
 	    }
 	  /* No superclass found, just fall through to change ptr type.  */
 	}
-      arg2->type = type;
+      deprecated_set_value_type (arg2, type);
       arg2 = value_change_enclosing_type (arg2, type);
       set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
       return arg2;
@@ -730,7 +730,7 @@ value_assign (struct value *toval, struc
   val = value_copy (toval);
   memcpy (value_contents_raw (val), value_contents (fromval),
 	  TYPE_LENGTH (type));
-  val->type = type;
+  deprecated_set_value_type (val, type);
   val = value_change_enclosing_type (val, value_enclosing_type (fromval));
   set_value_embedded_offset (val, value_embedded_offset (fromval));
   set_value_pointed_to_offset (val, value_pointed_to_offset (fromval));
@@ -855,7 +855,7 @@ value_addr (struct value *arg1)
          We keep the same location information, which is efficient,
          and allows &(&X) to get the location containing the reference. */
       arg2 = value_copy (arg1);
-      arg2->type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
+      deprecated_set_value_type (arg2, lookup_pointer_type (TYPE_TARGET_TYPE (type)));
       return arg2;
     }
   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
@@ -911,7 +911,7 @@ value_ind (struct value *arg1)
       arg2 = value_at_lazy (enc_type, (value_as_address (arg1)
 				       - value_pointed_to_offset (arg1)));
       /* Re-adjust type */
-      arg2->type = TYPE_TARGET_TYPE (base_type);
+      deprecated_set_value_type (arg2, TYPE_TARGET_TYPE (base_type));
       /* Add embedding info */
       arg2 = value_change_enclosing_type (arg2, enc_type);
       set_value_embedded_offset (arg2, value_pointed_to_offset (arg1));
@@ -2625,7 +2625,7 @@ value_full_object (struct value *argp, s
      used for its computation. */
   new_val = value_at_lazy (real_type, VALUE_ADDRESS (argp) - top +
 			   (using_enc ? 0 : value_embedded_offset (argp)));
-  new_val->type = value_type (argp);
+  deprecated_set_value_type (new_val, value_type (argp));
   set_value_embedded_offset (new_val, (using_enc
 				       ? top + value_embedded_offset (argp)
 				       : top));
Index: value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.17
diff -p -u -r1.17 value.c
--- value.c	7 Feb 2005 21:42:36 -0000	1.17
+++ value.c	7 Feb 2005 23:35:34 -0000
@@ -128,6 +132,11 @@ value_type (struct value *value)
 {
   return value->type;
 }
+void
+deprecated_set_value_type (struct value *value, struct type *type)
+{
+  value->type = type;
+}
 
 int
 value_offset (struct value *value)
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.75
diff -p -u -r1.75 value.h
--- value.h	7 Feb 2005 21:42:36 -0000	1.75
+++ value.h	7 Feb 2005 23:35:34 -0000
@@ -174,6 +178,11 @@ struct value
 
 
 extern struct type *value_type (struct value *);
+/* This is being used to change the type of an existing value, that
+   code should instead be creating a new value with the changed type
+   (but possibly shared content).  */
+extern void deprecated_set_value_type (struct value *value,
+				       struct type *type);
 extern int value_bitsize (struct value *);
 extern int value_bitpos (struct value *);
 extern int value_offset (struct value *);

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