This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: ObjC++ template expansion -- Part 1
- From: Ziemowit Laski <zlaski at apple dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 12 Sep 2004 15:15:16 -0700
- Subject: PATCH: ObjC++ template expansion -- Part 1
Yes, ObjC++ supports it. More specifically, there are two ObjC-specific
expression nodes, MESSAGE_SEND_EXPR and CLASS_REFERENCE_EXPR (see
objc/objc-tree.def),
which may have dependent types (forgive if this is not the correct C++
nomenclature)
embedded in them.
The C++ front-end needs to be modified in two places for this purpose.
This patch
touches the first place.
The template_args_equal() routine must be taught to distinguish among
ObjC types
differing only in protocol qualifications (e.g., 'NSObject *' vs.
'NSObject <Foo> *').
The "ordinary" C and C++ type comparisons presently fail to do this,
which is why
we also needed the modifications to build_c_cast() earlier on.
Does this look OK?
Thanks,
--Zem
2004-09-12 Ziemowit Laski <zlaski@apple.com>
* Make-lang.in (cp/pt.o): Depend on c-common.h.
* pt.c: Include c-common.h.
(template_args_equal): Call objc_comptypes() to compare
ObjC types correctly.
Index: gcc/cp/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.194
diff -u -3 -p -r1.194 Make-lang.in
--- gcc/cp/Make-lang.in 9 Sep 2004 22:53:51 -0000 1.194
+++ gcc/cp/Make-lang.in 12 Sep 2004 22:02:50 -0000
@@ -260,7 +260,7 @@ cp/except.o: cp/except.c $(CXX_TREE_H) $
cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(RTL_H) flags.h $(EXPR_H)
toplev.h \
except.h $(TM_P_H)
cp/pt.o: cp/pt.c $(CXX_TREE_H) $(TM_H) cp/decl.h \
- toplev.h $(RTL_H) except.h tree-inline.h gt-cp-pt.h
+ toplev.h $(RTL_H) except.h tree-inline.h gt-cp-pt.h c-common.h
cp/error.o: cp/error.c $(CXX_TREE_H) $(TM_H) toplev.h $(DIAGNOSTIC_H) \
flags.h real.h $(LANGHOOKS_DEF_H) $(CXX_PRETTY_PRINT_H)
cp/repo.o: cp/repo.c $(CXX_TREE_H) $(TM_H) toplev.h diagnostic.h \
Index: gcc/cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.921
diff -u -3 -p -r1.921 pt.c
--- gcc/cp/pt.c 12 Sep 2004 04:45:46 -0000 1.921
+++ gcc/cp/pt.c 12 Sep 2004 22:02:52 -0000
@@ -33,6 +33,7 @@ Boston, MA 02111-1307, USA. */
#include "obstack.h"
#include "tree.h"
#include "flags.h"
+#include "c-common.h"
#include "cp-tree.h"
#include "tree-inline.h"
#include "decl.h"
@@ -3960,7 +3961,24 @@ template_args_equal (tree ot, tree nt)
/* For member templates */
return TREE_CODE (ot) == TREE_VEC && comp_template_args (ot, nt);
else if (TYPE_P (nt))
- return TYPE_P (ot) && same_type_p (ot, nt);
+ {
+ int c1, c2;
+
+ if (!TYPE_P (ot))
+ return 0;
+
+ /* We must handle ObjC types specially because they may differ
+ only in protocol qualifications (e.g., 'NSObject *' vs.
+ 'NSObject <Foo> *') that must be taken into account here.
+ See also cp/typeck.c:build_c_cast(), where a similar problem
+ arises. We must call objc_comptypes() twice, since its
+ comparisons are _not_ symmetric. */
+ if ((c1 = objc_comptypes (ot, nt, 0)) >= 0
+ && (c2 = objc_comptypes (nt, ot, 0)) >= 0)
+ return (c1 && c2);
+
+ return same_type_p (ot, nt);
+ }
else if (TREE_CODE (ot) == TREE_VEC || TYPE_P (ot))
return 0;
else