Type für Return fixen

This commit is contained in:
JanUlrich 2017-06-26 16:59:10 +02:00
parent 1be1bb83ca
commit e6c58d44c2
8 changed files with 48 additions and 8 deletions

View File

@ -1,8 +1,21 @@
package de.dhbwstuttgart.core;
import de.dhbwstuttgart.parser.ClassNotFoundException;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class ConsoleInterface {
private static final String directory = System.getProperty("user.dir");
public static void main(String[] args) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler();
for(String arg : Arrays.asList(args)){
compiler.parse(new File(arg));
}
compiler.typeInference();
}
}

View File

@ -65,6 +65,7 @@ public class JavaTXCompiler {
results.addAll(result);
}
return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
//return new ResultSet(new HashSet<>(Arrays.asList(UnifyTypeFactory.convert(results, generateTPHMap(cons)).iterator().next())));
}
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints){

View File

@ -118,16 +118,15 @@ public class UnifyTypeFactory {
}
public static UnifyPair convert(Pair p) {
if(p.OperatorSmaller()) {
if(p.GetOperator().equals(PairOperator.SMALLERDOT)) {
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}else if(p.OperatorEqual()){
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)){
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}else throw new NotImplementedException();
}else throw new NotImplementedException();
}
/**

View File

@ -14,7 +14,7 @@ import java.util.List;
public class ConstraintsFactory {
public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2, PairOperator equalsdot, TypeInferenceBlockInformation info){
//Check whether Generics are in the same class:
return new Pair(checkGeneric(t1, info), checkGeneric(t2, info));
return new Pair(checkGeneric(t1, info), checkGeneric(t2, info), equalsdot);
}
public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1,
RefTypeOrTPHOrWildcardOrGeneric t2, TypeInferenceBlockInformation info){

View File

@ -176,7 +176,7 @@ public class TYPE implements StatementVisitor{
public void visit(Return returnExpr) {
returnExpr.retexpr.accept(this);
constraintsSet.addUndConstraint(ConstraintsFactory.createPair(
returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), info));
returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT, info));
}
@Override

View File

@ -0,0 +1,9 @@
class Faculty {
m () {
auto fact = (Integer x) -> {
return fact.apply(x);
};
return fact;
}
}

View File

@ -0,0 +1,18 @@
class mathStruc<A> {
mathStruc(A a) { ;}
A model(){ A a; return a; }
void methode(){
auto innerOp = o -> ms ->
new mathStruc<A>(o.apply(this.model(),ms.model()));
}
}
interface Fun1<A,B>{
A apply(B b);
}
interface Fun2<A,B,C>{
A apply(B b, C c);
}

View File

@ -26,8 +26,8 @@ public class JavaTXCompilerTest {
@Test
public void test() throws IOException, ClassNotFoundException {
filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
//filesToTest.add(new File(rootDirectory+"Vector.jav"));