Simple-Classes.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-2019 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 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>STABS: Simple Classes</title>
  15. <meta name="description" content="STABS: Simple Classes">
  16. <meta name="keywords" content="STABS: Simple Classes">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="Class-Instance.html#Class-Instance" rel="next" title="Class Instance">
  26. <link href="Basic-Cplusplus-Types.html#Basic-Cplusplus-Types" rel="prev" title="Basic Cplusplus Types">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; font-weight:normal}
  51. span.sansserif {font-family:sans-serif; font-weight:normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Simple-Classes"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Class-Instance.html#Class-Instance" accesskey="n" rel="next">Class Instance</a>, Previous: <a href="Basic-Cplusplus-Types.html#Basic-Cplusplus-Types" accesskey="p" rel="prev">Basic Cplusplus Types</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>
  61. </div>
  62. <hr>
  63. <a name="Simple-Class-Definition"></a>
  64. <h3 class="section">8.4 Simple Class Definition</h3>
  65. <p>The stabs describing C<tt>++</tt> language features are an extension of the
  66. stabs describing C. Stabs representing C<tt>++</tt> class types elaborate
  67. extensively on the stab format used to describe structure types in C.
  68. Stabs representing class type variables look just like stabs
  69. representing C language variables.
  70. </p>
  71. <p>Consider the following very simple class definition.
  72. </p>
  73. <div class="example">
  74. <pre class="example">class baseA {
  75. public:
  76. int Adat;
  77. int Ameth(int in, char other);
  78. };
  79. </pre></div>
  80. <p>The class <code>baseA</code> is represented by two stabs. The first stab describes
  81. the class as a structure type. The second stab describes a structure
  82. tag of the class type. Both stabs are of stab type <code>N_LSYM</code>. Since the
  83. stab is not located between an <code>N_FUN</code> and an <code>N_LBRAC</code> stab this indicates
  84. that the class is defined at file scope. If it were, then the <code>N_LSYM</code>
  85. would signify a local variable.
  86. </p>
  87. <p>A stab describing a C<tt>++</tt> class type is similar in format to a stab
  88. describing a C struct, with each class member shown as a field in the
  89. structure. The part of the struct format describing fields is
  90. expanded to include extra information relevant to C<tt>++</tt> class members.
  91. In addition, if the class has multiple base classes or virtual
  92. functions the struct format outside of the field parts is also
  93. augmented.
  94. </p>
  95. <p>In this simple example the field part of the C<tt>++</tt> class stab
  96. representing member data looks just like the field part of a C struct
  97. stab. The section on protections describes how its format is
  98. sometimes extended for member data.
  99. </p>
  100. <p>The field part of a C<tt>++</tt> class stab representing a member function
  101. differs substantially from the field part of a C struct stab. It
  102. still begins with &lsquo;<samp>name:</samp>&rsquo; but then goes on to define a new type number
  103. for the member function, describe its return type, its argument types,
  104. its protection level, any qualifiers applied to the method definition,
  105. and whether the method is virtual or not. If the method is virtual
  106. then the method description goes on to give the vtable index of the
  107. method, and the type number of the first base class defining the
  108. method.
  109. </p>
  110. <p>When the field name is a method name it is followed by two colons rather
  111. than one. This is followed by a new type definition for the method.
  112. This is a number followed by an equal sign and the type of the method.
  113. Normally this will be a type declared using the &lsquo;<samp>#</samp>&rsquo; type
  114. descriptor; see <a href="Method-Type-Descriptor.html#Method-Type-Descriptor">Method Type Descriptor</a>; static member functions
  115. are declared using the &lsquo;<samp>f</samp>&rsquo; type descriptor instead; see
  116. <a href="Function-Types.html#Function-Types">Function Types</a>.
  117. </p>
  118. <p>The format of an overloaded operator method name differs from that of
  119. other methods. It is &lsquo;<samp>op$::<var>operator-name</var>.</samp>&rsquo; where
  120. <var>operator-name</var> is the operator name such as &lsquo;<samp>+</samp>&rsquo; or &lsquo;<samp>+=</samp>&rsquo;.
  121. The name ends with a period, and any characters except the period can
  122. occur in the <var>operator-name</var> string.
  123. </p>
  124. <p>The next part of the method description represents the arguments to the
  125. method, preceded by a colon and ending with a semi-colon. The types of
  126. the arguments are expressed in the same way argument types are expressed
  127. in C<tt>++</tt> name mangling. In this example an <code>int</code> and a <code>char</code>
  128. map to &lsquo;<samp>ic</samp>&rsquo;.
  129. </p>
  130. <p>This is followed by a number, a letter, and an asterisk or period,
  131. followed by another semicolon. The number indicates the protections
  132. that apply to the member function. Here the 2 means public. The
  133. letter encodes any qualifier applied to the method definition. In
  134. this case, &lsquo;<samp>A</samp>&rsquo; means that it is a normal function definition. The dot
  135. shows that the method is not virtual. The sections that follow
  136. elaborate further on these fields and describe the additional
  137. information present for virtual methods.
  138. </p>
  139. <div class="display">
  140. <pre class="display">.stabs &quot;class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
  141. field_name(Adat):type(int),bit_offset(0),field_bits(32);
  142. method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
  143. :arg_types(int char);
  144. protection(public)qualifier(normal)virtual(no);;&quot;
  145. N_LSYM,NIL,NIL,NIL
  146. </pre></div>
  147. <div class="smallexample">
  148. <pre class="smallexample">.stabs &quot;baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;&quot;,128,0,0,0
  149. .stabs &quot;class_name:sym_desc(struct tag)&quot;,N_LSYM,NIL,NIL,NIL
  150. .stabs &quot;baseA:T20&quot;,128,0,0,0
  151. </pre></div>
  152. <hr>
  153. <div class="header">
  154. <p>
  155. Next: <a href="Class-Instance.html#Class-Instance" accesskey="n" rel="next">Class Instance</a>, Previous: <a href="Basic-Cplusplus-Types.html#Basic-Cplusplus-Types" accesskey="p" rel="prev">Basic Cplusplus Types</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>
  156. </div>
  157. </body>
  158. </html>