Namespaces.html 7.8 KB

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