Don't allow NULL as an argument to block_scope

block_scope has special behavior when the block is NULL.
Remove this and patch up the callers instead.
This commit is contained in:
Tom Tromey
2023-01-19 17:37:15 -07:00
parent f52688890e
commit 683aecac8c
3 changed files with 6 additions and 5 deletions

View File

@ -511,7 +511,7 @@ d_lookup_symbol_nonlocal (const struct language_defn *langdef,
const domain_enum domain) const domain_enum domain)
{ {
struct block_symbol sym; struct block_symbol sym;
const char *scope = block_scope (block); const char *scope = block == nullptr ? "" : block_scope (block);
sym = lookup_module_scope (langdef, name, block, domain, scope, 0); sym = lookup_module_scope (langdef, name, block, domain, scope, 0);
if (sym.symbol != NULL) if (sym.symbol != NULL)

View File

@ -148,17 +148,16 @@ public:
{ {
struct block_symbol result = {}; struct block_symbol result = {};
const char *scope = block == nullptr ? "" : block_scope (block);
symbol_lookup_debug_printf symbol_lookup_debug_printf
("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)", ("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)",
name, host_address_to_string (block), block_scope (block), name, host_address_to_string (block), scope,
domain_name (domain)); domain_name (domain));
/* Look up bare names in the block's scope. */ /* Look up bare names in the block's scope. */
std::string scopedname; std::string scopedname;
if (name[cp_find_first_component (name)] == '\0') if (name[cp_find_first_component (name)] == '\0')
{ {
const char *scope = block_scope (block);
if (scope[0] != '\0') if (scope[0] != '\0')
{ {
scopedname = std::string (scope) + "::" + name; scopedname = std::string (scope) + "::" + name;

View File

@ -373,7 +373,9 @@ rust_parser::crate_name (const std::string &name)
std::string std::string
rust_parser::super_name (const std::string &ident, unsigned int n_supers) rust_parser::super_name (const std::string &ident, unsigned int n_supers)
{ {
const char *scope = block_scope (pstate->expression_context_block); const char *scope = "";
if (pstate->expression_context_block != nullptr)
scope = block_scope (pstate->expression_context_block);
int offset; int offset;
if (scope[0] == '\0') if (scope[0] == '\0')