Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

239 lines
11KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Classes (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Classes (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Classes (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" rel="up" title="C and C++ Trees">
  30. <link href="Functions-for-C_002b_002b.html#Functions-for-C_002b_002b" rel="next" title="Functions for C++">
  31. <link href="Namespaces.html#Namespaces" rel="prev" title="Namespaces">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Classes"></a>
  62. <div class="header">
  63. <p>
  64. 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> &nbsp; [<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>
  65. </div>
  66. <hr>
  67. <a name="Classes-1"></a>
  68. <h4 class="subsection">11.10.3 Classes</h4>
  69. <a name="index-class_002c-scope"></a>
  70. <a name="index-RECORD_005fTYPE-1"></a>
  71. <a name="index-UNION_005fTYPE-1"></a>
  72. <a name="index-CLASSTYPE_005fDECLARED_005fCLASS"></a>
  73. <a name="index-TYPE_005fBINFO"></a>
  74. <a name="index-BINFO_005fTYPE"></a>
  75. <a name="index-TYPE_005fFIELDS-2"></a>
  76. <a name="index-TYPE_005fVFIELD"></a>
  77. <p>Besides namespaces, the other high-level scoping construct in C++ is the
  78. class. (Throughout this manual the term <em>class</em> is used to mean the
  79. types referred to in the ANSI/ISO C++ Standard as classes; these include
  80. types defined with the <code>class</code>, <code>struct</code>, and <code>union</code>
  81. keywords.)
  82. </p>
  83. <p>A class type is represented by either a <code>RECORD_TYPE</code> or a
  84. <code>UNION_TYPE</code>. A class declared with the <code>union</code> tag is
  85. represented by a <code>UNION_TYPE</code>, while classes declared with either
  86. the <code>struct</code> or the <code>class</code> tag are represented by
  87. <code>RECORD_TYPE</code>s. You can use the <code>CLASSTYPE_DECLARED_CLASS</code>
  88. macro to discern whether or not a particular type is a <code>class</code> as
  89. opposed to a <code>struct</code>. This macro will be true only for classes
  90. declared with the <code>class</code> tag.
  91. </p>
  92. <p>Almost all members are available on the <code>TYPE_FIELDS</code>
  93. list. Given one member, the next can be found by following the
  94. <code>TREE_CHAIN</code>. You should not depend in any way on the order in
  95. which fields appear on this list. All nodes on this list will be
  96. &lsquo;<samp>DECL</samp>&rsquo; nodes. A <code>FIELD_DECL</code> is used to represent a non-static
  97. data member, a <code>VAR_DECL</code> is used to represent a static data
  98. member, and a <code>TYPE_DECL</code> is used to represent a type. Note that
  99. the <code>CONST_DECL</code> for an enumeration constant will appear on this
  100. list, if the enumeration type was declared in the class. (Of course,
  101. the <code>TYPE_DECL</code> for the enumeration type will appear here as well.)
  102. There are no entries for base classes on this list. In particular,
  103. there is no <code>FIELD_DECL</code> for the &ldquo;base-class portion&rdquo; of an
  104. object. If a function member is overloaded, each of the overloaded
  105. functions appears; no <code>OVERLOAD</code> nodes appear on the <code>TYPE_FIELDS</code>
  106. list. Implicitly declared functions (including default constructors,
  107. copy constructors, assignment operators, and destructors) will appear on
  108. this list as well.
  109. </p>
  110. <p>The <code>TYPE_VFIELD</code> is a compiler-generated field used to point to
  111. virtual function tables. It may or may not appear on the
  112. <code>TYPE_FIELDS</code> list. However, back ends should handle the
  113. <code>TYPE_VFIELD</code> just like all the entries on the <code>TYPE_FIELDS</code>
  114. list.
  115. </p>
  116. <p>Every class has an associated <em>binfo</em>, which can be obtained with
  117. <code>TYPE_BINFO</code>. Binfos are used to represent base-classes. The
  118. binfo given by <code>TYPE_BINFO</code> is the degenerate case, whereby every
  119. class is considered to be its own base-class. The base binfos for a
  120. particular binfo are held in a vector, whose length is obtained with
  121. <code>BINFO_N_BASE_BINFOS</code>. The base binfos themselves are obtained
  122. with <code>BINFO_BASE_BINFO</code> and <code>BINFO_BASE_ITERATE</code>. To add a
  123. new binfo, use <code>BINFO_BASE_APPEND</code>. The vector of base binfos can
  124. be obtained with <code>BINFO_BASE_BINFOS</code>, but normally you do not need
  125. to use that. The class type associated with a binfo is given by
  126. <code>BINFO_TYPE</code>. It is not always the case that <code>BINFO_TYPE
  127. (TYPE_BINFO (x))</code>, because of typedefs and qualified types. Neither is
  128. it the case that <code>TYPE_BINFO (BINFO_TYPE (y))</code> is the same binfo as
  129. <code>y</code>. The reason is that if <code>y</code> is a binfo representing a
  130. base-class <code>B</code> of a derived class <code>D</code>, then <code>BINFO_TYPE
  131. (y)</code> will be <code>B</code>, and <code>TYPE_BINFO (BINFO_TYPE (y))</code> will be
  132. <code>B</code> as its own base-class, rather than as a base-class of <code>D</code>.
  133. </p>
  134. <p>The access to a base type can be found with <code>BINFO_BASE_ACCESS</code>.
  135. This will produce <code>access_public_node</code>, <code>access_private_node</code>
  136. or <code>access_protected_node</code>. If bases are always public,
  137. <code>BINFO_BASE_ACCESSES</code> may be <code>NULL</code>.
  138. </p>
  139. <p><code>BINFO_VIRTUAL_P</code> is used to specify whether the binfo is inherited
  140. virtually or not. The other flags, <code>BINFO_FLAG_0</code> to
  141. <code>BINFO_FLAG_6</code>, can be used for language specific use.
  142. </p>
  143. <p>The following macros can be used on a tree node representing a class-type.
  144. </p>
  145. <dl compact="compact">
  146. <dt><code>LOCAL_CLASS_P</code>
  147. <a name="index-LOCAL_005fCLASS_005fP"></a>
  148. </dt>
  149. <dd><p>This predicate holds if the class is local class <em>i.e.</em> declared
  150. inside a function body.
  151. </p>
  152. </dd>
  153. <dt><code>TYPE_POLYMORPHIC_P</code>
  154. <a name="index-TYPE_005fPOLYMORPHIC_005fP"></a>
  155. </dt>
  156. <dd><p>This predicate holds if the class has at least one virtual function
  157. (declared or inherited).
  158. </p>
  159. </dd>
  160. <dt><code>TYPE_HAS_DEFAULT_CONSTRUCTOR</code>
  161. <a name="index-TYPE_005fHAS_005fDEFAULT_005fCONSTRUCTOR"></a>
  162. </dt>
  163. <dd><p>This predicate holds whenever its argument represents a class-type with
  164. default constructor.
  165. </p>
  166. </dd>
  167. <dt><code>CLASSTYPE_HAS_MUTABLE</code>
  168. <a name="index-CLASSTYPE_005fHAS_005fMUTABLE"></a>
  169. </dt>
  170. <dt><code>TYPE_HAS_MUTABLE_P</code>
  171. <a name="index-TYPE_005fHAS_005fMUTABLE_005fP"></a>
  172. </dt>
  173. <dd><p>These predicates hold for a class-type having a mutable data member.
  174. </p>
  175. </dd>
  176. <dt><code>CLASSTYPE_NON_POD_P</code>
  177. <a name="index-CLASSTYPE_005fNON_005fPOD_005fP"></a>
  178. </dt>
  179. <dd><p>This predicate holds only for class-types that are not PODs.
  180. </p>
  181. </dd>
  182. <dt><code>TYPE_HAS_NEW_OPERATOR</code>
  183. <a name="index-TYPE_005fHAS_005fNEW_005fOPERATOR"></a>
  184. </dt>
  185. <dd><p>This predicate holds for a class-type that defines
  186. <code>operator new</code>.
  187. </p>
  188. </dd>
  189. <dt><code>TYPE_HAS_ARRAY_NEW_OPERATOR</code>
  190. <a name="index-TYPE_005fHAS_005fARRAY_005fNEW_005fOPERATOR"></a>
  191. </dt>
  192. <dd><p>This predicate holds for a class-type for which
  193. <code>operator new[]</code> is defined.
  194. </p>
  195. </dd>
  196. <dt><code>TYPE_OVERLOADS_CALL_EXPR</code>
  197. <a name="index-TYPE_005fOVERLOADS_005fCALL_005fEXPR"></a>
  198. </dt>
  199. <dd><p>This predicate holds for class-type for which the function call
  200. <code>operator()</code> is overloaded.
  201. </p>
  202. </dd>
  203. <dt><code>TYPE_OVERLOADS_ARRAY_REF</code>
  204. <a name="index-TYPE_005fOVERLOADS_005fARRAY_005fREF"></a>
  205. </dt>
  206. <dd><p>This predicate holds for a class-type that overloads
  207. <code>operator[]</code>
  208. </p>
  209. </dd>
  210. <dt><code>TYPE_OVERLOADS_ARROW</code>
  211. <a name="index-TYPE_005fOVERLOADS_005fARROW"></a>
  212. </dt>
  213. <dd><p>This predicate holds for a class-type for which <code>operator-&gt;</code> is
  214. overloaded.
  215. </p>
  216. </dd>
  217. </dl>
  218. <hr>
  219. <div class="header">
  220. <p>
  221. 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> &nbsp; [<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>
  222. </div>
  223. </body>
  224. </html>