Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

163 lines
7.5KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1992-2020 Free Software Foundation, Inc.
  4. Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
  5. and David MacKenzie.
  6. Permission is granted to copy, distribute and/or modify this document
  7. under the terms of the GNU Free Documentation License, Version 1.3 or
  8. any later version published by the Free Software Foundation; with no
  9. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  10. Texts. A copy of the license is included in the section entitled "GNU
  11. Free Documentation License". -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>Virtual Methods (STABS)</title>
  16. <meta name="description" content="Virtual Methods (STABS)">
  17. <meta name="keywords" content="Virtual Methods (STABS)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Cplusplus.html#Cplusplus" rel="up" title="Cplusplus">
  25. <link href="Inheritance.html#Inheritance" rel="next" title="Inheritance">
  26. <link href="Method-Modifiers.html#Method-Modifiers" rel="prev" title="Method Modifiers">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="Virtual-Methods"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="Inheritance.html#Inheritance" accesskey="n" rel="next">Inheritance</a>, Previous: <a href="Method-Modifiers.html#Method-Modifiers" accesskey="p" rel="prev">Method Modifiers</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="Virtual-Methods-1"></a>
  63. <h3 class="section">8.11 Virtual Methods</h3>
  64. <p>&lt;&lt; The following examples are based on a4.C &gt;&gt;
  65. </p>
  66. <p>The presence of virtual methods in a class definition adds additional
  67. data to the class description. The extra data is appended to the
  68. description of the virtual method and to the end of the class
  69. description. Consider the class definition below:
  70. </p>
  71. <div class="example">
  72. <pre class="example">class A {
  73. public:
  74. int Adat;
  75. virtual int A_virt (int arg) { return arg; };
  76. };
  77. </pre></div>
  78. <p>This results in the stab below describing class A. It defines a new
  79. type (20) which is an 8 byte structure. The first field of the class
  80. struct is &lsquo;<samp>Adat</samp>&rsquo;, an integer, starting at structure offset 0 and
  81. occupying 32 bits.
  82. </p>
  83. <p>The second field in the class struct is not explicitly defined by the
  84. C<tt>++</tt> class definition but is implied by the fact that the class
  85. contains a virtual method. This field is the vtable pointer. The
  86. name of the vtable pointer field starts with &lsquo;<samp>$vf</samp>&rsquo; and continues with a
  87. type reference to the class it is part of. In this example the type
  88. reference for class A is 20 so the name of its vtable pointer field is
  89. &lsquo;<samp>$vf20</samp>&rsquo;, followed by the usual colon.
  90. </p>
  91. <p>Next there is a type definition for the vtable pointer type (21).
  92. This is in turn defined as a pointer to another new type (22).
  93. </p>
  94. <p>Type 22 is the vtable itself, which is defined as an array, indexed by
  95. a range of integers between 0 and 1, and whose elements are of type
  96. 17. Type 17 was the vtable record type defined by the boilerplate C<tt>++</tt>
  97. type definitions, as shown earlier.
  98. </p>
  99. <p>The bit offset of the vtable pointer field is 32. The number of bits
  100. in the field are not specified when the field is a vtable pointer.
  101. </p>
  102. <p>Next is the method definition for the virtual member function <code>A_virt</code>.
  103. Its description starts out using the same format as the non-virtual
  104. member functions described above, except instead of a dot after the
  105. &lsquo;<samp>A</samp>&rsquo; there is an asterisk, indicating that the function is virtual.
  106. Since is is virtual some addition information is appended to the end
  107. of the method description.
  108. </p>
  109. <p>The first number represents the vtable index of the method. This is a
  110. 32 bit unsigned number with the high bit set, followed by a
  111. semi-colon.
  112. </p>
  113. <p>The second number is a type reference to the first base class in the
  114. inheritance hierarchy defining the virtual member function. In this
  115. case the class stab describes a base class so the virtual function is
  116. not overriding any other definition of the method. Therefore the
  117. reference is to the type number of the class that the stab is
  118. describing (20).
  119. </p>
  120. <p>This is followed by three semi-colons. One marks the end of the
  121. current sub-section, one marks the end of the method field, and the
  122. third marks the end of the struct definition.
  123. </p>
  124. <p>For classes containing virtual functions the very last section of the
  125. string part of the stab holds a type reference to the first base
  126. class. This is preceded by &lsquo;<samp>~%</samp>&rsquo; and followed by a final semi-colon.
  127. </p>
  128. <div class="display">
  129. <pre class="display">.stabs &quot;class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
  130. field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
  131. field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
  132. sym_desc(array)index_type_ref(range of int from 0 to 1);
  133. elem_type_ref(vtbl elem type),
  134. bit_offset(32);
  135. meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
  136. :arg_type(int),protection(public)normal(yes)virtual(yes)
  137. vtable_index(1);class_first_defining(A);;;~%first_base(A);&quot;,
  138. N_LSYM,NIL,NIL,NIL
  139. </pre></div>
  140. <div class="example">
  141. <pre class="example">.stabs &quot;A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
  142. A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;&quot;,128,0,0,0
  143. </pre></div>
  144. <hr>
  145. <div class="header">
  146. <p>
  147. Next: <a href="Inheritance.html#Inheritance" accesskey="n" rel="next">Inheritance</a>, Previous: <a href="Method-Modifiers.html#Method-Modifiers" accesskey="p" rel="prev">Method Modifiers</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  148. </div>
  149. </body>
  150. </html>