use remote-utils facilities for baud_rate
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index b5caccff83c415761035daba503c5b8af567e864..c6e41f349e102e6606eaf932a8f55e2ff56b7e21 100644 (file)
@@ -472,43 +472,20 @@ smash_to_method_type (type, domain, to_type, args)
   TYPE_CODE (type) = TYPE_CODE_METHOD;
 }
 
-/* Return a typename for a struct/union/enum type
-   without the tag qualifier.  If the type has a NULL name,
-   NULL is returned.  */
+/* Return a typename for a struct/union/enum type without "struct ",
+   "union ", or "enum ".  If the type has a NULL name, return NULL.  */
 
 char *
 type_name_no_tag (type)
      register const struct type *type;
 {
-  register char *name;
+  if (TYPE_TAG_NAME (type) != NULL)
+    return TYPE_TAG_NAME (type);
 
-  if ((name = TYPE_NAME (type)) != NULL)
-    {
-      switch (TYPE_CODE (type))
-       {
-         case TYPE_CODE_STRUCT:
-           if(!strncmp (name, "struct ", 7))
-             {
-               name += 7;
-             }
-           break;
-         case TYPE_CODE_UNION:
-           if(!strncmp (name, "union ", 6))
-             {
-               name += 6;
-             }
-           break;
-         case TYPE_CODE_ENUM:
-           if(!strncmp (name, "enum ", 5))
-             {
-               name += 5;
-             }
-           break;
-         default:              /* To avoid -Wall warnings */
-           break;
-       }
-    }
-  return (name);
+  /* Is there code which expects this to return the name if there is no
+     tag name?  My guess is that this is mainly used for C++ in cases where
+     the two will always be the same.  */
+  return TYPE_NAME (type);
 }
 
 /* Lookup a primitive type named NAME. 
@@ -690,9 +667,15 @@ lookup_template_type (name, type, block)
   return (SYMBOL_TYPE (sym));
 }
 
-/* Given a type TYPE, lookup the type of the component of type named
-   NAME.  
-   If NOERR is nonzero, return zero if NAME is not suitably defined.  */
+/* Given a type TYPE, lookup the type of the component of type named NAME.  
+
+   TYPE can be either a struct or union, or a pointer or reference to a struct or
+   union.  If it is a pointer or reference, its target type is automatically used.
+   Thus '.' and '->' are interchangable, as specified for the definitions of the
+   expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
+
+   If NOERR is nonzero, return zero if NAME is not suitably defined.
+   If NAME is the name of a baseclass type, return that type.  */
 
 struct type *
 lookup_struct_elt_type (type, name, noerr)
@@ -718,6 +701,20 @@ lookup_struct_elt_type (type, name, noerr)
 
   check_stub_type (type);
 
+#if 0
+  /* FIXME:  This change put in by Michael seems incorrect for the case where
+     the structure tag name is the same as the member name.  I.E. when doing
+     "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
+     Disabled by fnf. */
+  {
+    char *typename;
+
+    typename = type_name_no_tag (type);
+    if (typename != NULL && STREQ (typename, name))
+      return type;
+  }
+#endif
+
   for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
     {
       char *t_field_name = TYPE_FIELD_NAME (type, i);
@@ -733,7 +730,7 @@ lookup_struct_elt_type (type, name, noerr)
     {
       struct type *t;
 
-      t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 0);
+      t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
       if (t != NULL)
        {
          return t;
@@ -755,17 +752,26 @@ lookup_struct_elt_type (type, name, noerr)
   return (struct type *)-1;    /* For lint */
 }
 
-/* This function is really horrible, but to avoid it, there would need
-   to be more filling in of forward references.  */
+/* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
+   valid.  Callers should be aware that in some cases (for example,
+   the type or one of its baseclasses is a stub type and we are
+   debugging a .o file), this function will not be able to find the virtual
+   function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
+   will remain NULL.  */
 
 void
 fill_in_vptr_fieldno (type)
      struct type *type;
 {
+  check_stub_type (type);
+
   if (TYPE_VPTR_FIELDNO (type) < 0)
     {
       int i;
-      for (i = 1; i < TYPE_N_BASECLASSES (type); i++)
+
+      /* We must start at zero in case the first (and only) baseclass is
+        virtual (and hence we cannot share the table pointer).  */
+      for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
        {
          fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
          if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
@@ -802,6 +808,10 @@ check_stub_type (type)
   if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
     {
       char* name = type_name_no_tag (type);
+      /* FIXME: shouldn't we separately check the TYPE_NAME and the
+        TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
+        as appropriate?  (this code was written before TYPE_NAME and
+        TYPE_TAG_NAME were separate).  */
       struct symbol *sym;
       if (name == NULL)
        {
This page took 0.02795 seconds and 4 git commands to generate.