modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java

Auswahl des Tphs bei der Abfrage, ob ein größerer oder kleinerer Typ des vorherigen bestimmt wurde
korrigiert
	modified:   ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../../../main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
innerType eingeführt
	modified:   ../../bytecode/javFiles/MatrixOP.jav
	deleted:    ../Field.java
	deleted:    ../Import.java
	deleted:    ../Lam1.java
	deleted:    ../LamRun.java
	deleted:    ../MethFieldVar.java
	deleted:    ../Subclass.java
	deleted:    ../SuperTest.java
	deleted:    ../Superclass.java
	deleted:    ../TestMyTest.java
	deleted:    ../testF.java
	deleted:    ../testTets.java
	deleted:    ../testTetsF.java
This commit is contained in:
Martin Plümicke 2019-01-12 18:19:16 +01:00
parent 58d757398d
commit 6de1c50542
16 changed files with 88 additions and 154 deletions

View File

@ -64,26 +64,26 @@ public class UnifyTypeFactory {
* Convert from * Convert from
* ASTType -> UnifyType * ASTType -> UnifyType
*/ */
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t){ public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){
if(t instanceof GenericRefType){ if(t instanceof GenericRefType){
return UnifyTypeFactory.convert((GenericRefType)t); return UnifyTypeFactory.convert((GenericRefType)t, innerType);
}else }else
if(t instanceof FunN){ if(t instanceof FunN){
return UnifyTypeFactory.convert((FunN)t); return UnifyTypeFactory.convert((FunN)t, innerType);
}else if(t instanceof TypePlaceholder){ }else if(t instanceof TypePlaceholder){
return UnifyTypeFactory.convert((TypePlaceholder)t); return UnifyTypeFactory.convert((TypePlaceholder)t, innerType);
}else if(t instanceof ExtendsWildcardType){ }else if(t instanceof ExtendsWildcardType){
return UnifyTypeFactory.convert((ExtendsWildcardType)t); return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType);
}else if(t instanceof SuperWildcardType){ }else if(t instanceof SuperWildcardType){
return UnifyTypeFactory.convert((SuperWildcardType)t); return UnifyTypeFactory.convert((SuperWildcardType)t, innerType);
}else if(t instanceof RefType){ }else if(t instanceof RefType){
return UnifyTypeFactory.convert((RefType)t); return UnifyTypeFactory.convert((RefType)t, innerType);
} }
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist //Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden"); throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
} }
public static UnifyType convert(RefType t){ public static UnifyType convert(RefType t, Boolean innerType){
//Check if it is a FunN Type: //Check if it is a FunN Type:
Pattern p = Pattern.compile("Fun(\\d+)"); Pattern p = Pattern.compile("Fun(\\d+)");
Matcher m = p.matcher(t.getName().toString()); Matcher m = p.matcher(t.getName().toString());
@ -91,14 +91,14 @@ public class UnifyTypeFactory {
if(b){ if(b){
Integer N = Integer.valueOf(m.group(1)); Integer N = Integer.valueOf(m.group(1));
if((N + 1) == t.getParaList().size()){ if((N + 1) == t.getParaList().size()){
return convert(new FunN(t.getParaList())); return convert(new FunN(t.getParaList()), false);
} }
} }
UnifyType ret; UnifyType ret;
if(t.getParaList() != null && t.getParaList().size() > 0){ if(t.getParaList() != null && t.getParaList().size() > 0){
List<UnifyType> params = new ArrayList<>(); List<UnifyType> params = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
params.add(UnifyTypeFactory.convert(pT)); params.add(UnifyTypeFactory.convert(pT, true));
} }
ret = new ReferenceType(t.getName().toString(),new TypeParams(params)); ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
}else{ }else{
@ -107,27 +107,38 @@ public class UnifyTypeFactory {
return ret; return ret;
} }
public static UnifyType convert(FunN t){ public static UnifyType convert(FunN t, Boolean innerType){
UnifyType ret; UnifyType ret;
List<UnifyType> params = new ArrayList<>(); List<UnifyType> params = new ArrayList<>();
if(t.getParaList() != null && t.getParaList().size() > 0){ if(t.getParaList() != null && t.getParaList().size() > 0){
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
params.add(UnifyTypeFactory.convert(pT)); params.add(UnifyTypeFactory.convert(pT, false));
} }
} }
ret = FunNType.getFunNType(new TypeParams(params)); ret = FunNType.getFunNType(new TypeParams(params));
return ret; return ret;
} }
public static UnifyType convert(TypePlaceholder tph){ public static UnifyType convert(TypePlaceholder tph, Boolean innerType){
if (tph.getName().equals("AFQ")) {
System.out.println("");
}
PlaceholderType ntph = new PlaceholderType(tph.getName()); PlaceholderType ntph = new PlaceholderType(tph.getName());
int in = PLACEHOLDERS.indexOf(ntph); int in = PLACEHOLDERS.indexOf(ntph);
if (in == -1) { if (in == -1) {
PLACEHOLDERS.add(ntph); PLACEHOLDERS.add(ntph);
ntph.setInnerType(innerType);
return ntph; return ntph;
} }
else { else {
return PLACEHOLDERS.get(in); PlaceholderType oldpht = PLACEHOLDERS.get(in);
if (oldpht.isWildcardable()) {
return oldpht;
}
else {
oldpht.setInnerType(innerType);
return oldpht;
}
} }
} }
@ -137,9 +148,9 @@ public class UnifyTypeFactory {
public static UnifyType convert(WildcardType t){ public static UnifyType convert(WildcardType t){
if(t.isExtends()) if(t.isExtends())
return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType())); return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType(), false));
else if(t.isSuper()) else if(t.isSuper())
return new SuperType(UnifyTypeFactory.convert(t.getInnerType())); return new SuperType(UnifyTypeFactory.convert(t.getInnerType(), false));
else throw new NotImplementedException(); else throw new NotImplementedException();
} }
@ -153,22 +164,42 @@ public class UnifyTypeFactory {
} }
public static UnifyPair convert(Pair p) { public static UnifyPair convert(Pair p) {
UnifyPair ret = null;
if(p.GetOperator().equals(PairOperator.SMALLERDOT)) { if(p.GetOperator().equals(PairOperator.SMALLERDOT)) {
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1) ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1, false)
, UnifyTypeFactory.convert(p.TA2)); , UnifyTypeFactory.convert(p.TA2, false));
return ret; //return ret;
}else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) { }else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) {
UnifyPair ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1) ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1, false)
, UnifyTypeFactory.convert(p.TA2)); , UnifyTypeFactory.convert(p.TA2, false));
return ret; //return ret;
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) { }else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) {
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1) ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1, false)
, UnifyTypeFactory.convert(p.TA2)); , UnifyTypeFactory.convert(p.TA2, false));
return ret; //return ret;
}else if(p.GetOperator().equals(PairOperator.SMALLER)){ }else if(p.GetOperator().equals(PairOperator.SMALLER)){
return generateSmallerPair(UnifyTypeFactory.convert(p.TA1), ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1, false),
UnifyTypeFactory.convert(p.TA2)); UnifyTypeFactory.convert(p.TA2, false));
}else throw new NotImplementedException(); }else throw new NotImplementedException();
UnifyType lhs, rhs;
if (((lhs = ret.getLhsType()) instanceof PlaceholderType)
&& ((PlaceholderType)lhs).isWildcardable()
&& (rhs = ret.getLhsType()) instanceof PlaceholderType) {
if (lhs.getName().equals("AQ")) {
System.out.println("");
}
((PlaceholderType)rhs).enableWildcardtable();
}
if (((rhs = ret.getLhsType()) instanceof PlaceholderType)
&& ((PlaceholderType)rhs).isWildcardable()
&& (lhs = ret.getLhsType()) instanceof PlaceholderType) {
if (rhs.getName().equals("AQ")) {
System.out.println("");
}
((PlaceholderType)lhs).enableWildcardtable();
}
return ret;
} }
/** /**

View File

@ -816,17 +816,25 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar //PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar
System.out.println(""); System.out.println("");
List<PlaceholderType> vars_a = List<PlaceholderType> vars_a =
a.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) a.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))) && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType))
|| ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))
&& (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType)))
)
.map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new));
Set<UnifyPair> fstElemRes = res.iterator().next(); Set<UnifyPair> fstElemRes = res.iterator().next();
Set<UnifyPair> compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new)); Set<UnifyPair> compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last //Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
System.out.println(a_last);
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});
List<PlaceholderType> varsLast_a = List<PlaceholderType> varsLast_a =
a_last.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))) && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType))
|| ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())))
&& (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType)))
.map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new));
//[(java.util.Vector<java.lang.Integer> <. gen_aq, , 1), (CEK =. ? extends gen_aq, 1)] KANN VORKOMMEN
//erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen //erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen
Set<UnifyPair> fstElemResult = result.iterator().next(); Set<UnifyPair> fstElemResult = result.iterator().next();
Set<UnifyPair> compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));; Set<UnifyPair> compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));;

View File

@ -46,6 +46,11 @@ public final class PlaceholderType extends UnifyType{
*/ */
private boolean wildcardable = true; private boolean wildcardable = true;
/**
* is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird
*/
private boolean innerType = true;
/** /**
* variance shows the variance of the pair * variance shows the variance of the pair
* -1: contravariant * -1: contravariant
@ -124,6 +129,18 @@ public final class PlaceholderType extends UnifyType{
wildcardable = false; wildcardable = false;
} }
public void enableWildcardtable() {
wildcardable = true;
}
public void setWildcardtable(Boolean wildcardable) {
this.wildcardable = wildcardable;
}
public void setInnerType(Boolean innerType) {
this.innerType = innerType;
}
@Override @Override
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) { Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
return fc.smArg(this, fBounded); return fc.smArg(this, fBounded);

View File

@ -1,6 +1,6 @@
import java.util.Vector; import java.util.Vector;
import java.lang.Integer; import java.lang.Integer;
import java.lang.Byte; //import java.lang.Byte;
import java.lang.Boolean; import java.lang.Boolean;
public class MatrixOP extends Vector<Vector<Integer>> { public class MatrixOP extends Vector<Vector<Integer>> {

View File

@ -1,6 +0,0 @@
public class Field{
public void m(){
MethFieldVar mF = new MethFieldVar();
mF.s1 = "Field S1";
}
}

View File

@ -1,8 +0,0 @@
import java.util.Vector;
class Import {
void methode(){
Vector v = new Vector();
v.add(v);
}
}

View File

@ -1,10 +0,0 @@
import java.util.function.Function;
public class Lam1{
public Lam1() {
Function<String,String> fun = (x) -> x+"1";
fun.apply("2");
Runnable lam = () -> System.out.println("lambda");
lam.run();
}
}

View File

@ -1,8 +0,0 @@
public class LamRun{
public void mRun(){
Runnable lam = () -> System.out.println("lambda");
lam.run();
}
}

View File

@ -1,38 +0,0 @@
public class MethFieldVar{
String s1;// = "";
String s2;
/* public void meth(Integer i, String j, Boolean b){
//String local = "a";
//int localL = local.length();
//int l = s.length();
String s = null;
//s = "";
//return s.length();//l+localL;
}
*/
public void mm(){
// return "mm";
}
public void m2(){
System.out.println("");
// Math.abs(1);
// String lV = "local";
// s1 = "1";
// s1.concat("2");
s2 = s1;
mm();
Clazz i = new Clazz();
Runnable lam = ()->{
String test = "";
String b = "b";
test = b;
System.out.println(test);
};
}
}
class Clazz{}

View File

@ -1,6 +0,0 @@
public class Subclass extends Superclass {
public void printMethod() {
super.printMethod();
}
}

View File

@ -1,14 +0,0 @@
public class Superclass {
public void printMethod() {
System.out.println("Printed in Superclass.");
}
}
public class Subclass extends Superclass {
public void printMethod() {
super.printMethod();
}
}

View File

@ -1,6 +0,0 @@
public class Superclass {
public void printMethod() {
System.out.println("Printed in Superclass.");
}
}

View File

@ -1,11 +0,0 @@
class TestMyTest{
public static void main(String[] a){
//test1
//new TestClass();
//test if statement
//new TestIf(new Boolean(true));
// test lambda
//new TestClass();
new LamRun();
}
}

View File

@ -1,5 +0,0 @@
public class testTets(){
public static void main(String[] args){
new tetsF();
}
}

View File

@ -1,5 +0,0 @@
public class testTets{
public static void main(String[] args){
new TetsF();
}
}

View File

@ -1,5 +0,0 @@
public class testTets(){
public static void main(String[] args){
new tetsF();
}
}