* c-exp.y (block, variable, name_not_typename, lex_one_token,

classify_name): Update.
	* c-valprint.c (c_val_print): Update.
	* f-exp.y (yylex): Update.
	* go-exp.y (package_name_p, classify_packaged_name)
	(classify_name): Update.
	* jv-exp.y (push_variable): Update.
	* m2-exp.y (variable): Update.
	* mi/mi-cmd-stack.c (list_args_or_locals): Update.
	* p-exp.y (block, variable, yylex): Update.
	* p-valprint.c (pascal_val_print): Update.
	* parse.c (write_dollar_variable): Update.
	* printcmd.c (address_info): Update.
	* python/py-symbol.c (gdbpy_lookup_symbol): Update.
	* symtab.c (lookup_symbol_aux, lookup_symbol_in_language)
	(lookup_symbol): Change type of 'is_a_field_of_this'.
	(check_field): Add 'is_a_field_of_this' argument.
	* symtab.h (struct field_of_this_result): New.
	(lookup_symbol, lookup_symbol_in_language): Update.
This commit is contained in:
Tom Tromey 2012-12-14 17:47:40 +00:00
parent 2dc3df72a7
commit 1993b71979
15 changed files with 127 additions and 64 deletions

View File

@ -1,3 +1,25 @@
2012-12-14 Tom Tromey <tromey@redhat.com>
* c-exp.y (block, variable, name_not_typename, lex_one_token,
classify_name): Update.
* c-valprint.c (c_val_print): Update.
* f-exp.y (yylex): Update.
* go-exp.y (package_name_p, classify_packaged_name)
(classify_name): Update.
* jv-exp.y (push_variable): Update.
* m2-exp.y (variable): Update.
* mi/mi-cmd-stack.c (list_args_or_locals): Update.
* p-exp.y (block, variable, yylex): Update.
* p-valprint.c (pascal_val_print): Update.
* parse.c (write_dollar_variable): Update.
* printcmd.c (address_info): Update.
* python/py-symbol.c (gdbpy_lookup_symbol): Update.
* symtab.c (lookup_symbol_aux, lookup_symbol_in_language)
(lookup_symbol): Change type of 'is_a_field_of_this'.
(check_field): Add 'is_a_field_of_this' argument.
* symtab.h (struct field_of_this_result): New.
(lookup_symbol, lookup_symbol_in_language): Update.
2012-12-14 Tom Tromey <tromey@redhat.com>
* symtab.c (check_field): Now static. Move from...

View File

@ -871,7 +871,7 @@ block : BLOCKNAME
block : block COLONCOLON name
{ struct symbol *tem
= lookup_symbol (copy_name ($3), $1,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
error (_("No function \"%s\" in specified context."),
copy_name ($3));
@ -896,7 +896,7 @@ variable: name_not_typename ENTRY
variable: block COLONCOLON name
{ struct symbol *sym;
sym = lookup_symbol (copy_name ($3), $1,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (sym == 0)
error (_("No symbol \"%s\" in specified context."),
copy_name ($3));
@ -972,7 +972,7 @@ variable: qualified_name
sym =
lookup_symbol (name, (const struct block *) NULL,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (sym)
{
write_exp_elt_opcode (OP_VAR_VALUE);
@ -1577,11 +1577,15 @@ name_not_typename : NAME
*/
| operator
{
struct field_of_this_result is_a_field_of_this;
$$.stoken = $1;
$$.sym = lookup_symbol ($1.ptr,
expression_context_block,
VAR_DOMAIN,
&$$.is_a_field_of_this);
&is_a_field_of_this);
$$.is_a_field_of_this
= is_a_field_of_this.type != NULL;
}
| UNKNOWN_CPP_NAME
;
@ -2690,7 +2694,7 @@ lex_one_token (void)
if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
{
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
if (lookup_symbol (copy, expression_context_block,
VAR_DOMAIN,
@ -2747,18 +2751,22 @@ classify_name (const struct block *block)
{
struct symbol *sym;
char *copy;
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
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));
sym = lookup_symbol (copy, block, VAR_DOMAIN,
parse_language->la_name_of_this
? &is_a_field_of_this : (int *) NULL);
? &is_a_field_of_this : NULL);
if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return BLOCKNAME;
}
else if (!sym)
@ -2812,18 +2820,18 @@ classify_name (const struct block *block)
if (hextype == INT)
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return NAME_OR_INT;
}
}
/* Any other kind of symbol */
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
if (sym == NULL
&& parse_language->la_language == language_cplus
&& !is_a_field_of_this
&& is_a_field_of_this.type == NULL
&& !lookup_minimal_symbol (copy, NULL, NULL))
return UNKNOWN_CPP_NAME;

View File

@ -333,7 +333,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
struct symbol *wsym = (struct symbol *) NULL;
struct type *wtype;
struct block *block = (struct block *) NULL;
int is_this_fld;
struct field_of_this_result is_this_fld;
if (want_space)
fputs_filtered (" ", stream);

View File

@ -1175,9 +1175,13 @@ yylex (void)
{
char *tmp = copy_name (yylval.sval);
struct symbol *sym;
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
int hextype;
/* 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));
sym = lookup_symbol (tmp, expression_context_block,
VAR_DOMAIN,
parse_language->la_language == language_cplus
@ -1205,14 +1209,14 @@ yylex (void)
if (hextype == INT)
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return NAME_OR_INT;
}
}
/* Any other kind of symbol */
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return NAME;
}
}

View File

@ -1365,7 +1365,7 @@ static int
package_name_p (const char *name, const struct block *block)
{
struct symbol *sym;
int is_a_field_of_this;
struct field_of_this_result is_a_field_of_this;
sym = lookup_symbol (name, block, STRUCT_DOMAIN, &is_a_field_of_this);
@ -1406,7 +1406,7 @@ classify_packaged_name (const struct block *block)
{
char *copy;
struct symbol *sym;
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
copy = copy_name (yylval.sval);
@ -1415,7 +1415,7 @@ classify_packaged_name (const struct block *block)
if (sym)
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
}
return NAME;
@ -1435,7 +1435,7 @@ classify_name (const struct block *block)
struct type *type;
struct symbol *sym;
char *copy;
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
copy = copy_name (yylval.sval);
@ -1458,7 +1458,7 @@ classify_name (const struct block *block)
if (sym)
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return NAME;
}
@ -1484,7 +1484,7 @@ classify_name (const struct block *block)
{
yylval.ssym.stoken = sval;
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return NAME;
}
}

View File

@ -1227,7 +1227,7 @@ static int
push_variable (struct stoken name)
{
char *tmp = copy_name (name);
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
struct symbol *sym;
sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN,
&is_a_field_of_this);
@ -1248,7 +1248,7 @@ push_variable (struct stoken name)
write_exp_elt_opcode (OP_VAR_VALUE);
return 1;
}
if (is_a_field_of_this)
if (is_a_field_of_this.type != NULL)
{
/* it hangs off of `this'. Must not inadvertently convert from a
method call to data ref. */

View File

@ -602,7 +602,7 @@ variable: block COLONCOLON NAME
/* Base case for variables. */
variable: NAME
{ struct symbol *sym;
int is_a_field_of_this;
struct field_of_this_result is_a_field_of_this;
sym = lookup_symbol (copy_name ($1),
expression_context_block,

View File

@ -397,7 +397,7 @@ list_args_or_locals (enum what_to_list what, enum print_values values,
if (SYMBOL_IS_ARGUMENT (sym))
sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
block, VAR_DOMAIN,
(int *) NULL);
NULL);
else
sym2 = sym;
gdb_assert (sym2 != NULL);

View File

@ -658,7 +658,7 @@ block : BLOCKNAME
block : block COLONCOLON name
{ struct symbol *tem
= lookup_symbol (copy_name ($3), $1,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
error (_("No function \"%s\" in specified context."),
copy_name ($3));
@ -668,7 +668,7 @@ block : block COLONCOLON name
variable: block COLONCOLON name
{ struct symbol *sym;
sym = lookup_symbol (copy_name ($3), $1,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (sym == 0)
error (_("No symbol \"%s\" in specified context."),
copy_name ($3));
@ -704,7 +704,7 @@ variable: qualified_name
sym =
lookup_symbol (name, (const struct block *) NULL,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (sym)
{
write_exp_elt_opcode (OP_VAR_VALUE);
@ -1483,7 +1483,7 @@ yylex (void)
static const char this_name[] = "this";
if (lookup_symbol (this_name, expression_context_block,
VAR_DOMAIN, (int *) NULL))
VAR_DOMAIN, NULL))
{
free (uptokstart);
return THIS;
@ -1522,7 +1522,7 @@ yylex (void)
{
char *tmp = copy_name (yylval.sval);
struct symbol *sym;
int is_a_field_of_this = 0;
struct field_of_this_result is_a_field_of_this;
int is_a_field = 0;
int hextype;
@ -1535,7 +1535,7 @@ yylex (void)
sym = lookup_symbol (tmp, expression_context_block,
VAR_DOMAIN, &is_a_field_of_this);
/* second chance uppercased (as Free Pascal does). */
if (!sym && !is_a_field_of_this && !is_a_field)
if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
{
for (i = 0; i <= namelen; i++)
{
@ -1549,7 +1549,7 @@ yylex (void)
else
sym = lookup_symbol (tmp, expression_context_block,
VAR_DOMAIN, &is_a_field_of_this);
if (sym || is_a_field_of_this || is_a_field)
if (sym || is_a_field_of_this.type != NULL || is_a_field)
for (i = 0; i <= namelen; i++)
{
if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
@ -1557,7 +1557,7 @@ yylex (void)
}
}
/* Third chance Capitalized (as GPC does). */
if (!sym && !is_a_field_of_this && !is_a_field)
if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
{
for (i = 0; i <= namelen; i++)
{
@ -1577,7 +1577,7 @@ yylex (void)
else
sym = lookup_symbol (tmp, expression_context_block,
VAR_DOMAIN, &is_a_field_of_this);
if (sym || is_a_field_of_this || is_a_field)
if (sym || is_a_field_of_this.type != NULL || is_a_field)
for (i = 0; i <= namelen; i++)
{
if (i == 0)
@ -1607,7 +1607,7 @@ yylex (void)
|| lookup_symtab (tmp))
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
free (uptokstart);
return BLOCKNAME;
}
@ -1673,7 +1673,7 @@ yylex (void)
memcpy (tmp1, namestart, p - namestart);
tmp1[p - namestart] = '\0';
cur_sym = lookup_symbol (ncopy, expression_context_block,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (cur_sym)
{
if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
@ -1722,7 +1722,7 @@ yylex (void)
if (hextype == INT)
{
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
free (uptokstart);
return NAME_OR_INT;
}
@ -1731,7 +1731,7 @@ yylex (void)
free(uptokstart);
/* Any other kind of symbol. */
yylval.ssym.sym = sym;
yylval.ssym.is_a_field_of_this = is_a_field_of_this;
yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
return NAME;
}
}

View File

@ -243,7 +243,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
struct symbol *wsym = (struct symbol *) NULL;
struct type *wtype;
struct block *block = (struct block *) NULL;
int is_this_fld;
struct field_of_this_result is_this_fld;
if (want_space)
fputs_filtered (" ", stream);

View File

@ -692,7 +692,7 @@ write_dollar_variable (struct stoken str)
have names beginning with $ or $$. Check for those, first. */
sym = lookup_symbol (copy_name (str), (struct block *) NULL,
VAR_DOMAIN, (int *) NULL);
VAR_DOMAIN, NULL);
if (sym)
{
write_exp_elt_opcode (OP_VAR_VALUE);

View File

@ -1199,8 +1199,7 @@ address_info (char *exp, int from_tty)
long val;
struct obj_section *section;
CORE_ADDR load_addr, context_pc = 0;
int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero
if exp is a field of `this'. */
struct field_of_this_result is_a_field_of_this;
if (exp == 0)
error (_("Argument required."));
@ -1209,7 +1208,7 @@ address_info (char *exp, int from_tty)
&is_a_field_of_this);
if (sym == NULL)
{
if (is_a_field_of_this)
if (is_a_field_of_this.type != NULL)
{
printf_filtered ("Symbol \"");
fprintf_symbol_filtered (gdb_stdout, exp,

View File

@ -354,7 +354,8 @@ sympy_dealloc (PyObject *obj)
PyObject *
gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
{
int domain = VAR_DOMAIN, is_a_field_of_this = 0;
int domain = VAR_DOMAIN;
struct field_of_this_result is_a_field_of_this;
const char *name;
static char *keywords[] = { "name", "block", "domain", NULL };
struct symbol *symbol = NULL;
@ -407,7 +408,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
}
PyTuple_SET_ITEM (ret_tuple, 0, sym_obj);
bool_obj = is_a_field_of_this? Py_True : Py_False;
bool_obj = (is_a_field_of_this.type != NULL) ? Py_True : Py_False;
Py_INCREF (bool_obj);
PyTuple_SET_ITEM (ret_tuple, 1, bool_obj);

View File

@ -82,7 +82,7 @@ static struct symbol *lookup_symbol_aux (const char *name,
const struct block *block,
const domain_enum domain,
enum language language,
int *is_a_field_of_this);
struct field_of_this_result *is_a_field_of_this);
static
struct symbol *lookup_symbol_aux_local (const char *name,
@ -1225,7 +1225,7 @@ demangle_for_lookup (const char *name, enum language lang,
struct symbol *
lookup_symbol_in_language (const char *name, const struct block *block,
const domain_enum domain, enum language lang,
int *is_a_field_of_this)
struct field_of_this_result *is_a_field_of_this)
{
const char *modified_name;
struct symbol *returnval;
@ -1243,7 +1243,8 @@ lookup_symbol_in_language (const char *name, const struct block *block,
struct symbol *
lookup_symbol (const char *name, const struct block *block,
domain_enum domain, int *is_a_field_of_this)
domain_enum domain,
struct field_of_this_result *is_a_field_of_this)
{
return lookup_symbol_in_language (name, block, domain,
current_language->la_language,
@ -1283,7 +1284,8 @@ lookup_language_this (const struct language_defn *lang,
structure/union is defined, otherwise, return 0. */
static int
check_field (struct type *type, const char *name)
check_field (struct type *type, const char *name,
struct field_of_this_result *is_a_field_of_this)
{
int i;
@ -1295,7 +1297,11 @@ check_field (struct type *type, const char *name)
const char *t_field_name = TYPE_FIELD_NAME (type, i);
if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
return 1;
{
is_a_field_of_this->type = type;
is_a_field_of_this->field = &TYPE_FIELD (type, i);
return 1;
}
}
/* C++: If it was not found as a data field, then try to return it
@ -1304,11 +1310,15 @@ check_field (struct type *type, const char *name)
for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
{
if (strcmp_iw (TYPE_FN_FIELDLIST_NAME (type, i), name) == 0)
return 1;
{
is_a_field_of_this->type = type;
is_a_field_of_this->fn_field = &TYPE_FN_FIELDLIST (type, i);
return 1;
}
}
for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
if (check_field (TYPE_BASECLASS (type, i), name))
if (check_field (TYPE_BASECLASS (type, i), name, is_a_field_of_this))
return 1;
return 0;
@ -1320,18 +1330,17 @@ check_field (struct type *type, const char *name)
static struct symbol *
lookup_symbol_aux (const char *name, const struct block *block,
const domain_enum domain, enum language language,
int *is_a_field_of_this)
struct field_of_this_result *is_a_field_of_this)
{
struct symbol *sym;
const struct language_defn *langdef;
/* Make sure we do something sensible with is_a_field_of_this, since
the callers that set this parameter to some non-null value will
certainly use it later and expect it to be either 0 or 1.
If we don't set it, the contents of is_a_field_of_this are
undefined. */
certainly use it later. If we don't set it, the contents of
is_a_field_of_this are undefined. */
if (is_a_field_of_this != NULL)
*is_a_field_of_this = 0;
memset (is_a_field_of_this, 0, sizeof (*is_a_field_of_this));
/* Search specified block and its superiors. Don't search
STATIC_BLOCK or GLOBAL_BLOCK. */
@ -1365,11 +1374,8 @@ lookup_symbol_aux (const char *name, const struct block *block,
error (_("Internal error: `%s' is not an aggregate"),
langdef->la_name_of_this);
if (check_field (t, name))
{
*is_a_field_of_this = 1;
return NULL;
}
if (check_field (t, name, is_a_field_of_this))
return NULL;
}
}

View File

@ -919,19 +919,42 @@ int symbol_matches_domain (enum language symbol_language,
extern struct symtab *lookup_symtab (const char *);
/* An object of this type is passed as the 'is_a_field_of_this'
argument to lookup_symbol and lookup_symbol_in_language. */
struct field_of_this_result
{
/* The type in which the field was found. If this is NULL then the
symbol was not found in 'this'. If non-NULL, then one of the
other fields will be non-NULL as well. */
struct type *type;
/* If the symbol was found as an ordinary field of 'this', then this
is non-NULL and points to the particular field. */
struct field *field;
/* If the symbol was found as an function field of 'this', then this
is non-NULL and points to the particular field. */
struct fn_fieldlist *fn_field;
};
/* lookup a symbol by name (optional block) in language. */
extern struct symbol *lookup_symbol_in_language (const char *,
const struct block *,
const domain_enum,
enum language,
int *);
struct field_of_this_result *);
/* lookup a symbol by name (optional block, optional symtab)
in the current language. */
extern struct symbol *lookup_symbol (const char *, const struct block *,
const domain_enum, int *);
const domain_enum,
struct field_of_this_result *);
/* A default version of lookup_symbol_nonlocal for use by languages
that can't think of anything better to do. */