/* YACC parser for Pascal expressions, for GDB.
- Copyright (C) 2000-2019 Free Software Foundation, Inc.
+ Copyright (C) 2000-2020 Free Software Foundation, Inc.
This file is part of GDB.
static struct parser_state *pstate = NULL;
+/* Depth of parentheses. */
+static int paren_depth;
+
int yyparse (void);
static int yylex (void);
}
;
exp : field_exp name COMPLETE
- { mark_struct_expression (pstate);
+ { pstate->mark_struct_expression ();
write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
write_exp_string (pstate, $2);
write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
;
exp : field_exp COMPLETE
{ struct stoken s;
- mark_struct_expression (pstate);
+ pstate->mark_struct_expression ();
write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
s.ptr = "";
s.length = 0;
/* This is to save the value of arglist_len
being accumulated by an outer function call. */
{ push_current_type ();
- start_arglist (); }
+ pstate->start_arglist (); }
arglist ')' %prec ARROW
{ write_exp_elt_opcode (pstate, OP_FUNCALL);
write_exp_elt_longcst (pstate,
- (LONGEST) end_arglist ());
+ pstate->end_arglist ());
write_exp_elt_opcode (pstate, OP_FUNCALL);
pop_current_type ();
if (current_type)
arglist :
| exp
- { arglist_len = 1; }
+ { pstate->arglist_len = 1; }
| arglist ',' exp %prec ABOVE_COMMA
- { arglist_len++; }
+ { pstate->arglist_len++; }
;
exp : type '(' exp ')' %prec UNARY
$$ = 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 (sym.symbol)
{
if (symbol_read_needs_frame (sym.symbol))
- innermost_block.update (sym);
+ pstate->block_tracker->update (sym);
write_exp_elt_opcode (pstate, OP_VAR_VALUE);
write_exp_elt_block (pstate, sym.block);
/* Object pascal: it hangs off of `this'. Must
not inadvertently convert from a method call
to data ref. */
- innermost_block.update (sym);
+ pstate->block_tracker->update (sym);
write_exp_elt_opcode (pstate, OP_THIS);
write_exp_elt_opcode (pstate, OP_THIS);
write_exp_elt_opcode (pstate, STRUCTOP_PTR);
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
retry:
- prev_lexptr = lexptr;
+ pstate->prev_lexptr = pstate->lexptr;
- tokstart = lexptr;
- explen = strlen (lexptr);
+ tokstart = pstate->lexptr;
+ explen = strlen (pstate->lexptr);
/* See if it is a special token of length 3. */
if (explen > 2)
|| (!isalpha (tokstart[3])
&& !isdigit (tokstart[3]) && tokstart[3] != '_')))
{
- lexptr += 3;
+ pstate->lexptr += 3;
yylval.opcode = tokentab3[i].opcode;
return tokentab3[i].token;
}
|| (!isalpha (tokstart[2])
&& !isdigit (tokstart[2]) && tokstart[2] != '_')))
{
- lexptr += 2;
+ pstate->lexptr += 2;
yylval.opcode = tokentab2[i].opcode;
return tokentab2[i].token;
}
switch (c = *tokstart)
{
case 0:
- if (search_field && parse_completion)
+ if (search_field && pstate->parse_completion)
return COMPLETE;
else
return 0;
case ' ':
case '\t':
case '\n':
- lexptr++;
+ pstate->lexptr++;
goto retry;
case '\'':
/* We either have a character constant ('0' or '\177' for example)
or we have a quoted symbol reference ('foo(int,int)' in object pascal
for example). */
- lexptr++;
- c = *lexptr++;
+ pstate->lexptr++;
+ c = *pstate->lexptr++;
if (c == '\\')
- c = parse_escape (pstate->gdbarch (), &lexptr);
+ c = parse_escape (pstate->gdbarch (), &pstate->lexptr);
else if (c == '\'')
error (_("Empty character constant."));
yylval.typed_val_int.val = c;
yylval.typed_val_int.type = parse_type (pstate)->builtin_char;
- c = *lexptr++;
+ c = *pstate->lexptr++;
if (c != '\'')
{
namelen = skip_quoted (tokstart) - tokstart;
if (namelen > 2)
{
- lexptr = tokstart + namelen;
- if (lexptr[-1] != '\'')
+ pstate->lexptr = tokstart + namelen;
+ if (pstate->lexptr[-1] != '\'')
error (_("Unmatched single quote."));
namelen -= 2;
tokstart++;
case '(':
paren_depth++;
- lexptr++;
+ pstate->lexptr++;
return c;
case ')':
if (paren_depth == 0)
return 0;
paren_depth--;
- lexptr++;
+ pstate->lexptr++;
return c;
case ',':
- if (comma_terminates && paren_depth == 0)
+ if (pstate->comma_terminates && paren_depth == 0)
return 0;
- lexptr++;
+ pstate->lexptr++;
return c;
case '.':
/* Might be a floating point number. */
- if (lexptr[1] < '0' || lexptr[1] > '9')
+ if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9')
{
goto symbol; /* Nope, must be a symbol. */
}
err_copy[p - tokstart] = 0;
error (_("Invalid number \"%s\"."), err_copy);
}
- lexptr = p;
+ pstate->lexptr = p;
return toktype;
}
case '{':
case '}':
symbol:
- lexptr++;
+ pstate->lexptr++;
return c;
case '"':
tempbuf[tempbufindex] = '\0'; /* See note above. */
yylval.sval.ptr = tempbuf;
yylval.sval.length = tempbufindex;
- lexptr = tokptr;
+ pstate->lexptr = tokptr;
return (STRING);
}
return 0;
}
- lexptr += namelen;
+ pstate->lexptr += namelen;
tryname:
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;
us whether a type is nested), we just ignore the
containing type. */
- p = lexptr;
+ p = pstate->lexptr;
best_sym = sym;
while (1)
{
/* 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);
if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
{
best_sym = cur_sym;
- lexptr = p;
+ pstate->lexptr = p;
}
else
break;
}
yylval.tsym.type
= language_lookup_primitive_type (pstate->language (),
- pstate->gdbarch (), tmp);
+ pstate->gdbarch (), tmp.c_str ());
if (yylval.tsym.type != NULL)
{
free (uptokstart);
scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
+ paren_depth = 0;
return yyparse ();
}
static void
yyerror (const char *msg)
{
- if (prev_lexptr)
- lexptr = prev_lexptr;
+ if (pstate->prev_lexptr)
+ pstate->lexptr = pstate->prev_lexptr;
- error (_("A %s in expression, near `%s'."), msg, lexptr);
+ error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
}