* 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> 2012-12-14 Tom Tromey <tromey@redhat.com>
* symtab.c (check_field): Now static. Move from... * symtab.c (check_field): Now static. Move from...

View File

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

View File

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

View File

@ -1365,7 +1365,7 @@ static int
package_name_p (const char *name, const struct block *block) package_name_p (const char *name, const struct block *block)
{ {
struct symbol *sym; 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); 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; char *copy;
struct symbol *sym; 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); copy = copy_name (yylval.sval);
@ -1415,7 +1415,7 @@ classify_packaged_name (const struct block *block)
if (sym) if (sym)
{ {
yylval.ssym.sym = 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; return NAME;
@ -1435,7 +1435,7 @@ classify_name (const struct block *block)
struct type *type; struct type *type;
struct symbol *sym; struct symbol *sym;
char *copy; char *copy;
int is_a_field_of_this = 0; struct field_of_this_result is_a_field_of_this;
copy = copy_name (yylval.sval); copy = copy_name (yylval.sval);
@ -1458,7 +1458,7 @@ classify_name (const struct block *block)
if (sym) if (sym)
{ {
yylval.ssym.sym = 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; return NAME;
} }
@ -1484,7 +1484,7 @@ classify_name (const struct block *block)
{ {
yylval.ssym.stoken = sval; yylval.ssym.stoken = sval;
yylval.ssym.sym = 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; return NAME;
} }
} }

View File

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

View File

@ -602,7 +602,7 @@ variable: block COLONCOLON NAME
/* Base case for variables. */ /* Base case for variables. */
variable: NAME variable: NAME
{ struct symbol *sym; { 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), sym = lookup_symbol (copy_name ($1),
expression_context_block, 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)) if (SYMBOL_IS_ARGUMENT (sym))
sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
block, VAR_DOMAIN, block, VAR_DOMAIN,
(int *) NULL); NULL);
else else
sym2 = sym; sym2 = sym;
gdb_assert (sym2 != NULL); gdb_assert (sym2 != NULL);

View File

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

View File

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

View File

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

View File

@ -354,7 +354,8 @@ sympy_dealloc (PyObject *obj)
PyObject * PyObject *
gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) 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; const char *name;
static char *keywords[] = { "name", "block", "domain", NULL }; static char *keywords[] = { "name", "block", "domain", NULL };
struct symbol *symbol = 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); 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); Py_INCREF (bool_obj);
PyTuple_SET_ITEM (ret_tuple, 1, 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 struct block *block,
const domain_enum domain, const domain_enum domain,
enum language language, enum language language,
int *is_a_field_of_this); struct field_of_this_result *is_a_field_of_this);
static static
struct symbol *lookup_symbol_aux_local (const char *name, struct symbol *lookup_symbol_aux_local (const char *name,
@ -1225,7 +1225,7 @@ demangle_for_lookup (const char *name, enum language lang,
struct symbol * struct symbol *
lookup_symbol_in_language (const char *name, const struct block *block, lookup_symbol_in_language (const char *name, const struct block *block,
const domain_enum domain, enum language lang, 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; const char *modified_name;
struct symbol *returnval; struct symbol *returnval;
@ -1243,7 +1243,8 @@ lookup_symbol_in_language (const char *name, const struct block *block,
struct symbol * struct symbol *
lookup_symbol (const char *name, const struct block *block, 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, return lookup_symbol_in_language (name, block, domain,
current_language->la_language, current_language->la_language,
@ -1283,7 +1284,8 @@ lookup_language_this (const struct language_defn *lang,
structure/union is defined, otherwise, return 0. */ structure/union is defined, otherwise, return 0. */
static int 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; int i;
@ -1295,7 +1297,11 @@ check_field (struct type *type, const char *name)
const char *t_field_name = TYPE_FIELD_NAME (type, i); const char *t_field_name = TYPE_FIELD_NAME (type, i);
if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) 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 /* 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) for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
{ {
if (strcmp_iw (TYPE_FN_FIELDLIST_NAME (type, i), name) == 0) 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--) 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 1;
return 0; return 0;
@ -1320,18 +1330,17 @@ check_field (struct type *type, const char *name)
static struct symbol * static struct symbol *
lookup_symbol_aux (const char *name, const struct block *block, lookup_symbol_aux (const char *name, const struct block *block,
const domain_enum domain, enum language language, 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; struct symbol *sym;
const struct language_defn *langdef; const struct language_defn *langdef;
/* Make sure we do something sensible with is_a_field_of_this, since /* 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 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. certainly use it later. If we don't set it, the contents of
If we don't set it, the contents of is_a_field_of_this are is_a_field_of_this are undefined. */
undefined. */
if (is_a_field_of_this != NULL) 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 /* Search specified block and its superiors. Don't search
STATIC_BLOCK or GLOBAL_BLOCK. */ 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"), error (_("Internal error: `%s' is not an aggregate"),
langdef->la_name_of_this); langdef->la_name_of_this);
if (check_field (t, name)) if (check_field (t, name, is_a_field_of_this))
{ return NULL;
*is_a_field_of_this = 1;
return NULL;
}
} }
} }

View File

@ -919,19 +919,42 @@ int symbol_matches_domain (enum language symbol_language,
extern struct symtab *lookup_symtab (const char *); 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. */ /* lookup a symbol by name (optional block) in language. */
extern struct symbol *lookup_symbol_in_language (const char *, extern struct symbol *lookup_symbol_in_language (const char *,
const struct block *, const struct block *,
const domain_enum, const domain_enum,
enum language, enum language,
int *); struct field_of_this_result *);
/* lookup a symbol by name (optional block, optional symtab) /* lookup a symbol by name (optional block, optional symtab)
in the current language. */ in the current language. */
extern struct symbol *lookup_symbol (const char *, const struct block *, 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 /* A default version of lookup_symbol_nonlocal for use by languages
that can't think of anything better to do. */ that can't think of anything better to do. */