Next:Support for user-provided GC marking routines, Previous:The Inside of aGTY(()), Up:Memory Management and Type Information [Contents][Index]
gengtype has some support for simple class hierarchies. You can usethis to have gengtype autogenerate marking routines, provided:
If your class hierarchy does not fit in this pattern, you must useSupport for user-provided GC marking routines instead.
The base class and its discriminator must be identified using the “desc”option. Each concrete subclass must use the “tag” option to identifywhich value of the discriminator it corresponds to.
Every class in the hierarchy must have aGTY(()) marker, asgengtype will only attempt to parse classes that have such a marker8.
class GTY((desc("%h.kind"), tag("0"))) example_base{public: int kind; tree a;};class GTY((tag("1"))) some_subclass : public example_base{public: tree b;};class GTY((tag("2"))) some_other_subclass : public example_base{public: tree c;};The generated marking routines for the above will contain a “switch”on “kind”, visiting all appropriate fields. For example, if kind is2, it will cast to “some_other_subclass” and visit fields a, b, and c.
Classes lacking such a marker will not be identified as beingpart of the hierarchy, and so the marking routines will not handle them,leading to a assertion failure within the marking routines due to anunknown tag value (assuming that assertions are enabled).