Commit cb0dbb9a by Jason Merrill

cp-tree.h (CP_DECL_CONTEXT): New macro.

	* cp-tree.h (CP_DECL_CONTEXT): New macro.
	* decl2.c (is_namespace_ancestor, lookup_using_namespace): Use it.
	* method.c (build_overload_nested_name): Likewise.
	* sig.c (build_signature_pointer_or_reference_type): Don't set
	DECL_CONTEXT.
	Set DECL_CONTEXT for globals to NULL_TREE instead of global_namespace.
	* cp-tree.h (FROB_CONTEXT): New macro.
	(DECL_MAIN_P): ::main should have a DECL_CONTEXT of NULL_TREE.
	* decl.c (namespace_binding): Replace NULL_TREE with
	global_namespace.
	(set_namespace_binding, pop_namespace, lookup_name_real): Likewise.
	* decl2.c (is_namespace_ancestor, lookup_using_namespace):
	Likewise.
	* decl.c (pushtag): Use FROB_CONTEXT.
	(pushdecl, make_typename_type, define_function, grokdeclarator):
	Likewise.
	* decl2.c (set_decl_namespace, do_namespace_alias): Likewise.
	* pt.c (push_template_decl_real, lookup_template_class, tsubst):
	Likewise.
	* decl2.c (decl_namespace): Return global_namespace if no context.
	* method.c (build_overload_nested_name): Expect null as context.
	* pt.c (mangle_class_name_for_template): Do nothing for null
	contexts.
	(lookup_template_class): Allow for null id_context.

From-SVN: r20710
parent acd92049
1998-06-25 Jason Merrill <jason@yorick.cygnus.com>
* cp-tree.h (CP_DECL_CONTEXT): New macro.
* decl2.c (is_namespace_ancestor, lookup_using_namespace): Use it.
* method.c (build_overload_nested_name): Likewise.
* sig.c (build_signature_pointer_or_reference_type): Don't set
DECL_CONTEXT.
1998-06-24 Martin v. Lwis <loewis@informatik.hu-berlin.de>
Set DECL_CONTEXT for globals to NULL_TREE instead of global_namespace.
* cp-tree.h (FROB_CONTEXT): New macro.
(DECL_MAIN_P): ::main should have a DECL_CONTEXT of NULL_TREE.
* decl.c (namespace_binding): Replace NULL_TREE with
global_namespace.
(set_namespace_binding, pop_namespace, lookup_name_real): Likewise.
* decl2.c (is_namespace_ancestor, lookup_using_namespace):
Likewise.
* decl.c (pushtag): Use FROB_CONTEXT.
(pushdecl, make_typename_type, define_function, grokdeclarator):
Likewise.
* decl2.c (set_decl_namespace, do_namespace_alias): Likewise.
* pt.c (push_template_decl_real, lookup_template_class, tsubst):
Likewise.
* decl2.c (decl_namespace): Return global_namespace if no context.
* method.c (build_overload_nested_name): Expect null as context.
* pt.c (mangle_class_name_for_template): Do nothing for null
contexts.
(lookup_template_class): Allow for null id_context.
1998-06-25 Richard Henderson <rth@cygnus.com>
* method.c (emit_thunk): Set current_function_is_thunk for the
......
......@@ -214,7 +214,7 @@ parse.o : $(PARSE_C) $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h lex.h \
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \
`echo $(PARSE_C) | sed 's,^\./,,'`
CONFLICTS = expect 21 shift/reduce conflicts and 39 reduce/reduce conflicts.
CONFLICTS = expect 21 shift/reduce conflicts and 42 reduce/reduce conflicts.
$(PARSE_H) : $(PARSE_C)
$(PARSE_C) : $(srcdir)/parse.y
@echo $(CONFLICTS)
......
......@@ -1184,7 +1184,12 @@ struct lang_decl
#define DECL_CLASS_CONTEXT(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.context)
#define DECL_REAL_CONTEXT(NODE) \
((TREE_CODE (NODE) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (NODE)) \
? DECL_CLASS_CONTEXT (NODE) : DECL_CONTEXT (NODE))
? DECL_CLASS_CONTEXT (NODE) : CP_DECL_CONTEXT (NODE))
/* NULL_TREE in DECL_CONTEXT represents the global namespace. */
#define CP_DECL_CONTEXT(NODE) \
(DECL_CONTEXT (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
#define FROB_CONTEXT(NODE) ((NODE) == global_namespace ? NULL_TREE : (NODE))
/* 1 iff NODE has namespace scope, including the global namespace. */
#define DECL_NAMESPACE_SCOPE_P(NODE) \
......@@ -2027,8 +2032,7 @@ extern int current_function_parms_stored;
`main'. */
#define DECL_MAIN_P(NODE) \
(TREE_CODE (NODE) == FUNCTION_DECL \
&& (DECL_CONTEXT (NODE) == global_namespace \
|| DECL_CONTEXT (NODE) == NULL_TREE) \
&& DECL_CONTEXT (NODE) == NULL_TREE \
&& DECL_NAME (NODE) != NULL_TREE \
&& MAIN_NAME_P (DECL_NAME (NODE)))
......
......@@ -1719,6 +1719,8 @@ namespace_binding (name, scope)
tree b = IDENTIFIER_NAMESPACE_BINDINGS (name);
if (b == NULL_TREE)
return NULL_TREE;
if (scope == NULL_TREE)
scope = global_namespace;
if (TREE_CODE (b) != CPLUS_BINDING)
return (scope == global_namespace) ? b : NULL_TREE;
name = find_binding (name,scope);
......@@ -1737,6 +1739,10 @@ set_namespace_binding (name, scope, val)
tree val;
{
tree b;
if (scope == NULL_TREE)
scope = global_namespace;
if (scope == global_namespace)
{
b = IDENTIFIER_NAMESPACE_BINDINGS (name);
......@@ -1837,7 +1843,7 @@ pop_namespace ()
in_std--;
return;
}
current_namespace = DECL_CONTEXT (current_namespace);
current_namespace = CP_DECL_CONTEXT (current_namespace);
/* The binding level is not popped, as it might be re-opened later. */
suspend_binding_level ();
}
......@@ -2263,7 +2269,7 @@ pushtag (name, type, globalize)
d = TYPE_MAIN_DECL (d);
TYPE_NAME (type) = d;
DECL_CONTEXT (d) = context;
DECL_CONTEXT (d) = FROB_CONTEXT (context);
if (processing_template_parmlist)
/* You can't declare a new template type in a template
......@@ -3241,7 +3247,7 @@ pushdecl (x)
&& ! DECL_CONTEXT (x))
DECL_CONTEXT (x) = current_function_decl;
if (!DECL_CONTEXT (x))
DECL_CONTEXT (x) = current_namespace;
DECL_CONTEXT (x) = FROB_CONTEXT (current_namespace);
/* Type are looked up using the DECL_NAME, as that is what the rest of the
compiler wants to use. */
......@@ -4687,10 +4693,10 @@ make_typename_type (context, name)
if (processing_template_decl)
pop_obstacks ();
TYPE_CONTEXT (t) = context;
TYPE_CONTEXT (t) = FROB_CONTEXT (context);
TYPE_NAME (TREE_TYPE (d)) = d;
TYPE_STUB_DECL (TREE_TYPE (d)) = d;
DECL_CONTEXT (d) = context;
DECL_CONTEXT (d) = FROB_CONTEXT (context);
CLASSTYPE_GOT_SEMICOLON (t) = 1;
return t;
......@@ -4920,6 +4926,8 @@ lookup_name_real (name, prefer_type, nonclass, namespaces_only)
if (scope == global_namespace)
break;
scope = DECL_CONTEXT (scope);
if (scope == NULL_TREE)
scope = global_namespace;
}
}
......@@ -5980,7 +5988,7 @@ define_function (name, type, function_code, pfn, library_name)
DECL_ARTIFICIAL (decl) = 1;
my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392);
DECL_CONTEXT (decl) = current_namespace;
DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
/* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
we cannot change DECL_ASSEMBLER_NAME until we have installed this
......@@ -9707,7 +9715,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
if (current_class_type)
DECL_CONTEXT (decl) = current_class_type;
else
DECL_CONTEXT (decl) = current_namespace;
DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
DECL_ASSEMBLER_NAME (decl)
......
......@@ -3806,7 +3806,7 @@ is_namespace_ancestor (root, child)
return 1;
if (child == global_namespace)
return 0;
return is_namespace_ancestor (root, DECL_CONTEXT (child));
return is_namespace_ancestor (root, CP_DECL_CONTEXT (child));
}
......@@ -3950,7 +3950,7 @@ lookup_using_namespace (name, val, current, scope)
}
if (current == scope)
break;
current = DECL_CONTEXT (current);
current = CP_DECL_CONTEXT (current);
}
return val != error_mark_node;
}
......@@ -4013,7 +4013,7 @@ set_decl_namespace (decl, scope)
if (!is_namespace_ancestor (current_namespace, scope))
cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
decl, scope);
DECL_CONTEXT (decl) = scope;
DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
if (scope != current_namespace)
{
/* See whether this has been declared in the namespace. */
......@@ -4056,9 +4056,7 @@ decl_namespace (decl)
my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 390);
}
/* We should always find the namespace. */
my_friendly_abort (390);
return NULL_TREE;
return global_namespace;
}
/* Return the namespace where the current declaration is declared. */
......@@ -4388,7 +4386,7 @@ do_namespace_alias (alias, namespace)
/* Build the alias. */
alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
DECL_NAMESPACE_ALIAS (alias) = namespace;
DECL_CONTEXT (alias) = current_namespace;
DECL_CONTEXT (alias) = FROB_CONTEXT (current_namespace);
BINDING_VALUE (binding) = alias;
}
}
......
......@@ -416,34 +416,31 @@ build_overload_nested_name (decl)
tree decl;
{
tree context;
if (ktypelist && issue_ktype (decl))
return;
if (decl == global_namespace)
return;
if (DECL_CONTEXT (decl))
{
tree context = DECL_CONTEXT (decl);
context = CP_DECL_CONTEXT (decl);
/* try to issue a K type, and if we can't continue the normal path */
if (!(ktypelist && issue_ktype (context)))
{
/* For a template type parameter, we want to output an 'Xn'
rather than 'T' or some such. */
if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
|| TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
build_mangled_name (context, 0, 0);
else
{
if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
context = TYPE_NAME (context);
build_overload_nested_name (context);
}
}
/* try to issue a K type, and if we can't continue the normal path */
if (!(ktypelist && issue_ktype (context)))
{
/* For a template type parameter, we want to output an 'Xn'
rather than 'T' or some such. */
if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
|| TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
build_mangled_name (context, 0, 0);
else
{
if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
context = TYPE_NAME (context);
build_overload_nested_name (context);
}
else
my_friendly_abort (392);
}
if (TREE_CODE (decl) == FUNCTION_DECL)
{
......
......@@ -280,13 +280,14 @@ empty_parms ()
%{
/* List of types and structure classes of the current declaration. */
static tree current_declspecs = NULL_TREE;
static tree current_declspecs;
/* List of prefix attributes in effect.
Prefix attributes are parsed by the reserved_declspecs and declmods
rules. They create a list that contains *both* declspecs and attrs. */
/* ??? It is not clear yet that all cases where an attribute can now appear in
a declspec list have been updated. */
static tree prefix_attributes = NULL_TREE;
static tree prefix_attributes;
/* When defining an aggregate, this is the most recent one being defined. */
static tree current_aggr;
......
......@@ -1662,7 +1662,7 @@ push_template_decl_real (decl, is_friend)
ctx = NULL_TREE;
if (!DECL_CONTEXT (decl))
DECL_CONTEXT (decl) = current_namespace;
DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
/* For determining whether this is a primary template or not, we're really
interested in the lexical context, not the true context. */
......@@ -2748,10 +2748,10 @@ mangle_class_name_for_template (name, parms, arglist, ctx)
{
/* Already substituted with real template. Just output
the template name here */
my_friendly_assert (TREE_CODE (DECL_CONTEXT (arg))
== NAMESPACE_DECL, 980422);
if (DECL_CONTEXT (arg) != global_namespace)
tree context = DECL_CONTEXT (arg);
if (context)
{
my_friendly_assert (TREE_CODE (context) == NAMESPACE_DECL, 980422);
cat(decl_as_string (DECL_CONTEXT (arg), 0));
cat("::");
}
......@@ -2980,7 +2980,8 @@ lookup_template_class (d1, arglist, in_decl, context)
id_context = context;
else
id_context = DECL_CONTEXT (template);
my_friendly_assert (id_context != NULL_TREE, 980410);
if (id_context == NULL_TREE)
id_context = global_namespace;
if (TREE_CODE (template) != TEMPLATE_DECL)
{
......@@ -3097,8 +3098,8 @@ lookup_template_class (d1, arglist, in_decl, context)
build_overload_name into creating a new name. */
tree type_decl = TYPE_STUB_DECL (t);
TYPE_CONTEXT (t) = context;
DECL_CONTEXT (type_decl) = context;
TYPE_CONTEXT (t) = FROB_CONTEXT (context);
DECL_CONTEXT (type_decl) = FROB_CONTEXT (context);
DECL_ASSEMBLER_NAME (type_decl) = DECL_NAME (type_decl);
DECL_ASSEMBLER_NAME (type_decl) =
get_identifier (build_overload_name (t, 1, 1));
......@@ -5025,7 +5026,7 @@ tsubst (t, args, in_decl)
{
fntype = make_node (TREE_CODE (t));
TREE_TYPE (fntype) = type;
TYPE_CONTEXT (fntype) = context;
TYPE_CONTEXT (fntype) = FROB_CONTEXT (context);
TYPE_VALUES (fntype) = values;
TYPE_SIZE (fntype) = TYPE_SIZE (t);
TYPE_ALIGN (fntype) = TYPE_ALIGN (t);
......
......@@ -96,8 +96,6 @@ build_signature_pointer_or_reference_decl (type, name)
decl = build_decl (TYPE_DECL, name, type);
TYPE_NAME (type) = decl;
TREE_CHAIN (type) = decl;
/* But we mangle it, so it needs a scope. */
DECL_CONTEXT (decl) = global_namespace;
}
/* Construct, lay out and return the type of pointers or references
......
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