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

minor simplifications in TLATypes

parent 0a920dfc
No related branches found
No related tags found
No related merge requests found
Pipeline #144886 passed
package de.tla2b.types; package de.tla2b.types;
import de.be4.classicalb.core.parser.node.AMultOrCartExpression; import de.be4.classicalb.core.parser.node.AMultOrCartExpression;
import de.be4.classicalb.core.parser.node.PExpression; import de.be4.classicalb.core.parser.node.PExpression;
import de.tla2b.exceptions.UnificationException; import de.tla2b.exceptions.UnificationException;
...@@ -107,33 +106,22 @@ public class PairType extends AbstractHasFollowers { ...@@ -107,33 +106,22 @@ public class PairType extends AbstractHasFollowers {
@Override @Override
public PairType cloneTLAType() { public PairType cloneTLAType() {
return new PairType(this.first.cloneTLAType(), return new PairType(this.first.cloneTLAType(), this.second.cloneTLAType());
this.second.cloneTLAType());
} }
@Override @Override
public boolean contains(TLAType o) { public boolean contains(TLAType o) {
return first.equals(o) || first.contains(o) || second.equals(o) return first.equals(o) || first.contains(o) || second.equals(o) || second.contains(o);
|| second.contains(o);
} }
@Override @Override
public String toString() { public String toString() {
String res = first + "*"; return first + "*" + (second instanceof PairType ? "(" + second + ")" : second);
if (second instanceof PairType) {
res += "(" + second + ")";
} else
res += second;
return res;
} }
@Override @Override
public PExpression getBNode() { public PExpression getBNode() {
AMultOrCartExpression card = new AMultOrCartExpression(); return new AMultOrCartExpression(first.getBNode(), second.getBNode());
card.setLeft(first.getBNode());
card.setRight(second.getBNode());
return card;
} }
public void apply(TypeVisitorInterface visitor) { public void apply(TypeVisitorInterface visitor) {
......
...@@ -25,7 +25,6 @@ public class StringType extends TLAType { ...@@ -25,7 +25,6 @@ public class StringType extends TLAType {
return o.compare(this); return o.compare(this);
} else } else
return false; return false;
} }
@Override @Override
...@@ -38,22 +37,15 @@ public class StringType extends TLAType { ...@@ -38,22 +37,15 @@ public class StringType extends TLAType {
if (!this.compare(o)) { if (!this.compare(o)) {
throw new UnificationException(); throw new UnificationException();
} }
if (o.getKind() == STRING) { if (o instanceof UntypedType) {
return this;
} else if (o instanceof UntypedType) {
((UntypedType) o).setFollowersTo(this); ((UntypedType) o).setFollowersTo(this);
((UntypedType) o).deleteFollowers(); ((UntypedType) o).deleteFollowers();
return this;
} else if (o instanceof FunctionType) { } else if (o instanceof FunctionType) {
// function // function
if (o instanceof AbstractHasFollowers) { ((FunctionType) o).setFollowersTo(this);
((AbstractHasFollowers) o).setFollowersTo(this); ((FunctionType) o).deleteFollowers();
((AbstractHasFollowers) o).deleteFollowers();
} }
return this; return this;
} else {
throw new UnificationException();
}
} }
@Override @Override
......
...@@ -155,8 +155,7 @@ public class StructOrFunctionType extends AbstractHasFollowers { ...@@ -155,8 +155,7 @@ public class StructOrFunctionType extends AbstractHasFollowers {
this.types.put(field, type); this.types.put(field, type);
} }
} }
TLAType res = testRecord(); return testRecord();
return res;
} }
return this; return this;
} }
......
...@@ -104,8 +104,8 @@ public class StructType extends AbstractHasFollowers { ...@@ -104,8 +104,8 @@ public class StructType extends AbstractHasFollowers {
if (o instanceof StructType) { if (o instanceof StructType) {
StructType otherStruct = (StructType) o; StructType otherStruct = (StructType) o;
boolean extendStruct = false;
boolean extendStruct;
if (this.incompleteStruct && otherStruct.incompleteStruct) { if (this.incompleteStruct && otherStruct.incompleteStruct) {
extendStruct = false; extendStruct = false;
} else if (this.incompleteStruct) { } else if (this.incompleteStruct) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment