summaryrefslogtreecommitdiff
path: root/MLKLexicalContext.m
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 19:18:52 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 19:18:52 +0200
commit428aa889649c3688240a14a4f291b8a2be1e2ae8 (patch)
tree46674240dee89c93632274d6329b84b00e1f5b42 /MLKLexicalContext.m
parentd9a4288c6b7acfbcb7e819841a291f3063daa00c (diff)
MLKLexicalContext: Add management of user-defined function and variable properties.
Diffstat (limited to 'MLKLexicalContext.m')
-rw-r--r--MLKLexicalContext.m75
1 files changed, 75 insertions, 0 deletions
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