Changes for new class parser.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20385 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-11-27 10:56:40 +00:00
parent 1d23eafdf9
commit bc8ec60a05
17 changed files with 1139 additions and 11 deletions

View file

@ -1,3 +1,18 @@
2004-11-27 05:53 Gregory John Casamento <greg_casamento@yahoo.com>
* GormObjCHeaderParser/OCClass.h
* GormObjCHeaderParser/OCClass.m
* GormObjCHeaderParser/NSScanner+OCHeaderParser.h
* GormObjCHeaderParser/NSScanner+OCHeaderParser.m
* GormObjCHeaderParser/OCMethod.h
* GormObjCHeaderParser/OCMethod.m
* GormObjCHeaderParser/OCIVar.h
* GormObjCHeaderParser/OCIVar.m
* GormObjCHeaderParser/OCHeaderParser.h
* GormObjCHeaderParser/OCHeaderParser.m
* GormObjCHeaderParser/GNUmakefile: New files for class parser.
* GormClassManager.m: Changes to use new class parser.
2004-11-24 00:04 Gregory John Casamento <greg_casamento@yahoo.com>
* Palettes/3Containers/GormNSOutlineView.h: Removed savedColor and

View file

@ -38,6 +38,7 @@ include ./Version
SUBPROJECTS = \
GormLib \
Palettes \
GormObjCHeaderParser \
Testing
#

View file

@ -23,6 +23,6 @@
#
# ADDITIONAL_OBJCFLAGS += -Wall -Werror
ADDITIONAL_GUI_LIBS += -lGorm
ADDITIONAL_INCLUDE_DIRS += -IInterfaceBuilder
ADDITIONAL_LIB_DIRS += -LGormLib/$(GNUSTEP_OBJ_DIR)
ADDITIONAL_GUI_LIBS += -lGorm -lGormObjCHeaderParser
ADDITIONAL_INCLUDE_DIRS += -IInterfaceBuilder -IGormObjCHeaderParser
ADDITIONAL_LIB_DIRS += -LGormLib/$(GNUSTEP_OBJ_DIR) -LGormObjCHeaderParser/$(GNUSTEP_OBJ_DIR)

2
Gorm.m
View file

@ -1253,10 +1253,12 @@ static NSImage *testingImage = nil;
NSArray *s = [selectionOwner selection];
// temporarily disabling this functionality....
/*
if (sel_eq(action, @selector(loadClass:)))
{
return NO;
}
*/
if (sel_eq(action, @selector(close:))
|| sel_eq(action, @selector(miniaturize:))

View file

@ -33,6 +33,11 @@
#include <GNUstepBase/GSCategories.h>
#include <Foundation/NSValue.h>
#include <GormObjCHeaderParser/OCHeaderParser.h>
#include <GormObjCHeaderParser/OCClass.h>
#include <GormObjCHeaderParser/OCMethod.h>
#include <GormObjCHeaderParser/OCIVar.h>
/** Private methods not accesible from outside */
@interface GormClassManager (Private)
- (NSMutableDictionary*) classInfoForClassName: (NSString*)className;
@ -1564,13 +1569,54 @@
- (BOOL) parseHeader: (NSString *)headerPath
{
OCHeaderParser *ochp = AUTORELEASE([[OCHeaderParser alloc] initWithContentsOfFile: headerPath]);
BOOL result = NO;
/*
OCHeaderParser *ochp = [[OCHeaderParser alloc] initWithContentsOfFile: headerPath];
NSArray *classes = [ochp ];
NSArray *actions = [ochp actionList];
NSString
*/
if(ochp != nil)
{
result = [ochp parse];
if(result)
{
NSArray *classes = [ochp classes];
NSEnumerator *en = [classes objectEnumerator];
OCClass *cls = nil;
while((cls = (OCClass *)[en nextObject]) != nil)
{
NSArray *methods = [cls methods];
NSArray *ivars = [cls ivars];
NSString *superClass = [cls superClassName];
NSString *className = [cls className];
NSEnumerator *ien = [ivars objectEnumerator];
NSEnumerator *men = [methods objectEnumerator];
OCMethod *method = nil;
OCIVar *ivar = nil;
NSMutableArray *actions = [NSMutableArray array];
NSMutableArray *outlets = [NSMutableArray array];
while((method = (OCMethod *)[men nextObject]) != nil)
{
if([method isAction])
{
[actions addObject: [method name]];
}
}
while((ivar = (OCIVar *)[ien nextObject]) != nil)
{
if([ivar isOutlet])
{
[outlets addObject: [ivar name]];
}
}
[self addClassNamed: className
withSuperClassNamed: superClass
withActions: actions
withOutlets: outlets];
}
}
}
return result;
}

View file

@ -1258,8 +1258,19 @@ static NSImage *fileImage = nil;
types: fileTypes];
if (result == NSOKButton)
{
[classManager parseHeader: [oPanel filename]];
return self;
NSString *fileName = [oPanel filename];
if(![classManager parseHeader: fileName])
{
NSString *message = [NSString stringWithFormat:
_(@"An error occurred while parsing %@"),fileName];
NSRunAlertPanel(_(@"Problem parsing class"),
message,
nil, nil, nil);
}
else
{
return self;
}
}
return nil;

View file

@ -0,0 +1,72 @@
#
# GNUmakefile
# Written by Gregory John Casamento <greg_casamento@yahoo.com>
#
# NOTE: Do NOT change this file -- ProjectCenter maintains it!
#
# Put all of your customisations in GNUmakefile.preamble and
# GNUmakefile.postamble
#
include $(GNUSTEP_MAKEFILES)/common.make
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
#
# Subprojects
#
#
# Library
#
PACKAGE_NAME=GormObjCHeaderParser
LIBRARY_VAR=GMOBJCHEADERPARSER
LIBRARY_NAME=libGormObjCHeaderParser
libGormObjCHeaderParser_HEADER_FILES_DIR=.
libGormObjCHeaderParser_HEADER_FILES_INSTALL_DIR=/GormObjCHeaderParser
ADDITIONAL_INCLUDE_DIRS = -I..
srcdir = .
#
# Additional libraries
#
libGormObjCHeaderParser_LIBRARIES_DEPEND_UPON += -lgnustep-gui -l$(FOUNDATION_LIBRARY_NAME)
#
# Header files
#
libGormObjCHeaderParser_HEADER_FILES= \
OCHeaderParser.h \
OCClass.h \
OCIVar.h \
OCMethod.h \
NSScanner+OCHeaderParser.h
#
# Class files
#
libGormObjCHeaderParser_OBJC_FILES= \
OCHeaderParser.m \
OCClass.m \
OCIVar.m \
OCMethod.m \
NSScanner+OCHeaderParser.m
#
# C files
#
libGormObjCHeaderParser_C_FILES=
HEADERS_INSTALL = $(libGormObjCHeaderParser_HEADER_FILES)
-include GNUmakefile.preamble
-include GNUmakefile.local
include $(GNUSTEP_MAKEFILES)/library.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,40 @@
/* NSScanner+OCHeaderParser.h
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/NSScanner.h>
#ifndef INCLUDED_NSScanner_OCHeaderParser_h
#define INCLUDED_NSScanner_OCHeaderParser_h
@class NSString, NSCharacterSet;
@interface NSScanner (OCHeaderParser)
- (void) scanUpToAndIncludingString: (NSString *)string
intoString: (NSString **)buffer;
- (void) scanUpToAndIncludingCharactersFromSet: (NSCharacterSet *)set
intoString: (NSString **)buffer;
@end
#endif

View file

@ -0,0 +1,54 @@
/* NSScanner+OCHeaderParser.h
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/Foundation.h>
#include <GormObjCHeaderParser/NSScanner+OCHeaderParser.h>
@implementation NSScanner (OCHeaderParser)
- (void) scanUpToAndIncludingString: (NSString *)string
intoString: (NSString **)buffer
{
NSString *buffer2;
[self scanUpToString: string intoString: buffer];
[self scanString: string intoString: &buffer2];
if(buffer != NULL)
{
*buffer = [*buffer stringByAppendingString: buffer2];
}
}
- (void) scanUpToAndIncludingCharactersFromSet: (NSCharacterSet *)set
intoString: (NSString **)buffer
{
NSString *buffer2;
[self scanUpToCharactersFromSet: set intoString: buffer];
[self scanCharactersFromSet: set intoString: &buffer2];
if(buffer != NULL)
{
*buffer = [*buffer stringByAppendingString: buffer2];
}
}
@end

View file

@ -0,0 +1,56 @@
/* OCHeaderParser.h
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/NSObject.h>
#ifndef INCLUDED_OCClass_h
#define INCLUDED_OCClass_h
@class NSMutableArray, NSString;
@interface OCClass : NSObject
{
NSMutableArray *ivars;
NSMutableArray *methods;
NSMutableArray *protocols;
NSString *className;
NSString *superClassName;
NSString *classString;
BOOL isCategory;
}
- (id) initWithString: (NSString *)string;
- (NSArray *) methods;
- (void) addMethod: (NSString *)name isAction: (BOOL) flag;
- (NSArray *) ivars;
- (void) addIVar: (NSString *)name isOutlet: (BOOL) flag;
- (NSString *) className;
- (void) setClassName: (NSString *)name;
- (NSString *) superClassName;
- (void) setSuperClassName: (NSString *)name;
- (BOOL) isCategory;
- (void) setIsCategory: (BOOL)flag;
- (void) parse;
@end
#endif

View file

@ -0,0 +1,206 @@
/* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/NSString.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSScanner.h>
#include <GormObjCHeaderParser/OCClass.h>
#include <GormObjCHeaderParser/OCMethod.h>
#include <GormObjCHeaderParser/OCIVar.h>
#include <GormObjCHeaderParser/NSScanner+OCHeaderParser.h>
@implementation OCClass
- (id) initWithString: (NSString *)string
{
if((self = [super init]) != nil)
{
methods = [[NSMutableArray alloc] init];
ivars = [[NSMutableArray alloc] init];
ASSIGN(classString, string);
}
return self;
}
- (void) dealloc
{
RELEASE(methods);
RELEASE(ivars);
RELEASE(classString);
RELEASE(className);
RELEASE(superClassName);
[super dealloc];
}
- (NSArray *) methods
{
return methods;
}
- (void) addMethod: (NSString *)name isAction: (BOOL) flag
{
OCMethod *method = AUTORELEASE([[OCMethod alloc] init]);
[method setName: name];
[method setIsAction: flag];
[methods addObject: method];
}
- (NSArray *) ivars
{
return ivars;
}
- (void) addIVar: (NSString *)name isOutlet: (BOOL) flag
{
OCIVar *ivar = AUTORELEASE([[OCIVar alloc] init]);
[ivar setName: name];
[ivar setIsOutlet: flag];
[ivars addObject: ivar];
}
- (NSString *) className
{
return className;
}
- (void) setClassName: (NSString *)name
{
ASSIGN(className, name);
}
- (NSString *) superClassName
{
return superClassName;
}
- (void) setSuperClassName: (NSString *)name
{
ASSIGN(superClassName,name);
}
- (BOOL) isCategory
{
return isCategory;
}
- (void) setIsCategory: (BOOL)flag
{
isCategory = flag;
}
- (void) _strip
{
NSString *resultString = nil;
// strip whitespace...
ASSIGN(classString, resultString);
}
- (void) _parseClass
{
NSScanner *scanner = [NSScanner scannerWithString: classString];
NSString *interfaceLine = nil;
[scanner scanUpToString: @"@interface" intoString: NULL]; // look ahead...
[scanner scanUpToString: @"\n" intoString: &interfaceLine];
scanner = [NSScanner scannerWithString: interfaceLine]; // reset scanner...
if(NSEqualRanges([interfaceLine rangeOfString: @":"],NSMakeRange(NSNotFound,0)) == NO)
{
[scanner scanUpToAndIncludingString: @"@interface" intoString: NULL];
[scanner scanUpToString: @":" intoString: &className];
RETAIN(className);
[scanner scanString: @":" intoString: NULL];
[scanner scanUpToString: @" " intoString: &superClassName];
RETAIN(superClassName);
}
else // category...
{
[scanner scanUpToAndIncludingString: @"@interface" intoString: NULL];
[scanner scanUpToString: @" " intoString: &className];
RETAIN(className);
[self setIsCategory: YES];
}
}
- (void) _parseIVars
{
NSScanner *scanner = [NSScanner scannerWithString: classString];
NSString *ivarsString = nil;
// put the ivars into a a string...
[scanner scanUpToAndIncludingString: @"{" intoString: NULL];
[scanner scanUpToString: @"}" intoString: &ivarsString];
[scanner scanString: @"}" intoString: NULL];
// scan each ivar...
scanner = [NSScanner scannerWithString: ivarsString];
while(![scanner isAtEnd])
{
NSString *ivarLine = nil;
OCIVar *ivar = nil;
[scanner scanUpToString: @";" intoString: &ivarLine];
[scanner scanString: @";" intoString: NULL];
ivar = AUTORELEASE([[OCIVar alloc] initWithString: ivarLine]);
[ivar parse];
[ivars addObject: ivar];
}
}
- (void) _parseMethods
{
NSScanner *scanner = [NSScanner scannerWithString: classString];
NSString *methodsString = nil;
// put the methods into a a string...
[scanner scanUpToAndIncludingString: @"{" intoString: NULL];
[scanner scanUpToString: @"}" intoString: NULL];
[scanner scanString: @"}" intoString: NULL];
[scanner scanUpToString: @"@end" intoString: &methodsString];
// scan each method...
scanner = [NSScanner scannerWithString: methodsString];
while(![scanner isAtEnd])
{
NSString *methodLine = nil;
OCMethod *method = nil;
[scanner scanUpToString: @";" intoString: &methodLine];
[scanner scanString: @";" intoString: NULL];
method = AUTORELEASE([[OCMethod alloc] initWithString: methodLine]);
[method parse];
[methods addObject: method];
}
}
- (void) parse
{
// [self _strip];
[self _parseClass];
if([self isCategory] == NO)
{
[self _parseIVars];
}
[self _parseMethods];
}
@end

View file

@ -0,0 +1,43 @@
/* OCHeaderParser.h
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/NSObject.h>
#ifndef INCLUDED_OCHeaderParser_h
#define INCLUDED_OCHeaderParser_h
@class NSMutableArray, NSString;
@interface OCHeaderParser : NSObject
{
NSMutableArray *classes;
NSString *fileData;
}
- (id) initWithContentsOfFile: (NSString *)file;
- (NSMutableArray *)classes;
- (BOOL) parse;
@end
#endif

View file

@ -0,0 +1,168 @@
/* OCHeaderParser.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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/Foundation.h>
#include <GormObjCHeaderParser/OCHeaderParser.h>
#include <GormObjCHeaderParser/OCClass.h>
#include <GormObjCHeaderParser/NSScanner+OCHeaderParser.h>
@implementation OCHeaderParser
+(void) initialize
{
if(self == [OCHeaderParser class])
{
//
}
}
- (id) initWithContentsOfFile: (NSString *)file
{
if((self = [super init]) != nil)
{
fileData = [NSString stringWithContentsOfFile: file];
classes = [[NSMutableArray alloc] init];
RETAIN(fileData);
}
return self;
}
- (void) dealloc
{
RELEASE(classes);
RELEASE(fileData);
[super dealloc];
}
- (NSArray *)classes
{
return classes;
}
- (void) _stripComments
{
NSScanner *scanner = [NSScanner scannerWithString: fileData];
NSString *resultString = [NSString stringWithString: @""];
NSString *finalString = [NSString stringWithString: @""];
// strip all of the one line comments out...
while(![scanner isAtEnd])
{
NSString *tempString = nil;
[scanner scanUpToString: @"//" intoString: &tempString];
[scanner scanUpToAndIncludingString: @"\n" intoString: NULL];
resultString = [resultString stringByAppendingString: tempString];
}
// strip all of the multiline comments out...
scanner = [NSScanner scannerWithString: resultString];
while(![scanner isAtEnd])
{
NSString *tempString = nil;
[scanner scanUpToString: @"/*" intoString: &tempString];
[scanner scanUpToAndIncludingString: @"*/" intoString: NULL];
finalString = [finalString stringByAppendingString: tempString];
}
// make this our new fileData...
ASSIGN(fileData, finalString);
}
- (void) _stripPreProcessor
{
NSScanner *scanner = [NSScanner scannerWithString: fileData];
NSString *resultString = [NSString stringWithString: @""];
// strip all of the one line comments out...
while(![scanner isAtEnd])
{
NSString *tempString = nil;
[scanner scanUpToString: @"#" intoString: &tempString];
[scanner scanUpToAndIncludingString: @"\n" intoString: NULL];
resultString = [resultString stringByAppendingString: tempString];
}
// make this our new fileData...
ASSIGN(fileData,resultString);
}
- (void) _preProcessFile
{
[self _stripComments];
[self _stripPreProcessor];
}
- (BOOL) _processClasses
{
NSScanner *scanner = [NSScanner scannerWithString: fileData];
BOOL result = YES;
NS_DURING
{
// get all of the classes...
while(![scanner isAtEnd])
{
NSString *classString = nil;
OCClass *cls = nil;
[scanner scanUpToString: @"@interface" intoString: NULL];
[scanner scanUpToAndIncludingString: @"@end" intoString: &classString];
cls = AUTORELEASE([[OCClass alloc] initWithString: classString]);
[cls parse];
[classes addObject: cls];
}
}
NS_HANDLER
{
NSLog(@"%@",localException);
result = NO;
}
NS_ENDHANDLER
return result;
}
- (BOOL) parse
{
BOOL result = NO;
[self _preProcessFile];
NS_DURING
{
// parse the header here...
result = [self _processClasses];
}
NS_HANDLER
{
// exception while processing...
NSLog(@"%@",localException);
result = NO;
}
NS_ENDHANDLER
return result;
}
@end

View file

@ -0,0 +1,47 @@
/* OCHeaderParser.h
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/NSObject.h>
#ifndef INCLUDED_OCIVar_h
#define INCLUDED_OCIVar_h
@class NSMutableArray, NSString;
@interface OCIVar : NSObject
{
NSString *name;
BOOL isOutlet;
NSString *ivarString;
}
- (id) initWithString: (NSString *)string;
- (NSString *)name;
- (void) setName: (NSString *)aName;
- (BOOL) isOutlet;
- (void) setIsOutlet: (BOOL)flag;
- (void) parse;
@end
#endif

View file

@ -0,0 +1,107 @@
/* OCHeaderParser.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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/Foundation.h>
#include <GormObjCHeaderParser/OCIVar.h>
#include <GormObjCHeaderParser/NSScanner+OCHeaderParser.h>
@implementation OCIVar
- (id) initWithString: (NSString *)string
{
if((self = [super init]) != nil)
{
ASSIGN(ivarString, string);
}
return self;
}
- (void) dealloc
{
RELEASE(ivarString);
RELEASE(name);
[super dealloc];
}
- (NSString *) name
{
return name;
}
- (void) setName: (NSString *)aName
{
ASSIGN(name,aName);
}
- (BOOL) isOutlet
{
return isOutlet;
}
- (void) setIsOutlet: (BOOL)flag
{
isOutlet = flag;
}
- (void) parse
{
NSRange notFound = NSMakeRange(NSNotFound,0);
NSCharacterSet *wsnl = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSScanner *scanner = [NSScanner scannerWithString: [ivarString stringByTrimmingCharactersInSet: wsnl]];
NSRange range;
NSString *tempName = nil;
if(NSEqualRanges((range = [ivarString rangeOfString: @"IBOutlet"]),notFound) == NO &&
range.location == 0)
{
[scanner scanUpToAndIncludingString: @"IBOutlet" intoString: NULL]; // return type
[scanner scanCharactersFromSet: wsnl intoString: NULL];
[scanner scanUpToCharactersFromSet: wsnl intoString: NULL]; // typespec...
[scanner scanCharactersFromSet: wsnl intoString: NULL];
[scanner scanUpToCharactersFromSet: wsnl intoString: &tempName]; // variable name...
[self setIsOutlet: YES];
}
else if(NSEqualRanges((range = [ivarString rangeOfString: @"id"]),notFound) == NO &&
range.location == 0)
{
[scanner scanUpToCharactersFromSet: wsnl intoString: NULL]; // id
[scanner scanCharactersFromSet: wsnl intoString: NULL];
[scanner scanUpToCharactersFromSet: wsnl intoString: &tempName]; // id
[self setIsOutlet: YES];
}
else // for everything else...
{
[scanner scanUpToCharactersFromSet: wsnl intoString: NULL];
[scanner scanCharactersFromSet: wsnl intoString: NULL];
[scanner scanUpToCharactersFromSet: wsnl intoString: &tempName];
}
// fix name...
scanner = [NSScanner scannerWithString: tempName];
[scanner setCharactersToBeSkipped: [NSCharacterSet characterSetWithCharactersInString: @"*"]];
[scanner scanUpToCharactersFromSet: wsnl intoString: &name];
RETAIN(name);
}
@end

View file

@ -0,0 +1,50 @@
/* OCMethod.h
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/NSObject.h>
#ifndef INCLUDED_OCMethod_h
#define INCLUDED_OCMethod_h
@class NSMutableArray, NSString;
@interface OCMethod : NSObject
{
NSString *name;
NSString *methodString;
BOOL isAction;
BOOL isClassMethod;
}
- (id) initWithString: (NSString *)string;
- (NSString *)name;
- (void) setName: (NSString *)aName;
- (BOOL) isAction;
- (void) setIsAction: (BOOL)flag;
- (BOOL) isClassMethod;
- (void) setIsClassMethod: (BOOL) flag;
- (void) parse;
@end
#endif

View file

@ -0,0 +1,210 @@
/* OCHeaderParser.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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*/
#include <Foundation/Foundation.h>
#include <GormObjCHeaderParser/OCMethod.h>
#include <GormObjCHeaderParser/NSScanner+OCHeaderParser.h>
@implementation OCMethod
- (id) initWithString: (NSString *)string
{
if((self = [super init]) != nil)
{
ASSIGN(methodString, string);
}
return self;
}
- (void) dealloc
{
RELEASE(methodString);
RELEASE(name);
[super dealloc];
}
- (NSString *) name
{
return name;
}
- (void) setName: (NSString *)aName
{
ASSIGN(name,aName);
}
- (BOOL) isAction
{
return isAction;
}
- (void) setIsAction: (BOOL)flag
{
isAction = flag;
}
- (BOOL) isClassMethod
{
return isClassMethod;
}
- (void) setIsClassMethod: (BOOL) flag
{
isClassMethod = flag;
}
- (void) _strip
{
NSScanner *stripScanner = [NSScanner scannerWithString: methodString];
NSString *resultString = [NSString stringWithString: @""];
NSCharacterSet *wsnl = [NSCharacterSet whitespaceAndNewlineCharacterSet];
while(![stripScanner isAtEnd])
{
NSString *string = nil;
[stripScanner scanUpToCharactersFromSet: wsnl intoString: &string];
resultString = [resultString stringByAppendingString: string];
resultString = [resultString stringByAppendingString: @" "];
}
[resultString stringByAppendingString: @"\n"];
ASSIGN(methodString, resultString);
}
- (void) parse
{
NSRange notFound = NSMakeRange(NSNotFound,0);
NSCharacterSet *wsnl = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSScanner *scanner = [NSScanner scannerWithString: [methodString stringByTrimmingCharactersInSet: wsnl]];
NSString *tempSelector = nil;
NSString *selectorPart = nil;
NSString *returnPart = nil;
NSString *argPart = nil;
NSRange range;
[self _strip];
isClassMethod = ([methodString compare: @"+" options: NSLiteralSearch range: NSMakeRange(0,1)] == NSOrderedSame);
if(isClassMethod)
{
[scanner scanString: @"+" intoString: NULL];
[scanner scanCharactersFromSet: wsnl intoString: NULL];
}
else
{
[scanner scanString: @"-" intoString: NULL];
[scanner scanCharactersFromSet: wsnl intoString: NULL];
}
if(NSEqualRanges((range = [methodString rangeOfString: @":"]),notFound) == NO &&
isClassMethod == NO)
{
[scanner scanUpToAndIncludingString: @":" intoString: &tempSelector];
// [scanner scanUpToAndIncludingString: @"\n" intoString: &argPart];
argPart = [methodString substringFromIndex: (range.location + 1)]; // the rest of the line...
if(NSEqualRanges([tempSelector rangeOfString: @"("],notFound) == NO)
{
NSScanner *selScanner = [NSScanner scannerWithString: tempSelector];
[selScanner scanUpToAndIncludingString: @"(" intoString: NULL];
[selScanner scanUpToString: @")" intoString: &returnPart];
[selScanner scanString: @")" intoString: NULL];
[selScanner scanUpToAndIncludingString: @":" intoString: &selectorPart];
if([returnPart isEqual: @"IBAction"] ||
[returnPart isEqual: @"id"] ||
[returnPart isEqual: @"void"])
{
BOOL noMoreArgs = NSEqualRanges([argPart rangeOfString: @":"],notFound);
if(NSEqualRanges([argPart rangeOfString: @"("],notFound) == NO && noMoreArgs)
{
NSString *argType = nil;
NSScanner *argScanner = [NSScanner scannerWithString: argPart];
[argScanner scanUpToAndIncludingString: @"(" intoString: NULL];
[argScanner scanUpToString: @")" intoString: &argType];
[argScanner scanString: @")" intoString: NULL];
if([argType isEqual: @"id"])
{
isAction = YES;
}
}
else if(noMoreArgs)
{
isAction = YES;
}
else
{
selectorPart = [selectorPart stringByAppendingString: argPart];
}
}
ASSIGN(name, selectorPart);
}
else // No return type specified. The default is id, so we must treat it as a potential action...
{
BOOL noMoreArgs = NSEqualRanges([argPart rangeOfString: @":"],notFound);
NSScanner *selScanner = [NSScanner scannerWithString: tempSelector];
[selScanner scanUpToAndIncludingString: @":" intoString: &selectorPart];
if(NSEqualRanges([argPart rangeOfString: @"("],notFound) == NO && noMoreArgs)
{
NSString *argType = nil;
NSScanner *argScanner = [NSScanner scannerWithString: argPart];
[argScanner scanUpToAndIncludingString: @"(" intoString: NULL];
[argScanner scanUpToString: @")" intoString: &argType];
[argScanner scanString: @")" intoString: NULL];
if([argType isEqual: @"id"])
{
isAction = YES;
}
}
else if(noMoreArgs)
{
isAction = YES;
}
else
{
selectorPart = [selectorPart stringByAppendingString: argPart];
}
ASSIGN(name, selectorPart);
}
}
else
{
[scanner scanUpToCharactersFromSet: wsnl intoString: &tempSelector];
if(NSEqualRanges([tempSelector rangeOfString: @"("],notFound) == NO)
{
NSScanner *selScanner = [NSScanner scannerWithString: tempSelector];
[selScanner scanUpToAndIncludingString: @")" intoString: NULL];
[selScanner scanUpToCharactersFromSet: wsnl intoString: &selectorPart];
ASSIGN(name, selectorPart);
}
}
}
@end