Commit 092de795 authored by Michael Schwarz's avatar Michael Schwarz

further RR + bugfix for SR if prod has no prec

parent 15d50333
......@@ -42,6 +42,7 @@ import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.Pair;
import de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails;
import de.tum.in.www2.cupplugin.views.PrecedenceToInsert.PrecedenceCyclicException;
import de.tum.in.www2.cupplugin.views.ReordersToDo.OrderCyclicException;
class ConflictPanel extends Composite {
private final CupConflictsView cupConflictsView;
......@@ -591,11 +592,6 @@ class ConflictPanel extends Composite {
}
private void resolutionButtonSRClick(){
if(cupConflictsView.currentResolution != null && cupConflictsView.currentResolution.isActive()) {
// That should not happen, if we are inside a connected conflict, button is disabled
return;
}
if(!srdetails.shiftAndReducePrecedenceFromSameTerminal()){
// The user wants to shift, but shifting affects other conflicts
if(srdetails.shiftAffectsOthers && resolutionOptions.getSelectionIndex() == 1){
......@@ -667,7 +663,22 @@ class ConflictPanel extends Composite {
rrr.apply();
}
else {
cupConflictsView.beginConnectedResolutionRR();
if(resolutionOptions.getSelectionIndex() == 1){
try {
cupConflictsView.setOrder(item1, item2);
} catch (OrderCyclicException e) {
e.printStackTrace();
}
}
if(resolutionOptions.getSelectionIndex() == 2){
try {
cupConflictsView.setOrder(item2, item1);
} catch (OrderCyclicException e) {
e.printStackTrace();
}
}
}
}
......@@ -679,6 +690,12 @@ class ConflictPanel extends Composite {
if(resolutionOptions.getSelectionIndex() == 0){
return;
}
if(cupConflictsView.currentResolution != null && cupConflictsView.currentResolution.isActive()) {
// That should not happen, if we are inside a connected conflict, button is disabled
return;
}
if(conflict instanceof ShiftReduceConflict){
resolutionButtonSRClick();
}
......@@ -738,6 +755,41 @@ class ConflictPanel extends Composite {
}
}
private void resolutionBoxSelectedRR() throws internal_error {
ReordersToDo rtd = (ReordersToDo) cupConflictsView.currentResolution;
ReduceReduceConflict rrc = (ReduceReduceConflict) conflict;
lr_item_core item1 = new lr_item_core(rrc.getConflictItem1().the_production(),rrc.getConflictItem1().dot_pos());
lr_item_core item2 = new lr_item_core(rrc.getConflictItem2().the_production(),rrc.getConflictItem2().dot_pos());
if((resolutionOptions.getSelectionIndex() == 1 && rtd.isResolvedInFavorOf1(item1,item2))
|| (resolutionOptions.getSelectionIndex() == 2 && rtd.isResolvedInFavorOf2(item1,item2))) {
// Current action is desired -> Do nothing
return;
}
if(resolutionOptions.getSelectionIndex() == 1){ //Reduce with 1
try {
cupConflictsView.setOrder(item1, item2);
} catch (OrderCyclicException e1) {
showCyclicMessageAndResetDropdown(e1);
return;
}
}
if(resolutionOptions.getSelectionIndex() == 2){ // Reduce
try {
cupConflictsView.setOrder(item2, item1);
} catch (OrderCyclicException e1) {
showCyclicMessageAndResetDropdown(e1);
return;
}
}
}
private SelectionListener resolutionBoxSelected = new SelectionListener() {
@Override
......@@ -756,7 +808,12 @@ class ConflictPanel extends Composite {
resolutionBoxSelectedSR();
}
else {
try {
resolutionBoxSelectedRR();
} catch (internal_error e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
......@@ -782,4 +839,20 @@ class ConflictPanel extends Composite {
markIfAffected(cupConflictsView.currentResolution);
}
/**
* Show the message that the orders were cyclic. Reset the dropdown to the value determined by the
* order
* @param e Exception that caused this. Contains cycle
*/
private void showCyclicMessageAndResetDropdown(OrderCyclicException e){
Shell shell = new Shell(Display.getCurrent());
MessageBox box = new MessageBox(shell,SWT.ICON_WARNING | SWT.OK);
box.setText("Information");
box.setMessage("These orders are inconsistent because they contain a cycle.\n" + e.cycleToString() +"\n"
+ "The order that was inserted last is undone.");
box.open();
markIfAffected(cupConflictsView.currentResolution);
}
}
\ No newline at end of file
......@@ -68,6 +68,7 @@ import de.tum.in.www2.cupplugin.editors.RevisionManager;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
import de.tum.in.www2.cupplugin.views.PrecedenceToInsert.PrecedenceCyclicException;
import de.tum.in.www2.cupplugin.views.ReordersToDo.OrderCyclicException;
public class CupConflictsView extends FailableView
implements ICupEditorPageVisibility, ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
......@@ -250,7 +251,7 @@ public class CupConflictsView extends FailableView
int size = conflicts.size();
// Do this less often
updateBuildfile(ignored);
// updateBuildfile(ignored);
scrolled.setLayoutDeferred(true);
......@@ -450,7 +451,11 @@ public class CupConflictsView extends FailableView
return (PrecedenceToInsert) currentResolution;
}
void addFirstPrecedence(terminal t, terminal other) {
private ReordersToDo getRtd(){
return (ReordersToDo) currentResolution;
}
void addFirstPrecedence(terminal t, terminal other) {
getPti().add(t, other);
markAllAffected();
}
......@@ -465,6 +470,11 @@ public class CupConflictsView extends FailableView
markAllAffected();
}
void setOrder(lr_item_core higher,lr_item_core lower) throws OrderCyclicException {
getRtd().insertOrder(higher, lower);
markAllAffected();
}
/**
* Set currentPrecs Doesn't mark affected conflicts
*/
......
......@@ -114,8 +114,8 @@ class PrecedenceToInsert extends GraphHelper<terminal> implements ResolutionStra
* @return true iff it can be changed
*/
public boolean canChangeDefaultResolution(ShiftReduceDetails srd){
return !((precs.containsKey(srd.shift) || (originalEdge != null && originalEdge.getFirst().equals(srd.shift))) &&
(precs.containsKey(srd.reduce) || (originalEdge != null && originalEdge.getFirst().equals(srd.reduce))));
return !((precs.containsKey(srd.shift) || (originalEdge != null && originalEdge.getFirst() != null && originalEdge.getFirst().equals(srd.shift))) &&
(precs.containsKey(srd.reduce) || (originalEdge != null && originalEdge.getFirst() != null && originalEdge.getFirst().equals(srd.reduce))));
}
/**
......
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