2003-11-06 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / valops.c
index 39ee49781c4f7e935b58bc3e431a0aaa11bae205..0d247080591a5a9e14edde0665ef7f922e433aa8 100644 (file)
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include "gdb_string.h"
 #include "gdb_assert.h"
+#include "cp-support.h"
 
 /* Flag indicating HP compilers were used; needed to correctly handle some
    value operations with HP aCC code/runtime. */
@@ -63,6 +64,17 @@ static struct value *search_struct_method (char *, struct value **,
 
 static int check_field_in (struct type *, const char *);
 
+
+static struct value *value_struct_elt_for_reference (struct type *domain,
+                                                    int offset,
+                                                    struct type *curtype,
+                                                    char *name,
+                                                    struct type *intype);
+
+static struct value *value_namespace_elt (const struct type *curtype,
+                                         const char *name,
+                                         enum noside noside);
+
 static CORE_ADDR allocate_space_in_inferior (int);
 
 static struct value *cast_into_complex (struct type *, struct value *);
@@ -615,7 +627,7 @@ value_assign (struct value *toval, struct value *fromval)
            {
              int offset;
              for (reg_offset = value_reg, offset = 0;
-                  offset + REGISTER_RAW_SIZE (reg_offset) <= VALUE_OFFSET (toval);
+                  offset + DEPRECATED_REGISTER_RAW_SIZE (reg_offset) <= VALUE_OFFSET (toval);
                   reg_offset++);
              byte_offset = VALUE_OFFSET (toval) - offset;
            }
@@ -633,7 +645,7 @@ value_assign (struct value *toval, struct value *fromval)
            /* Copy it in.  */
            for (regno = reg_offset, amount_copied = 0;
                 amount_copied < amount_to_copy;
-                amount_copied += REGISTER_RAW_SIZE (regno), regno++)
+                amount_copied += DEPRECATED_REGISTER_RAW_SIZE (regno), regno++)
              frame_register_read (frame, regno, buffer + amount_copied);
            
            /* Modify what needs to be modified.  */
@@ -650,7 +662,7 @@ value_assign (struct value *toval, struct value *fromval)
            /* Copy it out.  */
            for (regno = reg_offset, amount_copied = 0;
                 amount_copied < amount_to_copy;
-                amount_copied += REGISTER_RAW_SIZE (regno), regno++)
+                amount_copied += DEPRECATED_REGISTER_RAW_SIZE (regno), regno++)
              put_frame_register (frame, regno, buffer + amount_copied);
 
          }
@@ -969,7 +981,7 @@ push_bytes (CORE_ADDR sp, char *buffer, int len)
    it to be an argument to a function.  */
 
 static CORE_ADDR
-value_push (register CORE_ADDR sp, struct value *arg)
+value_push (CORE_ADDR sp, struct value *arg)
 {
   int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg));
   int container_len = len;
@@ -1232,7 +1244,7 @@ typecmp (int staticp, int varargs, int nargs,
 
 static struct value *
 search_struct_field (char *name, struct value *arg1, int offset,
-                    register struct type *type, int looking_for_baseclass)
+                    struct type *type, int looking_for_baseclass)
 {
   int i;
   int nbases = TYPE_N_BASECLASSES (type);
@@ -1472,7 +1484,7 @@ find_rt_vbase_offset (struct type *type, struct type *basetype, char *valaddr,
 static struct value *
 search_struct_method (char *name, struct value **arg1p,
                      struct value **args, int offset,
-                     int *static_memfuncp, register struct type *type)
+                     int *static_memfuncp, struct type *type)
 {
   int i;
   struct value *v;
@@ -2125,7 +2137,7 @@ destructor_name_p (const char *name, const struct type *type)
        len = strlen (dname);
       else
        len = cp - dname;
-      if (strlen (name + 1) != len || !STREQN (dname, name + 1, len))
+      if (strlen (name + 1) != len || strncmp (dname, name + 1, len) != 0)
        error ("name of destructor must equal name of class");
       else
        return 1;
@@ -2138,7 +2150,7 @@ destructor_name_p (const char *name, const struct type *type)
    target structure/union is defined, otherwise, return 0. */
 
 static int
-check_field_in (register struct type *type, const char *name)
+check_field_in (struct type *type, const char *name)
 {
   int i;
 
@@ -2207,6 +2219,30 @@ check_field (struct value *arg1, const char *name)
   return check_field_in (t, name);
 }
 
+/* C++: Given an aggregate type CURTYPE, and a member name NAME,
+   return the appropriate member.  This function is used to resolve
+   user expressions of the form "DOMAIN::NAME".  For more details on
+   what happens, see the comment before
+   value_struct_elt_for_reference.  */
+
+struct value *
+value_aggregate_elt (struct type *curtype,
+                    char *name,
+                    enum noside noside)
+{
+  switch (TYPE_CODE (curtype))
+    {
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+      return value_struct_elt_for_reference (curtype, 0, curtype, name, NULL);
+    case TYPE_CODE_NAMESPACE:
+      return value_namespace_elt (curtype, name, noside);
+    default:
+      internal_error (__FILE__, __LINE__,
+                     "non-aggregate type in value_aggregate_elt");
+    }
+}
+
 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
    return the address of this member as a "pointer to member"
    type.  If INTYPE is non-null, then it will be the type
@@ -2347,6 +2383,37 @@ value_struct_elt_for_reference (struct type *domain, int offset,
   return 0;
 }
 
+/* C++: Return the member NAME of the namespace given by the type
+   CURTYPE.  */
+
+static struct value *
+value_namespace_elt (const struct type *curtype,
+                    const char *name,
+                    enum noside noside)
+{
+  const char *namespace_name = TYPE_TAG_NAME (curtype);
+  struct symbol *sym;
+  struct value *retval;
+
+  sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
+                                   get_selected_block (0), VAR_DOMAIN,
+                                   NULL);
+
+  if (sym == NULL)
+    retval = NULL;
+  else if ((noside == EVAL_AVOID_SIDE_EFFECTS)
+          && (SYMBOL_CLASS (sym) == LOC_TYPEDEF))
+    retval = allocate_value (SYMBOL_TYPE (sym));
+  else
+    retval = value_of_variable (sym, get_selected_block (0));
+
+  if (retval == NULL)
+    error ("No symbol \"%s\" in namespace \"%s\".", name,
+          TYPE_TAG_NAME (curtype));
+
+  return retval;
+}
+
 
 /* Given a pointer value V, find the real (RTTI) type
    of the object it points to.
This page took 0.026417 seconds and 4 git commands to generate.