From patchwork Wed Dec 10 18:25:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4150 Received: (qmail 1000 invoked by alias); 10 Dec 2014 18:26:21 -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 985 invoked by uid 89); 10 Dec 2014 18:26:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pa0-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 10 Dec 2014 18:26:15 +0000 Received: by mail-pa0-f46.google.com with SMTP id lf10so2670853pab.5 for ; Wed, 10 Dec 2014 10:26:13 -0800 (PST) X-Received: by 10.68.65.16 with SMTP id t16mr9731920pbs.70.1418235972814; Wed, 10 Dec 2014 10:26:12 -0800 (PST) Received: from seba.sebabeach.org.gmail.com (173-13-178-50-sfba.hfc.comcastbusiness.net. [173.13.178.50]) by mx.google.com with ESMTPSA id sr4sm1691153pbc.28.2014.12.10.10.26.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Dec 2014 10:26:11 -0800 (PST) From: Doug Evans To: gdb-patches@sourceware.org Subject: [COMMITTED PATCH] lookup_symbol_file: Move next to only caller. Date: Wed, 10 Dec 2014 10:25:22 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. It's easier to reason about this code if related functions are grouped together. Here the only caller of lookup_symbol_file is quite far away. I moved it instead of its caller because further patches refactor this, but this move is standalone enough. 2014-12-10 Doug Evans * cp-namespace.c (lookup_symbol_file): Move next to only caller. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 7e971e0..a1abc91 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -38,12 +38,6 @@ static struct symbol *lookup_namespace_scope (const char *name, const char *scope, int scope_len); -static struct symbol *lookup_symbol_file (const char *name, - const struct block *block, - const domain_enum domain, - int anonymous_namespace, - int search); - static struct type *cp_lookup_transparent_type_loop (const char *name, const char *scope, int scope_len); @@ -237,6 +231,112 @@ cp_lookup_symbol_nonlocal (const char *name, block, domain); } +/* Look up NAME in BLOCK's static block and in global blocks. If + ANONYMOUS_NAMESPACE is nonzero, the symbol in question is located + within an anonymous namespace. If SEARCH is non-zero, search through + base classes for a matching symbol. Other arguments are as in + cp_lookup_symbol_nonlocal. */ + +static struct symbol * +lookup_symbol_file (const char *name, + const struct block *block, + const domain_enum domain, + int anonymous_namespace, int search) +{ + struct symbol *sym = NULL; + + sym = lookup_symbol_in_static_block (name, block, domain); + if (sym != NULL) + return sym; + + if (anonymous_namespace) + { + /* Symbols defined in anonymous namespaces have external linkage + but should be treated as local to a single file nonetheless. + So we only search the current file's global block. */ + + const struct block *global_block = block_global_block (block); + + if (global_block != NULL) + sym = lookup_symbol_in_block (name, global_block, domain); + } + else + { + sym = lookup_global_symbol (name, block, domain); + } + + if (sym != NULL) + return sym; + + if (search) + { + char *klass, *nested; + unsigned int prefix_len; + struct cleanup *cleanup; + struct symbol *klass_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 = cp_entire_prefix_len (name); + + /* If no prefix was found, search "this". */ + if (prefix_len == 0) + { + struct type *type; + struct symbol *this; + + this = lookup_language_this (language_def (language_cplus), block); + if (this == NULL) + { + do_cleanups (cleanup); + return NULL; + } + + type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (this))); + /* If TYPE_NAME is NULL, abandon trying to find this symbol. + This can happen for lambda functions compiled with clang++, + which outputs no name for the container class. */ + if (TYPE_NAME (type) == NULL) + return NULL; + klass = xstrdup (TYPE_NAME (type)); + nested = xstrdup (name); + } + else + { + /* The class name is everything up to and including PREFIX_LEN. */ + klass = savestring (name, prefix_len); + + /* The rest of the name is everything else past the initial scope + operator. */ + nested = xstrdup (name + prefix_len + 2); + } + + /* Add cleanups to free memory for these strings. */ + make_cleanup (xfree, klass); + make_cleanup (xfree, nested); + + /* Lookup a class named KLASS. If none is found, there is nothing + more that can be done. */ + klass_sym = lookup_global_symbol (klass, block, domain); + if (klass_sym == NULL) + { + do_cleanups (cleanup); + return NULL; + } + + /* Look for a symbol named NESTED in this class. */ + sym = cp_lookup_nested_symbol (SYMBOL_TYPE (klass_sym), nested, block); + do_cleanups (cleanup); + } + + return sym; +} + /* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in cp_lookup_symbol_nonlocal. If SEARCH is non-zero, search through base classes for a matching symbol. */ @@ -599,112 +699,6 @@ lookup_namespace_scope (const char *name, block, domain, 1); } -/* Look up NAME in BLOCK's static block and in global blocks. If - ANONYMOUS_NAMESPACE is nonzero, the symbol in question is located - within an anonymous namespace. If SEARCH is non-zero, search through - base classes for a matching symbol. Other arguments are as in - cp_lookup_symbol_nonlocal. */ - -static struct symbol * -lookup_symbol_file (const char *name, - const struct block *block, - const domain_enum domain, - int anonymous_namespace, int search) -{ - struct symbol *sym = NULL; - - sym = lookup_symbol_in_static_block (name, block, domain); - if (sym != NULL) - return sym; - - if (anonymous_namespace) - { - /* Symbols defined in anonymous namespaces have external linkage - but should be treated as local to a single file nonetheless. - So we only search the current file's global block. */ - - const struct block *global_block = block_global_block (block); - - if (global_block != NULL) - sym = lookup_symbol_in_block (name, global_block, domain); - } - else - { - sym = lookup_global_symbol (name, block, domain); - } - - if (sym != NULL) - return sym; - - if (search) - { - char *klass, *nested; - unsigned int prefix_len; - struct cleanup *cleanup; - struct symbol *klass_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 = cp_entire_prefix_len (name); - - /* If no prefix was found, search "this". */ - if (prefix_len == 0) - { - struct type *type; - struct symbol *this; - - this = lookup_language_this (language_def (language_cplus), block); - if (this == NULL) - { - do_cleanups (cleanup); - return NULL; - } - - type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (this))); - /* If TYPE_NAME is NULL, abandon trying to find this symbol. - This can happen for lambda functions compiled with clang++, - which outputs no name for the container class. */ - if (TYPE_NAME (type) == NULL) - return NULL; - klass = xstrdup (TYPE_NAME (type)); - nested = xstrdup (name); - } - else - { - /* The class name is everything up to and including PREFIX_LEN. */ - klass = savestring (name, prefix_len); - - /* The rest of the name is everything else past the initial scope - operator. */ - nested = xstrdup (name + prefix_len + 2); - } - - /* Add cleanups to free memory for these strings. */ - make_cleanup (xfree, klass); - make_cleanup (xfree, nested); - - /* Lookup a class named KLASS. If none is found, there is nothing - more that can be done. */ - klass_sym = lookup_global_symbol (klass, block, domain); - if (klass_sym == NULL) - { - do_cleanups (cleanup); - return NULL; - } - - /* Look for a symbol named NESTED in this class. */ - sym = cp_lookup_nested_symbol (SYMBOL_TYPE (klass_sym), nested, block); - do_cleanups (cleanup); - } - - return sym; -} - /* Search through the base classes of PARENT_TYPE for a base class named NAME and return its type. If not found, return NULL. */