Use new+delete for struct expression

In another series I'm working on, it is necessary to manage
"struct expression" with new and delete.  Because the patch is
straightforward and could be extracted, I've done so here.

gdb/ChangeLog
2020-12-01  Tom Tromey  <tom@tromey.com>

	* parse.c (expr_builder::expr_builder): Initialize expout.
	(expr_builder::release): Use expression::resize.
	(expression::expression, expression::~expression)
	(expression::resize): New methods.
	(write_exp_elt): Use expression::resize.
	(prefixify_expression): Update.
	(increase_expout_size): Use expression::resize.
	* expression.h (struct expression): Add constructor, destructor.
	<resize>: New method.
	(expression_up): Change type.
This commit is contained in:
Tom Tromey 2020-12-01 17:22:05 -07:00
parent e89b3d5293
commit 77bf7e9911
3 changed files with 56 additions and 29 deletions

View file

@ -93,15 +93,22 @@ union exp_element
};
struct expression
{
const struct language_defn *language_defn; /* language it was
entered in. */
struct gdbarch *gdbarch; /* architecture it was parsed in. */
int nelts;
union exp_element elts[1];
};
{
expression (const struct language_defn *, struct gdbarch *, size_t);
~expression ();
DISABLE_COPY_AND_ASSIGN (expression);
typedef gdb::unique_xmalloc_ptr<expression> expression_up;
void resize (size_t);
/* Language it was entered in. */
const struct language_defn *language_defn;
/* Architecture it was parsed in. */
struct gdbarch *gdbarch;
int nelts = 0;
union exp_element *elts;
};
typedef std::unique_ptr<expression> expression_up;
/* Macros for converting between number of expression elements and bytes
to store that many expression elements. */