public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Split up a big 'if' in symtab.c
@ 2024-01-28 23:43 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-01-28 23:43 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d4f48c1e26a550a8b3ba8312268b706454b00ee2

commit d4f48c1e26a550a8b3ba8312268b706454b00ee2
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Mar 10 11:48:25 2023 -0700

    Split up a big 'if' in symtab.c
    
    global_symbol_searcher::add_matching_symbols in symtab.c has a
    gigantic 'if' statement -- 33 lines of conditional expression.  This
    patch splits it up into a series of separate 'if's.

Diff:
---
 gdb/symtab.c | 83 ++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 50 insertions(+), 33 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index b408941f998..2020210c5f4 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4855,39 +4855,56 @@ global_symbol_searcher::add_matching_symbols
 	      /* Check first sole REAL_SYMTAB->FILENAME.  It does
 		 not need to be a substring of symtab_to_fullname as
 		 it may contain "./" etc.  */
-	      if ((file_matches (real_symtab->filename, filenames, false)
-		   || ((basenames_may_differ
-			|| file_matches (lbasename (real_symtab->filename),
-					 filenames, true))
-		       && file_matches (symtab_to_fullname (real_symtab),
-					filenames, false)))
-		  && ((!preg.has_value ()
-		       || preg->exec (sym->natural_name (), 0,
-				      NULL, 0) == 0)
-		      && ((kind == VARIABLES_DOMAIN
-			   && sym->aclass () != LOC_TYPEDEF
-			   && sym->aclass () != LOC_UNRESOLVED
-			   && sym->aclass () != LOC_BLOCK
-			   /* LOC_CONST can be used for more than
-			      just enums, e.g., c++ static const
-			      members.  We only want to skip enums
-			      here.  */
-			   && !(sym->aclass () == LOC_CONST
-				&& (sym->type ()->code ()
-				    == TYPE_CODE_ENUM))
-			   && (!treg.has_value ()
-			       || treg_matches_sym_type_name (*treg, sym)))
-			  || (kind == FUNCTIONS_DOMAIN
-			      && sym->aclass () == LOC_BLOCK
-			      && (!treg.has_value ()
-				  || treg_matches_sym_type_name (*treg,
-								 sym)))
-			  || (kind == TYPES_DOMAIN
-			      && sym->aclass () == LOC_TYPEDEF
-			      && sym->domain () != MODULE_DOMAIN)
-			  || (kind == MODULES_DOMAIN
-			      && sym->domain () == MODULE_DOMAIN
-			      && sym->line () != 0))))
+	      if (!(file_matches (real_symtab->filename, filenames, false)
+		    || ((basenames_may_differ
+			 || file_matches (lbasename (real_symtab->filename),
+					  filenames, true))
+			&& file_matches (symtab_to_fullname (real_symtab),
+					 filenames, false))))
+		continue;
+
+	      if (preg.has_value () && !preg->exec (sym->natural_name (), 0,
+						    nullptr, 0) == 0)
+		continue;
+
+	      bool matches = false;
+	      if (!matches && kind == VARIABLES_DOMAIN)
+		{
+		  if (sym->aclass () != LOC_TYPEDEF
+		      && sym->aclass () != LOC_UNRESOLVED
+		      && sym->aclass () != LOC_BLOCK
+		      /* LOC_CONST can be used for more than
+			 just enums, e.g., c++ static const
+			 members.  We only want to skip enums
+			 here.  */
+		      && !(sym->aclass () == LOC_CONST
+			   && (sym->type ()->code ()
+			       == TYPE_CODE_ENUM))
+		      && (!treg.has_value ()
+			  || treg_matches_sym_type_name (*treg, sym)))
+		    matches = true;
+		}
+	      if (!matches && kind == FUNCTIONS_DOMAIN)
+		{
+		  if (sym->aclass () == LOC_BLOCK
+		      && (!treg.has_value ()
+			  || treg_matches_sym_type_name (*treg,
+							 sym)))
+		    matches = true;
+		}
+	      if (!matches && kind == TYPES_DOMAIN)
+		{
+		  if (sym->aclass () == LOC_TYPEDEF
+		      && sym->domain () != MODULE_DOMAIN)
+		    matches = true;
+		}
+	      if (!matches && kind == MODULES_DOMAIN)
+		{
+		  if (sym->domain () == MODULE_DOMAIN
+		      && sym->line () != 0)
+		    matches = true;
+		}
+	      if (matches)
 		{
 		  if (result_set->size () < m_max_search_results)
 		    {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-28 23:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 23:43 [binutils-gdb] Split up a big 'if' in symtab.c Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).