OSDN Git Service

* name-lookup.h (get_global_value_if_present): New function.
authorgdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 27 Sep 2003 16:44:05 +0000 (16:44 +0000)
committergdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 27 Sep 2003 16:44:05 +0000 (16:44 +0000)
(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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71858 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/except.c
gcc/cp/name-lookup.h
gcc/cp/parser.c
gcc/cp/rtti.c

index 2fec9ae..54f84be 100644 (file)
@@ -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
index 424ec8d..989a84a 100644 (file)
@@ -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;
index 628a0c9..0786bc5 100644 (file)
@@ -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) \
index 51edfd2..5eab210 100644 (file)
@@ -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>";
index 1303919..962da96 100644 (file)
@@ -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
index 923f480..04c6161 100644 (file)
@@ -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);
 \f
+/* 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 */
index 7968b28..ec5912f 100644 (file)
@@ -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))
index c53238f..391a581 100644 (file)
@@ -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);