mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
Always pass an explicit language down to c_type_print
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
This commit is contained in:
@@ -981,7 +981,7 @@ ada_print_type (struct type *type0, const char *varstring,
|
|||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
gdb_printf (stream, "<");
|
gdb_printf (stream, "<");
|
||||||
c_print_type (type, "", stream, show, level, flags);
|
c_print_type (type, "", stream, show, level, language_ada, flags);
|
||||||
gdb_printf (stream, ">");
|
gdb_printf (stream, ">");
|
||||||
break;
|
break;
|
||||||
case TYPE_CODE_PTR:
|
case TYPE_CODE_PTR:
|
||||||
|
|||||||
@@ -1783,6 +1783,7 @@ oper: OPERATOR NEW
|
|||||||
{
|
{
|
||||||
string_file buf;
|
string_file buf;
|
||||||
c_print_type ($2, NULL, &buf, -1, 0,
|
c_print_type ($2, NULL, &buf, -1, 0,
|
||||||
|
pstate->language ()->la_language,
|
||||||
&type_print_raw_options);
|
&type_print_raw_options);
|
||||||
std::string name = buf.release ();
|
std::string name = buf.release ();
|
||||||
|
|
||||||
|
|||||||
@@ -820,7 +820,7 @@ public:
|
|||||||
struct ui_file *stream, int show, int level,
|
struct ui_file *stream, int show, int level,
|
||||||
const struct type_print_options *flags) const override
|
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. */
|
/* See language.h. */
|
||||||
@@ -966,7 +966,7 @@ public:
|
|||||||
struct ui_file *stream, int show, int level,
|
struct ui_file *stream, int show, int level,
|
||||||
const struct type_print_options *flags) const override
|
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. */
|
/* See language.h. */
|
||||||
@@ -1066,7 +1066,7 @@ public:
|
|||||||
struct ui_file *stream, int show, int level,
|
struct ui_file *stream, int show, int level,
|
||||||
const struct type_print_options *flags) const override
|
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. */
|
/* See language.h. */
|
||||||
@@ -1118,7 +1118,7 @@ public:
|
|||||||
struct ui_file *stream, int show, int level,
|
struct ui_file *stream, int show, int level,
|
||||||
const struct type_print_options *flags) const override
|
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. */
|
/* See language.h. */
|
||||||
|
|||||||
17
gdb/c-lang.h
17
gdb/c-lang.h
@@ -65,16 +65,17 @@ extern int c_parse (struct parser_state *);
|
|||||||
extern int c_parse_escape (const char **, struct obstack *);
|
extern int c_parse_escape (const char **, struct obstack *);
|
||||||
|
|
||||||
/* Defined in c-typeprint.c */
|
/* 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 *,
|
extern void c_print_type (struct type *type,
|
||||||
struct ui_file *, int, int,
|
const char *varstring,
|
||||||
enum language,
|
struct ui_file *stream,
|
||||||
const struct type_print_options *);
|
int show, int level,
|
||||||
|
enum language language,
|
||||||
|
const struct type_print_options *flags);
|
||||||
|
|
||||||
extern void c_print_typedef (struct type *,
|
extern void c_print_typedef (struct type *,
|
||||||
struct symbol *,
|
struct symbol *,
|
||||||
|
|||||||
@@ -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. */
|
/* See c-lang.h. */
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -303,7 +287,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
|
|||||||
if (FIELD_ARTIFICIAL (arg))
|
if (FIELD_ARTIFICIAL (arg))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
c_print_type (arg.type (), "", stream, 0, 0, flags);
|
c_print_type (arg.type (), "", stream, 0, 0, language, flags);
|
||||||
|
|
||||||
if (i == nargs && varargs)
|
if (i == nargs && varargs)
|
||||||
gdb_printf (stream, ", ...");
|
gdb_printf (stream, ", ...");
|
||||||
@@ -872,7 +856,8 @@ c_type_print_varspec_suffix (struct type *type,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
c_type_print_template_args (const struct type_print_options *flags,
|
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;
|
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 ());
|
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)
|
if (!first)
|
||||||
@@ -1094,7 +1079,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
|
|||||||
struct type *basetype;
|
struct type *basetype;
|
||||||
int vptr_fieldno;
|
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. */
|
/* Add in template parameters when printing derivation info. */
|
||||||
if (local_flags.local_typedefs != NULL)
|
if (local_flags.local_typedefs != NULL)
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ public:
|
|||||||
struct ui_file *stream, int show, int level,
|
struct ui_file *stream, int show, int level,
|
||||||
const struct type_print_options *flags) const override
|
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. */
|
/* See language.h. */
|
||||||
|
|||||||
@@ -659,7 +659,8 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
|
|||||||
{
|
{
|
||||||
/* Found a non-virtual function: print out the type. */
|
/* Found a non-virtual function: print out the type. */
|
||||||
gdb_puts ("(", stream);
|
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);
|
gdb_puts (") ", stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,5 +59,5 @@ go_language::print_type (struct type *type, const char *varstring,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Punt the rest to C for now. */
|
/* 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ public:
|
|||||||
struct ui_file *stream, int show, int level,
|
struct ui_file *stream, int show, int level,
|
||||||
const struct type_print_options *flags) const override
|
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. */
|
/* See language.h. */
|
||||||
|
|||||||
@@ -969,7 +969,7 @@ public:
|
|||||||
show = 0;
|
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. */
|
/* See language.h. */
|
||||||
|
|||||||
@@ -669,7 +669,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
|
|||||||
|
|
||||||
/* If we see a base class, delegate to C. */
|
/* If we see a base class, delegate to C. */
|
||||||
if (TYPE_N_BASECLASSES (type) > 0)
|
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)
|
if (flags->print_offsets)
|
||||||
{
|
{
|
||||||
@@ -922,7 +922,8 @@ rust_internal_print_type (struct type *type, const char *varstring,
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
c_printer:
|
c_printer:
|
||||||
c_print_type (type, varstring, stream, show, level, flags);
|
c_print_type (type, varstring, stream, show, level, language_rust,
|
||||||
|
flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user