2015-08-14 02:34:15 +08:00
|
|
|
/* Helper routines for D support in GDB.
|
|
|
|
|
2021-01-01 16:03:39 +08:00
|
|
|
Copyright (C) 2014-2021 Free Software Foundation, Inc.
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
2019-04-07 03:38:10 +08:00
|
|
|
#include "symtab.h"
|
2015-08-14 02:34:15 +08:00
|
|
|
#include "block.h"
|
2019-04-03 10:04:24 +08:00
|
|
|
#include "language.h"
|
|
|
|
#include "namespace.h"
|
2019-04-07 03:38:10 +08:00
|
|
|
#include "d-lang.h"
|
|
|
|
#include "gdb_obstack.h"
|
Don't include gdbarch.h from defs.h
I touched symtab.h and was surprised to see how many files were
rebuilt. I looked into it a bit, and found that defs.h includes
gdbarch.h, which in turn includes many things.
gdbarch.h is only needed by a minority ofthe files in gdb, so this
patch removes the include from defs.h and updates the fallout.
I did "wc -l" on the files in build/gdb/.deps; this patch reduces the
line count from 139935 to 137030; so there are definitely future
build-time savings here.
Note that while I configured with --enable-targets=all, it's possible
that some *-nat.c file needs an update. I could not test all of
these. The buildbot caught a few problems along these lines.
gdb/ChangeLog
2019-07-10 Tom Tromey <tom@tromey.com>
* defs.h: Don't include gdbarch.h.
* aarch64-ravenscar-thread.c, aarch64-tdep.c, alpha-bsd-tdep.h,
alpha-linux-tdep.c, alpha-mdebug-tdep.c, arch-utils.h, arm-tdep.h,
ax-general.c, btrace.c, buildsym-legacy.c, buildsym.h, c-lang.c,
cli/cli-decode.h, cli/cli-dump.c, cli/cli-script.h,
cli/cli-style.h, coff-pe-read.h, compile/compile-c-support.c,
compile/compile-cplus.h, compile/compile-loc2c.c, corefile.c,
cp-valprint.c, cris-linux-tdep.c, ctf.c, d-lang.c, d-namespace.c,
dcache.c, dicos-tdep.c, dictionary.c, disasm-selftests.c,
dummy-frame.c, dummy-frame.h, dwarf2-frame-tailcall.c,
dwarf2expr.c, expression.h, f-lang.c, frame-base.c,
frame-unwind.c, frv-linux-tdep.c, gdbarch-selftests.c, gdbtypes.h,
go-lang.c, hppa-nbsd-tdep.c, hppa-obsd-tdep.c, i386-dicos-tdep.c,
i386-tdep.h, ia64-vms-tdep.c, interps.h, language.c,
linux-record.c, location.h, m2-lang.c, m32r-linux-tdep.c,
mem-break.c, memattr.c, mn10300-linux-tdep.c, nios2-linux-tdep.c,
objfiles.h, opencl-lang.c, or1k-linux-tdep.c, p-lang.c,
parser-defs.h, ppc-tdep.h, probe.h, python/py-record-btrace.c,
record-btrace.c, record.h, regcache-dump.c, regcache.h,
riscv-fbsd-tdep.c, riscv-linux-tdep.c, rust-exp.y,
sh-linux-tdep.c, sh-nbsd-tdep.c, source-cache.c,
sparc-nbsd-tdep.c, sparc-obsd-tdep.c, sparc-ravenscar-thread.c,
sparc64-fbsd-tdep.c, std-regs.c, target-descriptions.h,
target-float.c, tic6x-linux-tdep.c, tilegx-linux-tdep.c, top.c,
tracefile.c, trad-frame.c, type-stack.h, ui-style.c, utils.c,
utils.h, valarith.c, valprint.c, varobj.c, x86-tdep.c,
xml-support.h, xtensa-linux-tdep.c, cli/cli-cmds.h: Update.
* s390-linux-nat.c, procfs.c, inf-ptrace.c: Likewise.
2019-06-10 05:21:02 +08:00
|
|
|
#include "gdbarch.h"
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
/* This returns the length of first component of NAME, which should be
|
|
|
|
the demangled name of a D variable/function/method/etc.
|
|
|
|
Specifically, it returns the index of the first dot forming the
|
|
|
|
boundary of the first component: so, given 'A.foo' or 'A.B.foo'
|
|
|
|
it returns the 1, and given 'foo', it returns 0. */
|
|
|
|
|
|
|
|
/* The character in NAME indexed by the return value is guaranteed to
|
|
|
|
always be either '.' or '\0'. */
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
d_find_first_component (const char *name)
|
|
|
|
{
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
for (;; ++index)
|
|
|
|
{
|
|
|
|
if (name[index] == '.' || name[index] == '\0')
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If NAME is the fully-qualified name of a D function/variable/method,
|
|
|
|
this returns the length of its entire prefix: all of the modules and
|
|
|
|
classes that make up its name. Given 'A.foo', it returns 1, given
|
|
|
|
'A.B.foo', it returns 4, given 'foo', it returns 0. */
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
d_entire_prefix_len (const char *name)
|
|
|
|
{
|
|
|
|
unsigned int current_len = d_find_first_component (name);
|
|
|
|
unsigned int previous_len = 0;
|
|
|
|
|
|
|
|
while (name[current_len] != '\0')
|
|
|
|
{
|
|
|
|
gdb_assert (name[current_len] == '.');
|
|
|
|
previous_len = current_len;
|
|
|
|
/* Skip the '.' */
|
|
|
|
current_len++;
|
|
|
|
current_len += d_find_first_component (name + current_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return previous_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up NAME in BLOCK's static block and in global blocks.
|
|
|
|
If SEARCH is non-zero, search through base classes for a matching
|
|
|
|
symbol. Other arguments are as in d_lookup_symbol_nonlocal. */
|
|
|
|
|
|
|
|
static struct block_symbol
|
2015-09-26 15:08:12 +08:00
|
|
|
d_lookup_symbol (const struct language_defn *langdef,
|
|
|
|
const char *name, const struct block *block,
|
2015-08-14 02:34:15 +08:00
|
|
|
const domain_enum domain, int search)
|
|
|
|
{
|
|
|
|
struct block_symbol sym;
|
|
|
|
|
|
|
|
sym = lookup_symbol_in_static_block (name, block, domain);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
2015-09-26 15:08:12 +08:00
|
|
|
/* If we didn't find a definition for a builtin type in the static block,
|
|
|
|
such as "ucent" which is a specialist type, search for it now. */
|
|
|
|
if (langdef != NULL && 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);
|
|
|
|
sym.block = NULL;
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2015-08-14 02:34:15 +08:00
|
|
|
sym = lookup_global_symbol (name, block, domain);
|
|
|
|
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
if (search)
|
|
|
|
{
|
2017-09-10 00:46:36 +08:00
|
|
|
std::string classname, nested;
|
2015-08-14 02:34:15 +08:00
|
|
|
unsigned int prefix_len;
|
|
|
|
struct block_symbol class_sym;
|
|
|
|
|
|
|
|
/* A simple lookup failed. Check if the symbol was defined in
|
|
|
|
a base class. */
|
|
|
|
|
|
|
|
/* Find the name of the class and the name of the method,
|
|
|
|
variable, etc. */
|
|
|
|
prefix_len = d_entire_prefix_len (name);
|
|
|
|
|
|
|
|
/* If no prefix was found, search "this". */
|
|
|
|
if (prefix_len == 0)
|
|
|
|
{
|
|
|
|
struct type *type;
|
|
|
|
struct block_symbol lang_this;
|
|
|
|
|
|
|
|
lang_this = lookup_language_this (language_def (language_d), block);
|
|
|
|
if (lang_this.symbol == NULL)
|
2019-03-23 06:53:12 +08:00
|
|
|
return {};
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (lang_this.symbol)));
|
2020-05-17 00:16:06 +08:00
|
|
|
classname = type->name ();
|
2017-09-10 00:46:36 +08:00
|
|
|
nested = name;
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The class name is everything up to and including PREFIX_LEN. */
|
2017-09-10 00:46:36 +08:00
|
|
|
classname = std::string (name, prefix_len);
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
/* The rest of the name is everything else past the initial scope
|
|
|
|
operator. */
|
2017-09-10 00:46:36 +08:00
|
|
|
nested = std::string (name + prefix_len + 1);
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup a class named CLASSNAME. If none is found, there is nothing
|
|
|
|
more that can be done. */
|
2017-09-10 00:46:36 +08:00
|
|
|
class_sym = lookup_global_symbol (classname.c_str (), block, domain);
|
2015-08-14 02:34:15 +08:00
|
|
|
if (class_sym.symbol == NULL)
|
2019-03-23 06:53:12 +08:00
|
|
|
return {};
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
/* Look for a symbol named NESTED in this class. */
|
|
|
|
sym = d_lookup_nested_symbol (SYMBOL_TYPE (class_sym.symbol),
|
2017-09-10 00:46:36 +08:00
|
|
|
nested.c_str (), block);
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up NAME in the D module MODULE. Other arguments are as in
|
|
|
|
d_lookup_symbol_nonlocal. If SEARCH is non-zero, search through
|
|
|
|
base classes for a matching symbol. */
|
|
|
|
|
|
|
|
static struct block_symbol
|
|
|
|
d_lookup_symbol_in_module (const char *module, const char *name,
|
|
|
|
const struct block *block,
|
|
|
|
const domain_enum domain, int search)
|
|
|
|
{
|
|
|
|
char *concatenated_name = NULL;
|
|
|
|
|
|
|
|
if (module[0] != '\0')
|
|
|
|
{
|
2015-09-26 02:08:06 +08:00
|
|
|
concatenated_name
|
|
|
|
= (char *) alloca (strlen (module) + strlen (name) + 2);
|
2015-08-14 02:34:15 +08:00
|
|
|
strcpy (concatenated_name, module);
|
|
|
|
strcat (concatenated_name, ".");
|
|
|
|
strcat (concatenated_name, name);
|
|
|
|
name = concatenated_name;
|
|
|
|
}
|
|
|
|
|
2015-09-26 15:08:12 +08:00
|
|
|
return d_lookup_symbol (NULL, name, block, domain, search);
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup NAME at module scope. SCOPE is the module that the current
|
|
|
|
function is defined within; only consider modules whose length is at
|
|
|
|
least SCOPE_LEN. Other arguments are as in d_lookup_symbol_nonlocal.
|
|
|
|
|
|
|
|
For example, if we're within a function A.B.f and looking for a
|
|
|
|
symbol x, this will get called with NAME = "x", SCOPE = "A.B", and
|
|
|
|
SCOPE_LEN = 0. It then calls itself with NAME and SCOPE the same,
|
|
|
|
but with SCOPE_LEN = 1. And then it calls itself with NAME and
|
|
|
|
SCOPE the same, but with SCOPE_LEN = 4. This third call looks for
|
|
|
|
"A.B.x"; if it doesn't find it, then the second call looks for "A.x",
|
|
|
|
and if that call fails, then the first call looks for "x". */
|
|
|
|
|
|
|
|
static struct block_symbol
|
2015-09-26 15:08:12 +08:00
|
|
|
lookup_module_scope (const struct language_defn *langdef,
|
|
|
|
const char *name, const struct block *block,
|
2015-08-14 02:34:15 +08:00
|
|
|
const domain_enum domain, const char *scope,
|
|
|
|
int scope_len)
|
|
|
|
{
|
|
|
|
char *module;
|
|
|
|
|
|
|
|
if (scope[scope_len] != '\0')
|
|
|
|
{
|
|
|
|
/* Recursively search for names in child modules first. */
|
|
|
|
|
|
|
|
struct block_symbol sym;
|
|
|
|
int new_scope_len = scope_len;
|
|
|
|
|
|
|
|
/* If the current scope is followed by ".", skip past that. */
|
|
|
|
if (new_scope_len != 0)
|
|
|
|
{
|
|
|
|
gdb_assert (scope[new_scope_len] == '.');
|
|
|
|
new_scope_len++;
|
|
|
|
}
|
|
|
|
new_scope_len += d_find_first_component (scope + new_scope_len);
|
2015-09-26 15:08:12 +08:00
|
|
|
sym = lookup_module_scope (langdef, name, block, domain,
|
2015-08-14 02:34:15 +08:00
|
|
|
scope, new_scope_len);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Okay, we didn't find a match in our children, so look for the
|
2015-09-26 15:08:12 +08:00
|
|
|
name in the current module.
|
|
|
|
|
|
|
|
If we there is no scope and we know we have a bare symbol, then short
|
|
|
|
circuit everything and call d_lookup_symbol directly.
|
|
|
|
This isn't an optimization, rather it allows us to pass LANGDEF which
|
|
|
|
is needed for primitive type lookup. */
|
|
|
|
|
|
|
|
if (scope_len == 0 && strchr (name, '.') == NULL)
|
|
|
|
return d_lookup_symbol (langdef, name, block, domain, 1);
|
2015-08-14 02:34:15 +08:00
|
|
|
|
2015-09-26 02:08:06 +08:00
|
|
|
module = (char *) alloca (scope_len + 1);
|
2015-08-14 02:34:15 +08:00
|
|
|
strncpy (module, scope, scope_len);
|
|
|
|
module[scope_len] = '\0';
|
|
|
|
return d_lookup_symbol_in_module (module, name,
|
|
|
|
block, domain, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search through the base classes of PARENT_TYPE for a symbol named
|
|
|
|
NAME in block BLOCK. */
|
|
|
|
|
|
|
|
static struct block_symbol
|
|
|
|
find_symbol_in_baseclass (struct type *parent_type, const char *name,
|
|
|
|
const struct block *block)
|
|
|
|
{
|
2019-03-23 06:53:12 +08:00
|
|
|
struct block_symbol sym = {};
|
2015-08-14 02:34:15 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < TYPE_N_BASECLASSES (parent_type); ++i)
|
|
|
|
{
|
|
|
|
struct type *base_type = TYPE_BASECLASS (parent_type, i);
|
|
|
|
const char *base_name = TYPE_BASECLASS_NAME (parent_type, i);
|
|
|
|
|
|
|
|
if (base_name == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Search this particular base class. */
|
|
|
|
sym = d_lookup_symbol_in_module (base_name, name, block,
|
|
|
|
VAR_DOMAIN, 0);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Now search all static file-level symbols. We have to do this for
|
|
|
|
things like typedefs in the class. First search in this symtab,
|
|
|
|
what we want is possibly there. */
|
2017-09-10 00:46:36 +08:00
|
|
|
std::string concatenated_name = std::string (base_name) + "." + name;
|
|
|
|
sym = lookup_symbol_in_static_block (concatenated_name.c_str (), block,
|
2015-08-14 02:34:15 +08:00
|
|
|
VAR_DOMAIN);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Nope. We now have to search all static blocks in all objfiles,
|
|
|
|
even if block != NULL, because there's no guarantees as to which
|
|
|
|
symtab the symbol we want is in. */
|
2017-09-10 00:46:36 +08:00
|
|
|
sym = lookup_static_symbol (concatenated_name.c_str (), VAR_DOMAIN);
|
2015-08-14 02:34:15 +08:00
|
|
|
if (sym.symbol != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If this class has base classes, search them next. */
|
|
|
|
base_type = check_typedef (base_type);
|
|
|
|
if (TYPE_N_BASECLASSES (base_type) > 0)
|
|
|
|
{
|
|
|
|
sym = find_symbol_in_baseclass (base_type, name, block);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up a symbol named NESTED_NAME that is nested inside the D
|
|
|
|
class or module given by PARENT_TYPE, from within the context
|
|
|
|
given by BLOCK. Return NULL if there is no such nested type. */
|
|
|
|
|
|
|
|
struct block_symbol
|
|
|
|
d_lookup_nested_symbol (struct type *parent_type,
|
|
|
|
const char *nested_name,
|
|
|
|
const struct block *block)
|
|
|
|
{
|
|
|
|
/* type_name_no_tag_required provides better error reporting using the
|
|
|
|
original type. */
|
|
|
|
struct type *saved_parent_type = parent_type;
|
|
|
|
|
|
|
|
parent_type = check_typedef (parent_type);
|
|
|
|
|
2020-05-15 01:46:38 +08:00
|
|
|
switch (parent_type->code ())
|
2015-08-14 02:34:15 +08:00
|
|
|
{
|
|
|
|
case TYPE_CODE_STRUCT:
|
|
|
|
case TYPE_CODE_UNION:
|
2015-08-18 03:45:42 +08:00
|
|
|
case TYPE_CODE_ENUM:
|
2015-08-14 02:34:15 +08:00
|
|
|
case TYPE_CODE_MODULE:
|
|
|
|
{
|
|
|
|
int size;
|
Remove type_name_no_tag and rename type_name_no_tag_or_error
type_name_no_tag is just a plain wrapper for TYPE_NAME now, so this
patch removes it. And, because tag names no longer exist, this
renames type_name_no_tag_or_error to type_name_or_error.
gdb/ChangeLog
2018-06-01 Tom Tromey <tom@tromey.com>
* valops.c (value_cast_structs, destructor_name_p): Update.
* symtab.c (gdb_mangle_name): Update.
* stabsread.c (define_symbol, read_cpp_abbrev, read_baseclasses):
Update.
* p-valprint.c (pascal_object_is_vtbl_ptr_type)
(pascal_object_print_value_fields, pascal_object_print_value):
Update.
* p-typeprint.c (pascal_type_print_derivation_info): Update.
* linespec.c (find_methods): Update.
* gdbtypes.h (type_name_no_tag): Remove.
(type_name_or_error): Rename from type_name_no_tag_or_error.
* gdbtypes.c (type_name_no_tag): Remove.
(type_name_or_error): Rename from type_name_no_tag_or_error.
(lookup_struct_elt_type, check_typedef): Update.
* expprint.c (print_subexp_standard): Update.
* dwarf2read.c (dwarf2_add_field, load_partial_dies): Update.
* d-namespace.c (d_lookup_nested_symbol): Update.
* cp-valprint.c (cp_is_vtbl_ptr_type, cp_print_value_fields)
(cp_print_class_member): Update.
* cp-namespace.c (cp_lookup_nested_symbol): Update.
* completer.c (add_struct_fields): Update.
* c-typeprint.c (cp_type_print_derivation_info)
(c_type_print_varspec_prefix, c_type_print_base_struct_union):
Update.
* ada-lang.c (parse_old_style_renaming, xget_renaming_scope)
(ada_prefer_type, ada_is_exception_sym): Update.
2018-04-18 03:51:25 +08:00
|
|
|
const char *parent_name = type_name_or_error (saved_parent_type);
|
2015-08-14 02:34:15 +08:00
|
|
|
struct block_symbol sym
|
|
|
|
= d_lookup_symbol_in_module (parent_name, nested_name,
|
|
|
|
block, VAR_DOMAIN, 0);
|
|
|
|
char *concatenated_name;
|
|
|
|
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
/* Now search all static file-level symbols. We have to do this
|
|
|
|
for things like typedefs in the class. We do not try to
|
|
|
|
guess any imported module as even the fully specified
|
|
|
|
module search is already not D compliant and more assumptions
|
|
|
|
could make it too magic. */
|
|
|
|
size = strlen (parent_name) + strlen (nested_name) + 2;
|
2015-09-26 02:08:06 +08:00
|
|
|
concatenated_name = (char *) alloca (size);
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
xsnprintf (concatenated_name, size, "%s.%s",
|
|
|
|
parent_name, nested_name);
|
|
|
|
|
|
|
|
sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
/* If no matching symbols were found, try searching any
|
|
|
|
base classes. */
|
|
|
|
return find_symbol_in_baseclass (parent_type, nested_name, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_CODE_FUNC:
|
|
|
|
case TYPE_CODE_METHOD:
|
2019-03-23 06:53:12 +08:00
|
|
|
return {};
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
gdb_assert_not_reached ("called with non-aggregate type.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for NAME by applying all import statements belonging to
|
2016-02-22 04:38:10 +08:00
|
|
|
BLOCK which are applicable in SCOPE. */
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
static struct block_symbol
|
|
|
|
d_lookup_symbol_imports (const char *scope, const char *name,
|
|
|
|
const struct block *block,
|
2016-02-22 04:38:10 +08:00
|
|
|
const domain_enum domain)
|
2015-08-14 02:34:15 +08:00
|
|
|
{
|
|
|
|
struct using_direct *current;
|
|
|
|
struct block_symbol sym;
|
|
|
|
|
|
|
|
/* First, try to find the symbol in the given module. */
|
|
|
|
sym = d_lookup_symbol_in_module (scope, name, block, domain, 1);
|
|
|
|
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
/* Go through the using directives. If any of them add new names to
|
|
|
|
the module we're searching in, see if we can find a match by
|
|
|
|
applying them. */
|
|
|
|
|
|
|
|
for (current = block_using (block);
|
|
|
|
current != NULL;
|
|
|
|
current = current->next)
|
|
|
|
{
|
|
|
|
const char **excludep;
|
2016-02-22 04:38:10 +08:00
|
|
|
|
|
|
|
/* If the import destination is the current scope then search it. */
|
|
|
|
if (!current->searched && strcmp (scope, current->import_dest) == 0)
|
2015-08-14 02:34:15 +08:00
|
|
|
{
|
|
|
|
/* Mark this import as searched so that the recursive call
|
|
|
|
does not search it again. */
|
2017-11-01 22:32:13 +08:00
|
|
|
scoped_restore restore_searched
|
|
|
|
= make_scoped_restore (¤t->searched, 1);
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
/* If there is an import of a single declaration, compare the
|
|
|
|
imported declaration (after optional renaming by its alias)
|
|
|
|
with the sought out name. If there is a match pass
|
|
|
|
current->import_src as MODULE to direct the search towards
|
|
|
|
the imported module. */
|
|
|
|
if (current->declaration
|
|
|
|
&& strcmp (name, current->alias
|
|
|
|
? current->alias : current->declaration) == 0)
|
|
|
|
sym = d_lookup_symbol_in_module (current->import_src,
|
|
|
|
current->declaration,
|
|
|
|
block, domain, 1);
|
|
|
|
|
|
|
|
/* If a symbol was found or this import statement was an import
|
|
|
|
declaration, the search of this import is complete. */
|
|
|
|
if (sym.symbol != NULL || current->declaration)
|
|
|
|
{
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not follow CURRENT if NAME matches its EXCLUDES. */
|
|
|
|
for (excludep = current->excludes; *excludep; excludep++)
|
|
|
|
if (strcmp (name, *excludep) == 0)
|
|
|
|
break;
|
|
|
|
if (*excludep)
|
2017-11-01 22:32:13 +08:00
|
|
|
continue;
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
/* If the import statement is creating an alias. */
|
|
|
|
if (current->alias != NULL)
|
|
|
|
{
|
|
|
|
if (strcmp (name, current->alias) == 0)
|
|
|
|
{
|
|
|
|
/* If the alias matches the sought name. Pass
|
|
|
|
current->import_src as the NAME to direct the
|
|
|
|
search towards the aliased module. */
|
2015-09-26 15:08:12 +08:00
|
|
|
sym = lookup_module_scope (NULL, current->import_src, block,
|
2015-08-14 02:34:15 +08:00
|
|
|
domain, scope, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the alias matches the first component of the
|
|
|
|
sought name, pass current->import_src as MODULE
|
|
|
|
to direct the search, skipping over the aliased
|
|
|
|
component in NAME. */
|
|
|
|
int name_scope = d_find_first_component (name);
|
|
|
|
|
|
|
|
if (name[name_scope] != '\0'
|
|
|
|
&& strncmp (name, current->alias, name_scope) == 0)
|
|
|
|
{
|
|
|
|
/* Skip the '.' */
|
|
|
|
name_scope++;
|
2016-02-28 17:25:55 +08:00
|
|
|
sym = d_lookup_symbol_in_module (current->import_src,
|
|
|
|
name + name_scope,
|
|
|
|
block, domain, 1);
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If this import statement creates no alias, pass
|
|
|
|
current->import_src as MODULE to direct the search
|
|
|
|
towards the imported module. */
|
2016-02-28 17:25:55 +08:00
|
|
|
sym = d_lookup_symbol_in_module (current->import_src,
|
|
|
|
name, block, domain, 1);
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 06:53:12 +08:00
|
|
|
return {};
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Searches for NAME in the current module, and by applying relevant
|
|
|
|
import statements belonging to BLOCK and its parents. SCOPE is the
|
|
|
|
module scope of the context in which the search is being evaluated. */
|
|
|
|
|
|
|
|
static struct block_symbol
|
|
|
|
d_lookup_symbol_module (const char *scope, const char *name,
|
|
|
|
const struct block *block,
|
|
|
|
const domain_enum domain)
|
|
|
|
{
|
|
|
|
struct block_symbol sym;
|
|
|
|
|
|
|
|
/* First, try to find the symbol in the given module. */
|
|
|
|
sym = d_lookup_symbol_in_module (scope, name,
|
|
|
|
block, domain, 1);
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
/* Search for name in modules imported to this and parent
|
|
|
|
blocks. */
|
|
|
|
while (block != NULL)
|
|
|
|
{
|
2016-02-22 04:38:10 +08:00
|
|
|
sym = d_lookup_symbol_imports (scope, name, block, domain);
|
2015-08-14 02:34:15 +08:00
|
|
|
|
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
block = BLOCK_SUPERBLOCK (block);
|
|
|
|
}
|
|
|
|
|
2019-03-23 06:53:12 +08:00
|
|
|
return {};
|
2015-08-14 02:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The D-specific version of name lookup for static and global names
|
|
|
|
This makes sure that names get looked for in all modules that are
|
|
|
|
in scope. NAME is the natural name of the symbol that we're looking
|
|
|
|
looking for, BLOCK is the block that we're searching within, DOMAIN
|
|
|
|
says what kind of symbols we're looking for, and if SYMTAB is non-NULL,
|
|
|
|
we should store the symtab where we found the symbol in it. */
|
|
|
|
|
|
|
|
struct block_symbol
|
|
|
|
d_lookup_symbol_nonlocal (const struct language_defn *langdef,
|
|
|
|
const char *name,
|
|
|
|
const struct block *block,
|
|
|
|
const domain_enum domain)
|
|
|
|
{
|
|
|
|
struct block_symbol sym;
|
|
|
|
const char *scope = block_scope (block);
|
|
|
|
|
2015-09-26 15:08:12 +08:00
|
|
|
sym = lookup_module_scope (langdef, name, block, domain, scope, 0);
|
2015-08-14 02:34:15 +08:00
|
|
|
if (sym.symbol != NULL)
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
return d_lookup_symbol_module (scope, name, block, domain);
|
|
|
|
}
|
|
|
|
|