This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
namespaces -- time to do something?
- To: egcs at cygnus dot com
- Subject: namespaces -- time to do something?
- From: "Marc W. Mengel" <mengel at fnal dot gov>
- Date: Tue, 09 Dec 1997 10:17:08 -0600
- Organization: Fermilab Unix System Support Group
- Reply-to: "Marc W. Mengel" <mengel at fnal dot gov>
Well, now that egcs-1.0 is out, it seems to me it's time to do something about
namespaces for egcs-1.1. Towards that end, I have a simple idea that I think
will work which I'd like to toss out for folks to knock around.
Premise:
--------
Unless I am missing something, it looks like egcs *declares* namespaces
okay, creates symbols in namespaces properly, and does fully-qualified names
correctly, it just doesn't do "using" correctly.
Proposal:
---------
If so, I propose we fix this by adding the following tokens to the grammar:
%token NAMESPACE_ID_ALIAS
%token NAMESPACE_TYPE_ALIAS
%token NAMESPACE_NAMESPACE_ALIAS
similar to TYPENAME, which carry around a tree-node for
"namespace::name" instead of a type. We then expand the symbol
to the fully qualified name when needed, like:
qualified_id : NAMESPACE_ID_ALIAS
{ $$ = EXPAND_NAMESPACE_ALIAS($1); }
qualified_type : NAMESPACE_TYPE_ALIAS
{ $$ = EXPAND_NAMESPACE_ALIAS($1); }
identifier : NAMESPACE_NAMESPACE_ALIAS
{ $$ = EXPAND_NAMESPACE_ALIAS($1); }
Then "using" statements simply define the appropriate NAMESPACE_xxx_ALIAS
symbols in the current scope, similiar to how typedefs define a TYPENAME.
(By the way, how *do* typedefs define a TYPENAME? I've tried to follow
through the code by hand to figure this out and keep getting lost...)
The only slightly painful part is when we see a "using xxx;" statement to
import a whole namespace, we have to make aliases for the whole list of
symbols in the namespace...
This has one possibly confusing side-effect; if we have:
namespace fred {
int a;
};
namespace jane {
int b;
using fred::a;
};
namespace paul {
int c;
using jane::a;
}
this could well succeed in making the "a" seen in namespace paul be actually
fred::a, or fail, depending on how we define EXPAND_NAMESPACE_ALIAS()...
It's not clear to me which way this is supposed to work.
Marc