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

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

parents d8a6bc48 993ca8ec
......@@ -17,10 +17,10 @@ public class Jumper {
}
public void jumpToConflictGraphState(ConflictType conflictType, int index) {
PluginUtility.showMessage("Jumper: Jump to conflict graph state - not yet implemented!");
//PluginUtility.showMessage("Jumper: Jump to conflict graph state - not yet implemented!");
mpe.jumpTo(mpe.CONFLICT_GRAPH_PAGE_INDEX);
// TODO!
// mpe.getConflictGraphView().
mpe.getConflictGraphView().showConflict(conflictType, index);
}
......
......@@ -55,6 +55,7 @@ import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictResolutionManager;
import de.in.tum.www2.cup.ConflictType;
import de.in.tum.www2.cup.CupConflictState;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
......@@ -97,11 +98,12 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
private boolean isVisible = false;
private boolean useDijkstra = true;
private boolean jumperTriggered = false;
private HashMap<Integer, lalr_state> stateHashMap;
private HashSet<lalr_state> visitedStates;
private ConflictResolutionManager conflictResulutionManager;
private ConflictResolutionManager conflictResolutionManager;
public CupConflictGraphView(Composite parent, Jumper jumper,
CupTextEditor editor) {
......@@ -113,8 +115,8 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
this.parseModel = Model.getInstanceForDocument(doc);
this.parseModel.registerModelObserver(this);
this.parentComposite = parent;
this.conflictResulutionManager = new ConflictResolutionManager(
null, true);
this.conflictResolutionManager = new ConflictResolutionManager(null,
true);
this.stateHashMap = new HashMap<Integer, lalr_state>();
......@@ -322,9 +324,9 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
}
}
conflictResulutionManager.setLaLrContext(lalrContext);
conflictResolutionManager.setLaLrContext(lalrContext);
// TODO: This should only contain tainted states!!
List<Conflict> allInterstingConflicts = conflictResulutionManager
List<Conflict> allInterstingConflicts = conflictResolutionManager
.getAllConflicts();
List<String> stateNames = new ArrayList<String>();
for (Conflict conf : allInterstingConflicts) {
......@@ -366,11 +368,11 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
private void setModelForDFSAfterState(lalr_state state) {
if (!useDijkstra) {
conflictResulutionManager.setUseDijkstar(false);
conflictResolutionManager.setUseDijkstar(false);
} else {
conflictResulutionManager.setUseDijkstar(true);
conflictResolutionManager.setUseDijkstar(true);
}
List<CupConflictState> resultList = conflictResulutionManager
List<CupConflictState> resultList = conflictResolutionManager
.searchForState(state);
if (resultList != null) {
String resultString = "";
......@@ -408,6 +410,10 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
public void willBecomeVisible() {
// this.graphViewer.refresh();
isVisible = true;
if (jumperTriggered) {
jumperTriggered = false;
return;
}
if (!Controller.getInstance(editor).requestJobRun()) {
// TODO: Handle no rerun!!
IDocument doc = editor.getDocumentProvider().getDocument(
......@@ -422,6 +428,38 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
}
public void showConflict(ConflictType conflictType, int index) {
jumperTriggered = true;
if (!Controller.getInstance(editor).requestJobRun()) {
// TODO: Handle no rerun!!
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
modelChanged(Model.getInstanceForDocument(doc));
}
String itemString = "";
switch (conflictType) {
case ReduceReduce:
itemString = "RR:State " + index;
break;
case ShiftReduce:
itemString = "SR:State: " + index;
break;
default:
return;
}
int idx = 0;
for (String item : nodeSelection.getItems()) {
if(item.equals(itemString)) {
break;
} else {
idx++;
}
}
nodeSelection.select(idx);
setModelForDFSAfterState(stateHashMap.get(index));
}
static class ParserConflictNode {
private final int id;
private final String name;
......@@ -556,9 +594,9 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
} else {
newNode.setIsNonTerm(true);
}
if(state.getTransition()!=null) {
newNode.setTransitionSymbol(state.getTransition().on_symbol()
.toString());
if (state.getTransition() != null) {
newNode.setTransitionSymbol(state.getTransition()
.on_symbol().toString());
}
nodes.add(newNode);
nodeMap.put(state.getState().index(), newNode);
......@@ -666,6 +704,7 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
if (entity instanceof ParserConflictNode) {
ParserConflictNode n = (ParserConflictNode) entity;
description = new org.eclipse.draw2d.Label(n.getDescription());
description.setText(n.getDescription());
return description;
}
description = new org.eclipse.draw2d.Label("");
......
......@@ -2,6 +2,7 @@ package de.tum.in.www2.cupplugin.wizards;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.Thread.State;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -18,13 +19,17 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
......@@ -35,6 +40,7 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
......@@ -47,6 +53,8 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
private NewJavaProjectWizardPageOne firstPage;
private NewJavaProjectWizardPageTwo secondPage;
private CupProjectWizardPage thirdPage;
private Map<String, Object> controls = new HashMap<String, Object>();
private Map<String, Object> options = new HashMap<String, Object>();
private static final String WIZARD_TITLE = "Create new CUP project";
private static final String WIZARD_DESCRIPTION1 = "CUP projects are based on Java projects. "
......@@ -72,7 +80,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
secondPage.setDescription(WIZARD_DESCRIPTION1);
addPage(secondPage);
thirdPage = new CupProjectWizardPage();
thirdPage = new CupProjectWizardPage(controls);
thirdPage.setTitle(WIZARD_TITLE);
thirdPage.setDescription(WIZARD_DESCRIPTION2);
addPage(thirdPage);
......@@ -151,7 +159,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
e2.printStackTrace();
return false;
}
createLaunchConfiguration(project, launchConfigFile);
ICommand[] commands = desc.getBuildSpec();
......@@ -179,6 +187,8 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
}
private void doFinish(IJavaProject jp, IProgressMonitor monitor) {
boolean generateCalculator = (Boolean) getOption("cup.createExamples.calculator");
boolean useJflex = (Boolean) getOption("cup.useFeature.jflex");
monitor.beginTask("Creating project ...", 2);
......@@ -189,24 +199,46 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
} catch (CoreException e1) {
e1.printStackTrace();
}
IContainer srcDir = (IContainer) project.findMember(new Path("src"));
IFolder cupDir = createDirectory(srcDir, monitor, "cup");
IFolder exampleDir = createDirectory(cupDir, monitor, "example");
IFile parserFile = createFile(project, monitor, "parser.cup",
getTemplate("parser.cup"));
createFile(project, monitor, "lexer.jflex", getTemplate("lexer.jflex"));
createFile(project, monitor, "input.txt", getTemplate("input.txt"));
createFile(project, monitor, "build.xml", getTemplate("build.xml"));
createFile(exampleDir, monitor, "Driver.java", getTemplate("Driver.java"));
IFile parserFile;
if (generateCalculator) {
parserFile = createFile(project, monitor, "parser.cup",
getTemplate("parser.cup"));
createFile(project, monitor, "lexer.jflex",
getTemplate("lexer.jflex"));
createFile(project, monitor, "input.txt", getTemplate("input.txt"));
createFile(project, monitor, "build.xml", getTemplate("build_jflex.xml"));
} else {
parserFile = createFile(project, monitor, "parser.cup",
getTemplate("empty_file"));
if (useJflex) {
createFile(project, monitor, "lexer.jflex",
getTemplate("empty_file"));
createFile(project, monitor, "build.xml", getTemplate("build_jflex.xml"));
}else{
createFile(project, monitor, "build.xml", getTemplate("build.xml"));
}
}
createFile(exampleDir, monitor, "Driver.java",
getTemplate("Driver.java"));
IFolder folder = createDirectory(project, monitor, "tools");
createFile(folder, monitor, "JFlex.jar", getTemplate("JFlex.jar"));
IFile runtimeFile = createFile(folder, monitor, "java-cup-11b-runtime.jar",
if(useJflex){
createFile(folder, monitor, "JFlex.jar", getTemplate("JFlex.jar"));
}
IFile runtimeFile = createFile(folder, monitor,
"java-cup-11b-runtime.jar",
getTemplate("java-cup-11b-runtime.jar"));
createFile(folder, monitor, "java-cup-11b.jar",
getTemplate("java-cup-11b.jar"));
......@@ -221,16 +253,17 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
IClasspathEntry[] newClassPath = new IClasspathEntry[oldClassPath.length + 1];
for (int i = 0; i < oldClassPath.length; i++)
newClassPath[i] = oldClassPath[i];
newClassPath[oldClassPath.length] = JavaCore.newLibraryEntry(runtimeFile.getFullPath(), null, null);
newClassPath[oldClassPath.length] = JavaCore.newLibraryEntry(
runtimeFile.getFullPath(), null, null);
try {
jp.setRawClasspath(newClassPath, monitor);
} catch (JavaModelException e1) {
e1.printStackTrace();
}
}
setBuilder(project);
monitor.worked(1);
......@@ -317,18 +350,54 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
+ "/build.xml}\"/>\n"
+ "<stringAttribute key=\"org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS\" value=\"full,incremental,\"/>\n"
+ "<booleanAttribute key=\"org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED\" value=\"true\"/>\n</launchConfiguration>";
IFile file = project.getFile(filename);
if (!file.exists()) {
byte[] bytes = FileContents.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
try {
byte[] bytes = FileContents.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
try {
file.create(source, IResource.NONE, null);
} catch (CoreException e) {
return false;
}
return true;
return true;
}
return false;
}
private void refreshOptions() {
UIJob j = new UIJob("refreshOptions") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
for (Map.Entry<String, Object> e : controls.entrySet()) {
if (e.getValue() instanceof Button) {
Button b = (Button) e.getValue();
if ((b.getStyle() & SWT.CHECK) == SWT.CHECK) {
options.put(e.getKey(),
new Boolean(b.getSelection()));
}
}
}
return Status.OK_STATUS;
}
};
j.setSystem(true);
j.schedule();
try {
j.join();
} catch (InterruptedException e) {
return;
}
return;
}
public Object getOption(String option) {
refreshOptions();
return options.get(option);
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.wizards;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class CupProjectWizardPage extends WizardPage {
public CupProjectWizardPage() {
private Map<String, Object> controls = new HashMap<String, Object>();
public CupProjectWizardPage(Map<String, Object> controls) {
super("wizardPage");
this.controls = controls;
setTitle("CUP Project Options");
setDescription("Configure CUP project ...");
}
......@@ -18,12 +25,26 @@ public class CupProjectWizardPage extends WizardPage {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 3;
layout.numColumns = 1;
layout.verticalSpacing = 9;
Label label = new Label(container, SWT.NULL);
label.setText("&Test:");
label.setText("&CUP project options:");
addOptions(container);
setControl(container);
}
private void addOptions(Composite c) {
Button current = new Button(c, SWT.CHECK);
current.setText("Create calculator example files");
current.setSelection(true);
controls.put("cup.createExamples.calculator", current);
current = new Button(c, SWT.CHECK);
current.setText("Use jflex");
current.setSelection(true);
controls.put("cup.useFeature.jflex", current);
}
}
\ No newline at end of file
......@@ -7,7 +7,6 @@
<property name="tools" location="tools" />
<property name="base" location="." />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" />
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" />
<target name="generate">
......@@ -17,7 +16,7 @@
interface="true"
locations="true"
debugsymbols="true" />
<jflex file="lexer.jflex" destdir="${java}" />
</target>
<path id="libraries">
......
<project name="MyProject" default="compile" basedir=".">
<property name="java" location="src" />
<property name="classes" location="bin/cls" />
<property name="result" location="bin/jar" />
<property name="lib" location="lib" />
<property name="tools" location="tools" />
<property name="base" location="." />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" />
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" />
<target name="generate">
<cup srcfile="${base}/parser.cup" destdir="${java}"
parser="Parser"
interface="true"
locations="true"
debugsymbols="true" />
<jflex file="lexer.jflex" destdir="${java}" />
</target>
<path id="libraries">
<files includes="${tools}/java-cup-11b-runtime.jar" />
</path>
<target name="compile" depends="generate">
<mkdir dir="${classes}"/>
<mkdir dir="${result}"/>
<javac includeantruntime="false" srcdir="${java}" destdir="${classes}">
<classpath refid="libraries" />
</javac>
</target>
<target name="clean">
<delete file="${java}/Parser.java" />
<delete file="${java}/sym.java" />
<delete file="${java}/Scanner.java" />
<delete dir="${classes}" />
<delete dir="${result}" />
</target>
</project>
\ No newline at end of file
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