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

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 {
private boolean partOfCurrentConnected = false;
private boolean forceEnableDropdown = false;
private boolean noResolutionPossible = false;
private Label conflictTypeLabel;
private Link stateLabel;
private Label symbolLabel;
......@@ -214,6 +216,8 @@ class ConflictPanel extends Composite {
}
public void update(ConflictResolutionManager crm, Conflict conflict) {
noResolutionPossible = cupConflictsView.isUnresolvable(conflict);
this.conflict = conflict;
gridData.heightHint = BASE_HEIGHT;
......@@ -273,6 +277,11 @@ class ConflictPanel extends Composite {
} else {
throw new RuntimeException("unexpected conflict type.");
}
if(noResolutionPossible){
resolutionOptions.setVisible(false);
resolutionButton.setVisible(false);
}
}
......@@ -429,6 +438,10 @@ class ConflictPanel extends Composite {
* @return true iff conflict is indeed affected
*/
public boolean markIfAffected(ResolutionStrategy s){
if(noResolutionPossible){
return false;
}
if(s.isAffected(conflict, srdetails)){
resolutionOptions.setForeground(textDefault);
partOfCurrentConnected = true;
......@@ -458,7 +471,7 @@ class ConflictPanel extends Composite {
}
private void markAffected(PrecedenceToInsert pti){
private void markAffected(PrecedenceToInsert pti){
if(pti.isResolvedInFavorOfReduce(srdetails)){
resolutionOptions.select(2);
resolutionOptions.setEnabled(true);
......@@ -545,6 +558,10 @@ class ConflictPanel extends Composite {
* Abort a connected resolution. Enable dropdown and set to default values
*/
public void connectedEditAborted(){
if(noResolutionPossible){
return;
}
resolutionButton.setEnabled(true);
resolutionOptions.setEnabled(true);
resolutionOptions.select(0);
......
......@@ -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.ProductionSymbolRef;
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.terminal;
import de.tum.in.www2.cupplugin.Colors;
......@@ -82,6 +83,9 @@ public class CupConflictsView extends FailableView
private HashMap<terminal, Integer> terminalsAffectConflicts;
private HashMap<lr_item_core, Integer> ordersAffectConflicts;
private HashMap<lalr_state,LinkedList<Conflict>> conflictInState;
ResolutionStrategy currentResolution;
public int ignoreRRAfterLine;
......@@ -131,7 +135,6 @@ public class CupConflictsView extends FailableView
}
}
public CupConflictsView(Composite realParent, Jumper jumper, CupTextEditor editor) {
super(realParent);
......@@ -235,8 +238,10 @@ public class CupConflictsView extends FailableView
terminalsAffectConflicts = new HashMap<>();
ordersAffectConflicts = new HashMap<>();
conflictInState = new HashMap<>();
for(Conflict c : conflicts){
addToTerminalSet(crm, c);
addToStateSet(c);
addToOrderSet(c);
}
......@@ -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) {
int excessPanels = this.conflictPanels.size() - number;
......@@ -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() {
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