+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.
+
2019-04-19 Sergei Trofimovich <siarheit@google.com>
* configure.ac: add --enable-source-highlight switch.
{
CORE_ADDR theclass;
+ std::string copy = copy_name ($2.stoken);
theclass = lookup_objc_class (pstate->gdbarch (),
- copy_name ($2.stoken));
+ copy.c_str ());
if (theclass == 0)
error (_("%s is not an ObjC Class"),
- copy_name ($2.stoken));
+ copy.c_str ());
write_exp_elt_opcode (pstate, OP_LONG);
write_exp_elt_type (pstate,
- parse_type (pstate)->builtin_int);
+ parse_type (pstate)->builtin_int);
write_exp_elt_longcst (pstate, (LONGEST) theclass);
write_exp_elt_opcode (pstate, OP_LONG);
start_msglist();
$$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
else
error (_("No file or function \"%s\"."),
- copy_name ($1.stoken));
+ copy_name ($1.stoken).c_str ());
}
| FILENAME
{
;
block : block COLONCOLON name
- { struct symbol *tem
- = lookup_symbol (copy_name ($3), $1,
+ {
+ std::string copy = copy_name ($3);
+ struct symbol *tem
+ = lookup_symbol (copy.c_str (), $1,
VAR_DOMAIN, NULL).symbol;
if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
error (_("No function \"%s\" in specified context."),
- copy_name ($3));
+ copy.c_str ());
$$ = SYMBOL_BLOCK_VALUE (tem); }
;
|| !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);
;
variable: block COLONCOLON name
- { struct block_symbol sym
- = lookup_symbol (copy_name ($3), $1,
+ {
+ std::string copy = copy_name ($3);
+ struct block_symbol sym
+ = lookup_symbol (copy.c_str (), $1,
VAR_DOMAIN, NULL);
if (sym.symbol == 0)
error (_("No symbol \"%s\" in specified context."),
- copy_name ($3));
+ copy.c_str ());
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
}
| TYPENAME COLONCOLON name COLONCOLON name
{
- char *copy = copy_name ($3);
+ std::string copy = copy_name ($3);
error (_("No type \"%s\" within class "
"or namespace \"%s\"."),
- copy, TYPE_SAFE_NAME ($1.type));
+ copy.c_str (), TYPE_SAFE_NAME ($1.type));
}
;
variable: qualified_name
| COLONCOLON name_not_typename
{
- char *name = copy_name ($2.stoken);
+ std::string name = copy_name ($2.stoken);
struct symbol *sym;
struct bound_minimal_symbol msymbol;
sym
- = lookup_symbol (name, (const struct block *) NULL,
+ = lookup_symbol (name.c_str (),
+ (const struct block *) NULL,
VAR_DOMAIN, NULL).symbol;
if (sym)
{
break;
}
- msymbol = lookup_bound_minimal_symbol (name);
+ msymbol = lookup_bound_minimal_symbol (name.c_str ());
if (msymbol.minsym != NULL)
write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
else
- error (_("No symbol \"%s\" in current context."), name);
+ error (_("No symbol \"%s\" in current context."),
+ name.c_str ());
}
;
}
else
{
- char *arg = copy_name ($1.stoken);
+ std::string arg = copy_name ($1.stoken);
bound_minimal_symbol msymbol
- = lookup_bound_minimal_symbol (arg);
+ = lookup_bound_minimal_symbol (arg.c_str ());
if (msymbol.minsym == NULL)
{
if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- copy_name ($1.stoken));
+ arg.c_str ());
}
/* This minsym might be an alias for
space_identifier : '@' NAME
{
- cpstate->type_stack.insert (pstate, copy_name ($2.stoken));
+ cpstate->type_stack.insert (pstate,
+ copy_name ($2.stoken).c_str ());
}
;
0); }
| STRUCT name
{ $$
- = lookup_struct (copy_name ($2),
+ = lookup_struct (copy_name ($2).c_str (),
pstate->expression_context_block);
}
| STRUCT COMPLETE
}
| CLASS name
{ $$ = lookup_struct
- (copy_name ($2), pstate->expression_context_block);
+ (copy_name ($2).c_str (),
+ pstate->expression_context_block);
}
| CLASS COMPLETE
{
}
| UNION name
{ $$
- = lookup_union (copy_name ($2),
+ = lookup_union (copy_name ($2).c_str (),
pstate->expression_context_block);
}
| UNION COMPLETE
$$ = NULL;
}
| ENUM name
- { $$ = lookup_enum (copy_name ($2),
+ { $$ = lookup_enum (copy_name ($2).c_str (),
pstate->expression_context_block);
}
| ENUM COMPLETE
in the token processing code in yylex. */
| TEMPLATE name '<' type '>'
{ $$ = lookup_template_type
- (copy_name($2), $4,
+ (copy_name($2).c_str (), $4,
pstate->expression_context_block);
}
| const_or_volatile_or_space_identifier_noopt typebase
unsigned int i;
const char *tokstart;
bool saw_structop = last_was_structop;
- char *copy;
last_was_structop = false;
*is_quoted_name = false;
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)
{
if ((ident_tokens[i].flags & FLAG_CXX) != 0
&& par_state->language ()->la_language != language_cplus)
{
struct field_of_this_result is_a_field_of_this;
- if (lookup_symbol (copy,
+ if (lookup_symbol (copy.c_str (),
pstate->expression_context_block,
VAR_DOMAIN,
(par_state->language ()->la_language
bool is_quoted_name, bool is_after_structop)
{
struct block_symbol bsym;
- char *copy;
struct field_of_this_result is_a_field_of_this;
- copy = copy_name (yylval.sval);
+ std::string copy = copy_name (yylval.sval);
/* Initialize this in case we *don't* use it in this call; that way
we can refer to it unconditionally below. */
memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
- bsym = lookup_symbol (copy, block, VAR_DOMAIN,
+ bsym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN,
par_state->language ()->la_name_of_this
? &is_a_field_of_this : NULL);
{
struct field_of_this_result inner_is_a_field_of_this;
- bsym = lookup_symbol (copy, block, STRUCT_DOMAIN,
+ bsym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN,
&inner_is_a_field_of_this);
if (bsym.symbol != NULL)
{
/* See if it's a file name. */
struct symtab *symtab;
- symtab = lookup_symtab (copy);
+ symtab = lookup_symtab (copy.c_str ());
if (symtab)
{
yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab),
/* See if it's an ObjC classname. */
if (par_state->language ()->la_language == language_objc && !bsym.symbol)
{
- CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (), copy);
+ CORE_ADDR Class = lookup_objc_class (par_state->gdbarch (),
+ copy.c_str ());
if (Class)
{
struct symbol *sym;
yylval.theclass.theclass = Class;
- sym = lookup_struct_typedef (copy,
+ sym = lookup_struct_typedef (copy.c_str (),
par_state->expression_context_block, 1);
if (sym)
yylval.theclass.type = SYMBOL_TYPE (sym);
|| (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,
+ int hextype = parse_number (par_state, copy.c_str (), yylval.sval.length,
0, &newlval);
if (hextype == INT)
if (bsym.symbol == NULL
&& par_state->language ()->la_language == language_cplus
&& is_a_field_of_this.type == NULL
- && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL)
+ && lookup_minimal_symbol (copy.c_str (), NULL, NULL).minsym == NULL)
return UNKNOWN_CPP_NAME;
return NAME;
const struct block *block, struct type *context)
{
struct type *type;
- char *copy;
if (context == NULL)
return classify_name (par_state, block, false, false);
if (!type_aggregate_p (type))
return ERROR;
- copy = copy_name (yylval.ssym.stoken);
+ std::string copy = copy_name (yylval.ssym.stoken);
/* N.B. We assume the symbol can only be in VAR_DOMAIN. */
- yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block, VAR_DOMAIN);
+ yylval.ssym.sym = cp_lookup_nested_symbol (type, copy.c_str (), block,
+ VAR_DOMAIN);
/* If no symbol was found, search for a matching base class named
COPY. This will allow users to enter qualified names of class members
relative to the `this' pointer. */
if (yylval.ssym.sym.symbol == NULL)
{
- struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
+ struct type *base_type = cp_find_type_baseclass_by_name (type,
+ copy.c_str ());
if (base_type != NULL)
{
named COPY when we really wanted a base class of the same name.
Double-check this case by looking for a base class. */
{
- struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
+ struct type *base_type
+ = cp_find_type_baseclass_by_name (type, copy.c_str ());
if (base_type != NULL)
{
case NSSTRING:
case DOLLAR_VARIABLE:
- parser_fprintf (file, "sval<%s>", copy_name (value.sval));
+ parser_fprintf (file, "sval<%s>", copy_name (value.sval).c_str ());
break;
case TYPENAME:
parser_fprintf (file, "tsym<type=%s, name=%s>",
TYPE_SAFE_NAME (value.tsym.type),
- copy_name (value.tsym.stoken));
+ copy_name (value.tsym.stoken).c_str ());
break;
case NAME:
case NAME_OR_INT:
case BLOCKNAME:
parser_fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>",
- copy_name (value.ssym.stoken),
+ copy_name (value.ssym.stoken).c_str (),
(value.ssym.sym.symbol == NULL
? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym.symbol)),
value.ssym.is_a_field_of_this);
{ /* Do nothing. */ }
| IdentifierExp
{ struct bound_minimal_symbol msymbol;
- char *copy = copy_name ($1);
+ std::string copy = copy_name ($1);
struct field_of_this_result is_a_field_of_this;
struct block_symbol sym;
/* Handle VAR, which could be local or global. */
- sym = lookup_symbol (copy, pstate->expression_context_block,
+ sym = lookup_symbol (copy.c_str (),
+ pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this);
if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
{
else
{
/* Lookup foreign name in global static symbols. */
- msymbol = lookup_bound_minimal_symbol (copy);
+ msymbol = lookup_bound_minimal_symbol (copy.c_str ());
if (msymbol.minsym != NULL)
write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command"));
else
- error (_("No symbol \"%s\" in current context."), copy);
+ error (_("No symbol \"%s\" in current context."),
+ copy.c_str ());
}
}
| TypeExp '.' IdentifierExp
unsigned int i;
const char *tokstart;
int saw_structop = last_was_structop;
- char *copy;
last_was_structop = 0;
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. */
yylval.tsym.type
= language_lookup_primitive_type (par_state->language (),
- par_state->gdbarch (), copy);
+ par_state->gdbarch (), copy.c_str ());
if (yylval.tsym.type != NULL)
return TYPENAME;
classify_name (struct parser_state *par_state, const struct block *block)
{
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);
- 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 && SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF)
{
yylval.tsym.type = SYMBOL_TYPE (sym.symbol);
else if (sym.symbol == NULL)
{
/* Look-up first for a module name, then a type. */
- sym = lookup_symbol (copy, block, MODULE_DOMAIN, NULL);
+ sym = lookup_symbol (copy.c_str (), block, MODULE_DOMAIN, NULL);
if (sym.symbol == NULL)
- sym = lookup_symbol (copy, block, STRUCT_DOMAIN, NULL);
+ sym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN, NULL);
if (sym.symbol != NULL)
{
const struct block *block, struct type *context)
{
struct type *type;
- char *copy;
if (context == NULL)
return classify_name (par_state, block);
if (!type_aggregate_p (type))
return ERROR;
- copy = copy_name (yylval.ssym.stoken);
- yylval.ssym.sym = d_lookup_nested_symbol (type, copy, block);
+ std::string copy = copy_name (yylval.ssym.stoken);
+ yylval.ssym.sym = d_lookup_nested_symbol (type, copy.c_str (), block);
if (yylval.ssym.sym.symbol == NULL)
return ERROR;
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 () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- copy_name ($1.stoken));
+ arg.c_str ());
}
}
;
currently as names of types; NAME for other symbols.
The caller is not constrained to care about the distinction. */
{
- char *tmp = copy_name (yylval.sval);
+ std::string tmp = copy_name (yylval.sval);
struct block_symbol result;
struct field_of_this_result is_a_field_of_this;
enum domain_enum_tag lookup_domains[] =
way we can refer to it unconditionally below. */
memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
- result = lookup_symbol (tmp, pstate->expression_context_block,
+ result = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
lookup_domains[i],
pstate->language ()->la_language
== language_cplus
yylval.tsym.type
= language_lookup_primitive_type (pstate->language (),
- pstate->gdbarch (), tmp);
+ pstate->gdbarch (), tmp.c_str ());
if (yylval.tsym.type != NULL)
return TYPENAME;
return the integer flag defined in gdbtypes.h. */
int
-address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
+address_space_name_to_int (struct gdbarch *gdbarch,
+ const char *space_identifier)
{
int type_flags;
visible in lexical block BLOCK. */
struct type *
-lookup_template_type (char *name, struct type *type,
+lookup_template_type (const char *name, struct type *type,
const struct block *block)
{
struct symbol *sym;
extern void replace_type (struct type *, struct type *);
-extern int address_space_name_to_int (struct gdbarch *, char *);
+extern int address_space_name_to_int (struct gdbarch *, const char *);
extern const char *address_space_int_to_name (struct gdbarch *, int);
struct gdbarch *, const char *,
const struct block *, int);
-extern struct type *lookup_template_type (char *, struct type *,
+extern struct type *lookup_template_type (const char *, struct type *,
const struct block *);
extern int get_vptr_fieldno (struct type *, struct type **);
|| !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);
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 ()
"Use the \"file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- copy_name ($1.stoken));
+ arg.c_str ());
}
}
;
unsigned int i;
const char *tokstart;
int saw_structop = last_was_structop;
- char *copy;
last_was_structop = 0;
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. */
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.
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)
{
{
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
/* 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)
{
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,
|| (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;
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,
fblock : BLOCKNAME
{ struct symbol *sym
- = lookup_symbol (copy_name ($1),
+ = lookup_symbol (copy_name ($1).c_str (),
pstate->expression_context_block,
VAR_DOMAIN, 0).symbol;
$$ = sym;}
/* GDB scope operator */
fblock : block COLONCOLON BLOCKNAME
{ struct symbol *tem
- = lookup_symbol (copy_name ($3), $1,
+ = lookup_symbol (copy_name ($3).c_str (), $1,
VAR_DOMAIN, 0).symbol;
if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
error (_("No function \"%s\" in specified context."),
- copy_name ($3));
+ copy_name ($3).c_str ());
$$ = tem;
}
;
/* GDB scope operator */
variable: block COLONCOLON NAME
{ struct block_symbol sym
- = lookup_symbol (copy_name ($3), $1,
+ = lookup_symbol (copy_name ($3).c_str (), $1,
VAR_DOMAIN, 0);
if (sym.symbol == 0)
error (_("No symbol \"%s\" in specified context."),
- copy_name ($3));
+ copy_name ($3).c_str ());
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
struct field_of_this_result is_a_field_of_this;
sym
- = lookup_symbol (copy_name ($1),
+ = lookup_symbol (copy_name ($1).c_str (),
pstate->expression_context_block,
VAR_DOMAIN,
&is_a_field_of_this);
else
{
struct bound_minimal_symbol msymbol;
- char *arg = copy_name ($1);
+ std::string arg = copy_name ($1);
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 () && !have_partial_symbols ())
error (_("No symbol table is loaded. Use the \"symbol-file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- copy_name ($1));
+ arg.c_str ());
}
}
;
{ $$
= lookup_typename (pstate->language (),
pstate->gdbarch (),
- copy_name ($1),
+ copy_name ($1).c_str (),
pstate->expression_context_block,
0);
}
currently as names of types; NAME for other symbols.
The caller is not constrained to care about the distinction. */
{
-
-
- char *tmp = copy_name (yylval.sval);
+ std::string tmp = copy_name (yylval.sval);
struct symbol *sym;
- if (lookup_symtab (tmp))
+ if (lookup_symtab (tmp.c_str ()))
return BLOCKNAME;
- sym = lookup_symbol (tmp, pstate->expression_context_block,
+ sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
VAR_DOMAIN, 0).symbol;
if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
return BLOCKNAME;
if (lookup_typename (pstate->language (), pstate->gdbarch (),
- copy_name (yylval.sval),
- pstate->expression_context_block, 1))
+ tmp.c_str (), pstate->expression_context_block, 1))
return TYPENAME;
if(sym)
$$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
else
{
+ std::string copy = copy_name ($1.stoken);
struct symtab *tem =
- lookup_symtab (copy_name ($1.stoken));
+ lookup_symtab (copy.c_str ());
if (tem)
$$ = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (tem),
STATIC_BLOCK);
else
error (_("No file or function \"%s\"."),
- copy_name ($1.stoken));
+ copy.c_str ());
}
}
;
block : block COLONCOLON name
- { struct symbol *tem
- = lookup_symbol (copy_name ($3), $1,
+ {
+ std::string copy = copy_name ($3);
+ struct symbol *tem
+ = lookup_symbol (copy.c_str (), $1,
VAR_DOMAIN, NULL).symbol;
if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
error (_("No function \"%s\" in specified context."),
- copy_name ($3));
+ copy.c_str ());
$$ = SYMBOL_BLOCK_VALUE (tem); }
;
variable: block COLONCOLON name
{ struct block_symbol sym;
- sym = lookup_symbol (copy_name ($3), $1,
+ std::string copy = copy_name ($3);
+ sym = lookup_symbol (copy.c_str (), $1,
VAR_DOMAIN, NULL);
if (sym.symbol == 0)
error (_("No symbol \"%s\" in specified context."),
- copy_name ($3));
+ copy.c_str ());
write_exp_elt_opcode (pstate, OP_VAR_VALUE);
write_exp_elt_block (pstate, sym.block);
variable: qualified_name
| COLONCOLON name
{
- char *name = copy_name ($2);
+ std::string name = copy_name ($2);
struct symbol *sym;
struct bound_minimal_symbol msymbol;
sym =
- lookup_symbol (name, (const struct block *) NULL,
+ lookup_symbol (name.c_str (),
+ (const struct block *) NULL,
VAR_DOMAIN, NULL).symbol;
if (sym)
{
break;
}
- msymbol = lookup_bound_minimal_symbol (name);
+ msymbol
+ = lookup_bound_minimal_symbol (name.c_str ());
if (msymbol.minsym != NULL)
write_exp_msymbol (pstate, msymbol);
else if (!have_full_symbols ()
"Use the \"file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- name);
+ name.c_str ());
}
;
if (this_type)
current_type = lookup_struct_elt_type (
this_type,
- copy_name ($1.stoken), 0);
+ copy_name ($1.stoken).c_str (), 0);
else
current_type = NULL;
}
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 ()
"Use the \"file\" command."));
else
error (_("No symbol \"%s\" in current context."),
- copy_name ($1.stoken));
+ arg.c_str ());
}
}
;
{ $$ = $1.type; }
| STRUCT name
{ $$
- = lookup_struct (copy_name ($2),
+ = lookup_struct (copy_name ($2).c_str (),
pstate->expression_context_block);
}
| CLASS name
{ $$
- = lookup_struct (copy_name ($2),
+ = lookup_struct (copy_name ($2).c_str (),
pstate->expression_context_block);
}
/* "const" and "volatile" are curently ignored. A type qualifier
currently as names of types; NAME for other symbols.
The caller is not constrained to care about the distinction. */
{
- char *tmp = copy_name (yylval.sval);
+ std::string tmp = copy_name (yylval.sval);
struct symbol *sym;
struct field_of_this_result is_a_field_of_this;
int is_a_field = 0;
is_a_field_of_this.type = NULL;
if (search_field && current_type)
- is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+ is_a_field = (lookup_struct_elt_type (current_type,
+ tmp.c_str (), 1) != NULL);
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, pstate->expression_context_block,
+ sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this).symbol;
/* second chance uppercased (as Free Pascal does). */
if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
tmp[i] -= ('a'-'A');
}
if (search_field && current_type)
- is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+ is_a_field = (lookup_struct_elt_type (current_type,
+ tmp.c_str (), 1) != NULL);
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, pstate->expression_context_block,
+ sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this).symbol;
}
/* Third chance Capitalized (as GPC does). */
tmp[i] -= ('A'-'a');
}
if (search_field && current_type)
- is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
+ is_a_field = (lookup_struct_elt_type (current_type,
+ tmp.c_str (), 1) != NULL);
if (is_a_field)
sym = NULL;
else
- sym = lookup_symbol (tmp, pstate->expression_context_block,
+ sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
VAR_DOMAIN, &is_a_field_of_this).symbol;
}
if (is_a_field || (is_a_field_of_this.type != NULL))
{
tempbuf = (char *) realloc (tempbuf, namelen + 1);
- strncpy (tempbuf, tmp, namelen);
+ strncpy (tempbuf, tmp.c_str (), namelen);
tempbuf [namelen] = 0;
yylval.sval.ptr = tempbuf;
yylval.sval.length = namelen;
no psymtabs (coff, xcoff, or some future change to blow away the
psymtabs once once symbols are read). */
if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
- || lookup_symtab (tmp))
+ || lookup_symtab (tmp.c_str ()))
{
yylval.ssym.sym.symbol = sym;
yylval.ssym.sym.block = NULL;
/* As big as the whole rest of the expression, which is
at least big enough. */
char *ncopy
- = (char *) alloca (strlen (tmp) + strlen (namestart)
+ = (char *) alloca (tmp.size () + strlen (namestart)
+ 3);
char *tmp1;
tmp1 = ncopy;
- memcpy (tmp1, tmp, strlen (tmp));
- tmp1 += strlen (tmp);
+ memcpy (tmp1, tmp.c_str (), tmp.size ());
+ tmp1 += tmp.size ();
memcpy (tmp1, "::", 2);
tmp1 += 2;
memcpy (tmp1, namestart, p - namestart);
}
yylval.tsym.type
= language_lookup_primitive_type (pstate->language (),
- pstate->gdbarch (), tmp);
+ pstate->gdbarch (), tmp.c_str ());
if (yylval.tsym.type != NULL)
{
free (uptokstart);
struct block_symbol sym;
struct bound_minimal_symbol msym;
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). */
/* Any names starting with $ are probably debugger internal variables. */
- isym = lookup_only_internalvar (copy_name (str) + 1);
+ copy = copy_name (str);
+ isym = lookup_only_internalvar (copy.c_str () + 1);
if (isym)
{
write_exp_elt_opcode (ps, OP_INTERNALVAR);
/* On some systems, such as HP-UX and hppa-linux, certain system routines
have names beginning with $ or $$. Check for those, first. */
- sym = lookup_symbol (copy_name (str), NULL, VAR_DOMAIN, NULL);
+ sym = lookup_symbol (copy.c_str (), NULL, VAR_DOMAIN, NULL);
if (sym.symbol)
{
write_exp_elt_opcode (ps, OP_VAR_VALUE);
write_exp_elt_opcode (ps, OP_VAR_VALUE);
return;
}
- msym = lookup_bound_minimal_symbol (copy_name (str));
+ msym = lookup_bound_minimal_symbol (copy.c_str ());
if (msym.minsym)
{
write_exp_msymbol (ps, msym);
/* Any other names are assumed to be debugger internal variables. */
write_exp_elt_opcode (ps, OP_INTERNALVAR);
- write_exp_elt_intern (ps, create_internalvar (copy_name (str) + 1));
+ write_exp_elt_intern (ps, create_internalvar (copy.c_str () + 1));
write_exp_elt_opcode (ps, OP_INTERNALVAR);
return;
handle_last:
so they can share the storage that lexptr is parsing.
When it is necessary to pass a name to a function that expects
a null-terminated string, the substring is copied out
- into a separate block of storage.
+ into a separate block of storage. */
- N.B. A single buffer is reused on each call. */
-
-char *
+std::string
copy_name (struct stoken token)
{
- /* A temporary buffer for identifiers, so we can null-terminate them.
- We allocate this with xrealloc. parse_exp_1 used to allocate with
- alloca, using the size of the whole expression as a conservative
- estimate of the space needed. However, macro expansion can
- introduce names longer than the original expression; there's no
- practical way to know beforehand how large that might be. */
- static char *namecopy;
- static size_t namecopy_size;
-
- /* Make sure there's enough space for the token. */
- if (namecopy_size < token.length + 1)
- {
- namecopy_size = token.length + 1;
- namecopy = (char *) xrealloc (namecopy, token.length + 1);
- }
-
- memcpy (namecopy, token.ptr, token.length);
- namecopy[token.length] = 0;
-
- return namecopy;
+ return std::string (token.ptr, token.length);
}
\f
extern const char *find_template_name_end (const char *);
-extern char *copy_name (struct stoken);
+extern std::string copy_name (struct stoken);
extern int dump_subexp (struct expression *, struct ui_file *, int);
/* See type-stack.h. */
void
-type_stack::insert (struct expr_builder *pstate, char *string)
+type_stack::insert (struct expr_builder *pstate, const char *string)
{
union type_stack_elt element;
int slot;
tp_pointer, and the new values are inserted above the first
item. */
- void insert (struct expr_builder *pstate, char *string);
+ void insert (struct expr_builder *pstate, const char *string);
/* Append the elements of the type stack FROM to the type stack
THIS. Always returns THIS. */