177 lines
7.8 KiB
HTML
177 lines
7.8 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!-- Copyright (C) 1988-2016 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with the
|
||
|
Invariant Sections being "Funding Free Software", the Front-Cover
|
||
|
Texts being (a) (see below), and with the Back-Cover Texts being (b)
|
||
|
(see below). A copy of the license is included in the section entitled
|
||
|
"GNU Free Documentation License".
|
||
|
|
||
|
(a) The FSF's Front-Cover Text is:
|
||
|
|
||
|
A GNU Manual
|
||
|
|
||
|
(b) The FSF's Back-Cover Text is:
|
||
|
|
||
|
You have freedom to copy and modify this GNU Manual, like GNU
|
||
|
software. Copies published by the Free Software Foundation raise
|
||
|
funds for GNU development. -->
|
||
|
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>GNU Compiler Collection (GCC) Internals: Namespaces</title>
|
||
|
|
||
|
<meta name="description" content="GNU Compiler Collection (GCC) Internals: Namespaces">
|
||
|
<meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Namespaces">
|
||
|
<meta name="resource-type" content="document">
|
||
|
<meta name="distribution" content="global">
|
||
|
<meta name="Generator" content="makeinfo">
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<link href="index.html#Top" rel="start" title="Top">
|
||
|
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
|
||
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
||
|
<link href="C-and-C_002b_002b-Trees.html#C-and-C_002b_002b-Trees" rel="up" title="C and C++ Trees">
|
||
|
<link href="Classes.html#Classes" rel="next" title="Classes">
|
||
|
<link href="Types-for-C_002b_002b.html#Types-for-C_002b_002b" rel="prev" title="Types for C++">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.indentedblock {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
|
||
|
div.smalllisp {margin-left: 3.2em}
|
||
|
kbd {font-style:oblique}
|
||
|
pre.display {font-family: inherit}
|
||
|
pre.format {font-family: inherit}
|
||
|
pre.menu-comment {font-family: serif}
|
||
|
pre.menu-preformatted {font-family: serif}
|
||
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
||
|
pre.smallexample {font-size: smaller}
|
||
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
||
|
pre.smalllisp {font-size: smaller}
|
||
|
span.nocodebreak {white-space:nowrap}
|
||
|
span.nolinebreak {white-space:nowrap}
|
||
|
span.roman {font-family:serif; font-weight:normal}
|
||
|
span.sansserif {font-family:sans-serif; font-weight:normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
|
||
|
<a name="Namespaces"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
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> [<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>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<a name="Namespaces-1"></a>
|
||
|
<h4 class="subsection">10.10.2 Namespaces</h4>
|
||
|
<a name="index-namespace_002c-scope"></a>
|
||
|
<a name="index-NAMESPACE_005fDECL-1"></a>
|
||
|
|
||
|
<p>The root of the entire intermediate representation is the variable
|
||
|
<code>global_namespace</code>. This is the namespace specified with <code>::</code>
|
||
|
in C++ source code. All other namespaces, types, variables, functions,
|
||
|
and so forth can be found starting with this namespace.
|
||
|
</p>
|
||
|
<p>However, except for the fact that it is distinguished as the root of the
|
||
|
representation, the global namespace is no different from any other
|
||
|
namespace. Thus, in what follows, we describe namespaces generally,
|
||
|
rather than the global namespace in particular.
|
||
|
</p>
|
||
|
<p>A namespace is represented by a <code>NAMESPACE_DECL</code> node.
|
||
|
</p>
|
||
|
<p>The following macros and functions can be used on a <code>NAMESPACE_DECL</code>:
|
||
|
</p>
|
||
|
<dl compact="compact">
|
||
|
<dt><code>DECL_NAME</code>
|
||
|
<a name="index-DECL_005fNAME-3"></a>
|
||
|
</dt>
|
||
|
<dd><p>This macro is used to obtain the <code>IDENTIFIER_NODE</code> corresponding to
|
||
|
the unqualified name of the name of the namespace (see <a href="Identifiers.html#Identifiers">Identifiers</a>).
|
||
|
The name of the global namespace is ‘<samp>::</samp>’, even though in C++ the
|
||
|
global namespace is unnamed. However, you should use comparison with
|
||
|
<code>global_namespace</code>, rather than <code>DECL_NAME</code> to determine
|
||
|
whether or not a namespace is the global one. An unnamed namespace
|
||
|
will have a <code>DECL_NAME</code> equal to <code>anonymous_namespace_name</code>.
|
||
|
Within a single translation unit, all unnamed namespaces will have the
|
||
|
same name.
|
||
|
</p>
|
||
|
</dd>
|
||
|
<dt><code>DECL_CONTEXT</code>
|
||
|
<a name="index-DECL_005fCONTEXT"></a>
|
||
|
</dt>
|
||
|
<dd><p>This macro returns the enclosing namespace. The <code>DECL_CONTEXT</code> for
|
||
|
the <code>global_namespace</code> is <code>NULL_TREE</code>.
|
||
|
</p>
|
||
|
</dd>
|
||
|
<dt><code>DECL_NAMESPACE_ALIAS</code>
|
||
|
<a name="index-DECL_005fNAMESPACE_005fALIAS"></a>
|
||
|
</dt>
|
||
|
<dd><p>If this declaration is for a namespace alias, then
|
||
|
<code>DECL_NAMESPACE_ALIAS</code> is the namespace for which this one is an
|
||
|
alias.
|
||
|
</p>
|
||
|
<p>Do not attempt to use <code>cp_namespace_decls</code> for a namespace which is
|
||
|
an alias. Instead, follow <code>DECL_NAMESPACE_ALIAS</code> links until you
|
||
|
reach an ordinary, non-alias, namespace, and call
|
||
|
<code>cp_namespace_decls</code> there.
|
||
|
</p>
|
||
|
</dd>
|
||
|
<dt><code>DECL_NAMESPACE_STD_P</code>
|
||
|
<a name="index-DECL_005fNAMESPACE_005fSTD_005fP"></a>
|
||
|
</dt>
|
||
|
<dd><p>This predicate holds if the namespace is the special <code>::std</code>
|
||
|
namespace.
|
||
|
</p>
|
||
|
</dd>
|
||
|
<dt><code>cp_namespace_decls</code>
|
||
|
<a name="index-cp_005fnamespace_005fdecls"></a>
|
||
|
</dt>
|
||
|
<dd><p>This function will return the declarations contained in the namespace,
|
||
|
including types, overloaded functions, other namespaces, and so forth.
|
||
|
If there are no declarations, this function will return
|
||
|
<code>NULL_TREE</code>. The declarations are connected through their
|
||
|
<code>TREE_CHAIN</code> fields.
|
||
|
</p>
|
||
|
<p>Although most entries on this list will be declarations,
|
||
|
<code>TREE_LIST</code> nodes may also appear. In this case, the
|
||
|
<code>TREE_VALUE</code> will be an <code>OVERLOAD</code>. The value of the
|
||
|
<code>TREE_PURPOSE</code> is unspecified; back ends should ignore this value.
|
||
|
As with the other kinds of declarations returned by
|
||
|
<code>cp_namespace_decls</code>, the <code>TREE_CHAIN</code> will point to the next
|
||
|
declaration in this list.
|
||
|
</p>
|
||
|
<p>For more information on the kinds of declarations that can occur on this
|
||
|
list, See <a href="Declarations.html#Declarations">Declarations</a>. Some declarations will not appear on this
|
||
|
list. In particular, no <code>FIELD_DECL</code>, <code>LABEL_DECL</code>, or
|
||
|
<code>PARM_DECL</code> nodes will appear here.
|
||
|
</p>
|
||
|
<p>This function cannot be used with namespaces that have
|
||
|
<code>DECL_NAMESPACE_ALIAS</code> set.
|
||
|
</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
|
||
|
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
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> [<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>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|