2004-11-27 10:56:40 +00:00
|
|
|
/* OCClass.m
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
|
|
|
* Date: 1999, 2002
|
|
|
|
*
|
|
|
|
* This file is part of GNUstep.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-11-05 23:44:36 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-11-27 10:56:40 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2019-11-03 01:57:39 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
2004-11-27 10:56:40 +00:00
|
|
|
|
2024-12-22 02:47:10 +00:00
|
|
|
#include "GormObjCHeaderParser/OCClass.h"
|
|
|
|
#include "GormObjCHeaderParser/OCMethod.h"
|
|
|
|
#include "GormObjCHeaderParser/OCProperty.h"
|
|
|
|
#include "GormObjCHeaderParser/OCIVar.h"
|
|
|
|
#include "GormObjCHeaderParser/OCIVarDecl.h"
|
|
|
|
#include "GormObjCHeaderParser/NSScanner+OCHeaderParser.h"
|
|
|
|
#include "GormObjCHeaderParser/ParserFunctions.h"
|
2004-11-27 10:56:40 +00:00
|
|
|
|
|
|
|
@implementation OCClass
|
|
|
|
- (id) initWithString: (NSString *)string
|
|
|
|
{
|
2024-12-08 22:34:43 +00:00
|
|
|
if ((self = [super init]) != nil)
|
2004-11-27 10:56:40 +00:00
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
_methods = [[NSMutableArray alloc] init];
|
|
|
|
_ivars = [[NSMutableArray alloc] init];
|
|
|
|
_properties = [[NSMutableArray alloc] init];
|
|
|
|
_protocols = [[NSMutableArray alloc] init];
|
2024-12-25 07:55:27 +00:00
|
|
|
_superClassName = nil;
|
2024-12-21 06:19:41 +00:00
|
|
|
ASSIGN(_classString, string);
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
RELEASE(_methods);
|
|
|
|
RELEASE(_ivars);
|
|
|
|
RELEASE(_properties);
|
|
|
|
RELEASE(_protocols);
|
|
|
|
RELEASE(_classString);
|
|
|
|
RELEASE(_className);
|
|
|
|
RELEASE(_superClassName);
|
2004-11-27 10:56:40 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) methods
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
return _methods;
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addMethod: (NSString *)name isAction: (BOOL) flag
|
|
|
|
{
|
|
|
|
OCMethod *method = AUTORELEASE([[OCMethod alloc] init]);
|
|
|
|
[method setName: name];
|
|
|
|
[method setIsAction: flag];
|
2024-12-21 06:19:41 +00:00
|
|
|
[_methods addObject: method];
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) ivars
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
return _ivars;
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addIVar: (NSString *)name isOutlet: (BOOL) flag
|
|
|
|
{
|
|
|
|
OCIVar *ivar = AUTORELEASE([[OCIVar alloc] init]);
|
|
|
|
[ivar setName: name];
|
|
|
|
[ivar setIsOutlet: flag];
|
2024-12-21 06:19:41 +00:00
|
|
|
[_ivars addObject: ivar];
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) className
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
return _className;
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setClassName: (NSString *)name
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
ASSIGN(_className, name);
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) superClassName
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
return _superClassName;
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSuperClassName: (NSString *)name
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
ASSIGN(_superClassName,name);
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isCategory
|
|
|
|
{
|
2024-12-22 02:47:10 +00:00
|
|
|
return _isCategory;
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setIsCategory: (BOOL)flag
|
|
|
|
{
|
2024-12-22 02:47:10 +00:00
|
|
|
_isCategory = flag;
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
2024-12-08 19:36:07 +00:00
|
|
|
- (NSArray *) properties
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
return _properties;
|
2024-12-08 19:36:07 +00:00
|
|
|
}
|
|
|
|
|
2004-11-27 10:56:40 +00:00
|
|
|
- (void) _strip
|
|
|
|
{
|
2024-12-21 06:19:41 +00:00
|
|
|
NSScanner *stripScanner = [NSScanner scannerWithString: _classString];
|
2012-04-20 14:34:55 +00:00
|
|
|
NSString *resultString = @"";
|
2004-11-27 20:37:25 +00:00
|
|
|
NSCharacterSet *wsnl = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
|
|
|
|
|
|
|
while(![stripScanner isAtEnd])
|
|
|
|
{
|
|
|
|
NSString *string = nil;
|
|
|
|
[stripScanner scanUpToCharactersFromSet: wsnl intoString: &string];
|
|
|
|
resultString = [resultString stringByAppendingString: string];
|
2024-12-08 22:34:43 +00:00
|
|
|
if (![stripScanner isAtEnd])
|
2004-11-27 20:37:25 +00:00
|
|
|
{
|
|
|
|
resultString = [resultString stringByAppendingString: @" "];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-21 06:19:41 +00:00
|
|
|
ASSIGN(_classString, resultString);
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
|
2004-11-27 14:14:55 +00:00
|
|
|
- (void) parse
|
2004-11-27 10:56:40 +00:00
|
|
|
{
|
2004-11-27 20:37:25 +00:00
|
|
|
NSScanner *scanner = nil;
|
2004-11-27 14:14:55 +00:00
|
|
|
NSScanner *iscan = nil;
|
2004-11-27 10:56:40 +00:00
|
|
|
NSString *interfaceLine = nil;
|
2004-11-27 14:14:55 +00:00
|
|
|
NSString *methodsString = nil;
|
|
|
|
NSString *ivarsString = nil;
|
2004-11-27 18:20:44 +00:00
|
|
|
NSCharacterSet *wsnl = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
2004-11-27 20:37:25 +00:00
|
|
|
NSCharacterSet *pmcs = [NSCharacterSet characterSetWithCharactersInString: @"+-"];
|
|
|
|
|
2004-11-27 18:20:44 +00:00
|
|
|
// get the interface line... look ahead...
|
2004-11-27 20:37:25 +00:00
|
|
|
[self _strip];
|
2024-12-25 10:43:01 +00:00
|
|
|
NSDebugLog(@"_classString = %@", _classString);
|
2024-12-21 06:19:41 +00:00
|
|
|
scanner = [NSScanner scannerWithString: _classString];
|
2024-12-25 07:55:27 +00:00
|
|
|
if (lookAhead(_classString, @"@implementation"))
|
2004-11-27 18:20:44 +00:00
|
|
|
{
|
2024-12-25 07:55:27 +00:00
|
|
|
NSString *cn = nil;
|
|
|
|
|
|
|
|
[scanner scanUpToAndIncludingString: @"@implementation" intoString: NULL];
|
|
|
|
[scanner scanUpToCharactersFromSet: wsnl intoString: &cn];
|
2024-12-21 06:19:41 +00:00
|
|
|
_className = [cn stringByTrimmingCharactersInSet: wsnl];
|
|
|
|
RETAIN(_className);
|
2024-12-25 10:43:01 +00:00
|
|
|
NSDebugLog(@"_className = %@", _className);
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
2024-12-25 07:55:27 +00:00
|
|
|
else
|
2004-11-27 10:56:40 +00:00
|
|
|
{
|
2024-12-25 07:55:27 +00:00
|
|
|
if (lookAhead(_classString, @"{"))
|
2006-09-29 02:28:49 +00:00
|
|
|
{
|
2024-12-25 07:55:27 +00:00
|
|
|
[scanner scanUpToString: @"@interface" intoString: NULL];
|
|
|
|
[scanner scanUpToString: @"{" intoString: &interfaceLine];
|
|
|
|
iscan = [NSScanner scannerWithString: interfaceLine]; // reset scanner...
|
|
|
|
}
|
|
|
|
else // if there is no "{", then there are no ivars...
|
|
|
|
{
|
|
|
|
[scanner scanUpToString: @"@interface" intoString: NULL];
|
|
|
|
[scanner scanUpToCharactersFromSet: pmcs intoString: &interfaceLine];
|
|
|
|
iscan = [NSScanner scannerWithString: interfaceLine]; // reset scanner...
|
2006-09-29 02:28:49 +00:00
|
|
|
}
|
2004-11-27 14:14:55 +00:00
|
|
|
|
2024-12-25 07:55:27 +00:00
|
|
|
// look ahead...
|
|
|
|
if (lookAhead(interfaceLine, @":"))
|
|
|
|
{
|
|
|
|
NSString *cn = nil, *scn = nil;
|
|
|
|
|
|
|
|
[iscan scanUpToAndIncludingString: @"@interface" intoString: NULL];
|
|
|
|
[iscan scanUpToString: @":" intoString: &cn];
|
|
|
|
_className = [cn stringByTrimmingCharactersInSet: wsnl];
|
|
|
|
RETAIN(_className);
|
|
|
|
[iscan scanString: @":" intoString: NULL];
|
|
|
|
[iscan scanUpToCharactersFromSet: wsnl intoString: &scn];
|
|
|
|
[self setSuperClassName: [scn stringByTrimmingCharactersInSet: wsnl]];
|
|
|
|
}
|
|
|
|
else // category...
|
2004-11-27 14:14:55 +00:00
|
|
|
{
|
2024-12-25 07:55:27 +00:00
|
|
|
NSString *cn = nil;
|
|
|
|
|
|
|
|
[iscan scanUpToAndIncludingString: @"@interface" intoString: NULL];
|
|
|
|
[iscan scanUpToCharactersFromSet: wsnl intoString: &cn];
|
|
|
|
_className = [cn stringByTrimmingCharactersInSet: wsnl];
|
|
|
|
RETAIN(_className);
|
|
|
|
|
|
|
|
// check to see if it's a category on an existing interface...
|
|
|
|
if (lookAhead(interfaceLine,@"("))
|
2004-12-03 03:43:24 +00:00
|
|
|
{
|
2024-12-25 07:55:27 +00:00
|
|
|
_isCategory = YES;
|
2004-12-03 03:43:24 +00:00
|
|
|
}
|
2004-11-27 14:14:55 +00:00
|
|
|
}
|
2024-12-25 07:55:27 +00:00
|
|
|
|
|
|
|
if (_isCategory == NO)
|
|
|
|
{
|
|
|
|
NSScanner *ivarScan = nil;
|
|
|
|
|
|
|
|
// put the ivars into a a string...
|
|
|
|
[scanner scanUpToAndIncludingString: @"{" intoString: NULL];
|
|
|
|
[scanner scanUpToString: @"}" intoString: &ivarsString];
|
|
|
|
[scanner scanString: @"}" intoString: NULL];
|
|
|
|
|
|
|
|
if (ivarsString != nil)
|
|
|
|
{
|
|
|
|
// scan each ivar...
|
|
|
|
ivarScan = [NSScanner scannerWithString: ivarsString];
|
|
|
|
while(![ivarScan isAtEnd])
|
|
|
|
{
|
|
|
|
NSString *ivarLine = nil;
|
|
|
|
OCIVarDecl *ivarDecl = nil;
|
|
|
|
|
|
|
|
[ivarScan scanUpToString: @";" intoString: &ivarLine];
|
|
|
|
[ivarScan scanString: @";" intoString: NULL];
|
|
|
|
ivarDecl = AUTORELEASE([[OCIVarDecl alloc] initWithString: ivarLine]);
|
|
|
|
[ivarDecl parse];
|
|
|
|
[_ivars addObjectsFromArray: [ivarDecl ivars]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString *cn = nil;
|
|
|
|
NSScanner *cs = [NSScanner scannerWithString: _classString];
|
2004-12-03 03:43:24 +00:00
|
|
|
|
2024-12-25 07:55:27 +00:00
|
|
|
[cs scanUpToAndIncludingString: @"@interface" intoString: NULL];
|
|
|
|
[cs scanUpToCharactersFromSet: wsnl intoString: &cn];
|
|
|
|
_className = [cn stringByTrimmingCharactersInSet: wsnl];
|
|
|
|
RETAIN(_className);
|
2024-12-25 10:43:01 +00:00
|
|
|
NSDebugLog(@"_className = %@", _className);
|
2024-12-25 07:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// put the methods into a string...
|
|
|
|
if (ivarsString != nil)
|
|
|
|
{
|
|
|
|
[scanner scanUpToString: @"@end" intoString: &methodsString];
|
|
|
|
}
|
|
|
|
else //
|
|
|
|
{
|
|
|
|
scanner = [NSScanner scannerWithString: _classString];
|
|
|
|
[scanner scanUpToAndIncludingString: interfaceLine intoString: NULL];
|
|
|
|
[scanner scanUpToString: @"@end" intoString: &methodsString];
|
|
|
|
}
|
2004-11-27 14:14:55 +00:00
|
|
|
}
|
2024-12-25 07:55:27 +00:00
|
|
|
|
2024-12-22 02:47:10 +00:00
|
|
|
if (_classString != nil)
|
|
|
|
{
|
|
|
|
NSScanner *propertiesScan = [NSScanner scannerWithString: _classString];
|
|
|
|
while ([propertiesScan isAtEnd] == NO)
|
|
|
|
{
|
|
|
|
NSString *propertiesLine = nil;
|
|
|
|
OCProperty *property = nil;
|
|
|
|
|
|
|
|
[propertiesScan scanUpToString: @";" intoString: &propertiesLine];
|
|
|
|
[propertiesScan scanString: @";" intoString: NULL];
|
|
|
|
property = AUTORELEASE([[OCProperty alloc] initWithString: propertiesLine]);
|
|
|
|
[property parse];
|
|
|
|
[_properties addObject: property];
|
|
|
|
}
|
|
|
|
}
|
2004-11-27 14:14:55 +00:00
|
|
|
|
2004-11-27 10:56:40 +00:00
|
|
|
// scan each method...
|
2024-12-08 22:34:43 +00:00
|
|
|
if (methodsString != nil)
|
2004-11-27 10:56:40 +00:00
|
|
|
{
|
2004-12-03 03:43:24 +00:00
|
|
|
NSScanner *methodScan = [NSScanner scannerWithString: methodsString];
|
2024-12-22 02:47:10 +00:00
|
|
|
while ([methodScan isAtEnd] == NO)
|
2004-12-03 03:43:24 +00:00
|
|
|
{
|
|
|
|
NSString *methodLine = nil;
|
|
|
|
OCMethod *method = nil;
|
|
|
|
|
|
|
|
[methodScan scanUpToString: @";" intoString: &methodLine];
|
|
|
|
[methodScan scanString: @";" intoString: NULL];
|
|
|
|
method = AUTORELEASE([[OCMethod alloc] initWithString: methodLine]);
|
|
|
|
[method parse];
|
2024-12-21 06:19:41 +00:00
|
|
|
[_methods addObject: method];
|
2024-12-22 02:47:10 +00:00
|
|
|
}
|
2004-11-27 10:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|