forked from JavaTX/JavaCompilerCore
Bug-fixes; GenericTypeVar kann von mehreren Klassen per extends abhängen.
This commit is contained in:
parent
36fd915248
commit
ce61fdf3c7
@ -34,7 +34,8 @@ public abstract class SyntaxTreeNode {
|
||||
public Class getParentClass(){
|
||||
SyntaxTreeNode parent = this.getParent();
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -500,8 +500,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
}
|
||||
|
||||
@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
|
||||
Type returnType=getType();
|
||||
Type pendantReturnType = null;
|
||||
@ -561,7 +565,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
{
|
||||
Type replaceType = null;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -592,6 +597,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert die MethodAssumption zu dieser Methode
|
||||
*/
|
||||
@Override
|
||||
public TypeAssumptions createTypeAssumptions(Class classmember) {
|
||||
Class parentClass = this.getParentClass();
|
||||
|
@ -468,10 +468,11 @@ public class LocalVarDecl extends Statement implements TypeInsertable
|
||||
if((this.getType() instanceof RefType)){
|
||||
Type replaceType = null;
|
||||
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);
|
||||
}
|
||||
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.
|
||||
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
|
||||
return ret;
|
||||
|
@ -670,7 +670,7 @@ public class MethodCall extends Expr
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
//Berechne die Constraints des Receivers
|
||||
if(receiver == null){
|
||||
receiver = new Receiver(new This(0,0));
|
||||
receiver = new Receiver(new This(this));
|
||||
}
|
||||
ret.add(receiver.get_Expr().TYPEExpr(assumptions));
|
||||
|
||||
|
@ -50,7 +50,6 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
|
||||
// ino.end
|
||||
|
||||
protected Type type;
|
||||
private SyntaxTreeNode parent;
|
||||
|
||||
// ino.method.Statement.26194.definition
|
||||
public Statement(int offset, int variableLength)
|
||||
|
@ -50,6 +50,11 @@ public class This extends Expr
|
||||
}
|
||||
// ino.end
|
||||
|
||||
public This(SyntaxTreeNode parent){
|
||||
this(0,0);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
// ino.attribute.arglist.26268.declaration
|
||||
public ArgumentList arglist;
|
||||
// ino.end
|
||||
|
@ -51,8 +51,10 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
// ino.method.BoundedGenericTypeVar.29409.body
|
||||
{
|
||||
super(s, offset);
|
||||
if(bounds.size()>1)throw new NotImplementedException();
|
||||
this.genericTypeVar = new Pair(new RefType(s,offset),bounds.elementAt(0));
|
||||
if(bounds != null)for(Type t : bounds){
|
||||
if(t!=null)this.extendVars.add(t);
|
||||
}
|
||||
this.genericTypeVar = new RefType(s,offset);
|
||||
this.bounds = bounds;
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,6 +4,7 @@ package mycompiler.mytype;
|
||||
|
||||
// ino.module.GenericTypeVar.8671.import
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
// ino.end
|
||||
|
||||
@ -12,6 +13,7 @@ import java.util.Vector;
|
||||
|
||||
|
||||
|
||||
|
||||
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
|
||||
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
|
||||
import typinferenz.JavaCodeResult;
|
||||
@ -32,8 +34,9 @@ public class GenericTypeVar extends Type
|
||||
// ino.end
|
||||
// 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
|
||||
* Ihre Superklasse ersetzt werden m<EFBFBD>ssen. Siehe "Type Erasure" in Sun Spezifikation.
|
||||
* <br/>Autor: J<EFBFBD>rg B<EFBFBD>uerle
|
||||
@ -49,7 +52,8 @@ public class GenericTypeVar extends Type
|
||||
*/
|
||||
public GenericTypeVar(Pair genericTypeVarExtendsVar, int offset){
|
||||
super(offset);
|
||||
genericTypeVar = genericTypeVarExtendsVar;
|
||||
genericTypeVar = genericTypeVarExtendsVar.TA1;
|
||||
if(genericTypeVarExtendsVar.TA2!=null)this.extendVars.add(genericTypeVarExtendsVar.TA2);
|
||||
this.name = genericTypeVar.toString();
|
||||
}
|
||||
|
||||
@ -144,8 +148,16 @@ public class GenericTypeVar extends Type
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
if(this.genericTypeVar!=null){
|
||||
JavaCodeResult ret = new JavaCodeResult();
|
||||
ret.attach(this.genericTypeVar.TA1.printJavaCode(resultSet));
|
||||
if(this.genericTypeVar.TA2!=null)ret.attach(" extends ").attach(this.genericTypeVar.TA2.printJavaCode(resultSet));
|
||||
ret.attach(this.genericTypeVar.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 new JavaCodeResult(this.name);
|
||||
|
@ -6,15 +6,17 @@ import mycompiler.mystatement.LocalVarDecl;
|
||||
|
||||
public class LocalVarAssumption extends Assumption {
|
||||
private LocalVarDecl localVar;
|
||||
private Type type;
|
||||
|
||||
public LocalVarAssumption(LocalVarDecl localVar){
|
||||
public LocalVarAssumption(LocalVarDecl localVar, Type declaredType){
|
||||
super(localVar);
|
||||
this.localVar = localVar;
|
||||
this.type = declaredType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getAssumedType() {
|
||||
return this.localVar.getType();
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ public class TypeAssumptions {
|
||||
private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>();
|
||||
private Vector<ClassAssumption> classAssumptions = new Vector<ClassAssumption>();
|
||||
|
||||
|
||||
/**
|
||||
* Dieser Konstruktor setzt bei der Initialisierung auch den Wert von "this"
|
||||
* @param klassenname - Wert für "this"
|
||||
|
@ -51,7 +51,43 @@ public class Tester extends TypeInsertTester{
|
||||
|
||||
@Test
|
||||
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>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user