From 8c9afc45929ee3818b8c8e17828e5021fcb8e3e3 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 14 Jun 2022 22:01:54 -0700 Subject: [PATCH] recursively update variable table size --- .../addons/terrascript/parser/lang/Scope.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/parser/lang/Scope.java b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/parser/lang/Scope.java index da597898c..946abbfea 100644 --- a/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/parser/lang/Scope.java +++ b/common/addons/structure-terrascript-loader/src/main/java/com/dfsek/terra/addons/terrascript/parser/lang/Scope.java @@ -82,9 +82,7 @@ public class Scope { int num = numSize; indices.put(check(id), Pair.of(num, ReturnType.NUMBER)); numSize++; - if(parent != null) { - parent.numSize = FastMath.max(parent.numSize, numSize); - } + updateNumSize(numSize); return num; } @@ -92,9 +90,7 @@ public class Scope { int str = strSize; indices.put(check(id), Pair.of(str, ReturnType.STRING)); strSize++; - if(parent != null) { - parent.strSize = FastMath.max(parent.strSize, strSize); - } + updateStrSize(strSize); return str; } @@ -102,12 +98,31 @@ public class Scope { int bool = boolSize; indices.put(check(id), Pair.of(bool, ReturnType.BOOLEAN)); boolSize++; - if(parent != null) { - parent.boolSize = FastMath.max(parent.boolSize, boolSize); - } + updateBoolSize(boolSize); 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) { return indices.get(id).getLeft(); }