Commit 65de4205 authored by Michael Schwarz's avatar Michael Schwarz
Browse files

Remove resolution options for conflicts that can not be resolved

(SR + RR in same state, where terminal set of RR intersects with SR)
for details see last section of thesis
parent 683d4c0f
...@@ -57,6 +57,8 @@ class ConflictPanel extends Composite { ...@@ -57,6 +57,8 @@ class ConflictPanel extends Composite {
private boolean partOfCurrentConnected = false; private boolean partOfCurrentConnected = false;
private boolean forceEnableDropdown = false; private boolean forceEnableDropdown = false;
private boolean noResolutionPossible = false;
private Label conflictTypeLabel; private Label conflictTypeLabel;
private Link stateLabel; private Link stateLabel;
private Label symbolLabel; private Label symbolLabel;
...@@ -214,6 +216,8 @@ class ConflictPanel extends Composite { ...@@ -214,6 +216,8 @@ class ConflictPanel extends Composite {
} }
public void update(ConflictResolutionManager crm, Conflict conflict) { public void update(ConflictResolutionManager crm, Conflict conflict) {
noResolutionPossible = cupConflictsView.isUnresolvable(conflict);
this.conflict = conflict; this.conflict = conflict;
gridData.heightHint = BASE_HEIGHT; gridData.heightHint = BASE_HEIGHT;
...@@ -273,6 +277,11 @@ class ConflictPanel extends Composite { ...@@ -273,6 +277,11 @@ class ConflictPanel extends Composite {
} else { } else {
throw new RuntimeException("unexpected conflict type."); throw new RuntimeException("unexpected conflict type.");
} }
if(noResolutionPossible){
resolutionOptions.setVisible(false);
resolutionButton.setVisible(false);
}
} }
...@@ -429,6 +438,10 @@ class ConflictPanel extends Composite { ...@@ -429,6 +438,10 @@ class ConflictPanel extends Composite {
* @return true iff conflict is indeed affected * @return true iff conflict is indeed affected
*/ */
public boolean markIfAffected(ResolutionStrategy s){ public boolean markIfAffected(ResolutionStrategy s){
if(noResolutionPossible){
return false;
}
if(s.isAffected(conflict, srdetails)){ if(s.isAffected(conflict, srdetails)){
resolutionOptions.setForeground(textDefault); resolutionOptions.setForeground(textDefault);
partOfCurrentConnected = true; partOfCurrentConnected = true;
...@@ -458,7 +471,7 @@ class ConflictPanel extends Composite { ...@@ -458,7 +471,7 @@ class ConflictPanel extends Composite {
} }
private void markAffected(PrecedenceToInsert pti){ private void markAffected(PrecedenceToInsert pti){
if(pti.isResolvedInFavorOfReduce(srdetails)){ if(pti.isResolvedInFavorOfReduce(srdetails)){
resolutionOptions.select(2); resolutionOptions.select(2);
resolutionOptions.setEnabled(true); resolutionOptions.setEnabled(true);
...@@ -545,6 +558,10 @@ class ConflictPanel extends Composite { ...@@ -545,6 +558,10 @@ class ConflictPanel extends Composite {
* Abort a connected resolution. Enable dropdown and set to default values * Abort a connected resolution. Enable dropdown and set to default values
*/ */
public void connectedEditAborted(){ public void connectedEditAborted(){
if(noResolutionPossible){
return;
}
resolutionButton.setEnabled(true); resolutionButton.setEnabled(true);
resolutionOptions.setEnabled(true); resolutionOptions.setEnabled(true);
resolutionOptions.select(0); resolutionOptions.select(0);
......
...@@ -44,6 +44,7 @@ import de.in.tum.www2.cup.ast.Precedence; ...@@ -44,6 +44,7 @@ import de.in.tum.www2.cup.ast.Precedence;
import de.in.tum.www2.cup.ast.ProductionRight; import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.ast.ProductionSymbolRef; import de.in.tum.www2.cup.ast.ProductionSymbolRef;
import de.in.tum.www2.cup.internal.internal_error; import de.in.tum.www2.cup.internal.internal_error;
import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.lr_item_core; import de.in.tum.www2.cup.internal.lr_item_core;
import de.in.tum.www2.cup.internal.terminal; import de.in.tum.www2.cup.internal.terminal;
import de.tum.in.www2.cupplugin.Colors; import de.tum.in.www2.cupplugin.Colors;
...@@ -82,6 +83,9 @@ public class CupConflictsView extends FailableView ...@@ -82,6 +83,9 @@ public class CupConflictsView extends FailableView
private HashMap<terminal, Integer> terminalsAffectConflicts; private HashMap<terminal, Integer> terminalsAffectConflicts;
private HashMap<lr_item_core, Integer> ordersAffectConflicts; private HashMap<lr_item_core, Integer> ordersAffectConflicts;
private HashMap<lalr_state,LinkedList<Conflict>> conflictInState;
ResolutionStrategy currentResolution; ResolutionStrategy currentResolution;
public int ignoreRRAfterLine; public int ignoreRRAfterLine;
...@@ -131,7 +135,6 @@ public class CupConflictsView extends FailableView ...@@ -131,7 +135,6 @@ public class CupConflictsView extends FailableView
} }
} }
public CupConflictsView(Composite realParent, Jumper jumper, CupTextEditor editor) { public CupConflictsView(Composite realParent, Jumper jumper, CupTextEditor editor) {
super(realParent); super(realParent);
...@@ -235,8 +238,10 @@ public class CupConflictsView extends FailableView ...@@ -235,8 +238,10 @@ public class CupConflictsView extends FailableView
terminalsAffectConflicts = new HashMap<>(); terminalsAffectConflicts = new HashMap<>();
ordersAffectConflicts = new HashMap<>(); ordersAffectConflicts = new HashMap<>();
conflictInState = new HashMap<>();
for(Conflict c : conflicts){ for(Conflict c : conflicts){
addToTerminalSet(crm, c); addToTerminalSet(crm, c);
addToStateSet(c);
addToOrderSet(c); addToOrderSet(c);
} }
...@@ -326,6 +331,14 @@ public class CupConflictsView extends FailableView ...@@ -326,6 +331,14 @@ public class CupConflictsView extends FailableView
} }
} }
} }
private void addToStateSet(Conflict conflict){
if(conflictInState.get(conflict.getState()) == null){
conflictInState.put(conflict.getState(), new LinkedList<>());
}
conflictInState.get(conflict.getState()).add(conflict);
}
private void matchPanelNumber(int number) { private void matchPanelNumber(int number) {
int excessPanels = this.conflictPanels.size() - number; int excessPanels = this.conflictPanels.size() - number;
...@@ -606,6 +619,35 @@ public class CupConflictsView extends FailableView ...@@ -606,6 +619,35 @@ public class CupConflictsView extends FailableView
} }
} }
boolean isUnresolvable(Conflict c){
List<Conflict> conflicts = conflictInState.get(c.getState());
if(c instanceof ShiftReduceConflict){
terminal under = ((ShiftReduceConflict)c).getTerminal();
for(Conflict other : conflicts){
if(other instanceof ReduceReduceConflict){
if(((ReduceReduceConflict)other).getTerminals().contains(under)){
return true;
}
}
}
return false;
}
else{
List<terminal> under = ((ReduceReduceConflict)c).getTerminals();
for(Conflict other : conflicts){
if(other instanceof ShiftReduceConflict){
if(under.contains(((ShiftReduceConflict)other).getTerminal())){
return true;
}
}
}
return false;
}
}
public IDocument getDocument() { public IDocument getDocument() {
return editor.getDocument(); return editor.getDocument();
} }
......
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