quakeforge/ruamoko/scheme/Scope.r

93 lines
1.5 KiB
R
Raw Normal View History

#include "Scope.h"
#include "defs.h"
@implementation Scope
2011-02-14 13:39:43 +00:00
+ (id) newWithOuter: (Scope *) o
{
return [[self alloc] initWithOuter: o];
}
2011-02-14 13:39:43 +00:00
- (id) initWithOuter: (Scope *) o
{
self = [super init];
outerScope = o;
names = [Array new];
return self;
}
- (int) indexLocal: (Symbol *) sym
{
local int index;
for (index = 0; index < [names count]; index++) {
if (sym == [names objectAtIndex: index]) {
return index;
}
}
return -1;
}
- (int) indexOf: (Symbol *) sym
{
local int index;
index = [self indexLocal: sym];
if (index < 0 && outerScope) {
return [outerScope indexOf: sym];
} else {
return index;
}
}
- (int) depthOf: (Symbol *) sym
{
local int index;
local int res;
index = [self indexLocal: sym];
if (index < 0) {
if (outerScope) {
res = [outerScope depthOf: sym];
if (res < 0) {
return -1;
} else {
return 1 + res;
}
} else {
return -1;
}
} else {
return 0;
}
}
2011-02-14 13:39:43 +00:00
- (void) addName: (Symbol *) sym
{
2010-12-12 10:40:24 +00:00
[names addObject: sym];
}
- (void) dealloc
{
if (names) {
[names release];
}
2011-01-14 03:07:40 +00:00
names = nil;
[super dealloc];
}
- (void) markReachable
{
[names makeObjectsPerformSelector: @selector(mark)];
[outerScope mark];
}
2011-02-14 13:39:43 +00:00
- (Scope *) outer
{
return outerScope;
}
@end