Commit d0e782b8 authored by Sebastian Pretscher's avatar Sebastian Pretscher

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

parents a8fb2740 a93cb319
......@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt;bundle-version="3.10.0",
org.eclipse.jdt.debug;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1"
org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
package de.tum.in.www2.cupplugin;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.eclipse.core.resources.IWorkspace;
import de.tum.in.www2.cupplugin.debug.BreakpointMapper;
import de.tum.in.www2.cupplugin.debug.Debugger;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
public class DebugListener implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("GOT EVENT: " + event.getType());
Debugger.getBreakpointMapper().remap();
if (event.getType() != IResourceChangeEvent.POST_BUILD)
return;
System.out.println("GOT POST BUILD EVENT!");
}
}
// The plug-in ID
public static final String PLUGIN_ID = "CupPlugin"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(new DebugListener());
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
......@@ -32,7 +56,10 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
* )
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
......@@ -49,10 +76,11 @@ public class Activator extends AbstractUIPlugin {
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
* Returns an image descriptor for the image file at the given plug-in
* relative path
*
* @param path the path
* @param path
* the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
......
......@@ -20,12 +20,17 @@ import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
import org.eclipse.jdt.debug.core.JDIDebugModel;
import de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor.Mapping;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.GeneratedFileLocator;
import de.tum.in.www2.cupplugin.PluginUtility;
public class BreakpointMapper {
private Map<CupLineBreakpoint, IBreakpoint> mappings = new HashMap<CupLineBreakpoint, IBreakpoint>();
private Set<CupLineBreakpoint> breakpoints = new HashSet<CupLineBreakpoint>();
private GeneratedFileLocator locator = new GeneratedFileLocator();
public IBreakpoint getRemoteBreakpoint(CupLineBreakpoint breakpoint) {
return mappings.get(breakpoint);
}
......@@ -47,8 +52,13 @@ public class BreakpointMapper {
if(originResource == null){
return;
}
IFile resource = PluginUtility.findGenerated(((IFile) origin
.getResource()));
ParserResult astModel = Debugger.getInstance(originResource).getParserResult();
if(astModel == null){
return;
}
IFile resource = locator.find((IFile) originResource, astModel);
if(resource == null){
return;
}
......
......@@ -23,8 +23,7 @@ public class Debugger {
static HashMap<IResource, Debugger> delayedInstances = new HashMap<IResource, Debugger>();
private static final BreakpointMapper breakpointMapper = new BreakpointMapper();
private static final String DEFAULT_CLASS = "Test";// TODO: auf Parser
// umstellen
private static final String DEFAULT_CLASS = "Parser";
/**
* Add Debug hooks to an editor
......@@ -94,7 +93,7 @@ public class Debugger {
}
current = null;
}
Debugger tmp = new Debugger(new CupTextEditor());
Debugger tmp = new Debugger(new CupTextEditor());// TODO: lösen
delayedInstances.put(resource, tmp);
return tmp;
......@@ -151,11 +150,9 @@ public class Debugger {
* @return the class name
*/
public String getGeneratedTargetClass(CupLineBreakpoint breakpoint) {
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider()
.getDocument(myEditor.getEditorInput()));
try {
String rname = m.getAstModel().className.getName().name;
String rname = getParserResult().className.getName().name;
if (!rname.trim().equals("")) {
return rname;
}
......@@ -167,9 +164,7 @@ public class Debugger {
}
public Mapping getDebugId(int lineNumber) {
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider()
.getDocument(myEditor.getEditorInput()));
ParserResult astModel = m.getAstModel();
ParserResult astModel = getParserResult();
if (astModel == null) {
return null;
......@@ -186,4 +181,13 @@ public class Debugger {
}
public ParserResult getParserResult(){
if(myEditor == null){
System.out.println("myEditor: NULL");
}
Model m = Model.getInstanceForDocument(myEditor.getDocument());
ParserResult astModel = m.getAstModel();
return astModel;
}
}
\ No newline at end of file
......@@ -22,30 +22,31 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
/*
* find out where the editor is
*/
if (part instanceof CupTextEditor){
if (part instanceof CupTextEditor) {
textEditor = (CupTextEditor) part;
}
else if (part instanceof MultiPageEditor) {
} else if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
if (editor instanceof CupTextEditor)
textEditor = (CupTextEditor) editor;
}
if (textEditor != null) {
//prepare everything
// prepare everything
IResource resource = (IResource) textEditor.getEditorInput()
.getAdapter(IResource.class);
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
int nextPossibleLine = (Debugger.getInstance((CupTextEditor)textEditor).getNextCodeBlockForLineBreakpoint(((ITextSelection)selection).getStartLine()));
if( nextPossibleLine != -1){
int nextPossibleLine = (Debugger
.getInstance((CupTextEditor) textEditor)
.getNextCodeBlockForLineBreakpoint(((ITextSelection) selection)
.getStartLine()));
if (nextPossibleLine != -1) {
lineNumber = nextPossibleLine;
}else{
} else {
return;
}
// get doc identifier:
IDocument doc = null;
......@@ -55,18 +56,18 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
if (doc == null) {
return;
}
//create preakpoint and give it to IDE
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger.getBreakpointManager()
.getBreakpoints();
// create preakpoint and give it to IDE
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger
.getBreakpointManager().getBreakpoints();
if (breakpoints != null) {
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (resource.equals(breakpoint.getMarker().getResource())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
// existing breakpoint; delete
Debugger.getBreakpointManager()
.removeBreakpoint(breakpoint, true);
Debugger.getBreakpointManager().removeBreakpoint(
breakpoint, true);
return;
}
}
......@@ -76,11 +77,11 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
// new breakpoint; create
CupLineBreakpoint lineBreakpoint = new CupLineBreakpoint(resource,
lineNumber + 1);
Debugger.getBreakpointManager()
.addBreakpoint(lineBreakpoint);
/*System.out.println("CREATED! Length: "
+ Debugger.getBreakpointManager()
.getBreakpoints().length);*/// TODO: DELETE
Debugger.getBreakpointManager().addBreakpoint(lineBreakpoint);
/*
* System.out.println("CREATED! Length: " +
* Debugger.getBreakpointManager() .getBreakpoints().length);
*/// TODO: DELETE
}
}
......@@ -89,19 +90,30 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
public boolean canToggleLineBreakpoints(IWorkbenchPart part,
ISelection selection) {
// true, if we have an CupTextEditor
if (part instanceof CupTextEditor)
return true;
if (part instanceof CupTextEditor) {
if (selection instanceof ITextSelection) {
return (Debugger.getInstance((CupTextEditor) part)
.getNextCodeBlockForLineBreakpoint(
((ITextSelection) selection).getStartLine()) != -1);
} else {
return false;
}
}
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Breakpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
if (editor instanceof CupTextEditor){
if(selection instanceof ITextSelection){
return (Debugger.getInstance((CupTextEditor)editor).getNextCodeBlockForLineBreakpoint(((ITextSelection)selection).getStartLine()) != -1);
}
else{
/*
* System.out.println("" + editor +
* " is a CupTextEditor(Breakpoints):" + (editor instanceof
* CupTextEditor));
*/// TODO: DELETE
if (editor instanceof CupTextEditor) {
if (selection instanceof ITextSelection) {
return (Debugger
.getInstance((CupTextEditor) editor)
.getNextCodeBlockForLineBreakpoint(
((ITextSelection) selection).getStartLine()) != -1);
} else {
return false;
}
}
......@@ -112,54 +124,53 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
@Override
public void toggleMethodBreakpoints(IWorkbenchPart part,
ISelection selection) throws CoreException {
//not implemented
//System.out.println("toggle watchpoints called");// TODO: DELETE
// not implemented
// System.out.println("toggle watchpoints called");// TODO: DELETE
}
@Override
public boolean canToggleMethodBreakpoints(IWorkbenchPart part,
ISelection selection) {
//default answer: false
// default answer: false
return false;
//do this, if you want to toggle method bps
/*if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(MethodBreakpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
// do this, if you want to toggle method bps
/*
* if (part instanceof CupTextEditor) return true; if (part instanceof
* MultiPageEditor) { Object editor = ((MultiPageEditor)
* part).getSelectedPage(); /*System.out.println("" + editor +
* " is a CupTextEditor(MethodBreakpoints):" + (editor instanceof
* CupTextEditor));
*/// TODO: DELETE
/*
* return (editor instanceof CupTextEditor); } return false;
*/
}
@Override
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection)
throws CoreException {
//System.out.println("toggleWatchpoints called");
// System.out.println("toggleWatchpoints called");
}
@Override
public boolean canToggleWatchpoints(IWorkbenchPart part,
ISelection selection) {
return false;
/*
if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Watchpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
* if (part instanceof CupTextEditor) return true; if (part instanceof
* MultiPageEditor) { Object editor = ((MultiPageEditor)
* part).getSelectedPage(); /*System.out.println("" + editor +
* " is a CupTextEditor(Watchpoints):" + (editor instanceof
* CupTextEditor));
*/// TODO: DELETE
/*
* return (editor instanceof CupTextEditor); } return false;
*/
}
}
\ No newline at end of file
package cup.example;
class Driver {
public static void main(String[] args) throws Exception {
......
......@@ -5,21 +5,23 @@
<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">
<jflex file="lexer.jflex" destdir="${java}" />
<cup srcfile="parser.cup" destdir="${java}"
<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="${lib}/java-cup-11b-runtime.jar" />
<files includes="${tools}/java-cup-11b-runtime.jar" />
</path>
<target name="compile" depends="generate">
......
package de.in.tum.www2.cup.internal;
package cup.example;
import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.ComplexSymbolFactory.Location;
import java_cup.runtime.Symbol;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.ErrorManager;
import de.in.tum.www2.cup.ErrorSource;
import java.lang.Error;
import java.io.InputStreamReader;
......@@ -19,7 +16,7 @@ import java.io.InputStreamReader;
%cup
%char
%{
private ErrorManager errMan;
public Lexer(ComplexSymbolFactory sf, java.io.InputStream is){
this(is);
......@@ -47,12 +44,12 @@ import java.io.InputStreamReader;
}
protected void emit_warning(String message){
System.out.println("scanner warning: " + message + " at : 2 +
System.out.println("scanner warning: " + message + " at : 2 "+
(yyline+1) + " " + (yycolumn+1) + " " + yychar);
}
protected void emit_error(String message){
System.out.println("scanner error: " + message + " at : 2 +
System.out.println("scanner error: " + message + " at : 2" +
(yyline+1) + " " + (yycolumn+1) + " " + yychar);
}
%}
......@@ -84,10 +81,7 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
"other" { return symbol("OTHERTERMINAL",OTHERTERMINAL); }
}
<CODESEG> {
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn),new Location(yyline+1,yycolumn+1+yylength()), sb.toString()); }
.|\n { sb.append(yytext()); }
}
// error fallback
.|\n { emit_warning("Unrecognized character '" +yytext()+"' -- ignored"); }
package cup.example;
import java_cup.runtime.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
parser code {:
:}
init with {: :}
scan with {: :}
/* override error routines */
protected Lexer lexer;
:};
init with {:
ComplexSymbolFactory f = new ComplexSymbolFactory();
symbolFactory = f;
File file = new File("input.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
}catch (IOException e) {
e.printStackTrace();
}
lexer = new Lexer(f,fis);
:};
scan with {: return lexer.next_token(); :};
terminal MYTERMINAL, OTHERTERMINAL;
non terminal Integer expr;
......
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