Skip to content

Commit

Permalink
Fix #76
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbro1 committed May 1, 2023
1 parent cfa51b6 commit 1345b89
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.cinrc</groupId>
<artifactId>IRDC</artifactId>
<version>4.3.6.1</version>
<version>4.3.7.1</version>

<packaging>jar</packaging>
<properties>
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/cinrc/process/ProcessContainer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.cinrc.process;

import java.util.Collection;
import java.util.Iterator;
import org.cinrc.parser.CCSTransitionException;
import org.cinrc.process.nodes.Label;
import org.cinrc.process.nodes.LabelKey;
import org.cinrc.process.nodes.NodeIDGenerator;
import org.cinrc.process.nodes.TauLabelNode;
import org.cinrc.process.process.ComplexProcess;
import org.cinrc.process.process.Process;
import org.cinrc.util.SetUtil;

public class ProcessContainer {

Expand All @@ -21,6 +25,7 @@ public String prettyString() {

public Collection<Label> getActionableLabels() {
Collection<Label> labels = process.getActionableLabels();
labels = removeUnsyncableKeys(labels);

return labels;
}
Expand All @@ -30,6 +35,32 @@ public boolean canAct(Label node) {
return l.contains(node);
}

protected Collection<Label> removeUnsyncableKeys(Collection<Label> labels){
if (!(process instanceof ComplexProcess cp))
return labels;
Iterator<Label> iter = labels.iterator();
while (iter.hasNext()) {
Label l = iter.next();
if (!(l instanceof LabelKey key))//we only care about keys
{
continue;
}
if (!(key.from instanceof TauLabelNode)) {
continue; //don't care about regular keys
}
try {
if (!cp.recursiveIsSyncable(key))//both sides need to be able to do it
{
iter.remove();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return labels;
}


public void act(Label node) {
process = process.act(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cinrc/process/nodes/LabelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static Label createLabel(String channel, int dupe) {
}


public static String stripTau(String s){
private static String stripTau(String s){
//Tau{a...}
//Strips first 4 and last 1 characters
Matcher m = CCSGrammar.LABEL_TAU.match(s);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/cinrc/process/process/ComplexProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.cinrc.IRDC;
import org.cinrc.parser.CCSGrammar;
import org.cinrc.process.nodes.Label;
import org.cinrc.process.nodes.LabelKey;
import org.cinrc.util.RCCSFlag;
import org.cinrc.util.SetUtil;

Expand Down Expand Up @@ -164,6 +165,21 @@ public String origin() {
return b.toString();
}

public boolean recursiveIsSyncable(LabelKey key){
if (left.canAct(key) && right.canAct(key)){
return true;
}
if (left instanceof ComplexProcess cp)
if (cp.recursiveIsSyncable(key))
return true;
if (right instanceof ComplexProcess cp)
if (cp.recursiveIsSyncable(key))
return true;

return false;

}

public boolean hasKey() {
if (left == null || right == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.cinrc.process.process;

import static org.cinrc.util.SetUtil.removeUnsyncableKeys;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.cinrc.parser.CCSParserException;
Expand Down Expand Up @@ -114,6 +117,7 @@ public Collection<Label> getActionableLabels() {
if (!prefixes.isEmpty()) {
return l;
}

l.addAll(getActionableLabelsStrict());
l.addAll(collectSynchronizations(l));
l = removeRestrictions(l);
Expand All @@ -137,6 +141,7 @@ protected List<TauLabelNode> collectSynchronizations(Collection<Label> labels){
return n;
}


public Process attemptRewind(LabelKey key) {
if (getLeftRightLabels().stream().noneMatch(LabelKey.class::isInstance))//no keys left/right?
{
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/cinrc/util/SetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static Collection<TauLabelNode> getTauMatches(Collection<Label> nodes) {
}

//Not sure why, but this no longer is feasible.
@Deprecated
public static Collection<Label> removeUnsyncableKeys(ComplexProcess p, Collection<Label> labels) {
Iterator<Label> iter = labels.iterator();
while (iter.hasNext()) {
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/tests/ActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,17 @@ public void testAdvancedActions() {
assert !p.canAct(b) && !p.canAct(d);
}

@Test
public void tauTest1(){
Process p = new CCSParser().parseLine("Tau{a}[k1] | Tau{a}[k1].Tau{b}[k2] | Tau{b}[k2]");
Label key2 = LabelFactory.createDebugLabel("Tau{b}[k2]");
Label key1 = LabelFactory.createDebugLabel("Tau{a}[k1]");
ProcessContainer pc = new ProcessContainer(p);
assert (pc.canAct(key2));
assert !(pc.canAct(key1));
pc.act(key2);
assert pc.canAct(key1);

}

}

0 comments on commit 1345b89

Please sign in to comment.