Add simple implementation of evaluatedObjectExpression

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31468 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-10-04 08:21:34 +00:00
parent 0222fe1e6d
commit 1b0e3dbcda
2 changed files with 44 additions and 22 deletions

View file

@ -1,3 +1,8 @@
2010-10-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPredicate.m: Add simple implementation of
evalutedObjectExpression
2010-10-01 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSObjCRuntime.m: Revert to the working version

View file

@ -52,6 +52,10 @@
// For pow()
#include <math.h>
/* Object to represent the expression beign evaluated.
*/
static NSExpression *evaluatedObjectExpression = nil;
@interface GSPredicateScanner : NSScanner
{
NSEnumerator *_args; // Not retained.
@ -806,22 +810,22 @@
- (BOOL) _evaluateLeftValue: (id)leftResult rightValue: (id)rightResult
{
unsigned compareOptions = 0;
BOOL leftIsNil;
BOOL rightIsNil;
leftIsNil = (leftResult == nil || [leftResult isEqual: [NSNull null]]);
rightIsNil = (rightResult == nil || [rightResult isEqual: [NSNull null]]);
if (leftIsNil || rightIsNil)
{
/* One of the values is nil. The result is YES,
* if both are nil and equlality is requested.
*/
return ((leftIsNil == rightIsNil)
&& ((_type == NSEqualToPredicateOperatorType)
|| (_type == NSLessThanOrEqualToPredicateOperatorType)
|| (_type == NSGreaterThanOrEqualToPredicateOperatorType)));
}
unsigned compareOptions = 0;
BOOL leftIsNil;
BOOL rightIsNil;
leftIsNil = (leftResult == nil || [leftResult isEqual: [NSNull null]]);
rightIsNil = (rightResult == nil || [rightResult isEqual: [NSNull null]]);
if (leftIsNil || rightIsNil)
{
/* One of the values is nil. The result is YES,
* if both are nil and equality is requested.
*/
return ((leftIsNil == rightIsNil)
&& ((_type == NSEqualToPredicateOperatorType)
|| (_type == NSLessThanOrEqualToPredicateOperatorType)
|| (_type == NSGreaterThanOrEqualToPredicateOperatorType)));
}
// Change predicate options into string options.
if (!(_options & NSDiacriticInsensitivePredicateOption))
@ -903,7 +907,16 @@
{
id leftValue = [_left expressionValueWithObject: object context: nil];
id rightValue = [_right expressionValueWithObject: object context: nil];
if (leftValue == evaluatedObjectExpression)
{
leftValue = object;
}
if (rightValue == evaluatedObjectExpression)
{
rightValue = object;
}
if (_modifier == NSDirectPredicateModifier)
{
return [self _evaluateLeftValue: leftValue rightValue: rightValue];
@ -966,6 +979,14 @@
@implementation NSExpression
+ (void) initialize
{
if (self == [NSExpression class] && nil == evaluatedObjectExpression)
{
evaluatedObjectExpression = [GSEvaluatedObjectExpression new];
}
}
+ (NSExpression *) expressionForConstantValue: (id)obj
{
GSConstantValueExpression *e;
@ -978,11 +999,7 @@
+ (NSExpression *) expressionForEvaluatedObject
{
GSEvaluatedObjectExpression *e;
e = [[GSEvaluatedObjectExpression alloc]
initWithExpressionType: NSEvaluatedObjectExpressionType];
return AUTORELEASE(e);
return evaluatedObjectExpression;
}
+ (NSExpression *) expressionForFunction: (NSString *)name