|
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <!-- Copyright (C) 1988-2020 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. -->
- <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Classes (GNU Compiler Collection (GCC) Internals)</title>
-
- <meta name="description" content="Classes (GNU Compiler Collection (GCC) Internals)">
- <meta name="keywords" content="Classes (GNU Compiler Collection (GCC) Internals)">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="makeinfo">
- <link href="index.html#Top" rel="start" title="Top">
- <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
- <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
- <link href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" rel="up" title="C and C++ Trees">
- <link href="Functions-for-C_002b_002b.html#Functions-for-C_002b_002b" rel="next" title="Functions for C++">
- <link href="Namespaces.html#Namespaces" rel="prev" title="Namespaces">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.indentedblock {margin-right: 0em}
- blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
- blockquote.smallquotation {font-size: smaller}
- div.display {margin-left: 3.2em}
- div.example {margin-left: 3.2em}
- div.lisp {margin-left: 3.2em}
- div.smalldisplay {margin-left: 3.2em}
- div.smallexample {margin-left: 3.2em}
- div.smalllisp {margin-left: 3.2em}
- kbd {font-style: oblique}
- pre.display {font-family: inherit}
- pre.format {font-family: inherit}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: inherit; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: inherit; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.nolinebreak {white-space: nowrap}
- span.roman {font-family: initial; font-weight: normal}
- span.sansserif {font-family: sans-serif; font-weight: normal}
- ul.no-bullet {list-style: none}
- -->
- </style>
-
-
- </head>
-
- <body lang="en">
- <a name="Classes"></a>
- <div class="header">
- <p>
- Next: <a href="Functions-for-C_002b_002b.html#Functions-for-C_002b_002b" accesskey="n" rel="next">Functions for C++</a>, Previous: <a href="Namespaces.html#Namespaces" accesskey="p" rel="prev">Namespaces</a>, Up: <a href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" accesskey="u" rel="up">C and C++ Trees</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
- </div>
- <hr>
- <a name="Classes-1"></a>
- <h4 class="subsection">11.10.3 Classes</h4>
- <a name="index-class_002c-scope"></a>
- <a name="index-RECORD_005fTYPE-1"></a>
- <a name="index-UNION_005fTYPE-1"></a>
- <a name="index-CLASSTYPE_005fDECLARED_005fCLASS"></a>
- <a name="index-TYPE_005fBINFO"></a>
- <a name="index-BINFO_005fTYPE"></a>
- <a name="index-TYPE_005fFIELDS-2"></a>
- <a name="index-TYPE_005fVFIELD"></a>
-
- <p>Besides namespaces, the other high-level scoping construct in C++ is the
- class. (Throughout this manual the term <em>class</em> is used to mean the
- types referred to in the ANSI/ISO C++ Standard as classes; these include
- types defined with the <code>class</code>, <code>struct</code>, and <code>union</code>
- keywords.)
- </p>
- <p>A class type is represented by either a <code>RECORD_TYPE</code> or a
- <code>UNION_TYPE</code>. A class declared with the <code>union</code> tag is
- represented by a <code>UNION_TYPE</code>, while classes declared with either
- the <code>struct</code> or the <code>class</code> tag are represented by
- <code>RECORD_TYPE</code>s. You can use the <code>CLASSTYPE_DECLARED_CLASS</code>
- macro to discern whether or not a particular type is a <code>class</code> as
- opposed to a <code>struct</code>. This macro will be true only for classes
- declared with the <code>class</code> tag.
- </p>
- <p>Almost all members are available on the <code>TYPE_FIELDS</code>
- list. Given one member, the next can be found by following the
- <code>TREE_CHAIN</code>. You should not depend in any way on the order in
- which fields appear on this list. All nodes on this list will be
- ‘<samp>DECL</samp>’ nodes. A <code>FIELD_DECL</code> is used to represent a non-static
- data member, a <code>VAR_DECL</code> is used to represent a static data
- member, and a <code>TYPE_DECL</code> is used to represent a type. Note that
- the <code>CONST_DECL</code> for an enumeration constant will appear on this
- list, if the enumeration type was declared in the class. (Of course,
- the <code>TYPE_DECL</code> for the enumeration type will appear here as well.)
- There are no entries for base classes on this list. In particular,
- there is no <code>FIELD_DECL</code> for the “base-class portion” of an
- object. If a function member is overloaded, each of the overloaded
- functions appears; no <code>OVERLOAD</code> nodes appear on the <code>TYPE_FIELDS</code>
- list. Implicitly declared functions (including default constructors,
- copy constructors, assignment operators, and destructors) will appear on
- this list as well.
- </p>
- <p>The <code>TYPE_VFIELD</code> is a compiler-generated field used to point to
- virtual function tables. It may or may not appear on the
- <code>TYPE_FIELDS</code> list. However, back ends should handle the
- <code>TYPE_VFIELD</code> just like all the entries on the <code>TYPE_FIELDS</code>
- list.
- </p>
- <p>Every class has an associated <em>binfo</em>, which can be obtained with
- <code>TYPE_BINFO</code>. Binfos are used to represent base-classes. The
- binfo given by <code>TYPE_BINFO</code> is the degenerate case, whereby every
- class is considered to be its own base-class. The base binfos for a
- particular binfo are held in a vector, whose length is obtained with
- <code>BINFO_N_BASE_BINFOS</code>. The base binfos themselves are obtained
- with <code>BINFO_BASE_BINFO</code> and <code>BINFO_BASE_ITERATE</code>. To add a
- new binfo, use <code>BINFO_BASE_APPEND</code>. The vector of base binfos can
- be obtained with <code>BINFO_BASE_BINFOS</code>, but normally you do not need
- to use that. The class type associated with a binfo is given by
- <code>BINFO_TYPE</code>. It is not always the case that <code>BINFO_TYPE
- (TYPE_BINFO (x))</code>, because of typedefs and qualified types. Neither is
- it the case that <code>TYPE_BINFO (BINFO_TYPE (y))</code> is the same binfo as
- <code>y</code>. The reason is that if <code>y</code> is a binfo representing a
- base-class <code>B</code> of a derived class <code>D</code>, then <code>BINFO_TYPE
- (y)</code> will be <code>B</code>, and <code>TYPE_BINFO (BINFO_TYPE (y))</code> will be
- <code>B</code> as its own base-class, rather than as a base-class of <code>D</code>.
- </p>
- <p>The access to a base type can be found with <code>BINFO_BASE_ACCESS</code>.
- This will produce <code>access_public_node</code>, <code>access_private_node</code>
- or <code>access_protected_node</code>. If bases are always public,
- <code>BINFO_BASE_ACCESSES</code> may be <code>NULL</code>.
- </p>
- <p><code>BINFO_VIRTUAL_P</code> is used to specify whether the binfo is inherited
- virtually or not. The other flags, <code>BINFO_FLAG_0</code> to
- <code>BINFO_FLAG_6</code>, can be used for language specific use.
- </p>
- <p>The following macros can be used on a tree node representing a class-type.
- </p>
- <dl compact="compact">
- <dt><code>LOCAL_CLASS_P</code>
- <a name="index-LOCAL_005fCLASS_005fP"></a>
- </dt>
- <dd><p>This predicate holds if the class is local class <em>i.e.</em> declared
- inside a function body.
- </p>
- </dd>
- <dt><code>TYPE_POLYMORPHIC_P</code>
- <a name="index-TYPE_005fPOLYMORPHIC_005fP"></a>
- </dt>
- <dd><p>This predicate holds if the class has at least one virtual function
- (declared or inherited).
- </p>
- </dd>
- <dt><code>TYPE_HAS_DEFAULT_CONSTRUCTOR</code>
- <a name="index-TYPE_005fHAS_005fDEFAULT_005fCONSTRUCTOR"></a>
- </dt>
- <dd><p>This predicate holds whenever its argument represents a class-type with
- default constructor.
- </p>
- </dd>
- <dt><code>CLASSTYPE_HAS_MUTABLE</code>
- <a name="index-CLASSTYPE_005fHAS_005fMUTABLE"></a>
- </dt>
- <dt><code>TYPE_HAS_MUTABLE_P</code>
- <a name="index-TYPE_005fHAS_005fMUTABLE_005fP"></a>
- </dt>
- <dd><p>These predicates hold for a class-type having a mutable data member.
- </p>
- </dd>
- <dt><code>CLASSTYPE_NON_POD_P</code>
- <a name="index-CLASSTYPE_005fNON_005fPOD_005fP"></a>
- </dt>
- <dd><p>This predicate holds only for class-types that are not PODs.
- </p>
- </dd>
- <dt><code>TYPE_HAS_NEW_OPERATOR</code>
- <a name="index-TYPE_005fHAS_005fNEW_005fOPERATOR"></a>
- </dt>
- <dd><p>This predicate holds for a class-type that defines
- <code>operator new</code>.
- </p>
- </dd>
- <dt><code>TYPE_HAS_ARRAY_NEW_OPERATOR</code>
- <a name="index-TYPE_005fHAS_005fARRAY_005fNEW_005fOPERATOR"></a>
- </dt>
- <dd><p>This predicate holds for a class-type for which
- <code>operator new[]</code> is defined.
- </p>
- </dd>
- <dt><code>TYPE_OVERLOADS_CALL_EXPR</code>
- <a name="index-TYPE_005fOVERLOADS_005fCALL_005fEXPR"></a>
- </dt>
- <dd><p>This predicate holds for class-type for which the function call
- <code>operator()</code> is overloaded.
- </p>
- </dd>
- <dt><code>TYPE_OVERLOADS_ARRAY_REF</code>
- <a name="index-TYPE_005fOVERLOADS_005fARRAY_005fREF"></a>
- </dt>
- <dd><p>This predicate holds for a class-type that overloads
- <code>operator[]</code>
- </p>
- </dd>
- <dt><code>TYPE_OVERLOADS_ARROW</code>
- <a name="index-TYPE_005fOVERLOADS_005fARROW"></a>
- </dt>
- <dd><p>This predicate holds for a class-type for which <code>operator-></code> is
- overloaded.
- </p>
- </dd>
- </dl>
-
- <hr>
- <div class="header">
- <p>
- Next: <a href="Functions-for-C_002b_002b.html#Functions-for-C_002b_002b" accesskey="n" rel="next">Functions for C++</a>, Previous: <a href="Namespaces.html#Namespaces" accesskey="p" rel="prev">Namespaces</a>, Up: <a href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" accesskey="u" rel="up">C and C++ Trees</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
- </div>
-
-
-
- </body>
- </html>
|