1 /* GNU Objective C Runtime messaging declarations
2 Copyright (C) 1993, 1995, 1996, 2004, 2009,
3 2010 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef __objc_message_INCLUDE_GNU
27 #define __objc_message_INCLUDE_GNU
30 #include "objc-decls.h"
36 /* This file includes declarations of the messaging functions and
39 /* Compatibility note: the messaging function is one area where the
40 GNU runtime and the Apple/NeXT runtime differ significantly. If
41 you can, it is recommended that you use higher-level facilities
42 (provided by a Foundation library such as GNUstep Base) to perform
43 forwarding or other advanced messaging tricks. */
45 /* This function returns the IMP (C function implementing a method) to
46 use to invoke the method with selector 'op' of receiver 'receiver'.
48 This is the function used by the compiler when compiling method
49 invocations with the GNU runtime. For example, the method call
51 result = [receiver method];
53 is compiled by the compiler (with the GNU runtime) into the
57 IMP function = objc_msg_lookup (receiver, @selector (method));
58 result = function (receiver, @selector (method));
61 so, a call to objc_msg_lookup() determines the IMP (the C function
62 implementing the method) to call. Then, the function is called.
63 If the method takes or returns different arguments, the compiler
64 will cast 'function' to the right type before invoking it, making
65 sure arguments and return value are handled correctly.
67 objc_msg_lookup() must always return a valid function that can be
68 called with the required method signature (otherwise the
69 compiler-generated code shown above could segfault). If 'receiver'
70 is NULL, objc_msg_lookup() returns a C function that does nothing,
71 ignores all its arguments, and returns NULL (see nil_method.c). If
72 'receiver' does not respond to the selector 'op', objc_msg_lookup()
73 will try to call +resolveClassMethod: or resolveInstanceMethod: as
74 appropriate, and if they return YES, it will try the lookup again
75 (+resolveClassMethod: and +resolveInstanceMethod: can thus install
76 dynamically methods as they are requested). If
77 +resolveClassMethod: or +resolveInstanceMethod: are either not
78 available, or return NO, or return YES but 'receiver' still doesn't
79 implement the 'selector' after calling them, the runtime returns a
80 generic "forwarding" function that can be called with the required
81 method signature and which can process the method invocation
82 according to the forwarding API. There are two runtime hooks that
83 allow Foundation libraries (such as GNUstep-Base) to return their
84 own forwarding function in preference to the runtime ones. When
85 that happens, the Foundation library effectively takes complete
86 control of the forwarding process; any method invocation where the
87 selector is not implemented by the receiver will end up calling a
88 forwarding function chosen by the Foundation library. */
89 objc_EXPORT IMP
objc_msg_lookup (id receiver
, SEL op
);
91 /* Structure used when a message is send to a class's super class.
92 The compiler generates one of these structures and passes it to
93 objc_msg_lookup_super() when a [super method] call is compiled. */
95 /* In the traditional API, the super class field is called 'class' in
96 Objective-C and 'super_class' in Objective-C++. In the new API
97 (objc/runtime.h) it is always called 'super_class'. We detect the
98 "traditional API" by the fact that the objc/objc-api.h header
99 include guards are defined, which means objc/objc-api.h has been
100 included. This works because objc/message.h does not exist in the
101 Traditional API and is only read because objc-api.h itself includes
103 #ifdef __objc_api_INCLUDE_GNU
104 /* Traditional API. */
105 typedef struct objc_super
107 id self
; /* Id of the object sending the message. */
111 Class
class; /* Object's super class. */
118 id self
; /* The receiver of the message. */
119 Class super_class
; /* The superclass of the receiver. */
123 /* This is used by the compiler instead of objc_msg_lookup () when
124 compiling a call to 'super', such as [super method]. This requires
125 sending a message to super->self, but looking up the method as if
126 super->self was in class super->super_class. */
127 objc_EXPORT IMP
objc_msg_lookup_super (struct objc_super
*super
, SEL sel
);
129 /* Hooks for method forwarding. They make it easy to substitute the
130 built-in forwarding with one based on a library, such as ffi, that
131 implement closures, thereby avoiding gcc's __builtin_apply
132 problems. __objc_msg_forward2's result will be preferred over that
133 of __objc_msg_forward if both are set and return non-NULL. */
134 objc_EXPORT
IMP (*__objc_msg_forward
)(SEL
);
135 objc_EXPORT
IMP (*__objc_msg_forward2
)(id
, SEL
);
141 #endif /* not __objc_message_INCLUDE_GNU */