2010-09-11 14:38:56 +02:00
|
|
|
/* GNU Objective C Runtime messaging declarations
|
2013-02-03 12:16:21 +01:00
|
|
|
Copyright (C) 1993-2013 Free Software Foundation, Inc.
|
2010-09-11 14:38:56 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-10-17 21:33:19 +02:00
|
|
|
#include "objc.h"
|
|
|
|
#include "objc-decls.h"
|
|
|
|
|
2010-09-11 14:38:56 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-10-09 22:11:02 +02:00
|
|
|
/* This file includes declarations of the messaging functions and
|
2010-12-15 18:43:01 +01:00
|
|
|
types. */
|
2010-10-09 22:11:02 +02:00
|
|
|
|
|
|
|
/* Compatibility note: the messaging function is one area where the
|
|
|
|
GNU runtime and the Apple/NeXT runtime differ significantly. If
|
|
|
|
you can, it is recommended that you use higher-level facilities
|
|
|
|
(provided by a Foundation library such as GNUstep Base) to perform
|
2010-12-15 18:43:01 +01:00
|
|
|
forwarding or other advanced messaging tricks. */
|
|
|
|
|
|
|
|
/* This function returns the IMP (C function implementing a method) to
|
|
|
|
use to invoke the method with selector 'op' of receiver 'receiver'.
|
|
|
|
|
|
|
|
This is the function used by the compiler when compiling method
|
|
|
|
invocations with the GNU runtime. For example, the method call
|
|
|
|
|
|
|
|
result = [receiver method];
|
|
|
|
|
|
|
|
is compiled by the compiler (with the GNU runtime) into the
|
|
|
|
equivalent of:
|
|
|
|
|
|
|
|
{
|
|
|
|
IMP function = objc_msg_lookup (receiver, @selector (method));
|
|
|
|
result = function (receiver, @selector (method));
|
|
|
|
}
|
|
|
|
|
|
|
|
so, a call to objc_msg_lookup() determines the IMP (the C function
|
|
|
|
implementing the method) to call. Then, the function is called.
|
|
|
|
If the method takes or returns different arguments, the compiler
|
|
|
|
will cast 'function' to the right type before invoking it, making
|
|
|
|
sure arguments and return value are handled correctly.
|
|
|
|
|
|
|
|
objc_msg_lookup() must always return a valid function that can be
|
|
|
|
called with the required method signature (otherwise the
|
|
|
|
compiler-generated code shown above could segfault). If 'receiver'
|
|
|
|
is NULL, objc_msg_lookup() returns a C function that does nothing,
|
|
|
|
ignores all its arguments, and returns NULL (see nil_method.c). If
|
|
|
|
'receiver' does not respond to the selector 'op', objc_msg_lookup()
|
|
|
|
will try to call +resolveClassMethod: or resolveInstanceMethod: as
|
|
|
|
appropriate, and if they return YES, it will try the lookup again
|
|
|
|
(+resolveClassMethod: and +resolveInstanceMethod: can thus install
|
|
|
|
dynamically methods as they are requested). If
|
|
|
|
+resolveClassMethod: or +resolveInstanceMethod: are either not
|
|
|
|
available, or return NO, or return YES but 'receiver' still doesn't
|
|
|
|
implement the 'selector' after calling them, the runtime returns a
|
|
|
|
generic "forwarding" function that can be called with the required
|
|
|
|
method signature and which can process the method invocation
|
|
|
|
according to the forwarding API. There are two runtime hooks that
|
|
|
|
allow Foundation libraries (such as GNUstep-Base) to return their
|
|
|
|
own forwarding function in preference to the runtime ones. When
|
|
|
|
that happens, the Foundation library effectively takes complete
|
|
|
|
control of the forwarding process; any method invocation where the
|
|
|
|
selector is not implemented by the receiver will end up calling a
|
|
|
|
forwarding function chosen by the Foundation library. */
|
|
|
|
objc_EXPORT IMP objc_msg_lookup (id receiver, SEL op);
|
|
|
|
|
|
|
|
/* Structure used when a message is send to a class's super class.
|
|
|
|
The compiler generates one of these structures and passes it to
|
|
|
|
objc_msg_lookup_super() when a [super method] call is compiled. */
|
2010-12-15 20:47:18 +01:00
|
|
|
|
|
|
|
/* Modern API. */
|
|
|
|
struct objc_super
|
|
|
|
{
|
|
|
|
id self; /* The receiver of the message. */
|
|
|
|
Class super_class; /* The superclass of the receiver. */
|
|
|
|
};
|
2010-10-09 22:11:02 +02:00
|
|
|
|
2010-12-15 18:43:01 +01:00
|
|
|
/* This is used by the compiler instead of objc_msg_lookup () when
|
|
|
|
compiling a call to 'super', such as [super method]. This requires
|
|
|
|
sending a message to super->self, but looking up the method as if
|
|
|
|
super->self was in class super->super_class. */
|
2010-12-15 20:47:18 +01:00
|
|
|
objc_EXPORT IMP objc_msg_lookup_super (struct objc_super *super, SEL sel);
|
2010-10-09 22:11:02 +02:00
|
|
|
|
2010-12-15 18:43:01 +01:00
|
|
|
/* Hooks for method forwarding. They make it easy to substitute the
|
|
|
|
built-in forwarding with one based on a library, such as ffi, that
|
|
|
|
implement closures, thereby avoiding gcc's __builtin_apply
|
|
|
|
problems. __objc_msg_forward2's result will be preferred over that
|
2010-12-19 17:04:55 +01:00
|
|
|
of __objc_msg_forward if both are set and return non-NULL. */
|
2010-10-09 22:11:02 +02:00
|
|
|
objc_EXPORT IMP (*__objc_msg_forward)(SEL);
|
|
|
|
objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL);
|
2010-09-11 14:38:56 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* not __objc_message_INCLUDE_GNU */
|