Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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>Namespaces (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Namespaces (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Namespaces (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="Classes.html#Classes" rel="next" title="Classes">
  31. <link href="Types-for-C_002b_002b.html#Types-for-C_002b_002b" rel="prev" title="Types for C++">
  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="Namespaces"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Classes.html#Classes" accesskey="n" rel="next">Classes</a>, Previous: <a href="Types-for-C_002b_002b.html#Types-for-C_002b_002b" accesskey="p" rel="prev">Types for C++</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="Namespaces-1"></a>
  68. <h4 class="subsection">11.10.2 Namespaces</h4>
  69. <a name="index-namespace_002c-scope"></a>
  70. <a name="index-NAMESPACE_005fDECL-1"></a>
  71. <p>The root of the entire intermediate representation is the variable
  72. <code>global_namespace</code>. This is the namespace specified with <code>::</code>
  73. in C++ source code. All other namespaces, types, variables, functions,
  74. and so forth can be found starting with this namespace.
  75. </p>
  76. <p>However, except for the fact that it is distinguished as the root of the
  77. representation, the global namespace is no different from any other
  78. namespace. Thus, in what follows, we describe namespaces generally,
  79. rather than the global namespace in particular.
  80. </p>
  81. <p>A namespace is represented by a <code>NAMESPACE_DECL</code> node.
  82. </p>
  83. <p>The following macros and functions can be used on a <code>NAMESPACE_DECL</code>:
  84. </p>
  85. <dl compact="compact">
  86. <dt><code>DECL_NAME</code>
  87. <a name="index-DECL_005fNAME-3"></a>
  88. </dt>
  89. <dd><p>This macro is used to obtain the <code>IDENTIFIER_NODE</code> corresponding to
  90. the unqualified name of the name of the namespace (see <a href="Identifiers.html#Identifiers">Identifiers</a>).
  91. The name of the global namespace is &lsquo;<samp>::</samp>&rsquo;, even though in C++ the
  92. global namespace is unnamed. However, you should use comparison with
  93. <code>global_namespace</code>, rather than <code>DECL_NAME</code> to determine
  94. whether or not a namespace is the global one. An unnamed namespace
  95. will have a <code>DECL_NAME</code> equal to <code>anonymous_namespace_name</code>.
  96. Within a single translation unit, all unnamed namespaces will have the
  97. same name.
  98. </p>
  99. </dd>
  100. <dt><code>DECL_CONTEXT</code>
  101. <a name="index-DECL_005fCONTEXT"></a>
  102. </dt>
  103. <dd><p>This macro returns the enclosing namespace. The <code>DECL_CONTEXT</code> for
  104. the <code>global_namespace</code> is <code>NULL_TREE</code>.
  105. </p>
  106. </dd>
  107. <dt><code>DECL_NAMESPACE_ALIAS</code>
  108. <a name="index-DECL_005fNAMESPACE_005fALIAS"></a>
  109. </dt>
  110. <dd><p>If this declaration is for a namespace alias, then
  111. <code>DECL_NAMESPACE_ALIAS</code> is the namespace for which this one is an
  112. alias.
  113. </p>
  114. <p>Do not attempt to use <code>cp_namespace_decls</code> for a namespace which is
  115. an alias. Instead, follow <code>DECL_NAMESPACE_ALIAS</code> links until you
  116. reach an ordinary, non-alias, namespace, and call
  117. <code>cp_namespace_decls</code> there.
  118. </p>
  119. </dd>
  120. <dt><code>DECL_NAMESPACE_STD_P</code>
  121. <a name="index-DECL_005fNAMESPACE_005fSTD_005fP"></a>
  122. </dt>
  123. <dd><p>This predicate holds if the namespace is the special <code>::std</code>
  124. namespace.
  125. </p>
  126. </dd>
  127. <dt><code>cp_namespace_decls</code>
  128. <a name="index-cp_005fnamespace_005fdecls"></a>
  129. </dt>
  130. <dd><p>This function will return the declarations contained in the namespace,
  131. including types, overloaded functions, other namespaces, and so forth.
  132. If there are no declarations, this function will return
  133. <code>NULL_TREE</code>. The declarations are connected through their
  134. <code>TREE_CHAIN</code> fields.
  135. </p>
  136. <p>Although most entries on this list will be declarations,
  137. <code>TREE_LIST</code> nodes may also appear. In this case, the
  138. <code>TREE_VALUE</code> will be an <code>OVERLOAD</code>. The value of the
  139. <code>TREE_PURPOSE</code> is unspecified; back ends should ignore this value.
  140. As with the other kinds of declarations returned by
  141. <code>cp_namespace_decls</code>, the <code>TREE_CHAIN</code> will point to the next
  142. declaration in this list.
  143. </p>
  144. <p>For more information on the kinds of declarations that can occur on this
  145. list, See <a href="Declarations.html#Declarations">Declarations</a>. Some declarations will not appear on this
  146. list. In particular, no <code>FIELD_DECL</code>, <code>LABEL_DECL</code>, or
  147. <code>PARM_DECL</code> nodes will appear here.
  148. </p>
  149. <p>This function cannot be used with namespaces that have
  150. <code>DECL_NAMESPACE_ALIAS</code> set.
  151. </p>
  152. </dd>
  153. </dl>
  154. <hr>
  155. <div class="header">
  156. <p>
  157. Next: <a href="Classes.html#Classes" accesskey="n" rel="next">Classes</a>, Previous: <a href="Types-for-C_002b_002b.html#Types-for-C_002b_002b" accesskey="p" rel="prev">Types for C++</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>
  158. </div>
  159. </body>
  160. </html>