2001-12-17 14:31:42 +00:00
|
|
|
/** Implementation of NSMethodSignature for GNUStep
|
1998-08-13 20:45:32 +00:00
|
|
|
Copyright (C) 1994, 1995, 1996, 1998 Free Software Foundation, Inc.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1995-03-12 19:58:48 +00:00
|
|
|
Date: August 1994
|
1998-08-13 20:45:32 +00:00
|
|
|
Rewritten: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Date: August 1998
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-12 19:58:48 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1995-03-12 19:58:48 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2007-09-14 11:36:11 +00:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-03-12 19:58:48 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1995-03-12 19:58:48 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2006-10-20 10:56:27 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSMethodSignature class reference</title>
|
|
|
|
$Date$ $Revision$
|
2005-02-22 11:22:44 +00:00
|
|
|
*/
|
1994-11-08 16:44:01 +00:00
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
#include "config.h"
|
2003-07-31 23:49:32 +00:00
|
|
|
#include "GNUstepBase/preface.h"
|
2004-07-02 08:04:54 +00:00
|
|
|
#include <mframe.h>
|
1998-01-26 14:18:18 +00:00
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
#include "Foundation/NSMethodSignature.h"
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
#include "Foundation/NSString.h"
|
1994-11-08 16:44:01 +00:00
|
|
|
|
1998-04-30 20:11:42 +00:00
|
|
|
|
1994-11-08 16:44:01 +00:00
|
|
|
@implementation NSMethodSignature
|
|
|
|
|
1995-11-06 17:36:48 +00:00
|
|
|
+ (NSMethodSignature*) signatureWithObjCTypes: (const char*)t
|
1994-11-08 16:44:01 +00:00
|
|
|
{
|
2001-04-10 03:27:01 +00:00
|
|
|
NSMethodSignature *newMs;
|
1998-04-30 20:11:42 +00:00
|
|
|
|
2001-04-10 03:27:01 +00:00
|
|
|
if (t == 0 || *t == '\0')
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
newMs = AUTORELEASE([NSMethodSignature alloc]);
|
2005-07-08 11:48:37 +00:00
|
|
|
newMs->_methodTypes = mframe_build_signature(t, (int*)&newMs->_argFrameLength,
|
|
|
|
(int*)&newMs->_numArgs, 0);
|
1998-04-30 20:11:42 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
return newMs;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArgumentInfo) argumentInfoAtIndex: (unsigned)index
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (index >= _numArgs)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Index too high."];
|
1998-02-03 14:20:00 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info == 0)
|
|
|
|
{
|
|
|
|
[self methodInfo];
|
1998-02-03 14:20:00 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
return _info[index+1];
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned) frameLength
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _argFrameLength;
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (const char*) getArgumentTypeAtIndex: (unsigned)index
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (index >= _numArgs)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Index too high."];
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info == 0)
|
|
|
|
{
|
|
|
|
[self methodInfo];
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
return _info[index+1].type;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isOneway
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info == 0)
|
|
|
|
{
|
|
|
|
[self methodInfo];
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
return (_info[0].qual & _F_ONEWAY) ? YES : NO;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned) methodReturnLength
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info == 0)
|
|
|
|
{
|
|
|
|
[self methodInfo];
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
return _info[0].size;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
1998-08-13 20:45:32 +00:00
|
|
|
- (const char*) methodReturnType
|
1994-11-08 16:44:01 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info == 0)
|
|
|
|
{
|
|
|
|
[self methodInfo];
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
return _info[0].type;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned) numberOfArguments
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _numArgs;
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
1995-03-12 19:58:48 +00:00
|
|
|
- (void) dealloc
|
1994-11-08 16:44:01 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_methodTypes)
|
1999-09-28 11:10:34 +00:00
|
|
|
NSZoneFree(NSDefaultMallocZone(), (void*)_methodTypes);
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info)
|
1999-09-28 11:10:34 +00:00
|
|
|
NSZoneFree(NSDefaultMallocZone(), (void*)_info);
|
1999-09-16 07:21:34 +00:00
|
|
|
[super dealloc];
|
1994-11-08 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
2002-05-06 14:42:14 +00:00
|
|
|
- (BOOL)isEqual:(id)other
|
|
|
|
{
|
|
|
|
BOOL isEqual = YES;
|
|
|
|
if (other == nil)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
if (((NSMethodSignature *)other)->isa != isa)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
isEqual = ([self numberOfArguments] == [other numberOfArguments]
|
|
|
|
&& [self frameLength] == [other frameLength]
|
|
|
|
&& *[self methodReturnType] == *[other methodReturnType]
|
2002-05-06 14:42:14 +00:00
|
|
|
&& [self isOneway] == [other isOneway]);
|
2005-02-22 11:22:44 +00:00
|
|
|
if (isEqual == NO)
|
2002-05-06 14:42:14 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
n = [self numberOfArguments];
|
2005-02-22 11:22:44 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2002-05-06 14:42:14 +00:00
|
|
|
{
|
2005-02-22 11:22:44 +00:00
|
|
|
if ((*[self getArgumentTypeAtIndex:i]
|
2002-05-06 14:42:14 +00:00
|
|
|
== *[other getArgumentTypeAtIndex:i]) == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isEqual;
|
|
|
|
}
|
|
|
|
|
1994-11-08 16:44:01 +00:00
|
|
|
@end
|
1998-01-26 14:18:18 +00:00
|
|
|
|
2004-04-16 23:21:26 +00:00
|
|
|
@implementation NSMethodSignature(GNUstep)
|
1998-08-13 20:45:32 +00:00
|
|
|
- (NSArgumentInfo*) methodInfo
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_info == 0)
|
|
|
|
{
|
2004-07-02 08:04:54 +00:00
|
|
|
const char *types = _methodTypes;
|
2003-01-03 20:14:47 +00:00
|
|
|
unsigned int i;
|
1999-09-16 07:21:34 +00:00
|
|
|
|
1999-09-28 11:10:34 +00:00
|
|
|
_info = NSZoneMalloc(NSDefaultMallocZone(),
|
|
|
|
sizeof(NSArgumentInfo)*(_numArgs+1));
|
1999-09-16 07:21:34 +00:00
|
|
|
for (i = 0; i <= _numArgs; i++)
|
|
|
|
{
|
|
|
|
types = mframe_next_arg(types, &_info[i]);
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
return _info;
|
1998-08-13 20:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (const char*) methodType
|
1998-01-26 14:18:18 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _methodTypes;
|
1998-01-26 14:18:18 +00:00
|
|
|
}
|
|
|
|
@end
|