--- gcc/objc/Object.m 2018/04/24 18:10:17 1.1.1.1 +++ gcc/objc/Object.m 2018/04/24 18:20:17 1.1.1.3 @@ -1,5 +1,5 @@ /* The implementation of class Object for Objective-C. - Copyright (C) 1993 Free Software Foundation, Inc. + Copyright (C) 1993, 1994 Free Software Foundation, Inc. This file is part of GNU CC. @@ -23,11 +23,11 @@ the Free Software Foundation, 675 Mass A exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ +#include #include "objc/Object.h" #include "objc/Protocol.h" #include "objc/objc-api.h" -#include "gstdarg.h" extern void (*_objc_error)(id object, const char *format, va_list); extern int errno; @@ -116,6 +116,18 @@ extern int errno; return self==anObject; } +- (int)compare:anotherObject; +{ + if ([self isEqual:anotherObject]) + return 0; + // Ordering objects by their address is pretty useless, + // so subclasses should override this is some useful way. + else if (self > anotherObject) + return 1; + else + return -1; +} + - (BOOL)isMetaClass { return NO; @@ -182,12 +194,17 @@ extern int errno; // Indicates if the receiving class or instance conforms to the given protocol // not usually overridden by subclasses -- (BOOL) conformsTo: (Protocol*)aProtocol +// +// Modified 9/5/94 to always search the class object's protocol list, rather +// than the meta class. + ++ (BOOL) conformsTo: (Protocol*)aProtocol { int i; struct objc_protocol_list* proto_list; + id parent; - for (proto_list = isa->protocols; + for (proto_list = ((Class*)self)->protocols; proto_list; proto_list = proto_list->next) { for (i=0; i < proto_list->count; i++) @@ -197,12 +214,17 @@ extern int errno; } } - if ([self superClass]) - return [[self superClass] conformsTo: aProtocol]; + if (parent = [self superClass]) + return [parent conformsTo: aProtocol]; else return NO; } +- (BOOL) conformsTo: (Protocol*)aProtocol +{ + return [[self class] conformsTo:aProtocol]; +} + - (IMP)methodFor:(SEL)aSel { return (method_get_imp(object_is_instance(self) @@ -248,14 +270,14 @@ extern int errno; return (*msg)(self, aSel, anObject1, anObject2); } -- forward:(SEL)aSel :(arglist_t)argFrame +- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame { - return [self doesNotRecognize: aSel]; + return (retval_t)[self doesNotRecognize: aSel]; } -- performv:(SEL)aSel :(arglist_t)argFrame +- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame { - return objc_msg_sendv(self, aSel, method_get_argsize(0), argFrame); + return objc_msg_sendv(self, aSel, argFrame); } + poseAs:(Class*)aClassObject @@ -287,12 +309,22 @@ extern int errno; return [self error:"method %s not implemented", sel_get_name(aSel)]; } +- shouldNotImplement:(SEL)aSel +{ + return [self error:"%s should not implement %s", + object_get_class_name(self), sel_get_name(aSel)]; +} + - doesNotRecognize:(SEL)aSel { return [self error:"%s does not recognize %s", object_get_class_name(self), sel_get_name(aSel)]; } +#ifdef __alpha__ +extern size_t strlen(const char*); +#endif + - error:(const char *)aString, ... { #define FMT "error: %s (%s)\n%s\n" @@ -323,11 +355,9 @@ extern int errno; + (int)streamVersion: (TypedStream*)aStream { -#ifndef __alpha__ if (aStream->mode == OBJC_READONLY) return objc_get_stream_class_version (aStream, self); else -#endif return class_get_version (self); }