This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Namespaces update


Since I got several requests, I'll post a status report on the
namespaces code. This patch should be quite complete now. It causes
no regressions and passes the remaining test cases.

Still missing:
- using-directives and using-declarations in functions. This
  requires changes to the parser.
- support for debugging is quite limited. Since the mangling
  is compatible with class scoping, one can use qualified names
  inside gdb in many cases.
- extern "C" symbols are not properly checked when they appear
  in different namespaces.
- namespace aliases are accepted in places where they shouldn't.

There are also some limitations in the 'got_scope' and
'looking_for_typename' mechanisms. I don't have solutions for
that.

This patch requires the DECL_CONTEXT patch I sent earlier. Jason
suggested that the NAMESPACE_DECL node should be moved to the back-end
instead, as it would allow to generate better debugging information.
I can supply the patch moving NAMESPACE_DECL if desired :-)

Since the patch is rather large now, I've mime-attached download
instructions for your mail reader. The URL is 
ftp://site.informatik.hu-berlin.de/pub/loewis/namespaces.gz

Please report any problems you find with that code.

Regards,
Martin

Sun Apr  5 11:56:50 1998  Martin von Loewis  <loewis@informatik.hu-berlin.de>

	* cp-tree.def (OVERLOAD): New node.  

	* cp-tree.h (BINDING_TYPE, SET_IDENTIFIER_GLOBAL_VALUE,
	SET_IDENTIFIER_NAMESPACE_VALUE): Define.
	(NAMESPACE_BINDING): Remove.
	(IDENTIFIER_GLOBAL_VALUE, IDENTIFIER_NAMESPACE_VALUE): Use
	namespace_binding.
	(OVL_FUNCTION, OVL_CHAIN, OVL_CURRENT, OVL_NEXT, OVL_USED):
	Define.
	(tree_overload): New struct.
	(IDENTIFIER_TYPE_VALUE): Use identifier_type_value.
	(REAL_IDENTIFIER_TYPE_VALUE): Define.
	(IDENTIFIER_HAS_TYPE_VALUE): Use IDENTIFIER_TYPE_VALUE.
	(lang_decl_flags): Remove in_namespace.
	(lang_decl): Remove chain.
	(DECL_CHAIN, DECL_NAMESPACE): Remove.
	(identifier_type_value, pushdecl_namespace_level, push_using_decl,
	namespace_binding, set_namespace_binding,
	lookup_function_nonclass, cat_namespace_levels,
	set_decl_namespace, lookup_arg_dependent, binding_init, ovl_cons,
	scratch_ovl_cons, ovl_member, build_overload): Declare.
	(decl_list_length, get_namespace_id, current_namespace_id,
	overloaded_globals_p): Remove.
	(lookup_using_namespace, qualified_lookup_using_namespace): Change
	return type.
	(push_scratch_obstack): New macro.
	
	* call.c (add_function_candidate): Special-case type of OVERLOAD node.
	(build_user_conversions_1): Iterate using OVL_NEXT for ctors,
	convs, fns.
	(build_new_function_call): Iterate using OVL_CHAIN.  
	Print DECL_NAME in when reporting ambiguities.
	(build_object_call): Iterate using OVL_NEXT for fns, convs.
	(build_new_op): Call lookup_function_nonclass.  
	Iterate using OVL_NEXT.
	(build_op_delete_call): Change detection of members.
	Do not wrap TREE_LIST around fields and single global functions.
	(build_over_call): Don't push a class level if the context is a
	namespace.
	(build_new_method_call): Iterate using OVL_NEXT.
	
	* class.c (add_method): Chain overloaded members using
	build_overload.  Remove copying of method.
	(grow_method): When iterating through the obstack, expect OVERLOAD
	nodes.  Chain overload members.
	(finish_struct_methods): Chain overload members.  Unpack OVERLOAD
	nodes in call to get_baselinks.
	(duplicate_tag_error): Expect OVERLOAD nodes when unchaining.
	(finish_struct_1): Iterate over ctor using OVL_NEXT.  Handle
	fdecls that are OVERLOAD nodes.
	(validate_lhs): New function.
	(instantiate_type): Do not copy OVERLOAD nodes.  Remove dead
	code. Use DECL_NAME in error messages. Split code between global
	and member function processing.

	* decl.c (global_type_node): New static variable.
	(struct binding_level): New field usings.
	(resume_binding_level): Assert that we are not in a class.
	(toplevel_bindings_p): Just check for namespace_p or
	pseudo_global.
	(resume_level): Remove.
	(find_binding): New function.
	(binding_for_name): Call it.
	(namespace_binding, set_namespace_binding): New functions.
	(push_namespace): Associate binding level with new namespace,
	resume_binding_level for existing namespace.  Remove old code.
	(store_bindings): Use REAL_IDENTIFIER_TYPE_VALUE.
	(maybe_push_to_top_level): Break when reaching a namespace level.
	(pop_namespace): Call suspend_binding_level.  Remove old code.
	(cat_namespace_levels): New function.
	(set_identifier_type_value_with_scope): For namespace bindings,
	set BINDING_TYPE, and use global_type_node.
	Use REAL_IDENTIFIER_TYPE_VALUE otherwise.
	(identifier_type_value): New function.
	(pushtag): If no context, use current_namespace.
	(duplicate_decls): Don't process DECL_CHAIN.
	(pushdecl): Set DECL_CONTEXT to current_namespace, if it is not
	already set. Never reset it to NULL_TREE.  Lookup global variables
	in their namespace.  Push overloaded templates if they are on
	namespace level.
	(pushdecl_namespace_level): New function.
	(pushdecl_top_level): Implement using pushdecl_namespace_level.
	(pushdecl_using_decl): New function.
	(overloaded_globals_p): Remove.
	(push_overloaded_decl): Create OVERLOAD nodes, and iterate through
	them. Use namespace_binding and set_namespace_value.
	(redeclaration_error_message): Complain if the declarations come
	from different namespaces.
	(lookup_tag): On namespace level, look in the BINDING_TYPE.
	(lookup_namespace_name): Pass tree_bindings from stack.  Remove
	old code.
	(select_decl): New function.
	(lookup_name_real): Call it for qualified and unqualified lookup.
	Pass tree_bindings from the stack.
	If prefer_type is 1, also accept namespaces.
	(lookup_function_nonclass): New function.
	(init_decl_processing): Set the binding level of the global
	namespace to global_binding_level.
	Initialize global_type_node.
	(init_decl_processing): Build a proper type list for
	__builtin_apply.
	(define_function): Set the DECL_CONTEXT to the global_namespace.
	(start_decl): A namespace is not considered as a context here.  If
	the DECL_CONTEXT is a namespace, push the decl.
	(cp_finish_decl): Check for namespaces used as initializers.
	(grokfndecl): Add namespace parameter.  Remove processing of
	DECL_CHAIN.
	(grokvardecl): Add namespace parameter.
	(grokdeclarator): Process SCOPEs that are namespaces.  For
	mangling, temporarily set the DECL_CONTEXT on anonymous structs.
	(start_function): Check for contexts that are namespaces.  
	Set context for declarations that have not been pushed.
	(store_parm_decls): Check for ::main only.
	(finish_function): Likewise.
	(start_method): Check for contexts that are namespaces.
	(start_method): Remove DECL_CHAIN processing.

	* decl2.c (grok_x_components): Ignore namespaces as type contexts.
	(check_classfn): Expect OVERLOAD nodes.
	(grokfield): Remove DECL_CHAIN processing.
	(finish_file): Call cat_namespace_levels.
	(merge_functions): New function.
	(ambiguous_decl): Rewrite.
	(lookup_using_namespace): Produce tree_bindings.
	(qualified_lookup_using_namespace): Likewise.
	(set_decl_namespace, decl_namespace): New functions.
	(arg_lookup): New struct.
	(add_function, arg_assoc_namespace, arg_assoc_class,
	arg_assoc_type, arg_assoc_args, arg_assoc, lookup_arg_dependent):
	New functions.
	(get_namespace_id, current_namespace_id): Remove.
	(do_toplevel_using_decl): Rewrite.
	(do_using_directive): Sorry if not on namespace level.  Complain
	about unknown namespaces.

	* error.c (dump_aggr_type): Check for namespace contexts.

	* friend.c (is_friend): A namespace is not a context, here.

	* init.c (expand_member_init): Remove DECL_CHAIN processing.
	(build_offset_ref): Process OVERLOAD nodes.

	* lex.c (identifier_type): Loop using OVL_CHAIN.
	(do_identifier): Expect OVERLOAD nodes instead of TREE_LISTs.
	(do_scoped_id): Expect OVERLOAD nodes.
	Change calling convention for qualified_lookup_using_namespace.
	(build_lang_decl): Don't set in_namespace anymore.

	* method.c (typevec_size): New global.
	(build_overload_nested_name): Return if global_namespace.
	Otherwise, always expect a declaration context.
	(build_qualified_name): Likewise.
	Make sure we don't write beyond typevec_size.
	(build_decl_overload_real): Likewise.
	Allocate one extra slot for the namespace.
	(hack_identifier): Mark code dead.
	Process OVERLOAD and NAMESPACE_DECL nodes.

	* parse.y (program): Pop namespaces until in global namespace.
	(extdef): In a using-declaration, don't discard the identifier if
	there is no declaration.
	(left_curly): Ignore type contexts which are namespaces.
	(typename_sub2): Use IDENTIFIER_TYPE_VALUE to retrieve the type
	used as scope.

	* pt.c (template_class_depth): Expect types to be namespaces.
	(determine_specialization): Simplify by expecting OVERLOAD nodes.
	(push_template_decl): Push into namespace level.
	Reset ctx if it is a namespace.
	Set DECL_CONTEXT to current_namespace if not set already.
	Ignore real contexts that are namespaces.
	(mangle_class_name_for_template): Skip global_namespace.
	Mangle other namepaces as declarations.
	(lookup_template_function): Set type of OVERLOAD nodes to unknown.
	(lookup_template_class): Ignore namespace contexts.
	(for_each_template_parm): Handle OVERLOAD and NAMESPACE_DECL nodes.
	(tsubst_friend_function): Ignore namespace contexts.
	Push into namespace level.
	(tsubst): Handle NAMESPACE_DECL nodes.
	Remove DECL_CHAIN processing.
	(type_unification_real): Recognize OVERLOAD instead of TREE_LIST nodes.

	* ptree.c (print_lang_identifier): Print bindings.
	(lang_print_xnode): Print OVERLOAD nodes.


	* search.c (lookup_fnfields_here): Expect OVERLOAD nodes.
	(lookup_fnfields_1): Likewise.
	(get_virtuals_named_this): Likewise.
	(get_matching_virtual): Likewise.
	(dfs_debug_mark): Likewise.
	(dfs_pushdecls): Likewise.
	(dfs_compress_decls): Likewise.
	(add_conversions): Likewise.
	(lookup_fnfields_here): Likewise.
	Process all nodes, instead of going through TREE_CHAIN.

	* sig.c (build_signature_pointer_or_reference_type): Set context
	to global_namespace.
	(build_signature_table_constructor): Expect OVERLOAD nodes.

	* tree.c (decl_list_length): Remove.
	(binding_init): New function.
	(count_functions): Rewrite.
	(is_overloaded_fn): Expect OVERLOAD nodes.
	(really_overloaded_fn): Likewise.
	(get_first_fn): Likewise.
	(lvalue_type): Likewise.
	(ovl_cons, scratch_ovl_cons, build_overload, build_overload_after,
	 ovl_member): New function.

	* typeck.c (require_complete_type): Expect OVERLOAD nodes.
	(type_unknown_p): Likewise.
	(require_instantiated_type): Likewise.
	(build_component_ref): Declare code dead.
	(build_x_function_call): Create and expect OVERLOAD nodes.
	(build_function_call_real): Check for ::main only.
	(build_unary_op): Likewise.  Expect OVERLOAD nodes.
	(convert_for_assignment): Check for TREE_LIST before accessing
	TREE_VALUE.
	
	* decl.c (duplicate_decls): Check for namespace bindings instead
	of global bindings.
	(pushdecl): Likewise.
	(push_overloaded_decl): Likewise.
	(lookup_tag): Likewise.
	(lookup_name_real): Likewise.
	(lookup_name_current_level): Likewise.
	(start_decl): Likewise.
	(xref_tag): Likewise.
	(finish_enum): Likewise.
	* init.c (build_offset_ref): Likewise.
	* search.c (lookup_field): Likewise.
	(lookup_fnfields): Likewise.
	(dfs_debug_mark): Likewise.

	* decl.c (poplevel): Use SET_IDENTIFIER_TYPE_VALUE.
	(poplevel_class): Likewise.
	(pop_from_toplevel): Likewise.	
	* decl2.c (finish_method): Likewise.

	* class.c (build_vtable): Use SET_IDENTIFIER_GLOBAL_VALUE.
	* decl.c (record_builtin_type): Likewise.
	(init_decl_processing): Likewise.
	(grokfndecl): Likewise.
	* lex.c (get_time_identifier): Likewise.
	(do_identifier): Likewise.
	(do_scoped_id): Likewise.
	(make_lang_type): Likewise.
	* parse.y (make_thunk): Likewise.
	* pt.c (tsubst): Likewise.
	* tree.c (debug_binfo): Likewise.
<ftp://site.informatik.hu-berlin.de/pub/loewis/namespaces.gz>
Content-type: application/octet-stream;type=x-gzip
Transfer-mode: image

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]