Commit 9cbcef27 authored by Johannes Roith's avatar Johannes Roith

Basic work on conflicts view.

parent b771524c
......@@ -19,6 +19,7 @@ public class ConflictManager
}
public void addConflict(Conflict conflict) {
System.out.println("DEBUG: ADDING CONFLICT TO " + this + "!"); // TODO: remove
this.conflicts.add(conflict);
}
}
......
......@@ -17,7 +17,7 @@ class Demo
IErrorReporter er = new NoopErrorReporter();
FileInputStream input = new FileInputStream("/Users/jroith/testcup/testspeed.cup");
FileInputStream input = new FileInputStream("/Users/jroith/testcup/test.cup");
CupParser parser = new CupParser(er, input);
ParserResult res = parser.parse();
......
......@@ -58,8 +58,7 @@ public class LALRResult {
// if we have more conflicts than we expected issue a message and die
if (context.num_conflicts > expect_conflicts)
{
System.out.println("*** More conflicts encountered than expected " +
"-- parser generation aborted");
System.err.println("*** More conflicts encountered than expected.");
return result;
}
......
......@@ -8,6 +8,7 @@ public class Colors {
public static final RGB darkGray = new RGB (20, 20, 20);
// public static final RGB darkGray = new RGB (30, 30, 30);
public static final RGB gray = new RGB (150, 150, 150);
public static final RGB lightGray = new RGB (240, 240, 240);
public static final RGB blue = new RGB (53, 87, 197);
public static final RGB brightBlue = new RGB (38, 99, 236);
public static final RGB green = new RGB (44, 173, 57);
......
......@@ -13,9 +13,13 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictManager;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.ReduceReduceConflict;
import de.in.tum.www2.cup.ShiftReduceConflict;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
......@@ -37,17 +41,38 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private List<ConflictPanel> conflictPanels;
private ScrolledComposite scrolled;
private Composite list;
static class ConflictPanel extends Composite {
private Label conflictTypeLabel;
public ConflictPanel(Composite parent, int style) {
super(parent, style);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.grabExcessHorizontalSpace = true;
data.heightHint = 50;
setLayoutData(data);
setBackground(new Color(Display.getCurrent(), Colors.gray));
setBackground(new Color(Display.getCurrent(), Colors.lightGray));
GridLayout layout = new GridLayout();
layout.numColumns = 5;
layout.verticalSpacing = 3;
setLayout(layout);
this.conflictTypeLabel = new Label(this, SWT.NONE);
}
public void update(Conflict conflict) {
if (conflict instanceof ReduceReduceConflict) {
conflictTypeLabel.setText("Reduce-Reduce conflict");
} else if (conflict instanceof ShiftReduceConflict) {
conflictTypeLabel.setText("Shift-Reduce conflict");
} else {
throw new RuntimeException("unexpected conflict type.");
}
}
}
public CupConflictsView(Composite parent, Jumper jumper, CupTextEditor editor) {
......@@ -80,8 +105,19 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
refreshScrolledLayout ();
}
private void updateConflicts(List<Conflict> conflicts) {
int size = conflicts.size();
matchPanelNumber(size);
for (int i=0; i < size; i++) {
Conflict conflict = conflicts.get(i);
ConflictPanel panel = conflictPanels.get(i);
panel.update(conflict);
}
refreshScrolledLayout ();
}
private void matchPanelNumber(int number) {
int excessPanels = number - this.conflictPanels.size();
int excessPanels = this.conflictPanels.size() - number;
if (excessPanels > 0) {
// TODO!
// for (int i=0; i < excessPanels; i++)
......@@ -112,11 +148,14 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
if (!Controller.getInstance(editor).requestJobRun()) {
// TODO: Handle no rerun!!
System.out.println("NO RERUN!!!");
Model model = Model.getInstanceForDocument(editor.getDocument());
LALRResult result = model.getLaLrResult();
ConflictManager cm = result.getContext().getConflictManager();
matchPanelNumber(cm.getConflicts().size());
if (result != null) {
ConflictManager cm = result.getContext().getConflictManager();
updateConflicts(cm.getConflicts());
// TODO: update conflicts
}
}
}
......@@ -142,15 +181,17 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
LALRResult result = model.getLaLrResult();
if (result != null) {
System.out.println("IF CASE!!!"); // TODO
ConflictManager cm = result.getContext().getConflictManager();
matchPanelNumber(cm.getConflicts().size());
System.out.println("MANAGER: " + cm + " SIZE: " + cm.getConflicts().size());
updateConflicts(cm.getConflicts());
// TODO: update conflicts
} else {
System.out.println("ELSE CASE!!!"); // TODO
matchPanelNumber(0);
}
refreshScrolledLayout ();
}
}
}
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