Lots of tidying, removing legacy stuff.
parent
1f7f5cbfab
commit
779b28abeb
@ -1,45 +0,0 @@
|
||||
/* Implementation of the NXConstantString class for Objective-C.
|
||||
Copyright (C) 1995, 2009 Free Software Foundation, Inc.
|
||||
Contributed by Pieter J. Schoenmakers <tiggr@es.ele.tue.nl>
|
||||
|
||||
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/NXConstStr.h"
|
||||
#include "objc/objc-api.h"
|
||||
|
||||
@implementation NXConstantString
|
||||
+ (void)load
|
||||
{
|
||||
__CLS_INFO((Class)self) &= ~_CLS_PLANE_AWARE;
|
||||
}
|
||||
|
||||
-(const char *) cString
|
||||
{
|
||||
return (c_string);
|
||||
} /* -cString */
|
||||
|
||||
-(unsigned int) length
|
||||
{
|
||||
return (len);
|
||||
} /* -length */
|
||||
|
||||
@end
|
||||
@ -1,360 +0,0 @@
|
||||
/* The implementation of class Object for Objective-C.
|
||||
Copyright (C) 1993, 1994, 1995, 1997, 2002, 2009 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 <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include "objc/Object.h"
|
||||
#include "objc/Protocol.h"
|
||||
#include "objc/objc-api.h"
|
||||
|
||||
#define MAX_CLASS_NAME_LEN 256
|
||||
|
||||
@implementation Object
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
__CLS_INFO((Class)self) &= ~_CLS_PLANE_AWARE;
|
||||
}
|
||||
+ initialize
|
||||
{
|
||||
// Object subclasses are not plane aware either.
|
||||
__CLS_INFO((Class)self) &= ~_CLS_PLANE_AWARE;
|
||||
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)class
|
||||
{
|
||||
return object_get_class(self);
|
||||
}
|
||||
|
||||
- (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;
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:anObject
|
||||
{
|
||||
return self==anObject;
|
||||
}
|
||||
|
||||
- (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 class_respondsToSelector(Class, SEL);
|
||||
+ (BOOL)instancesRespondTo:(SEL)aSel
|
||||
{
|
||||
return class_respondsToSelector(self, aSel);
|
||||
}
|
||||
|
||||
- (BOOL)respondsTo:(SEL)aSel
|
||||
{
|
||||
return class_respondsToSelector(isa, aSel);
|
||||
}
|
||||
|
||||
IMP class_getMethodImplementation(Class cls, SEL name);
|
||||
+ (IMP)instanceMethodFor:(SEL)aSel
|
||||
{
|
||||
return class_getMethodImplementation(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 class_getMethodImplementation(isa, aSel);
|
||||
}
|
||||
|
||||
struct objc_method *class_getInstanceMethod(Class aClass, SEL aSelector);
|
||||
+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel
|
||||
{
|
||||
return ((struct objc_method_description *)
|
||||
class_getInstanceMethod(self, aSel));
|
||||
}
|
||||
|
||||
struct objc_method *class_getClassMethod(Class aClass, SEL aSelector);
|
||||
- (struct objc_method_description *)descriptionForMethod:(SEL)aSel
|
||||
{
|
||||
return ((struct objc_method_description *)
|
||||
(object_is_instance(self)
|
||||
?class_getInstanceMethod(self->isa, aSel)
|
||||
:class_getClassMethod(self->isa, aSel)));
|
||||
}
|
||||
|
||||
- perform:(SEL)aSel
|
||||
{
|
||||
IMP msg = objc_msg_lookup(self, aSel);
|
||||
if (!msg)
|
||||
return [self error:"invalid selector passed to %s", sel_get_name(_cmd)];
|
||||
return (*msg)(self, aSel);
|
||||
}
|
||||
|
||||
- perform:(SEL)aSel with:anObject
|
||||
{
|
||||
IMP msg = objc_msg_lookup(self, aSel);
|
||||
if (!msg)
|
||||
return [self error:"invalid selector passed to %s", sel_get_name(_cmd)];
|
||||
return (*msg)(self, aSel, anObject);
|
||||
}
|
||||
|
||||
- perform:(SEL)aSel with:anObject1 with:anObject2
|
||||
{
|
||||
IMP msg = objc_msg_lookup(self, aSel);
|
||||
if (!msg)
|
||||
return [self error:"invalid selector passed to %s", sel_get_name(_cmd)];
|
||||
return (*msg)(self, aSel, anObject1, anObject2);
|
||||
}
|
||||
|
||||
- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame
|
||||
{
|
||||
(void) argFrame; /* UNUSED */
|
||||
return (retval_t)[self doesNotRecognize: 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;
|
||||
}
|
||||
|
||||
- subclassResponsibility:(SEL)aSel
|
||||
{
|
||||
return [self error:"subclass should override %s", sel_get_name(aSel)];
|
||||
}
|
||||
|
||||
- notImplemented:(SEL)aSel
|
||||
{
|
||||
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)];
|
||||
}
|
||||
|
||||
- error:(const char *)aString, ...
|
||||
{
|
||||
#define FMT "error: %s (%s)\n%s\n"
|
||||
char fmt[(strlen((char*)FMT)+strlen((char*)object_get_class_name(self))
|
||||
+((aString!=NULL)?strlen((char*)aString):0)+8)];
|
||||
va_list ap;
|
||||
|
||||
sprintf(fmt, FMT, object_get_class_name(self),
|
||||
object_is_instance(self)?"instance":"class",
|
||||
(aString!=NULL)?aString:"");
|
||||
va_start(ap, aString);
|
||||
objc_verror(self, OBJC_ERR_UNKNOWN, fmt, ap);
|
||||
va_end(ap);
|
||||
return nil;
|
||||
#undef FMT
|
||||
}
|
||||
|
||||
+ (int)version
|
||||
{
|
||||
return class_get_version(self);
|
||||
}
|
||||
|
||||
+ setVersion:(int)aVersion
|
||||
{
|
||||
class_set_version(self, aVersion);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
long objc_get_stream_class_version (TypedStream* stream, Class class)
|
||||
{
|
||||
return class_get_version(class);
|
||||
}
|
||||
@ -1,198 +0,0 @@
|
||||
/* This file contains the implementation of class Protocol.
|
||||
Copyright (C) 1993, 2004, 2009 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/Protocol.h"
|
||||
#include "objc/objc-api.h"
|
||||
|
||||
/* Method description list */
|
||||
struct objc_method_description_list {
|
||||
int count;
|
||||
struct objc_method_description list[1];
|
||||
};
|
||||
|
||||
@interface Protocol2 : Protocol
|
||||
{
|
||||
struct objc_method_description_list *optional_instance_methods, *optional_class_methods;
|
||||
struct objc_property_list *properties, *optional_properties;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation Protocol
|
||||
+ (void)load
|
||||
{
|
||||
__CLS_INFO((Class)self) &= ~_CLS_PLANE_AWARE;
|
||||
}
|
||||
|
||||
/* Obtaining attributes intrinsic to the protocol */
|
||||
|
||||
- (const char *)name
|
||||
{
|
||||
return protocol_name;
|
||||
}
|
||||
|
||||
/* Testing protocol conformance */
|
||||
|
||||
- (BOOL) conformsTo: (Protocol *)aProtocolObject
|
||||
{
|
||||
size_t i;
|
||||
struct objc_protocol_list* proto_list;
|
||||
|
||||
if (aProtocolObject == nil)
|
||||
return NO;
|
||||
|
||||
if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
|
||||
return YES;
|
||||
|
||||
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
|
||||
{
|
||||
for (i=0; i < proto_list->count; i++)
|
||||
{
|
||||
if ([proto_list->list[i] conformsTo: aProtocolObject])
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
/* Looking up information specific to a protocol */
|
||||
|
||||
- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
|
||||
{
|
||||
int i;
|
||||
struct objc_protocol_list* proto_list;
|
||||
const char* name = sel_get_name (aSel);
|
||||
struct objc_method_description *result;
|
||||
|
||||
if (instance_methods)
|
||||
for (i = 0; i < instance_methods->count; i++)
|
||||
{
|
||||
if (!strcmp ((char*)instance_methods->list[i].name, name))
|
||||
return &(instance_methods->list[i]);
|
||||
}
|
||||
|
||||
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
|
||||
{
|
||||
size_t j;
|
||||
for (j=0; j < proto_list->count; j++)
|
||||
{
|
||||
if ((result = [proto_list->list[j]
|
||||
descriptionForInstanceMethod: aSel]))
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
|
||||
{
|
||||
int i;
|
||||
struct objc_protocol_list* proto_list;
|
||||
const char* name = sel_get_name (aSel);
|
||||
struct objc_method_description *result;
|
||||
|
||||
if (class_methods)
|
||||
for (i = 0; i < class_methods->count; i++)
|
||||
{
|
||||
if (!strcmp ((char*)class_methods->list[i].name, name))
|
||||
return &(class_methods->list[i]);
|
||||
}
|
||||
|
||||
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
|
||||
{
|
||||
size_t j;
|
||||
for (j=0; j < proto_list->count; j++)
|
||||
{
|
||||
if ((result = [proto_list->list[j]
|
||||
descriptionForClassMethod: aSel]))
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
/* Compute a hash of the protocol_name; use the same hash algorithm
|
||||
* that we use for class names; protocol names and class names are
|
||||
* somewhat similar types of string spaces.
|
||||
*/
|
||||
int hash = 0, index;
|
||||
|
||||
for (index = 0; protocol_name[index] != '\0'; index++)
|
||||
{
|
||||
hash = (hash << 4) ^ (hash >> 28) ^ protocol_name[index];
|
||||
}
|
||||
|
||||
hash = (hash ^ (hash >> 10) ^ (hash >> 20));
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* Equality between formal protocols is only formal (nothing to do
|
||||
* with actually checking the list of methods they have!). Two formal
|
||||
* Protocols are equal if and only if they have the same name.
|
||||
*
|
||||
* Please note (for comparisons with other implementations) that
|
||||
* checking the names is equivalent to checking that Protocol A
|
||||
* conforms to Protocol B and Protocol B conforms to Protocol A,
|
||||
* because this happens iff they have the same name. If they have
|
||||
* different names, A conforms to B if and only if A includes B, but
|
||||
* the situation where A includes B and B includes A is a circular
|
||||
* dependency between Protocols which is forbidden by the compiler, so
|
||||
* A conforms to B and B conforms to A with A and B having different
|
||||
* names is an impossible case.
|
||||
*/
|
||||
- (BOOL) isEqual: (id)obj
|
||||
{
|
||||
if (obj == self)
|
||||
return YES;
|
||||
|
||||
if ([obj isKindOf: [Protocol class]])
|
||||
{
|
||||
if (strcmp (protocol_name, ((Protocol *)obj)->protocol_name) == 0)
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
/**
|
||||
* Objective-C 2 protocol objects are opaque.
|
||||
*/
|
||||
@implementation Protocol2 @end
|
||||
|
||||
/**
|
||||
* This class exists for the sole reason that the legacy GNU ABI did not
|
||||
* provide a way of registering protocols with the runtime. With the new ABI,
|
||||
* every protocol in a compilation unit that is not referenced should be added
|
||||
* in a category on this class. This ensures that the runtime sees every
|
||||
* protocol at least once and can perform uniquing.
|
||||
*/
|
||||
@interface __ObjC_Protocol_Holder_Ugly_Hack : Object @end
|
||||
@implementation __ObjC_Protocol_Holder_Ugly_Hack @end
|
||||
@ -0,0 +1,36 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
void *valloc(size_t);
|
||||
|
||||
// Stubs that just call the libc implementations when you call these.
|
||||
|
||||
void *objc_malloc(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *objc_atomic_malloc(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *objc_valloc(size_t size)
|
||||
{
|
||||
return valloc(size);
|
||||
}
|
||||
|
||||
void *objc_realloc(void *mem, size_t size)
|
||||
{
|
||||
return realloc(mem, size);
|
||||
}
|
||||
|
||||
void * objc_calloc(size_t nelem, size_t size)
|
||||
{
|
||||
return calloc(nelem, size);
|
||||
}
|
||||
|
||||
void objc_free(void *mem)
|
||||
{
|
||||
free(mem);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue