Commit 9821195e authored by Konrad Pröll's avatar Konrad Pröll
Browse files

Added routine to remove empty nodes from tree for Javavariables

parent 7fc6b164
......@@ -6,6 +6,10 @@ import java.util.List;
import java_cup.runtime.ComplexSymbolFactory.Location;
public class JavaDeclarationsTreeElement {
public void setParent(JavaDeclarationsTreeElement parent) {
this.parent = parent;
}
List<Pair> variables;
Location end;
List<JavaDeclarationsTreeElement> children;
......@@ -16,10 +20,20 @@ public class JavaDeclarationsTreeElement {
this.parent = parent;
}
public List<JavaDeclarationsTreeElement> getChildren() {
return children;
}
public int childrenLength(){return children.size();}
public JavaDeclarationsTreeElement getParent() {
return parent;
}
public List<Pair> getVariables() {
return variables;
}
public void addDeclaration(String name, Location start) {
if (variables == null) {
variables = new LinkedList<>();
......
......@@ -83,7 +83,7 @@ public abstract class CodeBlock extends AbstractNode {
});
registerPreVisit("Block", (arg0, arg1) -> {
// neues Element hinzufgen und absteigen
// neues Element hinzufügen und absteigen
Location l = arg1.get(arg1.size() - 1).right();
JavaDeclarationsTreeElement t = new JavaDeclarationsTreeElement(l, tree);
tree.addChild(t);
......@@ -91,6 +91,37 @@ public abstract class CodeBlock extends AbstractNode {
});
registerPostVisit("Block", (arg0, arg1) -> {
if (tree.getVariables()==null)
{
JavaDeclarationsTreeElement parent= tree.getParent();
int x = parent.childrenLength();
if(!(tree.getChildren()==null))
{
for (int i=0; i<tree.childrenLength(); i++)
{
parent.addChild(tree.getChildren().get(i));
tree.getChildren().get(i).setParent(parent);
for (int j=0; j<x; j++)
{
if (parent.getChildren().get(j).equals(tree))
{
parent.getChildren().remove(j);
}
}
}
}
for (int i=0; i<x; i++)
{
List<JavaDeclarationsTreeElement> parentChildren=parent.getChildren();
if (parentChildren.get(i).equals(tree))
{
parentChildren.remove(i);
}
}
}
// TODO fix empty trees
// baum zurücksetzen und null-Bäume löschen
// wenn selber null und Kinder null/keine Kinder
......@@ -99,7 +130,7 @@ public abstract class CodeBlock extends AbstractNode {
// Im Children von Parents eigene Kinder eintragen und umgedreht
// aus Children von Parent löschen
// (Wenn selber nicht null -> nix tun)
tree = tree.getParent();
});
}
......
Supports Markdown
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