diff options
author | Nicola Pero <nicola.pero@meta-innovation.com> | 2010-09-11 12:38:56 +0000 |
---|---|---|
committer | Nicola Pero <nicola@gcc.gnu.org> | 2010-09-11 12:38:56 +0000 |
commit | 3d0d87390b1aad25556c927130ef0ec6890439e8 (patch) | |
tree | 34a7ed63e36b5323657af9af9dc423fa5a37dd3e /libobjc | |
parent | f9132eb797d897b8e66b8e8ddb3e8e2744b6ac51 (diff) | |
download | gcc-3d0d87390b1aad25556c927130ef0ec6890439e8.zip gcc-3d0d87390b1aad25556c927130ef0ec6890439e8.tar.gz gcc-3d0d87390b1aad25556c927130ef0ec6890439e8.tar.bz2 |
In libobjc:
* objc/deprecated/struct_objc_selector.h: New file. Definition of
'struct objc_selector' and 'sel_eq' moved here.
* objc/deprecated/struct_objc_protocol.h: New file. Definition of
'struct objc_procotol' moved here.
* objc/deprecated/struct_objc_class.h: New file. Definition of
'struct objc_class' moved here.
* objc/deprecated/MetaClass.h: New file. Definition of MetClass
moved here.
* objc/deprecated/STR.h: New file. Definition of STR moved here.
* objc/message.h: New file. Definitions for relval_t, apply_t,
arglist, arglist_t and objc_msg_lookup were moved here.
* objc/objc.h: Include the above files instead of defining the
corresponding structs, types and functions here. Added new opaque
definitions for SEL and Class. Use Class and not 'struct
objc_class *' in the definition of 'struct objc_object'.
Commented all types defined in the file. Removed special
definition of BOOL as 'int' on __vxworks; use 'unsigned char'
there as well.
* objc/deprecated/objc-unexpected-exception.h: Renamed to
objc_unexpected_exception.h.
* objc/objc-api.h: Updated include of
objc-unexpetected-exception.h
* objc/objc-exception.h: Updated comments.
* Makefile.in (OBJC_H, OBJC_DEPRECATED_H): Added the new header
files. Reindented list of files.
From-SVN: r164212
Diffstat (limited to 'libobjc')
-rw-r--r-- | libobjc/ChangeLog | 28 | ||||
-rw-r--r-- | libobjc/Makefile.in | 30 | ||||
-rw-r--r-- | libobjc/objc/deprecated/MetaClass.h | 1 | ||||
-rw-r--r-- | libobjc/objc/deprecated/STR.h | 2 | ||||
-rw-r--r-- | libobjc/objc/deprecated/objc_unexpected_exception.h (renamed from libobjc/objc/deprecated/objc-unexpected-exception.h) | 0 | ||||
-rw-r--r-- | libobjc/objc/deprecated/struct_objc_class.h | 44 | ||||
-rw-r--r-- | libobjc/objc/deprecated/struct_objc_protocol.h | 6 | ||||
-rw-r--r-- | libobjc/objc/deprecated/struct_objc_selector.h | 20 | ||||
-rw-r--r-- | libobjc/objc/message.h | 52 | ||||
-rw-r--r-- | libobjc/objc/objc-api.h | 2 | ||||
-rw-r--r-- | libobjc/objc/objc-exception.h | 12 | ||||
-rw-r--r-- | libobjc/objc/objc.h | 203 |
12 files changed, 286 insertions, 114 deletions
diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog index 4f9e160..431c7fc 100644 --- a/libobjc/ChangeLog +++ b/libobjc/ChangeLog @@ -1,3 +1,31 @@ +2010-09-11 Nicola Pero <nicola.pero@meta-innovation.com> + + * objc/deprecated/struct_objc_selector.h: New file. Definition of + 'struct objc_selector' and 'sel_eq' moved here. + * objc/deprecated/struct_objc_protocol.h: New file. Definition of + 'struct objc_procotol' moved here. + * objc/deprecated/struct_objc_class.h: New file. Definition of + 'struct objc_class' moved here. + * objc/deprecated/MetaClass.h: New file. Definition of MetClass + moved here. + * objc/deprecated/STR.h: New file. Definition of STR moved here. + * objc/message.h: New file. Definitions for relval_t, apply_t, + arglist, arglist_t and objc_msg_lookup were moved here. + * objc/objc.h: Include the above files instead of defining the + corresponding structs, types and functions here. Added new opaque + definitions for SEL and Class. Use Class and not 'struct + objc_class *' in the definition of 'struct objc_object'. + Commented all types defined in the file. Removed special + definition of BOOL as 'int' on __vxworks; use 'unsigned char' + there as well. + * objc/deprecated/objc-unexpected-exception.h: Renamed to + objc_unexpected_exception.h. + * objc/objc-api.h: Updated include of + objc-unexpetected-exception.h + * objc/objc-exception.h: Updated comments. + * Makefile.in (OBJC_H, OBJC_DEPRECATED_H): Added the new header + files. Reindented list of files. + 2010-09-10 Nicola Pero <nicola.pero@meta-innovation.com> * objc/objc-api.h (objc_trace): Unused variable removed. diff --git a/libobjc/Makefile.in b/libobjc/Makefile.in index a47f7ea..1dfced3 100644 --- a/libobjc/Makefile.in +++ b/libobjc/Makefile.in @@ -143,15 +143,35 @@ all: libobjc$(libsuffix).la $(OBJC_BOEHM_GC) # User-visible header files, from the objc/ directory -OBJC_H = hash.h objc-list.h sarray.h objc.h objc-api.h objc-exception.h \ - NXConstStr.h Object.h Protocol.h encoding.h typedstream.h \ - thr.h objc-decls.h +OBJC_H = \ + objc.h \ + objc-exception.h \ + \ + message.h \ + hash.h \ + objc-list.h \ + sarray.h \ + objc-api.h \ + NXConstStr.h \ + Object.h \ + Protocol.h \ + encoding.h \ + typedstream.h \ + thr.h \ + objc-decls.h # User-visible header files containing deprecated APIs, from the # objc/deprecated directory -OBJC_DEPRECATED_H = Object.h objc-unexpected-exception.h \ - typedstream.h +OBJC_DEPRECATED_H = \ + MetaClass.h \ + Object.h \ + STR.h \ + objc_unexpected_exception.h \ + struct_objc_class.h \ + struct_objc_protocol.h \ + struct_objc_selector.h \ + typedstream.h # Modules that comprise the runtime library. diff --git a/libobjc/objc/deprecated/MetaClass.h b/libobjc/objc/deprecated/MetaClass.h new file mode 100644 index 0000000..0159778 --- /dev/null +++ b/libobjc/objc/deprecated/MetaClass.h @@ -0,0 +1 @@ +typedef struct objc_class *MetaClass; diff --git a/libobjc/objc/deprecated/STR.h b/libobjc/objc/deprecated/STR.h new file mode 100644 index 0000000..17c20e2 --- /dev/null +++ b/libobjc/objc/deprecated/STR.h @@ -0,0 +1,2 @@ +/* Incredibly obsolete. */ +typedef char *STR; /* String alias */ diff --git a/libobjc/objc/deprecated/objc-unexpected-exception.h b/libobjc/objc/deprecated/objc_unexpected_exception.h index 69ffd4e..69ffd4e 100644 --- a/libobjc/objc/deprecated/objc-unexpected-exception.h +++ b/libobjc/objc/deprecated/objc_unexpected_exception.h diff --git a/libobjc/objc/deprecated/struct_objc_class.h b/libobjc/objc/deprecated/struct_objc_class.h new file mode 100644 index 0000000..4918e73 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_class.h @@ -0,0 +1,44 @@ +/* This structure used to be public, but is now private to the runtime. */ + +/* +** The compiler generates one of these structures for each class. +** +** This structure is the definition for classes. +** +** This structure is generated by the compiler in the executable and used by +** the run-time during normal messaging operations. Therefore some members +** change type. The compiler generates "char* const" and places a string in +** the following member variables: super_class. +*/ +struct objc_class { + MetaClass class_pointer; /* Pointer to the class's + meta class. */ + struct objc_class* super_class; /* Pointer to the super + class. NULL for class + Object. */ + const char* name; /* Name of the class. */ + long version; /* Unknown. */ + unsigned long info; /* Bit mask. See class masks + defined above. */ + long instance_size; /* Size in bytes of the class. + The sum of the class + definition and all super + class definitions. */ + struct objc_ivar_list* ivars; /* Pointer to a structure that + describes the instance + variables in the class + definition. NULL indicates + no instance variables. Does + not include super class + variables. */ + struct objc_method_list* methods; /* Linked list of instance + methods defined for the + class. */ + struct sarray * dtable; /* Pointer to instance + method dispatch table. */ + struct objc_class* subclass_list; /* Subclasses */ + struct objc_class* sibling_class; + + struct objc_protocol_list *protocols; /* Protocols conformed to */ + void* gc_object_type; +}; diff --git a/libobjc/objc/deprecated/struct_objc_protocol.h b/libobjc/objc/deprecated/struct_objc_protocol.h new file mode 100644 index 0000000..5344e3f --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_protocol.h @@ -0,0 +1,6 @@ +typedef struct objc_protocol { + struct objc_class* class_pointer; + char *protocol_name; + struct objc_protocol_list *protocol_list; + struct objc_method_description_list *instance_methods, *class_methods; +} Protocol; diff --git a/libobjc/objc/deprecated/struct_objc_selector.h b/libobjc/objc/deprecated/struct_objc_selector.h new file mode 100644 index 0000000..34aaf0d --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_selector.h @@ -0,0 +1,20 @@ +/* This struct used to be public, but is now private to the runtime. */ + +/* +** Definition of a selector. Selectors themselves are not unique, but +** the sel_id is a unique identifier. +*/ +struct objc_selector +{ + void *sel_id; + const char *sel_types; +}; + +inline static BOOL +sel_eq (SEL s1, SEL s2) +{ + if (s1 == 0 || s2 == 0) + return s1 == s2; + else + return s1->sel_id == s2->sel_id; +} diff --git a/libobjc/objc/message.h b/libobjc/objc/message.h new file mode 100644 index 0000000..31ee33b --- /dev/null +++ b/libobjc/objc/message.h @@ -0,0 +1,52 @@ +/* GNU Objective C Runtime messaging declarations + Copyright (C) 1993, 1995, 1996, 2004, 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/>. */ + +#ifndef __objc_message_INCLUDE_GNU +#define __objc_message_INCLUDE_GNU + +#ifdef __cplusplus +extern "C" { +#endif + +#include "objc.h" + +/* This file includes declarations of the messaging functions and types. */ + +typedef void* retval_t; /* return value */ +typedef void(*apply_t)(void); /* function pointer */ +typedef union arglist { + char *arg_ptr; + char arg_regs[sizeof (char*)]; +} *arglist_t; /* argument frame */ + +IMP objc_msg_lookup(id receiver, SEL op); + +/* TODO: Add the remaining messaging declarations from objc-api.h. */ + +#ifdef __cplusplus +} +#endif + +#endif /* not __objc_message_INCLUDE_GNU */ diff --git a/libobjc/objc/objc-api.h b/libobjc/objc/objc-api.h index dd0305f..018a3cc 100644 --- a/libobjc/objc/objc-api.h +++ b/libobjc/objc/objc-api.h @@ -426,7 +426,7 @@ objc_EXPORT void (*_objc_free)(void *); objc_EXPORT IMP (*__objc_msg_forward)(SEL); objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL); -#include "deprecated/objc-unexpected-exception.h" +#include "deprecated/objc_unexpected_exception.h" Method_t class_get_class_method(MetaClass _class, SEL aSel); diff --git a/libobjc/objc/objc-exception.h b/libobjc/objc/objc-exception.h index 715152d..2fb9ba6 100644 --- a/libobjc/objc/objc-exception.h +++ b/libobjc/objc/objc-exception.h @@ -59,9 +59,9 @@ extern "C" { */ void objc_exception_throw (id exception); -/* PS: the Apple runtime seems to also have objc_exception_rethrow(), - objc_begin_catch() and objc_end_catch(). Currently the GNU runtime - does not use them. +/* Compatibility note: the Apple/NeXT runtime seems to also have + objc_exception_rethrow(), objc_begin_catch() and objc_end_catch(). + Currently the GNU runtime does not use them. */ /* The following functions allow customizing to a certain extent the @@ -73,8 +73,8 @@ void objc_exception_throw (id exception); functions unless you are writing your own Foundation library. */ -/* PS: objc_set_exception_preprocessor() (available on the Apple - runtime) is not supported on the GNU runtime. */ +/* Compatibility note: objc_set_exception_preprocessor() (available on + the Apple/NeXT runtime) is not available on the GNU runtime. */ /* An 'objc_exception_matcher' function is used to match an exception to a @catch clause. 'catch_class' is the class of objects caught @@ -106,7 +106,7 @@ objc_uncaught_exception_handler objc_set_uncaught_exception_handler (objc_uncaught_exception_handler new_handler); -/* For compatibility with the Apple runtime. */ +/* For compatibility with the Apple/NeXT runtime. */ #define objc_setExceptionMatcher objc_set_exception_matcher #define objc_setUncaughtExceptionHandler objc_set_uncaught_exception_handler diff --git a/libobjc/objc/objc.h b/libobjc/objc/objc.h index 08f977d..17ae49b 100644 --- a/libobjc/objc/objc.h +++ b/libobjc/objc/objc.h @@ -1,5 +1,6 @@ /* Basic data types for Objective C. - Copyright (C) 1993, 1995, 1996, 2004, 2009 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 2004, 2009, + 2010 Free Software Foundation, Inc. This file is part of GCC. @@ -22,7 +23,6 @@ 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 @@ -33,130 +33,129 @@ extern "C" { #include <stddef.h> /* -** Definition of the boolean type. + 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. */ -#ifdef __vxworks -typedef int BOOL; -#else #undef BOOL typedef unsigned char BOOL; -#endif + #define YES (BOOL)1 #define NO (BOOL)0 -/* -** Definition of a selector. Selectors themselves are not unique, but -** the sel_id is a unique identifier. +/* 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. */ -typedef const struct objc_selector -{ - void *sel_id; - const char *sel_types; -} *SEL; - -inline static BOOL -sel_eq (SEL s1, SEL s2) -{ - if (s1 == 0 || s2 == 0) - return s1 == s2; - else - return s1->sel_id == s2->sel_id; -} - -/* -** ObjC uses this typedef for untyped instances. +/* 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; +#include "deprecated/struct_objc_selector.h" + +/* 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_object { - struct objc_class* class_pointer; +typedef struct objc_class *Class; +#include "deprecated/MetaClass.h" +#include "deprecated/struct_objc_class.h" + +/* An 'id' is an object of an unknown class. The struct objc_object + is private and what you see here is only the beginning of the + struct. In theory, the fact that 'class_pointer' is public means + that if you have any object 'object', you can immediately get its + class by using '((id)object)->class_pointer', but this is not + recommended; you should use object_get_class(object) instead. +*/ +typedef struct objc_object +{ + /* 'class_pointer' is the Class that the object belongs to. In case + of a Class object, this pointer points to the meta class. */ + /* Note that the Apple/NeXT runtime calls this variable 'isa'. + TODO: Decide if we want to call it 'isa' too. TODO: Why not + simply hide this pointer and force users to use the proper API to + get it ? + */ + Class class_pointer; } *id; /* -** Definition of method type. When retrieving the implementation of a -** method, this is 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. + '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, ...); -/* -** More simple types... -*/ -#define nil (id)0 /* id of Nil instance */ -#define Nil (Class)0 /* id of Nil class */ -typedef char *STR; /* String alias */ +/* 'nil' is the null object. Messages to nil do nothing and always + return 0. */ +#define nil (id)0 -/* -** The compiler generates one of these structures for each class. -** -** This structure is the definition for classes. -** -** This structure is generated by the compiler in the executable and used by -** the run-time during normal messaging operations. Therefore some members -** change type. The compiler generates "char* const" and places a string in -** the following member variables: super_class. +/* '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 + +#include "deprecated/STR.h" + +/* 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. */ -typedef struct objc_class *MetaClass; -typedef struct objc_class *Class; -struct objc_class { - MetaClass class_pointer; /* Pointer to the class's - meta class. */ - struct objc_class* super_class; /* Pointer to the super - class. NULL for class - Object. */ - const char* name; /* Name of the class. */ - long version; /* Unknown. */ - unsigned long info; /* Bit mask. See class masks - defined above. */ - long instance_size; /* Size in bytes of the class. - The sum of the class - definition and all super - class definitions. */ - struct objc_ivar_list* ivars; /* Pointer to a structure that - describes the instance - variables in the class - definition. NULL indicates - no instance variables. Does - not include super class - variables. */ - struct objc_method_list* methods; /* Linked list of instance - methods defined for the - class. */ - struct sarray * dtable; /* Pointer to instance - method dispatch table. */ - struct objc_class* subclass_list; /* Subclasses */ - struct objc_class* sibling_class; - - struct objc_protocol_list *protocols; /* Protocols conformed to */ - void* gc_object_type; -}; +/* 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__ -typedef struct objc_protocol { - struct objc_class* class_pointer; - char *protocol_name; - struct objc_protocol_list *protocol_list; - struct objc_method_description_list *instance_methods, *class_methods; -} Protocol; - + /* 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). + */ + /* typedef struct objc_object Protocol; */ + #include "deprecated/struct_objc_protocol.h" #else /* __OBJC__ */ -@class Protocol; + @class Protocol; #endif -typedef void* retval_t; /* return value */ -typedef void(*apply_t)(void); /* function pointer */ -typedef union arglist { - char *arg_ptr; - char arg_regs[sizeof (char*)]; -} *arglist_t; /* argument frame */ +/* Deprecated include - here temporarily, for backwards-compatibility + as reval_t, apply_t, arglist_t and objc_msg_lookup() used to be + defined here. */ +#include "message.h" +/* 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. -IMP objc_msg_lookup(id receiver, SEL op); + 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 } |