This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

PATCH: Let ObjC/ObjC++ use the C/C++ types_compatible_p langhook functions


I just noticed that ObjC was using the generic lhd_types_compatible_p() function for its
lang_hooks.types_compatible_p hooks, instead of calling c_types_compatible_p() just like C.
Similarly, ObjC++ will need to use the cxx_types_compatible_p() function provided by C++.
The following patch moves c_types_compatible_p() and cxx_types_compatible_p() and associated
LANG_HOOK_... definitions to where ObjC and ObjC++ can see them.


Since this patch does not affect the functioning of the C or C++ front-ends, I'm inclined to
commit it as C/C++-wise obvious, though I shall wait until tomorrow (Tuesday) should people have
comments.


Thanks,

--Zem

[gcc/ChangeLog]
2004-11-02  Ziemowit Laski  <zlaski@apple.com>

	* c-lang.c (LANG_HOOKS_TYPES_COMPATIBLE_P): Remove.
	(c_types_compatible_p): Move function definition...
	* c-objc-common.c (c_types_compatible_p): ...here.
	* c-objc-common.h (LANG_HOOKS_TYPES_COMPATIBLE_P): Moved here from
	c-lang.c.

[gcc/cp/ChangeLog]
2004-11-02  Ziemowit Laski  <zlaski@apple.com>

	* cp-lang.c (cxx_types_compatible_p): Remove prototype and definition.
	(LANG_HOOKS_TYPES_COMPATIBLE_P): Move to cp-objcp-common.h.
	* cp-objcp-common.c (cxx_types_compatible_p): Moved definition here
	from cp-lang.c.
	* cp-objcp-common.h (cxx_types_compatible_p): Moved prototype here
	from cp-lang.c.
	(LANG_HOOKS_TYPES_COMPATIBLE_P): Moved here from cp-lang.c.

Index: gcc/c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.135
diff -u -3 -p -r1.135 c-lang.c
--- gcc/c-lang.c        17 Sep 2004 21:54:22 -0000      1.135
+++ gcc/c-lang.c        2 Nov 2004 06:19:13 -0000
@@ -44,8 +44,6 @@ enum c_language_kind c_language = clk_c;
 #define LANG_HOOKS_NAME "GNU C"
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT c_objc_common_init
-#undef LANG_HOOKS_TYPES_COMPATIBLE_P
-#define LANG_HOOKS_TYPES_COMPATIBLE_P c_types_compatible_p

 /* Each front end provides its own lang hook initializer.  */
 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
@@ -92,10 +90,4 @@ finish_file (void)
 {
 }

-int
-c_types_compatible_p (tree x, tree y)
-{
- return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y));
-}
-
#include "gtype-c.h"
Index: gcc/c-objc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-objc-common.c,v
retrieving revision 1.58
diff -u -3 -p -r1.58 c-objc-common.c
--- gcc/c-objc-common.c 3 Oct 2004 20:53:04 -0000 1.58
+++ gcc/c-objc-common.c 2 Nov 2004 06:19:14 -0000
@@ -296,3 +296,9 @@ c_initialize_diagnostics (diagnostic_con
/* It is safe to free this object because it was previously XNEW()'d. */
XDELETE (base);
}
+
+int
+c_types_compatible_p (tree x, tree y)
+{
+ return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y));
+}
Index: gcc/c-objc-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-objc-common.h,v
retrieving revision 2.1
diff -u -3 -p -r2.1 c-objc-common.h
--- gcc/c-objc-common.h 15 Aug 2004 21:47:32 -0000 2.1
+++ gcc/c-objc-common.h 2 Nov 2004 06:19:14 -0000
@@ -66,6 +66,8 @@ extern void c_initialize_diagnostics (di
#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL c_warn_unused_global_decl
#undef LANG_HOOKS_PRINT_IDENTIFIER
#define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
+#undef LANG_HOOKS_TYPES_COMPATIBLE_P
+#define LANG_HOOKS_TYPES_COMPATIBLE_P c_types_compatible_p
#undef LANG_HOOKS_FUNCTION_ENTER_NESTED
#define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context
#undef LANG_HOOKS_FUNCTION_LEAVE_NESTED
Index: gcc/cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.95
diff -u -3 -p -r1.95 cp-lang.c
--- gcc/cp/cp-lang.c 22 Sep 2004 06:11:20 -0000 1.95
+++ gcc/cp/cp-lang.c 2 Nov 2004 06:19:18 -0000
@@ -39,16 +39,12 @@ enum c_language_kind c_language = clk_cx
/* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
consequently, there should be very few hooks below. */


-static int cxx_types_compatible_p (tree, tree);
-
 #undef LANG_HOOKS_NAME
 #define LANG_HOOKS_NAME "GNU C++"
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT cxx_init
 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
 #define LANG_HOOKS_DECL_PRINTABLE_NAME cxx_printable_name
-#undef LANG_HOOKS_TYPES_COMPATIBLE_P
-#define LANG_HOOKS_TYPES_COMPATIBLE_P cxx_types_compatible_p
 #undef LANG_HOOKS_FOLD_OBJ_TYPE_REF
 #define LANG_HOOKS_FOLD_OBJ_TYPE_REF cp_fold_obj_type_ref

@@ -99,25 +95,6 @@ const char *const tree_code_name[] = {
/* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
there should be very few routines below. */


-/* This compares two types for equivalence ("compatible" in C-based languages).
- This routine should only return 1 if it is sure. It should not be used
- in contexts where erroneously returning 0 causes problems. */
-
-static int cxx_types_compatible_p (tree x, tree y)
-{
- if (same_type_ignoring_top_level_qualifiers_p (x, y))
- return 1;
-
- /* Once we get to the middle-end, references and pointers are
- interchangeable. FIXME should we try to replace all references with
- pointers? */
- if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
- && same_type_p (TREE_TYPE (x), TREE_TYPE (y)))
- return 1;
-
- return 0;
-}
-
/* The following function does something real, but only in Objective-C++. */


 tree
Index: gcc/cp/cp-objcp-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-objcp-common.c,v
retrieving revision 1.2
diff -u -3 -p -r1.2 cp-objcp-common.c
--- gcc/cp/cp-objcp-common.c    31 Aug 2004 18:51:07 -0000      1.2
+++ gcc/cp/cp-objcp-common.c    2 Nov 2004 06:19:18 -0000
@@ -148,6 +148,26 @@ cxx_initialize_diagnostics (diagnostic_c
   free (base);
 }

+/* This compares two types for equivalence ("compatible" in C-based languages).
+ This routine should only return 1 if it is sure. It should not be used
+ in contexts where erroneously returning 0 causes problems. */
+
+int
+cxx_types_compatible_p (tree x, tree y)
+{
+ if (same_type_ignoring_top_level_qualifiers_p (x, y))
+ return 1;
+
+ /* Once we get to the middle-end, references and pointers are
+ interchangeable. FIXME should we try to replace all references with
+ pointers? */
+ if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
+ && same_type_p (TREE_TYPE (x), TREE_TYPE (y)))
+ return 1;
+
+ return 0;
+}
+
/* Stubs to keep c-opts.c happy. */
void
push_file_scope (void)
Index: gcc/cp/cp-objcp-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-objcp-common.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 cp-objcp-common.h
--- gcc/cp/cp-objcp-common.h 22 Sep 2004 06:11:20 -0000 1.4
+++ gcc/cp/cp-objcp-common.h 2 Nov 2004 06:19:18 -0000
@@ -30,6 +30,7 @@ extern tree cp_expr_size (tree);
extern size_t cp_tree_size (enum tree_code);
extern bool cp_var_mod_type_p (tree, tree);
extern void cxx_initialize_diagnostics (struct diagnostic_context *);
+extern int cxx_types_compatible_p (tree, tree);


/* In cp/cp-lang.c and objcp/objcp-lang.c. */

@@ -86,6 +87,8 @@ extern tree objcp_tsubst_copy_and_build
 #define LANG_HOOKS_PRINT_TYPE cxx_print_type
 #undef LANG_HOOKS_PRINT_IDENTIFIER
 #define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier
+#undef LANG_HOOKS_TYPES_COMPATIBLE_P
+#define LANG_HOOKS_TYPES_COMPATIBLE_P cxx_types_compatible_p
 #undef LANG_HOOKS_PRINT_ERROR_FUNCTION
 #define LANG_HOOKS_PRINT_ERROR_FUNCTION        cxx_print_error_function
 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL


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