+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.
+
2017-01-10 Tom Tromey <tom@tromey.com>
* top.c (prevent_dont_repeat): Change return type.
&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)
{
}
/* 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.
/* 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,
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;
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 ())
strcat (errbuf, "'");
*errmsg = errbuf;
}
- cp_demangled_name_parse_free (result);
return NULL;
}
return (char *) obstack_copy (obstack, string, *len);
}
-/* A cleanup wrapper for cp_demangled_name_parse_free. */
-
-static void
-do_demangled_name_parse_free_cleanup (void *data)
-{
- struct demangle_parse_info *info = (struct demangle_parse_info *) data;
-
- cp_demangled_name_parse_free (info);
-}
-
-/* Create a cleanup for C++ name parsing. */
-
-struct cleanup *
-make_cleanup_cp_demangled_name_parse_free (struct demangle_parse_info *info)
-{
- return make_cleanup (do_demangled_name_parse_free_cleanup, info);
-}
-
/* Return 1 if STRING is clearly already in canonical form. This
function is conservative; things which it does not recognize are
assumed to be non-canonical, and the parser will sort them out
long len;
int is_anon;
struct type *type;
- struct demangle_parse_info *i;
+ std::unique_ptr<demangle_parse_info> i;
struct ui_file *buf;
/* Get the real type of the typedef. */
if (i != NULL)
{
/* Merge the two trees. */
- cp_merge_demangle_parse_infos (info, ret_comp, i);
+ cp_merge_demangle_parse_infos (info, ret_comp, i.get ());
/* Replace any newly introduced typedefs -- but not
if the type is anonymous (that would lead to infinite
{
std::string ret;
unsigned int estimated_len;
- struct demangle_parse_info *info;
+ std::unique_ptr<demangle_parse_info> info;
estimated_len = strlen (string) * 2;
info = cp_demangled_name_to_comp (string, NULL);
if (info != NULL)
{
/* Replace all the typedefs in the tree. */
- replace_typedefs (info, info->tree, finder, data);
+ replace_typedefs (info.get (), info->tree, finder, data);
/* Convert the tree back into a string. */
ret = cp_comp_to_string (info->tree, estimated_len);
gdb_assert (!ret.empty ());
- /* Free the parse information. */
- cp_demangled_name_parse_free (info);
-
/* Finally, compare the original string with the computed
name, returning NULL if they are the same. */
if (ret == string)
std::string
cp_canonicalize_string (const char *string)
{
- struct demangle_parse_info *info;
+ std::unique_ptr<demangle_parse_info> info;
unsigned int estimated_len;
if (cp_already_canonical (string))
estimated_len = strlen (string) * 2;
std::string ret = cp_comp_to_string (info->tree, estimated_len);
- cp_demangled_name_parse_free (info);
if (ret.empty ())
{
freed when finished with the tree, or NULL if none was needed.
OPTIONS will be passed to the demangler. */
-static struct demangle_parse_info *
+static std::unique_ptr<demangle_parse_info>
mangled_name_to_comp (const char *mangled_name, int options,
void **memory, char **demangled_p)
{
char *demangled_name;
- struct demangle_parse_info *info;
/* If it looks like a v3 mangled name, then try to go directly
to trees. */
options, memory);
if (ret)
{
- info = cp_new_demangle_parse_info ();
+ std::unique_ptr<demangle_parse_info> info (new demangle_parse_info);
info->tree = ret;
*demangled_p = NULL;
return info;
/* If we could demangle the name, parse it to build the component
tree. */
- info = cp_demangled_name_to_comp (demangled_name, NULL);
+ std::unique_ptr<demangle_parse_info> info
+ = cp_demangled_name_to_comp (demangled_name, NULL);
if (info == NULL)
{
void *storage = NULL;
char *demangled_name = NULL, *ret;
struct demangle_component *ret_comp, *prev_comp, *cur_comp;
- struct demangle_parse_info *info;
+ std::unique_ptr<demangle_parse_info> info;
int done;
info = mangled_name_to_comp (physname, DMGL_ANSI,
xfree (storage);
xfree (demangled_name);
- cp_demangled_name_parse_free (info);
return ret;
}
void *storage = NULL;
char *demangled_name = NULL, *ret;
struct demangle_component *ret_comp;
- struct demangle_parse_info *info;
+ std::unique_ptr<demangle_parse_info> info;
info = mangled_name_to_comp (physname, DMGL_ANSI,
&storage, &demangled_name);
xfree (storage);
xfree (demangled_name);
- cp_demangled_name_parse_free (info);
return ret;
}
{
char *ret;
struct demangle_component *ret_comp;
- struct demangle_parse_info *info;
+ std::unique_ptr<demangle_parse_info> info;
info = cp_demangled_name_to_comp (full_name, NULL);
if (!info)
if (ret_comp != NULL)
ret = cp_comp_to_string (ret_comp, 10);
- cp_demangled_name_parse_free (info);
return ret;
}
{
int done = 0;
struct demangle_component *ret_comp;
- struct demangle_parse_info *info;
+ std::unique_ptr<demangle_parse_info> info;
char *ret = NULL;
if (demangled_name == NULL)
if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
ret = cp_comp_to_string (d_left (ret_comp), 10);
- cp_demangled_name_parse_free (info);
return ret;
}
struct demangle_parse_info
{
+ demangle_parse_info ();
+
+ ~demangle_parse_info ();
+
/* The memory used during the parse. */
struct demangle_info *info;
/* Functions from cp-name-parser.y. */
-extern struct demangle_parse_info *cp_demangled_name_to_comp
+extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp
(const char *demangled_name, const char **errmsg);
extern char *cp_comp_to_string (struct demangle_component *result,
int estimated_len);
-extern void cp_demangled_name_parse_free (struct demangle_parse_info *);
-extern struct cleanup *make_cleanup_cp_demangled_name_parse_free
- (struct demangle_parse_info *);
extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
struct demangle_component *,
struct demangle_parse_info *);
-extern struct demangle_parse_info *cp_new_demangle_parse_info (void);
-
/* The list of "maint cplus" commands. */
extern struct cmd_list_element *maint_cplus_cmd_list;
{
int i;
struct demangle_component *demangled;
- struct demangle_parse_info *info = NULL;
+ std::unique_ptr<demangle_parse_info> info;
const char *err;
struct type *argtype;
struct cleanup *cleanup;
return NULL;
}
demangled = info->tree;
- cleanup = make_cleanup_cp_demangled_name_parse_free (info);
/* Strip off component names. */
while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
{
- do_cleanups (cleanup);
PyErr_SetString (PyExc_RuntimeError, _("Type is not a template."));
return NULL;
}
if (! demangled)
{
- do_cleanups (cleanup);
PyErr_Format (PyExc_RuntimeError, _("No argument %d in template."),
argno);
return NULL;
}
argtype = typy_lookup_type (demangled->u.s_binary.left, block);
- do_cleanups (cleanup);
if (! argtype)
return NULL;