From 0bcce788f35a5b2964cb9acb97682786377abc2c Mon Sep 17 00:00:00 2001 From: Jonathan Dalrymple Date: Tue, 16 Apr 2019 12:20:14 +0100 Subject: [PATCH] Transitioned to arc --- CoreParse.xcodeproj/project.pbxproj | 10 +- CoreParse/Built In Parsers/CPJSONParser.m | 10 +- CoreParse/Grammar/CPGrammar.h | 2 +- CoreParse/Grammar/CPGrammar.m | 28 ++--- CoreParse/Grammar/CPGrammarInternal.m | 29 ++--- CoreParse/Grammar/CPGrammarSymbol.m | 11 +- CoreParse/Grammar/CPRHSItem.m | 14 +-- CoreParse/Grammar/CPRHSItemResult.h | 2 +- CoreParse/Grammar/CPRHSItemResult.m | 12 +- CoreParse/Grammar/CPRule.h | 4 +- CoreParse/Grammar/CPRule.m | 19 +-- CoreParse/NSArray+Functional.m | 10 +- CoreParse/NSSetFunctional.m | 12 +- CoreParse/Parsers/CPParser.h | 2 +- CoreParse/Parsers/CPParser.m | 9 +- CoreParse/Parsers/CPShiftReduceParser.m | 23 +--- .../Parsers/CPShiftReduceParsers/CPItem.h | 2 +- .../Parsers/CPShiftReduceParsers/CPItem.m | 14 +-- .../CPShiftReduceParsers/CPLALR1Parser.m | 4 +- .../Parsers/CPShiftReduceParsers/CPLR1Item.m | 9 +- .../CPShiftReduceParsers/CPLR1Parser.m | 4 +- .../CPShiftReduceParsers/CPSLRParser.m | 4 +- .../CPShiftReduceAction.m | 116 +++++++++--------- .../CPShiftReduceActionTable.m | 71 +++++------ .../CPShiftReduceGotoTable.m | 45 +++---- .../CPShiftReduceParserProtectedMethods.h | 4 +- .../CPShiftReduceParsers/CPShiftReduceState.h | 2 +- .../CPShiftReduceParsers/CPShiftReduceState.m | 10 +- .../Parsers/Error Recovery/CPRecoveryAction.m | 13 +- CoreParse/Syntax Tree/CPSyntaxTree.m | 13 +- CoreParse/Tokenisation/CPTokenStream.m | 19 +-- CoreParse/Tokenisation/CPTokeniser.h | 18 +-- CoreParse/Tokenisation/CPTokeniser.m | 12 +- .../CPIdentifierRecogniser.m | 16 +-- .../Token Recognisers/CPKeywordRecogniser.h | 4 +- .../Token Recognisers/CPKeywordRecogniser.m | 12 +- .../Token Recognisers/CPNumberRecogniser.m | 6 +- .../Token Recognisers/CPQuotedRecogniser.m | 16 +-- .../Token Recognisers/CPRegexpRecogniser.m | 9 +- .../CPWhiteSpaceRecogniser.m | 2 +- .../Tokenisation/Token Types/CPEOFToken.m | 2 +- .../Tokenisation/Token Types/CPErrorToken.m | 9 +- .../Token Types/CPIdentifierToken.m | 8 +- .../Tokenisation/Token Types/CPKeywordToken.m | 7 +- .../Tokenisation/Token Types/CPNumberToken.m | 7 +- .../Tokenisation/Token Types/CPQuotedToken.m | 11 +- .../Token Types/CPWhiteSpaceToken.m | 9 +- 47 files changed, 224 insertions(+), 451 deletions(-) diff --git a/CoreParse.xcodeproj/project.pbxproj b/CoreParse.xcodeproj/project.pbxproj index 0f7a558..e1b114e 100644 --- a/CoreParse.xcodeproj/project.pbxproj +++ b/CoreParse.xcodeproj/project.pbxproj @@ -1069,9 +1069,9 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.6; + MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; - SDKROOT = ""; + SDKROOT = macosx; SUPPORTED_PLATFORMS = macosx; VALID_ARCHS = "i386 x86_64 armv7 armv7s"; }; @@ -1108,9 +1108,9 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.6; + MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = NO; - SDKROOT = ""; + SDKROOT = macosx; SUPPORTED_PLATFORMS = macosx; VALID_ARCHS = "i386 x86_64 armv7 armv7s"; }; @@ -1120,6 +1120,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -1157,6 +1158,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_COMPATIBILITY_VERSION = 1; diff --git a/CoreParse/Built In Parsers/CPJSONParser.m b/CoreParse/Built In Parsers/CPJSONParser.m index bc2f537..1874950 100644 --- a/CoreParse/Built In Parsers/CPJSONParser.m +++ b/CoreParse/Built In Parsers/CPJSONParser.m @@ -99,21 +99,13 @@ - (id)init @"15 boolean ::= 'true';" @"16 boolean ::= 'false';" error:NULL]; - jsonParser = [[CPSLRParser parserWithGrammar:jsonGrammar] retain]; + jsonParser = [CPSLRParser parserWithGrammar:jsonGrammar]; [jsonParser setDelegate:self]; } return self; } -- (void)dealloc -{ - [jsonTokeniser release]; - [jsonParser release]; - - [super dealloc]; -} - - (id)parse:(NSString *)json { CPTokenStream *tokenStream = [jsonTokeniser tokenise:json]; diff --git a/CoreParse/Grammar/CPGrammar.h b/CoreParse/Grammar/CPGrammar.h index bcd32c7..285b356 100644 --- a/CoreParse/Grammar/CPGrammar.h +++ b/CoreParse/Grammar/CPGrammar.h @@ -220,6 +220,6 @@ typedef enum /** * The starting symbol for the grammar. */ -@property (readwrite,retain) NSString *start; +@property (readwrite,strong) NSString *start; @end diff --git a/CoreParse/Grammar/CPGrammar.m b/CoreParse/Grammar/CPGrammar.m index 048fba3..731ed2d 100644 --- a/CoreParse/Grammar/CPGrammar.m +++ b/CoreParse/Grammar/CPGrammar.m @@ -35,7 +35,7 @@ @interface CPBNFParserDelegate : NSObject -@property (readwrite, retain, nonatomic) NSError *err; +@property (readwrite, strong, nonatomic) NSError *err; @end @@ -114,7 +114,7 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree } else { - CPRHSItem *newI = [[[CPRHSItem alloc] init] autorelease]; + CPRHSItem *newI = [[CPRHSItem alloc] init]; [newI setAlternatives:[NSArray arrayWithObject:[NSArray arrayWithObject:i]]]; [newI setRepeats:NO]; [newI setMayNotExist:NO]; @@ -127,7 +127,7 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree return [children objectAtIndex:0]; case 13: { - CPRHSItem *i = [[[CPRHSItem alloc] init] autorelease]; + CPRHSItem *i = [[CPRHSItem alloc] init]; [i setAlternatives:[NSArray arrayWithObject:[NSArray arrayWithObject:[children objectAtIndex:0]]]]; NSString *symbol = [(CPKeywordToken *)[children objectAtIndex:1] keyword]; if ([symbol isEqualToString:@"*"]) @@ -151,7 +151,7 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree return [children objectAtIndex:0]; case 15: { - CPRHSItem *i = [[[CPRHSItem alloc] init] autorelease]; + CPRHSItem *i = [[CPRHSItem alloc] init]; [i setAlternatives:[children objectAtIndex:1]]; [i setRepeats:NO]; [i setMayNotExist:NO]; @@ -206,7 +206,7 @@ @implementation CPGrammar + (id)grammarWithStart:(NSString *)start rules:(NSArray *)rules { - return [[[self alloc] initWithStart:start rules:rules] autorelease]; + return [[self alloc] initWithStart:start rules:rules]; } - (id)initWithStart:(NSString *)initStart rules:(NSArray *)initRules; @@ -225,12 +225,12 @@ - (id)initWithStart:(NSString *)initStart rules:(NSArray *)initRules; + (id)grammarWithStart:(NSString *)start backusNaurForm:(NSString *)bnf { - return [[[self alloc] initWithStart:start backusNaurForm:bnf] autorelease]; + return [[self alloc] initWithStart:start backusNaurForm:bnf]; } + (id)grammarWithStart:(NSString *)start backusNaurForm:(NSString *)bnf error:(NSError **)error { - return [[[self alloc] initWithStart:start backusNaurForm:bnf error:error] autorelease]; + return [[self alloc] initWithStart:start backusNaurForm:bnf error:error]; } - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf @@ -247,8 +247,8 @@ - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf error:(NSError **)error { - CPBNFParserDelegate *del = [[[CPBNFParserDelegate alloc] init] autorelease]; - CPTokeniser *tokeniser = [[[CPTokeniser alloc] init] autorelease]; + CPBNFParserDelegate *del = [[CPBNFParserDelegate alloc] init]; + CPTokeniser *tokeniser = [[CPTokeniser alloc] init]; [tokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"::="]]; [tokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"@"]]; [tokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"<"]]; @@ -313,9 +313,8 @@ - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf error:( { if (NULL != error) { - *error = [[[del err] copy] autorelease]; + *error = [[del err] copy]; } - [self release]; return nil; } @@ -326,14 +325,12 @@ - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf error:( { *error = e; } - [self release]; return nil; } NSArray *newRules = [self tidyRightHandSides:initRules error:error]; if (nil == newRules) { - [self release]; return nil; } @@ -369,10 +366,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder - (void)dealloc { - [start release]; [self setRules:nil]; - - [super dealloc]; } - (NSSet *)allRules @@ -405,7 +399,7 @@ - (NSError *)checkForMissingNonTerminalsInRules:(NSArray *)rules NSSet *usedNonTerminals = [(CPRHSItem *)item nonTerminalsUsed]; if (![usedNonTerminals isSubsetOfSet:definedNonTerminals]) { - NSMutableSet *mutableUsedNonTerminals = [[usedNonTerminals mutableCopy] autorelease]; + NSMutableSet *mutableUsedNonTerminals = [usedNonTerminals mutableCopy]; [mutableUsedNonTerminals minusSet:definedNonTerminals]; return [NSError errorWithDomain:CPEBNFParserErrorDomain code:CPErrorCodeUndefinedNonTerminal diff --git a/CoreParse/Grammar/CPGrammarInternal.m b/CoreParse/Grammar/CPGrammarInternal.m index fcd8ea4..2ac5f8a 100644 --- a/CoreParse/Grammar/CPGrammarInternal.m +++ b/CoreParse/Grammar/CPGrammarInternal.m @@ -24,9 +24,8 @@ @implementation CPGrammar (CPGrammarInternal) - (CPGrammar *)augmentedGrammar { - return [[[CPGrammar alloc] initWithStart:@"s'" - rules:[[self rules] arrayByAddingObject:[CPRule ruleWithName:@"s'" rightHandSideElements:[NSArray arrayWithObject:[CPGrammarSymbol nonTerminalWithName:[self start]]]]]] - autorelease]; + return [[CPGrammar alloc] initWithStart:@"s'" + rules:[[self rules] arrayByAddingObject:[CPRule ruleWithName:@"s'" rightHandSideElements:[NSArray arrayWithObject:[CPGrammarSymbol nonTerminalWithName:[self start]]]]]]; } - (NSUInteger)indexOfRule:(CPRule *)rule @@ -73,9 +72,8 @@ - (NSSet *)lr0Closure:(NSSet *)i [processingQueue removeObjectAtIndex:0]; } - [processingQueue release]; - return [j autorelease]; + return j; } - (NSSet *)lr0GotoKernelWithItems:(NSSet *)i symbol:(CPGrammarSymbol *)symbol @@ -152,9 +150,8 @@ - (NSSet *)lr1Closure:(NSSet *)i [processingQueue removeObjectAtIndex:0]; } - [processingQueue release]; - return [j autorelease]; + return j; } - (NSSet *)lr1GotoKernelWithItems:(NSSet *)i symbol:(CPGrammarSymbol *)symbol @@ -232,7 +229,7 @@ - (NSString *)uniqueSymbolNameBasedOnName:(NSString *)name - (NSString *)symbolNameNotInSet:(NSSet *)symbols basedOnName:(NSString *)name { - NSString *testName = [[name copy] autorelease]; + NSString *testName = [name copy]; while ([symbols containsObject:testName]) { testName = [NSString stringWithFormat:@"_%@", testName]; @@ -280,7 +277,7 @@ - (NSError *)checkRulesForErrors:(NSArray *)rules { return error; } - NSMutableSet *duplicateTags = [[tagNames mutableCopy] autorelease]; + NSMutableSet *duplicateTags = [tagNames mutableCopy]; [duplicateTags intersectSet:newTagNames]; if ([duplicateTags count] > 0) { @@ -296,7 +293,7 @@ - (NSError *)checkRulesForErrors:(NSArray *)rules { if ([tagNames intersectsSet:tns]) { - NSMutableSet *intersection = [[tagNames mutableCopy] autorelease]; + NSMutableSet *intersection = [tagNames mutableCopy]; [intersection intersectSet:tns]; return [NSError errorWithDomain:CPEBNFParserErrorDomain code:CPErrorCodeDuplicateTag @@ -345,7 +342,7 @@ - (NSDictionary *)nameNewRules:(NSSet *)rhsElements withRules:(NSArray *)oldRule - (NSArray *)addRHSRules:(NSDictionary *)newRules toRules:(NSArray *)oldRules { - NSMutableArray *rules = [[[NSMutableArray alloc] initWithArray:oldRules] autorelease]; + NSMutableArray *rules = [[NSMutableArray alloc] initWithArray:oldRules]; Class rhsItemClass = [CPRHSItemResult class]; for (CPRHSItem *item in newRules) @@ -362,12 +359,12 @@ - (NSArray *)addRHSRules:(NSDictionary *)newRules toRules:(NSArray *)oldRules if ([item mayNotExist]) { - rule = [[[CPRule alloc] initWithName:ruleName rightHandSideElements:[NSArray array]] autorelease]; + rule = [[CPRule alloc] initWithName:ruleName rightHandSideElements:[NSArray array]]; [rule setTag:0]; } else { - rule = [[[CPRule alloc] initWithName:ruleName rightHandSideElements:[[item alternatives] objectAtIndex:0]] autorelease]; + rule = [[CPRule alloc] initWithName:ruleName rightHandSideElements:[[item alternatives] objectAtIndex:0]]; [rule setTag:1]; } [rule setShouldCollapse:[item shouldCollapse]]; @@ -377,12 +374,12 @@ - (NSArray *)addRHSRules:(NSDictionary *)newRules toRules:(NSArray *)oldRules if ([item repeats]) { - rule = [[[CPRule alloc] initWithName:ruleName rightHandSideElements:[[[item alternatives] objectAtIndex:0] arrayByAddingObject:[CPGrammarSymbol nonTerminalWithName:ruleName]]] autorelease]; + rule = [[CPRule alloc] initWithName:ruleName rightHandSideElements:[[[item alternatives] objectAtIndex:0] arrayByAddingObject:[CPGrammarSymbol nonTerminalWithName:ruleName]]]; [rule setTag:2]; } else if ([item mayNotExist]) { - rule = [[[CPRule alloc] initWithName:ruleName rightHandSideElements:[[item alternatives] objectAtIndex:0]] autorelease]; + rule = [[CPRule alloc] initWithName:ruleName rightHandSideElements:[[item alternatives] objectAtIndex:0]]; [rule setTag:1]; } else @@ -403,7 +400,7 @@ - (NSArray *)addRHSRules:(NSDictionary *)newRules toRules:(NSArray *)oldRules NSUInteger i = 0; for (NSArray *contents in [item alternatives]) { - CPRule *rule = [[[CPRule alloc] initWithName:ruleName rightHandSideElements:contents] autorelease]; + CPRule *rule = [[CPRule alloc] initWithName:ruleName rightHandSideElements:contents]; [rule setTag:3 + i]; [rule setRepresentitiveClass:rhsItemClass]; [rule setShouldCollapse:[item shouldCollapse]]; diff --git a/CoreParse/Grammar/CPGrammarSymbol.m b/CoreParse/Grammar/CPGrammarSymbol.m index 7133c35..411bdf8 100644 --- a/CoreParse/Grammar/CPGrammarSymbol.m +++ b/CoreParse/Grammar/CPGrammarSymbol.m @@ -15,12 +15,12 @@ @implementation CPGrammarSymbol + (id)nonTerminalWithName:(NSString *)name { - return [[[self alloc] initWithName:name isTerminal:NO] autorelease]; + return [[self alloc] initWithName:name isTerminal:NO]; } + (id)terminalWithName:(NSString *)name { - return [[[self alloc] initWithName:name isTerminal:YES] autorelease]; + return [[self alloc] initWithName:name isTerminal:YES]; } - (id)initWithName:(NSString *)initName isTerminal:(BOOL)isTerminal; @@ -97,13 +97,6 @@ - (NSString *)description } } -- (void)dealloc -{ - [name release]; - - [super dealloc]; -} - @end @implementation NSObject (CPGrammarSymbol) diff --git a/CoreParse/Grammar/CPRHSItem.m b/CoreParse/Grammar/CPRHSItem.m index 28864a0..f6ae17a 100644 --- a/CoreParse/Grammar/CPRHSItem.m +++ b/CoreParse/Grammar/CPRHSItem.m @@ -52,13 +52,6 @@ - (id)copyWithZone:(NSZone *)zone return other; } -- (void)dealloc -{ - [_alternatives release]; - [_tags release]; - - [super dealloc]; -} - (NSString *)description { @@ -101,14 +94,13 @@ - (NSString *)description - (NSSet *)tags { - return [[_tags retain] autorelease]; + return _tags; } - (void)setTags:(NSSet *)tags { if (tags != _tags) { - [_tags release]; _tags = [tags mutableCopy]; } } @@ -162,7 +154,7 @@ - (NSSet *)tagNamesWithError:(NSError **)err { return nil; } - NSMutableSet *duplicateTags = [[tagNamesInAlternative mutableCopy] autorelease]; + NSMutableSet *duplicateTags = [tagNamesInAlternative mutableCopy]; [duplicateTags intersectSet:newTagNames]; if ([duplicateTags count] > 0) { @@ -184,7 +176,7 @@ - (NSSet *)tagNamesWithError:(NSError **)err { if (NULL != err) { - NSMutableSet *intersection = [[tagNamesInAlternative mutableCopy] autorelease]; + NSMutableSet *intersection = [tagNamesInAlternative mutableCopy]; [intersection intersectSet:tns]; *err = [NSError errorWithDomain:CPEBNFParserErrorDomain code:CPErrorCodeDuplicateTag diff --git a/CoreParse/Grammar/CPRHSItemResult.h b/CoreParse/Grammar/CPRHSItemResult.h index 2232773..971ff8a 100644 --- a/CoreParse/Grammar/CPRHSItemResult.h +++ b/CoreParse/Grammar/CPRHSItemResult.h @@ -12,7 +12,7 @@ @interface CPRHSItemResult : NSObject -@property (readwrite, retain) NSMutableArray *contents; +@property (readwrite, strong) NSMutableArray *contents; @property (readwrite, assign) BOOL shouldCollapse; @property (readwrite, copy ) NSSet *tagNames; @property (readwrite, copy ) NSDictionary *tagValues; diff --git a/CoreParse/Grammar/CPRHSItemResult.m b/CoreParse/Grammar/CPRHSItemResult.m index 5e595ff..578f11b 100644 --- a/CoreParse/Grammar/CPRHSItemResult.m +++ b/CoreParse/Grammar/CPRHSItemResult.m @@ -32,7 +32,7 @@ - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree [self setContents:[NSMutableArray array]]; break; case 1: - [self setContents:[[children mutableCopy] autorelease]]; + [self setContents:[children mutableCopy]]; break; case 2: { @@ -47,7 +47,7 @@ - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree break; } default: - [self setContents:[[children mutableCopy] autorelease]]; + [self setContents:[children mutableCopy]]; break; } @@ -59,14 +59,6 @@ - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree return self; } -- (void)dealloc -{ - [_contents release]; - [_tagNames release]; - [_tagValues release]; - - [super dealloc]; -} - (BOOL)isRHSItemResult { diff --git a/CoreParse/Grammar/CPRule.h b/CoreParse/Grammar/CPRule.h index 4385fc8..d50dc96 100644 --- a/CoreParse/Grammar/CPRule.h +++ b/CoreParse/Grammar/CPRule.h @@ -116,7 +116,7 @@ /** * Specifies the name of the non-terminal this rule describes. */ -@property (readwrite, retain) NSString *name; +@property (readwrite, strong) NSString *name; /** * Specifies the right hand side of the rule. @@ -133,7 +133,7 @@ /** * The class used to represent syntax trees based off this rule. */ -@property (readwrite, assign) Class representitiveClass; +@property (readwrite, unsafe_unretained) Class representitiveClass; @end diff --git a/CoreParse/Grammar/CPRule.m b/CoreParse/Grammar/CPRule.m index 33393a6..d9a7d36 100644 --- a/CoreParse/Grammar/CPRule.m +++ b/CoreParse/Grammar/CPRule.m @@ -24,7 +24,7 @@ @implementation CPRule - (NSArray *)rightHandSideElements { - return [[rightHandSide retain] autorelease]; + return rightHandSide; } - (void)setRightHandSideElements:(NSArray *)rightHandSideElements @@ -33,7 +33,6 @@ - (void)setRightHandSideElements:(NSArray *)rightHandSideElements { if (rightHandSide != rightHandSideElements) { - [rightHandSide release]; rightHandSide = [rightHandSideElements mutableCopy]; } } @@ -41,7 +40,7 @@ - (void)setRightHandSideElements:(NSArray *)rightHandSideElements + (id)ruleWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements representitiveClass:(Class)representitiveClass { - return [[[self alloc] initWithName:name rightHandSideElements:rightHandSideElements representitiveClass:representitiveClass] autorelease]; + return [[self alloc] initWithName:name rightHandSideElements:rightHandSideElements representitiveClass:representitiveClass]; } - (id)initWithName:(NSString *)initName rightHandSideElements:(NSArray *)rightHandSideElements representitiveClass:(Class)initRepresentitiveClass @@ -61,7 +60,7 @@ - (id)initWithName:(NSString *)initName rightHandSideElements:(NSArray *)rightHa + (id)ruleWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements tag:(NSUInteger)tag { - return [[[self alloc] initWithName:name rightHandSideElements:rightHandSideElements tag:tag] autorelease]; + return [[self alloc] initWithName:name rightHandSideElements:rightHandSideElements tag:tag]; } - (id)initWithName:(NSString *)initName rightHandSideElements:(NSArray *)rightHandSideElements tag:(NSUInteger)initTag @@ -78,7 +77,7 @@ - (id)initWithName:(NSString *)initName rightHandSideElements:(NSArray *)rightHa + (id)ruleWithName:(NSString *)name rightHandSideElements:(NSArray *)rightHandSideElements { - return [[[CPRule alloc] initWithName:name rightHandSideElements:rightHandSideElements] autorelease]; + return [[CPRule alloc] initWithName:name rightHandSideElements:rightHandSideElements]; } - (id)initWithName:(NSString *)initName rightHandSideElements:(NSArray *)rightHandSideElements @@ -119,13 +118,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:NSStringFromClass([self representitiveClass]) forKey:CPRuleRepresentitiveClassKey]; } -- (void)dealloc -{ - [name release]; - [rightHandSide release]; - - [super dealloc]; -} - (NSString *)description { @@ -167,14 +159,13 @@ - (void)setShouldCollapse:(BOOL)shouldCollapse - (NSSet *)tagNames { - return [[_tagNames retain] autorelease]; + return _tagNames; } - (void)setTagNames:(NSSet *)tagNames { if (_tagNames != tagNames) { - [_tagNames release]; _tagNames = [tagNames copy]; } } diff --git a/CoreParse/NSArray+Functional.m b/CoreParse/NSArray+Functional.m index 9378b70..d76b3ab 100644 --- a/CoreParse/NSArray+Functional.m +++ b/CoreParse/NSArray+Functional.m @@ -13,22 +13,18 @@ @implementation NSArray (Functional) - (NSArray *)cp_map:(id(^)(id obj))block { NSUInteger c = [self count]; - id *resultingObjects = malloc(c * sizeof(id)); + NSMutableArray *a = [NSMutableArray arrayWithCapacity:c]; - NSUInteger nonNilCount = 0; for (id obj in self) { id r = block(obj); if (nil != r) { - resultingObjects[nonNilCount] = r; - nonNilCount++; + [a addObject:r]; } } - NSArray *a = [NSArray arrayWithObjects:resultingObjects count:nonNilCount]; - free(resultingObjects); - return a; + return [a copy]; } @end diff --git a/CoreParse/NSSetFunctional.m b/CoreParse/NSSetFunctional.m index 988a3e6..abdfeb1 100644 --- a/CoreParse/NSSetFunctional.m +++ b/CoreParse/NSSetFunctional.m @@ -14,22 +14,18 @@ @implementation NSSet(Functional) - (NSSet *)cp_map:(id(^)(id obj))block { NSUInteger c = [self count]; - id *resultingObjects = malloc(c * sizeof(id)); + NSMutableSet *s = [NSMutableSet setWithCapacity:c]; - NSUInteger nonNilCount = 0; for (id obj in self) { id r = block(obj); if (nil != r) { - resultingObjects[nonNilCount] = r; - nonNilCount++; + [s addObject:r]; } } - - NSSet *s = [NSSet setWithObjects:resultingObjects count:nonNilCount]; - free(resultingObjects); - return s; + + return [s copy]; } @end diff --git a/CoreParse/Parsers/CPParser.h b/CoreParse/Parsers/CPParser.h index d0fde28..86ae9ea 100644 --- a/CoreParse/Parsers/CPParser.h +++ b/CoreParse/Parsers/CPParser.h @@ -127,7 +127,7 @@ typedef struct /** * The parser's delegate. */ -@property (readwrite,assign, nonatomic) id delegate; +@property (readwrite,weak, nonatomic) id delegate; ///--------------------------------------------------------------------------------------- /// @name Finding out about the parsed Grammar diff --git a/CoreParse/Parsers/CPParser.m b/CoreParse/Parsers/CPParser.m index 4135a42..944d6b9 100644 --- a/CoreParse/Parsers/CPParser.m +++ b/CoreParse/Parsers/CPParser.m @@ -21,7 +21,7 @@ @implementation CPParser + (id)parserWithGrammar:(CPGrammar *)grammar { - return [[[self alloc] initWithGrammar:grammar] autorelease]; + return [[self alloc] initWithGrammar:grammar]; } - (id)initWithGrammar:(CPGrammar *)initGrammar @@ -41,13 +41,6 @@ - (id)init return [self initWithGrammar:nil]; } -- (void)dealloc -{ - [grammar release]; - - [super dealloc]; -} - - (id)parse:(CPTokenStream *)tokenStream { [NSException raise:@"Abstract Class Exception" diff --git a/CoreParse/Parsers/CPShiftReduceParser.m b/CoreParse/Parsers/CPShiftReduceParser.m index 0804af3..20a5e3c 100644 --- a/CoreParse/Parsers/CPShiftReduceParser.m +++ b/CoreParse/Parsers/CPShiftReduceParser.m @@ -41,7 +41,6 @@ - (id)initWithGrammar:(CPGrammar *)grammar BOOL succes = [self constructShiftReduceTables]; if (!succes) { - [self release]; return nil; } } @@ -73,13 +72,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:[self gotoTable] forKey:CPShiftReduceParserGotoTableKey]; } -- (void)dealloc -{ - [actionTable release]; - [gotoTable release]; - - [super dealloc]; -} - (BOOL)constructShiftReduceTables { @@ -94,7 +86,7 @@ - (id)parse:(CPTokenStream *)tokenStream @try { NSMutableArray *stateStack = [NSMutableArray arrayWithObject:[CPShiftReduceState shiftReduceStateWithObject:nil state:0]]; - CPToken *nextToken = [[tokenStream peekToken] retain]; + CPToken *nextToken = [tokenStream peekToken]; BOOL hasErrorToken = NO; while (1) { @@ -109,8 +101,7 @@ - (id)parse:(CPTokenStream *)tokenStream { [tokenStream popToken]; } - [nextToken release]; - nextToken = [[tokenStream peekToken] retain]; + nextToken = [tokenStream peekToken]; hasErrorToken = NO; } else if ([action isReduceAction]) @@ -169,7 +160,7 @@ - (id)parse:(CPTokenStream *)tokenStream Class c = [reductionRule representitiveClass]; if (nil != c) { - result = [[(id)[c alloc] initWithSyntaxTree:tree] autorelease]; + result = [(id)[c alloc] initWithSyntaxTree:tree]; } if (nil == result) @@ -186,7 +177,6 @@ - (id)parse:(CPTokenStream *)tokenStream } else if ([action isAccept]) { - [nextToken release]; return [(CPShiftReduceState *)[stateStack lastObject] object]; } else @@ -200,7 +190,6 @@ - (id)parse:(CPTokenStream *)tokenStream } else { - [nextToken release]; return nil; } } @@ -209,14 +198,12 @@ - (id)parse:(CPTokenStream *)tokenStream switch ([recoveryAction recoveryType]) { case CPRecoveryTypeAddToken: - [nextToken release]; - nextToken = [[recoveryAction additionalToken] retain]; + nextToken = [recoveryAction additionalToken]; hasErrorToken = YES; break; case CPRecoveryTypeRemoveToken: [tokenStream popToken]; - [nextToken release]; - nextToken = [[tokenStream peekToken] retain]; + nextToken = [tokenStream peekToken]; hasErrorToken = NO; break; case CPRecoveryTypeBail: diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPItem.h b/CoreParse/Parsers/CPShiftReduceParsers/CPItem.h index b07ad99..3a19bbc 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPItem.h +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPItem.h @@ -14,7 +14,7 @@ @interface CPItem : NSObject {} -@property (readonly,retain) CPRule *rule; +@property (readonly,strong) CPRule *rule; @property (readonly,assign) NSUInteger position; + (id)itemWithRule:(CPRule *)rule position:(NSUInteger)position; diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPItem.m b/CoreParse/Parsers/CPShiftReduceParsers/CPItem.m index 0d6277c..ba8cff9 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPItem.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPItem.m @@ -10,7 +10,7 @@ @interface CPItem () -@property (readwrite,retain) CPRule *rule; +@property (readwrite,strong) CPRule *rule; @property (readwrite,assign) NSUInteger position; @end @@ -22,7 +22,7 @@ @implementation CPItem + (id)itemWithRule:(CPRule *)rule position:(NSUInteger)position { - return [[[self alloc] initWithRule:rule position:position] autorelease]; + return [[self alloc] initWithRule:rule position:position]; } - (id)initWithRule:(CPRule *)initRule position:(NSUInteger)initPosition @@ -31,7 +31,7 @@ - (id)initWithRule:(CPRule *)initRule position:(NSUInteger)initPosition if (nil != self) { - rule = [initRule retain]; + rule = initRule; position = initPosition; } @@ -43,12 +43,6 @@ - (id)copyWithZone:(NSZone *)zone return [[CPItem allocWithZone:zone] initWithRule:rule position:position]; } -- (void)dealloc -{ - [rule release]; - - [super dealloc]; -} - (CPGrammarSymbol *)nextSymbol { @@ -73,7 +67,7 @@ - (id)itemByMovingDotRight { CPItem *c = [self copy]; [c setPosition:[self position] + 1]; - return [c autorelease]; + return c; } - (BOOL)isItem diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPLALR1Parser.m b/CoreParse/Parsers/CPShiftReduceParsers/CPLALR1Parser.m index 5fa0c91..a67d985 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPLALR1Parser.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPLALR1Parser.m @@ -35,8 +35,8 @@ - (BOOL)constructShiftReduceTables NSArray *allNonTerminalNames = [[self grammar] allNonTerminalNames]; NSString *startSymbol = [aug start]; - [self setActionTable:[[[CPShiftReduceActionTable alloc] initWithCapacity:itemCount] autorelease]]; - [self setGotoTable: [[[CPShiftReduceGotoTable alloc] initWithCapacity:itemCount] autorelease]]; + [self setActionTable:[[CPShiftReduceActionTable alloc] initWithCapacity:itemCount]]; + [self setGotoTable: [[CPShiftReduceGotoTable alloc] initWithCapacity:itemCount]]; NSUInteger idx = 0; for (NSSet *kernel in kernels) diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.m b/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.m index 4963120..52b7885 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.m @@ -20,7 +20,7 @@ @implementation CPLR1Item + (id)lr1ItemWithRule:(CPRule *)rule position:(NSUInteger)position terminal:(CPGrammarSymbol *)terminal { - return [[[self alloc] initWithRule:rule position:position terminal:terminal] autorelease]; + return [[self alloc] initWithRule:rule position:position terminal:terminal]; } - (id)initWithRule:(CPRule *)rule position:(NSUInteger)position terminal:(CPGrammarSymbol *)initTerminal @@ -45,13 +45,6 @@ - (id)copyWithZone:(NSZone *)zone return [[CPLR1Item allocWithZone:zone] initWithRule:[self rule] position:[self position] terminal:[self terminal]]; } -- (void)dealloc -{ - [terminal release]; - - [super dealloc]; -} - - (BOOL)isLR1Item { return YES; diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Parser.m b/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Parser.m index 2c72a6f..1fb3536 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Parser.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPLR1Parser.m @@ -35,8 +35,8 @@ - (BOOL)constructShiftReduceTables NSArray *allNonTerminalNames = [[self grammar] allNonTerminalNames]; NSString *startSymbol = [aug start]; - [self setActionTable:[[[CPShiftReduceActionTable alloc] initWithCapacity:itemCount] autorelease]]; - [self setGotoTable: [[[CPShiftReduceGotoTable alloc] initWithCapacity:itemCount] autorelease]]; + [self setActionTable:[[CPShiftReduceActionTable alloc] initWithCapacity:itemCount]]; + [self setGotoTable: [[CPShiftReduceGotoTable alloc] initWithCapacity:itemCount]]; NSUInteger idx = 0; for (NSSet *kernel in kernels) diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPSLRParser.m b/CoreParse/Parsers/CPShiftReduceParsers/CPSLRParser.m index eedad37..4d0b115 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPSLRParser.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPSLRParser.m @@ -32,8 +32,8 @@ - (BOOL)constructShiftReduceTables NSUInteger itemCount = [kernels count]; NSString *startSymbol = [aug start]; - [self setActionTable:[[[CPShiftReduceActionTable alloc] initWithCapacity:itemCount] autorelease]]; - [self setGotoTable: [[[CPShiftReduceGotoTable alloc] initWithCapacity:itemCount] autorelease]]; + [self setActionTable:[[CPShiftReduceActionTable alloc] initWithCapacity:itemCount]]; + [self setGotoTable: [[CPShiftReduceGotoTable alloc] initWithCapacity:itemCount]]; NSArray *allNonTerminalNames = [[self grammar] allNonTerminalNames]; NSUInteger idx = 0; diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.m b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.m index f03e1d2..7b66f6d 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.m @@ -17,42 +17,49 @@ kActionTypeAccept } ActionType; -typedef union -{ - NSUInteger shift; - CPRule *reductionRule; -} -ActionDetails; +@interface ActionDetails: NSObject + +@property (nonatomic, strong) CPRule *reductionRule; +@property (nonatomic, assign) NSUInteger shift; + +@end + +@implementation ActionDetails + +@end + +@interface CPShiftReduceAction () + +@property (nonatomic, strong) ActionDetails *details; +@property (nonatomic, assign) ActionType type; + +@end @implementation CPShiftReduceAction -{ - ActionType type; - ActionDetails details; -} + (id)shiftAction:(NSUInteger)shiftLocation { - return [[[self alloc] initWithShift:shiftLocation] autorelease]; + return [[self alloc] initWithShift:shiftLocation]; } + (id)reduceAction:(CPRule *)reduction { - return [[[self alloc] initWithReductionRule:reduction] autorelease]; + return [[self alloc] initWithReductionRule:reduction]; } + (id)acceptAction { - return [[[self alloc] init] autorelease]; + return [[self alloc] init]; } - (id)initWithShift:(NSUInteger)shiftLocation { - self = [super init]; + self = [self init]; if (nil != self) { - type = kActionTypeShift; - details.shift = shiftLocation; + _type = kActionTypeShift; + _details.shift = shiftLocation; } return self; @@ -60,12 +67,12 @@ - (id)initWithShift:(NSUInteger)shiftLocation - (id)initWithReductionRule:(CPRule *)reduction { - self = [super init]; + self = [self init]; if (nil != self) { - type = kActionTypeReduce; - details.reductionRule = [reduction retain]; + _type = kActionTypeReduce; + _details.reductionRule = reduction; } return self; @@ -77,7 +84,8 @@ - (id)init if (nil != self) { - type = kActionTypeAccept; + _details = [[ActionDetails alloc] init]; + _type = kActionTypeAccept; } return self; @@ -89,18 +97,18 @@ - (id)init - (id)initWithCoder:(NSCoder *)aDecoder { - self = [super init]; + self = [self init]; if (nil != self) { - type = [aDecoder decodeIntForKey:CPShiftReduceActionTypeKey]; - switch (type) + _type = [aDecoder decodeIntForKey:CPShiftReduceActionTypeKey]; + switch (_type) { case kActionTypeShift: - details.shift = [aDecoder decodeIntegerForKey:CPShiftReduceActionShiftKey]; + _details.shift = [aDecoder decodeIntegerForKey:CPShiftReduceActionShiftKey]; break; case kActionTypeReduce: - details.reductionRule = [[aDecoder decodeObjectForKey:CPShiftReduceActionRuleKey] retain]; + _details.reductionRule = [aDecoder decodeObjectForKey:CPShiftReduceActionRuleKey]; case kActionTypeAccept: default: break; @@ -112,58 +120,48 @@ - (id)initWithCoder:(NSCoder *)aDecoder - (void)encodeWithCoder:(NSCoder *)aCoder { - [aCoder encodeInt:type forKey:CPShiftReduceActionTypeKey]; - switch (type) + [aCoder encodeInt:_type forKey:CPShiftReduceActionTypeKey]; + switch (_type) { case kActionTypeShift: - [aCoder encodeInteger:details.shift forKey:CPShiftReduceActionShiftKey]; + [aCoder encodeInteger:_details.shift forKey:CPShiftReduceActionShiftKey]; break; case kActionTypeReduce: - [aCoder encodeObject:details.reductionRule forKey:CPShiftReduceActionRuleKey]; + [aCoder encodeObject:_details.reductionRule forKey:CPShiftReduceActionRuleKey]; case kActionTypeAccept: default: break; } } -- (void)dealloc -{ - if (kActionTypeReduce == type) - { - [details.reductionRule release]; - } - - [super dealloc]; -} - - (BOOL)isShiftAction { - return kActionTypeShift == type; + return kActionTypeShift == _type; } - (BOOL)isReduceAction { - return kActionTypeReduce == type; + return kActionTypeReduce == _type; } - (BOOL)isAccept { - return kActionTypeAccept == type; + return kActionTypeAccept == _type; } - (NSUInteger)newState { - return details.shift; + return _details.shift; } - (CPRule *)reductionRule { - return details.reductionRule; + return _details.reductionRule; } - (NSUInteger)hash { - return type; + return _type; } - (BOOL)isShiftReduceAction @@ -173,15 +171,15 @@ - (BOOL)isShiftReduceAction - (BOOL)isEqual:(id)object { - if ([object isShiftReduceAction] && ((CPShiftReduceAction *)object)->type == type) + if ([object isShiftReduceAction] && ((CPShiftReduceAction *)object).type == _type) { CPShiftReduceAction *other = (CPShiftReduceAction *)object; - switch (type) + switch (_type) { case kActionTypeShift: - return [other newState] == details.shift; + return [other newState] == _details.shift; case kActionTypeReduce: - return [other reductionRule] == details.reductionRule; + return [other reductionRule] == _details.reductionRule; case kActionTypeAccept: return YES; } @@ -192,14 +190,14 @@ - (BOOL)isEqual:(id)object - (BOOL)isEqualToShiftReduceAction:(CPShiftReduceAction *)object { - if (object != nil && object->type == type) + if (object != nil && object.type == _type) { - switch (type) + switch (_type) { case kActionTypeShift: - return [object newState] == details.shift; + return [object newState] == _details.shift; case kActionTypeReduce: - return [object reductionRule] == details.reductionRule; + return [object reductionRule] == _details.reductionRule; case kActionTypeAccept: return YES; } @@ -210,12 +208,12 @@ - (BOOL)isEqualToShiftReduceAction:(CPShiftReduceAction *)object - (NSString *)description { - switch (type) + switch (_type) { case kActionTypeShift: - return [NSString stringWithFormat:@"s%ld", (long)details.shift]; + return [NSString stringWithFormat:@"s%ld", (long)_details.shift]; case kActionTypeReduce: - return [NSString stringWithFormat:@"r%@", [details.reductionRule name]]; + return [NSString stringWithFormat:@"r%@", [_details.reductionRule name]]; case kActionTypeAccept: return @"acc"; } @@ -223,12 +221,12 @@ - (NSString *)description - (NSString *)descriptionWithGrammar:(CPGrammar *)g { - switch (type) + switch (_type) { case kActionTypeShift: - return [NSString stringWithFormat:@"s%ld", (long)details.shift]; + return [NSString stringWithFormat:@"s%ld", (long)_details.shift]; case kActionTypeReduce: - return [NSString stringWithFormat:@"r%ld", (long)[g indexOfRule:details.reductionRule]]; + return [NSString stringWithFormat:@"r%ld", (long)[g indexOfRule:_details.reductionRule]]; case kActionTypeAccept: return @"acc"; } diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceActionTable.m b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceActionTable.m index cef7cc6..e1e5fd4 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceActionTable.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceActionTable.m @@ -12,11 +12,14 @@ #import "CPGrammarSymbol.h" #import "CPShiftReduceAction.h" +@interface CPShiftReduceActionTable() + +@property (nonatomic, strong) NSMutableArray *table; +@property (nonatomic, assign) NSUInteger capacity; + +@end + @implementation CPShiftReduceActionTable -{ - NSMutableDictionary **table; - NSUInteger capacity; -} - (id)initWithCapacity:(NSUInteger)initCapacity { @@ -24,11 +27,11 @@ - (id)initWithCapacity:(NSUInteger)initCapacity if (nil != self) { - capacity = initCapacity; - table = malloc(capacity * sizeof(NSMutableDictionary *)); - for (NSUInteger buildingState = 0; buildingState < capacity; buildingState++) + _capacity = initCapacity; + _table = [NSMutableArray arrayWithCapacity:initCapacity]; + for (NSUInteger buildingState = 0; buildingState < _capacity; buildingState++) { - table[buildingState] = [[NSMutableDictionary alloc] init]; + _table[buildingState] = [[NSMutableDictionary alloc] init]; } } @@ -44,13 +47,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder if (nil != self) { NSArray *rows = [aDecoder decodeObjectForKey:CPShiftReduceActionTableTableKey]; - capacity = [rows count]; - table = malloc(capacity * sizeof(NSMutableDictionary *)); - [rows getObjects:table range:NSMakeRange(0, capacity)]; - for (NSUInteger i = 0; i < capacity; i++) - { - [table[i] retain]; - } + _capacity = [rows count]; + _table = [rows mutableCopy]; } return self; @@ -58,23 +56,12 @@ - (id)initWithCoder:(NSCoder *)aDecoder - (void)encodeWithCoder:(NSCoder *)aCoder { - [aCoder encodeObject:[NSArray arrayWithObjects:table count:capacity] forKey:CPShiftReduceActionTableTableKey]; -} - -- (void)dealloc -{ - for (NSUInteger state = 0; state < capacity; state++) - { - [table[state] release]; - } - free(table); - - [super dealloc]; + [aCoder encodeObject:_table forKey:CPShiftReduceActionTableTableKey]; } - (BOOL)setAction:(CPShiftReduceAction *)action forState:(NSUInteger)state name:(NSString *)token { - NSMutableDictionary *row = table[state]; + NSMutableDictionary *row = _table[state]; if (nil != [row objectForKey:token] && ![[row objectForKey:token] isEqualToShiftReduceAction:action]) { return NO; @@ -85,32 +72,32 @@ - (BOOL)setAction:(CPShiftReduceAction *)action forState:(NSUInteger)state name: - (CPShiftReduceAction *)actionForState:(NSUInteger)state token:(CPToken *)token { - return [table[state] objectForKey:token.name]; + return [_table[state] objectForKey:token.name]; } - (NSSet *)acceptableTokenNamesForState:(NSUInteger)state { NSMutableSet *toks = [NSMutableSet set]; - for (NSString *tok in table[state]) + for (NSString *tok in _table[state]) { - if (nil != [table[state] objectForKey:tok]) + if (nil != [_table[state] objectForKey:tok]) { [toks addObject:tok]; } } - return [[toks copy] autorelease]; + return [toks copy]; } - (NSString *)description { - if (capacity > 0) + if (_capacity > 0) { NSMutableString *s = [NSMutableString string]; NSMutableSet *keys = [NSMutableSet set]; NSUInteger width = 3; - for (NSUInteger state = 0; state < capacity; state++) + for (NSUInteger state = 0; state < _capacity; state++) { - [keys addObjectsFromArray:[table[state] allKeys]]; + [keys addObjectsFromArray:[_table[state] allKeys]]; } for (NSString *key in keys) { @@ -130,9 +117,9 @@ - (NSString *)description [s appendString:@"\n"]; NSUInteger idx = 0; - for (NSUInteger state = 0; state < capacity; state++) + for (NSUInteger state = 0; state < _capacity; state++) { - NSDictionary *row = table[state]; + NSDictionary *row = _table[state]; [s appendFormat:@"%5ld | ", (long)idx]; for (NSString *key in orderedKeys) { @@ -164,14 +151,14 @@ - (NSString *)description - (NSString *)descriptionWithGrammar:(CPGrammar *)g { - if (capacity > 0) + if (_capacity > 0) { NSMutableString *s = [NSMutableString string]; NSMutableSet *keys = [NSMutableSet set]; NSUInteger width = 3; - for (NSUInteger state = 0; state < capacity; state++) + for (NSUInteger state = 0; state < _capacity; state++) { - [keys addObjectsFromArray:[table[state] allKeys]]; + [keys addObjectsFromArray:[_table[state] allKeys]]; } for (NSString *key in keys) { @@ -191,9 +178,9 @@ - (NSString *)descriptionWithGrammar:(CPGrammar *)g [s appendString:@"\n"]; NSUInteger idx = 0; - for (NSUInteger state = 0; state < capacity; state++) + for (NSUInteger state = 0; state < _capacity; state++) { - NSDictionary *row = table[state]; + NSDictionary *row = _table[state]; [s appendFormat:@"%5ld | ", (long)idx]; for (NSString *key in orderedKeys) { diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceGotoTable.m b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceGotoTable.m index 1de736e..c2027b6 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceGotoTable.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceGotoTable.m @@ -7,13 +7,16 @@ // #import "CPShiftReduceGotoTable.h" +#import "CPRule.h" +@interface CPShiftReduceGotoTable() + +@property (nonatomic, strong) NSMutableArray *table; +@property (nonatomic, assign) NSUInteger capacity; + +@end @implementation CPShiftReduceGotoTable -{ - NSMutableDictionary **table; - NSUInteger capacity; -} - (id)initWithCapacity:(NSUInteger)initCapacity { @@ -21,11 +24,11 @@ - (id)initWithCapacity:(NSUInteger)initCapacity if (nil != self) { - capacity = initCapacity; - table = malloc(capacity * sizeof(NSMutableDictionary *)); - for (NSUInteger buildingState = 0; buildingState < capacity; buildingState++) + _capacity = initCapacity; + _table = [NSMutableArray arrayWithCapacity:initCapacity]; + for (NSUInteger buildingState = 0; buildingState < _capacity; buildingState++) { - table[buildingState] = [[NSMutableDictionary alloc] init]; + _table[buildingState] = [[NSMutableDictionary alloc] init]; } } @@ -41,13 +44,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder if (nil != self) { NSArray *rows = [aDecoder decodeObjectForKey:CPShiftReduceGotoTableTableKey]; - capacity = [rows count]; - table = malloc(capacity * sizeof(NSMutableDictionary *)); - [rows getObjects:table range:NSMakeRange(0, capacity)]; - for (NSUInteger i = 0; i < capacity; i++) - { - [table[i] retain]; - } + _capacity = [rows count]; + _table = [rows mutableCopy]; } return self; @@ -55,23 +53,12 @@ - (id)initWithCoder:(NSCoder *)aDecoder - (void)encodeWithCoder:(NSCoder *)aCoder { - [aCoder encodeObject:[NSArray arrayWithObjects:table count:capacity] forKey:CPShiftReduceGotoTableTableKey]; -} - -- (void)dealloc -{ - for (NSUInteger state = 0; state < capacity; state++) - { - [table[state] release]; - } - free(table); - - [super dealloc]; + [aCoder encodeObject:_table forKey:CPShiftReduceGotoTableTableKey]; } - (BOOL)setGoto:(NSUInteger)gotoIndex forState:(NSUInteger)state nonTerminalNamed:(NSString *)nonTerminalName { - NSMutableDictionary *row = table[state]; + NSMutableDictionary *row = _table[state]; if (nil != [row objectForKey:nonTerminalName] && [[row objectForKey:nonTerminalName] unsignedIntegerValue] != gotoIndex) { return NO; @@ -82,7 +69,7 @@ - (BOOL)setGoto:(NSUInteger)gotoIndex forState:(NSUInteger)state nonTerminalName - (NSUInteger)gotoForState:(NSUInteger)state rule:(CPRule *)rule { - return [(NSNumber *)[table[state] objectForKey:[rule name]] unsignedIntegerValue]; + return [(NSNumber *)[_table[state] objectForKey:[rule name]] unsignedIntegerValue]; } @end diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceParserProtectedMethods.h b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceParserProtectedMethods.h index c40bb43..898b285 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceParserProtectedMethods.h +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceParserProtectedMethods.h @@ -15,8 +15,8 @@ @interface CPShiftReduceParser () -@property (readwrite,retain) CPShiftReduceActionTable *actionTable; -@property (readwrite,retain) CPShiftReduceGotoTable *gotoTable; +@property (readwrite,strong) CPShiftReduceActionTable *actionTable; +@property (readwrite,strong) CPShiftReduceGotoTable *gotoTable; - (BOOL)constructShiftReduceTables; diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.h b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.h index 5916af1..3e49fee 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.h +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.h @@ -10,7 +10,7 @@ @interface CPShiftReduceState : NSObject -@property (readonly,retain) NSObject *object; +@property (readonly,strong) NSObject *object; @property (readonly,assign) NSUInteger state; + (id)shiftReduceStateWithObject:(NSObject *)object state:(NSUInteger)state; diff --git a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.m b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.m index 7281881..1aaf7f0 100644 --- a/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.m +++ b/CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceState.m @@ -10,7 +10,7 @@ @interface CPShiftReduceState () -@property (readwrite,retain) NSObject *object; +@property (readwrite,strong) NSObject *object; @property (readwrite,assign) NSUInteger state; @end @@ -22,7 +22,7 @@ @implementation CPShiftReduceState + (id)shiftReduceStateWithObject:(NSObject *)object state:(NSUInteger)state { - return [[[self alloc] initWithObject:object state:state] autorelease]; + return [[self alloc] initWithObject:object state:state]; } - (id)initWithObject:(NSObject *)initObject state:(NSUInteger)initState @@ -38,12 +38,6 @@ - (id)initWithObject:(NSObject *)initObject state:(NSUInteger)initState return self; } -- (void)dealloc -{ - [object release]; - - [super dealloc]; -} - (NSString *)description { diff --git a/CoreParse/Parsers/Error Recovery/CPRecoveryAction.m b/CoreParse/Parsers/Error Recovery/CPRecoveryAction.m index d5af294..ccfdd97 100644 --- a/CoreParse/Parsers/Error Recovery/CPRecoveryAction.m +++ b/CoreParse/Parsers/Error Recovery/CPRecoveryAction.m @@ -15,17 +15,17 @@ @implementation CPRecoveryAction + (id)recoveryActionWithAdditionalToken:(CPToken *)token { - return [[[self alloc] initWithAdditionalToken:token] autorelease]; + return [[self alloc] initWithAdditionalToken:token]; } + (id)recoveryActionDeletingCurrentToken { - return [[[self alloc] initWithDeleteAction] autorelease]; + return [[self alloc] initWithDeleteAction]; } + (id)recoveryActionStop { - return [[[self alloc] initWithStopAction] autorelease]; + return [[self alloc] initWithStopAction]; } - (id)initWithAdditionalToken:(CPToken *)token @@ -65,11 +65,4 @@ - (id)initWithStopAction return self; } -- (void)dealloc -{ - [additionalToken release]; - - [super dealloc]; -} - @end diff --git a/CoreParse/Syntax Tree/CPSyntaxTree.m b/CoreParse/Syntax Tree/CPSyntaxTree.m index d4c4b88..42f4f01 100644 --- a/CoreParse/Syntax Tree/CPSyntaxTree.m +++ b/CoreParse/Syntax Tree/CPSyntaxTree.m @@ -24,7 +24,7 @@ @implementation CPSyntaxTree + (id)syntaxTreeWithRule:(CPRule *)rule children:(NSArray *)children { - return [[[self alloc] initWithRule:rule children:children tagValues:[NSDictionary dictionary]] autorelease]; + return [[self alloc] initWithRule:rule children:children tagValues:[NSDictionary dictionary]]; } - (id)initWithRule:(CPRule *)initRule children:(NSArray *)initChildren; @@ -34,7 +34,7 @@ - (id)initWithRule:(CPRule *)initRule children:(NSArray *)initChildren; + (id)syntaxTreeWithRule:(CPRule *)rule children:(NSArray *)children tagValues:(NSDictionary *)tagValues; { - return [[[self alloc] initWithRule:rule children:children tagValues:tagValues] autorelease]; + return [[self alloc] initWithRule:rule children:children tagValues:tagValues]; } - (id)initWithRule:(CPRule *)initRule children:(NSArray *)initChildren tagValues:(NSDictionary *)initTagValues @@ -56,15 +56,6 @@ - (id)init return [self initWithRule:nil children:[NSArray array] tagValues:[NSDictionary dictionary]]; } -- (void)dealloc -{ - [rule release]; - [children release]; - [tagValues release]; - - [super dealloc]; -} - - (id)valueForTag:(NSString *)tagName { return [tagValues objectForKey:tagName]; diff --git a/CoreParse/Tokenisation/CPTokenStream.m b/CoreParse/Tokenisation/CPTokenStream.m index f6628f5..910b35b 100644 --- a/CoreParse/Tokenisation/CPTokenStream.m +++ b/CoreParse/Tokenisation/CPTokenStream.m @@ -31,7 +31,7 @@ @implementation CPTokenStream + (id)tokenStreamWithTokens:(NSArray *)tokens { - return [[[self alloc] initWithTokens:tokens] autorelease]; + return [[self alloc] initWithTokens:tokens]; } - (id)initWithTokens:(NSArray *)initTokens @@ -40,7 +40,7 @@ - (id)initWithTokens:(NSArray *)initTokens if (nil != self) { - [self setTokens:[[initTokens mutableCopy] autorelease]]; + [self setTokens:[initTokens mutableCopy]]; } return self; @@ -60,14 +60,6 @@ - (id)init return self; } -- (void)dealloc -{ - [tokens release]; - [readWriteLock release]; - - [super dealloc]; -} - - (CPToken *)peekToken { [readWriteLock lockWhenCondition:CPTokenStreamAvailable]; @@ -75,7 +67,7 @@ - (CPToken *)peekToken if ([tokens count] > 0) { - token = [[[tokens objectAtIndex:0] retain] autorelease]; + token = [tokens objectAtIndex:0]; } [readWriteLock unlockWithCondition:CPTokenStreamAvailable]; @@ -88,7 +80,7 @@ - (CPToken *)popToken CPToken *token = nil; if ([tokens count] > 0) { - token = [[[tokens objectAtIndex:0] retain] autorelease]; + token = [tokens objectAtIndex:0]; [tokens removeObjectAtIndex:0]; } [self unlockTokenStream]; @@ -98,7 +90,7 @@ - (CPToken *)popToken - (NSArray *)tokens { - return [[tokens copy] autorelease]; + return [tokens copy]; } - (void)setTokens:(NSMutableArray *)newTokens @@ -106,7 +98,6 @@ - (void)setTokens:(NSMutableArray *)newTokens [readWriteLock lock]; if (tokens != newTokens) { - [tokens release]; tokens = [newTokens mutableCopy]; } [self unlockTokenStream]; diff --git a/CoreParse/Tokenisation/CPTokeniser.h b/CoreParse/Tokenisation/CPTokeniser.h index c4b0376..cb8db8a 100644 --- a/CoreParse/Tokenisation/CPTokeniser.h +++ b/CoreParse/Tokenisation/CPTokeniser.h @@ -20,11 +20,11 @@ @required -/** +/** * Determines whether a CPTokeniser should produce a token and consume the associated input string. - * + * * If this method returns NO, the CPTokeniser continues to attempt to recognise tokens at the same point in the input string with other token recognisers. - * + * * @param tokeniser The CPTokeniser attempting to produce the token. * @param token The CPToken that the tokeniser has recognised. * @return Return YES if the tokeniser should consume the token, NO otherwise. @@ -85,7 +85,7 @@ /** * The CPTokeniser class provides tokenisation of NSStrings into CPTokenStreams, and describes what kinds of tokens to produce given particular string inputs. - * + * * Tokenisers are built up by adding a list of CPTokenRecogniser objects to the CPTokeniser. * Each one recognises a different token. Each recogniser is given a chance to match a token in priority order. * When a recogniser matches a token, the -tokeniser:shouldConsumeToken: delegate method is called. @@ -102,7 +102,7 @@ /** * The object that acts as a delegate to the receiving CPTokeniser. */ -@property (readwrite, assign, nonatomic) id delegate; +@property (readwrite, weak, nonatomic) id delegate; ///--------------------------------------------------------------------------------------- /// @name Managing recognised tokens @@ -122,7 +122,7 @@ * Inserts a given token recogniser at a given priority level in the tokeniser. * * The recogniser currently at that priority and all those below it move downwards. - * + * * @param recogniser The token recogniser to insert. This value must not be `nil`. * @param priority The priority level to insert at. * @exception Raises an `NSInvalidArgumentException` if recogniser is `nil`. @@ -136,7 +136,7 @@ * Inserts a given token recogniser before another. * * The recogniser currently at that priority and all those below it move downwards. - * + * * @param recogniser The token recogniser to insert. This value must not be `nil`. * @param other The token recogniser to insert before. * @exception Raises an `NSInvalidArgumentException` if recogniser is `nil` or if other is not in the tokeniser's priority queue. @@ -161,7 +161,7 @@ * Tokenises an input string by repeatedly using the recognisers in the tokeniser's priority list. * * If the entire input is tokenised a CPEOFToken is added to the end of the result token stream. If not, the token stream ends with no EOF token. - * + * * @param input The input string to tokenise. * @return Returns a token stream containing all tokens found in the input string. */ @@ -172,7 +172,7 @@ * * If the entire input is tokenised a CPEOFToken is added to the end of the result token stream. If not, the token stream ends with no EOF token. * This method can be useful for multithreading parsers, allowing you to create the token stream that the tokeniser writes to and pass it to both tokeniser and parser threads. - * + * * @param input The input string to tokenise. * @param tokenStream The token stream to add tokens to from the input string. */ diff --git a/CoreParse/Tokenisation/CPTokeniser.m b/CoreParse/Tokenisation/CPTokeniser.m index 60a0e1e..4347ec1 100644 --- a/CoreParse/Tokenisation/CPTokeniser.m +++ b/CoreParse/Tokenisation/CPTokeniser.m @@ -23,7 +23,7 @@ @interface CPTokeniser () -@property (readwrite, retain) NSMutableArray *tokenRecognisers; +@property (readwrite, strong) NSMutableArray *tokenRecognisers; - (void)addToken:(CPToken *)tok toStream:(CPTokenStream *)stream; - (void)advanceLineNumber:(NSUInteger *)ln columnNumber:(NSUInteger *)cn withInput:(NSString *)input range:(CFRange)range; @@ -69,12 +69,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:[self tokenRecognisers] forKey:CPTokeniserTokenRecognisersKey]; } -- (void)dealloc -{ - [tokenRecognisers release]; - - [super dealloc]; -} - (void)addTokenRecogniser:(id)recogniser { @@ -103,7 +97,7 @@ - (void)removeTokenRecogniser:(id)recogniser - (CPTokenStream *)tokenise:(NSString *)input { - CPTokenStream *stream = [[[CPTokenStream alloc] init] autorelease]; + CPTokenStream *stream = [[CPTokenStream alloc] init]; [self tokenise:input into:stream]; @@ -222,7 +216,7 @@ - (void)advanceLineNumber:(NSUInteger *)ln columnNumber:(NSUInteger *)cn withInp static dispatch_once_t onceToken; dispatch_once(&onceToken, ^ { - newlineCharset = (CFCharacterSetRef)[[NSCharacterSet characterSetWithCharactersInString:@"\n\r"] retain]; + newlineCharset = (CFCharacterSetRef)CFBridgingRetain([NSCharacterSet characterSetWithCharactersInString:@"\n\r"]); }); CFRange searchRange = range; diff --git a/CoreParse/Tokenisation/Token Recognisers/CPIdentifierRecogniser.m b/CoreParse/Tokenisation/Token Recognisers/CPIdentifierRecogniser.m index 28bf8a4..55d17e7 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPIdentifierRecogniser.m +++ b/CoreParse/Tokenisation/Token Recognisers/CPIdentifierRecogniser.m @@ -17,12 +17,12 @@ @implementation CPIdentifierRecogniser + (id)identifierRecogniser { - return [[[CPIdentifierRecogniser alloc] initWithInitialCharacters:nil identifierCharacters:nil] autorelease]; + return [[CPIdentifierRecogniser alloc] initWithInitialCharacters:nil identifierCharacters:nil]; } + (id)identifierRecogniserWithInitialCharacters:(NSCharacterSet *)initialCharacters identifierCharacters:(NSCharacterSet *)identifierCharacters { - return [[[CPIdentifierRecogniser alloc] initWithInitialCharacters:initialCharacters identifierCharacters:identifierCharacters] autorelease]; + return [[CPIdentifierRecogniser alloc] initWithInitialCharacters:initialCharacters identifierCharacters:identifierCharacters]; } - (id)initWithInitialCharacters:(NSCharacterSet *)initInitialCharacters identifierCharacters:(NSCharacterSet *)initIdentifierCharacters @@ -60,14 +60,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:[self identifierCharacters] forKey:CPIdentifierRecogniserIdentifierCharactersKey]; } -- (void)dealloc -{ - [initialCharacters release]; - [identifierCharacters release]; - - [super dealloc]; -} - - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition { NSCharacterSet *identifierStartCharacters = nil == [self initialCharacters] ? [NSCharacterSet characterSetWithCharactersInString: @@ -89,12 +81,12 @@ - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition BOOL success = [scanner scanCharactersFromSet:idCharacters intoString:&identifierString]; if (success) { - identifierString = [[[[NSString alloc] initWithCharacters:&firstChar length:1] autorelease] stringByAppendingString:identifierString]; + identifierString = [[[NSString alloc] initWithCharacters:&firstChar length:1] stringByAppendingString:identifierString]; *tokenPosition = [scanner scanLocation]; } else { - identifierString = [[[NSString alloc] initWithCharacters:&firstChar length:1] autorelease]; + identifierString = [[NSString alloc] initWithCharacters:&firstChar length:1]; *tokenPosition += 1; } return [CPIdentifierToken tokenWithIdentifier:identifierString]; diff --git a/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.h b/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.h index e72661b..7f6bf65 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.h +++ b/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.h @@ -82,11 +82,11 @@ /** * The keyword that the recogniser should attempt to recognise. */ -@property (readwrite,retain,nonatomic) NSString *keyword; +@property (readwrite,strong,nonatomic) NSString *keyword; /** * A set of characters that may not follow the keyword. */ -@property (readwrite,retain,nonatomic) NSCharacterSet *invalidFollowingCharacters; +@property (readwrite,strong,nonatomic) NSCharacterSet *invalidFollowingCharacters; @end diff --git a/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.m b/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.m index 9037d34..08df3a1 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.m +++ b/CoreParse/Tokenisation/Token Recognisers/CPKeywordRecogniser.m @@ -15,7 +15,7 @@ @implementation CPKeywordRecogniser + (id)recogniserForKeyword:(NSString *)keyword { - return [[[self alloc] initWithKeyword:keyword] autorelease]; + return [[self alloc] initWithKeyword:keyword]; } - (id)initWithKeyword:(NSString *)initKeyword @@ -25,7 +25,7 @@ - (id)initWithKeyword:(NSString *)initKeyword + (id)recogniserForKeyword:(NSString *)keyword invalidFollowingCharacters:(NSCharacterSet *)invalidFollowingCharacters { - return [[[self alloc] initWithKeyword:keyword invalidFollowingCharacters:invalidFollowingCharacters] autorelease]; + return [[self alloc] initWithKeyword:keyword invalidFollowingCharacters:invalidFollowingCharacters]; } - (id)initWithKeyword:(NSString *)initKeyword invalidFollowingCharacters:(NSCharacterSet *)initInvalidFollowingCharacters @@ -68,14 +68,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:[self invalidFollowingCharacters] forKey:CPKeywordRecogniserInvalidFollowingCharactersKey]; } -- (void)dealloc -{ - [keyword release]; - [invalidFollowingCharacters release]; - - [super dealloc]; -} - - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition { NSUInteger kwLength = [keyword length]; diff --git a/CoreParse/Tokenisation/Token Recognisers/CPNumberRecogniser.m b/CoreParse/Tokenisation/Token Recognisers/CPNumberRecogniser.m index 1cabf7e..39f6e85 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPNumberRecogniser.m +++ b/CoreParse/Tokenisation/Token Recognisers/CPNumberRecogniser.m @@ -39,7 +39,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder + (id)integerRecogniser { - CPNumberRecogniser *rec = [[[CPNumberRecogniser alloc] init] autorelease]; + CPNumberRecogniser *rec =[[CPNumberRecogniser alloc] init]; [rec setRecognisesInts:YES]; [rec setRecognisesFloats:NO]; return rec; @@ -47,7 +47,7 @@ + (id)integerRecogniser + (id)floatRecogniser { - CPNumberRecogniser *rec = [[[CPNumberRecogniser alloc] init] autorelease]; + CPNumberRecogniser *rec = [[CPNumberRecogniser alloc] init]; [rec setRecognisesInts:NO]; [rec setRecognisesFloats:YES]; return rec; @@ -55,7 +55,7 @@ + (id)floatRecogniser + (id)numberRecogniser { - CPNumberRecogniser *rec = [[[CPNumberRecogniser alloc] init] autorelease]; + CPNumberRecogniser *rec = [[CPNumberRecogniser alloc] init]; [rec setRecognisesInts:YES]; [rec setRecognisesFloats:YES]; return rec; diff --git a/CoreParse/Tokenisation/Token Recognisers/CPQuotedRecogniser.m b/CoreParse/Tokenisation/Token Recognisers/CPQuotedRecogniser.m index a5eeeea..55cc532 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPQuotedRecogniser.m +++ b/CoreParse/Tokenisation/Token Recognisers/CPQuotedRecogniser.m @@ -31,7 +31,7 @@ + (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString * + (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence maximumLength:(NSUInteger)maximumLength name:(NSString *)name { - return [[[CPQuotedRecogniser alloc] initWithStartQuote:startQuote endQuote:endQuote escapeSequence:escapeSequence maximumLength:maximumLength name:name] autorelease]; + return [[CPQuotedRecogniser alloc] initWithStartQuote:startQuote endQuote:endQuote escapeSequence:escapeSequence maximumLength:maximumLength name:name]; } - (id)initWithStartQuote:(NSString *)initStartQuote endQuote:(NSString *)initEndQuote escapeSequence:(NSString *)initEscapeSequence maximumLength:(NSUInteger)initMaximumLength name:(NSString *)initName @@ -93,17 +93,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:[self name] forKey:CPQuotedRecogniserNameKey]; } -- (void)dealloc -{ - [startQuote release]; - [endQuote release]; - [escapeSequence release]; - [escapeReplacer release]; - [name release]; - - [super dealloc]; -} - - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition { NSString *(^er)(NSString *tokenStream, NSUInteger *quotePosition) = [self escapeReplacer]; @@ -135,8 +124,7 @@ - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition CFStringRef substr = CFStringCreateWithSubstring(kCFAllocatorDefault, (CFStringRef)tokenString, CFRangeMake(searchRange.location, endRange.location - searchRange.location)); CFStringAppend(outputString, substr); CFRelease(substr); - CPQuotedToken *t = [CPQuotedToken content:(NSString *)outputString quotedWith:startQuote name:[self name]]; - CFRelease(outputString); + CPQuotedToken *t = [CPQuotedToken content:(NSString *)CFBridgingRelease(outputString) quotedWith:startQuote name:[self name]]; return t; } else diff --git a/CoreParse/Tokenisation/Token Recognisers/CPRegexpRecogniser.m b/CoreParse/Tokenisation/Token Recognisers/CPRegexpRecogniser.m index e00f7e2..93620fc 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPRegexpRecogniser.m +++ b/CoreParse/Tokenisation/Token Recognisers/CPRegexpRecogniser.m @@ -31,14 +31,7 @@ - (id)initWithRegexp:(NSRegularExpression *)initRegexp matchHandler:(CPRegexpKey + (id)recogniserForRegexp:(NSRegularExpression *)regexp matchHandler:(CPRegexpKeywordRecogniserMatchHandler)initMatchHandler { - return [[[self alloc] initWithRegexp:regexp matchHandler:initMatchHandler] autorelease]; -} - -- (void)dealloc -{ - [matchHandler release]; - [regexp release]; - [super dealloc]; + return [[self alloc] initWithRegexp:regexp matchHandler:initMatchHandler]; } #pragma mark - NSCoder diff --git a/CoreParse/Tokenisation/Token Recognisers/CPWhiteSpaceRecogniser.m b/CoreParse/Tokenisation/Token Recognisers/CPWhiteSpaceRecogniser.m index 347e647..57cb532 100644 --- a/CoreParse/Tokenisation/Token Recognisers/CPWhiteSpaceRecogniser.m +++ b/CoreParse/Tokenisation/Token Recognisers/CPWhiteSpaceRecogniser.m @@ -23,7 +23,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder + (id)whiteSpaceRecogniser { - return [[[CPWhiteSpaceRecogniser alloc] init] autorelease]; + return [[CPWhiteSpaceRecogniser alloc] init]; } - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition diff --git a/CoreParse/Tokenisation/Token Types/CPEOFToken.m b/CoreParse/Tokenisation/Token Types/CPEOFToken.m index 98a942f..10b52d5 100644 --- a/CoreParse/Tokenisation/Token Types/CPEOFToken.m +++ b/CoreParse/Tokenisation/Token Types/CPEOFToken.m @@ -12,7 +12,7 @@ @implementation CPEOFToken + (id)eof { - return [[[CPEOFToken alloc] init] autorelease]; + return [[CPEOFToken alloc] init]; } - (NSString *)name diff --git a/CoreParse/Tokenisation/Token Types/CPErrorToken.m b/CoreParse/Tokenisation/Token Types/CPErrorToken.m index ebadde4..a8ed0ae 100644 --- a/CoreParse/Tokenisation/Token Types/CPErrorToken.m +++ b/CoreParse/Tokenisation/Token Types/CPErrorToken.m @@ -14,7 +14,7 @@ @implementation CPErrorToken + (id)errorWithMessage:(NSString *)errorMessage { - return [[[self alloc] initWithMesage:errorMessage] autorelease]; + return [[self alloc] initWithMesage:errorMessage]; } - (id)initWithMesage:(NSString *)initErrorMessage @@ -29,13 +29,6 @@ - (id)initWithMesage:(NSString *)initErrorMessage return self; } -- (void)dealloc -{ - [errorMessage release]; - - [super dealloc]; -} - - (NSString *)name { return @"Error"; diff --git a/CoreParse/Tokenisation/Token Types/CPIdentifierToken.m b/CoreParse/Tokenisation/Token Types/CPIdentifierToken.m index 935aa60..c8a6729 100644 --- a/CoreParse/Tokenisation/Token Types/CPIdentifierToken.m +++ b/CoreParse/Tokenisation/Token Types/CPIdentifierToken.m @@ -17,7 +17,7 @@ @implementation CPIdentifierToken + (id)tokenWithIdentifier:(NSString *)identifier { - return [[(CPIdentifierToken *)[CPIdentifierToken alloc] initWithIdentifier:identifier] autorelease]; + return [(CPIdentifierToken *)[CPIdentifierToken alloc] initWithIdentifier:identifier]; } - (id)initWithIdentifier:(NSString *)initIdentifier @@ -37,12 +37,6 @@ - (id)init return [self initWithIdentifier:@""]; } -- (void)dealloc -{ - [identifier release]; - - [super dealloc]; -} - (NSString *)description { diff --git a/CoreParse/Tokenisation/Token Types/CPKeywordToken.m b/CoreParse/Tokenisation/Token Types/CPKeywordToken.m index b78ba41..7c640b8 100644 --- a/CoreParse/Tokenisation/Token Types/CPKeywordToken.m +++ b/CoreParse/Tokenisation/Token Types/CPKeywordToken.m @@ -14,7 +14,7 @@ @implementation CPKeywordToken + (id)tokenWithKeyword:(NSString *)keyword { - return [[[CPKeywordToken alloc] initWithKeyword:keyword] autorelease]; + return [[CPKeywordToken alloc] initWithKeyword:keyword]; } - (id)initWithKeyword:(NSString *)initKeyword @@ -34,11 +34,6 @@ - (id)init return [self initWithKeyword:@" "]; } -- (void)dealloc -{ - [keyword release]; - [super dealloc]; -} - (NSString *)description { diff --git a/CoreParse/Tokenisation/Token Types/CPNumberToken.m b/CoreParse/Tokenisation/Token Types/CPNumberToken.m index f99ed7a..3a8bcaf 100644 --- a/CoreParse/Tokenisation/Token Types/CPNumberToken.m +++ b/CoreParse/Tokenisation/Token Types/CPNumberToken.m @@ -14,7 +14,7 @@ @implementation CPNumberToken + (id)tokenWithNumber:(NSNumber *)number { - return [[[CPNumberToken alloc] initWithNumber:number] autorelease]; + return [[CPNumberToken alloc] initWithNumber:number]; } - (id)initWithNumber:(NSNumber *)initNumber @@ -34,11 +34,6 @@ - (id)init return [self initWithNumber:[NSNumber numberWithInteger:0]]; } -- (void)dealloc -{ - [number release]; - [super dealloc]; -} - (NSString *)description { diff --git a/CoreParse/Tokenisation/Token Types/CPQuotedToken.m b/CoreParse/Tokenisation/Token Types/CPQuotedToken.m index 40ae63e..c2d39a7 100644 --- a/CoreParse/Tokenisation/Token Types/CPQuotedToken.m +++ b/CoreParse/Tokenisation/Token Types/CPQuotedToken.m @@ -22,7 +22,7 @@ @implementation CPQuotedToken + (id)content:(NSString *)content quotedWith:(NSString *)quoteType name:(NSString *)name { - return [[[CPQuotedToken alloc] initWithContent:content quoteType:quoteType name:name] autorelease]; + return [[CPQuotedToken alloc] initWithContent:content quoteType:quoteType name:name]; } - (id)initWithContent:(NSString *)initContent quoteType:(NSString *)initQuoteType name:(NSString *)initName @@ -44,15 +44,6 @@ - (id)init return [self initWithContent:@"" quoteType:@"" name:@""]; } -- (void)dealloc -{ - [content release]; - [quoteType release]; - [name release]; - - [super dealloc]; -} - - (NSString *)description { return [NSString stringWithFormat:@"<%@: %@>", [self name], [self content]]; diff --git a/CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.m b/CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.m index 16410a9..9585edb 100644 --- a/CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.m +++ b/CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.m @@ -14,7 +14,7 @@ @implementation CPWhiteSpaceToken + (id)whiteSpace:(NSString *)whiteSpace { - return [[[CPWhiteSpaceToken alloc] initWithWhiteSpace:whiteSpace] autorelease]; + return [[CPWhiteSpaceToken alloc] initWithWhiteSpace:whiteSpace]; } - (id)initWithWhiteSpace:(NSString *)initWhiteSpace @@ -34,13 +34,6 @@ - (id)init return [self initWithWhiteSpace:@""]; } -- (void)dealloc -{ - [whiteSpace release]; - - [super dealloc]; -} - - (NSString *)name { return @"Whitespace";