Skip to content
Browse files

ARC compatible

  • Loading branch information...
1 parent ac0d944 commit c954d5162eeeab7e4b5a5046117d3ae6ca7d1c6a @davedelong committed Sep 29, 2011
View
6 DDMathParser/DDExpression.m
@@ -24,15 +24,15 @@ + (id) expressionFromString:(NSString *)expressionString error:(NSError **)error
}
+ (id) numberExpressionWithNumber:(NSNumber *)number {
- return [[[_DDNumberExpression alloc] initWithNumber:number] autorelease];
+ return AUTORELEASE([[_DDNumberExpression alloc] initWithNumber:number]);
}
+ (id) functionExpressionWithFunction:(NSString *)function arguments:(NSArray *)arguments error:(NSError **)error {
- return [[[_DDFunctionExpression alloc] initWithFunction:function arguments:arguments error:error] autorelease];
+ return AUTORELEASE([[_DDFunctionExpression alloc] initWithFunction:function arguments:arguments error:error]);
}
+ (id) variableExpressionWithVariable:(NSString *)variable {
- return [[[_DDVariableExpression alloc] initWithVariable:variable] autorelease];
+ return AUTORELEASE([[_DDVariableExpression alloc] initWithVariable:variable]);
}
#pragma mark -
View
6 DDMathParser/DDMathEvaluator.m
@@ -56,10 +56,12 @@ - (void) dealloc {
if (self == _sharedEvaluator) {
_sharedEvaluator = nil;
}
+#if !HAS_ARC
[functions release];
[functionMap release];
[rewriteRules release];
[super dealloc];
+#endif
}
#pragma mark - Functions
@@ -73,7 +75,7 @@ - (BOOL) registerFunction:(DDMathFunction)function forName:(NSString *)functionN
_DDFunctionContainer *container = [[_DDFunctionContainer alloc] initWithFunction:function name:name];
[functions addObject:container];
[functionMap setObject:container forKey:name];
- [container release];
+ RELEASE(container);
return YES;
}
@@ -359,7 +361,7 @@ - (void) _registerStandardFunctions {
_DDFunctionContainer *container = [[_DDFunctionContainer alloc] initWithFunction:function name:functionName];
[functions addObject:container];
[functionMap setObject:container forKey:functionName];
- [container release];
+ RELEASE(container);
} else {
NSLog(@"error registering function: %@", functionName);
}
View
4 DDMathParser/DDMathStringToken.m
@@ -11,11 +11,13 @@
@implementation DDMathStringToken
@synthesize token, tokenType, operatorType, operatorPrecedence, operatorArity;
+#if !HAS_ARC
- (void) dealloc {
[token release];
[numberValue release];
[super dealloc];
}
+#endif
- (id) initWithToken:(NSString *)t type:(DDTokenType)type {
self = [super init];
@@ -108,7 +110,7 @@ - (id) initWithToken:(NSString *)t type:(DDTokenType)type {
}
+ (id) mathStringTokenWithToken:(NSString *)t type:(DDTokenType)type {
- return [[[self alloc] initWithToken:t type:type] autorelease];
+ return AUTORELEASE([[self alloc] initWithToken:t type:type]);
}
- (NSNumber *) numberValue {
View
15 DDMathParser/DDMathStringTokenizer.m
@@ -40,7 +40,7 @@ + (NSCharacterSet *)_operatorCharacterSet {
static dispatch_once_t onceToken;
static NSCharacterSet *_operatorSet = nil;
dispatch_once(&onceToken, ^{
- _operatorSet = [[NSCharacterSet characterSetWithCharactersInString:@"+-*/&|!%^~()<>,x"] retain];
+ _operatorSet = RETAIN([NSCharacterSet characterSetWithCharactersInString:@"+-*/&|!%^~()<>,x"]);
});
return _operatorSet;
}
@@ -63,13 +63,13 @@ + (NSCharacterSet *)_singleCharacterFunctionCharacterSet {
static NSCharacterSet *_singleCharFunctionSet = nil;
dispatch_once(&onceToken, ^{
NSString *singleChars = [NSString stringWithFormat:@"\u03C0\u03D5\u03C4"]; // π, ϕ, and τ
- _singleCharFunctionSet = [[NSCharacterSet characterSetWithCharactersInString:singleChars] retain];
+ _singleCharFunctionSet = RETAIN([NSCharacterSet characterSetWithCharactersInString:singleChars]);
});
return _singleCharFunctionSet;
}
+ (id)tokenizerWithString:(NSString *)expressionString error:(NSError **)error {
- return [[[self alloc] initWithString:expressionString error:error] autorelease];
+ return AUTORELEASE([[self alloc] initWithString:expressionString error:error]);
}
- (id)initWithString:(NSString *)expressionString error:(NSError **)error {
@@ -87,13 +87,14 @@ - (id)initWithString:(NSString *)expressionString error:(NSError **)error {
DDMathStringToken *token = nil;
while((token = [self _nextTokenWithError:error]) != nil) {
if (![self _processToken:token withError:error]) {
- [self release];
+ RELEASE(self);
return nil;
}
}
if (error && *error) {
- [self release], self = nil;
+ RELEASE(self);
+ self = nil;
} else {
[self _processToken:nil withError:nil];
}
@@ -104,8 +105,10 @@ - (id)initWithString:(NSString *)expressionString error:(NSError **)error {
- (void)dealloc {
free(_characters);
+#if !HAS_ARC
[_tokens release];
[super dealloc];
+#endif
}
- (BOOL)_processToken:(DDMathStringToken *)token withError:(NSError **)error {
@@ -240,7 +243,7 @@ - (void)appendToken:(DDMathStringToken *)token {
#pragma mark Character methods
- (NSArray *)tokens {
- return [[_tokens copy] autorelease];
+ return AUTORELEASE([_tokens copy]);
}
- (DDMathStringToken *) nextToken {
DDMathStringToken *t = [self peekNextToken];
View
23 DDMathParser/DDParser.m
@@ -80,7 +80,7 @@ + (void) setDefaultPowerAssociativity:(DDOperatorAssociativity)newAssociativity
+ (id) parserWithString:(NSString *)string error:(NSError **)error {
- return [[[self alloc] initWithString:string error:error] autorelease];
+ return AUTORELEASE([[self alloc] initWithString:string error:error]);
}
- (id) initWithString:(NSString *)string error:(NSError **)error {
@@ -89,16 +89,16 @@ - (id) initWithString:(NSString *)string error:(NSError **)error {
}
+ (id)parserWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)error {
- return [[[self alloc] initWithTokenizer:tokenizer error:error] autorelease];
+ return AUTORELEASE([[self alloc] initWithTokenizer:tokenizer error:error]);
}
- (id)initWithTokenizer:(DDMathStringTokenizer *)t error:(NSError **)error {
ERR_ASSERT(error);
self = [super init];
if (self) {
- tokenizer = [t retain];
+ tokenizer = RETAIN(t);
if (!tokenizer) {
- [self release];
+ RELEASE(self);
return nil;
}
@@ -115,10 +115,12 @@ - (id)initWithTokenizer:(DDMathStringTokenizer *)t error:(NSError **)error {
return self;
}
+#if !HAS_ARC
- (void) dealloc {
[tokenizer release];
[super dealloc];
}
+#endif
- (DDOperatorAssociativity) associativityForOperator:(DDOperator)operatorType {
switch (operatorType) {
@@ -154,7 +156,11 @@ - (DDExpression *) parsedExpressionWithError:(NSError **)error {
DDExpression *expression = nil;
+#if HAS_ARC
+ @autoreleasepool {
+#else
NSAutoreleasePool * parserPool = [[NSAutoreleasePool alloc] init];
+#endif
_DDParserTerm *root = [_DDParserTerm rootTermWithTokenizer:tokenizer error:error];
if (!root) {
@@ -165,14 +171,19 @@ - (DDExpression *) parsedExpressionWithError:(NSError **)error {
goto errorExit;
}
- expression = [[root expressionWithError:error] retain];
+ expression = RETAIN([root expressionWithError:error]);
errorExit:
+#if HAS_ARC
+ ;
+ }
+#else
[*error retain];
[parserPool drain];
[*error autorelease];
+#endif
- return [expression autorelease];
+ return AUTORELEASE(expression);
}
@end
View
2 DDMathParser/_DDFunctionContainer.h
@@ -12,7 +12,7 @@
@interface _DDFunctionContainer : NSObject
@property (nonatomic,copy) DDMathFunction function;
-@property (nonatomic,readonly) NSSet *aliases;
+@property (nonatomic,readonly,strong) NSSet *aliases;
+ (NSString *)normalizedAlias:(NSString *)alias;
View
2 DDMathParser/_DDFunctionContainer.m
@@ -26,11 +26,13 @@ - (id)initWithFunction:(DDMathFunction)f name:(NSString *)name {
return self;
}
+#if !HAS_ARC
- (void)dealloc {
[function release];
[aliases release];
[super dealloc];
}
+#endif
- (NSMutableSet *)_aliases {
return (NSMutableSet *)aliases;
View
5 DDMathParser/_DDFunctionExpression.m
@@ -24,7 +24,7 @@ - (id) initWithFunction:(NSString *)f arguments:(NSArray *)a error:(NSError **)e
*error = ERR_GENERIC(@"function arguments must be DDExpression objects");
*error = nil;
}
- [self release];
+ RELEASE(self);
return nil;
}
}
@@ -46,11 +46,14 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:[self arguments] forKey:@"arguments"];
}
+#if !HAS_ARC
- (void) dealloc {
[function release];
[arguments release];
[super dealloc];
}
+#endif
+
- (DDExpressionType) expressionType { return DDExpressionTypeFunction; }
- (NSString *) function { return [function lowercaseString]; }
View
2 DDMathParser/_DDFunctionTerm.h
@@ -10,7 +10,7 @@
@interface _DDFunctionTerm : _DDGroupTerm
-@property (nonatomic,readonly) NSString *functionName;
+@property (nonatomic,readonly,strong) NSString *functionName;
- (id)_initWithFunction:(NSString *)function subterms:(NSArray *)terms error:(NSError **)error;
View
6 DDMathParser/_DDFunctionTerm.m
@@ -45,7 +45,7 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
if (parameterGroup) {
[newSubterms addObject:parameterGroup];
}
- [parameterGroup release];
+ RELEASE(parameterGroup);
} else {
// there's only one term in this parameter; no need to group it in parentheses
[newSubterms addObject:[parameterGroupTerms objectAtIndex:0]];
@@ -66,7 +66,7 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
NSArray *lastParameters = [[self subterms] subarrayWithRange:rangeOfLastParameter];
_DDGroupTerm *parameterGroup = [[_DDGroupTerm alloc] _initWithSubterms:lastParameters error:error];
[newSubterms addObject:parameterGroup];
- [parameterGroup release];
+ RELEASE(parameterGroup);
} else if (rangeOfLastParameter.length == 1) {
[newSubterms addObject:[[self subterms] objectAtIndex:rangeOfLastParameter.location]];
}
@@ -78,10 +78,12 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
return self;
}
+#if !HAS_ARC
- (void)dealloc {
[functionName release];
[super dealloc];
}
+#endif
- (DDParserTermType)type { return DDParserTermTypeFunction; }
View
158 DDMathParser/_DDFunctionUtilities.m
@@ -45,7 +45,7 @@ + (DDMathFunction) addFunction {
NSNumber *result = [NSNumber numberWithDouble:[firstValue doubleValue] + [secondValue doubleValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) subtractFunction {
@@ -59,7 +59,7 @@ + (DDMathFunction) subtractFunction {
NSNumber *result = [NSNumber numberWithDouble:[firstValue doubleValue] - [secondValue doubleValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) multiplyFunction {
@@ -73,7 +73,7 @@ + (DDMathFunction) multiplyFunction {
NSNumber *result = [NSNumber numberWithDouble:[firstValue doubleValue] * [secondValue doubleValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) divideFunction {
@@ -87,7 +87,7 @@ + (DDMathFunction) divideFunction {
NSNumber *result = [NSNumber numberWithDouble:[firstValue doubleValue] / [secondValue doubleValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) modFunction {
@@ -101,7 +101,7 @@ + (DDMathFunction) modFunction {
NSNumber *result = [NSNumber numberWithDouble:fmod([firstValue doubleValue], [secondValue doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) negateFunction {
@@ -113,7 +113,7 @@ + (DDMathFunction) negateFunction {
NSNumber *result = [NSNumber numberWithDouble:-1 * [firstValue doubleValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) factorialFunction {
@@ -125,7 +125,7 @@ + (DDMathFunction) factorialFunction {
NSNumber *result = [NSNumber numberWithDouble:tgamma([firstValue doubleValue]+1)];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) powFunction {
@@ -139,7 +139,7 @@ + (DDMathFunction) powFunction {
NSNumber *result = [NSNumber numberWithDouble:pow([base doubleValue], [exponent doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) nthrootFunction {
@@ -153,7 +153,7 @@ + (DDMathFunction) nthrootFunction {
NSNumber *result = [NSNumber numberWithDouble:pow([base doubleValue], 1/[root doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) andFunction {
@@ -167,7 +167,7 @@ + (DDMathFunction) andFunction {
NSNumber * result = [NSNumber numberWithInteger:([first integerValue] & [second integerValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) orFunction {
@@ -181,7 +181,7 @@ + (DDMathFunction) orFunction {
NSNumber * result = [NSNumber numberWithInteger:([first integerValue] | [second integerValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) notFunction {
@@ -193,7 +193,7 @@ + (DDMathFunction) notFunction {
NSNumber * result = [NSNumber numberWithInteger:(~[first integerValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) xorFunction {
@@ -207,7 +207,7 @@ + (DDMathFunction) xorFunction {
NSNumber * result = [NSNumber numberWithInteger:([first integerValue] ^ [second integerValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) rshiftFunction {
@@ -221,7 +221,7 @@ + (DDMathFunction) rshiftFunction {
NSNumber * result = [NSNumber numberWithInteger:[first integerValue] >> [second integerValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) lshiftFunction {
@@ -235,7 +235,7 @@ + (DDMathFunction) lshiftFunction {
NSNumber * result = [NSNumber numberWithInteger:[first integerValue] << [second integerValue]];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) averageFunction {
@@ -249,7 +249,7 @@ + (DDMathFunction) averageFunction {
NSNumber *avg = [NSNumber numberWithDouble:sum / [arguments count]];
return [DDExpression numberExpressionWithNumber:avg];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) sumFunction {
@@ -269,7 +269,7 @@ + (DDMathFunction) sumFunction {
NSNumber *result = [NSNumber numberWithDouble:sum];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) countFunction {
@@ -278,7 +278,7 @@ + (DDMathFunction) countFunction {
REQUIRE_GTOE_N_ARGS(1);
return [DDExpression numberExpressionWithNumber:[NSDecimalNumber decimalNumberWithMantissa:[arguments count] exponent:0 isNegative:NO]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) minFunction {
@@ -297,7 +297,7 @@ + (DDMathFunction) minFunction {
}
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) maxFunction {
@@ -316,7 +316,7 @@ + (DDMathFunction) maxFunction {
}
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) medianFunction {
@@ -343,7 +343,7 @@ + (DDMathFunction) medianFunction {
}
return [DDExpression numberExpressionWithNumber:median];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) stddevFunction {
@@ -368,7 +368,7 @@ + (DDMathFunction) stddevFunction {
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) sqrtFunction {
@@ -380,7 +380,7 @@ + (DDMathFunction) sqrtFunction {
NSNumber *result = [NSNumber numberWithDouble:sqrt([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) randomFunction {
@@ -424,7 +424,7 @@ + (DDMathFunction) randomFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithLongLong:random]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) logFunction {
@@ -436,7 +436,7 @@ + (DDMathFunction) logFunction {
NSNumber *result = [NSNumber numberWithDouble:log10([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) lnFunction {
@@ -446,7 +446,7 @@ + (DDMathFunction) lnFunction {
RETURN_IF_NIL(n);
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:log([n doubleValue])]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) log2Function {
@@ -458,7 +458,7 @@ + (DDMathFunction) log2Function {
NSNumber *result = [NSNumber numberWithDouble:log2([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) expFunction {
@@ -470,7 +470,7 @@ + (DDMathFunction) expFunction {
NSNumber *result = [NSNumber numberWithDouble:exp([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) ceilFunction {
@@ -482,7 +482,7 @@ + (DDMathFunction) ceilFunction {
NSNumber *result = [NSNumber numberWithDouble:ceil([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) absFunction {
@@ -494,7 +494,7 @@ + (DDMathFunction) absFunction {
NSNumber *result = [NSNumber numberWithLongLong:llabs([n longLongValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) floorFunction {
@@ -506,7 +506,7 @@ + (DDMathFunction) floorFunction {
NSNumber *result = [NSNumber numberWithDouble:floor([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) sinFunction {
@@ -518,7 +518,7 @@ + (DDMathFunction) sinFunction {
NSNumber *result = [NSNumber numberWithDouble:sin([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) cosFunction {
@@ -530,7 +530,7 @@ + (DDMathFunction) cosFunction {
NSNumber *result = [NSNumber numberWithDouble:cos([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) tanFunction {
@@ -542,7 +542,7 @@ + (DDMathFunction) tanFunction {
NSNumber *result = [NSNumber numberWithDouble:tan([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) asinFunction {
@@ -554,7 +554,7 @@ + (DDMathFunction) asinFunction {
NSNumber *result = [NSNumber numberWithDouble:asin([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) acosFunction {
@@ -566,7 +566,7 @@ + (DDMathFunction) acosFunction {
NSNumber *result = [NSNumber numberWithDouble:acos([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) atanFunction {
@@ -578,7 +578,7 @@ + (DDMathFunction) atanFunction {
NSNumber *result = [NSNumber numberWithDouble:atan([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) sinhFunction {
@@ -590,7 +590,7 @@ + (DDMathFunction) sinhFunction {
NSNumber *result = [NSNumber numberWithDouble:sinh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) coshFunction {
@@ -602,7 +602,7 @@ + (DDMathFunction) coshFunction {
NSNumber *result = [NSNumber numberWithDouble:cosh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) tanhFunction {
@@ -614,7 +614,7 @@ + (DDMathFunction) tanhFunction {
NSNumber *result = [NSNumber numberWithDouble:tanh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) asinhFunction {
@@ -626,7 +626,7 @@ + (DDMathFunction) asinhFunction {
NSNumber *result = [NSNumber numberWithDouble:asinh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) acoshFunction {
@@ -638,7 +638,7 @@ + (DDMathFunction) acoshFunction {
NSNumber *result = [NSNumber numberWithDouble:acosh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) atanhFunction {
@@ -650,7 +650,7 @@ + (DDMathFunction) atanhFunction {
NSNumber *result = [NSNumber numberWithDouble:atanh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) cscFunction {
@@ -662,7 +662,7 @@ + (DDMathFunction) cscFunction {
NSNumber *result = [NSNumber numberWithDouble:1/sin([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) secFunction {
@@ -674,7 +674,7 @@ + (DDMathFunction) secFunction {
NSNumber *result = [NSNumber numberWithDouble:1/cos([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) cotanFunction {
@@ -686,7 +686,7 @@ + (DDMathFunction) cotanFunction {
NSNumber *result = [NSNumber numberWithDouble:1/tan([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) acscFunction {
@@ -698,7 +698,7 @@ + (DDMathFunction) acscFunction {
NSNumber *result = [NSNumber numberWithDouble:1/asin([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) asecFunction {
@@ -710,7 +710,7 @@ + (DDMathFunction) asecFunction {
NSNumber *result = [NSNumber numberWithDouble:1/acos([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) acotanFunction {
@@ -722,7 +722,7 @@ + (DDMathFunction) acotanFunction {
NSNumber *result = [NSNumber numberWithDouble:1/atan([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) cschFunction {
@@ -734,7 +734,7 @@ + (DDMathFunction) cschFunction {
NSNumber *result = [NSNumber numberWithDouble:1/sinh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) sechFunction {
@@ -746,7 +746,7 @@ + (DDMathFunction) sechFunction {
NSNumber *result = [NSNumber numberWithDouble:1/cosh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) cotanhFunction {
@@ -758,7 +758,7 @@ + (DDMathFunction) cotanhFunction {
NSNumber *result = [NSNumber numberWithDouble:1/tanh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) acschFunction {
@@ -770,7 +770,7 @@ + (DDMathFunction) acschFunction {
NSNumber *result = [NSNumber numberWithDouble:1/sinh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) asechFunction {
@@ -782,7 +782,7 @@ + (DDMathFunction) asechFunction {
NSNumber *result = [NSNumber numberWithDouble:1/cosh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) acotanhFunction {
@@ -794,7 +794,7 @@ + (DDMathFunction) acotanhFunction {
NSNumber *result = [NSNumber numberWithDouble:1/atanh([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
// more trig functions
@@ -807,7 +807,7 @@ + (DDMathFunction) versinFunction {
NSNumber *result = [NSNumber numberWithDouble:1-cos([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) vercosinFunction {
@@ -819,7 +819,7 @@ + (DDMathFunction) vercosinFunction {
NSNumber *result = [NSNumber numberWithDouble:1+cos([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) coversinFunction {
@@ -831,7 +831,7 @@ + (DDMathFunction) coversinFunction {
NSNumber *result = [NSNumber numberWithDouble:1-sin([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) covercosinFunction {
@@ -843,7 +843,7 @@ + (DDMathFunction) covercosinFunction {
NSNumber *result = [NSNumber numberWithDouble:1+sin([n doubleValue])];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) haversinFunction {
@@ -855,7 +855,7 @@ + (DDMathFunction) haversinFunction {
NSNumber *result = [NSNumber numberWithDouble:(1-cos([n doubleValue]))/2];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) havercosinFunction {
@@ -867,7 +867,7 @@ + (DDMathFunction) havercosinFunction {
NSNumber *result = [NSNumber numberWithDouble:(1+cos([n doubleValue]))/2];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) hacoversinFunction {
@@ -879,7 +879,7 @@ + (DDMathFunction) hacoversinFunction {
NSNumber *result = [NSNumber numberWithDouble:(1-sin([n doubleValue]))/2];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) hacovercosinFunction {
@@ -891,7 +891,7 @@ + (DDMathFunction) hacovercosinFunction {
NSNumber *result = [NSNumber numberWithDouble:(1+sin([n doubleValue]))/2];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) exsecFunction {
@@ -903,7 +903,7 @@ + (DDMathFunction) exsecFunction {
NSNumber *result = [NSNumber numberWithDouble:(1/cos([n doubleValue]))-1];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) excscFunction {
@@ -915,7 +915,7 @@ + (DDMathFunction) excscFunction {
NSNumber *result = [NSNumber numberWithDouble:(1/sin([n doubleValue]))-1];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) crdFunction {
@@ -927,7 +927,7 @@ + (DDMathFunction) crdFunction {
NSNumber *result = [NSNumber numberWithDouble:2*sin([n doubleValue]/2)];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) dtorFunction {
@@ -939,7 +939,7 @@ + (DDMathFunction) dtorFunction {
NSNumber *result = [NSNumber numberWithDouble:[n doubleValue]/180 * M_PI];
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) rtodFunction {
@@ -952,7 +952,7 @@ + (DDMathFunction) rtodFunction {
return [DDExpression numberExpressionWithNumber:result];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
#pragma mark Constant Functions
@@ -964,7 +964,7 @@ + (DDMathFunction) phiFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:1.6180339887498948]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) piFunction {
@@ -974,7 +974,7 @@ + (DDMathFunction) piFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_PI]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) pi_2Function {
@@ -984,7 +984,7 @@ + (DDMathFunction) pi_2Function {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_PI_2]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) pi_4Function {
@@ -994,7 +994,7 @@ + (DDMathFunction) pi_4Function {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_PI_4]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) tauFunction {
@@ -1004,7 +1004,7 @@ + (DDMathFunction) tauFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:2*M_PI]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) sqrt2Function {
@@ -1014,7 +1014,7 @@ + (DDMathFunction) sqrt2Function {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_SQRT2]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) eFunction {
@@ -1024,7 +1024,7 @@ + (DDMathFunction) eFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_E]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) log2eFunction {
@@ -1034,7 +1034,7 @@ + (DDMathFunction) log2eFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_LOG2E]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) log10eFunction {
@@ -1044,7 +1044,7 @@ + (DDMathFunction) log10eFunction {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_LOG10E]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) ln2Function {
@@ -1054,7 +1054,7 @@ + (DDMathFunction) ln2Function {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_LN2]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
+ (DDMathFunction) ln10Function {
@@ -1064,7 +1064,7 @@ + (DDMathFunction) ln10Function {
return [DDExpression numberExpressionWithNumber:[NSNumber numberWithDouble:M_LN10]];
};
- return [[function copy] autorelease];
+ return AUTORELEASE([function copy]);
}
@end
View
2 DDMathParser/_DDGroupTerm.h
@@ -9,7 +9,7 @@
@interface _DDGroupTerm : _DDParserTerm
-@property (nonatomic,readonly) NSMutableArray *subterms;
+@property (nonatomic,readonly,strong) NSMutableArray *subterms;
- (id)_initWithSubterms:(NSArray *)terms error:(NSError **)error;
- (void)_setSubterms:(NSArray *)newTerms;
View
14 DDMathParser/_DDGroupTerm.m
@@ -28,7 +28,7 @@ @implementation _DDGroupTerm
@synthesize subterms;
- (void)_setSubterms:(NSArray *)newTerms {
- [subterms release];
+ RELEASE(subterms);
subterms = [newTerms mutableCopy];
}
@@ -53,7 +53,7 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
[terms addObject:nextTerm];
} else {
// extracting a term failed. *error should've been filled already
- [self release];
+ RELEASE(self);
return nil;
}
nextToken = [tokenizer peekNextToken];
@@ -62,7 +62,7 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
// consume the closing parenthesis and verify it exists
if ([tokenizer nextToken] == nil) {
*error = ERR_BADARG(@"imbalanced parentheses");
- [self release];
+ RELEASE(self);
return nil;
}
@@ -71,10 +71,12 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
return self;
}
+#if !HAS_ARC
- (void)dealloc {
[subterms release];
[super dealloc];
}
+#endif
- (DDParserTermType)type { return DDParserTermTypeGroup; }
@@ -195,7 +197,7 @@ - (BOOL)_reduceBinaryOperatorAtIndex:(NSUInteger)index withParser:(DDParser *)pa
NSArray *rightOperands = [[self subterms] subarrayWithRange:rightOperandRange];
_DDGroupTerm *group = [[_DDGroupTerm alloc] _initWithSubterms:rightOperands error:error];
[[self subterms] replaceObjectsInRange:rightOperandRange withObjectsFromArray:[NSArray arrayWithObject:group]];
- [group release];
+ RELEASE(group);
rightmostOperand = [[self subterms] objectAtIndex:NSMaxRange(replacementRange)-1];
}
@@ -204,7 +206,7 @@ - (BOOL)_reduceBinaryOperatorAtIndex:(NSUInteger)index withParser:(DDParser *)pa
_DDFunctionTerm *function = [[_DDFunctionTerm alloc] _initWithFunction:[operator operatorFunction] subterms:parameters error:error];
[[self subterms] replaceObjectsInRange:replacementRange withObjectsFromArray:[NSArray arrayWithObject:function]];
- [function release];
+ RELEASE(function);
return YES;
}
@@ -244,7 +246,7 @@ - (BOOL)_reduceUnaryOperatorAtIndex:(NSUInteger)index withParser:(DDParser *)par
[[self subterms] replaceObjectsInRange:replacementRange withObjectsFromArray:[NSArray arrayWithObject:function]];
- [function release];
+ RELEASE(function);
return YES;
}
View
4 DDMathParser/_DDNumberExpression.m
@@ -14,7 +14,7 @@ @implementation _DDNumberExpression
- (id) initWithNumber:(NSNumber *)n {
self = [super init];
if (self) {
- number = [n retain];
+ number = RETAIN(n);
}
return self;
}
@@ -27,10 +27,12 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:[self number] forKey:@"number"];
}
+#if !HAS_ARC
- (void) dealloc {
[number release];
[super dealloc];
}
+#endif
- (DDExpressionType) expressionType { return DDExpressionTypeNumber; }
View
2 DDMathParser/_DDParserTerm.h
@@ -25,7 +25,7 @@ typedef enum {
@property (nonatomic,getter=isResolved) BOOL resolved;
@property (nonatomic,readonly) DDParserTermType type;
-@property (nonatomic,readonly) DDMathStringToken *token;
+@property (nonatomic,readonly,strong) DDMathStringToken *token;
+ (id)rootTermWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)error;
+ (id)termWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)error;
View
8 DDMathParser/_DDParserTerm.m
@@ -41,7 +41,7 @@ + (id)rootTermWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **
[terms addObject:nextTerm];
}
- return [[[_DDGroupTerm alloc] _initWithSubterms:terms error:error] autorelease];
+ return AUTORELEASE([[_DDGroupTerm alloc] _initWithSubterms:terms error:error]);
}
+ (id)termWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)error {
@@ -63,7 +63,7 @@ + (id)termWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)err
term = [[_DDFunctionTerm alloc] _initWithTokenizer:tokenizer error:error];
}
- return [term autorelease];
+ return AUTORELEASE(term);
} else {
*error = ERR_GENERIC(@"can't create a term with a nil token");
}
@@ -75,7 +75,7 @@ - (id)_initWithToken:(DDMathStringToken *)t error:(NSError **)error {
self = [super init];
if (self) {
resolved = NO;
- token = [t retain];
+ token = RETAIN(t);
}
return self;
}
@@ -84,10 +84,12 @@ - (id)_initWithTokenizer:(DDMathStringTokenizer *)tokenizer error:(NSError **)er
return [self _initWithToken:[tokenizer nextToken] error:error];
}
+#if !HAS_ARC
- (void)dealloc {
[token release];
[super dealloc];
}
+#endif
- (BOOL)resolveWithParser:(DDParser *)parser error:(NSError **)error {
#pragma unused(parser,error)
View
10 DDMathParser/_DDRewriteRule.m
@@ -19,30 +19,32 @@ - (id)initWithTemplate:(NSString *)string replacementPattern:(NSString *)pattern
@implementation _DDRewriteRule
+ (_DDRewriteRule *)rewriteRuleWithTemplate:(NSString *)string replacementPattern:(NSString *)replacement {
- return [[[self alloc] initWithTemplate:string replacementPattern:replacement] autorelease];
+ return AUTORELEASE([[self alloc] initWithTemplate:string replacementPattern:replacement]);
}
- (id)initWithTemplate:(NSString *)string replacementPattern:(NSString *)patternFormat {
self = [super init];
if (self) {
NSError *error = nil;
- predicate = [[DDExpression expressionFromString:string error:&error] retain];
- pattern = [[DDExpression expressionFromString:patternFormat error:&error] retain];
+ predicate = RETAIN([DDExpression expressionFromString:string error:&error]);
+ pattern = RETAIN([DDExpression expressionFromString:patternFormat error:&error]);
if (!predicate || !pattern || [predicate expressionType] != DDExpressionTypeFunction) {
NSLog(@"error creating rule: %@", error);
- [self release];
+ RELEASE(self);
return nil;
}
}
return self;
}
+#if !HAS_ARC
- (void)dealloc {
[predicate release];
[pattern release];
[super dealloc];
}
+#endif
- (BOOL)_ruleExpression:(DDExpression *)rule matchesExpression:(DDExpression *)target withReplacements:(NSMutableDictionary *)replacements {
if ([rule expressionType] == DDExpressionTypeNumber || [rule expressionType] == DDExpressionTypeVariable) {
View
4 DDMathParser/_DDVariableExpression.m
@@ -20,7 +20,7 @@ - (id) initWithVariable:(NSString *)v {
v = [v substringFromIndex:1];
}
if ([v length] == 0) {
- [self release];
+ RELEASE(self);
return nil;
}
variable = [v copy];
@@ -36,10 +36,12 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:[self variable] forKey:@"variable"];
}
+#if !HAS_ARC
- (void) dealloc {
[variable release];
[super dealloc];
}
+#endif
- (DDExpressionType) expressionType { return DDExpressionTypeVariable; }
View
18 DDMathParser_Prefix.pch
@@ -4,4 +4,22 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
+
+#if __has_feature(objc_arc)
+
+#define HAS_ARC 1
+#define RETAIN(_o) (_o)
+#define RELEASE(_o)
+#define AUTORELEASE(_o) (_o)
+
+#else
+
+#define HAS_ARC 0
+#define RETAIN(_o) [(_o) retain]
+#define RELEASE(_o) [(_o) release]
+#define AUTORELEASE(_o) [(_o) autorelease]
+
+#endif
+
+
#endif
View
22 main.m
@@ -16,7 +16,7 @@
} while (1);
- return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
+ return AUTORELEASE([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
void listFunctions() {
@@ -29,7 +29,12 @@ void listFunctions() {
int main (int argc, const char * argv[]) {
#pragma unused(argc, argv)
+
+#if HAS_ARC
+ @autoreleasepool {
+#else
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+#endif
printf("Math Evaluator!\n");
printf("\ttype a mathematical expression to evaluate it.\n");
@@ -54,20 +59,25 @@ int main (int argc, const char * argv[]) {
DDExpression *rewritten = [[DDMathEvaluator sharedMathEvaluator] expressionByRewritingExpression:expression];
NSNumber *value = [expression evaluateWithSubstitutions:nil evaluator:nil error:&error];
- [tokenizer release];
+ RELEASE(tokenizer);
- if (value == nil) {
- printf("\tERROR: %s\n", [[error description] UTF8String]);
- } else {
+// if (value == nil) {
+// printf("\tERROR: %s\n", [[error description] UTF8String]);
+// } else {
printf("\t%s = %s\n", [[expression description] UTF8String], [[value description] UTF8String]);
- }
+// }
printf("\tRewritten: %s\n", [[rewritten description] UTF8String]);
} while (1);
// insert code here...
printf("Goodbye!\n");
+
+#if HAS_ARC
+ }
+#else
[pool drain];
+#endif
return 0;
}

0 comments on commit c954d51

Please sign in to comment.
Something went wrong with that request. Please try again.