Commit d9735492 authored by Johannes Roith's avatar Johannes Roith

Merge branch 'master' of github.com:jroith/cup-eclipse

parents 6374c1d0 5a82b4f4
package de.tum.in.www2.cupplugin.controller;
import java.awt.Event;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
......@@ -12,10 +10,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.texteditor.IDocumentProvider;
......@@ -23,14 +19,10 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.CupParser;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.NoopErrorReporter;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.analysis.LocationPatchVisitor;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.internal.internal_error;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.editors.CupEditorErrorReporter;
import de.tum.in.www2.cupplugin.editors.CupPartionScanner;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.RevisionManager;
import de.tum.in.www2.cupplugin.model.Model;
......@@ -149,7 +141,7 @@ public class DocumentDidChangeJob extends Job {
context.start_production);
} else {
System.out.println("LALRResult.Compute was not called, "
+ "because the parser has reported errors.");
+ "because the parser has reported errors.");//TODO: REMOVE
}
} catch (internal_error e) {
e.printStackTrace();
......
......@@ -72,7 +72,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
addHooksToMainTextEditor(editor);
editor.addActions();
IDocument doc = editor.getDocument();
editor.getDocument();
// we need to call init _after_ the editor has a document.
editor.init();
......@@ -96,7 +96,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
void createOverviewPage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocument();
overviewView = new CupOverviewView(composite, jumper, doc, editor.getTitle());
overviewView = new CupOverviewView(composite, jumper, doc, editor.getTitle(),editor);
addPage(OVERVIEW_PAGE_INDEX, composite);
setPageText(OVERVIEW_PAGE_INDEX, "Overview");
}
......@@ -110,7 +110,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
void createActionTablePage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocument();
editor.getDocument();
actionTableView = new CupActionTableView(composite, jumper, editor);
addPage(ACTION_TABLE_PAGE_INDEX, composite);
setPageText(ACTION_TABLE_PAGE_INDEX, "Action Table");
......@@ -126,7 +126,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
void createConflictGraphPage(Jumper jumper) {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocument();
editor.getDocument();
conflictGraphView = new CupConflictGraphView(composite, jumper, editor);
addPage(CONFLICT_GRAPH_PAGE_INDEX, composite);
setPageText(CONFLICT_GRAPH_PAGE_INDEX, "Conflict Graph");
......
package de.tum.in.www2.cupplugin.views;
import java.sql.Time;
import java.util.EnumSet;
import java.util.HashSet;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
......@@ -7,69 +11,103 @@ import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.ErrorManager;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.internal.lalr_state;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.ICupEditorPageVisibility;
import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserASTChangeObserver;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupOverviewView {
public class CupOverviewView implements IRegisterForControllerChanges,
ICupEditorPageVisibility, ICupParserLaLrChangeObserver,
ICupParserASTChangeObserver {
private static final int OUTER_MARGIN = 10;
private static final int INNER_MARGIN = 10;
private static final String SECTION_ANALYSIS = "Analysis";
private static final String SECTION_ANALYSIS_DESCRIPTION_TEMPLATE =
"Redundant Productions\t\t%5d\n"
+ "Unused terminals\t\t%5d\n"
+ "Unused non terminals:\t\t%d";
private static final String SECTION_PARSE_TABLES = "Parse Tables";
private static final String SECTION_PARSE_TABLES_DESCRIPTION_TEMPLATE = "last created, up2date, number of states, number of entries";
private static final String SECTION_CONTENT = "Content";
private static final String SECTION_CONTENT_DESCRIPTION_TEMPLATE = "start production, package, parser class, terminals, non-terminals";
private static final String SECTION_GRAMMAR = "Grammar";
private static final String SECTION_GRAMMAR_DESCRIPTION_TEMPLATE = "last checked, up2date, syntax correct";
private static final String SECTION_CONFLICTS = "Conflicts";
private static final String SECTION_CONFLICTS_DESCRIPTION_TEMPLATE = "Number of conflicts, etc.";
boolean visible = false;
private IDocument doc;
private FormToolkit toolkit;
private ScrolledForm form;
private CupTextEditor myEditor;
HashSet<Composite> sections = new HashSet<Composite>();
public CupOverviewView(Composite parent, Jumper jumper, IDocument doc, String title) {
public CupOverviewView(Composite parent, Jumper jumper, IDocument doc,
String title, CupTextEditor editor) {
this.doc = doc;
setupForm(parent, title);
myEditor = editor;
Composite section0 = createSection("Analysis", "double productions, unused terminals, unused non terminals", false);
Composite section1 = createSection("Parse Tables",
"last created, up2date, number of states, number of entries", false);
Composite section2 = createSection("Content", "start production, package, parser class, terminals, non-terminals", true);
Composite section3 = createSection("Grammar", "last checked, up2date, syntax correct", false);
Composite section4 = createSection("Conflicts", "Number of conflicts, etc.", false);
Controller.getInstance(editor).registerObserver(this);
Model.getInstanceForDocument(doc).registerModelObserver(this);
sections.add(createSection(SECTION_ANALYSIS,
SECTION_ANALYSIS_DESCRIPTION_TEMPLATE, false));
sections.add(createSection(SECTION_PARSE_TABLES,
SECTION_PARSE_TABLES_DESCRIPTION_TEMPLATE, false));
sections.add(createSection(SECTION_CONTENT,
SECTION_CONTENT_DESCRIPTION_TEMPLATE, true));
sections.add(createSection(SECTION_GRAMMAR,
SECTION_GRAMMAR_DESCRIPTION_TEMPLATE, false));
sections.add(createSection(SECTION_CONFLICTS,
SECTION_CONFLICTS_DESCRIPTION_TEMPLATE, false));
}
private Composite createSection(String title, String description, boolean doSpan) {
Section section = toolkit.createSection(form.getBody(),
Section.DESCRIPTION | Section.TITLE_BAR);
section.setText(title);
section.setDescription(description);
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = 200;
data.heightHint = 100;
if (doSpan)
data.horizontalSpan = 2;
section.setLayoutData(data);
// Composite for storing the data
Composite client = toolkit.createComposite(section, SWT.WRAP);
FillLayout layout = new FillLayout();
layout.marginWidth = INNER_MARGIN;
layout.marginHeight = INNER_MARGIN;
client.setLayout(layout);
section.setClient(client);
return client;
private Composite createSection(String title, String description,
boolean doSpan) {
Section section = toolkit.createSection(form.getBody(),
Section.DESCRIPTION | Section.TITLE_BAR);
section.setText(title);
section.setDescription(description);
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = 200;
data.heightHint = 100;
if (doSpan)
data.horizontalSpan = 2;
section.setLayoutData(data);
// Composite for storing the data
Composite client = toolkit.createComposite(section, SWT.WRAP);
FillLayout layout = new FillLayout();
layout.marginWidth = INNER_MARGIN;
layout.marginHeight = INNER_MARGIN;
client.setLayout(layout);
section.setClient(client);
return client;
}
private void setupForm(Composite parent, String title) {
parent.setBackground(new Color(parent.getDisplay(), 255, 255, 255));
FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = OUTER_MARGIN;
fillLayout.marginHeight = OUTER_MARGIN;
fillLayout.marginWidth = OUTER_MARGIN;
fillLayout.marginHeight = OUTER_MARGIN;
parent.setLayout(fillLayout);
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setText("CUP Parser Generator : " + title);
......@@ -77,25 +115,89 @@ public class CupOverviewView {
bodyLayout.numColumns = 2;
bodyLayout.marginTop = 20;
bodyLayout.makeColumnsEqualWidth = true;
form.getBody().setLayout(bodyLayout);
// form.getBody().setBackground(new Color(parent.getDisplay(), 255, 0, 0));
form.getBody().setLayout(bodyLayout);
// form.getBody().setBackground(new Color(parent.getDisplay(), 255, 0,
// 0));
}
public void dispose() {
toolkit.dispose();
}
public void willBecomeVisible() {
System.out.println("CupOverviewView will become visible.");
visible = true;
if (!Controller.getInstance(myEditor).requestJobRun()) {
// TODO: Handle no rerun!!
// Model model = Model.getInstanceForDocument(doc);
// LALRResult result = model.getLaLrResult();
// int numberOfStates = lalr_state.number(result.getContext());
}
// Model model = Model.getInstanceForDocument(doc);
// LALRResult result = model.getLaLrResult();
// int numberOfStates = lalr_state.number(result.getContext());
}
public void becameHidden() {
visible = false;
System.out.println("CupOverviewView became hidden.");
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
return visible ? EnumSet.of(JobsToDo.buildTable, JobsToDo.parseCode)
: EnumSet.noneOf(JobsToDo.class);
}
@Override
public void modelChanged(Model model) {
System.out.println("ModelChangedEvent");
if (model == null) {
return;
}
ParserResult astModel = model.getAstModel();
if(astModel == null){
return;
}
ErrorManager eManager = model.getAstModelContext().getErrorManager();
for (Composite e : sections) {
Section section = (Section) e.getParent();
switch (section.getText()) {
case SECTION_ANALYSIS:
int redundantProductions = 0;
int unusedTerminals = 0;
int unusedNonTerminals = 0;
section.setDescription(String.format(SECTION_ANALYSIS_DESCRIPTION_TEMPLATE,redundantProductions,unusedTerminals,unusedNonTerminals));
break;
case SECTION_CONFLICTS:
section.setDescription(String.format(SECTION_CONFLICTS_DESCRIPTION_TEMPLATE));
break;
case SECTION_CONTENT:
section.setDescription(String.format(SECTION_CONTENT_DESCRIPTION_TEMPLATE));
break;
case SECTION_GRAMMAR:
section.setDescription(String.format(SECTION_GRAMMAR_DESCRIPTION_TEMPLATE));
break;
case SECTION_PARSE_TABLES:
section.setDescription(String.format(SECTION_PARSE_TABLES_DESCRIPTION_TEMPLATE));
break;
default:
break;
}
}
}
}
......@@ -266,15 +266,26 @@ public class CupReduceGraphView implements ICupParserLaLrChangeObserver,
}
public void reloadGraph() {
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] {
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) // ,
// new GridLayoutAlgorithm(
// LayoutStyles.NO_LAYOUT_NODE_RESIZING)
});
LayoutAlgorithm layout = null;
if (nodeModel.getNodes().size() <= 40) {
layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
} else {
layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
}
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
synchronized (CupReduceGraphView.modelBuildLock) {
......@@ -401,12 +412,15 @@ public class CupReduceGraphView implements ICupParserLaLrChangeObserver,
rebuildJob.cancel();
}
rebuildJob = new ModelRebuildJob(model, lalrResult,
lalrContext, connections, nodes, nodeMap, reduceGraphView);
lalrContext, connections, nodes, nodeMap,
reduceGraphView);
rebuildJob.setSystem(false);
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
progressService.showInDialog(Display.getCurrent().getActiveShell(), rebuildJob);
IProgressService progressService = PlatformUI.getWorkbench()
.getProgressService();
progressService.showInDialog(Display.getCurrent()
.getActiveShell(), rebuildJob);
rebuildJob.schedule();
}
/*
......@@ -547,10 +561,11 @@ public class CupReduceGraphView implements ICupParserLaLrChangeObserver,
}
}
}
ModelRebuildJobFinished job = new ModelRebuildJobFinished(reduceGraphView);
ModelRebuildJobFinished job = new ModelRebuildJobFinished(
reduceGraphView);
job.setSystem(true);
job.schedule();
return Status.OK_STATUS;
}
......
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