JavaPatternMatching/src/mycompiler/SyntaxTreeNode.java

60 lines
1.6 KiB
Java
Raw Normal View History

2014-02-11 01:47:39 +00:00
package mycompiler;
import java.util.Vector;
2014-02-19 04:20:54 +00:00
2014-04-15 12:56:20 +00:00
import typinferenz.exceptions.DebugException;
import typinferenz.exceptions.TypeinferenceException;
import mycompiler.myclass.Class;
2014-04-09 12:12:55 +00:00
import mycompiler.mytype.GenericTypeVar;
2014-02-12 01:12:12 +00:00
public abstract class SyntaxTreeNode {
2014-02-19 04:20:54 +00:00
protected SyntaxTreeNode parent;
2014-02-11 01:47:39 +00:00
/**
* Wird nach dem Parsen aufgerufen.
* Erf<EFBFBD>llt folgenden Aufgaben:
* 1. F<EFBFBD>llt fehlende Typangaben mit TPHs auf.
* 2. Verkn<EFBFBD>pft die Knoten des Syntaxbaums. (setzt Parent)
2014-04-09 12:12:55 +00:00
* 3. Wechselt RefTypes gegebenenfalls mit GenericTypeVars aus.
* 4. F<EFBFBD>hrt einen Teil des Syntaxckecks durch.
*
*/
2014-02-12 01:12:12 +00:00
public void parserPostProcessing(SyntaxTreeNode parent) {
this.parent = parent;
for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
}
public SyntaxTreeNode getParent() {
return this.parent;
}
public abstract Vector<SyntaxTreeNode> getChildren();
public Class getParentClass(){
SyntaxTreeNode parent = this.getParent();
if(parent instanceof Class)return (Class)parent;
2014-04-15 12:56:20 +00:00
if(parent == null)throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein");
return parent.getParentClass();
}
/**
* Eine Beschreibung/Name des SyntaxTree-Nodes
* @return
*/
public String getDescription(){
return this.toString();
}
2014-03-14 15:34:25 +00:00
2014-04-09 12:12:55 +00:00
2014-03-14 15:34:25 +00:00
@Override
public boolean equals(Object object){
if(!(object instanceof SyntaxTreeNode))return false;
SyntaxTreeNode equal = (SyntaxTreeNode)object;
if(!equal.getDescription().equals(this.getDescription()))return false;
2014-03-17 16:55:55 +00:00
if(this.getParent()!=null)
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement <20>berpr<70>fen.
2014-03-14 15:34:25 +00:00
return true;
}
2014-02-11 01:47:39 +00:00
}