This is the mail archive of the gcc@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]

Re: RFC: Enhancing ObjC message lookup in the presence of protocols


Ziemowit Laski wrote:

> On 12 Oct 2004, at 9.15, David Ayers wrote:
> 
> 
>>@protocol Proto1
>>- (const char *)name;
>>- (void)set;
>>- (int)compare:(id)obj;
>>- (int)host
>>@end
>>
>>@protocol Proto2
>>- (NSString *)name;
>>- (NSSet *)set;
>>- (BOOL)compare:(id)obj;
>>- (NSString *)host
>>@end
> 
> 
> 
> If we have
> 
>    Class <Proto1, Proto2> cls;

This is not the case I'm worried about.  We had agreed to look at the
case of conflicting prototypes later.  Anything is fine be currently.

> I'll double-check, but I believe my current patch will perform correct 
> method selections for this test case.
> I think I'll collect the code fragments in this e-mail and make a 
> class-protocol-2.m out of it. :-)

Indeed, I'm sorry I misinterpreted your previous example above.  I now
had time to test the patch a bit (I still hope to take a closer look
though.) It is indeed awkward though that (returning to your example):

@protocol Proto
- method1;
+ method2;
@end

Class <Proto1> clsP1;
Class cls;

[clsP1 method1];
/* Will select the correct prototype from the protocol, but ... */
[cls method1];
/* .. won't find any prototype at all! */

because the instance methods for protocols adopted by root classes are
not inserted into the global hash table.

This strangeness becomes obvious when looking at the NSObject protocol
and compare it to the NSObject interface declaration.

@protocol NSObject

- (BOOL)isEqual:(id)object;
- (unsigned)hash;

*- (Class)superclass;
*- (Class)class;
- (id)self;
- (NSZone *)zone;

- (id)performSelector:(SEL)aSelector;
- (id)performSelector:(SEL)aSelector withObject:(id)object;
- (id)performSelector:(SEL)aSelector withObject:(id)object1
withObject:(id)object2;

- (BOOL)isProxy;

- (BOOL)isKindOfClass:(Class)aClass;
- (BOOL)isMemberOfClass:(Class)aClass;
- (BOOL)conformsToProtocol:(Protocol *)aProtocol;

- (BOOL)respondsToSelector:(SEL)aSelector;

- (id)retain;
- (oneway void)release;
- (id)autorelease;
- (unsigned)retainCount;

*- (NSString *)description;

@end

where only the selectors marked with (*) are repeated as class method
declarations of NSObject proper and therefor become part of the class
hash table.

But I can concede to this being viewed as a separate issue if we do not
introduce the concept of "protocols adopted by root classes".  Yet I'd
would be nice to understand your reservations against this concept
better.  In fact it would allow us to do better at selecting the correct
prototype in the presence of conflicting prototypes later.  But anyway,
that isn't the issue I was worried about.

Cheers,
David


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