annotate libobjc/objc/message.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* GNU Objective C Runtime messaging declarations
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1993-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #ifndef __objc_message_INCLUDE_GNU
kono
parents:
diff changeset
26 #define __objc_message_INCLUDE_GNU
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #include "objc.h"
kono
parents:
diff changeset
29 #include "objc-decls.h"
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 #ifdef __cplusplus
kono
parents:
diff changeset
32 extern "C" {
kono
parents:
diff changeset
33 #endif
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 /* This file includes declarations of the messaging functions and
kono
parents:
diff changeset
36 types. */
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 /* Compatibility note: the messaging function is one area where the
kono
parents:
diff changeset
39 GNU runtime and the Apple/NeXT runtime differ significantly. If
kono
parents:
diff changeset
40 you can, it is recommended that you use higher-level facilities
kono
parents:
diff changeset
41 (provided by a Foundation library such as GNUstep Base) to perform
kono
parents:
diff changeset
42 forwarding or other advanced messaging tricks. */
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* This function returns the IMP (C function implementing a method) to
kono
parents:
diff changeset
45 use to invoke the method with selector 'op' of receiver 'receiver'.
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 This is the function used by the compiler when compiling method
kono
parents:
diff changeset
48 invocations with the GNU runtime. For example, the method call
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 result = [receiver method];
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 is compiled by the compiler (with the GNU runtime) into the
kono
parents:
diff changeset
53 equivalent of:
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 {
kono
parents:
diff changeset
56 IMP function = objc_msg_lookup (receiver, @selector (method));
kono
parents:
diff changeset
57 result = function (receiver, @selector (method));
kono
parents:
diff changeset
58 }
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 so, a call to objc_msg_lookup() determines the IMP (the C function
kono
parents:
diff changeset
61 implementing the method) to call. Then, the function is called.
kono
parents:
diff changeset
62 If the method takes or returns different arguments, the compiler
kono
parents:
diff changeset
63 will cast 'function' to the right type before invoking it, making
kono
parents:
diff changeset
64 sure arguments and return value are handled correctly.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 objc_msg_lookup() must always return a valid function that can be
kono
parents:
diff changeset
67 called with the required method signature (otherwise the
kono
parents:
diff changeset
68 compiler-generated code shown above could segfault). If 'receiver'
kono
parents:
diff changeset
69 is NULL, objc_msg_lookup() returns a C function that does nothing,
kono
parents:
diff changeset
70 ignores all its arguments, and returns NULL (see nil_method.c). If
kono
parents:
diff changeset
71 'receiver' does not respond to the selector 'op', objc_msg_lookup()
kono
parents:
diff changeset
72 will try to call +resolveClassMethod: or resolveInstanceMethod: as
kono
parents:
diff changeset
73 appropriate, and if they return YES, it will try the lookup again
kono
parents:
diff changeset
74 (+resolveClassMethod: and +resolveInstanceMethod: can thus install
kono
parents:
diff changeset
75 dynamically methods as they are requested). If
kono
parents:
diff changeset
76 +resolveClassMethod: or +resolveInstanceMethod: are either not
kono
parents:
diff changeset
77 available, or return NO, or return YES but 'receiver' still doesn't
kono
parents:
diff changeset
78 implement the 'selector' after calling them, the runtime returns a
kono
parents:
diff changeset
79 generic "forwarding" function that can be called with the required
kono
parents:
diff changeset
80 method signature and which can process the method invocation
kono
parents:
diff changeset
81 according to the forwarding API. There are two runtime hooks that
kono
parents:
diff changeset
82 allow Foundation libraries (such as GNUstep-Base) to return their
kono
parents:
diff changeset
83 own forwarding function in preference to the runtime ones. When
kono
parents:
diff changeset
84 that happens, the Foundation library effectively takes complete
kono
parents:
diff changeset
85 control of the forwarding process; any method invocation where the
kono
parents:
diff changeset
86 selector is not implemented by the receiver will end up calling a
kono
parents:
diff changeset
87 forwarding function chosen by the Foundation library. */
kono
parents:
diff changeset
88 objc_EXPORT IMP objc_msg_lookup (id receiver, SEL op);
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* Structure used when a message is send to a class's super class.
kono
parents:
diff changeset
91 The compiler generates one of these structures and passes it to
kono
parents:
diff changeset
92 objc_msg_lookup_super() when a [super method] call is compiled. */
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* Modern API. */
kono
parents:
diff changeset
95 struct objc_super
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 id self; /* The receiver of the message. */
kono
parents:
diff changeset
98 Class super_class; /* The superclass of the receiver. */
kono
parents:
diff changeset
99 };
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* This is used by the compiler instead of objc_msg_lookup () when
kono
parents:
diff changeset
102 compiling a call to 'super', such as [super method]. This requires
kono
parents:
diff changeset
103 sending a message to super->self, but looking up the method as if
kono
parents:
diff changeset
104 super->self was in class super->super_class. */
kono
parents:
diff changeset
105 objc_EXPORT IMP objc_msg_lookup_super (struct objc_super *super, SEL sel);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* Hooks for method forwarding. They make it easy to substitute the
kono
parents:
diff changeset
108 built-in forwarding with one based on a library, such as ffi, that
kono
parents:
diff changeset
109 implement closures, thereby avoiding gcc's __builtin_apply
kono
parents:
diff changeset
110 problems. __objc_msg_forward2's result will be preferred over that
kono
parents:
diff changeset
111 of __objc_msg_forward if both are set and return non-NULL. */
kono
parents:
diff changeset
112 objc_EXPORT IMP (*__objc_msg_forward)(SEL);
kono
parents:
diff changeset
113 objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL);
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 #ifdef __cplusplus
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117 #endif
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 #endif /* not __objc_message_INCLUDE_GNU */