+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
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;
#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) \
{
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;
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>";
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>";
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);
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);
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);
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,
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);
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)
/* 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
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))
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 */
{
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))
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));
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);