Skip to content

Commit 8504562

Browse files
committed
Add a field for Obj's type
1 parent 064801b commit 8504562

File tree

5 files changed

+13
-28
lines changed

5 files changed

+13
-28
lines changed

src/main/java/pascal/taie/analysis/pta/core/heap/ConstantObj.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ public class ConstantObj extends Obj {
3636
private final ReferenceLiteral value;
3737

3838
ConstantObj(ReferenceLiteral value) {
39+
super(value.getType());
3940
this.value = value;
4041
}
4142

42-
@Override
43-
public Type getType() {
44-
return value.getType();
45-
}
46-
4743
@Override
4844
public ReferenceLiteral getAllocation() {
4945
return value;

src/main/java/pascal/taie/analysis/pta/core/heap/MergedObj.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public class MergedObj extends Obj {
3737

3838
private final String name;
3939

40-
private final Type type;
41-
4240
/**
4341
* Set of objects represented by this merged object.
4442
*/
@@ -51,7 +49,7 @@ public class MergedObj extends Obj {
5149
private Obj representative;
5250

5351
public MergedObj(Type type, String name) {
54-
this.type = type;
52+
super(type);
5553
this.name = name;
5654
}
5755

@@ -71,11 +69,6 @@ public Set<Obj> getAllocation() {
7169
return representedObjs;
7270
}
7371

74-
@Override
75-
public Type getType() {
76-
return type;
77-
}
78-
7972
@Override
8073
public Optional<JMethod> getContainerMethod() {
8174
return representative != null ?

src/main/java/pascal/taie/analysis/pta/core/heap/MockObj.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ public class MockObj extends Obj {
3838

3939
private final Object alloc;
4040

41-
private final Type type;
42-
4341
private final JMethod container;
4442

4543
private final boolean isFunctional;
4644

4745
public MockObj(Descriptor desc, Object alloc, Type type,
4846
JMethod container, boolean isFunctional) {
47+
super(type);
4948
this.desc = desc;
5049
this.alloc = alloc;
51-
this.type = type;
5250
this.container = container;
5351
this.isFunctional = isFunctional;
5452
}
@@ -57,11 +55,6 @@ public Descriptor getDescriptor() {
5755
return desc;
5856
}
5957

60-
@Override
61-
public Type getType() {
62-
return type;
63-
}
64-
6558
@Override
6659
public Object getAllocation() {
6760
return alloc;

src/main/java/pascal/taie/analysis/pta/core/heap/NewObj.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import pascal.taie.ir.stmt.New;
2626
import pascal.taie.language.classes.JMethod;
27-
import pascal.taie.language.type.ReferenceType;
2827
import pascal.taie.language.type.Type;
2928

3029
import java.util.Optional;
@@ -37,14 +36,10 @@ public class NewObj extends Obj {
3736
private final New allocSite;
3837

3938
NewObj(New allocSite) {
39+
super(allocSite.getRValue().getType());
4040
this.allocSite = allocSite;
4141
}
4242

43-
@Override
44-
public ReferenceType getType() {
45-
return allocSite.getRValue().getType();
46-
}
47-
4843
@Override
4944
public New getAllocation() {
5045
return allocSite;

src/main/java/pascal/taie/analysis/pta/core/heap/Obj.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@
3535
*/
3636
public abstract class Obj implements Indexable {
3737

38+
protected final Type type;
39+
3840
private int index = -1;
3941

42+
protected Obj(Type type) {
43+
this.type = type;
44+
}
45+
4046
void setIndex(int index) {
4147
if (this.index != -1) {
4248
throw new IllegalStateException("index already set");
@@ -65,7 +71,9 @@ public boolean isFunctional() {
6571
/**
6672
* @return the type of the object.
6773
*/
68-
public abstract Type getType();
74+
public Type getType() {
75+
return type;
76+
}
6977

7078
/**
7179
* @return the allocation of the object.

0 commit comments

Comments
 (0)