Commit c003e212 by Gabriel Dos Reis Committed by Gabriel Dos Reis

name-lookup.h (get_global_value_if_present): New function.

	* name-lookup.h (get_global_value_if_present): New function.
	(is_typename_at_global_scope): Likewise.
	* except.c (do_begin_catch): Use get_global_value_if_present.
	(do_end_catch): Likewise.
	(do_allocate_exception): Likewise.
	(do_free_exception): Likewise.
	(build_throw): Likewise.
	* parser.c (cp_parser_member_declaration): Likewise.
	* rtti.c (throw_bad_cast): Likewise.
	(throw_bad_typeid): Likewise.
	* decl.c (check_tag_decl): Use is_typename_at_global_scope.
	(grokdeclarator): Likewise.
	* cp-tree.h (global_namespace): Move to name-lookup.h
	* call.c (call_builtin_trap): Tidy.

From-SVN: r71858
parent 6398fbfd
2003-09-27 Gabriel Dos Reis <gdr@integrable-solutions.net>
* name-lookup.h (get_global_value_if_present): New function.
(is_typename_at_global_scope): Likewise.
* except.c (do_begin_catch): Use get_global_value_if_present.
(do_end_catch): Likewise.
(do_allocate_exception): Likewise.
(do_free_exception): Likewise.
(build_throw): Likewise.
* parser.c (cp_parser_member_declaration): Likewise.
* rtti.c (throw_bad_cast): Likewise.
(throw_bad_typeid): Likewise.
* decl.c (check_tag_decl): Use is_typename_at_global_scope.
(grokdeclarator): Likewise.
* cp-tree.h (global_namespace): Move to name-lookup.h
* call.c (call_builtin_trap): Tidy.
2003-09-27 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> 2003-09-27 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/11415 PR c++/11415
......
...@@ -4192,12 +4192,9 @@ convert_like_real (tree convs, tree expr, tree fn, int argnum, int inner, ...@@ -4192,12 +4192,9 @@ convert_like_real (tree convs, tree expr, tree fn, int argnum, int inner,
static tree static tree
call_builtin_trap (void) call_builtin_trap (void)
{ {
tree fn = get_identifier ("__builtin_trap"); tree fn = IDENTIFIER_GLOBAL_VALUE (get_identifier ("__builtin_trap"));
if (IDENTIFIER_GLOBAL_VALUE (fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
abort ();
my_friendly_assert (fn != NULL, 20030927);
fn = build_call (fn, NULL_TREE); fn = build_call (fn, NULL_TREE);
fn = build (COMPOUND_EXPR, integer_type_node, fn, integer_zero_node); fn = build (COMPOUND_EXPR, integer_type_node, fn, integer_zero_node);
return fn; return fn;
......
...@@ -870,8 +870,6 @@ struct language_function GTY(()) ...@@ -870,8 +870,6 @@ struct language_function GTY(())
#define current_function_return_value \ #define current_function_return_value \
(cp_function_chain->x_return_value) (cp_function_chain->x_return_value)
extern GTY(()) tree global_namespace;
#define ansi_opname(CODE) \ #define ansi_opname(CODE) \
(operator_name_info[(int) (CODE)].identifier) (operator_name_info[(int) (CODE)].identifier)
#define ansi_assopname(CODE) \ #define ansi_assopname(CODE) \
......
...@@ -6589,11 +6589,9 @@ check_tag_decl (tree declspecs) ...@@ -6589,11 +6589,9 @@ check_tag_decl (tree declspecs)
{ {
tree value = TREE_VALUE (link); tree value = TREE_VALUE (link);
if (TYPE_P (value) if (TYPE_P (value) || TREE_CODE (value) == TYPE_DECL
|| TREE_CODE (value) == TYPE_DECL
|| (TREE_CODE (value) == IDENTIFIER_NODE || (TREE_CODE (value) == IDENTIFIER_NODE
&& IDENTIFIER_GLOBAL_VALUE (value) && is_typename_at_global_scope (value)))
&& TREE_CODE (IDENTIFIER_GLOBAL_VALUE (value)) == TYPE_DECL))
{ {
++found_type; ++found_type;
...@@ -9674,9 +9672,7 @@ grokdeclarator (tree declarator, ...@@ -9674,9 +9672,7 @@ grokdeclarator (tree declarator,
flags = TYPENAME_FLAG; flags = TYPENAME_FLAG;
ctor_return_type = TREE_TYPE (dname); ctor_return_type = TREE_TYPE (dname);
sfk = sfk_conversion; sfk = sfk_conversion;
if (IDENTIFIER_GLOBAL_VALUE (dname) if (is_typename_at_global_scope (dname))
&& (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (dname))
== TYPE_DECL))
name = IDENTIFIER_POINTER (dname); name = IDENTIFIER_POINTER (dname);
else else
name = "<invalid operator>"; name = "<invalid operator>";
...@@ -10309,9 +10305,7 @@ grokdeclarator (tree declarator, ...@@ -10309,9 +10305,7 @@ grokdeclarator (tree declarator,
op = IDENTIFIER_OPNAME_P (tmp); op = IDENTIFIER_OPNAME_P (tmp);
if (IDENTIFIER_TYPENAME_P (tmp)) if (IDENTIFIER_TYPENAME_P (tmp))
{ {
if (IDENTIFIER_GLOBAL_VALUE (tmp) if (is_typename_at_global_scope (tmp))
&& (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (tmp))
== TYPE_DECL))
name = IDENTIFIER_POINTER (tmp); name = IDENTIFIER_POINTER (tmp);
else else
name = "<invalid operator>"; name = "<invalid operator>";
......
...@@ -161,9 +161,7 @@ do_begin_catch (void) ...@@ -161,9 +161,7 @@ do_begin_catch (void)
tree fn; tree fn;
fn = get_identifier ("__cxa_begin_catch"); fn = get_identifier ("__cxa_begin_catch");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* Declare void* __cxa_begin_catch (void *). */ /* Declare void* __cxa_begin_catch (void *). */
tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
...@@ -198,9 +196,7 @@ do_end_catch (tree type) ...@@ -198,9 +196,7 @@ do_end_catch (tree type)
tree fn, cleanup; tree fn, cleanup;
fn = get_identifier ("__cxa_end_catch"); fn = get_identifier ("__cxa_end_catch");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* Declare void __cxa_end_catch (). */ /* Declare void __cxa_end_catch (). */
fn = push_void_library_fn (fn, void_list_node); fn = push_void_library_fn (fn, void_list_node);
...@@ -498,9 +494,7 @@ do_allocate_exception (tree type) ...@@ -498,9 +494,7 @@ do_allocate_exception (tree type)
tree fn; tree fn;
fn = get_identifier ("__cxa_allocate_exception"); fn = get_identifier ("__cxa_allocate_exception");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* Declare void *__cxa_allocate_exception(size_t). */ /* Declare void *__cxa_allocate_exception(size_t). */
tree tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); tree tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
...@@ -521,9 +515,7 @@ do_free_exception (tree ptr) ...@@ -521,9 +515,7 @@ do_free_exception (tree ptr)
tree fn; tree fn;
fn = get_identifier ("__cxa_free_exception"); fn = get_identifier ("__cxa_free_exception");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* Declare void __cxa_free_exception (void *). */ /* Declare void __cxa_free_exception (void *). */
fn = push_void_library_fn (fn, tree_cons (NULL_TREE, ptr_type_node, fn = push_void_library_fn (fn, tree_cons (NULL_TREE, ptr_type_node,
...@@ -644,9 +636,7 @@ build_throw (tree exp) ...@@ -644,9 +636,7 @@ build_throw (tree exp)
if (exp && decl_is_java_type (TREE_TYPE (exp), 1)) if (exp && decl_is_java_type (TREE_TYPE (exp), 1))
{ {
tree fn = get_identifier ("_Jv_Throw"); tree fn = get_identifier ("_Jv_Throw");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* Declare void _Jv_Throw (void *). */ /* Declare void _Jv_Throw (void *). */
tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
...@@ -665,9 +655,7 @@ build_throw (tree exp) ...@@ -665,9 +655,7 @@ build_throw (tree exp)
tree temp_expr, allocate_expr; tree temp_expr, allocate_expr;
fn = get_identifier ("__cxa_throw"); fn = get_identifier ("__cxa_throw");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* The CLEANUP_TYPE is the internal type of a destructor. */ /* The CLEANUP_TYPE is the internal type of a destructor. */
if (cleanup_type == NULL_TREE) if (cleanup_type == NULL_TREE)
...@@ -772,9 +760,7 @@ build_throw (tree exp) ...@@ -772,9 +760,7 @@ build_throw (tree exp)
/* Rethrow current exception. */ /* Rethrow current exception. */
tree fn = get_identifier ("__cxa_rethrow"); tree fn = get_identifier ("__cxa_rethrow");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
/* Declare void __cxa_rethrow (void). */ /* Declare void __cxa_rethrow (void). */
fn = push_throw_library_fn fn = push_throw_library_fn
......
...@@ -97,6 +97,9 @@ extern cxx_binding *cxx_binding_make (tree, tree); ...@@ -97,6 +97,9 @@ extern cxx_binding *cxx_binding_make (tree, tree);
extern void cxx_binding_free (cxx_binding *); extern void cxx_binding_free (cxx_binding *);
extern bool supplement_binding (cxx_binding *, tree); extern bool supplement_binding (cxx_binding *, tree);
/* The tree node representing the global scope. */
extern GTY(()) tree global_namespace;
/* True if SCOPE designates the global scope binding contour. */ /* True if SCOPE designates the global scope binding contour. */
#define global_scope_p(SCOPE) \ #define global_scope_p(SCOPE) \
((SCOPE) == NAMESPACE_LEVEL (global_namespace)) ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
...@@ -107,4 +110,28 @@ extern cxx_binding *binding_for_name (cxx_scope *, tree); ...@@ -107,4 +110,28 @@ extern cxx_binding *binding_for_name (cxx_scope *, tree);
extern tree namespace_binding (tree, tree); extern tree namespace_binding (tree, tree);
extern void set_namespace_binding (tree, tree, tree); extern void set_namespace_binding (tree, tree, tree);
/* Set *DECL to the (non-hidden) declaration for ID at global scope,
if present and return true; otherwise return false. */
static inline bool
get_global_value_if_present (tree id, tree *decl)
{
tree global_value = namespace_binding (id, global_namespace);
if (global_value)
*decl = global_value;
return global_value != NULL;
}
/* True is the binding of IDENTIFIER at global scope names a type. */
static inline bool
is_typename_at_global_scope (tree id)
{
tree global_value = namespace_binding (id, global_namespace);
return global_value && TREE_CODE (global_value) == TYPE_DECL;
}
#endif /* GCC_CP_NAME_LOOKUP_H */ #endif /* GCC_CP_NAME_LOOKUP_H */
...@@ -11840,9 +11840,8 @@ cp_parser_member_declaration (cp_parser* parser) ...@@ -11840,9 +11840,8 @@ cp_parser_member_declaration (cp_parser* parser)
{ {
tree s = TREE_VALUE (specifier); tree s = TREE_VALUE (specifier);
if (TREE_CODE (s) == IDENTIFIER_NODE if (TREE_CODE (s) == IDENTIFIER_NODE)
&& IDENTIFIER_GLOBAL_VALUE (s)) get_global_value_if_present (s, &type);
type = IDENTIFIER_GLOBAL_VALUE (s);
if (TREE_CODE (s) == TYPE_DECL) if (TREE_CODE (s) == TYPE_DECL)
s = TREE_TYPE (s); s = TREE_TYPE (s);
if (TYPE_P (s)) if (TYPE_P (s))
......
...@@ -172,9 +172,7 @@ static tree ...@@ -172,9 +172,7 @@ static tree
throw_bad_cast (void) throw_bad_cast (void)
{ {
tree fn = get_identifier ("__cxa_bad_cast"); tree fn = get_identifier ("__cxa_bad_cast");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
fn = push_throw_library_fn (fn, build_function_type (ptr_type_node, fn = push_throw_library_fn (fn, build_function_type (ptr_type_node,
void_list_node)); void_list_node));
...@@ -188,9 +186,7 @@ static tree ...@@ -188,9 +186,7 @@ static tree
throw_bad_typeid (void) throw_bad_typeid (void)
{ {
tree fn = get_identifier ("__cxa_bad_typeid"); tree fn = get_identifier ("__cxa_bad_typeid");
if (IDENTIFIER_GLOBAL_VALUE (fn)) if (!get_global_value_if_present (fn, &fn))
fn = IDENTIFIER_GLOBAL_VALUE (fn);
else
{ {
tree t = build_qualified_type (type_info_type_node, TYPE_QUAL_CONST); tree t = build_qualified_type (type_info_type_node, TYPE_QUAL_CONST);
t = build_function_type (build_reference_type (t), void_list_node); t = build_function_type (build_reference_type (t), void_list_node);
......
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