[binutils-gdb] gdb: introduce demangle_parse_info_up
Simon Marchi via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7c1f6faaf3bcd28a37d5f5a9737f6c1dcd0f13ef commit 7c1f6faaf3bcd28a37d5f5a9737f6c1dcd0f13ef Author: Simon Marchi <[email protected]> Date: Thu Aug 20 14:02:34 2026 -0400 gdb: introduce demangle_parse_info_up Introduce the demangle_parse_info_up type alias, as per our convention. I find that more legible. Change-Id: I31944c7d81c8fd7d16df4aac5691fad38ef40ac2 Approved-By: Tom Tromey <[email protected]> Diff: --- gdb/cp-name-parser.y | 4 ++-- gdb/cp-support.c | 59 +++++++++++++++++++++++----------------------------- gdb/cp-support.h | 10 ++++++--- gdb/python/py-type.c | 2 +- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index aee5d834151..1fd4a17db06 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -2040,7 +2040,7 @@ cp_comp_to_string (struct demangle_component *result, int estimated_len) void cp_merge_demangle_parse_infos (struct demangle_parse_info *dest, struct demangle_component *target, - std::unique_ptr<demangle_parse_info> src) + demangle_parse_info_up src) { /* Copy the SRC's parse data into DEST. */ @@ -2055,7 +2055,7 @@ cp_merge_demangle_parse_infos (struct demangle_parse_info *dest, error, NULL is returned, and an error message will be set in *ERRMSG. */ -struct std::unique_ptr<demangle_parse_info> +demangle_parse_info_up cp_demangled_name_to_comp (const char *demangled_name, std::string *errmsg) { diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 36d7c8dd113..b17f1e77d68 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -182,7 +182,6 @@ inspect_type (struct demangle_parse_info *info, long len; int is_anon; struct type *type; - std::unique_ptr<demangle_parse_info> i; /* Get the real type of the typedef. */ type = check_typedef (otype); @@ -253,8 +252,9 @@ inspect_type (struct demangle_parse_info *info, tree will contain pointers into NAME, so NAME cannot be free'd until all typedef conversion is done and the final result is converted into a string. */ - i = cp_demangled_name_to_comp (name); - if (i != NULL) + if (demangle_parse_info_up i + = cp_demangled_name_to_comp (name); + i != nullptr) { /* Merge the two trees. */ cp_merge_demangle_parse_infos (info, ret_comp, std::move (i)); @@ -596,12 +596,10 @@ cp_canonicalize_string_full (const char *string, canonicalization_ftype *finder, void *data) { - unsigned int estimated_len; - std::unique_ptr<demangle_parse_info> info; + unsigned int estimated_len = strlen (string) * 2; + demangle_parse_info_up info = cp_demangled_name_to_comp (string); - estimated_len = strlen (string) * 2; - info = cp_demangled_name_to_comp (string); - if (info != NULL) + if (info != nullptr) { /* Replace all the typedefs in the tree. */ replace_typedefs (info.get (), info->tree, finder, data); @@ -641,17 +639,15 @@ cp_canonicalize_string_no_typedefs (const char *string) gdb::unique_xmalloc_ptr<char> cp_canonicalize_string (const char *string) { - std::unique_ptr<demangle_parse_info> info; - unsigned int estimated_len; - if (cp_already_canonical (string)) return nullptr; - info = cp_demangled_name_to_comp (string); - if (info == NULL) + demangle_parse_info_up info = cp_demangled_name_to_comp (string); + + if (info == nullptr) return nullptr; - estimated_len = strlen (string) * 2; + unsigned int estimated_len = strlen (string) * 2; gdb::unique_xmalloc_ptr<char> us (cp_comp_to_string (info->tree, estimated_len)); @@ -677,7 +673,7 @@ cp_canonicalize_string (const char *string) freed when finished with the tree, or NULL if none was needed. OPTIONS will be passed to the demangler. */ -static std::unique_ptr<demangle_parse_info> +static demangle_parse_info_up mangled_name_to_comp (const char *mangled_name, int options, void **memory, gdb::unique_xmalloc_ptr<char> *demangled_p) @@ -708,7 +704,7 @@ mangled_name_to_comp (const char *mangled_name, int options, /* If we could demangle the name, parse it to build the component tree. */ - std::unique_ptr<demangle_parse_info> info + demangle_parse_info_up info = cp_demangled_name_to_comp (demangled_name.get ()); if (info == NULL) @@ -727,13 +723,12 @@ cp_class_name_from_physname (const char *physname) gdb::unique_xmalloc_ptr<char> demangled_name; gdb::unique_xmalloc_ptr<char> ret; struct demangle_component *ret_comp, *prev_comp, *cur_comp; - std::unique_ptr<demangle_parse_info> info; + demangle_parse_info_up info + = mangled_name_to_comp (physname, DMGL_ANSI, &storage, &demangled_name); int done; - info = mangled_name_to_comp (physname, DMGL_ANSI, - &storage, &demangled_name); - if (info == NULL) - return NULL; + if (info == nullptr) + return nullptr; done = 0; ret_comp = info->tree; @@ -874,12 +869,11 @@ method_name_from_physname (const char *physname) gdb::unique_xmalloc_ptr<char> demangled_name; gdb::unique_xmalloc_ptr<char> ret; struct demangle_component *ret_comp; - std::unique_ptr<demangle_parse_info> info; + demangle_parse_info_up info + = mangled_name_to_comp (physname, DMGL_ANSI, &storage, &demangled_name); - info = mangled_name_to_comp (physname, DMGL_ANSI, - &storage, &demangled_name); - if (info == NULL) - return NULL; + if (info == nullptr) + return nullptr; ret_comp = unqualified_name_from_comp (info->tree); @@ -902,10 +896,9 @@ cp_func_name (const char *full_name) { gdb::unique_xmalloc_ptr<char> ret; struct demangle_component *ret_comp; - std::unique_ptr<demangle_parse_info> info; + demangle_parse_info_up info = cp_demangled_name_to_comp (full_name); - info = cp_demangled_name_to_comp (full_name); - if (!info) + if (info == nullptr) return nullptr; ret_comp = unqualified_name_from_comp (info->tree); @@ -927,15 +920,15 @@ cp_remove_params_1 (const char *demangled_name, bool require_params) { bool done = false; struct demangle_component *ret_comp; - std::unique_ptr<demangle_parse_info> info; gdb::unique_xmalloc_ptr<char> ret; if (demangled_name == NULL) return NULL; - info = cp_demangled_name_to_comp (demangled_name); - if (info == NULL) - return NULL; + demangle_parse_info_up info = cp_demangled_name_to_comp (demangled_name); + + if (info == nullptr) + return nullptr; /* First strip off any qualifiers, if we have a function or method. */ ret_comp = info->tree; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index e495895afdb..da8e777f516 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -53,6 +53,10 @@ struct using_direct; #define CP_OPERATOR_LEN 8 +struct demangle_parse_info; + +using demangle_parse_info_up = std::unique_ptr<demangle_parse_info>; + /* The result of parsing a name. */ struct demangle_parse_info @@ -69,7 +73,7 @@ struct demangle_parse_info /* Any other objects referred to by this object, and whose storage lifetime must be linked. */ - std::vector<std::unique_ptr<demangle_parse_info>> infos; + std::vector<demangle_parse_info_up> infos; }; @@ -168,7 +172,7 @@ struct type *cp_find_type_baseclass_by_name (struct type *parent_type, /* Functions from cp-name-parser.y. */ -extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp +extern demangle_parse_info_up cp_demangled_name_to_comp (const char *demangled_name, std::string *errmsg = nullptr); /* Convert RESULT to a string. ESTIMATED_LEN is used only as a guide @@ -179,7 +183,7 @@ extern gdb::unique_xmalloc_ptr<char> cp_comp_to_string extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *, struct demangle_component *, - std::unique_ptr<demangle_parse_info>); + demangle_parse_info_up); /* The list of "maint cplus" commands. */ diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 9dd0fe2ab37..f374af23d2a 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -925,7 +925,7 @@ typy_legacy_template_argument (struct type *type, const struct block *block, { int i; struct demangle_component *demangled; - std::unique_ptr<demangle_parse_info> info; + demangle_parse_info_up info; std::string err; struct type *argtype;