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