]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Always pass an explicit language down to c_type_print
authorPedro Alves <pedro@palves.net>
Fri, 29 Apr 2022 22:21:18 +0000 (23:21 +0100)
committerPedro Alves <pedro@palves.net>
Tue, 10 May 2022 13:16:21 +0000 (14:16 +0100)
The next patch will want to do language->print_type(type, ...), to
print a type in a given language, avoiding a dependency on the current
language.  That doesn't work correctly currently, however, because
most language implementations of language_defn::print_type call
c_print_type without passing down the language.  There are two
overloads of c_print_type, one that takes a language, and one that
does not.  The one that does not uses the current language, defeating
the point of calling language->print_type()...

This commit removes the c_print_type overload that does not take a
language, and adjusts the codebase throughout to always pass down a
language.  In most places, there's already an enum language handy.
language_defn::print_type implementations naturally pass down
this->la_language.  In a couple spots, like in ada-typeprint.c and
rust-lang.c there's no enum language handy, but the code is written
for a specific language, so we just hardcode the language.

In gnuv3_print_method_ptr, I wasn't sure whether we could hardcode C++
here, and we don't have an enum language handy, so I made it use the
current language, just like today.  Can always be improved later.

Change-Id: Ib54fab4cf0fd307bfd55bf1dd5056830096a653b

gdb/ada-typeprint.c
gdb/c-exp.y
gdb/c-lang.c
gdb/c-lang.h
gdb/c-typeprint.c
gdb/d-lang.c
gdb/gnu-v3-abi.c
gdb/go-typeprint.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/rust-lang.c

index 0eb95cb0a73bde840ff256850e24c01b95d930b1..05ffb8b833137e29528bdecac640bf75f5665bde 100644 (file)
@@ -981,7 +981,7 @@ ada_print_type (struct type *type0, const char *varstring,
       {
       default:
        gdb_printf (stream, "<");
-       c_print_type (type, "", stream, show, level, flags);
+       c_print_type (type, "", stream, show, level, language_ada, flags);
        gdb_printf (stream, ">");
        break;
       case TYPE_CODE_PTR:
index 517ab42b2297f9395ff95136edce163606474ed4..72f8dd32d93ae61b0588b4c66b625196b9c716f9 100644 (file)
@@ -1783,6 +1783,7 @@ oper:     OPERATOR NEW
                        {
                          string_file buf;
                          c_print_type ($2, NULL, &buf, -1, 0,
+                                       pstate->language ()->la_language,
                                        &type_print_raw_options);
                          std::string name = buf.release ();
 
index be9ee073f58ff6f75b732bb8c30d589a8c75e891..768963529544ceb9f40b4254565dbccda9c2c946 100644 (file)
@@ -820,7 +820,7 @@ public:
                   struct ui_file *stream, int show, int level,
                   const struct type_print_options *flags) const override
   {
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
@@ -966,7 +966,7 @@ public:
                   struct ui_file *stream, int show, int level,
                   const struct type_print_options *flags) const override
   {
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
@@ -1066,7 +1066,7 @@ public:
                   struct ui_file *stream, int show, int level,
                   const struct type_print_options *flags) const override
   {
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
@@ -1118,7 +1118,7 @@ public:
                   struct ui_file *stream, int show, int level,
                   const struct type_print_options *flags) const override
   {
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
index 46e562df055b9c5edb1c2aee07cb29f020b0f0f4..096eb027fd7516274de4dad0d5f9cac316cfeb96 100644 (file)
@@ -65,16 +65,17 @@ extern int c_parse (struct parser_state *);
 extern int c_parse_escape (const char **, struct obstack *);
 
 /* Defined in c-typeprint.c */
-extern void c_print_type (struct type *, const char *,
-                         struct ui_file *, int, int,
-                         const struct type_print_options *);
 
-/* Print a type but allow the precise language to be specified.  */
+/* Print TYPE to STREAM using syntax appropriate for LANGUAGE, a
+   C-like language.  The other parameters are like
+   type_language_defn::print_type's.  */
 
-extern void c_print_type (struct type *, const char *,
-                         struct ui_file *, int, int,
-                         enum language,
-                         const struct type_print_options *);
+extern void c_print_type (struct type *type,
+                         const char *varstring,
+                         struct ui_file *stream,
+                         int show, int level,
+                         enum language language,
+                         const struct type_print_options *flags);
 
 extern void c_print_typedef (struct type *,
                             struct symbol *,
index 3425c829e3f7e0e77e76059b50a5329ee21b1214..4f45475dc4aba85b9fbccf732a92886253196310 100644 (file)
@@ -163,22 +163,6 @@ c_print_type_1 (struct type *type,
     }
 }
 
-/* LEVEL is the depth to indent lines by.  */
-
-void
-c_print_type (struct type *type,
-             const char *varstring,
-             struct ui_file *stream,
-             int show, int level,
-             const struct type_print_options *flags)
-{
-  struct print_offset_data podata (flags);
-
-  c_print_type_1 (type, varstring, stream, show, level,
-                 current_language->la_language, flags, &podata);
-}
-
-
 /* See c-lang.h.  */
 
 void
@@ -303,7 +287,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
          if (FIELD_ARTIFICIAL (arg))
            continue;
 
-         c_print_type (arg.type (), "", stream, 0, 0, flags);
+         c_print_type (arg.type (), "", stream, 0, 0, language, flags);
 
          if (i == nargs && varargs)
            gdb_printf (stream, ", ...");
@@ -872,7 +856,8 @@ c_type_print_varspec_suffix (struct type *type,
 
 static void
 c_type_print_template_args (const struct type_print_options *flags,
-                           struct type *type, struct ui_file *stream)
+                           struct type *type, struct ui_file *stream,
+                           enum language language)
 {
   int first = 1, i;
 
@@ -899,7 +884,7 @@ c_type_print_template_args (const struct type_print_options *flags,
          gdb_printf (stream, "%s = ", sym->linkage_name ());
        }
 
-      c_print_type (sym->type (), "", stream, -1, 0, flags);
+      c_print_type (sym->type (), "", stream, -1, 0, language, flags);
     }
 
   if (!first)
@@ -1094,7 +1079,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
       struct type *basetype;
       int vptr_fieldno;
 
-      c_type_print_template_args (&local_flags, type, stream);
+      c_type_print_template_args (&local_flags, type, stream, language);
 
       /* Add in template parameters when printing derivation info.  */
       if (local_flags.local_typedefs != NULL)
index ec4a80a3223802ba07daaf1ec57dd3a84c109831..ce6dc058412f43d2b1358ce060aefa2c666c8e47 100644 (file)
@@ -148,7 +148,7 @@ public:
                   struct ui_file *stream, int show, int level,
                   const struct type_print_options *flags) const override
   {
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
index 7aac0ca4f9c206c404b961525de0b3eb92964b72..953645e7411fca3e86ebdd6fb5f66cbef764aa78 100644 (file)
@@ -659,7 +659,8 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
     {
       /* Found a non-virtual function: print out the type.  */
       gdb_puts ("(", stream);
-      c_print_type (type, "", stream, -1, 0, &type_print_raw_options);
+      c_print_type (type, "", stream, -1, 0, current_language->la_language,
+                   &type_print_raw_options);
       gdb_puts (") ", stream);
     }
 
index f8f155fbb648681f2de5a117767c20e52bb20176..4995ac3918673b8f3d510772a362ff7504922632 100644 (file)
@@ -59,5 +59,5 @@ go_language::print_type (struct type *type, const char *varstring,
     }
 
   /* Punt the rest to C for now.  */
-  c_print_type (type, varstring, stream, show, level, flags);
+  c_print_type (type, varstring, stream, show, level, la_language, flags);
 }
index 00c362c5c9c8a370f7b686665701ba2413ba86ba..37008da529a688ba87533879de0e8bbe2c34039b 100644 (file)
@@ -270,7 +270,7 @@ public:
                   struct ui_file *stream, int show, int level,
                   const struct type_print_options *flags) const override
   {
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
index 5145cd4062efcab463ab00021e53693816744cd5..1034d1c91fe5c729d8a10eac7fce2b55cb3296bf 100644 (file)
@@ -969,7 +969,7 @@ public:
          show = 0;
       }
 
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, la_language, flags);
   }
 
   /* See language.h.  */
index bf8dba99ecd6bb774bdf1d283fbb17df7a535917..746f565947be8e74dcbc1529d38e127129c15f1c 100644 (file)
@@ -669,7 +669,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
 
   /* If we see a base class, delegate to C.  */
   if (TYPE_N_BASECLASSES (type) > 0)
-    c_print_type (type, varstring, stream, show, level, flags);
+    c_print_type (type, varstring, stream, show, level, language_rust, flags);
 
   if (flags->print_offsets)
     {
@@ -922,7 +922,8 @@ rust_internal_print_type (struct type *type, const char *varstring,
 
     default:
     c_printer:
-      c_print_type (type, varstring, stream, show, level, flags);
+      c_print_type (type, varstring, stream, show, level, language_rust,
+                   flags);
     }
 }