I wanted to change rust-parse.c to use string_view and not stoken.
This was simple enough, but it seemed good to also change
parser_state::push_dollar to use string_view; and as it turned out,
this simplified the code a little.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
void
parser_state::push_dollar (struct stoken str)
+{
+ push_dollar (std::string_view (str.ptr, str.length));
+}
+
+/* See parser-defs.h. */
+
+void
+parser_state::push_dollar (std::string_view str)
{
struct block_symbol sym;
struct internalvar *isym = NULL;
- std::string copy;
/* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
and $$digits (equivalent to $<-digits> if you could type that). */
int i = 1;
/* Double dollar means negate the number and add -1 as well.
Thus $$ alone means -1. */
- if (str.length >= 2 && str.ptr[1] == '$')
+ if (str.length () >= 2 && str[1] == '$')
{
negate = 1;
i = 2;
}
- if (i == str.length)
+ if (i == str.length ())
{
/* Just dollars (one or two). */
i = -negate;
return;
}
/* Is the rest of the token digits? */
- for (; i < str.length; i++)
- if (!(str.ptr[i] >= '0' && str.ptr[i] <= '9'))
+ for (; i < str.length (); i++)
+ if (!(str[i] >= '0' && str[i] <= '9'))
break;
- if (i == str.length)
+ if (i == str.length ())
{
- i = atoi (str.ptr + 1 + negate);
+ i = atoi (&str[1 + negate]);
if (negate)
i = -i;
push_new<expr::last_operation> (i);
/* Handle tokens that refer to machine registers:
$ followed by a register name. */
- i = user_reg_map_name_to_regnum (gdbarch (),
- { str.ptr + 1, size_t (str.length - 1) });
+ i = user_reg_map_name_to_regnum (gdbarch (), str.substr (1));
if (i >= 0)
{
- str.length--;
- str.ptr++;
- push_new<expr::register_operation> (copy_name (str));
+ push_new<expr::register_operation> (std::string (str.substr (1)));
block_tracker->update (expression_context_block,
INNERMOST_BLOCK_FOR_REGISTERS);
return;
/* Any names starting with $ are probably debugger internal variables. */
- copy = copy_name (str);
+ std::string copy (str);
isym = lookup_only_internalvar (copy.c_str () + 1);
if (isym)
{
symbol. */
void push_symbol (const char *name, block_symbol sym);
+ /* Push a reference to $mumble. This may result in a convenience
+ variable, a history reference, or a register. */
+ void push_dollar (std::string_view str);
+
/* Push a reference to $mumble. This may result in a convenience
variable, a history reference, or a register. */
void push_dollar (struct stoken str);
/* Return the token's string value as a string. */
std::string get_string () const
{
- return std::string (current_string_val.ptr, current_string_val.length);
+ return std::string (current_string_val);
}
/* Storage for use while parsing. */
/* The current token's payload, if any. */
typed_val_int current_int_val {};
typed_val_float current_float_val {};
- struct stoken current_string_val {};
+ std::string_view current_string_val;
enum exp_opcode current_opcode = OP_NULL;
/* When completing, this may be set to the field operation to
}
}
- current_string_val.length = obstack_object_size (&obstack);
- current_string_val.ptr = (const char *) obstack_finish (&obstack);
+ size_t size = obstack_object_size (&obstack);
+ current_string_val = { (const char *) obstack_finish (&obstack), size };
return is_byte ? BYTESTRING : STRING;
}
}
if (token == NULL || (pstate->parse_completion && pstate->lexptr[0] == '\0'))
- {
- current_string_val.length = length;
- current_string_val.ptr = start;
- }
+ current_string_val = { start, length };
if (pstate->parse_completion && pstate->lexptr[0] == '\0')
{
{
if (pstate->parse_completion)
{
- current_string_val.length =0;
- current_string_val.ptr = "";
+ current_string_val = "";
return COMPLETE;
}
return 0;
std::vector<std::pair<std::string, operation_up>> field_v;
- size_t len = current_string_val.length;
+ size_t len = current_string_val.length ();
operation_up str = make_operation<string_operation> (get_string ());
operation_up addr
= make_operation<rust_unop_addr_operation> (std::move (str));