You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.3 KiB
HTML
112 lines
4.3 KiB
HTML
4 years ago
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Inheritance and GTY - GNU Compiler Collection (GCC) Internals</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html">
|
||
|
<meta name="description" content="GNU Compiler Collection (GCC) Internals">
|
||
|
<meta name="generator" content="makeinfo 4.13">
|
||
|
<link title="Top" rel="start" href="index.html#Top">
|
||
|
<link rel="up" href="Type-Information.html#Type-Information" title="Type Information">
|
||
|
<link rel="prev" href="GTY-Options.html#GTY-Options" title="GTY Options">
|
||
|
<link rel="next" href="User-GC.html#User-GC" title="User GC">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
Copyright (C) 1988-2015 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with the
|
||
|
Invariant Sections being ``Funding Free Software'', the Front-Cover
|
||
|
Texts being (a) (see below), and with the Back-Cover Texts being (b)
|
||
|
(see below). A copy of the license is included in the section entitled
|
||
|
``GNU Free Documentation License''.
|
||
|
|
||
|
(a) The FSF's Front-Cover Text is:
|
||
|
|
||
|
A GNU Manual
|
||
|
|
||
|
(b) The FSF's Back-Cover Text is:
|
||
|
|
||
|
You have freedom to copy and modify this GNU Manual, like GNU
|
||
|
software. Copies published by the Free Software Foundation raise
|
||
|
funds for GNU development.-->
|
||
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
||
|
<style type="text/css"><!--
|
||
|
pre.display { font-family:inherit }
|
||
|
pre.format { font-family:inherit }
|
||
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
||
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
||
|
pre.smallexample { font-size:smaller }
|
||
|
pre.smalllisp { font-size:smaller }
|
||
|
span.sc { font-variant:small-caps }
|
||
|
span.roman { font-family:serif; font-weight:normal; }
|
||
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Inheritance-and-GTY"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="User-GC.html#User-GC">User GC</a>,
|
||
|
Previous: <a rel="previous" accesskey="p" href="GTY-Options.html#GTY-Options">GTY Options</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Type-Information.html#Type-Information">Type Information</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section">22.2 Support for inheritance</h3>
|
||
|
|
||
|
<p>gengtype has some support for simple class hierarchies. You can use
|
||
|
this to have gengtype autogenerate marking routines, provided:
|
||
|
|
||
|
<ul>
|
||
|
<li>There must be a concrete base class, with a discriminator expression
|
||
|
that can be used to identify which subclass an instance is.
|
||
|
<li>Only single inheritance is used.
|
||
|
<li>None of the classes within the hierarchy are templates.
|
||
|
</ul>
|
||
|
|
||
|
<p>If your class hierarchy does not fit in this pattern, you must use
|
||
|
<a href="User-GC.html#User-GC">User GC</a> instead.
|
||
|
|
||
|
<p>The base class and its discriminator must be identified using the “desc”
|
||
|
option. Each concrete subclass must use the “tag” option to identify
|
||
|
which value of the discriminator it corresponds to.
|
||
|
|
||
|
<p>Every class in the hierarchy must have a <code>GTY(())</code> marker, as
|
||
|
gengtype will only attempt to parse classes that have such a marker
|
||
|
<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a>.
|
||
|
|
||
|
<pre class="smallexample"> 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;
|
||
|
};
|
||
|
</pre>
|
||
|
<p>The generated marking routines for the above will contain a “switch”
|
||
|
on “kind”, visiting all appropriate fields. For example, if kind is
|
||
|
2, it will cast to “some_other_subclass” and visit fields a, b, and c.
|
||
|
|
||
|
<div class="footnote">
|
||
|
<hr>
|
||
|
<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> Classes lacking such a marker will not be identified as being
|
||
|
part of the hierarchy, and so the marking routines will not handle them,
|
||
|
leading to a assertion failure within the marking routines due to an
|
||
|
unknown tag value (assuming that assertions are enabled).</p>
|
||
|
|
||
|
<hr></div>
|
||
|
|
||
|
</body></html>
|
||
|
|