gcc/libobjc/objc/objc.h

152 lines
6.2 KiB
C
Raw Normal View History

/* Basic data types for Objective C.
Copyright (C) 1993-2015 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/>. */
#ifndef __objc_INCLUDE_GNU
#define __objc_INCLUDE_GNU
/* This file contains the definition of the basic types used by the
Objective-C language. It needs to be included to do almost
anything with Objective-C. */
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
/* The current version of the GNU Objective-C Runtime library in
compressed ISO date format. This should be updated any time a new
version is released with changes to the public API (there is no
need to update it if there were no API changes since the previous
release). This macro is only defined starting with the GNU
Objective-C Runtime shipped with GCC 4.6.0. If it is not defined,
it is either an older version of the runtime, or another runtime. */
#define __GNU_LIBOBJC__ 20110608
/* Definition of the boolean type.
Compatibility note: the Apple/NeXT runtime defines a BOOL as a
'signed char'. The GNU runtime uses an 'unsigned char'.
Important: this could change and we could switch to 'typedef bool
BOOL' in the future. Do not depend on the type of BOOL. */
#undef BOOL
typedef unsigned char BOOL;
#define YES (BOOL)1
#define NO (BOOL)0
/* The basic Objective-C types (SEL, Class, id) are defined as pointer
to opaque structures. The details of the structures are private to
the runtime and may potentially change from one version to the
other. */
/* A SEL (selector) represents an abstract method (in the
object-oriented sense) and includes all the details of how to
invoke the method (which means its name, arguments and return
types) but provides no implementation of its own. You can check
whether a class implements a selector or not, and if you have a
selector and know that the class implements it, you can use it to
call the method for an object in the class. */
typedef const struct objc_selector *SEL;
/* A Class is a class (in the object-oriented sense). In Objective-C
there is the complication that each Class is an object itself, and
so belongs to a class too. This class that a class belongs to is
called its 'meta class'. */
typedef struct objc_class *Class;
objc.h: Updated comments. 2010-10-11 Nicola Pero <nicola.pero@meta-innovation.com> * objc/objc.h: Updated comments. * objc/objc-api.h: (object_copy): Added one argument; use a #define to maintain backwards-compatibility. Moved _objc_object_alloc, _objc_object_copy, _objc_object_dispose and objc_get_uninstalled_dtable into objc/deprecated/objc_get_uninstalled_dtable.h and objc/deprecated/objc_object_alloc.h. Include these files. * objc/deprecated/objc_get_uninstalled_dtable.h: New. * objc/deprecated/objc_object_alloc.h: New. * objc/runtime.h (set_getName): New. (sel_getType): New. (sel_getUid): New. (sel_registerName): New. (sel_registerTypedName): New. (sel_isEqual): New. (class_createInstance): New. (object_copy): New. (object_dispose): New. * objects.c: Do not include tconfig.h. Include gc_typed.h if building the garbage collection version. (__objc_object_alloc): Removed. (__objc_object_copy): Removed. (__objc_object_dispose): Removed. (class_createInstance): New from code in class_create_instance. Cast second argument of GC_malloc_explicitly_typed. Use objc_calloc. Do not call _objc_object_alloc. (class_create_instance): Call class_createInstance. (object_copy): Added extraBytes argument. Do not call _objc_object_copy. (object_dispose): Do not call _objc_object_dispose. * memory.c (objc_free): When using garbage collection, mark the argument as unused. * selector.c (sel_getName): New. (sel_get_name): Call sel_getName. (sel_getType): New. (sel_get_type): Call sel_getType. (sel_registerName): New. (sel_register_name): Call sel_registerName. (sel_registerTypedName): New. (sel_register_typed_name): Call sel_registerTypedName. (sel_getUid): New. (sel_get_uid): Call sel_getUid. From-SVN: r165264
2010-10-11 01:28:12 +02:00
/* An 'id' is an object of an unknown class. The way the object data
is stored inside the object is private and what you see here is
only the beginning of the actual struct. The first field is always
a pointer to the Class that the object belongs to. */
typedef struct objc_object
{
/* 'class_pointer' is the Class that the object belongs to. In case
objc.h: Updated comments. 2010-10-11 Nicola Pero <nicola.pero@meta-innovation.com> * objc/objc.h: Updated comments. * objc/objc-api.h: (object_copy): Added one argument; use a #define to maintain backwards-compatibility. Moved _objc_object_alloc, _objc_object_copy, _objc_object_dispose and objc_get_uninstalled_dtable into objc/deprecated/objc_get_uninstalled_dtable.h and objc/deprecated/objc_object_alloc.h. Include these files. * objc/deprecated/objc_get_uninstalled_dtable.h: New. * objc/deprecated/objc_object_alloc.h: New. * objc/runtime.h (set_getName): New. (sel_getType): New. (sel_getUid): New. (sel_registerName): New. (sel_registerTypedName): New. (sel_isEqual): New. (class_createInstance): New. (object_copy): New. (object_dispose): New. * objects.c: Do not include tconfig.h. Include gc_typed.h if building the garbage collection version. (__objc_object_alloc): Removed. (__objc_object_copy): Removed. (__objc_object_dispose): Removed. (class_createInstance): New from code in class_create_instance. Cast second argument of GC_malloc_explicitly_typed. Use objc_calloc. Do not call _objc_object_alloc. (class_create_instance): Call class_createInstance. (object_copy): Added extraBytes argument. Do not call _objc_object_copy. (object_dispose): Do not call _objc_object_dispose. * memory.c (objc_free): When using garbage collection, mark the argument as unused. * selector.c (sel_getName): New. (sel_get_name): Call sel_getName. (sel_getType): New. (sel_get_type): Call sel_getType. (sel_registerName): New. (sel_register_name): Call sel_registerName. (sel_registerTypedName): New. (sel_register_typed_name): Call sel_registerTypedName. (sel_getUid): New. (sel_get_uid): Call sel_getUid. From-SVN: r165264
2010-10-11 01:28:12 +02:00
of a Class object, this pointer points to the meta class.
Compatibility Note: The Apple/NeXT runtime calls this field
'isa'. To access this field, use object_getClass() from
runtime.h, which is an inline function so does not add any
overhead and is also portable to other runtimes. */
Class class_pointer;
} *id;
/* 'IMP' is a C function that implements a method. When retrieving
the implementation of a method from the runtime, this is the type
of the pointer returned. The idea of the definition of IMP is to
represent a 'pointer to a general function taking an id, a SEL,
followed by other unspecified arguments'. You must always cast an
IMP to a pointer to a function taking the appropriate, specific
types for that function, before calling it - to make sure the
appropriate arguments are passed to it. The code generated by the
compiler to perform method calls automatically does this cast
inside method calls. */
typedef id (*IMP)(id, SEL, ...);
/* 'nil' is the null object. Messages to nil do nothing and always
return 0. */
#define nil (id)0
/* 'Nil' is the null class. Since classes are objects too, this is
actually the same object as 'nil' (and behaves in the same way),
but it has a type of Class, so it is good to use it instead of
'nil' if you are comparing a Class object to nil as it enables the
compiler to do some type-checking. */
#define Nil (Class)0
/* TODO: Move the 'Protocol' declaration into objc/runtime.h. A
Protocol is simply an object, not a basic Objective-C type. The
Apple runtime defines Protocol in objc/runtime.h too, so it's good
to move it there for API compatibility. */
/* A 'Protocol' is a formally defined list of selectors (normally
created using the @protocol Objective-C syntax). It is mostly used
at compile-time to check that classes implement all the methods
that they are supposed to. Protocols are also available in the
runtime system as Protocol objects. */
#ifndef __OBJC__
/* Once we stop including the deprecated struct_objc_protocol.h
there is no reason to even define a 'struct objc_protocol'. As
all the structure details will be hidden, a Protocol basically is
simply an object (as it should be). */
In libobjc/: 2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> In libobjc/: 2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> Removed the Traditional Objective-C runtime public API. * Makefile.in (OBJC_DEPRECATED_H): Variable removed. (install-headers): Do not create the objc/deprecated directory and do not install the deprecated headers. (OBJC_H): Removed encoding.h and objc-api.h. * Object.m: Removed all methods with the exception of -class and -isEqual:. Updated includes. ([-class]): Use Modern API. * objc/Object.h: Do not include deprecated/Object.h. * objc/deprecated/Object.h: Removed. * linking.m (__objc_linking): Call [Object class] instead of [Object name]. * Protocol.m: Removed all methods with the exception of -isEqual:. Updated includes. * objc/Protocol.h: Do not include deprecated/Protocol.h. * objc/deprecated/Protocol.h: Removed. * objc/deprecated/struct_objc_symtab.h: Removed. * objc/deprecated/struct_objc_module.h: Removed. * objc/deprecated/struct_objc_ivar.h: Removed. * objc/deprecated/struct_objc_ivar_list.h: Removed. * objc/deprecated/struct_objc_method.h: Removed. * objc/deprecated/struct_objc_method_list.h: Removed. * objc/deprecated/struct_objc_protocol_list.h: Removed. * objc/deprecated/struct_objc_category.h: Removed. * objc/deprecated/MetaClass.h: Removed. * objc/deprecated/objc_msg_sendv.h: Removed. * objc/deprecated/README: Removed. * objc/deprecated/struct_objc_class.h: Removed. * objc/deprecated/struct_objc_protocol.h: Removed. * objc/deprecated/struct_objc_selector.h: Removed. * objc/encoding.h: Removed. * objc/message.h (struct objc_super): Removed the definition for the Traditional Objective-C runtime API. * objc/objc.h: Do not include objc/objc-decls.h. deprecated/struct_objc_selector.h, deprecated/MetaClass.h, deprecated/struct_objc_class.h, deprecated/struct_objc_protocol.h and deprecated/objc_msg_sendv.h. Uncommented new definition of Protocol *. * objc/objc-api.h: Removed. * objc/runtime.h: Updated comments. Removed check to detect concurrent usage of Traditional and Modern APIs. * objc-private/module-abi-8.h: Always define struct objc_class and struct objc_protocol. (struct objc_protocol_list): Changed type of 'list' argument from 'Protocol *' to 'struct objc_protocol *'. (class_get_instance_size): Added. * objc-private/protocols.h (__objc_protocols_add_protocol): Take a 'struct objc_protocol *' as argument, not a 'Protocol *'. * objc-private/runtime.h: Updated comments. * objc-private/selector.h (struct objc_selector, sel_eq): Added. * class.c: Include objc-private/selector.h. (objc_get_meta_class): Return a Class instead of a MetaClass. * encoding.c (method_get_next_argument): Removed. (method_get_first_argument): Removed. (method_get_nth_argument): Removed. * gc.c: Include objc/runtime.h instead of objc/encoding.h. Include objc-private/module-abi-8.h and ctype.h. * protocols.c (__objc_protocols_add_protocol): Take a 'struct objc_protocl *' as argument, not a 'Protocol *'. (class_addProtocol): Added casts to 'struct objc_protocol *' and 'Protocol *'. (class_copyProtocolList): Likewise. (protocol_conformsToProtocol): Likewise. (protocol_copyProtocolList): Likewise. * sarray.c: Include objc-private/module-abi-8.h. * sendmsg.c (method_get_next_argument): Removed. (method_get_first_argument): Removed. (method_get_nth_argument): Removed. (objc_msg_sendv): Removed. (arglist_t, retval_t): New. (class_get_class_method): Take a 'Class', not 'MetaClass', argument. * thr.c: Include module-abi-8.h. From-SVN: r174765
2011-06-07 21:37:35 +02:00
typedef struct objc_object Protocol;
#else /* __OBJC__ */
@class Protocol;
#endif
/* Compatibility note: the Apple/NeXT runtime defines sel_getName(),
sel_registerName(), object_getClassName(), object_getIndexedIvars()
in this file while the GNU runtime defines them in runtime.h.
The reason the GNU runtime does not define them here is that they
are not basic Objective-C types (defined in this file), but are
part of the runtime API (defined in runtime.h). */
#ifdef __cplusplus
}
#endif
#endif /* not __objc_INCLUDE_GNU */