dd3dba526f
In libobjc/: 2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> * Makefile.in (OBJC_H): Removed hash.h and sarray.h. (OBJC_DEPRECATED_H): Likewise. * libobjc.def (objc_hash_new, objc_hash_delete, objc_hash_add, objc_hash_remove, objc_hash_next, objc_hash_value_for_key, objc_hash_is_key_in_hash, hash_add, hash_delete, hash_new, hash_next, hash_remove, hash_value_for_key, hash_is_key_in_hash, sarray_at_put, sarray_at_put_safe, sarray_free, sarray_lazy_copy, sarray_new, sarray_realloc, sarray_remove_garbage): Removed. * objc/sarray.h: Removed. * objc/hash.h: Removed. * objc/deprecated/sarray.h: Removed. * objc/deprecated/hash.h: Removed. * objc/Object.h: Do not include objc/deprecated/hash.h * Object.m: Include string.h. * objc/objc-api.h: Do not include objc/deprecated/hash.h. * objc-private/common.h (GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF): Removed. In gcc/testsuite/: 2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/headers.m: Do not include sarray.h and hash.h. From-SVN: r174610
288 lines
5.7 KiB
Objective-C
288 lines
5.7 KiB
Objective-C
/* The implementation of class Object for Objective-C.
|
|
Copyright (C) 1993, 1994, 1995, 1997, 2002, 2009, 2010
|
|
Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation; either version 3, or (at your option) any
|
|
later version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
License for more details.
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include "objc-private/common.h"
|
|
#include <stdarg.h>
|
|
#include <string.h> /* For strcmp. */
|
|
#include <errno.h>
|
|
#include "objc/Object.h"
|
|
#include "objc/Protocol.h"
|
|
#include "objc/objc-api.h"
|
|
|
|
@implementation Object
|
|
|
|
- (Class)class
|
|
{
|
|
return object_get_class (self);
|
|
}
|
|
|
|
- (BOOL)isEqual: (id)anObject
|
|
{
|
|
return self == anObject;
|
|
}
|
|
|
|
@end
|
|
|
|
/* The following methods were deprecated in GCC 4.6.0 and will be
|
|
removed in the next GCC release. */
|
|
@implementation Object (Deprecated)
|
|
|
|
+ initialize
|
|
{
|
|
return self;
|
|
}
|
|
|
|
- init
|
|
{
|
|
return self;
|
|
}
|
|
|
|
+ new
|
|
{
|
|
return [[self alloc] init];
|
|
}
|
|
|
|
+ alloc
|
|
{
|
|
return class_create_instance(self);
|
|
}
|
|
|
|
- free
|
|
{
|
|
return object_dispose(self);
|
|
}
|
|
|
|
- copy
|
|
{
|
|
return [[self shallowCopy] deepen];
|
|
}
|
|
|
|
- shallowCopy
|
|
{
|
|
return object_copy(self);
|
|
}
|
|
|
|
- deepen
|
|
{
|
|
return self;
|
|
}
|
|
|
|
- deepCopy
|
|
{
|
|
return [self copy];
|
|
}
|
|
|
|
- (Class)superClass
|
|
{
|
|
return object_get_super_class(self);
|
|
}
|
|
|
|
- (MetaClass)metaClass
|
|
{
|
|
return object_get_meta_class(self);
|
|
}
|
|
|
|
- (const char *)name
|
|
{
|
|
return object_get_class_name(self);
|
|
}
|
|
|
|
- self
|
|
{
|
|
return self;
|
|
}
|
|
|
|
- (unsigned int)hash
|
|
{
|
|
return (size_t)self;
|
|
}
|
|
|
|
- (int)compare:(id)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 ((id)self > anotherObject)
|
|
return 1;
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
- (BOOL)isMetaClass
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)isClass
|
|
{
|
|
return object_is_class(self);
|
|
}
|
|
|
|
- (BOOL)isInstance
|
|
{
|
|
return object_is_instance(self);
|
|
}
|
|
|
|
- (BOOL)isKindOf:(Class)aClassObject
|
|
{
|
|
Class class;
|
|
|
|
for (class = self->isa; class!=Nil; class = class_get_super_class(class))
|
|
if (class==aClassObject)
|
|
return YES;
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)isMemberOf:(Class)aClassObject
|
|
{
|
|
return self->isa==aClassObject;
|
|
}
|
|
|
|
- (BOOL)isKindOfClassNamed:(const char *)aClassName
|
|
{
|
|
Class class;
|
|
|
|
if (aClassName!=NULL)
|
|
for (class = self->isa; class!=Nil; class = class_get_super_class(class))
|
|
if (!strcmp(class_get_class_name(class), aClassName))
|
|
return YES;
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)isMemberOfClassNamed:(const char *)aClassName
|
|
{
|
|
return ((aClassName!=NULL)
|
|
&&!strcmp(class_get_class_name(self->isa), aClassName));
|
|
}
|
|
|
|
+ (BOOL)instancesRespondTo:(SEL)aSel
|
|
{
|
|
return class_get_instance_method(self, aSel) != (Method_t)0;
|
|
}
|
|
|
|
- (BOOL)respondsTo:(SEL)aSel
|
|
{
|
|
return ((object_is_instance(self)
|
|
?class_get_instance_method(self->isa, aSel)
|
|
:class_get_class_method(self->isa, aSel)) != (Method_t)0);
|
|
}
|
|
|
|
+ (IMP)instanceMethodFor:(SEL)aSel
|
|
{
|
|
return method_get_imp(class_get_instance_method(self, aSel));
|
|
}
|
|
|
|
// Indicates if the receiving class or instance conforms to the given protocol
|
|
// not usually overridden by subclasses
|
|
//
|
|
// Modified 9/5/94 to always search the class object's protocol list, rather
|
|
// than the meta class.
|
|
|
|
+ (BOOL) conformsTo: (Protocol*)aProtocol
|
|
{
|
|
size_t i;
|
|
struct objc_protocol_list* proto_list;
|
|
id parent;
|
|
|
|
for (proto_list = ((Class)self)->protocols;
|
|
proto_list; proto_list = proto_list->next)
|
|
{
|
|
for (i=0; i < proto_list->count; i++)
|
|
{
|
|
if ([proto_list->list[i] conformsTo: aProtocol])
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
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)
|
|
?class_get_instance_method(self->isa, aSel)
|
|
:class_get_class_method(self->isa, aSel)));
|
|
}
|
|
|
|
+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel
|
|
{
|
|
return ((struct objc_method_description *)
|
|
class_get_instance_method(self, aSel));
|
|
}
|
|
|
|
- (struct objc_method_description *)descriptionForMethod:(SEL)aSel
|
|
{
|
|
return ((struct objc_method_description *)
|
|
(object_is_instance(self)
|
|
?class_get_instance_method(self->isa, aSel)
|
|
:class_get_class_method(self->isa, aSel)));
|
|
}
|
|
|
|
- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame
|
|
{
|
|
return objc_msg_sendv(self, aSel, argFrame);
|
|
}
|
|
|
|
+ poseAs:(Class)aClassObject
|
|
{
|
|
return class_pose_as(self, 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;
|
|
isa = aClassObject;
|
|
return old_isa;
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
+ (int)version
|
|
{
|
|
return class_get_version(self);
|
|
}
|
|
|
|
+ setVersion:(int)aVersion
|
|
{
|
|
class_set_version(self, aVersion);
|
|
return self;
|
|
}
|
|
|
|
@end
|