From patchwork Sun Oct 11 12:01:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 9047 Received: (qmail 94449 invoked by alias); 11 Oct 2015 12:01:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 94434 invoked by uid 89); 11 Oct 2015 12:01:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f172.google.com Received: from mail-wi0-f172.google.com (HELO mail-wi0-f172.google.com) (209.85.212.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 11 Oct 2015 12:01:13 +0000 Received: by wiclk2 with SMTP id lk2so119650144wic.1 for ; Sun, 11 Oct 2015 05:01:10 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.114.104 with SMTP id jf8mr27623469wjb.155.1444564870303; Sun, 11 Oct 2015 05:01:10 -0700 (PDT) Received: by 10.27.191.196 with HTTP; Sun, 11 Oct 2015 05:01:10 -0700 (PDT) Date: Sun, 11 Oct 2015 14:01:10 +0200 Message-ID: Subject: [PATCH 2/2] [D] Remove search_parents parameter from d_lookup_symbol_imports From: Iain Buclaw To: GDB Patches X-IsSubscribed: yes Whilst looking at part one, a moment of insight came to me and I realized this code is completely nonsensical. For a start, when importing modules, you don't gain access to all parent packages of the given module. To add some confusion, even the comment was wrong. It doesn't even cater for the example given (it's d_lookup_symbol_module that walks up each block scope). I feel embarrassed it didn't come to me before. :-) Regards, Iain. gdb/ChangeLog: * d-namespace.c (d_lookup_symbol_imports): Remove argument 'search_parents'. All callers updated. --- diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index da5da58..1524047 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -388,31 +388,15 @@ reset_directive_searched (void *data) } /* 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. */ @@ -430,18 +414,9 @@ 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. */ @@ -554,7 +529,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;