Berücksichtige TPH =. TPH Ergebnisse im ResultSet

This commit is contained in:
JanUlrich 2017-09-25 11:22:53 +02:00
parent b31da88902
commit 276ff44756
3 changed files with 34 additions and 6 deletions

View File

@ -146,7 +146,12 @@ public class UnifyTypeFactory {
RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs);
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
if(tl instanceof TypePlaceholder){
if(tr instanceof TypePlaceholder) return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
if(tr instanceof TypePlaceholder) {
if(mp.getPairOp().equals(PairOperator.EQUALSDOT))
return new PairTPHequalRefType((TypePlaceholder)tl, tr);
else
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
}
return new PairTPHequalRefType((TypePlaceholder)tl, tr);
}else throw new NotImplementedException();
}

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Pair;
@ -24,7 +25,8 @@ public class ResultSet {
type.accept(related);
return new ResolvedType(type, related.relatedTPHs);
}else{
return new ResolvedType(type,new HashSet<>());
throw new NotImplementedException();
//return new ResolvedType(type,new HashSet<>());
}
}
@ -68,11 +70,29 @@ class Resolver implements ResultSetVisitor {
@Override
public void visit(PairTPHequalRefType p) {
RefTypeOrTPHOrWildcardOrGeneric otherSide = null;
if(p.left.equals(toResolve)){
resolved = p.right;
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
p.right.accept(related);
additionalTPHs.addAll(related.relatedTPHs);
otherSide = p.left;
}
if(p.right.equals(toResolve)){
resolved = p.left;
otherSide = p.right;
}
if(otherSide != null){
if(resolved instanceof RefType){
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
otherSide.accept(related);
additionalTPHs.addAll(related.relatedTPHs);
}else if(resolved instanceof TypePlaceholder){
Set<ResultPair> newResultSet = new HashSet<>(result.results);
newResultSet.remove(p);
ResolvedType resolvedType = new Resolver(new ResultSet(newResultSet)).resolve((TypePlaceholder) resolved);
this.resolved = resolvedType.resolvedType;
this.additionalTPHs.addAll(resolvedType.additionalGenerics);
}else {
throw new NotImplementedException();
}
}
}

View File

@ -49,8 +49,11 @@ public class JavaTXCompilerTest {
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
for(ResultSet resultSet : compiler.typeInference()){
List<ResultSet> results = compiler.typeInference();
assert results.size()>0;
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
System.out.println(tip.insert(content));