Commit ee55970d authored by Michael Schwarz's avatar Michael Schwarz

Refactoring

parent 76347815
......@@ -511,7 +511,7 @@ class ConflictPanel extends Composite {
}
if(!srdetails.reduce.equals(srdetails.shift)){
if(!srdetails.shiftAndReducePrecedenceFromSameTerminal()){
// The user wants to shift, but shifting affects other conflicts
if(srdetails.shiftAffectsOthers && resolutionOptions.getSelectionIndex() == 1){
cupConflictsView.beginConnectedResolution();
......@@ -528,14 +528,14 @@ class ConflictPanel extends Composite {
// These are the cases where nothing is affected
if(resolutionOptions.getSelectionIndex() == 1) // Shift
cupConflictsView.insertPrecedence(srdetails.shift,Precedence.Type.Left);
cupConflictsView.insertSinglePrecedence(srdetails.shift,Precedence.Type.Left);
else if (resolutionOptions.getSelectionIndex() == 2) // Reduce
cupConflictsView.insertPrecedence(srdetails.reduce,Precedence.Type.Left);
cupConflictsView.insertSinglePrecedence(srdetails.reduce,Precedence.Type.Left);
}
else {
// Checking this is sufficient since the terminals are identical
if(srdetails.shiftAffectsOthers){
if(srdetails.shiftAffectsOthers) {
forceEnableDropdown = true;
cupConflictsView.beginConnectedResolution();
......@@ -547,19 +547,16 @@ class ConflictPanel extends Composite {
}
else if (resolutionOptions.getSelectionIndex() == 3) { // Non-Assoc
cupConflictsView.setTerminalAssoc(srdetails.shift,Precedence.Type.NonAssoc);
}
return;
}
}
if(resolutionOptions.getSelectionIndex() == 1) { // Shift
cupConflictsView.insertPrecedence(srdetails.shift,Precedence.Type.Right);
else if(resolutionOptions.getSelectionIndex() == 1) { // Shift
cupConflictsView.insertSinglePrecedence(srdetails.shift,Precedence.Type.Right);
}
else if (resolutionOptions.getSelectionIndex() == 2) { // Reduce
cupConflictsView.insertPrecedence(srdetails.shift,Precedence.Type.Left);
cupConflictsView.insertSinglePrecedence(srdetails.shift,Precedence.Type.Left);
}
else if (resolutionOptions.getSelectionIndex() == 3) { // Non-Assoc
cupConflictsView.insertPrecedence(srdetails.shift,Precedence.Type.NonAssoc);
cupConflictsView.insertSinglePrecedence(srdetails.shift,Precedence.Type.NonAssoc);
}
}
}
......@@ -579,18 +576,17 @@ class ConflictPanel extends Composite {
return;
}
if(srdetails.reduce.equals(srdetails.shift)){
if(srdetails.shiftAndReducePrecedenceFromSameTerminal()){
// We need to insert a assoc
forceEnableDropdown = true;
if(resolutionOptions.getSelectionIndex() == 1) { //Shift
forceEnableDropdown = true;
cupConflictsView.setTerminalAssoc(srdetails.shift,Precedence.Type.Right);
}
else if(resolutionOptions.getSelectionIndex() == 2) { // Reduce
forceEnableDropdown = true;
cupConflictsView.setTerminalAssoc(srdetails.shift,Precedence.Type.Left);
}
else if(resolutionOptions.getSelectionIndex() == 3) { // Non-Assoc
forceEnableDropdown = true;
cupConflictsView.setTerminalAssoc(srdetails.shift,Precedence.Type.NonAssoc);
}
}
......@@ -603,7 +599,7 @@ class ConflictPanel extends Composite {
if(resolutionOptions.getSelectionIndex() == 1){ //Shift
try {
cupConflictsView.addPrecedence(srdetails.shift, srdetails.reduce);
cupConflictsView.addFurtherPrecedence(srdetails.shift, srdetails.reduce);
} catch (PrecedenceCyclicException e1) {
showCyclicMessageAndResetDropdown(e1);
return;
......@@ -612,7 +608,7 @@ class ConflictPanel extends Composite {
if(resolutionOptions.getSelectionIndex() == 2){ // Reduce
try {
cupConflictsView.addPrecedence(srdetails.reduce, srdetails.shift);
cupConflictsView.addFurtherPrecedence(srdetails.reduce, srdetails.shift);
} catch (PrecedenceCyclicException e1) {
showCyclicMessageAndResetDropdown(e1);
return;
......
......@@ -365,6 +365,9 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
}
}
/**
* Mark all conflicts that are connected
*/
void markAllAffected(){
int affected = 0;
for(ConflictPanel c : conflictPanels){
......@@ -381,7 +384,7 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
markAllAffected();
}
void addPrecedence(terminal higher,terminal lower) throws PrecedenceCyclicException{
void addFurtherPrecedence(terminal higher,terminal lower) throws PrecedenceCyclicException{
currentPrecs.addPrecedence(higher,lower);
markAllAffected();
}
......@@ -391,6 +394,10 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
markAllAffected();
}
/**
* Set currentPrecs
* Doesn't mark affected conflicts
*/
void beginConnectedResolution(){
Shell shell = new Shell(Display.getCurrent());
MessageBox box = new MessageBox(shell,SWT.ICON_WARNING | SWT.OK);
......@@ -407,6 +414,10 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
refreshScrolledLayout();
}
/**
* Abort connected resolution and reset all panels
* @param refresh Refresh UI to make changes visible (true unless panels will change later anyway)
*/
private void abortConnectedResolution(boolean refresh){
currentPrecs = new PrecedenceToInsert();
this.connectedResolutionLabel.setVisible(false);
......@@ -422,6 +433,10 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
}
}
/**
* Check if current settings resolve all involved conflicts and if yes insert to appropriate position
* and end connected resolution
*/
private void applyConnectedResolution(){
// Conflicts are part of current connected conflicts that are not resolved yet.
......@@ -465,7 +480,12 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
}
}
void insertPrecedence(terminal terminal,Precedence.Type assoc){
/**
* Insert precedence (+ assoc) for a single terminal - use if this is not part of connected conflict
* @param terminal the terminal
* @param assoc the associativity
*/
void insertSinglePrecedence(terminal terminal,Precedence.Type assoc){
try {
String toInsert = "precedence " + assoc.toString().toLowerCase() + " " + terminal.name()+ "; // Inserted by Eclipse plugin";
......
......@@ -16,9 +16,6 @@ import de.tum.in.www2.cupplugin.Pair;
import de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails;
class PrecedenceToInsert {
// Occurs because the first terminal is not inserted
//TODO: Can I do this? Does the terminal class properly implement all the required things?
private HashMap<terminal,Precedence.Type> precs = new HashMap<>();
// Edges are stored in reverse order (i.e. there is a edge from a to b iff b has a explicit
......
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