From patchwork Wed Dec 17 09:26:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4297 Received: (qmail 20792 invoked by alias); 17 Dec 2014 09:27:33 -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 20779 invoked by uid 89); 17 Dec 2014 09:27:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f178.google.com Received: from mail-pd0-f178.google.com (HELO mail-pd0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 17 Dec 2014 09:27:30 +0000 Received: by mail-pd0-f178.google.com with SMTP id r10so15795519pdi.37 for ; Wed, 17 Dec 2014 01:27:28 -0800 (PST) X-Received: by 10.70.27.225 with SMTP id w1mr68620461pdg.40.1418808448796; Wed, 17 Dec 2014 01:27:28 -0800 (PST) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by mx.google.com with ESMTPSA id x8sm3378056pdi.7.2014.12.17.01.27.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 01:27:27 -0800 (PST) From: Doug Evans To: gdb-patches@sourceware.org Subject: Re: [PATCH 5/5] cp-namespace.c cleanup pass: remove redundancies in cp_lookup_symbol_nonlocal References: Date: Wed, 17 Dec 2014 01:26:36 -0800 In-Reply-To: (Doug Evans's message of "Sun, 14 Dec 2014 22:25:09 -0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Doug Evans writes: > Hi. > > This patch removes some redundancies in cp_lookup_symbol_nonlocal. > > It also makes cp_lookup_symbol_nonlocal way easier for me to understand. > cp_lookup_symbol_nonlocal basically just calls two functions: > > sym = lookup_namespace_scope (name, block, > domain, scope, 0); > if (sym != NULL) > return sym; > > return cp_lookup_symbol_namespace (scope, name, > block, domain); > > One has to dig to understand what's going on here because > the names lookup_namespace_scope and cp_lookup_symbol_namespace > are quite similar and a bit opaque. > > The redundancy is that the first thing cp_lookup_symbol_namespace does > is repeat what we've already done in the call to lookup_namespace_scope. > > So this patch just factors out the cp_lookup_symbol_via_imports loop > and calls that from both cp_lookup_symbol_namespace and > cp_lookup_symbol_nonlocal. Hi. Here is a revised patch for current HEAD. 2014-12-17 Doug Evans * cp-namespace.c (cp_lookup_symbol_via_all_imports): New function. (cp_lookup_symbol_namespace): Call it. (cp_lookup_symbol_nonlocal): Ditto. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index c58efa4..6e256e1 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -678,12 +678,35 @@ cp_lookup_symbol_imports_or_template (const char *scope, return result; } +/* Search for NAME by applying relevant import statements belonging to BLOCK + and its parents. SCOPE is the namespace scope of the context in which the + search is being evaluated. */ + +static struct symbol * +cp_lookup_symbol_via_all_imports (const char *scope, const char *name, + const struct block *block, + const domain_enum domain) +{ + struct symbol *sym; + + while (block != NULL) + { + sym = cp_lookup_symbol_via_imports (scope, name, block, domain, 0, 0, 1); + if (sym) + return sym; + + block = BLOCK_SUPERBLOCK (block); + } + + return NULL; +} + /* Searches for NAME in the current namespace, and by applying relevant import statements belonging to BLOCK and its parents. SCOPE is the namespace scope of the context in which the search is being evaluated. */ -struct symbol* +struct symbol * cp_lookup_symbol_namespace (const char *scope, const char *name, const struct block *block, @@ -700,46 +723,19 @@ cp_lookup_symbol_namespace (const char *scope, } /* First, try to find the symbol in the given namespace. */ - sym = cp_lookup_symbol_in_namespace (scope, name, - block, domain, 1); - if (sym != NULL) - { - if (symbol_lookup_debug) - { - fprintf_unfiltered (gdb_stdlog, - "cp_lookup_symbol_namespace (...) = %s\n", - host_address_to_string (sym)); - } - return sym; - } - - /* Search for name in namespaces imported to this and parent - blocks. */ - while (block != NULL) - { - sym = cp_lookup_symbol_via_imports (scope, name, block, - domain, 0, 0, 1); - - if (sym) - { - if (symbol_lookup_debug) - { - fprintf_unfiltered (gdb_stdlog, - "cp_lookup_symbol_namespace (...) = %s\n", - host_address_to_string (sym)); - } - return sym; - } + sym = cp_lookup_symbol_in_namespace (scope, name, block, domain, 1); - block = BLOCK_SUPERBLOCK (block); - } + /* Search for name in namespaces imported to this and parent blocks. */ + if (sym == NULL) + sym = cp_lookup_symbol_via_all_imports (scope, name, block, domain); if (symbol_lookup_debug) { fprintf_unfiltered (gdb_stdlog, - "cp_lookup_symbol_namespace (...) = NULL\n"); + "cp_lookup_symbol_namespace (...) = %s\n", + sym != NULL ? host_address_to_string (sym) : "NULL"); } - return NULL; + return sym; } /* Lookup NAME at namespace scope (or, in C terms, in static and @@ -819,19 +815,14 @@ cp_lookup_symbol_nonlocal (const char *name, domain_name (domain)); } + /* First, try to find the symbol in the given namespace, and all + containing namespaces. */ sym = lookup_namespace_scope (name, block, domain, scope, 0); - if (sym != NULL) - { - if (symbol_lookup_debug) - { - fprintf_unfiltered (gdb_stdlog, - "cp_lookup_symbol_nonlocal (...) = %s\n", - host_address_to_string (sym)); - } - return sym; - } - sym = cp_lookup_symbol_namespace (scope, name, block, domain); + /* Search for name in namespaces imported to this and parent blocks. */ + if (sym == NULL) + sym = cp_lookup_symbol_via_all_imports (scope, name, block, domain); + if (symbol_lookup_debug) { fprintf_unfiltered (gdb_stdlog,