Remove cleanups from findcmd.c
[deliverable/binutils-gdb.git] / gdb / typeprint.c
index 8dc57f20b8b29a5078f4f900c24f8f9977f80035..c82e623cfa9cf9c5f19bcac5a1c283ee64330774 100644 (file)
@@ -1,6 +1,6 @@
 /* Language independent support for printing types for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+   Copyright (C) 1986-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -37,8 +37,6 @@
 #include "extension.h"
 #include "completer.h"
 
-extern void _initialize_typeprint (void);
-
 static void ptype_command (char *, int);
 
 static void whatis_command (char *, int);
@@ -87,7 +85,7 @@ struct typedef_hash_table
 static hashval_t
 hash_typedef_field (const void *p)
 {
-  const struct typedef_field *tf = p;
+  const struct typedef_field *tf = (const struct typedef_field *) p;
   struct type *t = check_typedef (tf->type);
 
   return htab_hash_string (TYPE_SAFE_NAME (t));
@@ -98,8 +96,8 @@ hash_typedef_field (const void *p)
 static int
 eq_typedef_field (const void *a, const void *b)
 {
-  const struct typedef_field *tfa = a;
-  const struct typedef_field *tfb = b;
+  const struct typedef_field *tfa = (const struct typedef_field *) a;
+  const struct typedef_field *tfb = (const struct typedef_field *) b;
 
   return types_equal (tfa->type, tfb->type);
 }
@@ -195,7 +193,7 @@ free_typedef_hash (struct typedef_hash_table *table)
 static void
 do_free_typedef_hash (void *arg)
 {
-  free_typedef_hash (arg);
+  free_typedef_hash ((struct typedef_hash_table *) arg);
 }
 
 /* Return a new cleanup that frees TABLE.  */
@@ -211,7 +209,7 @@ make_cleanup_free_typedef_hash (struct typedef_hash_table *table)
 static int
 copy_typedef_hash_element (void **slot, void *nt)
 {
-  htab_t new_table = nt;
+  htab_t new_table = (htab_t) nt;
   void **new_slot;
 
   new_slot = htab_find_slot (new_table, *slot, INSERT);
@@ -242,7 +240,7 @@ copy_typedef_hash (struct typedef_hash_table *table)
 static void
 do_free_global_table (void *arg)
 {
-  struct type_print_options *flags = arg;
+  struct type_print_options *flags = (struct type_print_options *) arg;
 
   free_typedef_hash (flags->global_typedefs);
   free_ext_lang_type_printers (flags->global_printers);
@@ -281,7 +279,7 @@ find_global_typedef (const struct type_print_options *flags,
   slot = htab_find_slot (flags->global_typedefs->table, &tf, INSERT);
   if (*slot != NULL)
     {
-      new_tf = *slot;
+      new_tf = (struct typedef_field *) *slot;
       return new_tf->name;
     }
 
@@ -320,7 +318,8 @@ find_typedef_in_hash (const struct type_print_options *flags, struct type *t)
 
       tf.name = NULL;
       tf.type = t;
-      found = htab_find (flags->local_typedefs->table, &tf);
+      found = (struct typedef_field *) htab_find (flags->local_typedefs->table,
+                                                 &tf);
 
       if (found != NULL)
        return found->name;
@@ -367,30 +366,39 @@ type_print (struct type *type, const char *varstring, struct ui_file *stream,
 /* Print TYPE to a string, returning it.  The caller is responsible for
    freeing the string.  */
 
-char *
+std::string
 type_to_string (struct type *type)
 {
-  char *s = NULL;
-  struct ui_file *stb;
-  struct cleanup *old_chain;
-
-  stb = mem_fileopen ();
-  old_chain = make_cleanup_ui_file_delete (stb);
-
   TRY
     {
-      type_print (type, "", stb, -1);
-      s = ui_file_xstrdup (stb, NULL);
+      string_file stb;
+
+      type_print (type, "", &stb, -1);
+      return std::move (stb.string ());
     }
   CATCH (except, RETURN_MASK_ALL)
     {
-      s = NULL;
     }
   END_CATCH
 
-  do_cleanups (old_chain);
+  return {};
+}
+
+/* See typeprint.h.  */
 
-  return s;
+void
+type_print_unknown_return_type (struct ui_file *stream)
+{
+  fprintf_filtered (stream, _("<unknown return type>"));
+}
+
+/* See typeprint.h.  */
+
+void
+error_unknown_type (const char *sym_print_name)
+{
+  error (_("'%s' has unknown type; cast it to its declared type"),
+        sym_print_name);
 }
 
 /* Print type of EXP, or last thing in value history if EXP == NULL.
@@ -399,13 +407,12 @@ type_to_string (struct type *type)
 static void
 whatis_exp (char *exp, int show)
 {
-  struct expression *expr;
   struct value *val;
   struct cleanup *old_chain;
   struct type *real_type = NULL;
   struct type *type;
   int full = 0;
-  int top = -1;
+  LONGEST top = -1;
   int using_enc = 0;
   struct value_print_options opts;
   struct type_print_options flags = default_ptype_flags;
@@ -450,20 +457,46 @@ whatis_exp (char *exp, int show)
          exp = skip_spaces (exp);
        }
 
-      expr = parse_expression (exp);
-      make_cleanup (free_current_contents, &expr);
-      val = evaluate_type (expr);
+      expression_up expr = parse_expression (exp);
+
+      /* The behavior of "whatis" depends on whether the user
+        expression names a type directly, or a language expression
+        (including variable names).  If the former, then "whatis"
+        strips one level of typedefs, only.  If an expression,
+        "whatis" prints the type of the expression without stripping
+        any typedef level.  "ptype" always strips all levels of
+        typedefs.  */
+      if (show == -1 && expr->elts[0].opcode == OP_TYPE)
+       {
+         /* The user expression names a type directly.  */
+         type = expr->elts[1].type;
+
+         /* If this is a typedef, then find its immediate target.
+            Use check_typedef to resolve stubs, but ignore its result
+            because we do not want to dig past all typedefs.  */
+         check_typedef (type);
+         if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+           type = TYPE_TARGET_TYPE (type);
+       }
+      else
+       {
+         /* The user expression names a type indirectly by naming an
+            object or expression of that type.  Find that
+            indirectly-named type.  */
+         val = evaluate_type (expr.get ());
+         type = value_type (val);
+       }
     }
   else
-    val = access_value_history (0);
-
-  type = value_type (val);
+    {
+      val = access_value_history (0);
+      type = value_type (val);
+    }
 
   get_user_print_options (&opts);
   if (opts.objectprint)
     {
-      if (((TYPE_CODE (type) == TYPE_CODE_PTR)
-          || (TYPE_CODE (type) == TYPE_CODE_REF))
+      if (((TYPE_CODE (type) == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type))
          && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
         real_type = value_rtti_indirect_type (val, &full, &top, &using_enc);
       else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
@@ -580,6 +613,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     case TYPE_CODE_METHODPTR:
     case TYPE_CODE_METHOD:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_NAMESPACE:
       error (_("internal error: unhandled type in print_type_scalar"));
       break;
@@ -599,13 +633,10 @@ maintenance_print_type (char *type_name, int from_tty)
 {
   struct value *val;
   struct type *type;
-  struct cleanup *old_chain;
-  struct expression *expr;
 
   if (type_name != NULL)
     {
-      expr = parse_expression (type_name);
-      old_chain = make_cleanup (free_current_contents, &expr);
+      expression_up expr = parse_expression (type_name);
       if (expr->elts[0].opcode == OP_TYPE)
        {
          /* The user expression names a type directly, just use that type.  */
@@ -615,14 +646,13 @@ maintenance_print_type (char *type_name, int from_tty)
        {
          /* The user expression may name a type indirectly by naming an
             object of that type.  Find that indirectly named type.  */
-         val = evaluate_type (expr);
+         val = evaluate_type (expr.get ());
          type = value_type (val);
        }
       if (type != NULL)
        {
          recursive_dump_type (type, 0);
        }
-      do_cleanups (old_chain);
     }
 }
 \f
@@ -726,3 +756,19 @@ Show printing of typedefs defined in classes."), NULL,
                           show_print_type_typedefs,
                           &setprinttypelist, &showprinttypelist);
 }
+
+/* Print <not allocated> status to stream STREAM.  */
+
+void
+val_print_not_allocated (struct ui_file *stream)
+{
+  fprintf_filtered (stream, _("<not allocated>"));
+}
+
+/* Print <not associated> status to stream STREAM.  */
+
+void
+val_print_not_associated (struct ui_file *stream)
+{
+  fprintf_filtered (stream, _("<not associated>"));
+}
This page took 0.039688 seconds and 4 git commands to generate.