--- gcc/objc/Object.m 2018/04/24 18:10:17 1.1.1.1 +++ gcc/objc/Object.m 2018/04/24 18:26:53 1.1.1.4 @@ -1,5 +1,5 @@ /* The implementation of class Object for Objective-C. - Copyright (C) 1993 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. This file is part of GNU CC. @@ -15,7 +15,8 @@ License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ /* As a special exception, if you link this library with files compiled with GCC to produce an executable, this does not cause the resulting @@ -23,11 +24,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; @@ -81,17 +82,17 @@ extern int errno; return [self copy]; } -- (Class*)class +- (Class)class { return object_get_class(self); } -- (Class*)superClass +- (Class)superClass { return object_get_super_class(self); } -- (MetaClass*)metaClass +- (MetaClass)metaClass { return object_get_meta_class(self); } @@ -116,6 +117,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; @@ -131,9 +144,9 @@ extern int errno; return object_is_instance(self); } -- (BOOL)isKindOf:(Class*)aClassObject +- (BOOL)isKindOf:(Class)aClassObject { - Class* class; + Class class; for (class = self->isa; class!=Nil; class = class_get_super_class(class)) if (class==aClassObject) @@ -141,14 +154,14 @@ extern int errno; return NO; } -- (BOOL)isMemberOf:(Class*)aClassObject +- (BOOL)isMemberOf:(Class)aClassObject { return self->isa==aClassObject; } - (BOOL)isKindOfClassNamed:(const char *)aClassName { - Class* class; + Class class; if (aClassName!=NULL) for (class = self->isa; class!=Nil; class = class_get_super_class(class)) @@ -182,12 +195,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 +215,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,29 +271,29 @@ 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 ++ poseAs:(Class)aClassObject { return class_pose_as(self, aClassObject); } -- (Class*)transmuteClassTo:(Class*)aClassObject +- (Class)transmuteClassTo:(Class)aClassObject { if (object_is_instance(self)) if (class_is_class(aClassObject)) if (class_get_instance_size(aClassObject)==class_get_instance_size(isa)) if ([self isKindOf:aClassObject]) { - Class* old_isa = isa; + Class old_isa = isa; isa = aClassObject; return old_isa; } @@ -287,12 +310,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 +356,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); }