+2020-06-17 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * ada-lang.c (ada_lookup_symbol_nonlocal): Rename to
+ ada_language::lookup_symbol_nonlocal.
+ (ada_language_data): Delete la_lookup_symbol_nonlocal initializer.
+ (ada_language::lookup_symbol_nonlocal): New member function,
+ implementation from ada_lookup_symbol_nonlocal.
+ * c-lang.c (c_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ (cplus_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ (cplus_language::lookup_symbol_nonlocal): New member function.
+ (asm_language_data): Delete la_lookup_symbol_nonlocal initializer.
+ (minimal_language_data) Likewise.
+ * cp-namespace.c (cp_lookup_nested_symbol): Update comment.
+ * d-lang.c (d_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ (d_language::lookup_symbol_nonlocal): New member function.
+ * f-lang.c (f_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ (f_language::lookup_symbol_nonlocal): New member function.
+ * go-lang.c (go_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ * language.c (unknown_language_data): Likewise.
+ (auto_language_data): Likewise.
+ * language.h (language_data): Delete la_lookup_symbol_nonlocal
+ field.
+ (language_defn::lookup_symbol_nonlocal): New member function.
+ * m2-lang.c (m2_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ * objc-lang.c (objc_language_data): Likewise.
+ * opencl-lang.c (opencl_language_data): Likewise.
+ * p-lang.c (pascal_language_data): Likewise.
+ * rust-lang.c (rust_lookup_symbol_nonlocal): Rename to
+ rust_language::lookup_symbol_nonlocal.
+ (rust_language_data): Delete la_lookup_symbol_nonlocal
+ initializer.
+ (rust_language::lookup_symbol_nonlocal): New member function,
+ implementation from rust_lookup_symbol_nonlocal.
+ * symtab.c (lookup_symbol_aux): Update call to
+ lookup_symbol_nonlocal.
+ (basic_lookup_symbol_nonlocal): Rename to...
+ (language_defn::lookup_symbol_nonlocal): ...this, and update
+ header comment. Remove language_defn parameter, and replace with
+ uses of `this'.
+ * symtab.h (basic_lookup_symbol_nonlocal): Delete declaration.
+
2020-06-17 Andrew Burgess <andrew.burgess@embecosm.com>
* ada-lang.c (ada_language_data): Delete la_value_print_inner
return info;
}
-static struct block_symbol
-ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
- const char *name,
- const struct block *block,
- const domain_enum domain)
-{
- struct block_symbol sym;
-
- sym = ada_lookup_symbol (name, block_static_block (block), domain);
- if (sym.symbol != NULL)
- return sym;
-
- /* If we haven't found a match at this point, try the primitive
- types. In other languages, this search is performed before
- searching for global symbols in order to short-circuit that
- global-symbol search if it happens that the name corresponds
- to a primitive type. But we cannot do the same in Ada, because
- it is perfectly legitimate for a program to declare a type which
- has the same name as a standard type. If looking up a type in
- that situation, we have traditionally ignored the primitive type
- in favor of user-defined types. This is why, unlike most other
- languages, we search the primitive types this late and only after
- having searched the global symbols without success. */
-
- if (domain == VAR_DOMAIN)
- {
- struct gdbarch *gdbarch;
-
- if (block == NULL)
- gdbarch = target_gdbarch ();
- else
- gdbarch = block_gdbarch (block);
- sym.symbol = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
- if (sym.symbol != NULL)
- return sym;
- }
-
- return {};
-}
-
/* True iff STR is a possible encoded suffix of a normal Ada name
that is to be ignored for matching purposes. Suffixes of parallel
ada_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
true, /* la_store_sym_names_in_linkage_form_p */
- ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */
ada_op_print_tab, /* expression operators for printing */
0, /* c-style arrays */
1, /* String lower bound */
return ada_value_print_inner (val, stream, recurse, options);
}
+ /* See language.h. */
+
+ struct block_symbol lookup_symbol_nonlocal
+ (const char *name, const struct block *block,
+ const domain_enum domain) const override
+ {
+ struct block_symbol sym;
+
+ sym = ada_lookup_symbol (name, block_static_block (block), domain);
+ if (sym.symbol != NULL)
+ return sym;
+
+ /* If we haven't found a match at this point, try the primitive
+ types. In other languages, this search is performed before
+ searching for global symbols in order to short-circuit that
+ global-symbol search if it happens that the name corresponds
+ to a primitive type. But we cannot do the same in Ada, because
+ it is perfectly legitimate for a program to declare a type which
+ has the same name as a standard type. If looking up a type in
+ that situation, we have traditionally ignored the primitive type
+ in favor of user-defined types. This is why, unlike most other
+ languages, we search the primitive types this late and only after
+ having searched the global symbols without success. */
+
+ if (domain == VAR_DOMAIN)
+ {
+ struct gdbarch *gdbarch;
+
+ if (block == NULL)
+ gdbarch = target_gdbarch ();
+ else
+ gdbarch = block_gdbarch (block);
+ sym.symbol
+ = language_lookup_primitive_type_as_symbol (this, gdbarch, name);
+ if (sym.symbol != NULL)
+ return sym;
+ }
+
+ return {};
+ }
+
protected:
/* See language.h. */
c_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
true, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
c_print_typedef, /* Print a typedef using appropriate syntax */
"this", /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
return cp_class_name_from_physname (physname);
}
+ /* See language.h. */
+
+ struct block_symbol lookup_symbol_nonlocal
+ (const char *name, const struct block *block,
+ const domain_enum domain) const override
+ {
+ return cp_lookup_symbol_nonlocal (this, name, block, domain);
+ }
+
protected:
/* See language.h. */
c_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
true, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
c_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
true, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
case TYPE_CODE_ENUM:
/* NOTE: Handle modules here as well, because Fortran is re-using the C++
specific code to lookup nested symbols in modules, by calling the
- function pointer la_lookup_symbol_nonlocal, which ends up here. */
+ method lookup_symbol_nonlocal, which ends up here. */
case TYPE_CODE_MODULE:
{
int size;
syntax. */
"this",
false, /* la_store_sym_names_in_linkage_form_p */
- d_lookup_symbol_nonlocal,
d_op_print_tab, /* Expression operators for printing. */
1, /* C-style arrays. */
0, /* String lower bound. */
{
return d_value_print_inner (val, stream, recurse, options);
}
+
+ /* See language.h. */
+
+ struct block_symbol lookup_symbol_nonlocal
+ (const char *name, const struct block *block,
+ const domain_enum domain) const override
+ {
+ return d_lookup_symbol_nonlocal (this, name, block, domain);
+ }
};
/* Single instance of the D language class. */
f_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
f_op_print_tab, /* expression operators for printing */
0, /* arrays are first-class (not c-style) */
1, /* String lower bound */
return f_value_print_inner (val, stream, recurse, options);
}
+ /* See language.h. */
+
+ struct block_symbol lookup_symbol_nonlocal
+ (const char *name, const struct block *block,
+ const domain_enum domain) const override
+ {
+ return cp_lookup_symbol_nonlocal (this, name, block, domain);
+ }
protected:
syntax. */
NULL, /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal,
go_op_print_tab, /* Expression operators for printing. */
1, /* C-style arrays. */
0, /* String lower bound. */
default_print_typedef, /* Print a typedef using appropriate syntax */
"this", /* name_of_this */
true, /* store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
unk_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
default_print_typedef, /* Print a typedef using appropriate syntax */
"this", /* name_of_this */
false, /* store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
unk_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
const bool la_store_sym_names_in_linkage_form_p;
- /* This is a function that lookup_symbol will call when it gets to
- the part of symbol lookup where C looks up static and global
- variables. */
-
- struct block_symbol (*la_lookup_symbol_nonlocal)
- (const struct language_defn *,
- const char *,
- const struct block *,
- const domain_enum);
-
/* Table for printing expressions. */
const struct op_print *la_op_print_tab;
(tracker, mode, name_match_type, text, word, "", code);
}
+ /* This is a function that lookup_symbol will call when it gets to
+ the part of symbol lookup where C looks up static and global
+ variables. This default implements the basic C lookup rules. */
+
+ virtual struct block_symbol lookup_symbol_nonlocal
+ (const char *name,
+ const struct block *block,
+ const domain_enum domain) const;
+
/* Return an expression that can be used for a location
watchpoint. TYPE is a pointer type that points to the memory
to watch, and ADDR is the address of the watched memory. */
m2_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
m2_op_print_tab, /* expression operators for printing */
0, /* arrays are first-class (not c-style) */
0, /* String lower bound */
c_print_typedef, /* Print a typedef using appropriate syntax */
"self", /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
objc_op_print_tab, /* Expression operators for printing */
1, /* C-style arrays */
0, /* String lower bound */
c_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
pascal_print_typedef, /* Print a typedef using appropriate syntax */
"this", /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
pascal_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
\f
-/* Implementation of la_lookup_symbol_nonlocal for Rust. */
-
-static struct block_symbol
-rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
- const char *name,
- const struct block *block,
- const domain_enum domain)
-{
- struct block_symbol result = {};
-
- if (symbol_lookup_debug)
- {
- fprintf_unfiltered (gdb_stdlog,
- "rust_lookup_symbol_non_local"
- " (%s, %s (scope %s), %s)\n",
- name, host_address_to_string (block),
- block_scope (block), domain_name (domain));
- }
-
- /* Look up bare names in the block's scope. */
- std::string scopedname;
- if (name[cp_find_first_component (name)] == '\0')
- {
- const char *scope = block_scope (block);
-
- if (scope[0] != '\0')
- {
- scopedname = std::string (scope) + "::" + name;
- name = scopedname.c_str ();
- }
- else
- name = NULL;
- }
-
- if (name != NULL)
- {
- result = lookup_symbol_in_static_block (name, block, domain);
- if (result.symbol == NULL)
- result = lookup_global_symbol (name, block, domain);
- }
- return result;
-}
-
-\f
-
static const struct exp_descriptor exp_descriptor_rust =
{
rust_print_subexp,
rust_print_typedef, /* Print a typedef using appropriate syntax */
NULL, /* name_of_this */
false, /* la_store_sym_names_in_linkage_form_p */
- rust_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
0, /* String lower bound */
{
return rust_value_print_inner (val, stream, recurse, options);
}
+
+ /* See language.h. */
+
+ struct block_symbol lookup_symbol_nonlocal
+ (const char *name, const struct block *block,
+ const domain_enum domain) const override
+ {
+ struct block_symbol result = {};
+
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "rust_lookup_symbol_non_local"
+ " (%s, %s (scope %s), %s)\n",
+ name, host_address_to_string (block),
+ block_scope (block), domain_name (domain));
+ }
+
+ /* Look up bare names in the block's scope. */
+ std::string scopedname;
+ if (name[cp_find_first_component (name)] == '\0')
+ {
+ const char *scope = block_scope (block);
+
+ if (scope[0] != '\0')
+ {
+ scopedname = std::string (scope) + "::" + name;
+ name = scopedname.c_str ();
+ }
+ else
+ name = NULL;
+ }
+
+ if (name != NULL)
+ {
+ result = lookup_symbol_in_static_block (name, block, domain);
+ if (result.symbol == NULL)
+ result = lookup_global_symbol (name, block, domain);
+ }
+ return result;
+ }
};
/* Single instance of the Rust language class. */
/* Now do whatever is appropriate for LANGUAGE to look
up static and global variables. */
- result = langdef->la_lookup_symbol_nonlocal (langdef, name, block, domain);
+ result = langdef->lookup_symbol_nonlocal (name, block, domain);
if (result.symbol != NULL)
{
if (symbol_lookup_debug)
return result;
}
-/* See symtab.h. */
+/* See language.h. */
struct block_symbol
-basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
- const char *name,
- const struct block *block,
- const domain_enum domain)
+language_defn::lookup_symbol_nonlocal (const char *name,
+ const struct block *block,
+ const domain_enum domain) const
{
struct block_symbol result;
gdbarch = target_gdbarch ();
else
gdbarch = block_gdbarch (block);
- result.symbol = language_lookup_primitive_type_as_symbol (langdef,
+ result.symbol = language_lookup_primitive_type_as_symbol (this,
gdbarch, name);
result.block = NULL;
if (result.symbol != NULL)
const struct block *block,
domain_enum domain);
-/* A default version of lookup_symbol_nonlocal for use by languages
- that can't think of anything better to do.
- This implements the C lookup rules. */
-
-extern struct block_symbol
- basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
- const char *,
- const struct block *,
- const domain_enum);
-
/* Some helper functions for languages that need to write their own
lookup_symbol_nonlocal functions. */