+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.
+
2020-12-01 Rogerio A. Cardoso <rcardoso@linux.ibm.com>
* ppc-linux-nat.c: (PPC_DEBUG_FEATURE_DATA_BP_ARCH_31): New define.
(region_ok_for_hw_watchpoint): Check if 2nd DAWR is avaliable before
};
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);
+
+ 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 gdb::unique_xmalloc_ptr<expression> expression_up;
+typedef std::unique_ptr<expression> expression_up;
/* Macros for converting between number of expression elements and bytes
to store that many expression elements. */
expr_builder::expr_builder (const struct language_defn *lang,
struct gdbarch *gdbarch)
: expout_size (10),
- expout (XNEWVAR (expression,
- (sizeof (expression)
- + EXP_ELEM_TO_BYTES (expout_size)))),
+ expout (new expression (lang, gdbarch, expout_size)),
expout_ptr (0)
{
- expout->language_defn = lang;
- expout->gdbarch = gdbarch;
}
expression_up
excess elements. */
expout->nelts = expout_ptr;
- expout.reset (XRESIZEVAR (expression, expout.release (),
- (sizeof (expression)
- + EXP_ELEM_TO_BYTES (expout_ptr))));
+ expout->resize (expout_ptr);
return std::move (expout);
}
+expression::expression (const struct language_defn *lang, struct gdbarch *arch,
+ size_t n)
+ : language_defn (lang),
+ gdbarch (arch),
+ elts (nullptr)
+{
+ resize (n);
+}
+
+expression::~expression ()
+{
+ xfree (elts);
+}
+
+void
+expression::resize (size_t n)
+{
+ elts = XRESIZEVAR (union exp_element, elts, EXP_ELEM_TO_BYTES (n));
+}
+
/* This page contains the functions for adding data to the struct expression
being constructed. */
if (ps->expout_ptr >= ps->expout_size)
{
ps->expout_size *= 2;
- ps->expout.reset (XRESIZEVAR (expression, ps->expout.release (),
- (sizeof (expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size))));
+ ps->expout->resize (ps->expout_size);
}
ps->expout->elts[ps->expout_ptr++] = *expelt;
}
prefixify_expression (struct expression *expr, int last_struct)
{
gdb_assert (expr->nelts > 0);
- int len = sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts);
- struct expression *temp;
+ int len = EXP_ELEM_TO_BYTES (expr->nelts);
+ struct expression temp (expr->language_defn, expr->gdbarch, expr->nelts);
int inpos = expr->nelts, outpos = 0;
- temp = (struct expression *) alloca (len);
-
/* Copy the original expression into temp. */
- memcpy (temp, expr, len);
+ memcpy (temp.elts, expr->elts, len);
- return prefixify_subexp (temp, expr, inpos, outpos, last_struct);
+ return prefixify_subexp (&temp, expr, inpos, outpos, last_struct);
}
/* Return the number of exp_elements in the postfix subexpression
{
ps->expout_size = std::max (ps->expout_size * 2,
ps->expout_ptr + lenelt + 10);
- ps->expout.reset (XRESIZEVAR (expression,
- ps->expout.release (),
- (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size))));
+ ps->expout->resize (ps->expout_size);
}
}