Commit e3877096 authored by Sebastian Pretscher's avatar Sebastian Pretscher

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

Conflicts:
	CupPlugin/src/de/tum/in/www2/cupplugin/controller/DocumentDidChangeJob.java
	CupPlugin/src/de/tum/in/www2/cupplugin/editors/CupReduceGraphView.java
parents 9d14a84a 7c6692f2
......@@ -18,6 +18,10 @@ public class CupParser
return result;
}
public boolean hasParseErrors() {
return context.getErrorManager().hasParseErrors();
}
public CupContext getContext() {
return context;
}
......
......@@ -100,7 +100,8 @@ public class CupSymbol {
static {
keywords = new int[] {
sym.IMPORT,
sym.IMPORT,
sym.CLASS,
sym.PARSER,
sym.WITH,
sym.SCAN,
......
......@@ -3,7 +3,7 @@ package de.in.tum.www2.cup;
public class DefaultErrorReporter implements IErrorReporter
{
public void report(ErrorType type, ErrorSource source, int errorCode,
public void report(ErrorType type, ErrorSource source, ErrorCode errorCode,
String message, Position start, Position end)
{
StringBuilder m = new StringBuilder();
......
......@@ -14,14 +14,16 @@ import de.in.tum.www2.cup.internal.emit;
class Demo
{
public static void main(String[] blah) throws Exception {
IErrorReporter er = new DefaultErrorReporter();
FileInputStream input = new FileInputStream("/Users/jroith/testcup/test.cup");
IErrorReporter er = new DefaultErrorReporter();
FileInputStream input = new FileInputStream("/Users/jroith/testcup/testspeed.cup");
CupParser parser = new CupParser(er, input);
ParserResult res = parser.parse();
CupContext context = parser.getContext();
System.out.println(res);
// System.out.println(res);
System.out.println("\nLocationPatchVisitor:");
long ms = System.currentTimeMillis();
......@@ -45,10 +47,12 @@ class Demo
System.out.println("QUESTION is a declared terminal! :-)");
System.out.println("\nComputing tables ...");
LALRResult lalrResult = LALRResult.Compute(context, context.start_production);
// System.out.println("\nComputing tables ...");
// LALRResult lalrResult = LALRResult.Compute(context, context.start_production);
// System.out.println(lalrResult.getActionTable());
// System.out.println(lalrResult.getReduceTable());
......
package de.in.tum.www2.cup;
public enum ErrorCode {
SymbolAlreadyDeclared
}
......@@ -9,6 +9,26 @@ public class ErrorManager
private IErrorReporter er;
private int error_count;
public boolean hasScanErrors (){
throw new RuntimeException("TODO: implement!");
}
public boolean hasParseErrors (){
throw new RuntimeException("TODO: implement!");
}
public boolean hasLALRErrors (){
throw new RuntimeException("TODO: implement!");
}
public boolean hasErrors (){
throw new RuntimeException("TODO: implement!");
}
public boolean hasWarnings (){
throw new RuntimeException("TODO: implement!");
}
public int getErrorCount() {
return error_count;
}
......@@ -34,7 +54,7 @@ public class ErrorManager
// }
public void Warning(String msg) {
er.report(ErrorType.Warning, ErrorSource.Unknown, -1, msg, null, null);
er.report(ErrorType.Warning, ErrorSource.Unknown, null, msg, null, null);
}
public void Warning(ErrorSource source, String msg) {
......@@ -46,7 +66,7 @@ public class ErrorManager
}
public void Warning(ErrorSource source, String msg, Position start, Position end) {
er.report(ErrorType.Warning, source, -1, msg, start, end);
er.report(ErrorType.Warning, source, null, msg, start, end);
}
public void Fatal(ErrorSource source, String msg, ComplexSymbol sym) {
......@@ -54,7 +74,7 @@ public class ErrorManager
}
public void Fatal(ErrorSource source, String msg) {
er.report(ErrorType.Fatal, source, -1, msg, null, null);
er.report(ErrorType.Fatal, source, null, msg, null, null);
}
public void Error(ErrorSource source, String msg, ComplexSymbol sym) {
......@@ -82,7 +102,7 @@ public class ErrorManager
}
public void Error(ErrorSource source, String msg, Position start, Position end) {
er.report(ErrorType.Error, source, -1, msg, start, end);
er.report(ErrorType.Error, source, null, msg, start, end);
error_count++;
}
}
......
......@@ -8,12 +8,12 @@ public interface IErrorReporter
*
* @param type
* @param source
* @param errorCode May be -1 if no code is known.
* @param errorCode May be null if no code is known.
* @param message May be null if no message is provided.
* @param start May be null if there is no line information.
* @param end May be null if the error is not localized on the line.
*/
void report(ErrorType type, ErrorSource source, int errorCode,
void report(ErrorType type, ErrorSource source, ErrorCode errorCode,
String message, Position start, Position end);
}
......@@ -62,7 +62,7 @@ public class LALRResult {
System.out.println("*** More conflicts encountered than expected " +
"-- parser generation aborted");
return null;
return result;
}
return result;
......
......@@ -11,7 +11,7 @@ public class MultiErrorReporter implements IErrorReporter
this.reporters = reporters;
}
public void report(ErrorType type, ErrorSource source, int errorCode,
public void report(ErrorType type, ErrorSource source, ErrorCode errorCode,
String message, Position start, Position end)
{
for (IErrorReporter reporter : reporters)
......
......@@ -3,7 +3,7 @@ package de.in.tum.www2.cup;
public class NoopErrorReporter implements IErrorReporter
{
public void report(ErrorType type, ErrorSource source, int errorCode,
public void report(ErrorType type, ErrorSource source, ErrorCode errorCode,
String message, Position start, Position end)
{
}
......
......@@ -37,6 +37,10 @@ public class DeclarationsExtractorVisitor extends Visitor<Object>
}
StringBuilder builder = new StringBuilder();
if (parent.getName() == null)
return;
builder.append (parent.getName().name);
builder.append ("::");
builder.append (parent.getRightHandSides().size());
......@@ -63,7 +67,8 @@ public class DeclarationsExtractorVisitor extends Visitor<Object>
public void postVisit (TerminalDeclaration node, Object data) {
if (node != null && node.getTerminals() != null) {
for (Terminal t : node.getTerminals())
result.getTerminals().add(t.getName().name);
if (t != null)
result.getTerminals().add(t.getNameStringOrNull());
}
}
......@@ -71,7 +76,8 @@ public class DeclarationsExtractorVisitor extends Visitor<Object>
public void postVisit (NonTerminalDeclaration node, Object data) {
if (node != null && node.getNonTerminals() != null) {
for (NonTerminal nt : node.getNonTerminals())
result.getNonTerminals().add(nt.getName().name);
if (nt != null)
result.getNonTerminals().add(nt.getNameStringOrNull());
}
}
......@@ -80,7 +86,8 @@ public class DeclarationsExtractorVisitor extends Visitor<Object>
// TODO: OAOO!
if (node != null && node.getNonTerminals() != null) {
for (NonTerminal nt : node.getNonTerminals())
result.getNonTerminals().add(nt.getName().name);
if (nt != null)
result.getNonTerminals().add(nt.getNameStringOrNull());
}
}
......@@ -89,7 +96,8 @@ public class DeclarationsExtractorVisitor extends Visitor<Object>
// TODO: OAOO!
if (node != null && node.getTerminals() != null) {
for (Terminal nt : node.getTerminals())
result.getNonTerminals().add(nt.getName().name);
if (nt != null)
result.getNonTerminals().add(nt.getNameStringOrNull());
}
}
......
......@@ -2,8 +2,7 @@ package de.in.tum.www2.cup.analysis;
import de.in.tum.www2.cup.ast.*;
public class FindNextCodeBlockLineVisitor extends Visitor<Object>
{
public class FindNextCodeBlockLineVisitor extends Visitor<Object> {
private int line;
private int result;
......@@ -15,28 +14,34 @@ public class FindNextCodeBlockLineVisitor extends Visitor<Object>
this.line = line;
this.result = -1;
}
private void doCheck(AbstractNode node) {
if (node == null || result != -1)
if (node == null) {
return;
int blockLine = node.getBegin().getLine();
if (line >= blockLine && line <= node.getEnd().getLine()) {
}
int blockLine = node.getBegin().getLine();
int blockEndLine = node.getEnd().getLine();
if (line >= blockLine && line <= blockEndLine) {
System.out.println("Block begins: " + blockLine + " Block ends: "
+ blockEndLine);// TODO: DELETE
result = line;
return;
}
if (blockLine > line)
if (blockLine > line
&& ((result != -1 && (result - line) > (blockLine - line)) || result == -1)) {
result = blockLine;
}
}
@Override
public void postVisit (ActionCodeBlock node, Object data) {
public void postVisit(ActionCodeBlock node, Object data) {
doCheck(node);
}
@Override
public void postVisit (SpecialCodeBlock node, Object data) {
public void postVisit(SpecialCodeBlock node, Object data) {
doCheck(node);
}
......
......@@ -31,6 +31,8 @@ public class RefResolutionVisitor extends Visitor<Object>
}
private void resolveDeclarationFrom(String name, IHasDeclarationReference node) {
if (name == null)
return;
if (declarations.containsKey(name)) {
AbstractNode def = declarations.get(name);
node.setDeclaration(def);
......@@ -38,6 +40,8 @@ public class RefResolutionVisitor extends Visitor<Object>
}
private void resolveDefinitionFrom(String name, IHasDefinitionReference node) {
if (name == null)
return;
if (definitions.containsKey(name)) {
AbstractNode def = definitions.get(name);
node.setDefinition(def);
......@@ -50,9 +54,11 @@ public class RefResolutionVisitor extends Visitor<Object>
}
@Override public Object preVisit (StartWith node, Object data) {
if (node == null)
return data;
NonTerminal nt = node.getNonTerminal();
if (nt != null) {
String name = nt.getName().name;
String name = nt.getNameStringOrNull();
resolveDefinitionFrom(name, nt);
resolveDeclarationFrom(name, nt);
}
......@@ -60,8 +66,10 @@ public class RefResolutionVisitor extends Visitor<Object>
}
@Override public Object preVisit (NonTerminalDeclaration node, Object data) {
if (node == null)
return data;
for(NonTerminal nt : node.getNonTerminals()) {
String name = nt.getName().name;
String name = nt.getNameStringOrNull();
declarations.put(name, nt);
resolveDefinitionFrom(name, nt);
}
......@@ -69,14 +77,18 @@ public class RefResolutionVisitor extends Visitor<Object>
}
@Override public Object preVisit (TerminalDeclaration node, Object data) {
if (node == null)
return data;
for(Terminal t : node.getTerminals())
declarations.put(t.getName().name, t);
declarations.put(t.getNameStringOrNull(), t);
return data;
}
@Override public Object preVisit (TypedNonTerminalDeclaration node, Object data) {
if (node == null)
return data;
for(NonTerminal nt : node.getNonTerminals()) {
String name = nt.getName().name;
String name = nt.getNameStringOrNull();
declarations.put(name, nt);
resolveDefinitionFrom(name, nt);
}
......@@ -85,18 +97,20 @@ public class RefResolutionVisitor extends Visitor<Object>
@Override public Object preVisit (TypedTerminalDeclaration node, Object data) {
for(Terminal t : node.getTerminals())
declarations.put(t.getName().name, t);
declarations.put(t.getNameStringOrNull(), t);
return data;
}
@Override public Object preVisit (Precedence node, Object data) {
if (node == null)
return data;
for(Terminal t : node.getTerminals())
resolveDeclarationFrom(t.getName().name, t);
resolveDeclarationFrom(t.getNameStringOrNull(), t);
return data;
}
@Override public Object preVisit (Production node, Object data) {
String name = node.getName().name;
String name = node.getNameStringOrNull();
definitions.put(name, node);
resolveDeclarationFrom(name, node); // handles the LHS
......@@ -110,7 +124,7 @@ public class RefResolutionVisitor extends Visitor<Object>
}
@Override public Object preVisit (ProductionSymbolRef node, Object data) {
String name = node.getName().name;
String name = node.getNameStringOrNull();
resolveDefinitionFrom(name, node);
resolveDeclarationFrom(name, node);
return data;
......
......@@ -4,4 +4,11 @@ public interface IWithName {
Name getName();
default String getNameStringOrNull() {
Name name = getName();
if (name == null)
return null;
return name.name;
}
}
......@@ -12,7 +12,7 @@ public class NonTerminalDeclaration extends SymbolDeclaration {
public List<NonTerminal> getNonTerminals() {
return nonTerminals;
}
public NonTerminalDeclaration(List<NonTerminal> nonTerminals, Range range) {
super(range);
this.nonTerminals = nonTerminals;
......@@ -30,7 +30,8 @@ public class NonTerminalDeclaration extends SymbolDeclaration {
if (visitor.resetDescend()) {
if (nonTerminals != null) {
for (NonTerminal nt : nonTerminals)
nt.accept(visitor, childArg);
if (nt != null)
nt.accept(visitor, childArg);
}
}
visitor.postVisit(this, data);
......
......@@ -74,8 +74,9 @@ public class ParserResult extends AbstractNode {
if (pack != null)
pack.accept(visitor, childArg);
for (Import im : imports)
im.accept(visitor, childArg);
if (imports != null)
for (Import im : imports)
im.accept(visitor, childArg);
if (className != null)
className.accept(visitor, childArg);
......@@ -92,17 +93,20 @@ public class ParserResult extends AbstractNode {
if (scanCode != null)
scanCode.accept(visitor, childArg);
for (SymbolDeclaration s : symbols)
s.accept(visitor, childArg);
if (symbols != null)
for (SymbolDeclaration s : symbols)
s.accept(visitor, childArg);
for (Precedence p : precedences)
p.accept(visitor, childArg);
if (precedences != null)
for (Precedence p : precedences)
p.accept(visitor, childArg);
if (startWith != null)
startWith.accept(visitor, childArg);
for (Production p : productions)
p.accept(visitor, childArg);
if (productions != null)
for (Production p : productions)
p.accept(visitor, childArg);
}
visitor.postVisit(this, data);
......
//----------------------------------------------------
// The following code was generated by CUP v0.11b 20140808 (SVN rev 54)
// The following code was generated by CUP v0.11b 20140902 (SVN rev )
//----------------------------------------------------
package de.in.tum.www2.cup.internal;
......
......@@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CupPlugin
Bundle-SymbolicName: de.tum.in.www2.CupPlugin;singleton:=true
Bundle-Version: 0.0.0.qualifier
Bundle-Activator: cupplugin.Activator
Bundle-Version: 1.0
Bundle-Activator: de.tum.in.www2.cupplugin.Activator
Bundle-Vendor: de.tum.in.www2
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
......@@ -18,6 +18,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.expressions;bundle-version="3.4.600",
org.eclipse.debug.core;bundle-version="3.9.1",
org.eclipse.debug.ui;bundle-version="3.10.1",
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"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
......
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CupPlugin
Bundle-SymbolicName: de.tum.in.www2.CupPlugin;singleton:=true
Bundle-Version: 1.0
Bundle-Activator: de.tum.in.www2.cupplugin.Activator
Bundle-Vendor: de.tum.in.www2
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jface.text,
org.eclipse.core.resources,
org.eclipse.ui.editors,
org.eclipse.ui.ide,
org.eclipse.zest.core;bundle-version="1.5.100",
org.eclipse.zest.layouts;bundle-version="1.1.100",
CupReferencedLibraries;bundle-version="1.0.0",
org.eclipse.ui.views;bundle-version="3.7.0",
org.eclipse.core.expressions;bundle-version="3.4.600",
org.eclipse.debug.core;bundle-version="3.9.1",
org.eclipse.debug.ui;bundle-version="3.10.1",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
......@@ -3,5 +3,6 @@ output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/
icons/,\
templates/
jars.compile.order = .
package cupplugin;
package de.tum.in.www2.cupplugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
......
package de.tum.in.www2.cupplugin;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import de.in.tum.www2.cup.ast.Name;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.model.Model;
public class GeneratedFileLocator {
private IFile currentFile;
private void scanResources(List<IFile> candidates,
String filename, IContainer parent) throws CoreException {
for (IResource res : parent.members()) {
if (res instanceof IContainer) {
// System.out.println("found container: " + res.getName());
scanResources(candidates, filename, (IContainer) res);
} else if (res instanceof IFile) {
IFile file = (IFile) res;
if (res.getName().equals(filename)) {
// The file should have the correct class name.
candidates.add(file);
}
}
}
}
private List<IFile> findCandidates(IFile cupFile, ParserResult result) {
if (result == null)
return null;
List<IFile> candidates = new ArrayList<IFile>();
IProject project = cupFile.getProject();
String className = "Parser";
if (result.className != null) {
Name name = result.className.getName();
if (name != null)
className = name.name;
}
String filename = className + ".java";
try {
scanResources(candidates, filename, project);
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return candidates;
}
public IFile find(IFile cupFile, ParserResult result) {
if (currentFile != null && currentFile.exists()) {
// System.out.println("cached!");
return currentFile;
} else {
currentFile = null;
}
List<IFile> candidates = findCandidates(cupFile, result);
// if (candidates.size() == 0)
// System.out.println("Found no candidates!");
for (IFile candidate : candidates) {
System.out.println("candidate: " + candidate.getName());
if (currentFile != null) {
// TODO: check if better than candidate.
// e.g. if package matches
}
currentFile = candidate;
}
return currentFile;
}
}
......@@ -12,22 +12,26 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.source.ISourceViewer;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.MultiPageEditor;
import de.tum.in.www2.cupplugin.model.Model;
public final class PluginUtility {
public static void showMessage(String message) {
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! <<<<<<<<<<<<<<<");
sourceViewer.invalidateTextPresentation();
}
public static Range getRangeFromSelection (CupTextEditor editor)
{
ITextSelection textSelection = (ITextSelection) editor
......@@ -69,14 +73,38 @@ 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);
}
}*/return null;
}
public static void addFileTuple(IFile cupFile, IFile javaFile){
if(cupFile == null || javaFile == null)
return;
/*
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;
}
/**
* Find the generated file that matches our cup file.
* @param cupFile The original cup file.
* @return Can return null if no matching generated file is found.
*/
public static IFile findGenerated(IFile cupFile) {
if (cupFile == null)
if (cupFile == null){
return null;
}
IContainer container = cupFile.getParent();
String name = cupFile.getName();
......@@ -96,10 +124,14 @@ public final class PluginUtility {
// TODO: maybe search for "The following code was generated by CUP" string
// at the beginning of the file?
addFileTuple(cupFile,(IFile) res);
return (IFile) res;
}
return null;
}
}
\ No newline at end of file