You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
13KB

  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>Functions for C++ (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Functions for C++ (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Functions for C++ (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="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" rel="up" title="C and C++ Trees">
  30. <link href="Statements-for-C_002b_002b.html#Statements-for-C_002b_002b" rel="next" title="Statements for C++">
  31. <link href="Classes.html#Classes" rel="prev" title="Classes">
  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="Functions-for-C_002b_002b"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Statements-for-C_002b_002b.html#Statements-for-C_002b_002b" accesskey="n" rel="next">Statements for C++</a>, Previous: <a href="Classes.html#Classes" accesskey="p" rel="prev">Classes</a>, Up: <a href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" accesskey="u" rel="up">C and C++ Trees</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="Functions-for-C_002b_002b-1"></a>
  68. <h4 class="subsection">11.10.4 Functions for C++</h4>
  69. <a name="index-function-1"></a>
  70. <a name="index-FUNCTION_005fDECL-1"></a>
  71. <a name="index-OVERLOAD"></a>
  72. <a name="index-OVL_005fCURRENT"></a>
  73. <a name="index-OVL_005fNEXT"></a>
  74. <p>A function is represented by a <code>FUNCTION_DECL</code> node. A set of
  75. overloaded functions is sometimes represented by an <code>OVERLOAD</code> node.
  76. </p>
  77. <p>An <code>OVERLOAD</code> node is not a declaration, so none of the
  78. &lsquo;<samp>DECL_</samp>&rsquo; macros should be used on an <code>OVERLOAD</code>. An
  79. <code>OVERLOAD</code> node is similar to a <code>TREE_LIST</code>. Use
  80. <code>OVL_CURRENT</code> to get the function associated with an
  81. <code>OVERLOAD</code> node; use <code>OVL_NEXT</code> to get the next
  82. <code>OVERLOAD</code> node in the list of overloaded functions. The macros
  83. <code>OVL_CURRENT</code> and <code>OVL_NEXT</code> are actually polymorphic; you can
  84. use them to work with <code>FUNCTION_DECL</code> nodes as well as with
  85. overloads. In the case of a <code>FUNCTION_DECL</code>, <code>OVL_CURRENT</code>
  86. will always return the function itself, and <code>OVL_NEXT</code> will always
  87. be <code>NULL_TREE</code>.
  88. </p>
  89. <p>To determine the scope of a function, you can use the
  90. <code>DECL_CONTEXT</code> macro. This macro will return the class
  91. (either a <code>RECORD_TYPE</code> or a <code>UNION_TYPE</code>) or namespace (a
  92. <code>NAMESPACE_DECL</code>) of which the function is a member. For a virtual
  93. function, this macro returns the class in which the function was
  94. actually defined, not the base class in which the virtual declaration
  95. occurred.
  96. </p>
  97. <p>If a friend function is defined in a class scope, the
  98. <code>DECL_FRIEND_CONTEXT</code> macro can be used to determine the class in
  99. which it was defined. For example, in
  100. </p><div class="smallexample">
  101. <pre class="smallexample">class C { friend void f() {} };
  102. </pre></div>
  103. <p>the <code>DECL_CONTEXT</code> for <code>f</code> will be the
  104. <code>global_namespace</code>, but the <code>DECL_FRIEND_CONTEXT</code> will be the
  105. <code>RECORD_TYPE</code> for <code>C</code>.
  106. </p>
  107. <p>The following macros and functions can be used on a <code>FUNCTION_DECL</code>:
  108. </p><dl compact="compact">
  109. <dt><code>DECL_MAIN_P</code>
  110. <a name="index-DECL_005fMAIN_005fP"></a>
  111. </dt>
  112. <dd><p>This predicate holds for a function that is the program entry point
  113. <code>::code</code>.
  114. </p>
  115. </dd>
  116. <dt><code>DECL_LOCAL_FUNCTION_P</code>
  117. <a name="index-DECL_005fLOCAL_005fFUNCTION_005fP"></a>
  118. </dt>
  119. <dd><p>This predicate holds if the function was declared at block scope, even
  120. though it has a global scope.
  121. </p>
  122. </dd>
  123. <dt><code>DECL_ANTICIPATED</code>
  124. <a name="index-DECL_005fANTICIPATED"></a>
  125. </dt>
  126. <dd><p>This predicate holds if the function is a built-in function but its
  127. prototype is not yet explicitly declared.
  128. </p>
  129. </dd>
  130. <dt><code>DECL_EXTERN_C_FUNCTION_P</code>
  131. <a name="index-DECL_005fEXTERN_005fC_005fFUNCTION_005fP"></a>
  132. </dt>
  133. <dd><p>This predicate holds if the function is declared as an
  134. &lsquo;<code>extern &quot;C&quot;</code>&rsquo; function.
  135. </p>
  136. </dd>
  137. <dt><code>DECL_LINKONCE_P</code>
  138. <a name="index-DECL_005fLINKONCE_005fP"></a>
  139. </dt>
  140. <dd><p>This macro holds if multiple copies of this function may be emitted in
  141. various translation units. It is the responsibility of the linker to
  142. merge the various copies. Template instantiations are the most common
  143. example of functions for which <code>DECL_LINKONCE_P</code> holds; G++
  144. instantiates needed templates in all translation units which require them,
  145. and then relies on the linker to remove duplicate instantiations.
  146. </p>
  147. <p>FIXME: This macro is not yet implemented.
  148. </p>
  149. </dd>
  150. <dt><code>DECL_FUNCTION_MEMBER_P</code>
  151. <a name="index-DECL_005fFUNCTION_005fMEMBER_005fP"></a>
  152. </dt>
  153. <dd><p>This macro holds if the function is a member of a class, rather than a
  154. member of a namespace.
  155. </p>
  156. </dd>
  157. <dt><code>DECL_STATIC_FUNCTION_P</code>
  158. <a name="index-DECL_005fSTATIC_005fFUNCTION_005fP"></a>
  159. </dt>
  160. <dd><p>This predicate holds if the function a static member function.
  161. </p>
  162. </dd>
  163. <dt><code>DECL_NONSTATIC_MEMBER_FUNCTION_P</code>
  164. <a name="index-DECL_005fNONSTATIC_005fMEMBER_005fFUNCTION_005fP"></a>
  165. </dt>
  166. <dd><p>This macro holds for a non-static member function.
  167. </p>
  168. </dd>
  169. <dt><code>DECL_CONST_MEMFUNC_P</code>
  170. <a name="index-DECL_005fCONST_005fMEMFUNC_005fP"></a>
  171. </dt>
  172. <dd><p>This predicate holds for a <code>const</code>-member function.
  173. </p>
  174. </dd>
  175. <dt><code>DECL_VOLATILE_MEMFUNC_P</code>
  176. <a name="index-DECL_005fVOLATILE_005fMEMFUNC_005fP"></a>
  177. </dt>
  178. <dd><p>This predicate holds for a <code>volatile</code>-member function.
  179. </p>
  180. </dd>
  181. <dt><code>DECL_CONSTRUCTOR_P</code>
  182. <a name="index-DECL_005fCONSTRUCTOR_005fP"></a>
  183. </dt>
  184. <dd><p>This macro holds if the function is a constructor.
  185. </p>
  186. </dd>
  187. <dt><code>DECL_NONCONVERTING_P</code>
  188. <a name="index-DECL_005fNONCONVERTING_005fP"></a>
  189. </dt>
  190. <dd><p>This predicate holds if the constructor is a non-converting constructor.
  191. </p>
  192. </dd>
  193. <dt><code>DECL_COMPLETE_CONSTRUCTOR_P</code>
  194. <a name="index-DECL_005fCOMPLETE_005fCONSTRUCTOR_005fP"></a>
  195. </dt>
  196. <dd><p>This predicate holds for a function which is a constructor for an object
  197. of a complete type.
  198. </p>
  199. </dd>
  200. <dt><code>DECL_BASE_CONSTRUCTOR_P</code>
  201. <a name="index-DECL_005fBASE_005fCONSTRUCTOR_005fP"></a>
  202. </dt>
  203. <dd><p>This predicate holds for a function which is a constructor for a base
  204. class sub-object.
  205. </p>
  206. </dd>
  207. <dt><code>DECL_COPY_CONSTRUCTOR_P</code>
  208. <a name="index-DECL_005fCOPY_005fCONSTRUCTOR_005fP"></a>
  209. </dt>
  210. <dd><p>This predicate holds for a function which is a copy-constructor.
  211. </p>
  212. </dd>
  213. <dt><code>DECL_DESTRUCTOR_P</code>
  214. <a name="index-DECL_005fDESTRUCTOR_005fP"></a>
  215. </dt>
  216. <dd><p>This macro holds if the function is a destructor.
  217. </p>
  218. </dd>
  219. <dt><code>DECL_COMPLETE_DESTRUCTOR_P</code>
  220. <a name="index-DECL_005fCOMPLETE_005fDESTRUCTOR_005fP"></a>
  221. </dt>
  222. <dd><p>This predicate holds if the function is the destructor for an object a
  223. complete type.
  224. </p>
  225. </dd>
  226. <dt><code>DECL_OVERLOADED_OPERATOR_P</code>
  227. <a name="index-DECL_005fOVERLOADED_005fOPERATOR_005fP"></a>
  228. </dt>
  229. <dd><p>This macro holds if the function is an overloaded operator.
  230. </p>
  231. </dd>
  232. <dt><code>DECL_CONV_FN_P</code>
  233. <a name="index-DECL_005fCONV_005fFN_005fP"></a>
  234. </dt>
  235. <dd><p>This macro holds if the function is a type-conversion operator.
  236. </p>
  237. </dd>
  238. <dt><code>DECL_GLOBAL_CTOR_P</code>
  239. <a name="index-DECL_005fGLOBAL_005fCTOR_005fP"></a>
  240. </dt>
  241. <dd><p>This predicate holds if the function is a file-scope initialization
  242. function.
  243. </p>
  244. </dd>
  245. <dt><code>DECL_GLOBAL_DTOR_P</code>
  246. <a name="index-DECL_005fGLOBAL_005fDTOR_005fP"></a>
  247. </dt>
  248. <dd><p>This predicate holds if the function is a file-scope finalization
  249. function.
  250. </p>
  251. </dd>
  252. <dt><code>DECL_THUNK_P</code>
  253. <a name="index-DECL_005fTHUNK_005fP"></a>
  254. </dt>
  255. <dd><p>This predicate holds if the function is a thunk.
  256. </p>
  257. <p>These functions represent stub code that adjusts the <code>this</code> pointer
  258. and then jumps to another function. When the jumped-to function
  259. returns, control is transferred directly to the caller, without
  260. returning to the thunk. The first parameter to the thunk is always the
  261. <code>this</code> pointer; the thunk should add <code>THUNK_DELTA</code> to this
  262. value. (The <code>THUNK_DELTA</code> is an <code>int</code>, not an
  263. <code>INTEGER_CST</code>.)
  264. </p>
  265. <p>Then, if <code>THUNK_VCALL_OFFSET</code> (an <code>INTEGER_CST</code>) is nonzero
  266. the adjusted <code>this</code> pointer must be adjusted again. The complete
  267. calculation is given by the following pseudo-code:
  268. </p>
  269. <div class="smallexample">
  270. <pre class="smallexample">this += THUNK_DELTA
  271. if (THUNK_VCALL_OFFSET)
  272. this += (*((ptrdiff_t **) this))[THUNK_VCALL_OFFSET]
  273. </pre></div>
  274. <p>Finally, the thunk should jump to the location given
  275. by <code>DECL_INITIAL</code>; this will always be an expression for the
  276. address of a function.
  277. </p>
  278. </dd>
  279. <dt><code>DECL_NON_THUNK_FUNCTION_P</code>
  280. <a name="index-DECL_005fNON_005fTHUNK_005fFUNCTION_005fP"></a>
  281. </dt>
  282. <dd><p>This predicate holds if the function is <em>not</em> a thunk function.
  283. </p>
  284. </dd>
  285. <dt><code>GLOBAL_INIT_PRIORITY</code>
  286. <a name="index-GLOBAL_005fINIT_005fPRIORITY"></a>
  287. </dt>
  288. <dd><p>If either <code>DECL_GLOBAL_CTOR_P</code> or <code>DECL_GLOBAL_DTOR_P</code> holds,
  289. then this gives the initialization priority for the function. The
  290. linker will arrange that all functions for which
  291. <code>DECL_GLOBAL_CTOR_P</code> holds are run in increasing order of priority
  292. before <code>main</code> is called. When the program exits, all functions for
  293. which <code>DECL_GLOBAL_DTOR_P</code> holds are run in the reverse order.
  294. </p>
  295. </dd>
  296. <dt><code>TYPE_RAISES_EXCEPTIONS</code>
  297. <a name="index-TYPE_005fRAISES_005fEXCEPTIONS"></a>
  298. </dt>
  299. <dd><p>This macro returns the list of exceptions that a (member-)function can
  300. raise. The returned list, if non <code>NULL</code>, is comprised of nodes
  301. whose <code>TREE_VALUE</code> represents a type.
  302. </p>
  303. </dd>
  304. <dt><code>TYPE_NOTHROW_P</code>
  305. <a name="index-TYPE_005fNOTHROW_005fP"></a>
  306. </dt>
  307. <dd><p>This predicate holds when the exception-specification of its arguments
  308. is of the form &lsquo;<code>()</code>&rsquo;.
  309. </p>
  310. </dd>
  311. <dt><code>DECL_ARRAY_DELETE_OPERATOR_P</code>
  312. <a name="index-DECL_005fARRAY_005fDELETE_005fOPERATOR_005fP"></a>
  313. </dt>
  314. <dd><p>This predicate holds if the function an overloaded
  315. <code>operator delete[]</code>.
  316. </p>
  317. </dd>
  318. </dl>
  319. <hr>
  320. <div class="header">
  321. <p>
  322. Next: <a href="Statements-for-C_002b_002b.html#Statements-for-C_002b_002b" accesskey="n" rel="next">Statements for C++</a>, Previous: <a href="Classes.html#Classes" accesskey="p" rel="prev">Classes</a>, Up: <a href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" accesskey="u" rel="up">C and C++ Trees</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>
  323. </div>
  324. </body>
  325. </html>