aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2018-09-15 22:51:37 -0400
committerAustin Adams <git@austinjadams.com>2018-09-15 22:51:37 -0400
commit1fd60c5749e08e3928bc3e35073708b617bb30f1 (patch)
treec374ae6b6502c0baffaf152a9a94cc4fc26b674b
parentaee8b43bc46d54e4f08d1eb1e9268c2f62707ce4 (diff)
downloadcircuitsim-grader-template-1fd60c5749e08e3928bc3e35073708b617bb30f1.tar.gz
circuitsim-grader-template-1fd60c5749e08e3928bc3e35073708b617bb30f1.tar.xz
Don't unlink random Ports when substituting pinsHEADmaster
Currently, we disconnect all components from each other with they happen to be connected with an Input Pin intended to mock a Register port. Don't do that — instead, only disconnect the fake Pin from the Link it shares with the other components.
-rw-r--r--src/main/java/edu/gatech/cs2110/circuitsim/api/Subcircuit.java13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/main/java/edu/gatech/cs2110/circuitsim/api/Subcircuit.java b/src/main/java/edu/gatech/cs2110/circuitsim/api/Subcircuit.java
index 0d41c1d..255ed5b 100644
--- a/src/main/java/edu/gatech/cs2110/circuitsim/api/Subcircuit.java
+++ b/src/main/java/edu/gatech/cs2110/circuitsim/api/Subcircuit.java
@@ -375,15 +375,14 @@ public class Subcircuit {
return new MockRegister(q, d, en, clk, rst, this);
}
- private Collection<Port> makeOrphanPort(Port port) {
- Collection<Port> connectedPorts = port.getLink().getParticipants().stream()
- .filter(p -> p != port).collect(Collectors.toList());
- connectedPorts.stream().forEach(port::unlinkPort);
- return connectedPorts;
+ private Port.Link makeOrphanPort(Port port) {
+ Port.Link link = port.getLink();
+ port.unlinkPort(port);
+ return link;
}
private Pin substitutePin(Port port, boolean isInput) {
- Collection<Port> originallyConnectedPorts = makeOrphanPort(port);
+ Port.Link originalLink = makeOrphanPort(port);
PinPeer mockPinPeer = new PinPeer(new Properties(
new Properties.Property<>(Properties.BITSIZE, port.getLink().getBitSize()),
@@ -404,7 +403,7 @@ public class Subcircuit {
// anything, disconnect it
makeOrphanPort(newPort);
// Now reconnect all the old stuff
- originallyConnectedPorts.stream().forEach(newPort::linkPort);
+ originalLink.linkPort(newPort);
return mockPin;
}