forked from JavaTX/JavaCompilerCore
Type für Return fixen
This commit is contained in:
parent
1be1bb83ca
commit
e6c58d44c2
@ -1,8 +1,21 @@
|
|||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ConsoleInterface {
|
public class ConsoleInterface {
|
||||||
private static final String directory = System.getProperty("user.dir");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ public class JavaTXCompiler {
|
|||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
}
|
}
|
||||||
return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
|
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){
|
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints){
|
||||||
|
@ -118,16 +118,15 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair convert(Pair p) {
|
public static UnifyPair convert(Pair p) {
|
||||||
if(p.OperatorSmaller()) {
|
if(p.GetOperator().equals(PairOperator.SMALLERDOT)) {
|
||||||
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
||||||
, UnifyTypeFactory.convert(p.TA2));
|
, UnifyTypeFactory.convert(p.TA2));
|
||||||
return ret;
|
return ret;
|
||||||
}else if(p.OperatorEqual()){
|
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)){
|
||||||
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
|
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
|
||||||
, UnifyTypeFactory.convert(p.TA2));
|
, UnifyTypeFactory.convert(p.TA2));
|
||||||
return ret;
|
return ret;
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
public class ConstraintsFactory {
|
public class ConstraintsFactory {
|
||||||
public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2, PairOperator equalsdot, TypeInferenceBlockInformation info){
|
public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1, RefTypeOrTPHOrWildcardOrGeneric t2, PairOperator equalsdot, TypeInferenceBlockInformation info){
|
||||||
//Check whether Generics are in the same class:
|
//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,
|
public static Pair createPair(RefTypeOrTPHOrWildcardOrGeneric t1,
|
||||||
RefTypeOrTPHOrWildcardOrGeneric t2, TypeInferenceBlockInformation info){
|
RefTypeOrTPHOrWildcardOrGeneric t2, TypeInferenceBlockInformation info){
|
||||||
|
@ -176,7 +176,7 @@ public class TYPE implements StatementVisitor{
|
|||||||
public void visit(Return returnExpr) {
|
public void visit(Return returnExpr) {
|
||||||
returnExpr.retexpr.accept(this);
|
returnExpr.retexpr.accept(this);
|
||||||
constraintsSet.addUndConstraint(ConstraintsFactory.createPair(
|
constraintsSet.addUndConstraint(ConstraintsFactory.createPair(
|
||||||
returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), info));
|
returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT, info));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
9
test/javFiles/Faculty.jav
Normal file
9
test/javFiles/Faculty.jav
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class Faculty {
|
||||||
|
|
||||||
|
m () {
|
||||||
|
auto fact = (Integer x) -> {
|
||||||
|
return fact.apply(x);
|
||||||
|
};
|
||||||
|
return fact;
|
||||||
|
}
|
||||||
|
}
|
18
test/javFiles/mathStruc.jav
Normal file
18
test/javFiles/mathStruc.jav
Normal 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);
|
||||||
|
}
|
@ -26,8 +26,8 @@ public class JavaTXCompilerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException, ClassNotFoundException {
|
public void test() throws IOException, ClassNotFoundException {
|
||||||
filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
|
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user