Bug-fixes; GenericTypeVar kann von mehreren Klassen per extends abhängen.

This commit is contained in:
JanUlrich 2014-04-24 01:53:35 +02:00
parent 36fd915248
commit ce61fdf3c7
11 changed files with 83 additions and 18 deletions

View File

@ -34,7 +34,8 @@ public abstract class SyntaxTreeNode {
public Class getParentClass(){ public Class getParentClass(){
SyntaxTreeNode parent = this.getParent(); SyntaxTreeNode parent = this.getParent();
if(parent instanceof Class)return (Class)parent; if(parent instanceof Class)return (Class)parent;
if(parent == null)throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein"); if(parent == null)
throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein");
return parent.getParentClass(); return parent.getParentClass();
} }

View File

@ -500,8 +500,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
} }
@Override @Override
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist) public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> classParalist)
{ {
Vector<Type> paralist = new Vector<Type>();//Mit den Generischen Typen der Methode
paralist.addAll(classParalist);
paralist.addAll(this.genericMethodParameters);
// Zuerst Returntype untersuchen // Zuerst Returntype untersuchen
Type returnType=getType(); Type returnType=getType();
Type pendantReturnType = null; Type pendantReturnType = null;
@ -561,7 +565,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{ {
Type replaceType = null; Type replaceType = null;
replaceType = ass.getTypeFor((RefType)param.getType()); replaceType = ass.getTypeFor((RefType)param.getType());
if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",param); if(replaceType == null)
throw new TypeinferenceException("Der Typ "+param.getType().getName()+" ist nicht korrekt",param);
param.setType(replaceType); param.setType(replaceType);
} }
@ -592,6 +597,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
return ret; return ret;
} }
/**
* Liefert die MethodAssumption zu dieser Methode
*/
@Override @Override
public TypeAssumptions createTypeAssumptions(Class classmember) { public TypeAssumptions createTypeAssumptions(Class classmember) {
Class parentClass = this.getParentClass(); Class parentClass = this.getParentClass();

View File

@ -468,10 +468,11 @@ public class LocalVarDecl extends Statement implements TypeInsertable
if((this.getType() instanceof RefType)){ if((this.getType() instanceof RefType)){
Type replaceType = null; Type replaceType = null;
replaceType = assumptions.getTypeFor((RefType)this.getType()); replaceType = assumptions.getTypeFor((RefType)this.getType());
if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); if(replaceType == null)
throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
this.setType(replaceType); this.setType(replaceType);
} }
assumptions.addAssumption(new LocalVarAssumption(this)); assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden. //assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
return ret; return ret;

View File

@ -670,7 +670,7 @@ public class MethodCall extends Expr
this.setType(TypePlaceholder.fresh(this)); this.setType(TypePlaceholder.fresh(this));
//Berechne die Constraints des Receivers //Berechne die Constraints des Receivers
if(receiver == null){ if(receiver == null){
receiver = new Receiver(new This(0,0)); receiver = new Receiver(new This(this));
} }
ret.add(receiver.get_Expr().TYPEExpr(assumptions)); ret.add(receiver.get_Expr().TYPEExpr(assumptions));

View File

@ -50,7 +50,6 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
// ino.end // ino.end
protected Type type; protected Type type;
private SyntaxTreeNode parent;
// ino.method.Statement.26194.definition // ino.method.Statement.26194.definition
public Statement(int offset, int variableLength) public Statement(int offset, int variableLength)

View File

@ -50,6 +50,11 @@ public class This extends Expr
} }
// ino.end // ino.end
public This(SyntaxTreeNode parent){
this(0,0);
this.parent = parent;
}
// ino.attribute.arglist.26268.declaration // ino.attribute.arglist.26268.declaration
public ArgumentList arglist; public ArgumentList arglist;
// ino.end // ino.end

View File

@ -51,8 +51,10 @@ public class BoundedGenericTypeVar extends GenericTypeVar
// ino.method.BoundedGenericTypeVar.29409.body // ino.method.BoundedGenericTypeVar.29409.body
{ {
super(s, offset); super(s, offset);
if(bounds.size()>1)throw new NotImplementedException(); if(bounds != null)for(Type t : bounds){
this.genericTypeVar = new Pair(new RefType(s,offset),bounds.elementAt(0)); if(t!=null)this.extendVars.add(t);
}
this.genericTypeVar = new RefType(s,offset);
this.bounds = bounds; this.bounds = bounds;
} }
// ino.end // ino.end

View File

@ -4,6 +4,7 @@ package mycompiler.mytype;
// ino.module.GenericTypeVar.8671.import // ino.module.GenericTypeVar.8671.import
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
// ino.end // ino.end
@ -12,6 +13,7 @@ import java.util.Vector;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
@ -32,7 +34,8 @@ public class GenericTypeVar extends Type
// ino.end // ino.end
// ino.class.GenericTypeVar.26505.body // ino.class.GenericTypeVar.26505.body
{ {
Pair genericTypeVar; Type genericTypeVar;
Vector<Type> extendVars = new Vector<Type>();
/** /**
* Eine Registry f<EFBFBD>r alle Generic-Instanzen, die vor der Bytecode-Generierung durch * Eine Registry f<EFBFBD>r alle Generic-Instanzen, die vor der Bytecode-Generierung durch
* Ihre Superklasse ersetzt werden m<EFBFBD>ssen. Siehe "Type Erasure" in Sun Spezifikation. * Ihre Superklasse ersetzt werden m<EFBFBD>ssen. Siehe "Type Erasure" in Sun Spezifikation.
@ -49,7 +52,8 @@ public class GenericTypeVar extends Type
*/ */
public GenericTypeVar(Pair genericTypeVarExtendsVar, int offset){ public GenericTypeVar(Pair genericTypeVarExtendsVar, int offset){
super(offset); super(offset);
genericTypeVar = genericTypeVarExtendsVar; genericTypeVar = genericTypeVarExtendsVar.TA1;
if(genericTypeVarExtendsVar.TA2!=null)this.extendVars.add(genericTypeVarExtendsVar.TA2);
this.name = genericTypeVar.toString(); this.name = genericTypeVar.toString();
} }
@ -144,8 +148,16 @@ public class GenericTypeVar extends Type
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
if(this.genericTypeVar!=null){ if(this.genericTypeVar!=null){
JavaCodeResult ret = new JavaCodeResult(); JavaCodeResult ret = new JavaCodeResult();
ret.attach(this.genericTypeVar.TA1.printJavaCode(resultSet)); ret.attach(this.genericTypeVar.printJavaCode(resultSet));
if(this.genericTypeVar.TA2!=null)ret.attach(" extends ").attach(this.genericTypeVar.TA2.printJavaCode(resultSet)); if(this.extendVars.size()>0){
ret.attach(" extends ");
Iterator<Type> it = this.extendVars.iterator();
while(it.hasNext()){
Type extend = it.next();
ret.attach(extend.printJavaCode(resultSet));
if(it.hasNext())ret.attach(", ");
}
}
return ret; return ret;
} }
return new JavaCodeResult(this.name); return new JavaCodeResult(this.name);

View File

@ -6,15 +6,17 @@ import mycompiler.mystatement.LocalVarDecl;
public class LocalVarAssumption extends Assumption { public class LocalVarAssumption extends Assumption {
private LocalVarDecl localVar; private LocalVarDecl localVar;
private Type type;
public LocalVarAssumption(LocalVarDecl localVar){ public LocalVarAssumption(LocalVarDecl localVar, Type declaredType){
super(localVar); super(localVar);
this.localVar = localVar; this.localVar = localVar;
this.type = declaredType;
} }
@Override @Override
public Type getAssumedType() { public Type getAssumedType() {
return this.localVar.getType(); return this.type;
} }
} }

View File

@ -54,7 +54,6 @@ public class TypeAssumptions {
private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>(); private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>();
private Vector<ClassAssumption> classAssumptions = new Vector<ClassAssumption>(); private Vector<ClassAssumption> classAssumptions = new Vector<ClassAssumption>();
/** /**
* Dieser Konstruktor setzt bei der Initialisierung auch den Wert von "this" * Dieser Konstruktor setzt bei der Initialisierung auch den Wert von "this"
* @param klassenname - Wert für "this" * @param klassenname - Wert für "this"

View File

@ -51,7 +51,43 @@ public class Tester extends TypeInsertTester{
@Test @Test
public void runTests(){ public void runTests(){
Tester.test("OL.jav", new Vector<String>()); Vector<String> testFiles = new Vector<String>();
testFiles.add("AchimTest1.jav");
//testFiles.add("BoundedType1.jav");
testFiles.add("BoundedType2.jav");
testFiles.add("BoundedType.jav");
testFiles.add("OL2.jav");
testFiles.add("OL.jav");
testFiles.add("Probleme");
testFiles.add("Simple.jav");
testFiles.add("SMatrix.jav");
testFiles.add("Tester.java");
testFiles.add("UnifyTest1.jav");
testFiles.add("UsecaseEight_pl.jav");
testFiles.add("UsecaseFive_pl.jav");
testFiles.add("UsecaseFour_pl.jav");
testFiles.add("Usecase_MUBTest1.jav");
testFiles.add("Usecase_MUBTest2.jav");
testFiles.add("Usecase_MUBTest3.jav");
testFiles.add("Usecase_MUBTest4.jav");
testFiles.add("Usecase_MUBTest5.jav");
testFiles.add("Usecase_MUBTest6.jav");
testFiles.add("Usecase_MUBTest.jav");
testFiles.add("UsecaseNine_pl.jav");
testFiles.add("UsecaseOne_pl.jav");
testFiles.add("UsecaseSeven_pl.jav");
testFiles.add("UsecaseSix_pl.jav");
testFiles.add("UsecaseTen_pl.jav");
testFiles.add("UsecaseThree_pl.jav");
testFiles.add("UsecaseThree_pl.orig.jav");
testFiles.add("UsecaseTwo_pl.jav");
testFiles.add("ZweiKlassen.jav");
//*/
for(String file : testFiles){
System.out.println("Testfile: "+file);
Tester.test(file, new Vector<String>());
}
} }
} }