Tree-overview.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Tree overview</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Tree overview">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Tree overview">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="GENERIC.html#GENERIC" rel="up" title="GENERIC">
  30. <link href="Macros-and-Functions.html#Macros-and-Functions" rel="next" title="Macros and Functions">
  31. <link href="Deficiencies.html#Deficiencies" rel="prev" title="Deficiencies">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Tree-overview"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Types.html#Types" accesskey="n" rel="next">Types</a>, Previous: <a href="Deficiencies.html#Deficiencies" accesskey="p" rel="prev">Deficiencies</a>, Up: <a href="GENERIC.html#GENERIC" accesskey="u" rel="up">GENERIC</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>
  66. </div>
  67. <hr>
  68. <a name="Overview-1"></a>
  69. <h3 class="section">10.2 Overview</h3>
  70. <a name="index-tree"></a>
  71. <a name="index-TREE_005fCODE"></a>
  72. <p>The central data structure used by the internal representation is the
  73. <code>tree</code>. These nodes, while all of the C type <code>tree</code>, are of
  74. many varieties. A <code>tree</code> is a pointer type, but the object to
  75. which it points may be of a variety of types. From this point forward,
  76. we will refer to trees in ordinary type, rather than in <code>this
  77. font</code>, except when talking about the actual C type <code>tree</code>.
  78. </p>
  79. <p>You can tell what kind of node a particular tree is by using the
  80. <code>TREE_CODE</code> macro. Many, many macros take trees as input and
  81. return trees as output. However, most macros require a certain kind of
  82. tree node as input. In other words, there is a type-system for trees,
  83. but it is not reflected in the C type-system.
  84. </p>
  85. <p>For safety, it is useful to configure GCC with <samp>--enable-checking</samp>.
  86. Although this results in a significant performance penalty (since all
  87. tree types are checked at run-time), and is therefore inappropriate in a
  88. release version, it is extremely helpful during the development process.
  89. </p>
  90. <p>Many macros behave as predicates. Many, although not all, of these
  91. predicates end in &lsquo;<samp>_P</samp>&rsquo;. Do not rely on the result type of these
  92. macros being of any particular type. You may, however, rely on the fact
  93. that the type can be compared to <code>0</code>, so that statements like
  94. </p><div class="smallexample">
  95. <pre class="smallexample">if (TEST_P (t) &amp;&amp; !TEST_P (y))
  96. x = 1;
  97. </pre></div>
  98. <p>and
  99. </p><div class="smallexample">
  100. <pre class="smallexample">int i = (TEST_P (t) != 0);
  101. </pre></div>
  102. <p>are legal. Macros that return <code>int</code> values now may be changed to
  103. return <code>tree</code> values, or other pointers in the future. Even those
  104. that continue to return <code>int</code> may return multiple nonzero codes
  105. where previously they returned only zero and one. Therefore, you should
  106. not write code like
  107. </p><div class="smallexample">
  108. <pre class="smallexample">if (TEST_P (t) == 1)
  109. </pre></div>
  110. <p>as this code is not guaranteed to work correctly in the future.
  111. </p>
  112. <p>You should not take the address of values returned by the macros or
  113. functions described here. In particular, no guarantee is given that the
  114. values are lvalues.
  115. </p>
  116. <p>In general, the names of macros are all in uppercase, while the names of
  117. functions are entirely in lowercase. There are rare exceptions to this
  118. rule. You should assume that any macro or function whose name is made
  119. up entirely of uppercase letters may evaluate its arguments more than
  120. once. You may assume that a macro or function whose name is made up
  121. entirely of lowercase letters will evaluate its arguments only once.
  122. </p>
  123. <p>The <code>error_mark_node</code> is a special tree. Its tree code is
  124. <code>ERROR_MARK</code>, but since there is only ever one node with that code,
  125. the usual practice is to compare the tree against
  126. <code>error_mark_node</code>. (This test is just a test for pointer
  127. equality.) If an error has occurred during front-end processing the
  128. flag <code>errorcount</code> will be set. If the front end has encountered
  129. code it cannot handle, it will issue a message to the user and set
  130. <code>sorrycount</code>. When these flags are set, any macro or function
  131. which normally returns a tree of a particular kind may instead return
  132. the <code>error_mark_node</code>. Thus, if you intend to do any processing of
  133. erroneous code, you must be prepared to deal with the
  134. <code>error_mark_node</code>.
  135. </p>
  136. <p>Occasionally, a particular tree slot (like an operand to an expression,
  137. or a particular field in a declaration) will be referred to as
  138. &ldquo;reserved for the back end&rdquo;. These slots are used to store RTL when
  139. the tree is converted to RTL for use by the GCC back end. However, if
  140. that process is not taking place (e.g., if the front end is being hooked
  141. up to an intelligent editor), then those slots may be used by the
  142. back end presently in use.
  143. </p>
  144. <p>If you encounter situations that do not match this documentation, such
  145. as tree nodes of types not mentioned here, or macros documented to
  146. return entities of a particular kind that instead return entities of
  147. some different kind, you have found a bug, either in the front end or in
  148. the documentation. Please report these bugs as you would any other
  149. bug.
  150. </p>
  151. <table class="menu" border="0" cellspacing="0">
  152. <tr><td align="left" valign="top">&bull; <a href="Macros-and-Functions.html#Macros-and-Functions" accesskey="1">Macros and Functions</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Macros and functions that can be used with all trees.
  153. </td></tr>
  154. <tr><td align="left" valign="top">&bull; <a href="Identifiers.html#Identifiers" accesskey="2">Identifiers</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The names of things.
  155. </td></tr>
  156. <tr><td align="left" valign="top">&bull; <a href="Containers.html#Containers" accesskey="3">Containers</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Lists and vectors.
  157. </td></tr>
  158. </table>
  159. <hr>
  160. <div class="header">
  161. <p>
  162. Next: <a href="Types.html#Types" accesskey="n" rel="next">Types</a>, Previous: <a href="Deficiencies.html#Deficiencies" accesskey="p" rel="prev">Deficiencies</a>, Up: <a href="GENERIC.html#GENERIC" accesskey="u" rel="up">GENERIC</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>
  163. </div>
  164. </body>
  165. </html>