From patchwork Mon Dec 15 06:25:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4249 Received: (qmail 1328 invoked by alias); 15 Dec 2014 06:26:06 -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 1319 invoked by uid 89); 15 Dec 2014 06:26:05 -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-pa0-f51.google.com Received: from mail-pa0-f51.google.com (HELO mail-pa0-f51.google.com) (209.85.220.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 15 Dec 2014 06:26:04 +0000 Received: by mail-pa0-f51.google.com with SMTP id ey11so11138804pad.24 for ; Sun, 14 Dec 2014 22:26:02 -0800 (PST) X-Received: by 10.68.217.231 with SMTP id pb7mr48892521pbc.124.1418624762738; Sun, 14 Dec 2014 22:26:02 -0800 (PST) Received: from sspiff.org (173-13-178-50-sfba.hfc.comcastbusiness.net. [173.13.178.50]) by mx.google.com with ESMTPSA id fn5sm8110456pdb.55.2014.12.14.22.26.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Dec 2014 22:26:01 -0800 (PST) Received: by sspiff.org (sSMTP sendmail emulation); Sun, 14 Dec 2014 22:25:09 -0800 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH 5/5] cp-namespace.c cleanup pass: remove redundancies in cp_lookup_symbol_nonlocal Date: Sun, 14 Dec 2014 22:25:09 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes 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. 2014-12-14 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 045abc5..1caa3a1 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -646,12 +646,35 @@ cp_lookup_symbol_imports_or_template (const char *scope, return cp_lookup_symbol_via_imports (scope, name, block, domain, 0, 1, 1); } +/* 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, @@ -660,25 +683,12 @@ cp_lookup_symbol_namespace (const char *scope, struct symbol *sym; /* First, try to find the symbol in the given namespace. */ - sym = cp_lookup_symbol_in_namespace (scope, name, - block, domain, 1); + sym = cp_lookup_symbol_in_namespace (scope, name, block, domain, 1); if (sym != NULL) 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) - return sym; - - block = BLOCK_SUPERBLOCK (block); - } - - return NULL; + /* Search for name in namespaces imported to this and parent blocks. */ + return cp_lookup_symbol_via_all_imports (scope, name, block, domain); } /* Lookup NAME at namespace scope (or, in C terms, in static and @@ -749,13 +759,14 @@ cp_lookup_symbol_nonlocal (const char *name, struct symbol *sym; const char *scope = block_scope (block); - sym = lookup_namespace_scope (name, block, - domain, scope, 0); + /* 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) return sym; - return cp_lookup_symbol_namespace (scope, name, - block, domain); + /* Search for name in namespaces imported to this and parent blocks. */ + return cp_lookup_symbol_via_all_imports (scope, name, block, domain); } /* Search through the base classes of PARENT_TYPE for a base class