From bd10bf5b3fd9a71320068de3c81f2160af371a09 Mon Sep 17 00:00:00 2001 From: Jan Gruteser <jan.gruteser@hhu.de> Date: Tue, 29 Oct 2024 19:36:14 +0100 Subject: [PATCH] minor simplifications in TLATypes --- src/main/java/de/tla2b/types/PairType.java | 20 ++++--------------- src/main/java/de/tla2b/types/StringType.java | 16 ++++----------- .../de/tla2b/types/StructOrFunctionType.java | 3 +-- src/main/java/de/tla2b/types/StructType.java | 2 +- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/main/java/de/tla2b/types/PairType.java b/src/main/java/de/tla2b/types/PairType.java index 316d36b..14a787f 100644 --- a/src/main/java/de/tla2b/types/PairType.java +++ b/src/main/java/de/tla2b/types/PairType.java @@ -1,6 +1,5 @@ package de.tla2b.types; - import de.be4.classicalb.core.parser.node.AMultOrCartExpression; import de.be4.classicalb.core.parser.node.PExpression; import de.tla2b.exceptions.UnificationException; @@ -107,33 +106,22 @@ public class PairType extends AbstractHasFollowers { @Override public PairType cloneTLAType() { - return new PairType(this.first.cloneTLAType(), - this.second.cloneTLAType()); + return new PairType(this.first.cloneTLAType(), this.second.cloneTLAType()); } @Override public boolean contains(TLAType o) { - return first.equals(o) || first.contains(o) || second.equals(o) - || second.contains(o); + return first.equals(o) || first.contains(o) || second.equals(o) || second.contains(o); } @Override public String toString() { - String res = first + "*"; - if (second instanceof PairType) { - res += "(" + second + ")"; - } else - res += second; - return res; - + return first + "*" + (second instanceof PairType ? "(" + second + ")" : second); } @Override public PExpression getBNode() { - AMultOrCartExpression card = new AMultOrCartExpression(); - card.setLeft(first.getBNode()); - card.setRight(second.getBNode()); - return card; + return new AMultOrCartExpression(first.getBNode(), second.getBNode()); } public void apply(TypeVisitorInterface visitor) { diff --git a/src/main/java/de/tla2b/types/StringType.java b/src/main/java/de/tla2b/types/StringType.java index e88d0ed..e4af60b 100644 --- a/src/main/java/de/tla2b/types/StringType.java +++ b/src/main/java/de/tla2b/types/StringType.java @@ -25,7 +25,6 @@ public class StringType extends TLAType { return o.compare(this); } else return false; - } @Override @@ -38,22 +37,15 @@ public class StringType extends TLAType { if (!this.compare(o)) { throw new UnificationException(); } - if (o.getKind() == STRING) { - return this; - } else if (o instanceof UntypedType) { + if (o instanceof UntypedType) { ((UntypedType) o).setFollowersTo(this); ((UntypedType) o).deleteFollowers(); - return this; } else if (o instanceof FunctionType) { // function - if (o instanceof AbstractHasFollowers) { - ((AbstractHasFollowers) o).setFollowersTo(this); - ((AbstractHasFollowers) o).deleteFollowers(); - } - return this; - } else { - throw new UnificationException(); + ((FunctionType) o).setFollowersTo(this); + ((FunctionType) o).deleteFollowers(); } + return this; } @Override diff --git a/src/main/java/de/tla2b/types/StructOrFunctionType.java b/src/main/java/de/tla2b/types/StructOrFunctionType.java index 56af36e..d32b8f8 100644 --- a/src/main/java/de/tla2b/types/StructOrFunctionType.java +++ b/src/main/java/de/tla2b/types/StructOrFunctionType.java @@ -155,8 +155,7 @@ public class StructOrFunctionType extends AbstractHasFollowers { this.types.put(field, type); } } - TLAType res = testRecord(); - return res; + return testRecord(); } return this; } diff --git a/src/main/java/de/tla2b/types/StructType.java b/src/main/java/de/tla2b/types/StructType.java index 833651e..18137a9 100644 --- a/src/main/java/de/tla2b/types/StructType.java +++ b/src/main/java/de/tla2b/types/StructType.java @@ -104,8 +104,8 @@ public class StructType extends AbstractHasFollowers { if (o instanceof StructType) { StructType otherStruct = (StructType) o; - boolean extendStruct = false; + boolean extendStruct; if (this.incompleteStruct && otherStruct.incompleteStruct) { extendStruct = false; } else if (this.incompleteStruct) { -- GitLab