feat: implement "has" function for scopes
This commit is contained in:
parent
4a5e5a71af
commit
6481e992fa
@ -39,6 +39,14 @@ public class FunctionScope extends Scope {
|
|||||||
return childVar;
|
return childVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean has(String name) {
|
||||||
|
if (locals.has(name)) return true;
|
||||||
|
if (captures.has(name)) return true;
|
||||||
|
if (parent != null) return parent.has(name);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public int localsCount() {
|
public int localsCount() {
|
||||||
return locals.size();
|
return locals.size();
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,9 @@ public final class GlobalScope extends Scope {
|
|||||||
@Override public int offset() {
|
@Override public int offset() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@Override public boolean has(String name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalScope() { super(); }
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,13 @@ public class LocalScope extends Scope {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean has(String name) {
|
||||||
|
if (locals.has(name)) return true;
|
||||||
|
if (parent != null) return parent.has(name);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean end() {
|
@Override public boolean end() {
|
||||||
if (!super.end()) return false;
|
if (!super.end()) return false;
|
||||||
|
|
||||||
@ -40,6 +47,7 @@ public class LocalScope extends Scope {
|
|||||||
return () -> locals.iterator();
|
return () -> locals.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LocalScope(Scope parent) {
|
public LocalScope(Scope parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ public abstract class Scope {
|
|||||||
* which could break the semantics of a capture
|
* which could break the semantics of a capture
|
||||||
*/
|
*/
|
||||||
public abstract VariableDescriptor get(String name, boolean capture);
|
public abstract VariableDescriptor get(String name, boolean capture);
|
||||||
|
public abstract boolean has(String name);
|
||||||
/**
|
/**
|
||||||
* Gets the index offset from this scope to its children
|
* Gets the index offset from this scope to its children
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user