From 428aa889649c3688240a14a4f291b8a2be1e2ae8 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 12 Aug 2008 19:18:52 +0200 Subject: MLKLexicalContext: Add management of user-defined function and variable properties. --- MLKLexicalContext.m | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'MLKLexicalContext.m') diff --git a/MLKLexicalContext.m b/MLKLexicalContext.m index 001cd5c..d051b2a 100644 --- a/MLKLexicalContext.m +++ b/MLKLexicalContext.m @@ -99,6 +99,9 @@ static MLKSymbol *LEXICAL; LASSIGN (_knownSymbolMacros, [NSMutableSet setWithArray:[symbolMacros allKeys]]); LASSIGN (_declarations, declarations); + + _functionInfo = [[NSMutableDictionary alloc] init]; + _variableInfo = [[NSMutableDictionary alloc] init]; return self; } @@ -285,6 +288,76 @@ static MLKSymbol *LEXICAL; [_functions addObject:symbol]; } +-(id) deepPropertyForVariable:(id)name key:(id)key +{ + NSDictionary *props = [_variableInfo objectForKey:name]; + id property; + + if (props && (property = [props objectForKey:key])) + return property; + else if (!_parent || [_variables containsObject:name]) + return nil; + else + return [_parent deepPropertyForVariable:name key:key]; +} + +-(void) setDeepProperty:(id)object + forVariable:(id)name + key:(id)key +{ + // Changes propagate up to the origin of the binding. If there is no + // lexically apparent binding, the property is set in the global + // context. This does not make it pervasive, however. + + if (!_parent || [_variables containsObject:name]) + { + NSMutableDictionary *props = [_variableInfo objectForKey:name]; + if (!props) + { + props = [NSMutableDictionary dictionary]; + [_variableInfo setObject:props forKey:name]; + } + [props setObject:object forKey:key]; + } + else + { + [_parent setDeepProperty:object forVariable:name key:key]; + } +} + +-(id) deepPropertyForFunction:(id)name key:(id)key +{ + NSDictionary *props = [_functionInfo objectForKey:name]; + id property; + + if (props && (property = [props objectForKey:key])) + return property; + else if (!_parent || [_functions containsObject:name]) + return nil; + else + return [_parent deepPropertyForFunction:name key:key]; +} + +-(void) setDeepProperty:(id)object + forFunction:(id)name + key:(id)key +{ + if (!_parent || [_functions containsObject:name]) + { + NSMutableDictionary *props = [_functionInfo objectForKey:name]; + if (!props) + { + props = [NSMutableDictionary dictionary]; + [_functionInfo setObject:props forKey:name]; + } + [props setObject:object forKey:key]; + } + else + { + [_parent setDeepProperty:object forFunction:name key:key]; + } +} + -(void) dealloc { LRELEASE (_macros); @@ -298,6 +371,8 @@ static MLKSymbol *LEXICAL; LRELEASE (_variables); LRELEASE (_declarations); LRELEASE (_parent); + LRELEASE (_variableInfo); + LRELEASE (_functionInfo); [super dealloc]; } @end -- cgit v1.2.3