Commit b9082e8a by Jason Merrill

class.c (currently_open_class): New fn.

	* class.c (currently_open_class): New fn.
	* decl.c (lookup_name_real): Use it.
	* search.c (lookup_field): Likewise.

From-SVN: r19650
parent 6e940d05
Mon Apr 27 07:17:38 1998 Martin von Loewis <loewis@informatik.hu-berlin.de> Sat May 9 14:44:37 1998 Jason Merrill <jason@yorick.cygnus.com>
* class.c (currently_open_class): New fn.
* decl.c (lookup_name_real): Use it.
* search.c (lookup_field): Likewise.
Fri May 8 23:32:42 1998 Martin von Loewis <loewis@informatik.hu-berlin.de>
* cp-tree.def (OVERLOAD): New node. * cp-tree.def (OVERLOAD): New node.
* cp-tree.h (BINDING_TYPE, SET_IDENTIFIER_GLOBAL_VALUE, * cp-tree.h (BINDING_TYPE, SET_IDENTIFIER_GLOBAL_VALUE,
......
...@@ -4822,6 +4822,21 @@ popclass (modify) ...@@ -4822,6 +4822,21 @@ popclass (modify)
; ;
} }
/* Returns 1 if current_class_type is either T or a nested type of T. */
int
currently_open_class (t)
tree t;
{
int i;
if (t == current_class_type)
return 1;
for (i = 0; i < current_class_depth; ++i)
if (current_class_stack [-i*2 - 1] == t)
return 1;
return 0;
}
/* When entering a class scope, all enclosing class scopes' names with /* When entering a class scope, all enclosing class scopes' names with
static meaning (static variables, static functions, types and enumerators) static meaning (static variables, static functions, types and enumerators)
have to be visible. This recursive function calls pushclass for all have to be visible. This recursive function calls pushclass for all
......
...@@ -4826,20 +4826,21 @@ lookup_name_real (name, prefer_type, nonclass) ...@@ -4826,20 +4826,21 @@ lookup_name_real (name, prefer_type, nonclass)
TYPE_DECLs. */ TYPE_DECLs. */
classval = lookup_field (current_class_type, name, 0, 1); classval = lookup_field (current_class_type, name, 0, 1);
/* yylex() calls this with -2, since we should never start digging for
the nested name at the point where we haven't even, for example,
created the COMPONENT_REF or anything like that. */
if (classval == NULL_TREE)
classval = lookup_nested_field (name, ! yylex);
/* Add implicit 'typename' to types from template bases. lookup_field /* Add implicit 'typename' to types from template bases. lookup_field
will do this for us. */ will do this for us. If classval is actually from an enclosing
scope, lookup_nested_field will get it for us. */
if (processing_template_decl if (processing_template_decl
&& classval && TREE_CODE (classval) == TYPE_DECL && classval && TREE_CODE (classval) == TYPE_DECL
&& DECL_CONTEXT (classval) != current_class_type && ! currently_open_class (DECL_CONTEXT (classval))
&& uses_template_parms (current_class_type) && uses_template_parms (current_class_type)
&& ! DECL_ARTIFICIAL (classval)) && ! DECL_ARTIFICIAL (classval))
classval = lookup_field (current_class_type, name, 0, 1); classval = lookup_field (current_class_type, name, 0, 1);
/* yylex() calls this with -2, since we should never start digging for
the nested name at the point where we haven't even, for example,
created the COMPONENT_REF or anything like that. */
if (classval == NULL_TREE)
classval = lookup_nested_field (name, ! yylex);
} }
if (locval && classval) if (locval && classval)
......
...@@ -1549,7 +1549,7 @@ lookup_field (xbasetype, name, protect, want_type) ...@@ -1549,7 +1549,7 @@ lookup_field (xbasetype, name, protect, want_type)
if (rval && TREE_CODE (rval) == TYPE_DECL if (rval && TREE_CODE (rval) == TYPE_DECL
&& ! DECL_ARTIFICIAL (rval) && ! DECL_ARTIFICIAL (rval)
&& processing_template_decl && processing_template_decl
&& BINFO_TYPE (rval_binfo) != current_class_type && ! currently_open_class (BINFO_TYPE (rval_binfo))
&& uses_template_parms (type)) && uses_template_parms (type))
{ {
binfo = rval_binfo; binfo = rval_binfo;
...@@ -1577,14 +1577,14 @@ lookup_nested_field (name, complain) ...@@ -1577,14 +1577,14 @@ lookup_nested_field (name, complain)
register tree t; register tree t;
tree id = NULL_TREE; tree id = NULL_TREE;
if (TREE_CHAIN (current_class_type)) if (TYPE_MAIN_DECL (current_class_type))
{ {
/* Climb our way up the nested ladder, seeing if we're trying to /* Climb our way up the nested ladder, seeing if we're trying to
modify a field in an enclosing class. If so, we should only modify a field in an enclosing class. If so, we should only
be able to modify if it's static. */ be able to modify if it's static. */
for (t = TREE_CHAIN (current_class_type); for (t = TYPE_MAIN_DECL (current_class_type);
t && DECL_CONTEXT (t); t && DECL_CONTEXT (t);
t = TREE_CHAIN (DECL_CONTEXT (t))) t = TYPE_MAIN_DECL (DECL_CONTEXT (t)))
{ {
if (TREE_CODE (DECL_CONTEXT (t)) != RECORD_TYPE) if (TREE_CODE (DECL_CONTEXT (t)) != RECORD_TYPE)
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment