gccint: Inheritance and GTY
1
1 23.2 Support for inheritance
1 ============================
1
1 gengtype has some support for simple class hierarchies. You can use
1 this to have gengtype autogenerate marking routines, provided:
1
1 * There must be a concrete base class, with a discriminator
1 expression that can be used to identify which subclass an instance
1 is.
1 * Only single inheritance is used.
1 * None of the classes within the hierarchy are templates.
1
1 If your class hierarchy does not fit in this pattern, you must use
1 ⇒User GC instead.
1
1 The base class and its discriminator must be identified using the
1 "desc" option. Each concrete subclass must use the "tag" option to
1 identify which value of the discriminator it corresponds to.
1
1 Every class in the hierarchy must have a 'GTY(())' marker, as gengtype
1 will only attempt to parse classes that have such a marker (1).
1
1 class GTY((desc("%h.kind"), tag("0"))) example_base
1 {
1 public:
1 int kind;
1 tree a;
1 };
1
1 class GTY((tag("1"))) some_subclass : public example_base
1 {
1 public:
1 tree b;
1 };
1
1 class GTY((tag("2"))) some_other_subclass : public example_base
1 {
1 public:
1 tree c;
1 };
1
1 The generated marking routines for the above will contain a "switch" on
1 "kind", visiting all appropriate fields. For example, if kind is 2, it
1 will cast to "some_other_subclass" and visit fields a, b, and c.
1
1 ---------- Footnotes ----------
1
1 (1) Classes lacking such a marker will not be identified as being
1 part of the hierarchy, and so the marking routines will not handle them,
1 leading to a assertion failure within the marking routines due to an
1 unknown tag value (assuming that assertions are enabled).
1