From e6c58d44c2fbddada727ed0913e738223256f1f7 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 26 Jun 2017 16:59:10 +0200 Subject: [PATCH] =?UTF-8?q?Type=20f=C3=BCr=20Return=20fixen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dhbwstuttgart/core/ConsoleInterface.java | 13 +++++++++++++ src/de/dhbwstuttgart/core/JavaTXCompiler.java | 1 + .../syntaxtree/factory/UnifyTypeFactory.java | 7 +++---- .../constraints/ConstraintsFactory.java | 2 +- .../typeinference/typeAlgo/TYPE.java | 2 +- test/javFiles/Faculty.jav | 9 +++++++++ test/javFiles/mathStruc.jav | 18 ++++++++++++++++++ test/typeinference/JavaTXCompilerTest.java | 4 ++-- 8 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 test/javFiles/Faculty.jav create mode 100644 test/javFiles/mathStruc.jav diff --git a/src/de/dhbwstuttgart/core/ConsoleInterface.java b/src/de/dhbwstuttgart/core/ConsoleInterface.java index bbddfdfe..7c574456 100755 --- a/src/de/dhbwstuttgart/core/ConsoleInterface.java +++ b/src/de/dhbwstuttgart/core/ConsoleInterface.java @@ -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(); + } } diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 820c5b14..dc9a1127 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -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 generateTPHMap(ConstraintSet constraints){ diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index d640030a..9775fa17 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -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(); } /** diff --git a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java index 51274131..909f94d2 100644 --- a/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java +++ b/src/de/dhbwstuttgart/typeinference/constraints/ConstraintsFactory.java @@ -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){ diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 88eb7f78..6d76a462 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -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 diff --git a/test/javFiles/Faculty.jav b/test/javFiles/Faculty.jav new file mode 100644 index 00000000..0889314a --- /dev/null +++ b/test/javFiles/Faculty.jav @@ -0,0 +1,9 @@ +class Faculty { + + m () { + auto fact = (Integer x) -> { + return fact.apply(x); + }; + return fact; + } +} diff --git a/test/javFiles/mathStruc.jav b/test/javFiles/mathStruc.jav new file mode 100644 index 00000000..a4ac4741 --- /dev/null +++ b/test/javFiles/mathStruc.jav @@ -0,0 +1,18 @@ +class mathStruc { + +mathStruc(A a) { ;} + +A model(){ A a; return a; } + +void methode(){ +auto innerOp = o -> ms -> + new mathStruc(o.apply(this.model(),ms.model())); + } +} + +interface Fun1{ + A apply(B b); +} +interface Fun2{ + A apply(B b, C c); +} \ No newline at end of file diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index f62dd5b5..92f5754b 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -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"));