OLD | NEW |
1 //------------------------------------------------------------------------------
--------- | 1 /* |
2 // $Id$ | 2 * Copyright (c) 2009-2015 Erik Doernenburg and contributors |
3 // Copyright (c) 2009 by Mulle Kybernetik. See License file for details. | 3 * |
4 //------------------------------------------------------------------------------
--------- | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 * not use these files except in compliance with the License. You may obtain |
| 6 * a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 * License for the specific language governing permissions and limitations |
| 14 * under the License. |
| 15 */ |
5 | 16 |
6 #import "NSMethodSignature+OCMAdditions.h" | 17 #import "NSMethodSignature+OCMAdditions.h" |
| 18 #import "OCMFunctions.h" |
| 19 #import <objc/runtime.h> |
7 | 20 |
8 | 21 |
9 @implementation NSMethodSignature(OCMAdditions) | 22 @implementation NSMethodSignature(OCMAdditions) |
10 | 23 |
11 - (const char *)methodReturnTypeWithoutQualifiers | 24 - (BOOL)usesSpecialStructureReturn |
12 { | 25 { |
13 » const char *returnType = [self methodReturnType]; | 26 const char *types = OCMTypeWithoutQualifiers([self methodReturnType]); |
14 » while(strchr("rnNoORV", returnType[0]) != NULL) | 27 |
15 » » returnType += 1; | 28 if((types == NULL) || (types[0] != '{')) |
16 » return returnType; | 29 return NO; |
| 30 |
| 31 /* In some cases structures are returned by ref. The rules are complex and d
epend on the |
| 32 architecture, see: |
| 33 |
| 34 http://sealiesoftware.com/blog/archive/2008/10/30/objc_explain_objc_msgSe
nd_stret.html |
| 35 http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conc
eptual/LowLevelABI/000-Introduction/introduction.html |
| 36 https://github.com/atgreen/libffi/blob/master/src/x86/ffi64.c |
| 37 http://www.uclibc.org/docs/psABI-x86_64.pdf |
| 38 http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.
pdf |
| 39 |
| 40 NSMethodSignature knows the details but has no API to return it, though i
t is in |
| 41 the debugDescription. Horribly kludgy. |
| 42 */ |
| 43 NSRange range = [[self debugDescription] rangeOfString:@"is special struct r
eturn? YES"]; |
| 44 return range.length > 0; |
| 45 } |
| 46 |
| 47 - (NSString *)fullTypeString |
| 48 { |
| 49 NSMutableString *typeString = [NSMutableString string]; |
| 50 [typeString appendFormat:@"%s", [self methodReturnType]]; |
| 51 for (NSUInteger i=0; i<[self numberOfArguments]; i++) |
| 52 [typeString appendFormat:@"%s", [self getArgumentTypeAtIndex:i]]; |
| 53 return typeString; |
| 54 } |
| 55 |
| 56 - (const char *)fullObjCTypes |
| 57 { |
| 58 return [[self fullTypeString] UTF8String]; |
17 } | 59 } |
18 | 60 |
19 @end | 61 @end |
OLD | NEW |