This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Accessor macro wrappers removal [Re: [patch] static_kind -> bit0, bit1]


On Fri, 26 Sep 2008 14:54:22 +0200, Daniel Jacobowitz wrote:
> On Fri, Sep 26, 2008 at 06:43:09AM +0200, Jan Kratochvil wrote:
> > On Sat, 20 Sep 2008 00:12:21 +0200, Joel Brobecker wrote:
> > > > Also I do not understand why exist all the macros like this one at all:
> > > > #define TYPE_MAIN_TYPE(thistype) (thistype)->main_type
> > > > Why we cannot use it expanded?  This way it is always one (or more)
> > > > "tags"-jump (VIM ctrl-]) indirections while navigating the source files.
> > > 
> > > Personally, I find them to be very useful to quickly find who is using
> > > field "main_type" in struct type.
> > 
> > How does it differ from
> >   grep -- '->main_type\>' *.[ch]
> > ?
> 
> "in struct type" is the difference.

* Either to use static getters/setters (Gnome):
  struct main_type *type_main_type_get (struct type *type);

* or in the C++ way (optional get/set prefixes instead of the overloading):
  class type {
    private: struct main_type *_main_type;
    public: struct main_type *main_type () { return _main_type; }
    public: void main_type (struct main_type *v) { _main_type = v; }
  };
  One can get here even the automatic reference counting / memory management.

* or to use semiunique fields prefix:
  struct type { struct main_type *tp_main_type; ... };


> For main_type it's not too bad.  But for e.g. TYPE_FIELD_TYPE you can
> see the problem; there's lots of things that have a type.  If you're
> looking just for the ones that come from a "struct field", it can be
> pretty awful to locate them all.

There is not the mess of mixed prefix (macros) vs. postfix (fields):
xml-tdesc.c:
if (TYPE_VECTOR (TYPE_FIELD_TYPE (data->current_union, i)))

It gets expanded to:
if ((((((data->current_union)->main_type->fields[i]).type))->main_type->flag_vector))
if (data->current_union->main_type->fields[i].type->main_type->flag_vector)

Which could be simplified with C++ (do you also find it more clear?):
if (data->current_union->fields()[i]->type()->flag_vector())


Regards,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]