mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-29 06:57:03 +00:00
Added missing getters in CPExpression. Added a type: argument to FunctionExpression initializer used by subclasses to init super with their own type. Fixed evaluation with bindings dictionary in CPExpression_variable. Allow values in bindings to be a constant or an expression (per cocoa). Tests: added tests for subqueryExpressions, for variableExpression evaluation where the value in the bindings dictionary can be either a constant or another expression. Parsing a simple variable expression works (e.g. '$x = 12'), parsing a variable in a combined path (e.g. '$x.path = 12' won't yet.
65 lines
1.1 KiB
Plaintext
65 lines
1.1 KiB
Plaintext
|
|
@import "CPExpression.j"
|
|
@import <Foundation/CPDictionary.j>
|
|
|
|
@implementation CPExpression_constant : CPExpression
|
|
{
|
|
id _value;
|
|
}
|
|
|
|
- (id)initWithValue:(id)value
|
|
{
|
|
[super initWithExpressionType:CPConstantValueExpressionType];
|
|
_value = value;
|
|
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isEqual:(id)object
|
|
{
|
|
if (self === object)
|
|
return YES;
|
|
|
|
if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object constantValue] isEqual:[self constantValue]])
|
|
return NO;
|
|
|
|
return YES;
|
|
}
|
|
|
|
- (id)constantValue
|
|
{
|
|
return _value;
|
|
}
|
|
|
|
- (id)expressionValueWithObject:(id)object context:(CPDictionary)context
|
|
{
|
|
return _value;
|
|
}
|
|
|
|
- (CPString)description
|
|
{
|
|
if ([_value isKindOfClass:[CPString class]])
|
|
return @"\"" + _value + @"\"";
|
|
|
|
return [_value description];
|
|
}
|
|
|
|
@end
|
|
|
|
var CPConstantValueKey = @"CPConstantValue";
|
|
|
|
@implementation CPExpression_constant (CPCoding)
|
|
|
|
- (id)initWithCoder:(CPCoder)coder
|
|
{
|
|
var value = [coder decodeObjectForKey:CPConstantValueKey];
|
|
return [self initWithValue:value];
|
|
}
|
|
|
|
- (void)encodeWithCoder:(CPCoder)coder
|
|
{
|
|
[coder encodeObject:_value forKey:CPConstantValueKey];
|
|
}
|
|
|
|
@end
|