diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-09-01 23:13:55 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-09-01 23:13:55 +0200 |
commit | 73903e25720a373028a2bf269c2aab27385c4692 (patch) | |
tree | de083f9c93a7915d0f257990487500cb466b3655 | |
parent | c1131490d8282e8fe76ac348e3cf500598be2590 (diff) |
MLKForm class cluster: Add -freeVariables.
-rw-r--r-- | MLKForm.h | 1 | ||||
-rw-r--r-- | MLKForm.m | 56 |
2 files changed, 57 insertions, 0 deletions
@@ -43,6 +43,7 @@ forCompiler:(id)compiler; -(NSArray *) subforms; +-(NSSet *) freeVariables; @end @@ -85,6 +85,21 @@ return [NSArray array]; } +-(NSSet *) freeVariables +{ + NSMutableSet *freeVariables = [NSMutableSet set]; + NSArray *subforms = [self subforms]; + int i; + + for (i = 0; i < [subforms count]; i++) + { + MLKForm *subform = [subforms objectAtIndex:i]; + [freeVariables unionSet:[subform freeVariables]]; + } + + return freeVariables; +} + -(void) dealloc { LDESTROY (_form); @@ -121,6 +136,14 @@ { return self; } + +-(NSSet *) freeVariables +{ + if ([_context variableIsLexical:_form]) + return [NSSet setWithObject:_form]; + else + return [NSSet set]; +} @end @@ -617,6 +640,21 @@ return _lambdaListName; } +-(NSSet *) freeVariables +{ + id superfree = [super freeVariables]; + if ([superfree containsObject:_lambdaListName]) + { + NSMutableSet *freeVariables = [superfree mutableCopy]; + [freeVariables removeObject:_lambdaListName]; + return freeVariables; + } + else + { + return superfree; + } +} + -(void) dealloc { LDESTROY (_lambdaListName); @@ -773,6 +811,24 @@ return [[super subforms] arrayByAddingObjectsFromArray:_variableBindingForms]; } +-(NSSet *) freeVariables +{ + NSMutableSet *freeVariables = [[super freeVariables] mutableCopy]; + int i; + + for (i = 0; i < [_variableBindingForms count]; i++) + { + id symbol = [[_variableBindingForms objectAtIndex:i] name]; + if ([freeVariables containsObject:symbol] + && [_bodyContext variableIsLexical:symbol]) + { + [freeVariables removeObject:symbol]; + } + } + + return freeVariables; +} + -(void) dealloc { LDESTROY (_variableBindingForms); |