diff options
author | Tom Tromey <tromey@adacore.com> | 2023-04-28 08:08:49 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-05-23 13:57:54 -0600 |
commit | b8c03634d6537ee7ad068ab840b6e78483aaca80 (patch) | |
tree | af65690289d5f6db975f3318064a830d3f95e8ca | |
parent | 562db568441ed0f7e258b843916c34572170cc6d (diff) | |
download | fsf-binutils-gdb-b8c03634d6537ee7ad068ab840b6e78483aaca80.zip fsf-binutils-gdb-b8c03634d6537ee7ad068ab840b6e78483aaca80.tar.gz fsf-binutils-gdb-b8c03634d6537ee7ad068ab840b6e78483aaca80.tar.bz2 |
Introduce and use parser flags
This patch adds a new parser_flags type and changes the parser APIs to
use it rather than a collection of 'int' and 'bool'. More flags will
be added in subsquent patches.
-rw-r--r-- | gdb/ax-gdb.c | 3 | ||||
-rw-r--r-- | gdb/breakpoint.c | 3 | ||||
-rw-r--r-- | gdb/eval.c | 3 | ||||
-rw-r--r-- | gdb/expression.h | 21 | ||||
-rw-r--r-- | gdb/parse.c | 29 | ||||
-rw-r--r-- | gdb/printcmd.c | 5 | ||||
-rw-r--r-- | gdb/tracepoint.c | 10 |
7 files changed, 48 insertions, 26 deletions
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 528f45e..927dfc6 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2615,7 +2615,8 @@ maint_agent_printf_command (const char *cmdrest, int from_tty) const char *cmd1; cmd1 = cmdrest; - expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0, 1); + expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0, + PARSER_COMMA_TERMINATES); argvec.push_back (expr.release ()); cmdrest = cmd1; if (*cmdrest == ',') diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 552b789..36e53c0 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2519,7 +2519,8 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) const char *cmd1; cmd1 = cmdrest; - expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); + expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), + PARSER_COMMA_TERMINATES); argvec.push_back (expr.release ()); cmdrest = cmd1; if (*cmdrest == ',') @@ -81,7 +81,8 @@ parse_and_eval (const char *exp) struct value * parse_to_comma_and_eval (const char **expp) { - expression_up expr = parse_exp_1 (expp, 0, nullptr, 1); + expression_up expr = parse_exp_1 (expp, 0, nullptr, + PARSER_COMMA_TERMINATES); return expr->evaluate (); } diff --git a/gdb/expression.h b/gdb/expression.h index 8d351b3..2e2d2a0 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -283,11 +283,27 @@ private: const struct block *m_innermost_block; }; +/* Flags that can affect the parsers. */ + +enum parser_flag +{ + /* This flag is set if the expression is being evaluated in a + context where a 'void' result type is expected. Parsers are free + to ignore this, or to use it to help with overload resolution + decisions. */ + PARSER_VOID_CONTEXT = (1 << 0), + + /* This flag is set if a top-level comma terminates the + expression. */ + PARSER_COMMA_TERMINATES = (1 << 1), +}; +DEF_ENUM_FLAGS_TYPE (enum parser_flag, parser_flags); + /* From parse.c */ extern expression_up parse_expression (const char *, innermost_block_tracker * = nullptr, - bool void_context_p = false); + parser_flags flags = 0); extern expression_up parse_expression_with_language (const char *string, enum language lang); @@ -314,7 +330,8 @@ extern expression_up parse_expression_for_completion (const char *, std::unique_ptr<expr_completion_base> *completer); extern expression_up parse_exp_1 (const char **, CORE_ADDR pc, - const struct block *, int, + const struct block *, + parser_flags flags, innermost_block_tracker * = nullptr); /* From eval.c */ diff --git a/gdb/parse.c b/gdb/parse.c index e4678e9..ed0d0b8 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -328,7 +328,7 @@ copy_name (struct stoken token) static expression_up parse_exp_in_context (const char **stringptr, CORE_ADDR pc, const struct block *block, - int comma, bool void_context_p, + parser_flags flags, innermost_block_tracker *tracker, std::unique_ptr<expr_completion_base> *completer) { @@ -398,8 +398,11 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, to the value matching SELECTED_FRAME as set by get_current_arch. */ parser_state ps (lang, get_current_arch (), expression_context_block, - expression_context_pc, comma, *stringptr, - completer != nullptr, tracker, void_context_p); + expression_context_pc, + (flags & PARSER_COMMA_TERMINATES) != 0, + *stringptr, + completer != nullptr, tracker, + (flags & PARSER_VOID_CONTEXT) != 0); scoped_restore_current_language lang_saver; set_language (lang->la_language); @@ -435,31 +438,25 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, if BLOCK is zero, use the block of the selected stack frame. Meanwhile, advance *STRINGPTR to point after the expression, at the first nonwhite character that is not part of the expression - (possibly a null character). - - If COMMA is nonzero, stop if a comma is reached. */ + (possibly a null character). FLAGS are passed to the parser. */ expression_up parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block, - int comma, innermost_block_tracker *tracker) + parser_flags flags, innermost_block_tracker *tracker) { - return parse_exp_in_context (stringptr, pc, block, comma, false, + return parse_exp_in_context (stringptr, pc, block, flags, tracker, nullptr); } /* Parse STRING as an expression, and complain if this fails to use up all of the contents of STRING. TRACKER, if non-null, will be - updated by the parser. VOID_CONTEXT_P should be true to indicate - that the expression may be expected to return a value with void - type. Parsers are free to ignore this, or to use it to help with - overload resolution decisions. */ + updated by the parser. FLAGS are passed to the parser. */ expression_up parse_expression (const char *string, innermost_block_tracker *tracker, - bool void_context_p) + parser_flags flags) { - expression_up exp = parse_exp_in_context (&string, 0, nullptr, 0, - void_context_p, + expression_up exp = parse_exp_in_context (&string, 0, nullptr, flags, tracker, nullptr); if (*string) error (_("Junk after end of expression.")); @@ -495,7 +492,7 @@ parse_expression_for_completion try { - exp = parse_exp_in_context (&string, 0, 0, 0, false, nullptr, completer); + exp = parse_exp_in_context (&string, 0, 0, 0, nullptr, completer); } catch (const gdb_exception_error &except) { diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 679a24e..ca0966b 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1315,7 +1315,10 @@ process_print_command_args (const char *args, value_print_options *print_opts, /* VOIDPRINT is true to indicate that we do want to print a void value, so invert it for parse_expression. */ - expression_up expr = parse_expression (exp, nullptr, !voidprint); + parser_flags flags = 0; + if (!voidprint) + flags = PARSER_VOID_CONTEXT; + expression_up expr = parse_expression (exp, nullptr, flags); return expr->evaluate (); } diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index ffda4a6..9e5ced1 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -680,7 +680,8 @@ validate_actionline (const char *line, struct breakpoint *b) { p = tmp_p; expression_up exp = parse_exp_1 (&p, loc->address, - block_for_pc (loc->address), 1); + block_for_pc (loc->address), + PARSER_COMMA_TERMINATES); if (exp->first_opcode () == OP_VAR_VALUE) { @@ -732,7 +733,8 @@ validate_actionline (const char *line, struct breakpoint *b) /* Only expressions are allowed for this action. */ expression_up exp = parse_exp_1 (&p, loc->address, - block_for_pc (loc->address), 1); + block_for_pc (loc->address), + PARSER_COMMA_TERMINATES); /* We have something to evaluate, make sure that the expr to bytecode translator can handle it and that it's not too @@ -1349,7 +1351,7 @@ encode_actions_1 (struct command_line *action, const char *exp_start = action_exp; expression_up exp = parse_exp_1 (&action_exp, tloc->address, block_for_pc (tloc->address), - 1); + PARSER_COMMA_TERMINATES); switch (exp->first_opcode ()) { @@ -1439,7 +1441,7 @@ encode_actions_1 (struct command_line *action, { expression_up exp = parse_exp_1 (&action_exp, tloc->address, block_for_pc (tloc->address), - 1); + PARSER_COMMA_TERMINATES); agent_expr_up aexpr = gen_eval_for_expr (tloc->address, exp.get ()); |