aboutsummaryrefslogtreecommitdiff
path: root/gdb/go-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-04-07 15:29:58 -0600
committerTom Tromey <tom@tromey.com>2019-04-19 14:10:23 -0600
commit61f4b350419e91560be94e0671a760b2e4902c65 (patch)
treef1cc08b31b813c81d730ccd69974772d82cbcd12 /gdb/go-exp.y
parent189b8c2e104017600104457b97315da74a22f549 (diff)
downloadgdb-61f4b350419e91560be94e0671a760b2e4902c65.zip
gdb-61f4b350419e91560be94e0671a760b2e4902c65.tar.gz
gdb-61f4b350419e91560be94e0671a760b2e4902c65.tar.bz2
Make copy_name return std::string
This changes copy_name to return a std::string, updating all the callers. In some cases, an extra copy was removed. This also required a little bit of constification. Tested by the buildbot. gdb/ChangeLog 2019-04-19 Tom Tromey <tom@tromey.com> * type-stack.h (struct type_stack) <insert>: Constify string. * type-stack.c (type_stack::insert): Constify string. * gdbtypes.h (lookup_template_type): Update. (address_space_name_to_int): Update. * gdbtypes.c (address_space_name_to_int): Make space_identifier const. (lookup_template_type): Make name const. * c-exp.y: Update rules. (lex_one_token, classify_name, classify_inner_name) (c_print_token): Update. * p-exp.y: Update rules. (yylex): Update. * f-exp.y: Update rules. (yylex): Update. * d-exp.y: Update rules. (lex_one_token, classify_name, classify_inner_name): Update. * parse.c (write_dollar_variable, copy_name): Return std::string. * parser-defs.h (copy_name): Change return type. * m2-exp.y: Update rules. (yylex): Update. * go-exp.y (lex_one_token): Update. Update rules. (classify_unsafe_function, classify_packaged_name) (classify_name, yylex): Update.
Diffstat (limited to 'gdb/go-exp.y')
-rw-r--r--gdb/go-exp.y45
1 files changed, 20 insertions, 25 deletions
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 0084b2f..ad17411 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -538,7 +538,7 @@ variable: name_not_typename ENTRY
|| !symbol_read_needs_frame (sym))
error (_("@entry can be used only for function "
"parameters, not for \"%s\""),
- copy_name ($1.stoken));
+ copy_name ($1.stoken).c_str ());
write_exp_elt_opcode (pstate, OP_VAR_ENTRY_VALUE);
write_exp_elt_sym (pstate, sym);
@@ -568,10 +568,10 @@ variable: name_not_typename
else
{
struct bound_minimal_symbol msymbol;
- char *arg = copy_name ($1.stoken);
+ std::string arg = copy_name ($1.stoken);
msymbol =
- lookup_bound_minimal_symbol (arg);
+ lookup_bound_minimal_symbol (arg.c_str ());
if (msymbol.minsym != NULL)
write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols ()
@@ -580,7 +580,7 @@ variable: name_not_typename
"Use the \"file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- copy_name ($1.stoken));
+ arg.c_str ());
}
}
;
@@ -1014,7 +1014,6 @@ lex_one_token (struct parser_state *par_state)
unsigned int i;
const char *tokstart;
int saw_structop = last_was_structop;
- char *copy;
last_was_structop = 0;
@@ -1263,9 +1262,9 @@ lex_one_token (struct parser_state *par_state)
yylval.sval.length = namelen;
/* Catch specific keywords. */
- copy = copy_name (yylval.sval);
+ std::string copy = copy_name (yylval.sval);
for (i = 0; i < sizeof (ident_tokens) / sizeof (ident_tokens[0]); i++)
- if (strcmp (copy, ident_tokens[i].oper) == 0)
+ if (copy == ident_tokens[i].oper)
{
/* It is ok to always set this, even though we don't always
strictly need to. */
@@ -1347,15 +1346,15 @@ package_name_p (const char *name, const struct block *block)
static int
classify_unsafe_function (struct stoken function_name)
{
- char *copy = copy_name (function_name);
+ std::string copy = copy_name (function_name);
- if (strcmp (copy, "Sizeof") == 0)
+ if (copy == "Sizeof")
{
yylval.sval = function_name;
return SIZEOF_KEYWORD;
}
- error (_("Unknown function in `unsafe' package: %s"), copy);
+ error (_("Unknown function in `unsafe' package: %s"), copy.c_str ());
}
/* Classify token(s) "name1.name2" where name1 is known to be a package.
@@ -1367,13 +1366,12 @@ classify_unsafe_function (struct stoken function_name)
static int
classify_packaged_name (const struct block *block)
{
- char *copy;
struct block_symbol sym;
struct field_of_this_result is_a_field_of_this;
- copy = copy_name (yylval.sval);
+ std::string copy = copy_name (yylval.sval);
- sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+ sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
if (sym.symbol)
{
@@ -1397,15 +1395,14 @@ classify_name (struct parser_state *par_state, const struct block *block)
{
struct type *type;
struct block_symbol sym;
- char *copy;
struct field_of_this_result is_a_field_of_this;
- copy = copy_name (yylval.sval);
+ std::string copy = copy_name (yylval.sval);
/* Try primitive types first so they win over bad/weird debug info. */
type = language_lookup_primitive_type (par_state->language (),
par_state->gdbarch (),
- copy);
+ copy.c_str ());
if (type != NULL)
{
/* NOTE: We take advantage of the fact that yylval coming in was a
@@ -1417,7 +1414,7 @@ classify_name (struct parser_state *par_state, const struct block *block)
/* TODO: What about other types? */
- sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+ sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
if (sym.symbol)
{
@@ -1439,7 +1436,7 @@ classify_name (struct parser_state *par_state, const struct block *block)
struct stoken sval =
build_packaged_name (current_package_name,
strlen (current_package_name),
- copy, strlen (copy));
+ copy.c_str (), copy.size ());
xfree (current_package_name);
sym = lookup_symbol (sval.ptr, block, VAR_DOMAIN,
@@ -1461,8 +1458,8 @@ classify_name (struct parser_state *par_state, const struct block *block)
|| (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))
{
YYSTYPE newlval; /* Its value is ignored. */
- int hextype = parse_number (par_state, copy, yylval.sval.length,
- 0, &newlval);
+ int hextype = parse_number (par_state, copy.c_str (),
+ yylval.sval.length, 0, &newlval);
if (hextype == INT)
{
yylval.ssym.sym.symbol = NULL;
@@ -1521,17 +1518,15 @@ yylex (void)
if (name2.token == NAME)
{
/* Ok, we have "name1 . name2". */
- char *copy;
+ std::string copy = copy_name (current.value.sval);
- copy = copy_name (current.value.sval);
-
- if (strcmp (copy, "unsafe") == 0)
+ if (copy == "unsafe")
{
popping = 1;
return classify_unsafe_function (name2.value.sval);
}
- if (package_name_p (copy, pstate->expression_context_block))
+ if (package_name_p (copy.c_str (), pstate->expression_context_block))
{
popping = 1;
yylval.sval = build_packaged_name (current.value.sval.ptr,