Commit 4004e645 authored by Michael Schwarz's avatar Michael Schwarz

disable conflicts where no choice can be made without inserting cycle

parent df3d8605
...@@ -409,8 +409,11 @@ class ConflictPanel extends Composite { ...@@ -409,8 +409,11 @@ class ConflictPanel extends Composite {
if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){ if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){
resolutionOptions.setEnabled(forceEnableDropdown); resolutionOptions.setEnabled(forceEnableDropdown);
} }
else {
resolutionOptions.setEnabled(pti.canChangeDefaultResolution(srdetails));
}
} }
if(pti.isResolvedInFavorOfShift(srdetails)){ else if(pti.isResolvedInFavorOfShift(srdetails)){
resolutionOptions.select(1); resolutionOptions.select(1);
resolutionOptions.setEnabled(true); resolutionOptions.setEnabled(true);
...@@ -418,9 +421,12 @@ class ConflictPanel extends Composite { ...@@ -418,9 +421,12 @@ class ConflictPanel extends Composite {
if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){ if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){
resolutionOptions.setEnabled(forceEnableDropdown); resolutionOptions.setEnabled(forceEnableDropdown);
} }
else {
resolutionOptions.setEnabled(pti.canChangeDefaultResolution(srdetails));
}
} }
if(pti.isResolvedAsError(srdetails)){ else if(pti.isResolvedAsError(srdetails)){
resolutionOptions.select(3); resolutionOptions.select(3);
resolutionOptions.setEnabled(true); resolutionOptions.setEnabled(true);
...@@ -428,6 +434,13 @@ class ConflictPanel extends Composite { ...@@ -428,6 +434,13 @@ class ConflictPanel extends Composite {
if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){ if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){
resolutionOptions.setEnabled(forceEnableDropdown); resolutionOptions.setEnabled(forceEnableDropdown);
} }
else {
resolutionOptions.setEnabled(pti.canChangeDefaultResolution(srdetails));
}
}
else {
resolutionOptions.select(0);
resolutionOptions.setEnabled(true);
} }
resolutionButton.setEnabled(false); resolutionButton.setEnabled(false);
......
...@@ -116,6 +116,17 @@ class PrecedenceToInsert { ...@@ -116,6 +116,17 @@ class PrecedenceToInsert {
return precs.containsKey(srd.shift) || precs.containsKey(srd.reduce); return precs.containsKey(srd.shift) || precs.containsKey(srd.reduce);
} }
/**
* Returns true if the default way of resolving can be changed by inserting precedences.
* Undefined if there is no default way of resolving this conflict
* @param srd S
* @return true iff it can be changed
*/
public boolean canChangeDefaultResolution(ShiftReduceDetails srd){
return !((precs.containsKey(srd.shift) || originalEdge.getFirst().equals(srd.shift)) &&
(precs.containsKey(srd.reduce) || originalEdge.getFirst().equals(srd.reduce)));
}
/** /**
* Insert terminal precedence t over other. other is not inserted into the set of precedences because it might not be necessary to resolve * Insert terminal precedence t over other. other is not inserted into the set of precedences because it might not be necessary to resolve
* a conflict to insert both precs. However, the possible edge is recorded and will be added later on if it becomes necessary * a conflict to insert both precs. However, the possible edge is recorded and will be added later on if it becomes necessary
...@@ -138,7 +149,16 @@ class PrecedenceToInsert { ...@@ -138,7 +149,16 @@ class PrecedenceToInsert {
* @throws PrecedenceCyclicException if this would induce a cyclic precedence. In this case the action is not performed * @throws PrecedenceCyclicException if this would induce a cyclic precedence. In this case the action is not performed
*/ */
public void addPrecedence(terminal higher,terminal lower) throws PrecedenceCyclicException{ public void addPrecedence(terminal higher,terminal lower) throws PrecedenceCyclicException{
boolean addedHigher = false, addedLower = false; boolean addedHigher = false;
// Lower is guaranteed to be part of the current conflict,
// otherwise we would not need to insert prec since
// - not affected
// - resolved the way we want it to be resolved anyway
if(!precs.containsKey(lower)){
throw new IllegalArgumentException("This conflict is either not part of the set of affected conflicts,"
+ " or it is resolved in this way even without adding the precedence");
}
// Make sure all terminals are represented within the precs // Make sure all terminals are represented within the precs
if(!precs.containsKey(higher)){ if(!precs.containsKey(higher)){
...@@ -148,10 +168,6 @@ class PrecedenceToInsert { ...@@ -148,10 +168,6 @@ class PrecedenceToInsert {
addedHigher = true; addedHigher = true;
} }
// Lower is guaranteed to be part of the current conflict,
// otherwise we would not need to insert prec since
// - not affected
// - resolved the way we want it to be resolved anyway
if(originalEdge.getFirst().equals(higher)){ if(originalEdge.getFirst().equals(higher)){
// We know the for original edge u->v that u is present since u == higher // We know the for original edge u->v that u is present since u == higher
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment