Commit b08129f9 authored by Benedikt Engeser's avatar Benedikt Engeser

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

parents 9f637260 60de1a6a
......@@ -35,7 +35,6 @@ public class FindAtPositionVisitor extends Visitor<Object>
public void postVisit (Name node, Object data) {
if (node == null)
return;
System.out.println(node);
updateIfMatch(node);
}
......
......@@ -7,6 +7,7 @@ import java.util.List;
import de.in.tum.www2.cup.ast.AbstractNode;
import de.in.tum.www2.cup.ast.IHasDeclarationReference;
import de.in.tum.www2.cup.ast.IHasDefinitionReference;
import de.in.tum.www2.cup.ast.Precedence;
import de.in.tum.www2.cup.ast.Production;
import de.in.tum.www2.cup.ast.ProductionSymbolRef;
import de.in.tum.www2.cup.ast.StartWith;
......@@ -31,7 +32,6 @@ public class RefResolutionVisitor extends Visitor<Object>
// should also resolve:
// 1. declarations
// 2. matching precedences
private void resolveDeclarationFrom(String name, IHasDeclarationReference node) {
if (declarations.containsKey(name)) {
......@@ -54,8 +54,11 @@ public class RefResolutionVisitor extends Visitor<Object>
@Override public Object preVisit (StartWith node, Object data) {
NonTerminal nt = node.getNonTerminal();
if (nt != null)
resolveDefinitionFrom(nt.getName().name, nt);
if (nt != null) {
String name = nt.getName().name;
resolveDefinitionFrom(name, nt);
resolveDeclarationFrom(name, nt);
}
return data;
}
......@@ -67,7 +70,7 @@ public class RefResolutionVisitor extends Visitor<Object>
}
return data;
}
@Override public Object preVisit (TerminalDeclaration node, Object data) {
for(Terminal t : node.getTerminals())
declarations.put(t.getName().name, t);
......@@ -88,16 +91,24 @@ public class RefResolutionVisitor extends Visitor<Object>
declarations.put(t.getName().name, t);
return data;
}
@Override public Object preVisit (Precedence node, Object data) {
for(Terminal t : node.getTerminals())
resolveDeclarationFrom(t.getName().name, t);
return data;
}
@Override public Object preVisit (Production node, Object data) {
String name = node.getName().name;
definitions.put(name, node);
resolveDeclarationFrom(name, node); // handles the LHS
// update any forward references.
if (forwardDefRefs.containsKey(name)) {
for (IHasDefinitionReference d : forwardDefRefs.get(name))
d.setDefinition(node);
}
return data;
}
......
......@@ -7,6 +7,9 @@ import de.in.tum.www2.cup.internal.assoc;
import de.in.tum.www2.cup.Range;
public class Precedence extends AbstractNode {
private Type type;
private List<Terminal> terminals;
public enum Type {
Left,
......@@ -24,9 +27,14 @@ public class Precedence extends AbstractNode {
}
throw new RuntimeException("impossible.");
}
public Type type;
public List<Terminal> terminals;
public Type getType() {
return type;
}
public List<Terminal> getTerminals() {
return terminals;
}
public Precedence(int assoc, List<Terminal> lst, Range range) {
super(range);
......
......@@ -5,8 +5,10 @@ import java.util.List;
import de.in.tum.www2.cup.analysis.AbstractVisitor;
import de.in.tum.www2.cup.Range;
public class Production extends AbstractNode implements IWithName {
public class Production extends AbstractNode
implements IWithName, IHasDeclarationReference
{
private NonTerminal declarationRef;
private Name lhs;
private List<ProductionRight> rhs;
......@@ -14,7 +16,19 @@ public class Production extends AbstractNode implements IWithName {
public Name getName() {
return lhs;
}
@Override
public AbstractNode getDeclaration() {
return declarationRef;
}
@Override
public void setDeclaration(AbstractNode node) {
if (!(node instanceof NonTerminal))
throw new RuntimeException("Declaration must be a NonTerminal");
this.declarationRef = (NonTerminal) node;
}
public Production(Name lhs,
List<ProductionRight> rhs, Range range) {
super(range);
......@@ -57,5 +71,5 @@ public class Production extends AbstractNode implements IWithName {
builder.append("\n");
}
}
}
......@@ -302,10 +302,10 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
@Override
public void postVisit(Precedence node, OutlineEntry data) {
StringBuilder builder = new StringBuilder();
builder.append(node.type.toString().toLowerCase());
if (node.terminals != null) {
builder.append(node.getType().toString().toLowerCase());
if (node.getTerminals() != null) {
builder.append(" ");
builder.append(Utility.shortenedList(node.terminals,
builder.append(Utility.shortenedList(node.getTerminals(),
t -> t.getName().name, this.shortenListsTo));
}
addDeclOrPrec(OutlineEntry.fromNode(builder.toString(), node));
......
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