From: Tom Tromey Date: Fri, 28 Apr 2023 14:08:49 +0000 (-0600) Subject: Introduce and use parser flags X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b8c03634d6537ee7ad068ab840b6e78483aaca80;p=binutils-gdb.git 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. --- diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 528f45e19eb..927dfc6337e 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 552b789cba1..36e53c0c6a1 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 == ',') diff --git a/gdb/eval.c b/gdb/eval.c index 9d5ca0b47de..d8d53c28686 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -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 8d351b30a3a..2e2d2a090f9 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 *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 e4678e9c6e8..ed0d0b8a880 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 *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 679a24e665a..ca0966bebb9 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 ffda4a6439e..9e5ced1893e 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 ());