From ee60d3f9a32f75c628961f40a9bf4f1bf387ac06 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sun, 14 Apr 2024 02:21:48 -0600 Subject: Proper Allocation sizes for Boil VarDeclaration --- st/AbstractInstance.java | 5 ----- st/ClassInstance.java | 5 +++++ st/MethodInstance.java | 4 ++++ st/TypeInstance.java | 5 +++++ 4 files changed, 14 insertions(+), 5 deletions(-) (limited to 'st') diff --git a/st/AbstractInstance.java b/st/AbstractInstance.java index 241991d..d236044 100644 --- a/st/AbstractInstance.java +++ b/st/AbstractInstance.java @@ -5,7 +5,6 @@ import java.util.ArrayList; public abstract class AbstractInstance { protected String name; // the literal name of the declaration protected TypeEnum type; // the type of the declaration - protected int size; // the size in memory protected ArrayList scope; // the scope where the instance is valid public AbstractInstance(String name, TypeEnum type) { @@ -50,10 +49,6 @@ public abstract class AbstractInstance { return this.type; } - public int getSize() { - return this.size; - } - public ArrayList getScope() { return this.scope; } diff --git a/st/ClassInstance.java b/st/ClassInstance.java index ad7e6b0..e93d3bd 100644 --- a/st/ClassInstance.java +++ b/st/ClassInstance.java @@ -29,6 +29,11 @@ public class ClassInstance extends AbstractInstance { return this.mtds; } + public int getSize() { + return 4 * (this.attrs.size() + + this.mtds.size()); + } + protected void addLocal(TypeInstance attr) { this.attrs.add(attr); } diff --git a/st/MethodInstance.java b/st/MethodInstance.java index c7df92f..6cf6ccc 100644 --- a/st/MethodInstance.java +++ b/st/MethodInstance.java @@ -22,6 +22,10 @@ public class MethodInstance extends AbstractInstance { return this.lvars; } + public TypeEnum getReturn() { + return this.rtrn; + } + protected void addArgument(TypeInstance arg) { this.args.add(arg); this.lvars.add(arg); diff --git a/st/TypeInstance.java b/st/TypeInstance.java index 596f638..65311a8 100644 --- a/st/TypeInstance.java +++ b/st/TypeInstance.java @@ -12,6 +12,11 @@ public class TypeInstance extends AbstractInstance { this.cls = cls; } + public int getSize() { + return (this.cls != null) ? + cls.getSize() : 4; + } + public ClassInstance getClassInstance() { return this.cls; } -- cgit v1.2.3