aboutsummaryrefslogtreecommitdiff
path: root/gcc/objc
diff options
context:
space:
mode:
authorZiemowit Laski <zlaski@gcc.gnu.org>2004-10-25 22:55:25 +0000
committerZiemowit Laski <zlaski@gcc.gnu.org>2004-10-25 22:55:25 +0000
commit3a3589b4ba5e2d88874f8178f8808f784860fca5 (patch)
treeac249a647a7d1f72cb019c1e551cbb2d1a3eeda9 /gcc/objc
parent5307127042d75e40e952bb986e6f15377dac75db (diff)
downloadgcc-3a3589b4ba5e2d88874f8178f8808f784860fca5.zip
gcc-3a3589b4ba5e2d88874f8178f8808f784860fca5.tar.gz
gcc-3a3589b4ba5e2d88874f8178f8808f784860fca5.tar.bz2
c-common.h: Remove RID_ID.
[gcc/ChangeLog] 2004-10-25 David Ayers <d.ayers@inode.at> * c-common.h: Remove RID_ID. * c-parse.in: Remove OBJECTNAME and references to RID_ID. (typespec_reserved_attr): Add rule for TYPENAME non_empty_protocolrefs. (yylexname): Remove special handling of RID_ID. [gcc/objc/ChangeLog] 2004-10-25 Ziemowit Laski <zlaski@apple.com> David Ayers <d.ayers@inode.at> * objc-act.c (objc_comptypes): Use IS_PROTOCOL_QUALIFIED_UNTYPED instead of IS_PROTOCOL_QUALIFIED_ID; add comparisons for: 'Class <Protocol> != id <Protocol>'; 'Class <Protocol> != <class> *'; 'Class <Protocol> == id' and 'Class <Protocol> == Class'. (objc_is_id): Add test for 'super'. (objc_finish_message_expr): Allow for messaging of 'Class <Proto>' receivers; if class methods are not found in protocol lists, search for instance methods therein and warn if one is found. Look in global hash tables for suitable method as a last resort when messaging 'id <Proto>', 'Class <Proto>' and invalid receiver types. (objc_add_method): Insert instance methods listed in protocols into the global class method hash table. * objc-act.h (IS_PROTOCOL_QUALIFIED_ID): Rename to IS_PROTOCOL_QUALIFIED_UNTYPED and allow for 'Class <Proto>' in addition to 'id <Proto>'. [gcc/testsuite/ChangeLog] 2004-10-25 David Ayers <d.ayers@inode.at> Ziemowit Laski <zlaski@apple.com> * objc.dg/call-super-2.m: Add messages to 'Class <Proto>'; update diagnostics when messaging 'id <Proto>'. * objc.dg/class-protocol-1.m: New test. * objc.dg/desig-init-1.m: Add message to an invalid receiver using a non-existent method signature. * objc.dg/method-5.m, objc.dg/method-6.m, objc.dg/proto-hier-1.m: Update diagnostics when messaging with non-existent method signature. * objc.dg/proto-hier-2.m: Adjust wording of diagnostic. * objc.dg/proto-lossage-1.m, objc.dg/proto-lossage-4.m: Messages to invalid receivers are now resolved as if messaging 'id'; remove extraneous diagnostics. From-SVN: r89562
Diffstat (limited to 'gcc/objc')
-rw-r--r--gcc/objc/ChangeLog19
-rw-r--r--gcc/objc/objc-act.c103
-rw-r--r--gcc/objc/objc-act.h4
3 files changed, 97 insertions, 29 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index b904fa0..f781a1c 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,3 +1,22 @@
+2004-10-25 Ziemowit Laski <zlaski@apple.com>
+ David Ayers <d.ayers@inode.at>
+
+ * objc-act.c (objc_comptypes): Use IS_PROTOCOL_QUALIFIED_UNTYPED
+ instead of IS_PROTOCOL_QUALIFIED_ID; add comparisons for:
+ 'Class <Protocol> != id <Protocol>'; 'Class <Protocol> != <class> *';
+ 'Class <Protocol> == id' and 'Class <Protocol> == Class'.
+ (objc_is_id): Add test for 'super'.
+ (objc_finish_message_expr): Allow for messaging of 'Class <Proto>'
+ receivers; if class methods are not found in protocol lists, search
+ for instance methods therein and warn if one is found. Look in
+ global hash tables for suitable method as a last resort when messaging
+ 'id <Proto>', 'Class <Proto>' and invalid receiver types.
+ (objc_add_method): Insert instance methods listed in protocols into
+ the global class method hash table.
+ * objc-act.h (IS_PROTOCOL_QUALIFIED_ID): Rename to
+ IS_PROTOCOL_QUALIFIED_UNTYPED and allow for 'Class <Proto>' in
+ addition to 'id <Proto>'.
+
2004-10-21 Andrew Pinski <pinskia@physics.uc.edu>
PR objc/17923
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 3455095..21b279d 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -866,8 +866,8 @@ objc_comptypes (tree lhs, tree rhs, int reflexive)
&& TREE_CODE (rhs) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (rhs)) == RECORD_TYPE)
{
- int lhs_is_proto = IS_PROTOCOL_QUALIFIED_ID (lhs);
- int rhs_is_proto = IS_PROTOCOL_QUALIFIED_ID (rhs);
+ int lhs_is_proto = IS_PROTOCOL_QUALIFIED_UNTYPED (lhs);
+ int rhs_is_proto = IS_PROTOCOL_QUALIFIED_UNTYPED (rhs);
if (lhs_is_proto)
{
@@ -878,6 +878,11 @@ objc_comptypes (tree lhs, tree rhs, int reflexive)
/* <Protocol> = <Protocol> */
if (rhs_is_proto)
{
+ /* Class <Protocol> != id <Protocol>;
+ id <Protocol> != Class <Protocol> */
+ if (IS_ID (lhs) != IS_ID (rhs))
+ return 0;
+
rproto_list = TYPE_PROTOCOL_LIST (rhs);
if (!reflexive)
@@ -942,6 +947,10 @@ objc_comptypes (tree lhs, tree rhs, int reflexive)
tree rname = OBJC_TYPE_NAME (TREE_TYPE (rhs));
tree rinter;
+ /* Class <Protocol> != <class> * */
+ if (IS_CLASS (lhs))
+ return 0;
+
/* Make sure the protocol is supported by the object on
the rhs. */
for (lproto = lproto_list; lproto; lproto = TREE_CHAIN (lproto))
@@ -985,15 +994,15 @@ objc_comptypes (tree lhs, tree rhs, int reflexive)
}
return 1;
}
- /* <Protocol> = id */
+ /* id <Protocol> = id; Class <Protocol> = id */
else if (objc_is_object_id (TREE_TYPE (rhs)))
{
return 1;
}
- /* <Protocol> = Class */
+ /* id <Protocol> != Class; Class <Protocol> = Class */
else if (objc_is_class_id (TREE_TYPE (rhs)))
{
- return 0;
+ return IS_CLASS (lhs);
}
/* <Protocol> = ?? : let comptypes decide. */
return -1;
@@ -1003,6 +1012,10 @@ objc_comptypes (tree lhs, tree rhs, int reflexive)
/* <class> * = <Protocol> */
if (TYPED_OBJECT (TREE_TYPE (lhs)))
{
+ /* <class> * != Class <Protocol> */
+ if (IS_CLASS (rhs))
+ return 0;
+
if (reflexive)
{
tree rname = OBJC_TYPE_NAME (TREE_TYPE (lhs));
@@ -1062,15 +1075,15 @@ objc_comptypes (tree lhs, tree rhs, int reflexive)
else
return 0;
}
- /* id = <Protocol> */
+ /* id = id <Protocol>; id = Class <Protocol> */
else if (objc_is_object_id (TREE_TYPE (lhs)))
{
return 1;
}
- /* Class = <Protocol> */
+ /* Class != id <Protocol>; Class = Class <Protocol> */
else if (objc_is_class_id (TREE_TYPE (lhs)))
{
- return 0;
+ return IS_CLASS (rhs);
}
/* ??? = <Protocol> : let comptypes decide */
else
@@ -2714,7 +2727,8 @@ objc_is_id (tree type)
/* NB: This function may be called before the ObjC front-end has
been initialized, in which case OBJC_OBJECT_TYPE will (still) be NULL. */
- return (objc_object_type && type && (IS_ID (type) || IS_CLASS (type))
+ return (objc_object_type && type
+ && (IS_ID (type) || IS_CLASS (type) || IS_SUPER (type))
? type
: NULL_TREE);
}
@@ -5567,25 +5581,35 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params)
{
if (!rtype)
rtype = xref_tag (RECORD_TYPE, class_tree);
- else if (IS_ID (rtype))
+ else
{
+ class_tree = (IS_CLASS (rtype) ? objc_class_name : NULL_TREE);
rprotos = TYPE_PROTOCOL_LIST (rtype);
rtype = NULL_TREE;
}
- else
- {
- class_tree = objc_class_name;
- OBJC_SET_TYPE_NAME (rtype, class_tree);
- }
if (rprotos)
- method_prototype
- = lookup_method_in_protocol_list (rprotos, sel_name,
- class_tree != NULL_TREE);
- if (!method_prototype && !rprotos)
- method_prototype
- = lookup_method_in_hash_lists (sel_name,
- class_tree != NULL_TREE);
+ {
+ /* If messaging 'id <Protos>' or 'Class <Proto>', first search
+ in protocols themselves for the method prototype. */
+ method_prototype
+ = lookup_method_in_protocol_list (rprotos, sel_name,
+ class_tree != NULL_TREE);
+
+ /* If messaging 'Class <Proto>' but did not find a class method
+ prototype, search for an instance method instead, and warn
+ about having done so. */
+ if (!method_prototype && !rtype && class_tree != NULL_TREE)
+ {
+ method_prototype
+ = lookup_method_in_protocol_list (rprotos, sel_name, 0);
+
+ if (method_prototype)
+ warning ("found `-%s' instead of `+%s' in protocol(s)",
+ IDENTIFIER_POINTER (sel_name),
+ IDENTIFIER_POINTER (sel_name));
+ }
+ }
}
else
{
@@ -5642,10 +5666,28 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params)
{
warning ("invalid receiver type `%s'",
gen_type_name (orig_rtype));
+ /* After issuing the "invalid receiver" warning, perform method
+ lookup as if we were messaging 'id'. */
rtype = rprotos = NULL_TREE;
}
}
+
+ /* For 'id' or 'Class' receivers, search in the global hash table
+ as a last resort. For all receivers, warn if protocol searches
+ have failed. */
+ if (!method_prototype)
+ {
+ if (rprotos)
+ warning ("`%c%s' not found in protocol(s)",
+ (class_tree ? '+' : '-'),
+ IDENTIFIER_POINTER (sel_name));
+
+ if (!rtype)
+ method_prototype
+ = lookup_method_in_hash_lists (sel_name, class_tree != NULL_TREE);
+ }
+
if (!method_prototype)
{
static bool warn_missing_methods = false;
@@ -5655,10 +5697,14 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params)
IDENTIFIER_POINTER (OBJC_TYPE_NAME (rtype)),
(class_tree ? '+' : '-'),
IDENTIFIER_POINTER (sel_name));
- if (rprotos)
- warning ("`%c%s' not implemented by protocol(s)",
+ /* If we are messaging an 'id' or 'Class' object and made it here,
+ then we have failed to find _any_ instance or class method,
+ respectively. */
+ else
+ warning ("no `%c%s' method found",
(class_tree ? '+' : '-'),
IDENTIFIER_POINTER (sel_name));
+
if (!warn_missing_methods)
{
warning ("(Messages without a matching method signature");
@@ -6160,13 +6206,16 @@ objc_add_method (tree class, tree method, int is_class)
add_method_to_hash_list (nst_method_hash_list, method);
/* Instance methods in root classes (and categories thereof)
- may acts as class methods as a last resort. */
+ may act as class methods as a last resort. We also add
+ instance methods listed in @protocol declarations to
+ the class hash table, on the assumption that @protocols
+ may be adopted by root classes or categories. */
if (TREE_CODE (class) == CATEGORY_INTERFACE_TYPE
|| TREE_CODE (class) == CATEGORY_IMPLEMENTATION_TYPE)
class = lookup_interface (CLASS_NAME (class));
- if (TREE_CODE (class) != PROTOCOL_INTERFACE_TYPE
- && !CLASS_SUPER_NAME (class))
+ if (TREE_CODE (class) == PROTOCOL_INTERFACE_TYPE
+ || !CLASS_SUPER_NAME (class))
add_method_to_hash_list (cls_method_hash_list, method);
}
diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h
index 52eeb44..d13e374 100644
--- a/gcc/objc/objc-act.h
+++ b/gcc/objc/objc-act.h
@@ -277,8 +277,8 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX];
(POINTER_TYPE_P (TYPE) && TREE_TYPE (TYPE) == TREE_TYPE (objc_object_type))
#define IS_CLASS(TYPE) \
(POINTER_TYPE_P (TYPE) && TREE_TYPE (TYPE) == TREE_TYPE (objc_class_type))
-#define IS_PROTOCOL_QUALIFIED_ID(TYPE) \
- (IS_ID (TYPE) && TYPE_PROTOCOL_LIST (TYPE))
+#define IS_PROTOCOL_QUALIFIED_UNTYPED(TYPE) \
+ ((IS_ID (TYPE) || IS_CLASS (TYPE)) && TYPE_PROTOCOL_LIST (TYPE))
#define IS_SUPER(TYPE) \
(POINTER_TYPE_P (TYPE) && TREE_TYPE (TYPE) == objc_super_template)