Faculty Test ändern. UnifyTypeFactory konvertiert automatisch FunN Typen korrekt

This commit is contained in:
JanUlrich 2018-02-28 15:21:12 +01:00
parent f023754328
commit 327f36f1c2
4 changed files with 39 additions and 5 deletions

View File

@ -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<UnifyType> params = new ArrayList<>();

View File

@ -6,14 +6,10 @@ class Faculty {
return x;
}
Fun1<java.lang.Integer,java.lang.Integer> m () {
m () {
var fact = (Integer x) -> {
return mul(x, fact.apply(x));
};
return fact;
}
}
interface Fun1<A,B>{
B apply(A a);
}

View File

@ -0,0 +1,19 @@
import java.lang.Integer;
class Faculty {
Integer mul(Integer x, Integer y) {
return x;
}
Fun1<java.lang.Integer,java.lang.Integer> m () {
var fact = (Integer x) -> {
return mul(x, fact.apply(x));
};
return fact;
}
}
interface Fun1<A,B>{
B apply(A a);
}

View File

@ -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"));
}