Commit 0a6fa6b6 authored by Michael Schwarz's avatar Michael Schwarz

Refactoring. Also everywhere correct conflict count

parent 42e5f1d1
package de.tum.in.www2.cupplugin.conflictresolution;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictResolutionManager;
import de.in.tum.www2.cup.ReduceReduceConflict;
public class ConflictFilter {
public static final String TRESHOLD_STRING = "~~ CUP-ECLIPSE:CONFLICT-RES-RR ~~ ";
private IDocument document;
private int ignored = 0;
/**
*
* @param document document that contains specification
*/
public ConflictFilter(IDocument document){
this.document = document;
}
/**
* Get list of all conflicts from the CRM that are not resolved
* (resolved here means ignored because order was specified)
* @param crm ConflictResolutionManager
* @return list of conflicts that are yet to be resolved
*/
public List<Conflict> getConflictsNotResolved(ConflictResolutionManager crm){
ignored = 0;
ArrayList<Conflict> conflicts = new ArrayList<>();
for (int i = 0; i < crm.getAllConflicts().size(); i++) {
Conflict c = crm.getAllConflicts().get(i);
if (!isIgnored(c)) {
conflicts.add(c);
} else {
ignored++;
}
}
return conflicts;
}
/**
* Get the number of conflicts in the last crm that was "resolved"
* Only meaningful after call to getConflictsNotResolved(...)
* @return number of conflicts resolved
*/
public int getResolvedCountLastRun(){
return ignored;
}
private boolean isIgnored(Conflict c) {
if (c instanceof ReduceReduceConflict) {
ReduceReduceConflict rrc = (ReduceReduceConflict) c;
int ignoreRRAfterLine = computeIgnoreRRAfter();
return ((ignoreRRAfterLine >= 0)
&& (rrc.getConflictItem1().the_production().getAstNode().getEnd().getLine() > ignoreRRAfterLine)
&& (rrc.getConflictItem2().the_production().getAstNode().getEnd().getLine() > ignoreRRAfterLine));
} else {
return false;
}
}
private int computeIgnoreRRAfter() {
int offset = document.get().indexOf(TRESHOLD_STRING);
if (offset == -1) {
return -1;
}
try {
return document.getLineOfOffset(offset) + 1;
} catch (BadLocationException e) {
return -1;
}
}
}
......@@ -12,7 +12,6 @@ import de.in.tum.www2.cup.ast.Production;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.internal.lr_item_core;
import de.tum.in.www2.cupplugin.model.Model;
import de.tum.in.www2.cupplugin.views.CupConflictsView;
public class ReduceReduceReorder {
IDocument document;
......@@ -39,7 +38,7 @@ public class ReduceReduceReorder {
public ReduceReduceReorder(IDocument document){
this.document = document;
this.flagPresent = (document.get().indexOf(CupConflictsView.TRESHOLD_STRING) != -1);
this.flagPresent = (document.get().indexOf(ConflictFilter.TRESHOLD_STRING) != -1);
textToAppend="";
rangesToRemove = new ArrayList<>();
}
......@@ -130,7 +129,7 @@ public class ReduceReduceReorder {
}
if(!flagPresent){
toInsert = "\n\n// " + CupConflictsView.TRESHOLD_STRING + "\n // After this the order of productions matters" + toInsert;
toInsert = "\n\n// " + ConflictFilter.TRESHOLD_STRING + "\n // After this the order of productions matters" + toInsert;
flagPresent = true;
}
......
......@@ -31,6 +31,7 @@ import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import de.in.tum.www2.cup.ConflictManager;
import de.in.tum.www2.cup.ConflictResolutionManager;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.internal.parse_action;
......@@ -38,6 +39,7 @@ import de.in.tum.www2.cup.internal.parse_action_row;
import de.in.tum.www2.cup.internal.parse_action_table;
import de.in.tum.www2.cup.internal.parse_reduce_row;
import de.in.tum.www2.cup.internal.parse_reduce_table;
import de.tum.in.www2.cupplugin.conflictresolution.ConflictFilter;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
......@@ -400,8 +402,10 @@ public class MultiPageEditor extends MultiPageEditorPart implements
CupContext ctx = model.getLaLrContext();
if (result == null)
return;
ConflictManager cm = result.getContext().getConflictManager();
setCounter(CONFLICTS_PAGE_INDEX, cm.getConflicts().size());
ConflictFilter cf = new ConflictFilter(editor.getDocument());
ConflictResolutionManager crm = new ConflictResolutionManager(ctx);
setCounter(CONFLICTS_PAGE_INDEX, cf.getConflictsNotResolved(crm).size());
parse_action_table actionTable = result.getActionTable();
if (actionTable != null) {
......
......@@ -47,6 +47,7 @@ import de.in.tum.www2.cup.internal.internal_error;
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;
import de.tum.in.www2.cupplugin.conflictresolution.ConflictFilter;
import de.tum.in.www2.cupplugin.conflictresolution.PrecedenceToInsert;
import de.tum.in.www2.cupplugin.conflictresolution.PrecedenceToInsert.PrecedenceCyclicException;
import de.tum.in.www2.cupplugin.conflictresolution.ReduceReduceReorder;
......@@ -69,8 +70,6 @@ public class CupConflictsView extends FailableView
private static final int OUTER_MARGIN = 10;
static final int INNER_MARGIN = 5;
public static final String TRESHOLD_STRING = "~~ CUP-ECLIPSE:CONFLICT-RES-RR ~~ ";
Jumper jumper;
private CupTextEditor editor;
private boolean isVisible;
......@@ -228,24 +227,17 @@ public class CupConflictsView extends FailableView
}
private void updateConflicts(ConflictResolutionManager crm) {
ignoreRRAfterLine = computeIgnoreRRAfter();
List<Conflict> conflicts = new ArrayList<>();
ConflictFilter cf = new ConflictFilter(editor.getDocument());
List<Conflict> conflicts = cf.getConflictsNotResolved(crm);
int size = conflicts.size();
terminalsAffectConflicts = new HashMap<>();
ordersAffectConflicts = new HashMap<>();
int ignored = 0;
for (int i = 0; i < crm.getAllConflicts().size(); i++) {
Conflict c = crm.getAllConflicts().get(i);
if (!isIgnored(c)) {
conflicts.add(c);
addToTerminalSet(crm, c);
addToOrderSet(c);
} else {
ignored++;
}
for(Conflict c : conflicts){
addToTerminalSet(crm, c);
addToOrderSet(c);
}
int size = conflicts.size();
// Do this less often
// updateBuildfile(ignored);
......@@ -321,7 +313,6 @@ public class CupConflictsView extends FailableView
incrementOrSetTo1(ordersAffectConflicts, item1);
incrementOrSetTo1(ordersAffectConflicts, item2);
} catch (internal_error e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......@@ -472,7 +463,8 @@ public class CupConflictsView extends FailableView
}
/**
* Set currentPrecs Doesn't mark affected conflicts
* Start connected resolution
* Doesn't mark affected conflicts
*/
void beginConnectedResolutionSR() {
Shell shell = new Shell(Display.getCurrent());
......@@ -490,6 +482,10 @@ public class CupConflictsView extends FailableView
refreshScrolledLayout();
}
/**
* Start connected resolution
* Doesn't mark affected conflicts
*/
void beginConnectedResolutionRR(){
Shell shell = new Shell(Display.getCurrent());
MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
......@@ -586,10 +582,6 @@ public class CupConflictsView extends FailableView
}
}
boolean isThresholdPresent() {
return (ignoreRRAfterLine != -1);
}
boolean settingOrderAffetsOtherConflicts(lr_item_core item1, lr_item_core item2) {
Integer affected = ordersAffectConflicts.get(item1);
......@@ -605,33 +597,6 @@ public class CupConflictsView extends FailableView
}
}
private int computeIgnoreRRAfter() {
IDocument document = editor.getDocument();
int offset = document.get().indexOf(TRESHOLD_STRING);
if (offset == -1) {
return -1;
}
try {
return document.getLineOfOffset(offset) + 1;
} catch (BadLocationException e) {
return -1;
}
}
private boolean isIgnored(Conflict c) {
if (c instanceof ReduceReduceConflict) {
ReduceReduceConflict rrc = (ReduceReduceConflict) c;
return ((ignoreRRAfterLine >= 0)
&& (rrc.getConflictItem1().the_production().getAstNode().getEnd().getLine() > ignoreRRAfterLine)
&& (rrc.getConflictItem2().the_production().getAstNode().getEnd().getLine() > ignoreRRAfterLine));
} else {
return false;
}
}
public IDocument getDocument() {
return editor.getDocument();
}
......
......@@ -26,6 +26,7 @@ import de.in.tum.www2.cup.analysis.StatisticsVisitor;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.Pair;
import de.tum.in.www2.cupplugin.conflictresolution.ConflictFilter;
import de.tum.in.www2.cupplugin.controller.ControllerStatistics;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.ICupEditorPageVisibility;
......@@ -121,6 +122,7 @@ public class CupOverviewView extends FailableView
private static final int CONFLICTS_TOTAL = 0;
private static final int CONFLICTS_SR = 1;
private static final int CONFLICTS_RR = 2;
private static final int CONFLICTS_RR_RESOLVED = 3;
private static final int DEBUGGER_TARGET_FILE = 0;
private static final int DEBUGGER_BREAKPOINTS = 1;
......@@ -177,10 +179,11 @@ public class CupOverviewView extends FailableView
st.setRowLabel(STATUS_PRODUCTION_NOTREDUCED, "Not reduced Productions:");
st.setRowLabel(STATUS_ERRORS, "Errors:");
conflictsSection = createTableSection("Unresolved conflicts", "", false, 3);
conflictsSection = createTableSection("Unresolved conflicts", "", false, 4);
conflictsSection.getSecond().setRowLabel(CONFLICTS_TOTAL, "Total:");
conflictsSection.getSecond().setRowLabel(CONFLICTS_SR, "Shift/Reduce:");
conflictsSection.getSecond().setRowLabel(CONFLICTS_RR, "Reduce/Reduce:");
conflictsSection.getSecond().setRowLabel(CONFLICTS_RR_RESOLVED, "Resolved Reduce/Reduce:");
debuggerSection = createTableSection("Debugger", "", false, 2);
......@@ -282,18 +285,7 @@ public class CupOverviewView extends FailableView
visible = false;
System.out.println("CupOverviewView became hidden.");
}
/*
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
// we never request jobs ourselves.
return EnumSet.noneOf(JobsToDo.class);
}
@Override
public void jobStatusChanged(JobStatus status) {
// do nothing
}
*/
private void updateStatistics() {
boolean commonSectionNeedsLayout = false;
if (this.ast != null) {
......@@ -364,8 +356,10 @@ public class CupOverviewView extends FailableView
if(this.crm != null){
SimpleTable tbl = conflictsSection.getSecond();
ConflictFilter cf = new ConflictFilter(editor.getDocument());
int sr = 0,rr = 0;
for(Conflict c : crm.getAllConflicts()){
for(Conflict c : cf.getConflictsNotResolved(crm)){
if(c instanceof ShiftReduceConflict){
sr++;
} else {
......@@ -376,6 +370,7 @@ public class CupOverviewView extends FailableView
tbl.setRowValue(CONFLICTS_TOTAL,sr+rr);
tbl.setRowValue(CONFLICTS_SR, sr);
tbl.setRowValue(CONFLICTS_RR, rr);
tbl.setRowValue(CONFLICTS_RR_RESOLVED, cf.getResolvedCountLastRun());
conflictsSection.getFirst().layout();
}
......
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