Commit 1cbc1dec authored by baueko's avatar baueko

tried to fix classpathEntries

parent 1384c957
......@@ -6,6 +6,7 @@ import de.in.tum.www2.cup.ast.LabeledProductionSymbolRef;
import de.in.tum.www2.cup.ast.Production;
import de.in.tum.www2.cup.ast.ProductionRight;
//TODO rename
public class LabelToVariableVisitor extends Visitor<Object> {
ActionCodeBlock block;
......
package de.in.tum.www2.cup.ast;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.SimpleName;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.analysis.AbstractVisitor;
......@@ -34,10 +30,9 @@ public class ActionCodeBlock extends CodeBlock implements IProductionRightPart {
@Override
public void parseJavaCode(String[] classpathEntries) {
//
LabelToVariableVisitor visitor = new LabelToVariableVisitor(this);
this.getParent().accept(visitor, null);
CompilationUnit cu = (CompilationUnit) JavaCompiler.parseJava(getBlob(), this, classpathEntries);
BindingCollector variableCollector = new BindingCollector();
cu.accept(variableCollector);
......
......@@ -12,7 +12,7 @@ import org.eclipse.jdt.core.dom.SimpleName;
import de.in.tum.www2.cup.Range;
public abstract class CodeBlock extends AbstractNode {
protected IProblem[] problems;
protected HashMap<IVariableBinding, LinkedList<SimpleName>> variableMap;
protected LinkedList<SimpleName> methodList;
......@@ -22,7 +22,6 @@ public abstract class CodeBlock extends AbstractNode {
private String blob;
private BlockType bt;
private ASTNode tree;
public CompilationUnit getCompilationUnit() {
return cu;
......@@ -31,7 +30,7 @@ public abstract class CodeBlock extends AbstractNode {
public void setCompilationUnit(CompilationUnit cu) {
this.cu = cu;
}
public IProblem[] getProblems() {
return problems;
}
......
package de.in.tum.www2.cup.ast;
import java.util.HashMap;
import java.util.LinkedList;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import de.in.tum.www2.cup.ast.CodeBlock.BlockType;
public class JavaCompiler {
/**
*
* @param userCode
......@@ -33,8 +18,6 @@ public class JavaCompiler {
public static ASTNode parseJava(String userCode, CodeBlock codeblock, String[] classpathEntries) {
ASTParser parser = ASTParser.newParser(AST.JLS8);
ASTNode node;
// String[] classpathEntries = new String[] { "lib\\java-cup-11b-runtime.jar" };// jars
String[] sourcepathEntries = new String[] { "" };
parser.setEnvironment(classpathEntries, sourcepathEntries, new String[] { "UTF-8" }, true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
......@@ -43,10 +26,6 @@ public class JavaCompiler {
String dummyClass = "";
// File f = new File("");
// System.out.println(f.getAbsolutePath());
// C:\Users\Konstantin\git\cup-eclipse-plugin\CupParser
final String IMPORTS = "import java_cup.runtime.ComplexSymbolFactory.Location;\n";
final String DUMMY_CLASS_DEF = "public class DummyClass\n{";
final String RWING = "}";
......@@ -56,35 +35,36 @@ public class JavaCompiler {
final String DUMMY_METHOD_END = "\n\t" + RWING;
switch (codeblock.getBt()) {
case Action:
case Parser:
dummyClass = DUMMY_CLASS_DEF + userCode + RWING;
break;
case Init:
case Scan:
dummyClass = DUMMY_CLASS_DEF + DUMMY_METHOD_DEF + DUMMY_METHOD_ARGS_END + userCode + DUMMY_METHOD_END
case Action:
case Parser:
dummyClass = DUMMY_CLASS_DEF + userCode + RWING;
break;
case Init:
case Scan:
// TODO return
dummyClass = DUMMY_CLASS_DEF + DUMMY_METHOD_DEF + DUMMY_METHOD_ARGS_END + userCode + DUMMY_METHOD_END
+ DUMMY_CLASS_DEF_END;
break;
case ActionCode:
ActionCodeBlock block = (ActionCodeBlock) codeblock;
dummyClass = IMPORTS + DUMMY_CLASS_DEF + DUMMY_METHOD_DEF;
// TODO return type
dummyClass += block.getReturnType() + " RESULT";
for (LabeledProductionSymbolRef l : block.getVariables()) {
dummyClass += ", " + l.getDatatype() + " " + l.label;
dummyClass += ", " + "Location" + " " + l.label + "xleft"; // TODO Object should really be a Location
dummyClass += ", " + "Location" + " " + l.label + "xright"; // TODO Object should really be a Location
dummyClass += ", " + "int" + " " + l.label + "left";
dummyClass += ", " + "int" + " " + l.label + "right";
}
dummyClass += DUMMY_METHOD_ARGS_END + "\n\t\t";
dummyClass += userCode;
dummyClass += DUMMY_METHOD_END + DUMMY_CLASS_DEF_END;
break;
default:
throw new UnsupportedOperationException("java parsing not implemented: unknown blocktype");
break;
case ActionCode:
ActionCodeBlock block = (ActionCodeBlock) codeblock;
dummyClass = IMPORTS + DUMMY_CLASS_DEF + DUMMY_METHOD_DEF;
// TODO return type
dummyClass += block.getReturnType() + " RESULT";
for (LabeledProductionSymbolRef l : block.getVariables()) {
dummyClass += ", " + l.getDatatype() + " " + l.label;
dummyClass += ", " + "Location" + " " + l.label + "xleft"; // TODO Object should really be a Location
dummyClass += ", " + "Location" + " " + l.label + "xright"; // TODO Object should really be a Location
dummyClass += ", " + "int" + " " + l.label + "left";
dummyClass += ", " + "int" + " " + l.label + "right";
}
dummyClass += DUMMY_METHOD_ARGS_END + "\n\t\t";
dummyClass += userCode;
dummyClass += DUMMY_METHOD_END + DUMMY_CLASS_DEF_END;
break;
default:
throw new UnsupportedOperationException("java parsing not implemented: unknown blocktype");
}
parser.setSource(dummyClass.toCharArray());
node = parser.createAST(null);
......
package de.tum.in.www2.cupplugin;
import java.io.File;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
......@@ -20,24 +24,21 @@ import de.tum.in.www2.cupplugin.editors.MultiPageEditor;
public final class PluginUtility {
public static void showMessage(String message) {
MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getDisplay()
.getActiveShell());
MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell());
mb.setMessage(message);
mb.open();
}
public static void fullSyntaxRefresh(ISourceViewer sourceViewer) {
/*
* System.out.println(
* ">>>>>>>>>>>>>> FULL REFRESH OF SYNTAX HIGHLIGHTING! <<<<<<<<<<<<<<<"
* ); TODO: REMOVE OUTPUT
* System.out.println( ">>>>>>>>>>>>>> FULL REFRESH OF SYNTAX HIGHLIGHTING! <<<<<<<<<<<<<<<" ); TODO: REMOVE
* OUTPUT
*/
sourceViewer.invalidateTextPresentation();
}
public static Range getRangeFromSelection(CupTextEditor editor) {
ITextSelection textSelection = (ITextSelection) editor.getSite()
.getSelectionProvider().getSelection();
ITextSelection textSelection = (ITextSelection) editor.getSite().getSelectionProvider().getSelection();
int offset = textSelection.getOffset();
......@@ -50,15 +51,13 @@ public final class PluginUtility {
try {
int startLineNumber = document.getLineOfOffset(offset);
int startColumn = offset - document.getLineOffset(startLineNumber);
Position start = new Position(startLineNumber + 1, startColumn + 1,
offset + 1);
Position start = new Position(startLineNumber + 1, startColumn + 1, offset + 1);
int endOffset = offset + textSelection.getLength();
int endLineNumber = document.getLineOfOffset(endOffset);
int endColumn = endOffset - document.getLineOffset(endLineNumber);
Position end = new Position(endLineNumber + 1, endColumn + 1,
endOffset);
Position end = new Position(endLineNumber + 1, endColumn + 1, endOffset);
return new Range(start, end);
} catch (BadLocationException e) {
......@@ -66,10 +65,8 @@ public final class PluginUtility {
}
}
public static CupTextEditor getEditorFromEvent(ExecutionEvent event)
throws ExecutionException {
MultiPageEditor mpe = (MultiPageEditor) HandlerUtil
.getActiveEditorChecked(event);
public static CupTextEditor getEditorFromEvent(ExecutionEvent event) throws ExecutionException {
MultiPageEditor mpe = (MultiPageEditor) HandlerUtil.getActiveEditorChecked(event);
if (mpe == null)
return null;
return mpe.getEditor();
......@@ -77,8 +74,7 @@ public final class PluginUtility {
public static IFile getReverseFilePartner(IFile javaFile) {
/*
* for(Tuple<IFile,IFile> e : fileMatching){ if( e.has(javaFile)){
* return (IFile)e.other(javaFile); } }
* for(Tuple<IFile,IFile> e : fileMatching){ if( e.has(javaFile)){ return (IFile)e.other(javaFile); } }
*/return null;
}
......@@ -86,11 +82,21 @@ public final class PluginUtility {
if (cupFile == null || javaFile == null)
return;
/*
* for(Tuple<IFile,IFile> e : fileMatching){ if(e.has(cupFile) ||
* e.has(javaFile)){ fileMatching.remove(e); } }
* for(Tuple<IFile,IFile> e : fileMatching){ if(e.has(cupFile) || e.has(javaFile)){ fileMatching.remove(e); } }
*/
// fileMatching.add(new Tuple<IFile, IFile>(cupFile, javaFile));
return;
}
// TODO move somewhere else?
public static String[] createClasspath() {
final String PATH_TO_JAVA_CUP_RUNTIME = File.separator + "tools" + File.separator + "java-cup-11b-runtime.jar";
final String PATH_TO_ECLIPSE_APPLICATION = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
final String PROJECTNAME = ResourcesPlugin.getWorkspace().getRoot()
.getProjects(IWorkspaceRoot.INCLUDE_HIDDEN)[0].getFullPath().toOSString();// TODO how to get right
// project?
final String ret = PATH_TO_ECLIPSE_APPLICATION + PROJECTNAME + PATH_TO_JAVA_CUP_RUNTIME;
return new String[] { ret };
}
}
......@@ -22,6 +22,7 @@ import de.in.tum.www2.cup.CupParser;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.internal.internal_error;
import de.tum.in.www2.cupplugin.PluginUtility;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.editors.CupEditorErrorReporter;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
......@@ -34,14 +35,14 @@ public class DocumentDidChangeJob extends Job {
List<DocumentEvent> documentEvents;
EnumSet<JobsToDo> jobs;
String codeText;
private ParserResult result;
private CupContext context;
private LALRResult lalrResult;
private List<JobStatus> jobStatusList;
private ThreadMXBean tmxb;
private ControllerStatistics controllerStats;
public long revNumber;
public DocumentDidChangeJob(CupTextEditor editor) {
......@@ -60,9 +61,9 @@ public class DocumentDidChangeJob extends Job {
protected IStatus run(IProgressMonitor monitor) {
currentlyRunning = true;
// TODO: this was moved here from the SetupJob.
// I think it's correct and safe here, but this TODO
// should only be removed, once we are sure.
// TODO: this was moved here from the SetupJob.
// I think it's correct and safe here, but this TODO
// should only be removed, once we are sure.
jobStatusList.clear();
SetupJob setup = new SetupJob(editor, revNumber, this);
......@@ -88,7 +89,7 @@ public class DocumentDidChangeJob extends Job {
long tableTimeNano = -1;
boolean hasParserErrors = false;
boolean hasTableErrors = false;
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
CupEditorErrorReporter errorReporter = new CupEditorErrorReporter(file);
errorReporter.resetOnNextPush();
......@@ -103,7 +104,7 @@ public class DocumentDidChangeJob extends Job {
try {
parserDate = new Date();
long before = tmxb.getCurrentThreadCpuTime();
result = parser.parse();
result = parser.parse(PluginUtility.createClasspath());
parseTimeNano = tmxb.getCurrentThreadCpuTime() - before;
} catch (Exception e1) {
e1.printStackTrace();
......@@ -118,8 +119,7 @@ public class DocumentDidChangeJob extends Job {
hasParserErrors = true;
jobStatusList.add(new JobStatus(JobsToDo.parseCode, false));
ParserResultJob resultModelJob = new ParserResultJob(editor,
result, context, revNumber);
ParserResultJob resultModelJob = new ParserResultJob(editor, result, context, revNumber);
resultModelJob.setSystem(true);
resultModelJob.schedule();
try {
......@@ -131,8 +131,7 @@ public class DocumentDidChangeJob extends Job {
} else {
hasParserErrors = true;
if (context != null) {
StatisticsIfFailedJob statisticsJob = new StatisticsIfFailedJob(
editor, context, revNumber);
StatisticsIfFailedJob statisticsJob = new StatisticsIfFailedJob(editor, context, revNumber);
statisticsJob.setSystem(true);
statisticsJob.schedule();
}
......@@ -141,7 +140,7 @@ public class DocumentDidChangeJob extends Job {
}
if (jobs.contains(JobsToDo.buildTable)) {
lalrResult = null;
try {
if (parser != null && !parser.hasParseErrors()) {
......@@ -158,8 +157,7 @@ public class DocumentDidChangeJob extends Job {
if (lalrResult != null) {
jobStatusList.add(new JobStatus(JobsToDo.buildTable, false));
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(
editor, lalrResult, revNumber, context);
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(editor, lalrResult, revNumber, context);
resultLaLrModelJob.setSystem(true);
resultLaLrModelJob.schedule();
try {
......@@ -169,20 +167,19 @@ public class DocumentDidChangeJob extends Job {
}
} else {
hasTableErrors = true;
// TODO: we run the statistics job twice, here, even if we failed
// to build the parser. This should only run once.
// TODO: we run the statistics job twice, here, even if we failed
// to build the parser. This should only run once.
if (context != null) {
StatisticsIfFailedJob statisticsJob = new StatisticsIfFailedJob(
editor, context, revNumber);
StatisticsIfFailedJob statisticsJob = new StatisticsIfFailedJob(editor, context, revNumber);
statisticsJob.setSystem(true);
statisticsJob.schedule();
}
String message = null;
if (hasParserErrors)
message = "The parse tables were not created, because the " +
"grammar could not be parsed correctly.";
message = "The parse tables were not created, because the "
+ "grammar could not be parsed correctly.";
jobStatusList.add(new JobStatus(JobsToDo.buildTable, true, message));
}
}
......
......@@ -18,6 +18,7 @@ import de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor;
import de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor.Mapping;
import de.in.tum.www2.cup.ast.ClassName;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.PluginUtility;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.RevisionManager;
import de.tum.in.www2.cupplugin.model.Model;
......@@ -68,36 +69,33 @@ public class Debugger {
ParserResult astModel = getParserResult();
if (astModel == null) {
/*
* System.err .println(
* "WARNING: did not use breakpoint snapping, because AST was not available."
* ); TODO: REMOVE OUTPUT
* System.err .println( "WARNING: did not use breakpoint snapping, because AST was not available." ); TODO:
* REMOVE OUTPUT
*/
return line;
}
/*
* Eclipse's internal representation starts counting lines with 0, we do start with 1
*/
FindNextCodeBlockLineVisitor v = new FindNextCodeBlockLineVisitor(line+1);
FindNextCodeBlockLineVisitor v = new FindNextCodeBlockLineVisitor(line + 1);
astModel.accept(v, null);
/*
* convert from our to eclipse'S view on line-numbers
*/
return v.getResult()-1;
return v.getResult() - 1;
}
/**
* The java class in which a remote breakpoint will be set. The Java
* debugger needs that information to break correctly. example: Parser
* Parser$NestedSubClass
* The java class in which a remote breakpoint will be set. The Java debugger needs that information to break
* correctly. example: Parser Parser$NestedSubClass
*/
public String getGeneratedTargetClass(CupLineBreakpoint breakpoint) {
ParserResult result = getParserResult();
if (result == null) {
/*
* System.err .println(
* "WARNING: No AST available. Using default class. Debugger may not work."
* );TODO: REMOVE OUTPUT
* System.err .println( "WARNING: No AST available. Using default class. Debugger may not work." );TODO:
* REMOVE OUTPUT
*/
return DEFAULT_CLASS;
}
......@@ -108,9 +106,8 @@ public class Debugger {
if (packageName == null) {
/*
* System.err .println(
* "WARNING: No package specified in cup file. Debugger might not work."
* );TODO: REMOVE OUTPUT
* System.err .println( "WARNING: No package specified in cup file. Debugger might not work." );TODO: REMOVE
* OUTPUT
*/
packageName = "";
} else {
......@@ -159,11 +156,10 @@ public class Debugger {
InputStream in = new ByteArrayInputStream(document.get().getBytes());
CupParser parser = new CupParser(new NoopErrorReporter(), in);
try {
selfBuiltAstCache = parser.parse();
selfBuiltAstCache = parser.parse(PluginUtility.createClasspath());
// TODO: manage revisions properly?
long revision = RevisionManager.increment(document);
Model.getInstanceForDocument(document).setASTModel(
selfBuiltAstCache, parser.getContext(), revision);
Model.getInstanceForDocument(document).setASTModel(selfBuiltAstCache, parser.getContext(), revision);
} catch (Exception e1) {
e1.printStackTrace();
......@@ -175,9 +171,9 @@ public class Debugger {
// hack.
List<ParserResult> lst = new ArrayList<ParserResult>();
Display.getDefault().syncExec(new Runnable() {
public void run() {
lst.add(m.getAstModel());
}
public void run() {
lst.add(m.getAstModel());
}
});
if (lst.size() == 1)
return lst.get(0);
......
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