136ac495dSmrg /* GNU Objective C Runtime messaging declarations 2*8feb0f0bSmrg Copyright (C) 1993-2020 Free Software Foundation, Inc. 336ac495dSmrg 436ac495dSmrg This file is part of GCC. 536ac495dSmrg 636ac495dSmrg GCC is free software; you can redistribute it and/or modify 736ac495dSmrg it under the terms of the GNU General Public License as published by 836ac495dSmrg the Free Software Foundation; either version 3, or (at your option) 936ac495dSmrg any later version. 1036ac495dSmrg 1136ac495dSmrg GCC is distributed in the hope that it will be useful, 1236ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of 1336ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1436ac495dSmrg GNU General Public License for more details. 1536ac495dSmrg 1636ac495dSmrg Under Section 7 of GPL version 3, you are granted additional 1736ac495dSmrg permissions described in the GCC Runtime Library Exception, version 1836ac495dSmrg 3.1, as published by the Free Software Foundation. 1936ac495dSmrg 2036ac495dSmrg You should have received a copy of the GNU General Public License and 2136ac495dSmrg a copy of the GCC Runtime Library Exception along with this program; 2236ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2336ac495dSmrg <http://www.gnu.org/licenses/>. */ 2436ac495dSmrg 2536ac495dSmrg #ifndef __objc_message_INCLUDE_GNU 2636ac495dSmrg #define __objc_message_INCLUDE_GNU 2736ac495dSmrg 2836ac495dSmrg #include "objc.h" 2936ac495dSmrg #include "objc-decls.h" 3036ac495dSmrg 3136ac495dSmrg #ifdef __cplusplus 3236ac495dSmrg extern "C" { 3336ac495dSmrg #endif 3436ac495dSmrg 3536ac495dSmrg /* This file includes declarations of the messaging functions and 3636ac495dSmrg types. */ 3736ac495dSmrg 3836ac495dSmrg /* Compatibility note: the messaging function is one area where the 3936ac495dSmrg GNU runtime and the Apple/NeXT runtime differ significantly. If 4036ac495dSmrg you can, it is recommended that you use higher-level facilities 4136ac495dSmrg (provided by a Foundation library such as GNUstep Base) to perform 4236ac495dSmrg forwarding or other advanced messaging tricks. */ 4336ac495dSmrg 4436ac495dSmrg /* This function returns the IMP (C function implementing a method) to 4536ac495dSmrg use to invoke the method with selector 'op' of receiver 'receiver'. 4636ac495dSmrg 4736ac495dSmrg This is the function used by the compiler when compiling method 4836ac495dSmrg invocations with the GNU runtime. For example, the method call 4936ac495dSmrg 5036ac495dSmrg result = [receiver method]; 5136ac495dSmrg 5236ac495dSmrg is compiled by the compiler (with the GNU runtime) into the 5336ac495dSmrg equivalent of: 5436ac495dSmrg 5536ac495dSmrg { 5636ac495dSmrg IMP function = objc_msg_lookup (receiver, @selector (method)); 5736ac495dSmrg result = function (receiver, @selector (method)); 5836ac495dSmrg } 5936ac495dSmrg 6036ac495dSmrg so, a call to objc_msg_lookup() determines the IMP (the C function 6136ac495dSmrg implementing the method) to call. Then, the function is called. 6236ac495dSmrg If the method takes or returns different arguments, the compiler 6336ac495dSmrg will cast 'function' to the right type before invoking it, making 6436ac495dSmrg sure arguments and return value are handled correctly. 6536ac495dSmrg 6636ac495dSmrg objc_msg_lookup() must always return a valid function that can be 6736ac495dSmrg called with the required method signature (otherwise the 6836ac495dSmrg compiler-generated code shown above could segfault). If 'receiver' 6936ac495dSmrg is NULL, objc_msg_lookup() returns a C function that does nothing, 7036ac495dSmrg ignores all its arguments, and returns NULL (see nil_method.c). If 7136ac495dSmrg 'receiver' does not respond to the selector 'op', objc_msg_lookup() 7236ac495dSmrg will try to call +resolveClassMethod: or resolveInstanceMethod: as 7336ac495dSmrg appropriate, and if they return YES, it will try the lookup again 7436ac495dSmrg (+resolveClassMethod: and +resolveInstanceMethod: can thus install 7536ac495dSmrg dynamically methods as they are requested). If 7636ac495dSmrg +resolveClassMethod: or +resolveInstanceMethod: are either not 7736ac495dSmrg available, or return NO, or return YES but 'receiver' still doesn't 7836ac495dSmrg implement the 'selector' after calling them, the runtime returns a 7936ac495dSmrg generic "forwarding" function that can be called with the required 8036ac495dSmrg method signature and which can process the method invocation 8136ac495dSmrg according to the forwarding API. There are two runtime hooks that 8236ac495dSmrg allow Foundation libraries (such as GNUstep-Base) to return their 8336ac495dSmrg own forwarding function in preference to the runtime ones. When 8436ac495dSmrg that happens, the Foundation library effectively takes complete 8536ac495dSmrg control of the forwarding process; any method invocation where the 8636ac495dSmrg selector is not implemented by the receiver will end up calling a 8736ac495dSmrg forwarding function chosen by the Foundation library. */ 8836ac495dSmrg objc_EXPORT IMP objc_msg_lookup (id receiver, SEL op); 8936ac495dSmrg 9036ac495dSmrg /* Structure used when a message is send to a class's super class. 9136ac495dSmrg The compiler generates one of these structures and passes it to 9236ac495dSmrg objc_msg_lookup_super() when a [super method] call is compiled. */ 9336ac495dSmrg 9436ac495dSmrg /* Modern API. */ 9536ac495dSmrg struct objc_super 9636ac495dSmrg { 9736ac495dSmrg id self; /* The receiver of the message. */ 9836ac495dSmrg Class super_class; /* The superclass of the receiver. */ 9936ac495dSmrg }; 10036ac495dSmrg 10136ac495dSmrg /* This is used by the compiler instead of objc_msg_lookup () when 10236ac495dSmrg compiling a call to 'super', such as [super method]. This requires 10336ac495dSmrg sending a message to super->self, but looking up the method as if 10436ac495dSmrg super->self was in class super->super_class. */ 10536ac495dSmrg objc_EXPORT IMP objc_msg_lookup_super (struct objc_super *super, SEL sel); 10636ac495dSmrg 10736ac495dSmrg /* Hooks for method forwarding. They make it easy to substitute the 10836ac495dSmrg built-in forwarding with one based on a library, such as ffi, that 10936ac495dSmrg implement closures, thereby avoiding gcc's __builtin_apply 11036ac495dSmrg problems. __objc_msg_forward2's result will be preferred over that 11136ac495dSmrg of __objc_msg_forward if both are set and return non-NULL. */ 11236ac495dSmrg objc_EXPORT IMP (*__objc_msg_forward)(SEL); 11336ac495dSmrg objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL); 11436ac495dSmrg 11536ac495dSmrg #ifdef __cplusplus 11636ac495dSmrg } 11736ac495dSmrg #endif 11836ac495dSmrg 11936ac495dSmrg #endif /* not __objc_message_INCLUDE_GNU */ 120