* RFA: replace typedef_print with a language method @ 2008-09-10 15:15 Tom Tromey 2008-09-10 15:41 ` Pierre Muller 0 siblings, 1 reply; 6+ messages in thread From: Tom Tromey @ 2008-09-10 15:15 UTC (permalink / raw) To: gdb-patches I happened to notice a FIXME comment and some strange defines (e.g., _LANG_pascal) in language.h, and this led me to typedef_print, a strange piece of code. It seemed to me that rather than switching on the current language and having this code know about all the possible languages, it would be better replaced with a language-specific function. So, that is what this patch implements. This patch actually does change behavior slightly -- before this patch, I think ObjC did not print typedefs but instead errored out. Built and regtested on x86-64 (compile farm). Please review. thanks, Tom :ADDPATCH types: 2008-09-10 Tom Tromey <tromey@redhat.com> * value.h (typedef_print): Remove. * symtab.c (print_symbol_info): Use la_print_typedef. * scm-lang.c (scm_language_defn): Update. * p-typeprint.c (pascal_print_typedef): New function. * p-lang.h: (pascal_print_typedef): Declare. * p-lang.c (pascal_language_defn): Update. * objc-lang.c (objc_language_defn): Update. * m2-typeprint.c (m2_print_typedef): New function. * m2-lang.h (m2_print_typedef): Declare. * m2-lang.c (m2_language_defn): Update. * language.h (_LANG_c, _LANG_m2, _LANG_fortran, _LANG_pascal): Remove. (struct language_defn) <la_print_typedef>: New field. (default_print_typedef): Declare. * language.c (unknown_language_defn): Update. (auto_language_defn): Update. (local_language_defn): Update. * jv-lang.c (java_language_defn): Update. * f-lang.c (f_language_defn): Update. * c-typeprint.c (c_print_typedef): New function. * c-lang.h (c_print_typedef): Declare. * c-lang.c (c_language_defn): Update. (cplus_language_defn): Update. (asm_language_defn): Update. (minimal_language_defn): Update. * ada-lang.c (ada_language_defn): Update. * typeprint.c (typedef_print): Remove. (default_print_typedef): New function. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 643cbec..0a8d441 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10943,6 +10943,7 @@ const struct language_defn ada_language_defn = { ada_printstr, /* Function to print string constant */ emit_char, /* Function to print single char (not used) */ ada_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ ada_val_print, /* Print a value using appropriate syntax */ ada_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 9ce4bb9..7294c6c 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -398,6 +398,7 @@ const struct language_defn c_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ @@ -511,6 +512,7 @@ const struct language_defn cplus_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ cplus_skip_trampoline, /* Language specific skip_trampoline */ @@ -546,6 +548,7 @@ const struct language_defn asm_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ @@ -586,6 +589,7 @@ const struct language_defn minimal_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 58d99ce..fe1939a 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -37,6 +37,8 @@ extern void c_error (char *); /* Defined in c-exp.y */ extern void c_print_type (struct type *, char *, struct ui_file *, int, int); +extern void c_print_typedef (struct type *, struct symbol *, struct ui_file *); + extern int c_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, int, int, enum val_prettyprint); diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 56d12f9..31a98ea 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -97,6 +97,24 @@ c_print_type (struct type *type, char *varstring, struct ui_file *stream, } } +/* Print a typedef using C syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +c_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "typedef "); + type_print (type, "", stream, 0); + if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0 + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) + fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol)); + fprintf_filtered (stream, ";\n"); +} + /* If TYPE is a derived type, then print out derivation information. Print only the actual base classes of this type, not the base classes of the base classes. I.E. for the derivation hierarchy: diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 5dcbd33..35391c9 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -321,6 +321,7 @@ const struct language_defn f_language_defn = f_printstr, /* function to print string constant */ f_emit_char, /* Function to print a single character */ f_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ f_val_print, /* Print a value using appropriate syntax */ c_value_print, /* FIXME */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c index ecce237..f778ddc 100644 --- a/gdb/jv-lang.c +++ b/gdb/jv-lang.c @@ -1065,6 +1065,7 @@ const struct language_defn java_language_defn = c_printstr, /* Function to print string constant */ java_emit_char, /* Function to print a single character */ java_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ java_val_print, /* Print a value using appropriate syntax */ java_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/language.c b/gdb/language.c index 66e5542..cdd520f 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -1189,6 +1189,7 @@ const struct language_defn unknown_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ @@ -1225,6 +1226,7 @@ const struct language_defn auto_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ @@ -1260,6 +1262,7 @@ const struct language_defn local_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ diff --git a/gdb/language.h b/gdb/language.h index 8bdc212..6f82d10 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -31,14 +31,6 @@ struct frame_info; struct expression; struct ui_file; -/* This used to be included to configure GDB for one or more specific - languages. Now it is left out to configure for all of them. FIXME. */ -/* #include "lang_def.h" */ -#define _LANG_c -#define _LANG_m2 -#define _LANG_fortran -#define _LANG_pascal - #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ /* range_mode == @@ -187,6 +179,13 @@ struct language_defn void (*la_print_type) (struct type *, char *, struct ui_file *, int, int); + /* Print a typedef using syntax appropriate for this language. + TYPE is the underlying type. NEW_SYMBOL is the symbol naming + the type. STREAM is the output stream on which to print. */ + + void (*la_print_typedef) (struct type *type, struct symbol *new_symbol, + struct ui_file *stream); + /* Print a value using syntax appropriate for this language. */ int (*la_val_print) (struct type *, const gdb_byte *, int, CORE_ADDR, @@ -465,4 +464,8 @@ int language_pass_by_reference (struct type *type); independent of this. */ int default_pass_by_reference (struct type *type); +/* The default implementation of la_print_typedef. */ +void default_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream); + #endif /* defined (LANGUAGE_H) */ diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index bb205ad..8cb1cf7 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -372,6 +372,7 @@ const struct language_defn m2_language_defn = m2_printstr, /* function to print string constant */ m2_emit_char, /* Function to print a single character */ m2_print_type, /* Print a type using appropriate syntax */ + m2_print_typedef, /* Print a typedef using appropriate syntax */ m2_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index 12165ad..94ef411 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -26,6 +26,9 @@ extern void m2_error (char *); /* Defined in m2-exp.y */ extern void m2_print_type (struct type *, char *, struct ui_file *, int, int); +extern void m2_print_typedef (struct type *, struct symbol *, + struct ui_file *); + extern int m2_is_long_set (struct type *type); extern int m2_is_unbounded_array (struct type *type); diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c index 335f8c3..efe0df2 100644 --- a/gdb/m2-typeprint.c +++ b/gdb/m2-typeprint.c @@ -154,6 +154,26 @@ m2_print_type (struct type *type, char *varstring, struct ui_file *stream, } } +/* Print a typedef using M2 syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +m2_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "TYPE "); + if (!TYPE_NAME (SYMBOL_TYPE (new_symbol)) + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); + else + fprintf_filtered (stream, "<builtin> = "); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";\n"); +} + /* m2_type_name - if a, type, has a name then print it. */ void diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 56871e3..7077eb5 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -505,6 +505,7 @@ const struct language_defn objc_language_defn = { objc_printstr, /* Function to print string constant */ objc_emit_char, c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ objc_skip_trampoline, /* Language specific skip_trampoline */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 2accf35..291d3b4 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -411,6 +411,7 @@ const struct language_defn pascal_language_defn = pascal_printstr, /* Function to print string constant */ pascal_emit_char, /* Print a single char */ pascal_print_type, /* Print a type using appropriate syntax */ + pascal_print_typedef, /* Print a typedef using appropriate syntax */ pascal_val_print, /* Print a value using appropriate syntax */ pascal_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/p-lang.h b/gdb/p-lang.h index b840041..a4f878f 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -31,6 +31,9 @@ extern void pascal_error (char *); /* Defined in p-exp.y */ /* Defined in p-typeprint.c */ extern void pascal_print_type (struct type *, char *, struct ui_file *, int, int); +extern void pascal_print_typedef (struct type *, struct symbol *, + struct ui_file *); + extern int pascal_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, int, int, enum val_prettyprint); diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c index e2c34e5..676498b 100644 --- a/gdb/p-typeprint.c +++ b/gdb/p-typeprint.c @@ -87,6 +87,21 @@ pascal_print_type (struct type *type, char *varstring, struct ui_file *stream, } +/* Print a typedef using Pascal syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +pascal_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "type "); + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";\n"); +} + /* If TYPE is a derived type, then print out derivation information. Print only the actual base classes of this type, not the base classes of the base classes. I.E. for the derivation hierarchy: diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c index 991e4b4..cef5010 100644 --- a/gdb/scm-lang.c +++ b/gdb/scm-lang.c @@ -248,6 +248,7 @@ const struct language_defn scm_language_defn = scm_printstr, /* Function to print string constant */ NULL, /* Function to print a single character */ c_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ scm_val_print, /* Print a value using appropriate syntax */ scm_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/symtab.c b/gdb/symtab.c index 1a0dcba..331fc53 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3312,7 +3312,7 @@ print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym, /* Typedef that is not a C++ class */ if (kind == TYPES_DOMAIN && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN) - typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout); + current_language->la_print_typedef (SYMBOL_TYPE (sym), sym, gdb_stdout); /* variable, func, or typedef-that-is-c++-class */ else if (kind < TYPES_DOMAIN || (kind == TYPES_DOMAIN && diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 0ec0e26..7ca9cb2 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -47,48 +47,14 @@ static void whatis_command (char *, int); static void whatis_exp (char *, int); -/* Print a description of a type in the format of a - typedef for the current language. - NEW is the new name for a type TYPE. */ + +/* The default way to print a typedef. */ void -typedef_print (struct type *type, struct symbol *new, struct ui_file *stream) +default_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) { - CHECK_TYPEDEF (type); - switch (current_language->la_language) - { -#ifdef _LANG_c - case language_c: - case language_cplus: - fprintf_filtered (stream, "typedef "); - type_print (type, "", stream, 0); - if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0 - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME (new)) != 0) - fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new)); - break; -#endif -#ifdef _LANG_m2 - case language_m2: - fprintf_filtered (stream, "TYPE "); - if (!TYPE_NAME (SYMBOL_TYPE (new)) - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME (new)) != 0) - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); - else - fprintf_filtered (stream, "<builtin> = "); - type_print (type, "", stream, 0); - break; -#endif -#ifdef _LANG_pascal - case language_pascal: - fprintf_filtered (stream, "type "); - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); - type_print (type, "", stream, 0); - break; -#endif - default: - error (_("Language not supported.")); - } - fprintf_filtered (stream, ";\n"); + error (_("Language not supported.")); } /* Print a description of a type TYPE in the form of a declaration of a diff --git a/gdb/value.h b/gdb/value.h index 2aac9b2..c0046bf 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -543,9 +543,6 @@ extern void print_variable_value (struct symbol *var, extern int check_field (struct type *, const char *); -extern void typedef_print (struct type *type, struct symbol *news, - struct ui_file *stream); - extern char *internalvar_name (struct internalvar *var); extern void preserve_values (struct objfile *); ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: replace typedef_print with a language method 2008-09-10 15:15 RFA: replace typedef_print with a language method Tom Tromey @ 2008-09-10 15:41 ` Pierre Muller 2008-09-10 17:09 ` Tom Tromey 0 siblings, 1 reply; 6+ messages in thread From: Pierre Muller @ 2008-09-10 15:41 UTC (permalink / raw) To: 'Tom Tromey', gdb-patches; +Cc: 'Eli Zaretskii' This patch seems to me like a reasonable change, but I noticed that you removed all the _LANG_xxx macros in language.h source. As this was the last use of those macros, it is probably OK to remove them, but you should take care about removing the reference that exists in doc/gdbint.texinfo around line 2518 >>>> Start of gdbint.texinfo extract @item Use macros to trim code @cindex trimming language-dependent code The user has the option of building @value{GDBN} for some or all of the languages. If the user decides to build @value{GDBN} for the language @var{lang}, then every file dependent on @file{language.h} will have the macro @code{_LANG_@var{lang}} defined in it. Use @code{#ifdef}s to leave out large routines that the user won't need if he or she is not using your language. Note that you do not need to do this in your YACC parser, since if @value{GDBN} is not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (the compiled form of your parser) is not linked into @value{GDBN} at all. See the file @file{configure.in} for how @value{GDBN} is configured for different languages. >>>> End of gdbint.texinfo extract I think that the whole paragraph about trimming language-dependent code should be removed as this possibility seems not to exist anymore. Eli, what is your opinion on this? Pierre Muller Pascal language support maintainer for GDB > -----Message d'origine----- > De : gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Tom Tromey > Envoyé : Wednesday, September 10, 2008 5:15 PM > À : gdb-patches@sourceware.org > Objet : RFA: replace typedef_print with a language method > > I happened to notice a FIXME comment and some strange defines (e.g., > _LANG_pascal) in language.h, and this led me to typedef_print, a > strange piece of code. > > It seemed to me that rather than switching on the current language and > having this code know about all the possible languages, it would be > better replaced with a language-specific function. > > So, that is what this patch implements. This patch actually does > change behavior slightly -- before this patch, I think ObjC did not > print typedefs but instead errored out. > > Built and regtested on x86-64 (compile farm). > > Please review. > > thanks, > Tom > > :ADDPATCH types: > > 2008-09-10 Tom Tromey <tromey@redhat.com> > > * value.h (typedef_print): Remove. > * symtab.c (print_symbol_info): Use la_print_typedef. > * scm-lang.c (scm_language_defn): Update. > * p-typeprint.c (pascal_print_typedef): New function. > * p-lang.h: (pascal_print_typedef): Declare. > * p-lang.c (pascal_language_defn): Update. > * objc-lang.c (objc_language_defn): Update. > * m2-typeprint.c (m2_print_typedef): New function. > * m2-lang.h (m2_print_typedef): Declare. > * m2-lang.c (m2_language_defn): Update. > * language.h (_LANG_c, _LANG_m2, _LANG_fortran, _LANG_pascal): > Remove. > (struct language_defn) <la_print_typedef>: New field. > (default_print_typedef): Declare. > * language.c (unknown_language_defn): Update. > (auto_language_defn): Update. > (local_language_defn): Update. > * jv-lang.c (java_language_defn): Update. > * f-lang.c (f_language_defn): Update. > * c-typeprint.c (c_print_typedef): New function. > * c-lang.h (c_print_typedef): Declare. > * c-lang.c (c_language_defn): Update. > (cplus_language_defn): Update. > (asm_language_defn): Update. > (minimal_language_defn): Update. > * ada-lang.c (ada_language_defn): Update. > * typeprint.c (typedef_print): Remove. > (default_print_typedef): New function. > > diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c > index 643cbec..0a8d441 100644 > --- a/gdb/ada-lang.c > +++ b/gdb/ada-lang.c > @@ -10943,6 +10943,7 @@ const struct language_defn ada_language_defn = > { > ada_printstr, /* Function to print string constant > */ > emit_char, /* Function to print single char (not > used) */ > ada_print_type, /* Print a type using appropriate > syntax */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > ada_val_print, /* Print a value using appropriate > syntax */ > ada_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline > */ > diff --git a/gdb/c-lang.c b/gdb/c-lang.c > index 9ce4bb9..7294c6c 100644 > --- a/gdb/c-lang.c > +++ b/gdb/c-lang.c > @@ -398,6 +398,7 @@ const struct language_defn c_language_defn = > c_printstr, /* Function to print string constant */ > c_emit_char, /* Print a single char */ > c_print_type, /* Print a type using appropriate syntax > */ > + c_print_typedef, /* Print a typedef using appropriate > syntax */ > c_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > @@ -511,6 +512,7 @@ const struct language_defn cplus_language_defn = > c_printstr, /* Function to print string constant */ > c_emit_char, /* Print a single char */ > c_print_type, /* Print a type using appropriate syntax > */ > + c_print_typedef, /* Print a typedef using appropriate > syntax */ > c_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* Print a top-level value */ > cplus_skip_trampoline, /* Language specific skip_trampoline */ > @@ -546,6 +548,7 @@ const struct language_defn asm_language_defn = > c_printstr, /* Function to print string constant */ > c_emit_char, /* Print a single char */ > c_print_type, /* Print a type using appropriate syntax > */ > + c_print_typedef, /* Print a typedef using appropriate > syntax */ > c_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > @@ -586,6 +589,7 @@ const struct language_defn minimal_language_defn = > c_printstr, /* Function to print string constant */ > c_emit_char, /* Print a single char */ > c_print_type, /* Print a type using appropriate syntax > */ > + c_print_typedef, /* Print a typedef using appropriate > syntax */ > c_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > diff --git a/gdb/c-lang.h b/gdb/c-lang.h > index 58d99ce..fe1939a 100644 > --- a/gdb/c-lang.h > +++ b/gdb/c-lang.h > @@ -37,6 +37,8 @@ extern void c_error (char *); /* Defined in c-exp.y > */ > extern void c_print_type (struct type *, char *, struct ui_file *, > int, > int); > > +extern void c_print_typedef (struct type *, struct symbol *, struct > ui_file *); > + > extern int c_val_print (struct type *, const gdb_byte *, int, > CORE_ADDR, > struct ui_file *, int, int, int, > enum val_prettyprint); > diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c > index 56d12f9..31a98ea 100644 > --- a/gdb/c-typeprint.c > +++ b/gdb/c-typeprint.c > @@ -97,6 +97,24 @@ c_print_type (struct type *type, char *varstring, > struct ui_file *stream, > } > } > > +/* Print a typedef using C syntax. TYPE is the underlying type. > + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on > + which to print. */ > + > +void > +c_print_typedef (struct type *type, struct symbol *new_symbol, > + struct ui_file *stream) > +{ > + CHECK_TYPEDEF (type); > + fprintf_filtered (stream, "typedef "); > + type_print (type, "", stream, 0); > + if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0 > + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), > + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) > + fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol)); > + fprintf_filtered (stream, ";\n"); > +} > + > /* If TYPE is a derived type, then print out derivation information. > Print only the actual base classes of this type, not the base > classes > of the base classes. I.E. for the derivation hierarchy: > diff --git a/gdb/f-lang.c b/gdb/f-lang.c > index 5dcbd33..35391c9 100644 > --- a/gdb/f-lang.c > +++ b/gdb/f-lang.c > @@ -321,6 +321,7 @@ const struct language_defn f_language_defn = > f_printstr, /* function to print string constant */ > f_emit_char, /* Function to print a single character > */ > f_print_type, /* Print a type using appropriate syntax > */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > f_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* FIXME */ > NULL, /* Language specific skip_trampoline */ > diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c > index ecce237..f778ddc 100644 > --- a/gdb/jv-lang.c > +++ b/gdb/jv-lang.c > @@ -1065,6 +1065,7 @@ const struct language_defn java_language_defn = > c_printstr, /* Function to print string constant */ > java_emit_char, /* Function to print a single character > */ > java_print_type, /* Print a type using appropriate syntax > */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > java_val_print, /* Print a value using appropriate syntax > */ > java_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > diff --git a/gdb/language.c b/gdb/language.c > index 66e5542..cdd520f 100644 > --- a/gdb/language.c > +++ b/gdb/language.c > @@ -1189,6 +1189,7 @@ const struct language_defn unknown_language_defn > = > unk_lang_printstr, > unk_lang_emit_char, > unk_lang_print_type, /* Print a type using appropriate syntax > */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > unk_lang_val_print, /* Print a value using appropriate syntax > */ > unk_lang_value_print, /* Print a top-level value */ > unk_lang_trampoline, /* Language specific skip_trampoline */ > @@ -1225,6 +1226,7 @@ const struct language_defn auto_language_defn = > unk_lang_printstr, > unk_lang_emit_char, > unk_lang_print_type, /* Print a type using appropriate syntax > */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > unk_lang_val_print, /* Print a value using appropriate syntax > */ > unk_lang_value_print, /* Print a top-level value */ > unk_lang_trampoline, /* Language specific skip_trampoline */ > @@ -1260,6 +1262,7 @@ const struct language_defn local_language_defn = > unk_lang_printstr, > unk_lang_emit_char, > unk_lang_print_type, /* Print a type using appropriate syntax > */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > unk_lang_val_print, /* Print a value using appropriate syntax > */ > unk_lang_value_print, /* Print a top-level value */ > unk_lang_trampoline, /* Language specific skip_trampoline */ > diff --git a/gdb/language.h b/gdb/language.h > index 8bdc212..6f82d10 100644 > --- a/gdb/language.h > +++ b/gdb/language.h > @@ -31,14 +31,6 @@ struct frame_info; > struct expression; > struct ui_file; > > -/* This used to be included to configure GDB for one or more specific > - languages. Now it is left out to configure for all of them. > FIXME. */ > -/* #include "lang_def.h" */ > -#define _LANG_c > -#define _LANG_m2 > -#define _LANG_fortran > -#define _LANG_pascal > - > #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ > > /* range_mode == > @@ -187,6 +179,13 @@ struct language_defn > void (*la_print_type) (struct type *, char *, struct ui_file *, > int, > int); > > + /* Print a typedef using syntax appropriate for this language. > + TYPE is the underlying type. NEW_SYMBOL is the symbol naming > + the type. STREAM is the output stream on which to print. */ > + > + void (*la_print_typedef) (struct type *type, struct symbol > *new_symbol, > + struct ui_file *stream); > + > /* Print a value using syntax appropriate for this language. */ > > int (*la_val_print) (struct type *, const gdb_byte *, int, > CORE_ADDR, > @@ -465,4 +464,8 @@ int language_pass_by_reference (struct type *type); > independent of this. */ > int default_pass_by_reference (struct type *type); > > +/* The default implementation of la_print_typedef. */ > +void default_print_typedef (struct type *type, struct symbol > *new_symbol, > + struct ui_file *stream); > + > #endif /* defined (LANGUAGE_H) */ > diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c > index bb205ad..8cb1cf7 100644 > --- a/gdb/m2-lang.c > +++ b/gdb/m2-lang.c > @@ -372,6 +372,7 @@ const struct language_defn m2_language_defn = > m2_printstr, /* function to print string constant */ > m2_emit_char, /* Function to print a single character > */ > m2_print_type, /* Print a type using appropriate syntax */ > + m2_print_typedef, /* Print a typedef using appropriate > syntax */ > m2_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h > index 12165ad..94ef411 100644 > --- a/gdb/m2-lang.h > +++ b/gdb/m2-lang.h > @@ -26,6 +26,9 @@ extern void m2_error (char *); /* Defined in m2- > exp.y */ > extern void m2_print_type (struct type *, char *, struct ui_file *, > int, > int); > > +extern void m2_print_typedef (struct type *, struct symbol *, > + struct ui_file *); > + > extern int m2_is_long_set (struct type *type); > extern int m2_is_unbounded_array (struct type *type); > > diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c > index 335f8c3..efe0df2 100644 > --- a/gdb/m2-typeprint.c > +++ b/gdb/m2-typeprint.c > @@ -154,6 +154,26 @@ m2_print_type (struct type *type, char *varstring, > struct ui_file *stream, > } > } > > +/* Print a typedef using M2 syntax. TYPE is the underlying type. > + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on > + which to print. */ > + > +void > +m2_print_typedef (struct type *type, struct symbol *new_symbol, > + struct ui_file *stream) > +{ > + CHECK_TYPEDEF (type); > + fprintf_filtered (stream, "TYPE "); > + if (!TYPE_NAME (SYMBOL_TYPE (new_symbol)) > + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), > + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) > + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME > (new_symbol)); > + else > + fprintf_filtered (stream, "<builtin> = "); > + type_print (type, "", stream, 0); > + fprintf_filtered (stream, ";\n"); > +} > + > /* m2_type_name - if a, type, has a name then print it. */ > > void > diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c > index 56871e3..7077eb5 100644 > --- a/gdb/objc-lang.c > +++ b/gdb/objc-lang.c > @@ -505,6 +505,7 @@ const struct language_defn objc_language_defn = { > objc_printstr, /* Function to print string constant */ > objc_emit_char, > c_print_type, /* Print a type using appropriate syntax > */ > + c_print_typedef, /* Print a typedef using appropriate > syntax */ > c_val_print, /* Print a value using appropriate syntax > */ > c_value_print, /* Print a top-level value */ > objc_skip_trampoline, /* Language specific skip_trampoline */ > diff --git a/gdb/p-lang.c b/gdb/p-lang.c > index 2accf35..291d3b4 100644 > --- a/gdb/p-lang.c > +++ b/gdb/p-lang.c > @@ -411,6 +411,7 @@ const struct language_defn pascal_language_defn = > pascal_printstr, /* Function to print string constant */ > pascal_emit_char, /* Print a single char */ > pascal_print_type, /* Print a type using appropriate syntax > */ > + pascal_print_typedef, /* Print a typedef using > appropriate syntax */ > pascal_val_print, /* Print a value using appropriate syntax > */ > pascal_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > diff --git a/gdb/p-lang.h b/gdb/p-lang.h > index b840041..a4f878f 100644 > --- a/gdb/p-lang.h > +++ b/gdb/p-lang.h > @@ -31,6 +31,9 @@ extern void pascal_error (char *); /* Defined in p- > exp.y */ > /* Defined in p-typeprint.c */ > extern void pascal_print_type (struct type *, char *, struct ui_file > *, int, int); > > +extern void pascal_print_typedef (struct type *, struct symbol *, > + struct ui_file *); > + > extern int pascal_val_print (struct type *, const gdb_byte *, int, > CORE_ADDR, struct ui_file *, int, int, > int, enum val_prettyprint); > diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c > index e2c34e5..676498b 100644 > --- a/gdb/p-typeprint.c > +++ b/gdb/p-typeprint.c > @@ -87,6 +87,21 @@ pascal_print_type (struct type *type, char > *varstring, struct ui_file *stream, > > } > > +/* Print a typedef using Pascal syntax. TYPE is the underlying type. > + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on > + which to print. */ > + > +void > +pascal_print_typedef (struct type *type, struct symbol *new_symbol, > + struct ui_file *stream) > +{ > + CHECK_TYPEDEF (type); > + fprintf_filtered (stream, "type "); > + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); > + type_print (type, "", stream, 0); > + fprintf_filtered (stream, ";\n"); > +} > + > /* If TYPE is a derived type, then print out derivation information. > Print only the actual base classes of this type, not the base > classes > of the base classes. I.E. for the derivation hierarchy: > diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c > index 991e4b4..cef5010 100644 > --- a/gdb/scm-lang.c > +++ b/gdb/scm-lang.c > @@ -248,6 +248,7 @@ const struct language_defn scm_language_defn = > scm_printstr, /* Function to print string constant */ > NULL, /* Function to print a single character > */ > c_print_type, /* Print a type using appropriate syntax > */ > + default_print_typedef, /* Print a typedef using appropriate > syntax */ > scm_val_print, /* Print a value using appropriate syntax */ > scm_value_print, /* Print a top-level value */ > NULL, /* Language specific skip_trampoline */ > diff --git a/gdb/symtab.c b/gdb/symtab.c > index 1a0dcba..331fc53 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -3312,7 +3312,7 @@ print_symbol_info (domain_enum kind, struct > symtab *s, struct symbol *sym, > /* Typedef that is not a C++ class */ > if (kind == TYPES_DOMAIN > && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN) > - typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout); > + current_language->la_print_typedef (SYMBOL_TYPE (sym), sym, > gdb_stdout); > /* variable, func, or typedef-that-is-c++-class */ > else if (kind < TYPES_DOMAIN || > (kind == TYPES_DOMAIN && > diff --git a/gdb/typeprint.c b/gdb/typeprint.c > index 0ec0e26..7ca9cb2 100644 > --- a/gdb/typeprint.c > +++ b/gdb/typeprint.c > @@ -47,48 +47,14 @@ static void whatis_command (char *, int); > > static void whatis_exp (char *, int); > > -/* Print a description of a type in the format of a > - typedef for the current language. > - NEW is the new name for a type TYPE. */ > + > +/* The default way to print a typedef. */ > > void > -typedef_print (struct type *type, struct symbol *new, struct ui_file > *stream) > +default_print_typedef (struct type *type, struct symbol *new_symbol, > + struct ui_file *stream) > { > - CHECK_TYPEDEF (type); > - switch (current_language->la_language) > - { > -#ifdef _LANG_c > - case language_c: > - case language_cplus: > - fprintf_filtered (stream, "typedef "); > - type_print (type, "", stream, 0); > - if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0 > - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME > (new)) != 0) > - fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new)); > - break; > -#endif > -#ifdef _LANG_m2 > - case language_m2: > - fprintf_filtered (stream, "TYPE "); > - if (!TYPE_NAME (SYMBOL_TYPE (new)) > - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME > (new)) != 0) > - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); > - else > - fprintf_filtered (stream, "<builtin> = "); > - type_print (type, "", stream, 0); > - break; > -#endif > -#ifdef _LANG_pascal > - case language_pascal: > - fprintf_filtered (stream, "type "); > - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); > - type_print (type, "", stream, 0); > - break; > -#endif > - default: > - error (_("Language not supported.")); > - } > - fprintf_filtered (stream, ";\n"); > + error (_("Language not supported.")); > } > > /* Print a description of a type TYPE in the form of a declaration of > a > diff --git a/gdb/value.h b/gdb/value.h > index 2aac9b2..c0046bf 100644 > --- a/gdb/value.h > +++ b/gdb/value.h > @@ -543,9 +543,6 @@ extern void print_variable_value (struct symbol > *var, > > extern int check_field (struct type *, const char *); > > -extern void typedef_print (struct type *type, struct symbol *news, > - struct ui_file *stream); > - > extern char *internalvar_name (struct internalvar *var); > > extern void preserve_values (struct objfile *); ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: replace typedef_print with a language method 2008-09-10 15:41 ` Pierre Muller @ 2008-09-10 17:09 ` Tom Tromey 2008-09-27 19:51 ` Pedro Alves 0 siblings, 1 reply; 6+ messages in thread From: Tom Tromey @ 2008-09-10 17:09 UTC (permalink / raw) To: Pierre Muller; +Cc: gdb-patches, 'Eli Zaretskii' >>>>> "Pierre" == Pierre Muller <muller@ics.u-strasbg.fr> writes: Pierre> As this was the last use of those macros, Pierre> it is probably OK to remove them, Pierre> but you should take care about removing Pierre> the reference that exists in doc/gdbint.texinfo Aha, thanks. Pierre> I think that the whole paragraph about trimming language-dependent Pierre> code should be removed as this possibility seems Pierre> not to exist anymore. Yeah, I believe this is obsolete. Here's an updated patch. Tom 2008-09-10 Tom Tromey <tromey@redhat.com> * value.h (typedef_print): Remove. * symtab.c (print_symbol_info): Use la_print_typedef. * scm-lang.c (scm_language_defn): Update. * p-typeprint.c (pascal_print_typedef): New function. * p-lang.h: (pascal_print_typedef): Declare. * p-lang.c (pascal_language_defn): Update. * objc-lang.c (objc_language_defn): Update. * m2-typeprint.c (m2_print_typedef): New function. * m2-lang.h (m2_print_typedef): Declare. * m2-lang.c (m2_language_defn): Update. * language.h (_LANG_c, _LANG_m2, _LANG_fortran, _LANG_pascal): Remove. (struct language_defn) <la_print_typedef>: New field. (default_print_typedef): Declare. * language.c (unknown_language_defn): Update. (auto_language_defn): Update. (local_language_defn): Update. * jv-lang.c (java_language_defn): Update. * f-lang.c (f_language_defn): Update. * c-typeprint.c (c_print_typedef): New function. * c-lang.h (c_print_typedef): Declare. * c-lang.c (c_language_defn): Update. (cplus_language_defn): Update. (asm_language_defn): Update. (minimal_language_defn): Update. * ada-lang.c (ada_language_defn): Update. * typeprint.c (typedef_print): Remove. (default_print_typedef): New function. 2008-09-10 Tom Tromey <tromey@redhat.com> * gdbint.texinfo (Language Support): Remove text about omitting support for a language. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 643cbec..0a8d441 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10943,6 +10943,7 @@ const struct language_defn ada_language_defn = { ada_printstr, /* Function to print string constant */ emit_char, /* Function to print single char (not used) */ ada_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ ada_val_print, /* Print a value using appropriate syntax */ ada_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 9ce4bb9..7294c6c 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -398,6 +398,7 @@ const struct language_defn c_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ @@ -511,6 +512,7 @@ const struct language_defn cplus_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ cplus_skip_trampoline, /* Language specific skip_trampoline */ @@ -546,6 +548,7 @@ const struct language_defn asm_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ @@ -586,6 +589,7 @@ const struct language_defn minimal_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 58d99ce..fe1939a 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -37,6 +37,8 @@ extern void c_error (char *); /* Defined in c-exp.y */ extern void c_print_type (struct type *, char *, struct ui_file *, int, int); +extern void c_print_typedef (struct type *, struct symbol *, struct ui_file *); + extern int c_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, int, int, enum val_prettyprint); diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 56d12f9..31a98ea 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -97,6 +97,24 @@ c_print_type (struct type *type, char *varstring, struct ui_file *stream, } } +/* Print a typedef using C syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +c_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "typedef "); + type_print (type, "", stream, 0); + if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0 + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) + fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol)); + fprintf_filtered (stream, ";\n"); +} + /* If TYPE is a derived type, then print out derivation information. Print only the actual base classes of this type, not the base classes of the base classes. I.E. for the derivation hierarchy: diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo index fc2f255..27aaab7 100644 --- a/gdb/doc/gdbint.texinfo +++ b/gdb/doc/gdbint.texinfo @@ -2513,23 +2513,6 @@ printed representations of your operators to @code{op_print_tab}. Add a call to @code{@var{lang}_parse()} and @code{@var{lang}_error} in @code{parse_exp_1} (defined in @file{parse.c}). -@item Use macros to trim code - -@cindex trimming language-dependent code -The user has the option of building @value{GDBN} for some or all of the -languages. If the user decides to build @value{GDBN} for the language -@var{lang}, then every file dependent on @file{language.h} will have the -macro @code{_LANG_@var{lang}} defined in it. Use @code{#ifdef}s to -leave out large routines that the user won't need if he or she is not -using your language. - -Note that you do not need to do this in your YACC parser, since if @value{GDBN} -is not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (the -compiled form of your parser) is not linked into @value{GDBN} at all. - -See the file @file{configure.in} for how @value{GDBN} is configured -for different languages. - @item Edit @file{Makefile.in} Add dependencies in @file{Makefile.in}. Make sure you update the macro diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 5dcbd33..35391c9 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -321,6 +321,7 @@ const struct language_defn f_language_defn = f_printstr, /* function to print string constant */ f_emit_char, /* Function to print a single character */ f_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ f_val_print, /* Print a value using appropriate syntax */ c_value_print, /* FIXME */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c index ecce237..f778ddc 100644 --- a/gdb/jv-lang.c +++ b/gdb/jv-lang.c @@ -1065,6 +1065,7 @@ const struct language_defn java_language_defn = c_printstr, /* Function to print string constant */ java_emit_char, /* Function to print a single character */ java_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ java_val_print, /* Print a value using appropriate syntax */ java_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/language.c b/gdb/language.c index 66e5542..cdd520f 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -1189,6 +1189,7 @@ const struct language_defn unknown_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ @@ -1225,6 +1226,7 @@ const struct language_defn auto_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ @@ -1260,6 +1262,7 @@ const struct language_defn local_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ diff --git a/gdb/language.h b/gdb/language.h index 8bdc212..6f82d10 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -31,14 +31,6 @@ struct frame_info; struct expression; struct ui_file; -/* This used to be included to configure GDB for one or more specific - languages. Now it is left out to configure for all of them. FIXME. */ -/* #include "lang_def.h" */ -#define _LANG_c -#define _LANG_m2 -#define _LANG_fortran -#define _LANG_pascal - #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ /* range_mode == @@ -187,6 +179,13 @@ struct language_defn void (*la_print_type) (struct type *, char *, struct ui_file *, int, int); + /* Print a typedef using syntax appropriate for this language. + TYPE is the underlying type. NEW_SYMBOL is the symbol naming + the type. STREAM is the output stream on which to print. */ + + void (*la_print_typedef) (struct type *type, struct symbol *new_symbol, + struct ui_file *stream); + /* Print a value using syntax appropriate for this language. */ int (*la_val_print) (struct type *, const gdb_byte *, int, CORE_ADDR, @@ -465,4 +464,8 @@ int language_pass_by_reference (struct type *type); independent of this. */ int default_pass_by_reference (struct type *type); +/* The default implementation of la_print_typedef. */ +void default_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream); + #endif /* defined (LANGUAGE_H) */ diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index bb205ad..8cb1cf7 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -372,6 +372,7 @@ const struct language_defn m2_language_defn = m2_printstr, /* function to print string constant */ m2_emit_char, /* Function to print a single character */ m2_print_type, /* Print a type using appropriate syntax */ + m2_print_typedef, /* Print a typedef using appropriate syntax */ m2_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index 12165ad..94ef411 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -26,6 +26,9 @@ extern void m2_error (char *); /* Defined in m2-exp.y */ extern void m2_print_type (struct type *, char *, struct ui_file *, int, int); +extern void m2_print_typedef (struct type *, struct symbol *, + struct ui_file *); + extern int m2_is_long_set (struct type *type); extern int m2_is_unbounded_array (struct type *type); diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c index 335f8c3..efe0df2 100644 --- a/gdb/m2-typeprint.c +++ b/gdb/m2-typeprint.c @@ -154,6 +154,26 @@ m2_print_type (struct type *type, char *varstring, struct ui_file *stream, } } +/* Print a typedef using M2 syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +m2_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "TYPE "); + if (!TYPE_NAME (SYMBOL_TYPE (new_symbol)) + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); + else + fprintf_filtered (stream, "<builtin> = "); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";\n"); +} + /* m2_type_name - if a, type, has a name then print it. */ void diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 56871e3..7077eb5 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -505,6 +505,7 @@ const struct language_defn objc_language_defn = { objc_printstr, /* Function to print string constant */ objc_emit_char, c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ objc_skip_trampoline, /* Language specific skip_trampoline */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 2accf35..291d3b4 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -411,6 +411,7 @@ const struct language_defn pascal_language_defn = pascal_printstr, /* Function to print string constant */ pascal_emit_char, /* Print a single char */ pascal_print_type, /* Print a type using appropriate syntax */ + pascal_print_typedef, /* Print a typedef using appropriate syntax */ pascal_val_print, /* Print a value using appropriate syntax */ pascal_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/p-lang.h b/gdb/p-lang.h index b840041..a4f878f 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -31,6 +31,9 @@ extern void pascal_error (char *); /* Defined in p-exp.y */ /* Defined in p-typeprint.c */ extern void pascal_print_type (struct type *, char *, struct ui_file *, int, int); +extern void pascal_print_typedef (struct type *, struct symbol *, + struct ui_file *); + extern int pascal_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, int, int, enum val_prettyprint); diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c index e2c34e5..676498b 100644 --- a/gdb/p-typeprint.c +++ b/gdb/p-typeprint.c @@ -87,6 +87,21 @@ pascal_print_type (struct type *type, char *varstring, struct ui_file *stream, } +/* Print a typedef using Pascal syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +pascal_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "type "); + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";\n"); +} + /* If TYPE is a derived type, then print out derivation information. Print only the actual base classes of this type, not the base classes of the base classes. I.E. for the derivation hierarchy: diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c index 991e4b4..cef5010 100644 --- a/gdb/scm-lang.c +++ b/gdb/scm-lang.c @@ -248,6 +248,7 @@ const struct language_defn scm_language_defn = scm_printstr, /* Function to print string constant */ NULL, /* Function to print a single character */ c_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ scm_val_print, /* Print a value using appropriate syntax */ scm_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/symtab.c b/gdb/symtab.c index 1a0dcba..331fc53 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3312,7 +3312,7 @@ print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym, /* Typedef that is not a C++ class */ if (kind == TYPES_DOMAIN && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN) - typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout); + current_language->la_print_typedef (SYMBOL_TYPE (sym), sym, gdb_stdout); /* variable, func, or typedef-that-is-c++-class */ else if (kind < TYPES_DOMAIN || (kind == TYPES_DOMAIN && diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 0ec0e26..7ca9cb2 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -47,48 +47,14 @@ static void whatis_command (char *, int); static void whatis_exp (char *, int); -/* Print a description of a type in the format of a - typedef for the current language. - NEW is the new name for a type TYPE. */ + +/* The default way to print a typedef. */ void -typedef_print (struct type *type, struct symbol *new, struct ui_file *stream) +default_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) { - CHECK_TYPEDEF (type); - switch (current_language->la_language) - { -#ifdef _LANG_c - case language_c: - case language_cplus: - fprintf_filtered (stream, "typedef "); - type_print (type, "", stream, 0); - if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0 - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME (new)) != 0) - fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new)); - break; -#endif -#ifdef _LANG_m2 - case language_m2: - fprintf_filtered (stream, "TYPE "); - if (!TYPE_NAME (SYMBOL_TYPE (new)) - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME (new)) != 0) - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); - else - fprintf_filtered (stream, "<builtin> = "); - type_print (type, "", stream, 0); - break; -#endif -#ifdef _LANG_pascal - case language_pascal: - fprintf_filtered (stream, "type "); - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); - type_print (type, "", stream, 0); - break; -#endif - default: - error (_("Language not supported.")); - } - fprintf_filtered (stream, ";\n"); + error (_("Language not supported.")); } /* Print a description of a type TYPE in the form of a declaration of a diff --git a/gdb/value.h b/gdb/value.h index 2aac9b2..c0046bf 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -543,9 +543,6 @@ extern void print_variable_value (struct symbol *var, extern int check_field (struct type *, const char *); -extern void typedef_print (struct type *type, struct symbol *news, - struct ui_file *stream); - extern char *internalvar_name (struct internalvar *var); extern void preserve_values (struct objfile *); ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: replace typedef_print with a language method 2008-09-10 17:09 ` Tom Tromey @ 2008-09-27 19:51 ` Pedro Alves 2008-09-27 21:29 ` Tom Tromey 0 siblings, 1 reply; 6+ messages in thread From: Pedro Alves @ 2008-09-27 19:51 UTC (permalink / raw) To: gdb-patches, Tom Tromey; +Cc: Pierre Muller, 'Eli Zaretskii' Hi Tom, This looks good to me except for the minor comment below. On Wednesday 10 September 2008 18:07:14, Tom Tromey wrote: > @@ -3312,7 +3312,7 @@ print_symbol_info (domain_enum kind, struct symtab > *s, struct symbol *sym, /* Typedef that is not a C++ class */ > if (kind == TYPES_DOMAIN > && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN) > - typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout); > + current_language->la_print_typedef (SYMBOL_TYPE (sym), sym, gdb_stdout); For consistency with the other language print methods, could you please add a LA_PRINT_TYPEDEF macro to language.h, and use it instead of calling current_language->la_print_typedef directly? Okay with that change. For extra consistency, I'd be mildly inclined to leave typedef_print in place, similarly to type_print, but I've no strong opinion on that. As a side note, there's a ada_typedef_print function in ada-typeprint.c, but it isn't used anywhere, even pre-your patch. :REVIEWMAIL: Thanks, -- Pedro Alves ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: replace typedef_print with a language method 2008-09-27 19:51 ` Pedro Alves @ 2008-09-27 21:29 ` Tom Tromey 2008-09-27 21:30 ` Tom Tromey 0 siblings, 1 reply; 6+ messages in thread From: Tom Tromey @ 2008-09-27 21:29 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches >>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes: Pedro> For consistency with the other language print methods, could you please Pedro> add a LA_PRINT_TYPEDEF macro to language.h, and use it instead of calling Pedro> current_language-> la_print_typedef directly? Done. Pedro> For extra consistency, I'd be mildly inclined to leave typedef_print in Pedro> place, similarly to type_print, but I've no strong opinion on that. I restored it. Here is the patch I'm checking in. Tom 2008-09-27 Tom Tromey <tromey@redhat.com> * scm-lang.c (scm_language_defn): Update. * p-typeprint.c (pascal_print_typedef): New function. * p-lang.h: (pascal_print_typedef): Declare. * p-lang.c (pascal_language_defn): Update. * objc-lang.c (objc_language_defn): Update. * m2-typeprint.c (m2_print_typedef): New function. * m2-lang.h (m2_print_typedef): Declare. * m2-lang.c (m2_language_defn): Update. * language.h (_LANG_c, _LANG_m2, _LANG_fortran, _LANG_pascal): Remove. (struct language_defn) <la_print_typedef>: New field. (default_print_typedef): Declare. (LA_PRINT_TYPEDEF): New define. * language.c (unknown_language_defn): Update. (auto_language_defn): Update. (local_language_defn): Update. * jv-lang.c (java_language_defn): Update. * f-lang.c (f_language_defn): Update. * c-typeprint.c (c_print_typedef): New function. * c-lang.h (c_print_typedef): Declare. * c-lang.c (c_language_defn): Update. (cplus_language_defn): Update. (asm_language_defn): Update. (minimal_language_defn): Update. * ada-lang.c (ada_language_defn): Update. * typeprint.c (default_print_typedef): New function. 2008-09-27 Tom Tromey <tromey@redhat.com> * gdbint.texinfo (Language Support): Remove text about omitting support for a language. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7176561..d4d7dc0 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10943,6 +10943,7 @@ const struct language_defn ada_language_defn = { ada_printstr, /* Function to print string constant */ emit_char, /* Function to print single char (not used) */ ada_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ ada_val_print, /* Print a value using appropriate syntax */ ada_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index ebe781b..a9cd9c2 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -400,6 +400,7 @@ const struct language_defn c_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ @@ -516,6 +517,7 @@ const struct language_defn cplus_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ cplus_skip_trampoline, /* Language specific skip_trampoline */ @@ -551,6 +553,7 @@ const struct language_defn asm_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ @@ -591,6 +594,7 @@ const struct language_defn minimal_language_defn = c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 58d99ce..fe1939a 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -37,6 +37,8 @@ extern void c_error (char *); /* Defined in c-exp.y */ extern void c_print_type (struct type *, char *, struct ui_file *, int, int); +extern void c_print_typedef (struct type *, struct symbol *, struct ui_file *); + extern int c_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, int, int, enum val_prettyprint); diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 56d12f9..31a98ea 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -97,6 +97,24 @@ c_print_type (struct type *type, char *varstring, struct ui_file *stream, } } +/* Print a typedef using C syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +c_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "typedef "); + type_print (type, "", stream, 0); + if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0 + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) + fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol)); + fprintf_filtered (stream, ";\n"); +} + /* If TYPE is a derived type, then print out derivation information. Print only the actual base classes of this type, not the base classes of the base classes. I.E. for the derivation hierarchy: diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo index 63b0d34..1edb444 100644 --- a/gdb/doc/gdbint.texinfo +++ b/gdb/doc/gdbint.texinfo @@ -2513,23 +2513,6 @@ printed representations of your operators to @code{op_print_tab}. Add a call to @code{@var{lang}_parse()} and @code{@var{lang}_error} in @code{parse_exp_1} (defined in @file{parse.c}). -@item Use macros to trim code - -@cindex trimming language-dependent code -The user has the option of building @value{GDBN} for some or all of the -languages. If the user decides to build @value{GDBN} for the language -@var{lang}, then every file dependent on @file{language.h} will have the -macro @code{_LANG_@var{lang}} defined in it. Use @code{#ifdef}s to -leave out large routines that the user won't need if he or she is not -using your language. - -Note that you do not need to do this in your YACC parser, since if @value{GDBN} -is not build for @var{lang}, then @file{@var{lang}-exp.tab.o} (the -compiled form of your parser) is not linked into @value{GDBN} at all. - -See the file @file{configure.in} for how @value{GDBN} is configured -for different languages. - @item Edit @file{Makefile.in} Add dependencies in @file{Makefile.in}. Make sure you update the macro diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 8ae7775..4e2f3c4 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -324,6 +324,7 @@ const struct language_defn f_language_defn = f_printstr, /* function to print string constant */ f_emit_char, /* Function to print a single character */ f_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ f_val_print, /* Print a value using appropriate syntax */ c_value_print, /* FIXME */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c index 39d8f48..69570b4 100644 --- a/gdb/jv-lang.c +++ b/gdb/jv-lang.c @@ -1110,6 +1110,7 @@ const struct language_defn java_language_defn = c_printstr, /* Function to print string constant */ java_emit_char, /* Function to print a single character */ java_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ java_val_print, /* Print a value using appropriate syntax */ java_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/language.c b/gdb/language.c index 7b0b44a..0b21dc3 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -1145,6 +1145,7 @@ const struct language_defn unknown_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ @@ -1181,6 +1182,7 @@ const struct language_defn auto_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ @@ -1216,6 +1218,7 @@ const struct language_defn local_language_defn = unk_lang_printstr, unk_lang_emit_char, unk_lang_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_val_print, /* Print a value using appropriate syntax */ unk_lang_value_print, /* Print a top-level value */ unk_lang_trampoline, /* Language specific skip_trampoline */ diff --git a/gdb/language.h b/gdb/language.h index 04d4da2..ba28540 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -31,14 +31,6 @@ struct frame_info; struct expression; struct ui_file; -/* This used to be included to configure GDB for one or more specific - languages. Now it is left out to configure for all of them. FIXME. */ -/* #include "lang_def.h" */ -#define _LANG_c -#define _LANG_m2 -#define _LANG_fortran -#define _LANG_pascal - #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims */ /* range_mode == @@ -192,6 +184,13 @@ struct language_defn void (*la_print_type) (struct type *, char *, struct ui_file *, int, int); + /* Print a typedef using syntax appropriate for this language. + TYPE is the underlying type. NEW_SYMBOL is the symbol naming + the type. STREAM is the output stream on which to print. */ + + void (*la_print_typedef) (struct type *type, struct symbol *new_symbol, + struct ui_file *stream); + /* Print a value using syntax appropriate for this language. */ int (*la_val_print) (struct type *, const gdb_byte *, int, CORE_ADDR, @@ -350,6 +349,9 @@ extern enum language set_language (enum language); #define LA_PRINT_TYPE(type,varstring,stream,show,level) \ (current_language->la_print_type(type,varstring,stream,show,level)) +#define LA_PRINT_TYPEDEF(type,new_symbol,stream) \ + (current_language->la_print_typedef(type,new_symbol,stream)) + #define LA_VAL_PRINT(type,valaddr,offset,addr,stream,fmt,deref,recurse,pretty) \ (current_language->la_val_print(type,valaddr,offset,addr,stream,fmt,deref, \ recurse,pretty)) @@ -468,4 +470,8 @@ int language_pass_by_reference (struct type *type); independent of this. */ int default_pass_by_reference (struct type *type); +/* The default implementation of la_print_typedef. */ +void default_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream); + #endif /* defined (LANGUAGE_H) */ diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index 8bc0ce7..2b3ca6a 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -375,6 +375,7 @@ const struct language_defn m2_language_defn = m2_printstr, /* function to print string constant */ m2_emit_char, /* Function to print a single character */ m2_print_type, /* Print a type using appropriate syntax */ + m2_print_typedef, /* Print a typedef using appropriate syntax */ m2_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index ac7c8f5..8ce458c 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -26,6 +26,9 @@ extern void m2_error (char *); /* Defined in m2-exp.y */ extern void m2_print_type (struct type *, char *, struct ui_file *, int, int); +extern void m2_print_typedef (struct type *, struct symbol *, + struct ui_file *); + extern int m2_is_long_set (struct type *type); extern int m2_is_unbounded_array (struct type *type); diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c index 666ae28..e2970e2 100644 --- a/gdb/m2-typeprint.c +++ b/gdb/m2-typeprint.c @@ -154,6 +154,26 @@ m2_print_type (struct type *type, char *varstring, struct ui_file *stream, } } +/* Print a typedef using M2 syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +m2_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "TYPE "); + if (!TYPE_NAME (SYMBOL_TYPE (new_symbol)) + || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), + SYMBOL_LINKAGE_NAME (new_symbol)) != 0) + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); + else + fprintf_filtered (stream, "<builtin> = "); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";\n"); +} + /* m2_type_name - if a, type, has a name then print it. */ void diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 1692c3d..4608168 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -512,6 +512,7 @@ const struct language_defn objc_language_defn = { objc_printstr, /* Function to print string constant */ objc_emit_char, c_print_type, /* Print a type using appropriate syntax */ + c_print_typedef, /* Print a typedef using appropriate syntax */ c_val_print, /* Print a value using appropriate syntax */ c_value_print, /* Print a top-level value */ objc_skip_trampoline, /* Language specific skip_trampoline */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index b763e04..b829f8d 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -414,6 +414,7 @@ const struct language_defn pascal_language_defn = pascal_printstr, /* Function to print string constant */ pascal_emit_char, /* Print a single char */ pascal_print_type, /* Print a type using appropriate syntax */ + pascal_print_typedef, /* Print a typedef using appropriate syntax */ pascal_val_print, /* Print a value using appropriate syntax */ pascal_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/p-lang.h b/gdb/p-lang.h index b840041..a4f878f 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -31,6 +31,9 @@ extern void pascal_error (char *); /* Defined in p-exp.y */ /* Defined in p-typeprint.c */ extern void pascal_print_type (struct type *, char *, struct ui_file *, int, int); +extern void pascal_print_typedef (struct type *, struct symbol *, + struct ui_file *); + extern int pascal_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, int, int, enum val_prettyprint); diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c index a10982d..afc831c 100644 --- a/gdb/p-typeprint.c +++ b/gdb/p-typeprint.c @@ -87,6 +87,21 @@ pascal_print_type (struct type *type, char *varstring, struct ui_file *stream, } +/* Print a typedef using Pascal syntax. TYPE is the underlying type. + NEW_SYMBOL is the symbol naming the type. STREAM is the stream on + which to print. */ + +void +pascal_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + CHECK_TYPEDEF (type); + fprintf_filtered (stream, "type "); + fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol)); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";\n"); +} + /* If TYPE is a derived type, then print out derivation information. Print only the actual base classes of this type, not the base classes of the base classes. I.E. for the derivation hierarchy: diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c index 003e27a..607efb6 100644 --- a/gdb/scm-lang.c +++ b/gdb/scm-lang.c @@ -254,6 +254,7 @@ const struct language_defn scm_language_defn = scm_printstr, /* Function to print string constant */ NULL, /* Function to print a single character */ c_print_type, /* Print a type using appropriate syntax */ + default_print_typedef, /* Print a typedef using appropriate syntax */ scm_val_print, /* Print a value using appropriate syntax */ scm_value_print, /* Print a top-level value */ NULL, /* Language specific skip_trampoline */ diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 0ec0e26..44f1a77 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -47,6 +47,7 @@ static void whatis_command (char *, int); static void whatis_exp (char *, int); + /* Print a description of a type in the format of a typedef for the current language. NEW is the new name for a type TYPE. */ @@ -54,41 +55,16 @@ static void whatis_exp (char *, int); void typedef_print (struct type *type, struct symbol *new, struct ui_file *stream) { - CHECK_TYPEDEF (type); - switch (current_language->la_language) - { -#ifdef _LANG_c - case language_c: - case language_cplus: - fprintf_filtered (stream, "typedef "); - type_print (type, "", stream, 0); - if (TYPE_NAME ((SYMBOL_TYPE (new))) == 0 - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME (new)) != 0) - fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new)); - break; -#endif -#ifdef _LANG_m2 - case language_m2: - fprintf_filtered (stream, "TYPE "); - if (!TYPE_NAME (SYMBOL_TYPE (new)) - || strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), SYMBOL_LINKAGE_NAME (new)) != 0) - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); - else - fprintf_filtered (stream, "<builtin> = "); - type_print (type, "", stream, 0); - break; -#endif -#ifdef _LANG_pascal - case language_pascal: - fprintf_filtered (stream, "type "); - fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new)); - type_print (type, "", stream, 0); - break; -#endif - default: - error (_("Language not supported.")); - } - fprintf_filtered (stream, ";\n"); + LA_PRINT_TYPEDEF (type, new, stream); +} + +/* The default way to print a typedef. */ + +void +default_print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) +{ + error (_("Language not supported.")); } /* Print a description of a type TYPE in the form of a declaration of a ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: replace typedef_print with a language method 2008-09-27 21:29 ` Tom Tromey @ 2008-09-27 21:30 ` Tom Tromey 0 siblings, 0 replies; 6+ messages in thread From: Tom Tromey @ 2008-09-27 21:30 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches Tom> Here is the patch I'm checking in. I neglected to mention that I built and regtested this on x86-64 (compile farm). Tom ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-09-27 21:30 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-09-10 15:15 RFA: replace typedef_print with a language method Tom Tromey 2008-09-10 15:41 ` Pierre Muller 2008-09-10 17:09 ` Tom Tromey 2008-09-27 19:51 ` Pedro Alves 2008-09-27 21:29 ` Tom Tromey 2008-09-27 21:30 ` Tom Tromey
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox