Skip to content
Snippets Groups Projects
Commit 6a13701e authored by Jan Gruteser's avatar Jan Gruteser
Browse files

minor simplifications in type classes

parent a72d95b0
No related branches found
No related tags found
No related merge requests found
...@@ -7,11 +7,10 @@ import java.util.List; ...@@ -7,11 +7,10 @@ import java.util.List;
public abstract class AbstractHasFollowers extends TLAType { public abstract class AbstractHasFollowers extends TLAType {
public List<Object> followers; private List<Object> followers = new ArrayList<>();
public AbstractHasFollowers(int t) { public AbstractHasFollowers(int t) {
super(t); super(t);
followers = new ArrayList<>();
} }
public List<Object> getFollowers() { public List<Object> getFollowers() {
...@@ -20,18 +19,9 @@ public abstract class AbstractHasFollowers extends TLAType { ...@@ -20,18 +19,9 @@ public abstract class AbstractHasFollowers extends TLAType {
public void addFollower(Object o) { public void addFollower(Object o) {
// only (partial) untyped types need follower // only (partial) untyped types need follower
if (this.followers != null) { if (followers != null && !followers.contains(o))
for (Object follower : followers) {
if (follower == o)
return;
}
followers.add(o); followers.add(o);
} }
}
public void deleteFollower(Object o) {
followers.remove(o);
}
public void deleteFollowers() { public void deleteFollowers() {
followers = null; followers = null;
......
...@@ -18,6 +18,5 @@ public interface IType { ...@@ -18,6 +18,5 @@ public interface IType {
int TUPLE_OR_FUNCTION = 12; int TUPLE_OR_FUNCTION = 12;
int REAL = 13; int REAL = 13;
void apply(TypeVisitorInterface visitor); void apply(TypeVisitorInterface visitor);
} }
...@@ -20,7 +20,7 @@ public class SetType extends AbstractHasFollowers { ...@@ -20,7 +20,7 @@ public class SetType extends AbstractHasFollowers {
public void setSubType(TLAType t) { public void setSubType(TLAType t) {
// if (subType instanceof AbstractHasFollowers) { // if (subType instanceof AbstractHasFollowers) {
// // delete old reference // // delete old reference
// ((AbstractHasFollowers) subType).deleteFollower(this); // ((AbstractHasFollowers) subType).removeFollower(this);
// } // }
if (t instanceof AbstractHasFollowers) { if (t instanceof AbstractHasFollowers) {
...@@ -77,9 +77,7 @@ public class SetType extends AbstractHasFollowers { ...@@ -77,9 +77,7 @@ public class SetType extends AbstractHasFollowers {
@Override @Override
public String toString() { public String toString() {
String res = "POW(" + this.getSubType() + ")"; return "POW(" + this.getSubType() + ")";
return res;
} }
@Override @Override
......
...@@ -6,11 +6,12 @@ import de.tla2b.output.TypeVisitorInterface; ...@@ -6,11 +6,12 @@ import de.tla2b.output.TypeVisitorInterface;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
public class StructOrFunctionType extends AbstractHasFollowers { public class StructOrFunctionType extends AbstractHasFollowers {
private final LinkedHashMap<String, TLAType> types; private final Map<String, TLAType> types;
public StructOrFunctionType(String name, TLAType type) { public StructOrFunctionType(String name, TLAType type) {
super(STRUCT_OR_FUNCTION); super(STRUCT_OR_FUNCTION);
...@@ -64,8 +65,7 @@ public class StructOrFunctionType extends AbstractHasFollowers { ...@@ -64,8 +65,7 @@ public class StructOrFunctionType extends AbstractHasFollowers {
StructType s = (StructType) o; StructType s = (StructType) o;
for (String fieldName : types.keySet()) { for (String fieldName : types.keySet()) {
if (s.getFields().contains(fieldName)) { if (s.getFields().contains(fieldName)) {
if (!this.types.get(fieldName) if (!this.types.get(fieldName).compare(s.getType(fieldName))) {
.compare(s.getType(fieldName))) {
return false; return false;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment