diff options
author | Tom Tromey <tom@tromey.com> | 2018-03-14 16:38:02 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-03-27 10:09:25 -0600 |
commit | c819b2c0b216c69a4ae5bfba0eac71ffdf1b3596 (patch) | |
tree | 01abe30f0570df89f905e782787bca0ff136692b /gdb/c-typeprint.c | |
parent | 608219fb2917d407058952adf164eb616880662b (diff) | |
download | fsf-binutils-gdb-c819b2c0b216c69a4ae5bfba0eac71ffdf1b3596.zip fsf-binutils-gdb-c819b2c0b216c69a4ae5bfba0eac71ffdf1b3596.tar.gz fsf-binutils-gdb-c819b2c0b216c69a4ae5bfba0eac71ffdf1b3596.tar.bz2 |
C++-ify typedef hash
This changes the typedef_hash_table structure to be a C++ class. It
adds constructors and destructors and changes some functions to be
methods of the class. Then it changes the various users of this class
to adapt. This allows for the removal of some cleanups.
Regression tested by the buildbot.
gdb/ChangeLog
2018-03-27 Tom Tromey <tom@tromey.com>
* typeprint.h (struct type_print_options) <local_typedefs,
global_typedefs>: Remove "struct" keyword.
(class typedef_hash_table): New class.
(recursively_update_typedef_hash, add_template_parameters)
(create_typedef_hash, free_typedef_hash, copy_typedef_hash)
(find_typedef_in_hash): Don't declare.
* typeprint.c (struct typedef_hash_table): Move to typeprint.h.
(typedef_hash_table::recursively_update): Rename from
recursively_update_typedef_hash. Now a member.
(typedef_hash_table::add_template_parameters): Rename from
add_template_parameters. Now a member.
(typedef_hash_table::typedef_hash_table): Now a constructor;
rename from create_typedef_hash.
(typedef_hash_table::~typedef_hash_table): Now a destructor;
rename from free_typedef_hash.
(do_free_typedef_hash, make_cleanup_free_typedef_hash)
(do_free_global_table): Remove.
(typedef_hash_table::typedef_hash_table): New constructor; renamed
from copy_type_recursive.
(create_global_typedef_table): Remove.
(typedef_hash_table::find_global_typedef): Now a member of
typedef_hash_table.
(typedef_hash_table::find_typedef): Rename from
find_typedef_in_hash; now a member.
(whatis_exp): Update.
* extension.h (struct ext_lang_type_printers): Add constructor and
destructor.
(start_ext_lang_type_printers, free_ext_lang_type_printers): Don't
declare.
* extension.c (ext_lang_type_printers::ext_lang_type_printers):
Now a constructor; rename from start_ext_lang_type_printers.
(ext_lang_type_printers): Now a destructor; rename from
free_ext_lang_type_printers.
* c-typeprint.c (find_typedef_for_canonicalize, c_print_type_1):
Update.
(c_type_print_base_struct_union): Update. Remove cleanups.
Diffstat (limited to 'gdb/c-typeprint.c')
-rw-r--r-- | gdb/c-typeprint.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 2e9ed1b..1a8af78 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -68,12 +68,13 @@ static void c_type_print_base_1 (struct type *type, struct ui_file *stream, /* A callback function for cp_canonicalize_string_full that uses - find_typedef_in_hash. */ + typedef_hash_table::find_typedef. */ static const char * find_typedef_for_canonicalize (struct type *t, void *data) { - return find_typedef_in_hash ((const struct type_print_options *) data, t); + return typedef_hash_table::find_typedef + ((const struct type_print_options *) data, t); } /* Print NAME on STREAM. If the 'raw' field of FLAGS is not set, @@ -114,7 +115,7 @@ c_print_type_1 (struct type *type, if (show > 0) type = check_typedef (type); - local_name = find_typedef_in_hash (flags, type); + local_name = typedef_hash_table::find_typedef (flags, type); if (local_name != NULL) { fputs_filtered (local_name, stream); @@ -1109,21 +1110,18 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, struct print_offset_data *podata) { struct type_print_options local_flags = *flags; - struct type_print_options semi_local_flags = *flags; - struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL); - local_flags.local_typedefs = NULL; - semi_local_flags.local_typedefs = NULL; + std::unique_ptr<typedef_hash_table> hash_holder; if (!flags->raw) { if (flags->local_typedefs) local_flags.local_typedefs - = copy_typedef_hash (flags->local_typedefs); + = new typedef_hash_table (*flags->local_typedefs); else - local_flags.local_typedefs = create_typedef_hash (); + local_flags.local_typedefs = new typedef_hash_table (); - make_cleanup_free_typedef_hash (local_flags.local_typedefs); + hash_holder.reset (local_flags.local_typedefs); } c_type_print_modifier (type, stream, 0, 1); @@ -1164,18 +1162,25 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, c_type_print_template_args (&local_flags, type, stream); /* Add in template parameters when printing derivation info. */ - add_template_parameters (local_flags.local_typedefs, type); + if (local_flags.local_typedefs != NULL) + local_flags.local_typedefs->add_template_parameters (type); cp_type_print_derivation_info (stream, type, &local_flags); /* This holds just the global typedefs and the template parameters. */ - semi_local_flags.local_typedefs - = copy_typedef_hash (local_flags.local_typedefs); - if (semi_local_flags.local_typedefs) - make_cleanup_free_typedef_hash (semi_local_flags.local_typedefs); + struct type_print_options semi_local_flags = *flags; + semi_local_flags.local_typedefs = NULL; - /* Now add in the local typedefs. */ - recursively_update_typedef_hash (local_flags.local_typedefs, type); + std::unique_ptr<typedef_hash_table> semi_holder; + if (local_flags.local_typedefs != nullptr) + { + semi_local_flags.local_typedefs + = new typedef_hash_table (*local_flags.local_typedefs); + semi_holder.reset (semi_local_flags.local_typedefs); + + /* Now add in the local typedefs. */ + local_flags.local_typedefs->recursively_update (type); + } fprintf_filtered (stream, "{\n"); @@ -1518,8 +1523,6 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, fprintfi_filtered (level, stream, "}"); } - - do_cleanups (local_cleanups); } /* Print the name of the type (or the ultimate pointer target, |