diff options
author | Tom Tromey <tom@tromey.com> | 2016-11-28 21:39:47 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-01-10 19:14:15 -0700 |
commit | c8b23b3f89fbb0ed28d6b78f775b0038d8604798 (patch) | |
tree | 79c2e34a7eee05122c813fd6e3c04e5e2fd7044e /gdb/cp-name-parser.y | |
parent | 1ac32117f7224620f44ac966b5ca53df6e4fc5bd (diff) | |
download | gdb-c8b23b3f89fbb0ed28d6b78f775b0038d8604798.zip gdb-c8b23b3f89fbb0ed28d6b78f775b0038d8604798.tar.gz gdb-c8b23b3f89fbb0ed28d6b78f775b0038d8604798.tar.bz2 |
Add constructor and destructor to demangle_parse_info
This adds a constructor and destructor to demangle_parse_info, and
then changes all the users to use them. This removes
make_cleanup_cp_demangled_name_parse_free and its single use.
2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-type.c (typy_legacy_template_argument): Update.
* cp-support.h (struct demangle_parse_info) (demangle_parse_info,
~demangle_parse_info): Declare new members.
(cp_demangled_name_to_comp): Return unique_ptr.
(cp_demangled_name_parse_free)
(make_cleanup_cp_demangled_name_parse_free)
(cp_new_demangle_parse_info): Remove.
* cp-support.c (do_demangled_name_parse_free_cleanup)
(make_cleanup_cp_demangled_name_parse_free): Remove.
(inspect_type, cp_canonicalize_string_full)
(cp_canonicalize_string): Update.
(mangled_name_to_comp): Change return type.
(cp_class_name_from_physname, method_name_from_physname)
(cp_func_name, cp_remove_params): Update.
* cp-name-parser.y (demangle_parse_info): New constructor, from
cp_new_demangle_parse_info.
(~demangle_parse_info): New destructor, from
cp_demangled_name_parse_free.
(cp_merge_demangle_parse_infos): Update.
(cp_demangled_name_to_comp): Change return type.
Diffstat (limited to 'gdb/cp-name-parser.y')
-rw-r--r-- | gdb/cp-name-parser.y | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 6d854f1..fd1e949 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1999,29 +1999,19 @@ cp_comp_to_string (struct demangle_component *result, int estimated_len) &err); } -/* A convenience function to allocate and initialize a new struct - demangled_parse_info. */ +/* Constructor for demangle_parse_info. */ -struct demangle_parse_info * -cp_new_demangle_parse_info (void) +demangle_parse_info::demangle_parse_info () +: info (NULL), + tree (NULL) { - struct demangle_parse_info *info; - - info = XNEW (struct demangle_parse_info); - info->info = NULL; - info->tree = NULL; - obstack_init (&info->obstack); - - return info; + obstack_init (&obstack); } -/* Free any memory associated with the given PARSE_INFO. */ +/* Destructor for demangle_parse_info. */ -void -cp_demangled_name_parse_free (struct demangle_parse_info *parse_info) +demangle_parse_info::~demangle_parse_info () { - struct demangle_info *info = parse_info->info; - /* Free any allocated chunks of memory for the parse. */ while (info != NULL) { @@ -2032,15 +2022,11 @@ cp_demangled_name_parse_free (struct demangle_parse_info *parse_info) } /* Free any memory allocated during typedef replacement. */ - obstack_free (&parse_info->obstack, NULL); - - /* Free the parser info. */ - free (parse_info); + obstack_free (&obstack, NULL); } /* Merge the two parse trees given by DEST and SRC. The parse tree in SRC is attached to DEST at the node represented by TARGET. - SRC is then freed. NOTE 1: Since there is no API to merge obstacks, this function does even attempt to try it. Fortunately, we do not (yet?) need this ability. @@ -2067,9 +2053,6 @@ cp_merge_demangle_parse_infos (struct demangle_parse_info *dest, /* Clear the (pointer to) SRC's parse data so that it is not freed when cp_demangled_parse_info_free is called. */ src->info = NULL; - - /* Free SRC. */ - cp_demangled_name_parse_free (src); } /* Convert a demangled name to a demangle_component tree. On success, @@ -2078,11 +2061,10 @@ cp_merge_demangle_parse_infos (struct demangle_parse_info *dest, returned, and an error message will be set in *ERRMSG (which does not need to be freed). */ -struct demangle_parse_info * +struct std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp (const char *demangled_name, const char **errmsg) { static char errbuf[60]; - struct demangle_parse_info *result; prev_lexptr = lexptr = demangled_name; error_lexptr = NULL; @@ -2090,7 +2072,7 @@ cp_demangled_name_to_comp (const char *demangled_name, const char **errmsg) demangle_info = allocate_info (); - result = cp_new_demangle_parse_info (); + std::unique_ptr<demangle_parse_info> result (new demangle_parse_info); result->info = demangle_info; if (yyparse ()) @@ -2102,7 +2084,6 @@ cp_demangled_name_to_comp (const char *demangled_name, const char **errmsg) strcat (errbuf, "'"); *errmsg = errbuf; } - cp_demangled_name_parse_free (result); return NULL; } |