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>
+
+ * 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...
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));
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));
sym =
lookup_symbol (name, (const struct block *) NULL,
- VAR_DOMAIN, (int *) NULL);
+ VAR_DOMAIN, NULL);
if (sym)
{
write_exp_elt_opcode (OP_VAR_VALUE);
*/
| 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
;
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,
{
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)
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;
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);
{
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
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;
}
}
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);
{
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);
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;
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);
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;
}
{
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;
}
}
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);
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. */
/* 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,
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);
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));
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));
sym =
lookup_symbol (name, (const struct block *) NULL,
- VAR_DOMAIN, (int *) NULL);
+ VAR_DOMAIN, NULL);
if (sym)
{
write_exp_elt_opcode (OP_VAR_VALUE);
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;
{
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;
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++)
{
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'))
}
}
/* 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++)
{
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)
|| 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;
}
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)
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;
}
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;
}
}
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);
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);
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."));
&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,
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;
}
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);
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,
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;
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,
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;
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
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;
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. */
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;
}
}
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. */