diff options
author | Gabriel Dos Reis <gdr@integrable-solutions.net> | 2003-09-27 16:44:05 +0000 |
---|---|---|
committer | Gabriel Dos Reis <gdr@gcc.gnu.org> | 2003-09-27 16:44:05 +0000 |
commit | c003e212ead438407d7968c2ada135f90307a8be (patch) | |
tree | d165f5d3ea36c74d1560aeb2b2e40406468c4db1 | |
parent | 6398fbfddca9e92f601fa68764b2efccd3a30124 (diff) | |
download | gcc-c003e212ead438407d7968c2ada135f90307a8be.zip gcc-c003e212ead438407d7968c2ada135f90307a8be.tar.gz gcc-c003e212ead438407d7968c2ada135f90307a8be.tar.bz2 |
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
-rw-r--r-- | gcc/cp/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/cp/call.c | 7 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/decl.c | 14 | ||||
-rw-r--r-- | gcc/cp/except.c | 28 | ||||
-rw-r--r-- | gcc/cp/name-lookup.h | 27 | ||||
-rw-r--r-- | gcc/cp/parser.c | 5 | ||||
-rw-r--r-- | gcc/cp/rtti.c | 8 |
8 files changed, 61 insertions, 47 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2fec9ae..54f84be 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,20 @@ +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> PR c++/11415 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 424ec8d..989a84a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4192,12 +4192,9 @@ convert_like_real (tree convs, tree expr, tree fn, int argnum, int inner, static tree call_builtin_trap (void) { - tree fn = get_identifier ("__builtin_trap"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else - abort (); + tree fn = IDENTIFIER_GLOBAL_VALUE (get_identifier ("__builtin_trap")); + my_friendly_assert (fn != NULL, 20030927); fn = build_call (fn, NULL_TREE); fn = build (COMPOUND_EXPR, integer_type_node, fn, integer_zero_node); return fn; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 628a0c9..0786bc5 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -870,8 +870,6 @@ struct language_function GTY(()) #define current_function_return_value \ (cp_function_chain->x_return_value) -extern GTY(()) tree global_namespace; - #define ansi_opname(CODE) \ (operator_name_info[(int) (CODE)].identifier) #define ansi_assopname(CODE) \ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 51edfd2..5eab210 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6589,11 +6589,9 @@ check_tag_decl (tree declspecs) { tree value = TREE_VALUE (link); - if (TYPE_P (value) - || TREE_CODE (value) == TYPE_DECL + if (TYPE_P (value) || TREE_CODE (value) == TYPE_DECL || (TREE_CODE (value) == IDENTIFIER_NODE - && IDENTIFIER_GLOBAL_VALUE (value) - && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (value)) == TYPE_DECL)) + && is_typename_at_global_scope (value))) { ++found_type; @@ -9674,9 +9672,7 @@ grokdeclarator (tree declarator, flags = TYPENAME_FLAG; ctor_return_type = TREE_TYPE (dname); sfk = sfk_conversion; - if (IDENTIFIER_GLOBAL_VALUE (dname) - && (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (dname)) - == TYPE_DECL)) + if (is_typename_at_global_scope (dname)) name = IDENTIFIER_POINTER (dname); else name = "<invalid operator>"; @@ -10309,9 +10305,7 @@ grokdeclarator (tree declarator, op = IDENTIFIER_OPNAME_P (tmp); if (IDENTIFIER_TYPENAME_P (tmp)) { - if (IDENTIFIER_GLOBAL_VALUE (tmp) - && (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (tmp)) - == TYPE_DECL)) + if (is_typename_at_global_scope (tmp)) name = IDENTIFIER_POINTER (tmp); else name = "<invalid operator>"; diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 1303919..962da96 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -161,9 +161,7 @@ do_begin_catch (void) tree fn; fn = get_identifier ("__cxa_begin_catch"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* Declare void* __cxa_begin_catch (void *). */ tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); @@ -198,9 +196,7 @@ do_end_catch (tree type) tree fn, cleanup; fn = get_identifier ("__cxa_end_catch"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* Declare void __cxa_end_catch (). */ fn = push_void_library_fn (fn, void_list_node); @@ -498,9 +494,7 @@ do_allocate_exception (tree type) tree fn; fn = get_identifier ("__cxa_allocate_exception"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* Declare void *__cxa_allocate_exception(size_t). */ tree tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); @@ -521,9 +515,7 @@ do_free_exception (tree ptr) tree fn; fn = get_identifier ("__cxa_free_exception"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* Declare void __cxa_free_exception (void *). */ fn = push_void_library_fn (fn, tree_cons (NULL_TREE, ptr_type_node, @@ -644,9 +636,7 @@ build_throw (tree exp) if (exp && decl_is_java_type (TREE_TYPE (exp), 1)) { tree fn = get_identifier ("_Jv_Throw"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* Declare void _Jv_Throw (void *). */ tree tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); @@ -665,9 +655,7 @@ build_throw (tree exp) tree temp_expr, allocate_expr; fn = get_identifier ("__cxa_throw"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* The CLEANUP_TYPE is the internal type of a destructor. */ if (cleanup_type == NULL_TREE) @@ -772,9 +760,7 @@ build_throw (tree exp) /* Rethrow current exception. */ tree fn = get_identifier ("__cxa_rethrow"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { /* Declare void __cxa_rethrow (void). */ fn = push_throw_library_fn diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 923f480..04c6161 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -97,6 +97,9 @@ extern cxx_binding *cxx_binding_make (tree, tree); extern void cxx_binding_free (cxx_binding *); 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. */ #define global_scope_p(SCOPE) \ ((SCOPE) == NAMESPACE_LEVEL (global_namespace)) @@ -107,4 +110,28 @@ extern cxx_binding *binding_for_name (cxx_scope *, tree); extern tree namespace_binding (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 */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7968b28..ec5912f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11840,9 +11840,8 @@ cp_parser_member_declaration (cp_parser* parser) { tree s = TREE_VALUE (specifier); - if (TREE_CODE (s) == IDENTIFIER_NODE - && IDENTIFIER_GLOBAL_VALUE (s)) - type = IDENTIFIER_GLOBAL_VALUE (s); + if (TREE_CODE (s) == IDENTIFIER_NODE) + get_global_value_if_present (s, &type); if (TREE_CODE (s) == TYPE_DECL) s = TREE_TYPE (s); if (TYPE_P (s)) diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index c53238f..391a581 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -172,9 +172,7 @@ static tree throw_bad_cast (void) { tree fn = get_identifier ("__cxa_bad_cast"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) fn = push_throw_library_fn (fn, build_function_type (ptr_type_node, void_list_node)); @@ -188,9 +186,7 @@ static tree throw_bad_typeid (void) { tree fn = get_identifier ("__cxa_bad_typeid"); - if (IDENTIFIER_GLOBAL_VALUE (fn)) - fn = IDENTIFIER_GLOBAL_VALUE (fn); - else + if (!get_global_value_if_present (fn, &fn)) { tree t = build_qualified_type (type_info_type_node, TYPE_QUAL_CONST); t = build_function_type (build_reference_type (t), void_list_node); |