Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 4/7] Rename lookup_struct_typedef
Date: Sun, 16 Nov 2025 18:27:03 -0700	[thread overview]
Message-ID: <20251117012752.2657208-5-tom@tromey.com> (raw)
In-Reply-To: <20251117012752.2657208-1-tom@tromey.com>

The helper function lookup_struct_typedef is only ever called with
"noerr=1".  This patch removes the parameter, changes the name, and
removes some unnecessary code.
---
 gdb/c-exp.y     |  4 ++--
 gdb/objc-lang.c | 31 +++++++------------------------
 gdb/objc-lang.h |  5 ++---
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 9f1cb1b2e2a..6dd2b0800dd 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -3167,8 +3167,8 @@ classify_name (struct parser_state *par_state, const struct block *block,
 	  struct symbol *sym;
 
 	  yylval.theclass.theclass = Class;
-	  sym = lookup_struct_typedef (copy.c_str (),
-				       par_state->expression_context_block, 1);
+	  sym = lookup_struct_noerr (copy.c_str (),
+				     par_state->expression_context_block);
 	  if (sym)
 	    yylval.theclass.type = sym->type ();
 	  return CLASSNAME;
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index b6f42b982eb..b307a0022b5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -79,31 +79,14 @@ struct objc_method {
 static const registry<objfile>::key<unsigned int> objc_objfile_data;
 
 /* Lookup a structure type named "struct NAME", visible in lexical
-   block BLOCK.  If NOERR is nonzero, return zero if NAME is not
-   suitably defined.  */
+   block BLOCK.  Return nullptr if no such type is found.  */
 
 struct symbol *
-lookup_struct_typedef (const char *name, const struct block *block, int noerr)
+lookup_struct_noerr (const char *name, const struct block *block)
 {
-  struct symbol *sym;
-
-  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, 0).symbol;
-
-  if (sym == NULL)
-    {
-      if (noerr)
-	return 0;
-      else
-	error (_("No struct type named %s."), name);
-    }
-  if (sym->type ()->code () != TYPE_CODE_STRUCT)
-    {
-      if (noerr)
-	return 0;
-      else
-	error (_("This context has class, union or enum %s, not a struct."),
-	       name);
-    }
+  symbol *sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, 0).symbol;
+  if (sym == nullptr || sym->type ()->code () != TYPE_CODE_STRUCT)
+    return nullptr;
   return sym;
 }
 
@@ -212,9 +195,9 @@ value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len)
   else
     error (_("NSString: internal error -- no way to create new NSString"));
 
-  sym = lookup_struct_typedef("NSString", 0, 1);
+  sym = lookup_struct_noerr ("NSString", 0);
   if (sym == NULL)
-    sym = lookup_struct_typedef("NXString", 0, 1);
+    sym = lookup_struct_noerr ("NXString", 0);
   if (sym == NULL)
     type = builtin_type (gdbarch)->builtin_data_ptr;
   else
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index ec6fbe7aaf9..d6a7509f21a 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -44,8 +44,7 @@ extern void start_msglist (void);
 extern void add_msglist (struct stoken *str, int addcolon);
 extern int end_msglist (struct parser_state *);
 
-struct symbol *lookup_struct_typedef (const char *name,
-				      const struct block *block,
-				      int noerr);
+struct symbol *lookup_struct_noerr (const char *name,
+				    const struct block *block);
 
 #endif /* GDB_OBJC_LANG_H */
-- 
2.49.0


  parent reply	other threads:[~2025-11-17  1:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17  1:26 [PATCH 0/7] Objective-C fixes Tom Tromey
2025-11-17  1:27 ` [PATCH 1/7] Reformat gdb.objc tests Tom Tromey
2025-11-17  1:27 ` [PATCH 2/7] Make the gdb.objc tests compile Tom Tromey
2025-11-17 10:09   ` Matt Rice
2025-11-18  0:51     ` Tom Tromey
2025-11-18  1:12       ` Matt Rice
2025-12-02 16:20         ` Tom Tromey
2025-12-03 15:24           ` Matt Rice
2025-11-17  1:27 ` [PATCH 3/7] Minor fixes to make gdb.objc tests pass Tom Tromey
2025-11-17  1:27 ` Tom Tromey [this message]
2025-11-17  1:27 ` [PATCH 5/7] Remove a couple Objective-C expression helpers Tom Tromey
2025-11-17  1:27 ` [PATCH 6/7] Avoid crash with "NSString" literals Tom Tromey
2025-11-17  1:27 ` [PATCH 7/7] Rewrite the @selector code Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251117012752.2657208-5-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox