FunN Typen werden zu den entsprechenden UnifyTypen konvertiert
This commit is contained in:
parent
f2410154aa
commit
324864f8d8
@ -124,7 +124,8 @@ public class UnifyTypeFactory {
|
||||
}
|
||||
|
||||
public static UnifyType convert(GenericTypeVar t){
|
||||
return new PlaceholderType(t.get_Name());
|
||||
//return new PlaceholderType(t.get_Name());
|
||||
return new ReferenceType(t.get_Name());
|
||||
}
|
||||
|
||||
public static UnifyConstraintsSet convert(ConstraintsSet constraints) {
|
||||
|
@ -1,15 +1,20 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
|
||||
/**
|
||||
* @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke
|
||||
@ -23,7 +28,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
public class FunN extends RefType {
|
||||
|
||||
private Type R;
|
||||
private Menge<Type> T;
|
||||
private List<? extends Type> T;
|
||||
|
||||
/**
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
@ -33,7 +38,7 @@ public class FunN extends RefType {
|
||||
* @param T
|
||||
* @return
|
||||
*/
|
||||
public FunN(Type R, Menge<Type> T) {
|
||||
public FunN(Type R, List<? extends Type> T) {
|
||||
super("",null,0);
|
||||
if(T==null || R == null)throw new NullPointerException();
|
||||
setT(T);
|
||||
@ -44,11 +49,11 @@ public class FunN extends RefType {
|
||||
/**
|
||||
* Spezieller Konstruktor um eine FunN ohne Returntype zu generieren
|
||||
*/
|
||||
protected FunN(Menge<Type> T){
|
||||
protected FunN(List<? extends Type> list){
|
||||
super("",null,0);
|
||||
if(T==null)throw new NullPointerException();
|
||||
setT(T);
|
||||
this.name = new JavaClassName("Fun"+T.size());//getName();
|
||||
if(list==null)throw new NullPointerException();
|
||||
setT(list);
|
||||
this.name = new JavaClassName("Fun"+list.size());//getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,15 +73,6 @@ public class FunN extends RefType {
|
||||
setT(t);
|
||||
|
||||
this.name = new JavaClassName("Fun"+parameterCount);
|
||||
/*
|
||||
Menge<Type> t = new Menge<Type>();
|
||||
for(int i=0;i<parameterCount;i++){
|
||||
t.add(TypePlaceholder.fresh(this));
|
||||
}
|
||||
R = TypePlaceholder.fresh(this);
|
||||
T = t;
|
||||
this.name = getName();
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,11 +83,16 @@ public class FunN extends RefType {
|
||||
Menge<Type> t = new Menge<Type>();
|
||||
if(R!=null)t.add(R);
|
||||
if(T!=null)t.addAll(T);
|
||||
for(Type type : t){
|
||||
if(type instanceof WildcardType){
|
||||
throw new DebugException("Der FunN-Typ darf keine Wildcards in den Parameter enthalten");
|
||||
}
|
||||
}
|
||||
this.set_ParaList(t);
|
||||
}
|
||||
|
||||
protected void setT(Menge<Type> T){
|
||||
this.T = T;
|
||||
protected void setT(List<? extends Type> list){
|
||||
this.T = list;
|
||||
calculateNewParalist();
|
||||
}
|
||||
protected void setR(Type R){
|
||||
@ -137,6 +138,16 @@ public class FunN extends RefType {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
|
||||
//FunN Typen müssen nicht geprüft werden. Sie werden schließlich nur von unserem Typinferenzalgorithmus erstellt:
|
||||
List<Type> paraList = new ArrayList<>();
|
||||
for(Type t : this.T){
|
||||
paraList.add(t.TYPE(ass, parent));
|
||||
}
|
||||
FunN ret = new FunN(this.R.TYPE(ass, parent),paraList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
public CMethodTypeAssumption toCMethodTypeAssumption() {
|
||||
|
@ -2,9 +2,12 @@ package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
@ -79,4 +82,14 @@ public class FunNInterface extends Class{
|
||||
//return new FunNMethod(this.get_ParaList().size()-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefType getType() {
|
||||
List<? extends Type> paraList = this.get_ParaList();
|
||||
Type R = paraList.get(0);
|
||||
paraList.remove(0);
|
||||
return new FunN(R, paraList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -257,18 +257,6 @@ public class TypeAssumptions {
|
||||
* @return null, falls der Typ nicht vorhanden ist.
|
||||
*/
|
||||
public Type getTypeFor(Type t, SyntaxTreeNode inNode){
|
||||
/*
|
||||
if(t instanceof WildcardType){
|
||||
WildcardType wt = (WildcardType)t;
|
||||
Type innerType = wt.GetWildcardType();
|
||||
innerType = getTypeFor(innerType, t).getType();
|
||||
wt.SetWildcardType(innerType);
|
||||
return new ConstraintType(wt);
|
||||
}
|
||||
|
||||
if(t instanceof TypePlaceholder)
|
||||
return new ConstraintType((TypePlaceholder)t); //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen.
|
||||
*/
|
||||
//Alle bekannten Klassen nach diesem Typ durchsuchen:
|
||||
JavaClassName typName = t.getName();
|
||||
for(ClassAssumption ass : this.classAssumptions){
|
||||
|
@ -69,11 +69,12 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}finally{
|
||||
writeLog(sourceFileToInfere+".log");
|
||||
}
|
||||
for(String containString : mustContain){
|
||||
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
|
||||
}
|
||||
writeLog(sourceFileToInfere+".log");
|
||||
}
|
||||
|
||||
public static void testSingleInsert(String sourceFileToInfere, Menge<String> mustContain){
|
||||
|
Loading…
Reference in New Issue
Block a user