[binutils-gdb] gdb/gdbtypes: replace TYPE_IS_OPAQUE macro with method
Simon Marchi via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ace1b205a8933b376c10df349e639761e8977758 commit ace1b205a8933b376c10df349e639761e8977758 Author: Simon Marchi <[email protected]> Date: Tue Feb 17 14:13:58 2026 -0500 gdb/gdbtypes: replace TYPE_IS_OPAQUE macro with method Replace the TYPE_IS_OPAQUE macro with the method type::is_opaque. Change-Id: I9d8875d9fedca5681f7b4a9a56e8e5cb0bf0ad78 Approved-By: Tom Tromey <[email protected]> Diff: --- gdb/block.c | 2 +- gdb/block.h | 2 +- gdb/gdbtypes.c | 20 +++++++++++++++++++- gdb/gdbtypes.h | 14 ++++++-------- gdb/symtab.c | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 730e4580a5b..dc00327048f 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -749,7 +749,7 @@ block_find_symbol (const struct block *block, const lookup_name_info &name, if (!sym->matches (domain)) continue; - if (!TYPE_IS_OPAQUE (sym->type ())) + if (!sym->type ()->is_opaque ()) return sym; if (stub != nullptr) diff --git a/gdb/block.h b/gdb/block.h index b84ca12c35a..091120ae2b8 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -698,7 +698,7 @@ struct best_symbol_tracker }; /* Find symbol NAME in BLOCK and in DOMAIN. This will return a - matching symbol whose type is not a "opaque", see TYPE_IS_OPAQUE. + matching symbol whose type is not "opaque", see type::is_opaque. If STUB is non-NULL, an otherwise matching symbol whose type is a opaque will be stored here. */ diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 2b6244d6f38..d2e243abbe1 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3053,7 +3053,7 @@ check_typedef (struct type *type) { /* Nothing. */ } - else if (TYPE_IS_OPAQUE (type)) + else if (type->is_opaque ()) { const char *name = type->name (); struct type *newtype; @@ -5627,6 +5627,24 @@ type::fixed_point_scaling_factor () /* See gdbtypes.h. */ +bool +type::is_opaque () const +{ + if (this->code () != TYPE_CODE_STRUCT + && this->code () != TYPE_CODE_UNION) + return false; + + if (this->num_fields () > 0) + return false; + + if (HAVE_CPLUS_STRUCT (this) && TYPE_NFN_FIELDS (this) != 0) + return false; + + return this->is_stub () || !this->stub_is_supported (); +} + +/* See gdbtypes.h. */ + void type::alloc_fields (unsigned int nfields, bool init) { diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index e9a3c637be2..68c272d5fe5 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1072,6 +1072,11 @@ struct type return this->name () != nullptr ? this->name () : _("<error type>"); } + /* Return true if this type is "opaque", i.e. a struct or union with + no fields, no methods, and either a stub or with unsupported stub + information. */ + bool is_opaque () const; + /* Note that if thistype is a TYPEDEF type, you have to call check_typedef. But check_typedef does set the TYPE_LENGTH of the TYPEDEF type, so you only have to call check_typedef once. Since value::allocate @@ -1297,7 +1302,7 @@ struct type } /* This debug target supports TYPE_STUB(t). In the unsupported case - we have to rely on NFIELDS to be zero etc., see TYPE_IS_OPAQUE(). + we have to rely on NFIELDS to be zero etc., see type::is_opaque. TYPE_STUB(t) with !TYPE_STUB_SUPPORTED(t) may exist if we only guessed the TYPE_STUB(t) value (see dwarfread.c). */ @@ -2049,13 +2054,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *); (TYPE_NESTED_TYPES_FIELD (thistype, n).accessibility \ == accessibility::PRIVATE) -#define TYPE_IS_OPAQUE(thistype) \ - ((((thistype)->code () == TYPE_CODE_STRUCT) \ - || ((thistype)->code () == TYPE_CODE_UNION)) \ - && ((thistype)->num_fields () == 0) \ - && (!HAVE_CPLUS_STRUCT (thistype) \ - || TYPE_NFN_FIELDS (thistype) == 0) \ - && ((thistype)->is_stub () || !(thistype)->stub_is_supported ())) /* Given TYPE, return its floatformat. */ const struct floatformat *floatformat_from_type (const struct type *type); diff --git a/gdb/symtab.c b/gdb/symtab.c index cd3bf876551..6f5b998566e 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2680,7 +2680,7 @@ lookup_transparent_type_quick (struct objfile *objfile, sym = block_find_symbol (block, name, flags, nullptr); if (sym == nullptr) error_in_psymtab_expansion (block_index, name.c_str (), cust); - gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); + gdb_assert (!sym->type ()->is_opaque ()); return sym->type (); }