From 327f36f1c2cb345c5ceef23907b1c659d44b9099 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 28 Feb 2018 15:21:12 +0100 Subject: [PATCH] =?UTF-8?q?Faculty=20Test=20=C3=A4ndern.=20UnifyTypeFactor?= =?UTF-8?q?y=20konvertiert=20automatisch=20FunN=20Typen=20korrekt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/factory/UnifyTypeFactory.java | 15 +++++++++++++++ test/javFiles/Faculty.jav | 6 +----- test/javFiles/FacultyTyped.jav | 19 +++++++++++++++++++ test/typeinference/JavaTXCompilerTest.java | 4 ++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 test/javFiles/FacultyTyped.jav diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 43fcf1b4..e58ce50f 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -1,12 +1,17 @@ package de.dhbwstuttgart.syntaxtree.factory; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; +import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator; import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.parser.ASPParser; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.Void; @@ -72,6 +77,16 @@ public class UnifyTypeFactory { } public static UnifyType convert(RefType t){ + //Check if it is a FunN Type: + Pattern p = Pattern.compile("Fun(\\d+)"); + Matcher m = p.matcher(t.getName().toString()); + boolean b = m.matches(); + if(b){ + Integer N = Integer.valueOf(m.group(1)); + if((N + 1) == t.getParaList().size()){ + return convert(new FunN(t.getParaList())); + } + } UnifyType ret; if(t.getParaList() != null && t.getParaList().size() > 0){ List params = new ArrayList<>(); diff --git a/test/javFiles/Faculty.jav b/test/javFiles/Faculty.jav index 089d2f33..ca539add 100644 --- a/test/javFiles/Faculty.jav +++ b/test/javFiles/Faculty.jav @@ -6,14 +6,10 @@ class Faculty { return x; } - Fun1 m () { + m () { var fact = (Integer x) -> { return mul(x, fact.apply(x)); }; return fact; } -} - -interface Fun1{ - B apply(A a); } \ No newline at end of file diff --git a/test/javFiles/FacultyTyped.jav b/test/javFiles/FacultyTyped.jav new file mode 100644 index 00000000..089d2f33 --- /dev/null +++ b/test/javFiles/FacultyTyped.jav @@ -0,0 +1,19 @@ +import java.lang.Integer; + +class Faculty { + + Integer mul(Integer x, Integer y) { + return x; + } + + Fun1 m () { + var fact = (Integer x) -> { + return mul(x, fact.apply(x)); + }; + return fact; + } +} + +interface Fun1{ + B apply(A a); +} \ No newline at end of file diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 3fe7c17d..bf48a537 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -53,6 +53,10 @@ public class JavaTXCompilerTest { execute(new File(rootDirectory+"Faculty.jav")); } @Test + public void facultyTyped() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"FacultyTyped.jav")); + } + @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); }