2014-02-11 02:47:39 +01:00
|
|
|
|
package mycompiler;
|
|
|
|
|
|
2014-02-11 16:30:38 +01:00
|
|
|
|
import java.util.Vector;
|
2014-02-19 05:20:54 +01:00
|
|
|
|
|
2014-04-26 19:33:26 +02:00
|
|
|
|
import typinferenz.ResultSet;
|
|
|
|
|
import typinferenz.TypeInsertPoint;
|
2014-05-07 09:36:31 +02:00
|
|
|
|
import typinferenz.TypeInsertSet;
|
2014-05-07 08:10:55 +02:00
|
|
|
|
import typinferenz.TypeInsertable;
|
2014-04-15 14:56:20 +02:00
|
|
|
|
import typinferenz.exceptions.DebugException;
|
|
|
|
|
import typinferenz.exceptions.TypeinferenceException;
|
2014-02-14 17:31:55 +01:00
|
|
|
|
import mycompiler.myclass.Class;
|
2014-04-09 14:12:55 +02:00
|
|
|
|
import mycompiler.mytype.GenericTypeVar;
|
2014-05-07 08:10:55 +02:00
|
|
|
|
import mycompiler.mytype.Type;
|
|
|
|
|
import mycompiler.mytype.TypePlaceholder;
|
2014-02-11 16:30:38 +01:00
|
|
|
|
|
2014-02-12 02:12:12 +01:00
|
|
|
|
public abstract class SyntaxTreeNode {
|
|
|
|
|
|
2014-02-19 05:20:54 +01:00
|
|
|
|
protected SyntaxTreeNode parent;
|
2014-02-11 02:47:39 +01:00
|
|
|
|
|
2014-02-11 16:30:38 +01: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 14:12:55 +02:00
|
|
|
|
* 3. Wechselt RefTypes gegebenenfalls mit GenericTypeVars aus.
|
|
|
|
|
* 4. F<EFBFBD>hrt einen Teil des Syntaxckecks durch.
|
2014-02-11 16:30:38 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2014-02-12 02:12:12 +01:00
|
|
|
|
public void parserPostProcessing(SyntaxTreeNode parent) {
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SyntaxTreeNode getParent() {
|
|
|
|
|
return this.parent;
|
|
|
|
|
}
|
2014-02-11 16:30:38 +01:00
|
|
|
|
|
2014-02-19 23:04:48 +01:00
|
|
|
|
public abstract Vector<SyntaxTreeNode> getChildren();
|
2014-02-14 17:31:55 +01:00
|
|
|
|
|
|
|
|
|
public Class getParentClass(){
|
|
|
|
|
SyntaxTreeNode parent = this.getParent();
|
|
|
|
|
if(parent instanceof Class)return (Class)parent;
|
2014-04-24 01:53:35 +02:00
|
|
|
|
if(parent == null)
|
|
|
|
|
throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein");
|
2014-02-14 17:31:55 +01:00
|
|
|
|
return parent.getParentClass();
|
|
|
|
|
}
|
2014-03-12 15:27:26 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Eine Beschreibung/Name des SyntaxTree-Nodes
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String getDescription(){
|
|
|
|
|
return this.toString();
|
|
|
|
|
}
|
2014-03-14 16:34:25 +01:00
|
|
|
|
|
2014-04-09 14:12:55 +02:00
|
|
|
|
|
2014-03-14 16:34:25 +01: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 17:55:55 +01:00
|
|
|
|
if(this.getParent()!=null)
|
|
|
|
|
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement <20>berpr<70>fen.
|
2014-03-14 16:34:25 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-04-26 19:33:26 +02:00
|
|
|
|
|
2014-05-07 09:36:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Methode zur Generierung der TypeInsertPoints
|
|
|
|
|
* @param insertSet - Generierte InsertPoints werden dem insertSet angef<EFBFBD>gt
|
|
|
|
|
* @param result - Das ResultSet auf dessen Basis die InsertPoints generiert werden
|
|
|
|
|
*/
|
|
|
|
|
public void addTypeInsertPoints(TypeInsertSet insertSet,ResultSet result) {
|
2014-05-07 08:10:55 +02:00
|
|
|
|
Vector<TypeInsertPoint> ret = new Vector<TypeInsertPoint>();
|
|
|
|
|
//Fall der Knoten ein TypeInsertable ist, kann direkt der TypeInsertPoint generiert werden.
|
|
|
|
|
if(this instanceof TypeInsertable){
|
|
|
|
|
TypeInsertable that = (TypeInsertable)this;
|
|
|
|
|
Type t = that.getType();
|
|
|
|
|
if(t instanceof TypePlaceholder)
|
|
|
|
|
ret.add(that.createTypeInsertPoint((TypePlaceholder) t, result));//ret.addAll(((TypePlaceholder)t).getTypeInsertPoints(result));
|
2014-05-07 09:36:31 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
insertSet.add(ret);
|
|
|
|
|
|
|
|
|
|
//Nachdem die InsertPoints und GenericVarTypeInsertPoints angef<65>gt wurden, kann im Knoten abgestiegen werden:
|
|
|
|
|
for(SyntaxTreeNode node : this.getChildren()){
|
|
|
|
|
node.addTypeInsertPoints(insertSet, result);
|
2014-05-07 08:10:55 +02:00
|
|
|
|
}
|
2014-04-26 19:33:26 +02:00
|
|
|
|
}
|
2014-02-11 02:47:39 +01:00
|
|
|
|
}
|