decl2.c (add_using_namespace): Iterate over namespaces used indirectly.

* decl2.c (add_using_namespace): Iterate over namespaces used
	indirectly.
	* decl.c (lookup_name_real): Accept namespace aliases as locals.
	(cat_namespace_levels): Ignore aliases.
	(duplicate_decls): Ignore duplicate aliases.
	* decl2.c (do_namespace_alias): Process block level namespace
	aliases. Store alias with pushdecl. Remove odr errors.
	* parse.y (namespace_alias): New non-terminal.
	(extdef): Use it.

From-SVN: r21201
This commit is contained in:
Martin v. Löwis 1998-07-15 13:27:24 -04:00 committed by Jason Merrill
parent 2d39086779
commit 85c6cbaf2d
5 changed files with 4523 additions and 4529 deletions

View File

@ -1,3 +1,16 @@
1998-07-15 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* decl2.c (add_using_namespace): Iterate over namespaces used
indirectly.
* decl.c (lookup_name_real): Accept namespace aliases as locals.
(cat_namespace_levels): Ignore aliases.
(duplicate_decls): Ignore duplicate aliases.
* decl2.c (do_namespace_alias): Process block level namespace
aliases. Store alias with pushdecl. Remove odr errors.
* parse.y (namespace_alias): New non-terminal.
(extdef): Use it.
1998-07-15 Jason Merrill <jason@yorick.cygnus.com>
* decl2.c (arg_assoc_type): Handle METHOD_TYPE like FUNCTION_TYPE.

View File

@ -1865,7 +1865,8 @@ cat_namespace_levels()
/* The nested namespaces appear in the names list of their ancestors. */
for (current = last; current; current = TREE_CHAIN (current))
{
if (TREE_CODE (current) != NAMESPACE_DECL)
if (TREE_CODE (current) != NAMESPACE_DECL
|| DECL_NAMESPACE_ALIAS (current))
continue;
if (!DECL_LANG_SPECIFIC (current))
{
@ -2740,6 +2741,11 @@ duplicate_decls (newdecl, olddecl)
/* One of the declarations is a template instantiation, and the
other is not a template at all. That's OK. */
return 0;
else if (TREE_CODE (newdecl) == NAMESPACE_DECL
&& DECL_NAMESPACE_ALIAS (newdecl)
&& DECL_NAMESPACE_ALIAS (newdecl) == DECL_NAMESPACE_ALIAS (olddecl))
/* Redeclaration of namespace alias, ignore it. */
return 1;
else
{
char *errmsg = redeclaration_error_message (newdecl, olddecl);
@ -4913,12 +4919,26 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only)
locval = classval = NULL_TREE;
if (!namespaces_only && !current_binding_level->namespace_p
&& IDENTIFIER_LOCAL_VALUE (name)
/* Kludge to avoid infinite recursion with identifier_type_value. */
&& (prefer_type <= 0
|| TREE_CODE (IDENTIFIER_LOCAL_VALUE (name)) == TYPE_DECL))
locval = IDENTIFIER_LOCAL_VALUE (name);
if (!current_binding_level->namespace_p
&& IDENTIFIER_LOCAL_VALUE (name))
switch (TREE_CODE (IDENTIFIER_LOCAL_VALUE (name)))
{
case NAMESPACE_DECL:
/* A namespace is rejected only if we strictly require types. */
if (prefer_type <= 1)
locval = IDENTIFIER_LOCAL_VALUE (name);
break;
case TYPE_DECL:
/* A type is rejected only if we strictly require namespaces. */
if (!namespaces_only)
locval = IDENTIFIER_LOCAL_VALUE (name);
break;
default:
/* We require neither types or namespaces. */
if (!namespaces_only && prefer_type <= 0)
locval = IDENTIFIER_LOCAL_VALUE (name);
break;
}
/* In C++ class fields are between local and global scope,
just before the global scope. */

View File

@ -3877,9 +3877,14 @@ add_using_namespace (user, used, indirect)
/* Add user to the used's users list. */
DECL_NAMESPACE_USERS (used)
= perm_tree_cons (user, 0, DECL_NAMESPACE_USERS (used));
for (iter = DECL_NAMESPACE_USERS (user); iter; iter = TREE_CHAIN (iter))
/* Recursively add all namespaces used. */
for (iter = DECL_NAMESPACE_USING (used); iter; iter = TREE_CHAIN (iter))
/* indirect usage */
add_using_namespace (user, TREE_PURPOSE (iter), 1);
/* Tell everyone using us about the new used namespaces. */
for (iter = DECL_NAMESPACE_USERS (user); iter; iter = TREE_CHAIN (iter))
add_using_namespace (TREE_PURPOSE (iter), used, 1);
}
@ -4370,25 +4375,10 @@ do_namespace_alias (alias, namespace)
namespace = ORIGINAL_NAMESPACE (namespace);
binding = binding_for_name (alias, current_namespace);
old = BINDING_VALUE (binding);
if (old)
{
if (TREE_CODE (old) == NAMESPACE_DECL
&& DECL_NAMESPACE_ALIAS (old) == namespace)
/* Ok: redeclaration. */
return;
cp_error ("invalid namespace alias `%D'", alias);
cp_error_at ("`%D' previously declared here", old);
}
else
{
/* Build the alias. */
alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
DECL_NAMESPACE_ALIAS (alias) = namespace;
DECL_CONTEXT (alias) = FROB_CONTEXT (current_namespace);
BINDING_VALUE (binding) = alias;
}
/* Build the alias. */
alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
DECL_NAMESPACE_ALIAS (alias) = namespace;
pushdecl (alias);
}
/* Check a non-member using-declaration. Return the name and scope

File diff suppressed because it is too large Load Diff

View File

@ -403,7 +403,16 @@ extdef:
{ push_namespace (NULL_TREE); }
extdefs_opt '}'
{ pop_namespace (); }
| NAMESPACE identifier '='
| namespace_alias
| using_decl ';'
{ do_toplevel_using_decl ($1); }
| using_directive
| extension extdef
{ pedantic = $<itype>1; }
;
namespace_alias:
NAMESPACE identifier '='
{ begin_only_namespace_names (); }
any_id ';'
{
@ -412,11 +421,6 @@ extdef:
$5 = lastiddecl;
do_namespace_alias ($2, $5);
}
| using_decl ';'
{ do_toplevel_using_decl ($1); }
| using_directive
| extension extdef
{ pedantic = $<itype>1; }
;
using_decl:
@ -3288,6 +3292,7 @@ simple_stmt:
| using_directive
| namespace_using_decl
{ do_local_using_decl ($1); }
| namespace_alias
;
function_try_block: