8.4.1 Namespaces
A namespace is represented by a NAMESPACE_DECL node.
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.
The following macros and functions can be used on a NAMESPACE_DECL:
DECL_NAME- This macro is used to obtain the
IDENTIFIER_NODEcorresponding to the unqualified name of the name of the namespace (see Identifiers). The name of the global namespace is `::', even though in C++ the global namespace is unnamed. However, you should use comparison withglobal_namespace, rather thanDECL_NAMEto determine whether or not a namespace is the global one. An unnamed namespace will have aDECL_NAMEequal toanonymous_namespace_name. Within a single translation unit, all unnamed namespaces will have the same name. DECL_CONTEXT- This macro returns the enclosing namespace. The
DECL_CONTEXTfor theglobal_namespaceisNULL_TREE. DECL_NAMESPACE_ALIAS- If this declaration is for a namespace alias, then
DECL_NAMESPACE_ALIASis the namespace for which this one is an alias.Do not attempt to use
cp_namespace_declsfor a namespace which is an alias. Instead, followDECL_NAMESPACE_ALIASlinks until you reach an ordinary, non-alias, namespace, and callcp_namespace_declsthere. DECL_NAMESPACE_STD_P- This predicate holds if the namespace is the special
::stdnamespace. cp_namespace_decls- 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
NULL_TREE. The declarations are connected through theirTREE_CHAINfields.Although most entries on this list will be declarations,
TREE_LISTnodes may also appear. In this case, theTREE_VALUEwill be anOVERLOAD. The value of theTREE_PURPOSEis unspecified; back ends should ignore this value. As with the other kinds of declarations returned bycp_namespace_decls, theTREE_CHAINwill point to the next declaration in this list.For more information on the kinds of declarations that can occur on this list, See Declarations. Some declarations will not appear on this list. In particular, no
FIELD_DECL,LABEL_DECL, orPARM_DECLnodes will appear here.This function cannot be used with namespaces that have
DECL_NAMESPACE_ALIASset.