forked from JavaTX/JavaCompilerCore
Faculty Test ändern. UnifyTypeFactory konvertiert automatisch FunN Typen korrekt
This commit is contained in:
parent
f023754328
commit
327f36f1c2
@ -1,12 +1,17 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.factory;
|
package de.dhbwstuttgart.syntaxtree.factory;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
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.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
@ -72,6 +77,16 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(RefType t){
|
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;
|
UnifyType ret;
|
||||||
if(t.getParaList() != null && t.getParaList().size() > 0){
|
if(t.getParaList() != null && t.getParaList().size() > 0){
|
||||||
List<UnifyType> params = new ArrayList<>();
|
List<UnifyType> params = new ArrayList<>();
|
||||||
|
@ -6,14 +6,10 @@ class Faculty {
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
Fun1<java.lang.Integer,java.lang.Integer> m () {
|
m () {
|
||||||
var fact = (Integer x) -> {
|
var fact = (Integer x) -> {
|
||||||
return mul(x, fact.apply(x));
|
return mul(x, fact.apply(x));
|
||||||
};
|
};
|
||||||
return fact;
|
return fact;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
interface Fun1<A,B>{
|
|
||||||
B apply(A a);
|
|
||||||
}
|
}
|
19
test/javFiles/FacultyTyped.jav
Normal file
19
test/javFiles/FacultyTyped.jav
Normal 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);
|
||||||
|
}
|
@ -53,6 +53,10 @@ public class JavaTXCompilerTest {
|
|||||||
execute(new File(rootDirectory+"Faculty.jav"));
|
execute(new File(rootDirectory+"Faculty.jav"));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
public void facultyTyped() throws IOException, ClassNotFoundException {
|
||||||
|
execute(new File(rootDirectory+"FacultyTyped.jav"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
public void matrix() throws IOException, ClassNotFoundException {
|
public void matrix() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Matrix.jav"));
|
execute(new File(rootDirectory+"Matrix.jav"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user