aboutsummaryrefslogtreecommitdiff
path: root/gdb/parse.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-11-22 21:45:53 -0700
committerTom Tromey <tom@tromey.com>2017-12-30 17:05:37 -0700
commite9d9f57e11db6427db347bc5b9b100071355e63f (patch)
treeb431b37b9a20e1a406b30be36aee0f36489ef5ec /gdb/parse.c
parenta594729cfb10457e0046359d2dde0c28b4185449 (diff)
downloadgdb-e9d9f57e11db6427db347bc5b9b100071355e63f.zip
gdb-e9d9f57e11db6427db347bc5b9b100071355e63f.tar.gz
gdb-e9d9f57e11db6427db347bc5b9b100071355e63f.tar.bz2
C++-ify parser_state
This mildly C++-ifies parser_state and stap_parse_info -- just enough to remove some cleanups. This version includes the changes implemented by Simon. Regression tested by the buildbot. gdb/ChangeLog 2017-12-30 Tom Tromey <tom@tromey.com> Simon Marchi <simon.marchi@ericsson.com> * stap-probe.h (struct stap_parse_info): Add constructor, destructor. * stap-probe.c (stap_parse_argument): Update. * rust-exp.y (rust_lex_tests): Update. * parser-defs.h (struct parser_state): Add constructor, destructor, release method. <expout>: Change type to expression_up. (null_post_parser): Change type. (initialize_expout, reallocate_expout): Remove. * parse.c (parser_state::parser_state): Rename from initialize_expout. (parser_state::release): Rename from reallocate_expout. (write_exp_elt, parse_exp_in_context_1, increase_expout_size): Update. (null_post_parser): Change type of "exp". * dtrace-probe.c (dtrace_probe::build_arg_exprs): Update. * ada-lang.c (resolve, resolve_subexp) (replace_operator_with_call): Change type of "expp". * language.h (struct language_defn) <la_post_parser>: Change type of "expp".
Diffstat (limited to 'gdb/parse.c')
-rw-r--r--gdb/parse.c77
1 files changed, 37 insertions, 40 deletions
diff --git a/gdb/parse.c b/gdb/parse.c
index dff519b..127ce7f 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -152,34 +152,32 @@ end_arglist (void)
/* See definition in parser-defs.h. */
-void
-initialize_expout (struct parser_state *ps, size_t initial_size,
- const struct language_defn *lang,
- struct gdbarch *gdbarch)
+parser_state::parser_state (size_t initial_size,
+ const struct language_defn *lang,
+ struct gdbarch *gdbarch)
+ : expout_size (initial_size),
+ expout (XNEWVAR (expression,
+ (sizeof (expression)
+ + EXP_ELEM_TO_BYTES (expout_size)))),
+ expout_ptr (0)
{
- ps->expout_size = initial_size;
- ps->expout_ptr = 0;
- ps->expout
- = (struct expression *) xmalloc (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size));
- ps->expout->language_defn = lang;
- ps->expout->gdbarch = gdbarch;
+ expout->language_defn = lang;
+ expout->gdbarch = gdbarch;
}
-/* See definition in parser-defs.h. */
-
-void
-reallocate_expout (struct parser_state *ps)
+expression_up
+parser_state::release ()
{
/* Record the actual number of expression elements, and then
reallocate the expression memory so that we free up any
excess elements. */
- ps->expout->nelts = ps->expout_ptr;
- ps->expout = (struct expression *)
- xrealloc (ps->expout,
- sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_ptr));
+ expout->nelts = expout_ptr;
+ expout.reset (XRESIZEVAR (expression, expout.release (),
+ (sizeof (expression)
+ + EXP_ELEM_TO_BYTES (expout_ptr))));
+
+ return std::move (expout);
}
/* This page contains the functions for adding data to the struct expression
@@ -196,9 +194,9 @@ write_exp_elt (struct parser_state *ps, const union exp_element *expelt)
if (ps->expout_ptr >= ps->expout_size)
{
ps->expout_size *= 2;
- ps->expout = (struct expression *)
- xrealloc (ps->expout, sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size));
+ ps->expout.reset (XRESIZEVAR (expression, ps->expout.release (),
+ (sizeof (expression)
+ + EXP_ELEM_TO_BYTES (ps->expout_size))));
}
ps->expout->elts[ps->expout_ptr++] = *expelt;
}
@@ -1116,7 +1114,6 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
int comma, int void_context_p, int *out_subexp)
{
const struct language_defn *lang = NULL;
- struct parser_state ps;
int subexp;
lexptr = *stringptr;
@@ -1192,7 +1189,7 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
and others called from *.y) ensure CURRENT_LANGUAGE gets restored
to the value matching SELECTED_FRAME as set by get_current_arch. */
- initialize_expout (&ps, 10, lang, get_current_arch ());
+ parser_state ps (10, lang, get_current_arch ());
scoped_restore_current_language lang_saver;
set_language (lang->la_language);
@@ -1205,33 +1202,32 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
CATCH (except, RETURN_MASK_ALL)
{
if (! parse_completion)
- {
- xfree (ps.expout);
- throw_exception (except);
- }
+ throw_exception (except);
}
END_CATCH
- reallocate_expout (&ps);
+ /* We have to operate on an "expression *", due to la_post_parser,
+ which explains this funny-looking double release. */
+ expression_up result = ps.release ();
/* Convert expression from postfix form as generated by yacc
parser, to a prefix form. */
if (expressiondebug)
- dump_raw_expression (ps.expout, gdb_stdlog,
+ dump_raw_expression (result.get (), gdb_stdlog,
"before conversion to prefix form");
- subexp = prefixify_expression (ps.expout);
+ subexp = prefixify_expression (result.get ());
if (out_subexp)
*out_subexp = subexp;
- lang->la_post_parser (&ps.expout, void_context_p);
+ lang->la_post_parser (&result, void_context_p);
if (expressiondebug)
- dump_prefix_expression (ps.expout, gdb_stdlog);
+ dump_prefix_expression (result.get (), gdb_stdlog);
*stringptr = lexptr;
- return expression_up (ps.expout);
+ return result;
}
/* Parse STRING as an expression, and complain if this fails
@@ -1320,7 +1316,7 @@ parse_expression_for_completion (const char *string, char **name,
/* A post-parser that does nothing. */
void
-null_post_parser (struct expression **exp, int void_context_p)
+null_post_parser (expression_up *exp, int void_context_p)
{
}
@@ -1866,10 +1862,11 @@ increase_expout_size (struct parser_state *ps, size_t lenelt)
if ((ps->expout_ptr + lenelt) >= ps->expout_size)
{
ps->expout_size = std::max (ps->expout_size * 2,
- ps->expout_ptr + lenelt + 10);
- ps->expout = (struct expression *)
- xrealloc (ps->expout, (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size)));
+ ps->expout_ptr + lenelt + 10);
+ ps->expout.reset (XRESIZEVAR (expression,
+ ps->expout.release (),
+ (sizeof (struct expression)
+ + EXP_ELEM_TO_BYTES (ps->expout_size))));
}
}