From d89fc5f4a6f5257bedce838aaeec1b75daa396bd Mon Sep 17 00:00:00 2001 From: jpwang Date: Sat, 6 Sep 2025 23:36:47 +0800 Subject: [PATCH] Add a field for `Obj`'s type --- .../taie/analysis/pta/core/heap/ConstantObj.java | 6 +----- .../pascal/taie/analysis/pta/core/heap/MergedObj.java | 9 +-------- .../pascal/taie/analysis/pta/core/heap/MockObj.java | 9 +-------- .../pascal/taie/analysis/pta/core/heap/NewObj.java | 7 +------ .../java/pascal/taie/analysis/pta/core/heap/Obj.java | 10 +++++++++- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/main/java/pascal/taie/analysis/pta/core/heap/ConstantObj.java b/src/main/java/pascal/taie/analysis/pta/core/heap/ConstantObj.java index 7c7541b9c..6cbb50edc 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/heap/ConstantObj.java +++ b/src/main/java/pascal/taie/analysis/pta/core/heap/ConstantObj.java @@ -36,14 +36,10 @@ public class ConstantObj extends Obj { private final ReferenceLiteral value; ConstantObj(ReferenceLiteral value) { + super(value.getType()); this.value = value; } - @Override - public Type getType() { - return value.getType(); - } - @Override public ReferenceLiteral getAllocation() { return value; diff --git a/src/main/java/pascal/taie/analysis/pta/core/heap/MergedObj.java b/src/main/java/pascal/taie/analysis/pta/core/heap/MergedObj.java index a3e758cc2..86e52d1db 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/heap/MergedObj.java +++ b/src/main/java/pascal/taie/analysis/pta/core/heap/MergedObj.java @@ -37,8 +37,6 @@ public class MergedObj extends Obj { private final String name; - private final Type type; - /** * Set of objects represented by this merged object. */ @@ -51,7 +49,7 @@ public class MergedObj extends Obj { private Obj representative; public MergedObj(Type type, String name) { - this.type = type; + super(type); this.name = name; } @@ -71,11 +69,6 @@ public Set getAllocation() { return representedObjs; } - @Override - public Type getType() { - return type; - } - @Override public Optional getContainerMethod() { return representative != null ? diff --git a/src/main/java/pascal/taie/analysis/pta/core/heap/MockObj.java b/src/main/java/pascal/taie/analysis/pta/core/heap/MockObj.java index 59dcc4ba3..e53a04994 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/heap/MockObj.java +++ b/src/main/java/pascal/taie/analysis/pta/core/heap/MockObj.java @@ -38,17 +38,15 @@ public class MockObj extends Obj { private final Object alloc; - private final Type type; - private final JMethod container; private final boolean isFunctional; public MockObj(Descriptor desc, Object alloc, Type type, JMethod container, boolean isFunctional) { + super(type); this.desc = desc; this.alloc = alloc; - this.type = type; this.container = container; this.isFunctional = isFunctional; } @@ -57,11 +55,6 @@ public Descriptor getDescriptor() { return desc; } - @Override - public Type getType() { - return type; - } - @Override public Object getAllocation() { return alloc; diff --git a/src/main/java/pascal/taie/analysis/pta/core/heap/NewObj.java b/src/main/java/pascal/taie/analysis/pta/core/heap/NewObj.java index 784f41c9d..ca29f8b0b 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/heap/NewObj.java +++ b/src/main/java/pascal/taie/analysis/pta/core/heap/NewObj.java @@ -24,7 +24,6 @@ import pascal.taie.ir.stmt.New; import pascal.taie.language.classes.JMethod; -import pascal.taie.language.type.ReferenceType; import pascal.taie.language.type.Type; import java.util.Optional; @@ -37,14 +36,10 @@ public class NewObj extends Obj { private final New allocSite; NewObj(New allocSite) { + super(allocSite.getRValue().getType()); this.allocSite = allocSite; } - @Override - public ReferenceType getType() { - return allocSite.getRValue().getType(); - } - @Override public New getAllocation() { return allocSite; diff --git a/src/main/java/pascal/taie/analysis/pta/core/heap/Obj.java b/src/main/java/pascal/taie/analysis/pta/core/heap/Obj.java index 99b189ee0..89222d45f 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/heap/Obj.java +++ b/src/main/java/pascal/taie/analysis/pta/core/heap/Obj.java @@ -35,8 +35,14 @@ */ public abstract class Obj implements Indexable { + protected final Type type; + private int index = -1; + protected Obj(Type type) { + this.type = type; + } + void setIndex(int index) { if (this.index != -1) { throw new IllegalStateException("index already set"); @@ -65,7 +71,9 @@ public boolean isFunctional() { /** * @return the type of the object. */ - public abstract Type getType(); + public Type getType() { + return type; + } /** * @return the allocation of the object.