This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
How to distinguish inheritance from containment?
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: archer at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Wed, 1 Jul 2009 13:38:42 -0700 (PDT)
- Subject: How to distinguish inheritance from containment?
Greetings,
Consider this source:
--- cut ---
struct foo {
int x;
};
struct is_a_foo : public foo {
int y;
};
struct has_a_foo {
foo f;
int z;
};
int main()
{
is_a_foo a;
has_a_foo b;
return a.x + b.f.x;
}
--- cut ---
Suppose I want to define a pretty printer for anything that "is a foo",
but which should not apply to things which "contain a foo" as the first
field.
The only way I figured out how to do this currently feels very "hacky":
(assume gdb.Value('a') is bound to python variable a).
field0 = a.type.fields()[0]
if "foo" == field0.name and "foo" == str(field0.type):
print "is a foo"
In addition, above test is not fool-proof: if I rename 'f' member of
has_a_foo to 'foo':
struct has_a_foo {
struct foo foo;
int z;
};
then above test answers 'is a foo' for 'b' as well.
Would adding an 'inherited' pre-defined attribute to gdb.Field be a bad idea?
It would make 'is a foo' determination straightforward:
if "foo" == str(field0.type) and field0.inherited:
print "is a foo"
I'll send a patch if y'all think this is reasonable.
Thanks,
--
Paul Pluzhnikov