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ů.

Working-with-declarations.html 10KB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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>Working with declarations (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Working with declarations (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Working with declarations (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="Declarations.html#Declarations" rel="up" title="Declarations">
  30. <link href="Internal-structure.html#Internal-structure" rel="next" title="Internal structure">
  31. <link href="Declarations.html#Declarations" rel="prev" title="Declarations">
  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="Working-with-declarations"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Internal-structure.html#Internal-structure" accesskey="n" rel="next">Internal structure</a>, Up: <a href="Declarations.html#Declarations" accesskey="u" rel="up">Declarations</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="Working-with-declarations-1"></a>
  68. <h4 class="subsection">11.4.1 Working with declarations</h4>
  69. <p>Some macros can be used with any kind of declaration. These include:
  70. </p><dl compact="compact">
  71. <dt><code>DECL_NAME</code>
  72. <a name="index-DECL_005fNAME"></a>
  73. </dt>
  74. <dd><p>This macro returns an <code>IDENTIFIER_NODE</code> giving the name of the
  75. entity.
  76. </p>
  77. </dd>
  78. <dt><code>TREE_TYPE</code>
  79. <a name="index-TREE_005fTYPE-2"></a>
  80. </dt>
  81. <dd><p>This macro returns the type of the entity declared.
  82. </p>
  83. </dd>
  84. <dt><code>EXPR_FILENAME</code>
  85. <a name="index-EXPR_005fFILENAME"></a>
  86. </dt>
  87. <dd><p>This macro returns the name of the file in which the entity was
  88. declared, as a <code>char*</code>. For an entity declared implicitly by the
  89. compiler (like <code>__builtin_memcpy</code>), this will be the string
  90. <code>&quot;&lt;internal&gt;&quot;</code>.
  91. </p>
  92. </dd>
  93. <dt><code>EXPR_LINENO</code>
  94. <a name="index-EXPR_005fLINENO"></a>
  95. </dt>
  96. <dd><p>This macro returns the line number at which the entity was declared, as
  97. an <code>int</code>.
  98. </p>
  99. </dd>
  100. <dt><code>DECL_ARTIFICIAL</code>
  101. <a name="index-DECL_005fARTIFICIAL"></a>
  102. </dt>
  103. <dd><p>This predicate holds if the declaration was implicitly generated by the
  104. compiler. For example, this predicate will hold of an implicitly
  105. declared member function, or of the <code>TYPE_DECL</code> implicitly
  106. generated for a class type. Recall that in C++ code like:
  107. </p><div class="smallexample">
  108. <pre class="smallexample">struct S {};
  109. </pre></div>
  110. <p>is roughly equivalent to C code like:
  111. </p><div class="smallexample">
  112. <pre class="smallexample">struct S {};
  113. typedef struct S S;
  114. </pre></div>
  115. <p>The implicitly generated <code>typedef</code> declaration is represented by a
  116. <code>TYPE_DECL</code> for which <code>DECL_ARTIFICIAL</code> holds.
  117. </p>
  118. </dd>
  119. </dl>
  120. <p>The various kinds of declarations include:
  121. </p><dl compact="compact">
  122. <dt><code>LABEL_DECL</code></dt>
  123. <dd><p>These nodes are used to represent labels in function bodies. For more
  124. information, see <a href="Functions.html#Functions">Functions</a>. These nodes only appear in block
  125. scopes.
  126. </p>
  127. </dd>
  128. <dt><code>CONST_DECL</code></dt>
  129. <dd><p>These nodes are used to represent enumeration constants. The value of
  130. the constant is given by <code>DECL_INITIAL</code> which will be an
  131. <code>INTEGER_CST</code> with the same type as the <code>TREE_TYPE</code> of the
  132. <code>CONST_DECL</code>, i.e., an <code>ENUMERAL_TYPE</code>.
  133. </p>
  134. </dd>
  135. <dt><code>RESULT_DECL</code></dt>
  136. <dd><p>These nodes represent the value returned by a function. When a value is
  137. assigned to a <code>RESULT_DECL</code>, that indicates that the value should
  138. be returned, via bitwise copy, by the function. You can use
  139. <code>DECL_SIZE</code> and <code>DECL_ALIGN</code> on a <code>RESULT_DECL</code>, just as
  140. with a <code>VAR_DECL</code>.
  141. </p>
  142. </dd>
  143. <dt><code>TYPE_DECL</code></dt>
  144. <dd><p>These nodes represent <code>typedef</code> declarations. The <code>TREE_TYPE</code>
  145. is the type declared to have the name given by <code>DECL_NAME</code>. In
  146. some cases, there is no associated name.
  147. </p>
  148. </dd>
  149. <dt><code>VAR_DECL</code></dt>
  150. <dd><p>These nodes represent variables with namespace or block scope, as well
  151. as static data members. The <code>DECL_SIZE</code> and <code>DECL_ALIGN</code> are
  152. analogous to <code>TYPE_SIZE</code> and <code>TYPE_ALIGN</code>. For a declaration,
  153. you should always use the <code>DECL_SIZE</code> and <code>DECL_ALIGN</code> rather
  154. than the <code>TYPE_SIZE</code> and <code>TYPE_ALIGN</code> given by the
  155. <code>TREE_TYPE</code>, since special attributes may have been applied to the
  156. variable to give it a particular size and alignment. You may use the
  157. predicates <code>DECL_THIS_STATIC</code> or <code>DECL_THIS_EXTERN</code> to test
  158. whether the storage class specifiers <code>static</code> or <code>extern</code> were
  159. used to declare a variable.
  160. </p>
  161. <p>If this variable is initialized (but does not require a constructor),
  162. the <code>DECL_INITIAL</code> will be an expression for the initializer. The
  163. initializer should be evaluated, and a bitwise copy into the variable
  164. performed. If the <code>DECL_INITIAL</code> is the <code>error_mark_node</code>,
  165. there is an initializer, but it is given by an explicit statement later
  166. in the code; no bitwise copy is required.
  167. </p>
  168. <p>GCC provides an extension that allows either automatic variables, or
  169. global variables, to be placed in particular registers. This extension
  170. is being used for a particular <code>VAR_DECL</code> if <code>DECL_REGISTER</code>
  171. holds for the <code>VAR_DECL</code>, and if <code>DECL_ASSEMBLER_NAME</code> is not
  172. equal to <code>DECL_NAME</code>. In that case, <code>DECL_ASSEMBLER_NAME</code> is
  173. the name of the register into which the variable will be placed.
  174. </p>
  175. </dd>
  176. <dt><code>PARM_DECL</code></dt>
  177. <dd><p>Used to represent a parameter to a function. Treat these nodes
  178. similarly to <code>VAR_DECL</code> nodes. These nodes only appear in the
  179. <code>DECL_ARGUMENTS</code> for a <code>FUNCTION_DECL</code>.
  180. </p>
  181. <p>The <code>DECL_ARG_TYPE</code> for a <code>PARM_DECL</code> is the type that will
  182. actually be used when a value is passed to this function. It may be a
  183. wider type than the <code>TREE_TYPE</code> of the parameter; for example, the
  184. ordinary type might be <code>short</code> while the <code>DECL_ARG_TYPE</code> is
  185. <code>int</code>.
  186. </p>
  187. </dd>
  188. <dt><code>DEBUG_EXPR_DECL</code></dt>
  189. <dd><p>Used to represent an anonymous debug-information temporary created to
  190. hold an expression as it is optimized away, so that its value can be
  191. referenced in debug bind statements.
  192. </p>
  193. </dd>
  194. <dt><code>FIELD_DECL</code></dt>
  195. <dd><p>These nodes represent non-static data members. The <code>DECL_SIZE</code> and
  196. <code>DECL_ALIGN</code> behave as for <code>VAR_DECL</code> nodes.
  197. The position of the field within the parent record is specified by a
  198. combination of three attributes. <code>DECL_FIELD_OFFSET</code> is the position,
  199. counting in bytes, of the <code>DECL_OFFSET_ALIGN</code>-bit sized word containing
  200. the bit of the field closest to the beginning of the structure.
  201. <code>DECL_FIELD_BIT_OFFSET</code> is the bit offset of the first bit of the field
  202. within this word; this may be nonzero even for fields that are not bit-fields,
  203. since <code>DECL_OFFSET_ALIGN</code> may be greater than the natural alignment
  204. of the field&rsquo;s type.
  205. </p>
  206. <p>If <code>DECL_C_BIT_FIELD</code> holds, this field is a bit-field. In a bit-field,
  207. <code>DECL_BIT_FIELD_TYPE</code> also contains the type that was originally
  208. specified for it, while DECL_TYPE may be a modified type with lesser precision,
  209. according to the size of the bit field.
  210. </p>
  211. </dd>
  212. <dt><code>NAMESPACE_DECL</code></dt>
  213. <dd><p>Namespaces provide a name hierarchy for other declarations. They
  214. appear in the <code>DECL_CONTEXT</code> of other <code>_DECL</code> nodes.
  215. </p>
  216. </dd>
  217. </dl>
  218. <hr>
  219. <div class="header">
  220. <p>
  221. Next: <a href="Internal-structure.html#Internal-structure" accesskey="n" rel="next">Internal structure</a>, Up: <a href="Declarations.html#Declarations" accesskey="u" rel="up">Declarations</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>