X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=gdb%2Fd-namespace.c;h=768ba23f014677b44cbe665b879488a2a87a13f2;hb=29298bf66f62f2f6c1efb0685623fbc29dfade90;hp=9e0071089ee60394ad5218e66451b9a6972cf297;hpb=9a3c826307ae6ad4dd6fbd72431e7d9d4947f1dd;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index 9e0071089e..768ba23f01 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -1,6 +1,6 @@ /* Helper routines for D support in GDB. - Copyright (C) 2014-2015 Free Software Foundation, Inc. + Copyright (C) 2014-2019 Free Software Foundation, Inc. This file is part of GDB. @@ -24,6 +24,7 @@ #include "namespace.h" #include "d-lang.h" #include "gdb_obstack.h" +#include "gdbarch.h" /* This returns the length of first component of NAME, which should be the demangled name of a D variable/function/method/etc. @@ -74,7 +75,8 @@ d_entire_prefix_len (const char *name) symbol. Other arguments are as in d_lookup_symbol_nonlocal. */ static struct block_symbol -d_lookup_symbol (const char *name, const struct block *block, +d_lookup_symbol (const struct language_defn *langdef, + const char *name, const struct block *block, const domain_enum domain, int search) { struct block_symbol sym; @@ -83,6 +85,23 @@ d_lookup_symbol (const char *name, const struct block *block, if (sym.symbol != NULL) return sym; + /* 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; + } + sym = lookup_global_symbol (name, block, domain); if (sym.symbol != NULL) @@ -90,16 +109,13 @@ d_lookup_symbol (const char *name, const struct block *block, if (search) { - char *classname, *nested; + std::string classname, nested; unsigned int prefix_len; - struct cleanup *cleanup; struct block_symbol class_sym; /* A simple lookup failed. Check if the symbol was defined in a base class. */ - cleanup = make_cleanup (null_cleanup, NULL); - /* Find the name of the class and the name of the method, variable, etc. */ prefix_len = d_entire_prefix_len (name); @@ -112,42 +128,31 @@ d_lookup_symbol (const char *name, const struct block *block, lang_this = lookup_language_this (language_def (language_d), block); if (lang_this.symbol == NULL) - { - do_cleanups (cleanup); - return (struct block_symbol) {NULL, NULL}; - } + return {}; type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (lang_this.symbol))); - classname = xstrdup (TYPE_NAME (type)); - nested = xstrdup (name); + classname = TYPE_NAME (type); + nested = name; } else { /* The class name is everything up to and including PREFIX_LEN. */ - classname = savestring (name, prefix_len); + classname = std::string (name, prefix_len); /* The rest of the name is everything else past the initial scope operator. */ - nested = xstrdup (name + prefix_len + 1); + nested = std::string (name + prefix_len + 1); } - /* Add cleanups to free memory for these strings. */ - make_cleanup (xfree, classname); - make_cleanup (xfree, nested); - /* Lookup a class named CLASSNAME. If none is found, there is nothing more that can be done. */ - class_sym = lookup_global_symbol (classname, block, domain); + class_sym = lookup_global_symbol (classname.c_str (), block, domain); if (class_sym.symbol == NULL) - { - do_cleanups (cleanup); - return (struct block_symbol) {NULL, NULL}; - } + return {}; /* Look for a symbol named NESTED in this class. */ sym = d_lookup_nested_symbol (SYMBOL_TYPE (class_sym.symbol), - nested, block); - do_cleanups (cleanup); + nested.c_str (), block); } return sym; @@ -174,7 +179,7 @@ d_lookup_symbol_in_module (const char *module, const char *name, name = concatenated_name; } - return d_lookup_symbol (name, block, domain, search); + return d_lookup_symbol (NULL, name, block, domain, search); } /* Lookup NAME at module scope. SCOPE is the module that the current @@ -190,7 +195,8 @@ d_lookup_symbol_in_module (const char *module, const char *name, and if that call fails, then the first call looks for "x". */ static struct block_symbol -lookup_module_scope (const char *name, const struct block *block, +lookup_module_scope (const struct language_defn *langdef, + const char *name, const struct block *block, const domain_enum domain, const char *scope, int scope_len) { @@ -210,14 +216,22 @@ lookup_module_scope (const char *name, const struct block *block, new_scope_len++; } new_scope_len += d_find_first_component (scope + new_scope_len); - sym = lookup_module_scope (name, block, domain, + sym = lookup_module_scope (langdef, name, block, domain, scope, new_scope_len); if (sym.symbol != NULL) return sym; } /* Okay, we didn't find a match in our children, so look for the - name in the current module. */ + 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); module = (char *) alloca (scope_len + 1); strncpy (module, scope, scope_len); @@ -233,18 +247,11 @@ static struct block_symbol find_symbol_in_baseclass (struct type *parent_type, const char *name, const struct block *block) { - char *concatenated_name = NULL; - struct block_symbol sym; - struct cleanup *cleanup; + struct block_symbol sym = {}; int i; - sym.symbol = NULL; - sym.block = NULL; - cleanup = make_cleanup (free_current_contents, &concatenated_name); - for (i = 0; i < TYPE_N_BASECLASSES (parent_type); ++i) { - size_t len; struct type *base_type = TYPE_BASECLASS (parent_type, i); const char *base_name = TYPE_BASECLASS_NAME (parent_type, i); @@ -260,10 +267,8 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, /* 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. */ - len = strlen (base_name) + strlen (name) + 2; - concatenated_name = (char *) xrealloc (concatenated_name, len); - xsnprintf (concatenated_name, len, "%s.%s", base_name, name); - sym = lookup_symbol_in_static_block (concatenated_name, block, + std::string concatenated_name = std::string (base_name) + "." + name; + sym = lookup_symbol_in_static_block (concatenated_name.c_str (), block, VAR_DOMAIN); if (sym.symbol != NULL) break; @@ -271,7 +276,7 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, /* 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. */ - sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN); + sym = lookup_static_symbol (concatenated_name.c_str (), VAR_DOMAIN); if (sym.symbol != NULL) break; @@ -285,7 +290,6 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, } } - do_cleanups (cleanup); return sym; } @@ -312,7 +316,7 @@ d_lookup_nested_symbol (struct type *parent_type, case TYPE_CODE_MODULE: { int size; - const char *parent_name = type_name_no_tag_or_error (saved_parent_type); + const char *parent_name = type_name_or_error (saved_parent_type); struct block_symbol sym = d_lookup_symbol_in_module (parent_name, nested_name, block, VAR_DOMAIN, 0); @@ -343,50 +347,23 @@ d_lookup_nested_symbol (struct type *parent_type, case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: - return (struct block_symbol) {NULL, NULL}; + return {}; default: gdb_assert_not_reached ("called with non-aggregate type."); } } -/* Used for cleanups to reset the "searched" flag incase - of an error. */ - -static void -reset_directive_searched (void *data) -{ - struct using_direct *direct = (struct using_direct *) data; - direct->searched = 0; -} - /* Search for NAME by applying all import statements belonging to - BLOCK which are applicable in SCOPE. - - If SEARCH_PARENTS the search will include imports which are - applicable in parents of SCOPE. - Example: - - module A; - import X; - void B() { - import Y; - } - - If SCOPE is "A.B" and SEARCH_PARENTS is true, the imports of - modules X and Y will be considered. If SEARCH_PARENTS is false - only the import of Y is considered. */ + BLOCK which are applicable in SCOPE. */ static struct block_symbol d_lookup_symbol_imports (const char *scope, const char *name, const struct block *block, - const domain_enum domain, - const int search_parents) + const domain_enum domain) { struct using_direct *current; struct block_symbol sym; - int directive_match; - struct cleanup *searched_cleanup; /* First, try to find the symbol in the given module. */ sym = d_lookup_symbol_in_module (scope, name, block, domain, 1); @@ -403,24 +380,14 @@ d_lookup_symbol_imports (const char *scope, const char *name, current = current->next) { const char **excludep; - int len = strlen (current->import_dest); - - directive_match = (search_parents - ? (strncmp (scope, current->import_dest, len) == 0 - && (len == 0 - || scope[len] == '.' - || scope[len] == '\0')) - : strcmp (scope, current->import_dest) == 0); - - /* If the import destination is the current scope or one of its - ancestors then it is applicable. */ - if (directive_match && !current->searched) + + /* If the import destination is the current scope then search it. */ + if (!current->searched && strcmp (scope, current->import_dest) == 0) { /* Mark this import as searched so that the recursive call does not search it again. */ - current->searched = 1; - searched_cleanup = make_cleanup (reset_directive_searched, - current); + scoped_restore restore_searched + = make_scoped_restore (¤t->searched, 1); /* If there is an import of a single declaration, compare the imported declaration (after optional renaming by its alias) @@ -438,9 +405,6 @@ d_lookup_symbol_imports (const char *scope, const char *name, declaration, the search of this import is complete. */ if (sym.symbol != NULL || current->declaration) { - current->searched = 0; - discard_cleanups (searched_cleanup); - if (sym.symbol != NULL) return sym; @@ -452,10 +416,7 @@ d_lookup_symbol_imports (const char *scope, const char *name, if (strcmp (name, *excludep) == 0) break; if (*excludep) - { - discard_cleanups (searched_cleanup); - continue; - } + continue; /* If the import statement is creating an alias. */ if (current->alias != NULL) @@ -465,7 +426,7 @@ d_lookup_symbol_imports (const char *scope, const char *name, /* If the alias matches the sought name. Pass current->import_src as the NAME to direct the search towards the aliased module. */ - sym = lookup_module_scope (current->import_src, block, + sym = lookup_module_scope (NULL, current->import_src, block, domain, scope, 0); } else @@ -481,9 +442,9 @@ d_lookup_symbol_imports (const char *scope, const char *name, { /* Skip the '.' */ name_scope++; - sym = d_lookup_symbol_imports (current->import_src, - name + name_scope, - block, domain, 0); + sym = d_lookup_symbol_in_module (current->import_src, + name + name_scope, + block, domain, 1); } } } @@ -492,18 +453,16 @@ d_lookup_symbol_imports (const char *scope, const char *name, /* If this import statement creates no alias, pass current->import_src as MODULE to direct the search towards the imported module. */ - sym = d_lookup_symbol_imports (current->import_src, - name, block, domain, 0); + sym = d_lookup_symbol_in_module (current->import_src, + name, block, domain, 1); } - current->searched = 0; - discard_cleanups (searched_cleanup); if (sym.symbol != NULL) return sym; } } - return (struct block_symbol) {NULL, NULL}; + return {}; } /* Searches for NAME in the current module, and by applying relevant @@ -527,7 +486,7 @@ d_lookup_symbol_module (const char *scope, const char *name, blocks. */ while (block != NULL) { - sym = d_lookup_symbol_imports (scope, name, block, domain, 1); + sym = d_lookup_symbol_imports (scope, name, block, domain); if (sym.symbol != NULL) return sym; @@ -535,7 +494,7 @@ d_lookup_symbol_module (const char *scope, const char *name, block = BLOCK_SUPERBLOCK (block); } - return (struct block_symbol) {NULL, NULL}; + return {}; } /* The D-specific version of name lookup for static and global names @@ -554,7 +513,7 @@ d_lookup_symbol_nonlocal (const struct language_defn *langdef, struct block_symbol sym; const char *scope = block_scope (block); - sym = lookup_module_scope (name, block, domain, scope, 0); + sym = lookup_module_scope (langdef, name, block, domain, scope, 0); if (sym.symbol != NULL) return sym;