summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-09-01 23:13:55 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-09-01 23:13:55 +0200
commit73903e25720a373028a2bf269c2aab27385c4692 (patch)
treede083f9c93a7915d0f257990487500cb466b3655
parentc1131490d8282e8fe76ac348e3cf500598be2590 (diff)
MLKForm class cluster: Add -freeVariables.
-rw-r--r--MLKForm.h1
-rw-r--r--MLKForm.m56
2 files changed, 57 insertions, 0 deletions
diff --git a/MLKForm.h b/MLKForm.h
index 0924460..a62089d 100644
--- a/MLKForm.h
+++ b/MLKForm.h
@@ -43,6 +43,7 @@
forCompiler:(id)compiler;
-(NSArray *) subforms;
+-(NSSet *) freeVariables;
@end
diff --git a/MLKForm.m b/MLKForm.m
index 2105ef8..3821886 100644
--- a/MLKForm.m
+++ b/MLKForm.m
@@ -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);