#define GDB_YY_REMAP_PREFIX cpname
#include "yy-remap.h"
-/* The components built by the parser are allocated ahead of time,
- and cached in this structure. */
-
-#define ALLOC_CHUNK 100
-
-struct demangle_info {
- int used;
- struct demangle_info *next;
- struct demangle_component comps[ALLOC_CHUNK];
-};
-
%}
%union
const char *lexptr, *prev_lexptr, *error_lexptr, *global_errmsg;
- struct demangle_info *demangle_info;
+ demangle_parse_info *demangle_info;
/* The parse tree created by the parser is stored here after a
successful parse. */
struct demangle_component *
cpname_state::d_grab ()
{
- struct demangle_info *more;
-
- if (demangle_info->used >= ALLOC_CHUNK)
- {
- if (demangle_info->next == NULL)
- {
- more = XNEW (struct demangle_info);
- more->next = NULL;
- demangle_info->next = more;
- }
- else
- more = demangle_info->next;
-
- more->used = 0;
- demangle_info = more;
- }
- return &demangle_info->comps[demangle_info->used++];
+ return obstack_new<demangle_component> (&demangle_info->obstack);
}
/* Flags passed to d_qualify. */
state->global_errmsg = msg ? msg : "parse error";
}
-/* Allocate a chunk of the components we'll need to build a tree. We
- generally allocate too many components, but the extra memory usage
- doesn't hurt because the trees are temporary and the storage is
- reused. More may be allocated later, by d_grab. */
-static struct demangle_info *
-allocate_info (void)
-{
- struct demangle_info *info = XNEW (struct demangle_info);
-
- info->next = NULL;
- info->used = 0;
- return info;
-}
-
/* See cp-support.h. */
gdb::unique_xmalloc_ptr<char>
return gdb::unique_xmalloc_ptr<char> (res);
}
-/* Destructor for demangle_parse_info. */
-
-demangle_parse_info::~demangle_parse_info ()
-{
- /* Free any allocated chunks of memory for the parse. */
- while (info != NULL)
- {
- struct demangle_info *next = info->next;
-
- free (info);
- info = next;
- }
-}
-
/* 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.
void
cp_merge_demangle_parse_infos (struct demangle_parse_info *dest,
struct demangle_component *target,
- struct demangle_parse_info *src)
+ std::unique_ptr<demangle_parse_info> src)
{
- struct demangle_info *di;
-
/* Copy the SRC's parse data into DEST. */
*target = *src->tree;
- di = dest->info;
- while (di->next != NULL)
- di = di->next;
- di->next = src->info;
-
- /* 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;
+
+ /* Make sure SRC is owned by DEST. */
+ dest->infos.push_back (std::move (src));
}
/* Convert a demangled name to a demangle_component tree. On success,
state.error_lexptr = NULL;
state.global_errmsg = NULL;
- state.demangle_info = allocate_info ();
-
auto result = std::make_unique<demangle_parse_info> ();
- result->info = state.demangle_info;
+ state.demangle_info = result.get ();
if (yyparse (&state))
{
struct demangle_parse_info
{
- demangle_parse_info () = default;
-
- ~demangle_parse_info ();
-
- /* The memory used during the parse. */
- struct demangle_info *info = nullptr;
-
/* The result of the parse. */
struct demangle_component *tree = nullptr;
- /* Any temporary memory used during typedef replacement. */
+ /* Any memory used during processing. */
auto_obstack obstack;
+
+ /* Any other objects referred to by this object, and whose storage
+ lifetime must be linked. */
+ std::vector<std::unique_ptr<demangle_parse_info>> infos;
};
extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
struct demangle_component *,
- struct demangle_parse_info *);
+ std::unique_ptr<demangle_parse_info>);
/* The list of "maint cplus" commands. */