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 == ',')
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 == ',')
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 ();
}
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);
(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 */
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)
{
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);
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."));
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)
{
/* 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 ();
}
{
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)
{
/* 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
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 ())
{
{
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 ());