Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

209 lines
8.0KB

  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>Function Basics (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Function Basics (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Function Basics (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="Functions.html#Functions" rel="up" title="Functions">
  30. <link href="Function-Properties.html#Function-Properties" rel="next" title="Function Properties">
  31. <link href="Functions.html#Functions" rel="prev" title="Functions">
  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="Function-Basics"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Function-Properties.html#Function-Properties" accesskey="n" rel="next">Function Properties</a>, Up: <a href="Functions.html#Functions" accesskey="u" rel="up">Functions</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="Function-Basics-1"></a>
  68. <h4 class="subsection">11.8.1 Function Basics</h4>
  69. <a name="index-DECL_005fNAME-1"></a>
  70. <a name="index-DECL_005fASSEMBLER_005fNAME"></a>
  71. <a name="index-TREE_005fPUBLIC"></a>
  72. <a name="index-DECL_005fARTIFICIAL-1"></a>
  73. <a name="index-DECL_005fFUNCTION_005fSPECIFIC_005fTARGET"></a>
  74. <a name="index-DECL_005fFUNCTION_005fSPECIFIC_005fOPTIMIZATION"></a>
  75. <p>A function has four core parts: the name, the parameters, the result,
  76. and the body. The following macros and functions access these parts
  77. of a <code>FUNCTION_DECL</code> as well as other basic features:
  78. </p><dl compact="compact">
  79. <dt><code>DECL_NAME</code>
  80. <a name="index-DECL_005fNAME-2"></a>
  81. </dt>
  82. <dd><p>This macro returns the unqualified name of the function, as an
  83. <code>IDENTIFIER_NODE</code>. For an instantiation of a function template,
  84. the <code>DECL_NAME</code> is the unqualified name of the template, not
  85. something like <code>f&lt;int&gt;</code>. The value of <code>DECL_NAME</code> is
  86. undefined when used on a constructor, destructor, overloaded operator,
  87. or type-conversion operator, or any function that is implicitly
  88. generated by the compiler. See below for macros that can be used to
  89. distinguish these cases.
  90. </p>
  91. </dd>
  92. <dt><code>DECL_ASSEMBLER_NAME</code>
  93. <a name="index-DECL_005fASSEMBLER_005fNAME-1"></a>
  94. </dt>
  95. <dd><p>This macro returns the mangled name of the function, also an
  96. <code>IDENTIFIER_NODE</code>. This name does not contain leading underscores
  97. on systems that prefix all identifiers with underscores. The mangled
  98. name is computed in the same way on all platforms; if special processing
  99. is required to deal with the object file format used on a particular
  100. platform, it is the responsibility of the back end to perform those
  101. modifications. (Of course, the back end should not modify
  102. <code>DECL_ASSEMBLER_NAME</code> itself.)
  103. </p>
  104. <p>Using <code>DECL_ASSEMBLER_NAME</code> will cause additional memory to be
  105. allocated (for the mangled name of the entity) so it should be used
  106. only when emitting assembly code. It should not be used within the
  107. optimizers to determine whether or not two declarations are the same,
  108. even though some of the existing optimizers do use it in that way.
  109. These uses will be removed over time.
  110. </p>
  111. </dd>
  112. <dt><code>DECL_ARGUMENTS</code>
  113. <a name="index-DECL_005fARGUMENTS"></a>
  114. </dt>
  115. <dd><p>This macro returns the <code>PARM_DECL</code> for the first argument to the
  116. function. Subsequent <code>PARM_DECL</code> nodes can be obtained by
  117. following the <code>TREE_CHAIN</code> links.
  118. </p>
  119. </dd>
  120. <dt><code>DECL_RESULT</code>
  121. <a name="index-DECL_005fRESULT"></a>
  122. </dt>
  123. <dd><p>This macro returns the <code>RESULT_DECL</code> for the function.
  124. </p>
  125. </dd>
  126. <dt><code>DECL_SAVED_TREE</code>
  127. <a name="index-DECL_005fSAVED_005fTREE"></a>
  128. </dt>
  129. <dd><p>This macro returns the complete body of the function.
  130. </p>
  131. </dd>
  132. <dt><code>TREE_TYPE</code>
  133. <a name="index-TREE_005fTYPE-5"></a>
  134. </dt>
  135. <dd><p>This macro returns the <code>FUNCTION_TYPE</code> or <code>METHOD_TYPE</code> for
  136. the function.
  137. </p>
  138. </dd>
  139. <dt><code>DECL_INITIAL</code>
  140. <a name="index-DECL_005fINITIAL-1"></a>
  141. </dt>
  142. <dd><p>A function that has a definition in the current translation unit will
  143. have a non-<code>NULL</code> <code>DECL_INITIAL</code>. However, back ends should not make
  144. use of the particular value given by <code>DECL_INITIAL</code>.
  145. </p>
  146. <p>It should contain a tree of <code>BLOCK</code> nodes that mirrors the scopes
  147. that variables are bound in the function. Each block contains a list
  148. of decls declared in a basic block, a pointer to a chain of blocks at
  149. the next lower scope level, then a pointer to the next block at the
  150. same level and a backpointer to the parent <code>BLOCK</code> or
  151. <code>FUNCTION_DECL</code>. So given a function as follows:
  152. </p>
  153. <div class="smallexample">
  154. <pre class="smallexample">void foo()
  155. {
  156. int a;
  157. {
  158. int b;
  159. }
  160. int c;
  161. }
  162. </pre></div>
  163. <p>you would get the following:
  164. </p>
  165. <div class="smallexample">
  166. <pre class="smallexample">tree foo = FUNCTION_DECL;
  167. tree decl_a = VAR_DECL;
  168. tree decl_b = VAR_DECL;
  169. tree decl_c = VAR_DECL;
  170. tree block_a = BLOCK;
  171. tree block_b = BLOCK;
  172. tree block_c = BLOCK;
  173. BLOCK_VARS(block_a) = decl_a;
  174. BLOCK_SUBBLOCKS(block_a) = block_b;
  175. BLOCK_CHAIN(block_a) = block_c;
  176. BLOCK_SUPERCONTEXT(block_a) = foo;
  177. BLOCK_VARS(block_b) = decl_b;
  178. BLOCK_SUPERCONTEXT(block_b) = block_a;
  179. BLOCK_VARS(block_c) = decl_c;
  180. BLOCK_SUPERCONTEXT(block_c) = foo;
  181. DECL_INITIAL(foo) = block_a;
  182. </pre></div>
  183. </dd>
  184. </dl>
  185. <hr>
  186. <div class="header">
  187. <p>
  188. Next: <a href="Function-Properties.html#Function-Properties" accesskey="n" rel="next">Function Properties</a>, Up: <a href="Functions.html#Functions" accesskey="u" rel="up">Functions</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>
  189. </div>
  190. </body>
  191. </html>