recursively update variable table size

This commit is contained in:
dfsek
2022-06-14 22:01:54 -07:00
parent 3122962dc1
commit 8c9afc4592
@@ -82,9 +82,7 @@ public class Scope {
int num = numSize; int num = numSize;
indices.put(check(id), Pair.of(num, ReturnType.NUMBER)); indices.put(check(id), Pair.of(num, ReturnType.NUMBER));
numSize++; numSize++;
if(parent != null) { updateNumSize(numSize);
parent.numSize = FastMath.max(parent.numSize, numSize);
}
return num; return num;
} }
@@ -92,9 +90,7 @@ public class Scope {
int str = strSize; int str = strSize;
indices.put(check(id), Pair.of(str, ReturnType.STRING)); indices.put(check(id), Pair.of(str, ReturnType.STRING));
strSize++; strSize++;
if(parent != null) { updateStrSize(strSize);
parent.strSize = FastMath.max(parent.strSize, strSize);
}
return str; return str;
} }
@@ -102,12 +98,31 @@ public class Scope {
int bool = boolSize; int bool = boolSize;
indices.put(check(id), Pair.of(bool, ReturnType.BOOLEAN)); indices.put(check(id), Pair.of(bool, ReturnType.BOOLEAN));
boolSize++; boolSize++;
if(parent != null) { updateBoolSize(boolSize);
parent.boolSize = FastMath.max(parent.boolSize, boolSize);
}
return bool; return bool;
} }
private void updateBoolSize(int size) {
this.boolSize = FastMath.max(boolSize, size);
if(parent != null) {
parent.updateBoolSize(size);
}
}
private void updateNumSize(int size) {
this.numSize = FastMath.max(numSize, size);
if(parent != null) {
parent.updateNumSize(size);
}
}
private void updateStrSize(int size) {
this.strSize = FastMath.max(strSize, size);
if(parent != null) {
parent.updateStrSize(size);
}
}
public int getIndex(String id) { public int getIndex(String id) {
return indices.get(id).getLeft(); return indices.get(id).getLeft();
} }