Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9657ef5691 | |||
| 88db5f9eb7 | |||
| 8c5228f8c5 | |||
| 3a9a2576a2 | |||
| 5dccbffebd | |||
| 76f2048797 | |||
| a1195b689d | |||
| 3cd61778d6 | |||
| 021d3e1b27 | |||
| c90f01d5db | |||
| 8b3b018ea9 | |||
| 210adaa493 |
Binary file not shown.
@@ -0,0 +1,19 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
import Pair;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class Kombinatoren_After {
|
||||||
|
|
||||||
|
|
||||||
|
after (fst, snd) { //System.out.println("after2");
|
||||||
|
|
||||||
|
return () -> Stream.of(
|
||||||
|
toks -> {
|
||||||
|
return fst.apply().flatMap(x ->
|
||||||
|
x.apply(toks).flatMap(p1 ->
|
||||||
|
snd.apply().flatMap(y -> y.apply(p1.snd()).map(p2 ->
|
||||||
|
new Pair<>(new Pair<>(p1.fst(), p2.fst()), p2.snd()))))); } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
import Pair;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class Kombinatoren_After_Lazy {
|
||||||
|
|
||||||
|
|
||||||
|
afterP (fst, snd) {
|
||||||
|
return toks -> {
|
||||||
|
return fst.apply(toks).flatMap(p1 ->
|
||||||
|
snd.apply(p1.snd()).map(p2 ->
|
||||||
|
new Pair<>(new Pair<>(p1.fst(), p2.fst()), p2.snd())));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
import Pair;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class Kombinatoren_Or {
|
||||||
|
|
||||||
|
|
||||||
|
orP (p1, p2) {
|
||||||
|
return ()-> Stream.concat(p1.apply(), p2.apply());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
after (fst, snd) { //System.out.println("after2");
|
||||||
|
|
||||||
|
return () -> Stream.of(
|
||||||
|
toks -> {
|
||||||
|
return fst.apply().flatMap(x ->
|
||||||
|
x.apply(toks).flatMap(p1 ->
|
||||||
|
snd.apply().flatMap(y -> y.apply(p1.snd()).map(p2 ->
|
||||||
|
new Pair<>(new Pair<>(p1.fst(), p2.fst()), p2.snd()))))); } );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
trans (p, f) {
|
||||||
|
return () -> p.apply().map(x -> (toks -> x.apply(toks).map(pr -> new Pair<>(f.apply(pr.fst()), pr.snd() ) ) ) );
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
//import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
//import java.lang.String;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import Pair;
|
||||||
|
import Kombinatoren_failure;
|
||||||
|
|
||||||
|
public class Kombinatoren_Satisfy {
|
||||||
|
|
||||||
|
kb = new Kombinatoren_failure();
|
||||||
|
|
||||||
|
satisfy(cond) {
|
||||||
|
// return () -> Stream.of (newToks -> new Kombinatoren_failure().failure().apply().map(x -> x.apply(newToks)));
|
||||||
|
//}
|
||||||
|
return () -> Stream.of (toks -> {
|
||||||
|
if(toks.isEmpty()) {
|
||||||
|
return new ArrayList<>().stream();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var fst = toks.getFirst();
|
||||||
|
if (cond.apply(fst))
|
||||||
|
{
|
||||||
|
//var newToks = List.copyOf(toks.subList(1, toks.size()));
|
||||||
|
var newToks = new ArrayList<>(toks);
|
||||||
|
return newToks.removeFirst();
|
||||||
|
kb.getContent(
|
||||||
|
kb.succeed(fst).apply().map(x -> x.apply(newToks))
|
||||||
|
);
|
||||||
|
// ;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/* () -> Stream.of (toks -> {
|
||||||
|
//System.out.println(toks);
|
||||||
|
if(toks.isEmpty())
|
||||||
|
{
|
||||||
|
return new ArrayList<>().stream();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var fst = toks.getFirst();
|
||||||
|
if (cond.apply(fst))
|
||||||
|
{
|
||||||
|
var newToks = List.copyOf(toks.subList(1, toks.size()));
|
||||||
|
//System.out.println("satisfy ok " + fst.toString());
|
||||||
|
//return get(succeed(fst).apply().map(x -> x.apply(newToks)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//System.out.println("satisfy failure " + fst.toString());
|
||||||
|
//return get(failure().apply()).apply(toks);
|
||||||
|
}
|
||||||
|
return new ArrayList<>().stream();
|
||||||
|
} } ) ;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
import Pair;
|
||||||
|
//import java.util.function.Function;
|
||||||
|
|
||||||
|
public class Kombinatoren_Trans {
|
||||||
|
|
||||||
|
|
||||||
|
trans (p, f) {
|
||||||
|
return () -> p.apply().map(x -> (toks -> x.apply(toks).map(pr -> new Pair<>(f.apply(pr.fst()), pr.snd() ) ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import Pair;
|
||||||
|
|
||||||
|
|
||||||
|
public class Kombinatoren_failure {
|
||||||
|
public getContent(s) {
|
||||||
|
return s.toList().getFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public failure() {
|
||||||
|
return () -> Stream.of(
|
||||||
|
toks -> new ArrayList<>().stream());
|
||||||
|
}
|
||||||
|
public succeed( value) {
|
||||||
|
return () -> Stream.of(toks -> {
|
||||||
|
//System.out.println("succeed");
|
||||||
|
var al = new ArrayList<>();
|
||||||
|
al.add(new Pair<>(value, toks));
|
||||||
|
//al.forEach(x -> { System.out.println(x.toString());});
|
||||||
|
return al.stream();});
|
||||||
|
}
|
||||||
|
|
||||||
|
parser(p, inp) {
|
||||||
|
return p.map(y -> y.apply(
|
||||||
|
inp.chars().mapToObj(c -> (char) c)
|
||||||
|
.collect(Collectors.toList())))
|
||||||
|
.flatMap(x -> x)
|
||||||
|
.filter(x -> x.snd().isEmpty())
|
||||||
|
.findFirst()
|
||||||
|
.get()
|
||||||
|
.fst();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
satisfy(cond) {
|
||||||
|
return newToks -> failure().apply().map(x -> x.apply(newToks));
|
||||||
|
/*
|
||||||
|
return () -> Stream.of (toks -> {
|
||||||
|
if(toks.isEmpty()) {
|
||||||
|
return new ArrayList<>().stream();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var fst = toks.getFirst();
|
||||||
|
if (cond.apply(fst)) {
|
||||||
|
var newToks = List.copyOf(toks.subList(1, toks.size()));
|
||||||
|
this.getContent(
|
||||||
|
succeed(fst)
|
||||||
|
.apply().map(x -> x.apply(newToks))
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -1,36 +1,24 @@
|
|||||||
import java.util.Vector;
|
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
import java.lang.Object;
|
import java.lang.Object;
|
||||||
|
|
||||||
class Pair<U, T> {
|
import java.util.List;
|
||||||
U a;
|
|
||||||
T b;
|
|
||||||
|
|
||||||
make(x) {
|
class Pair<T, U> {
|
||||||
var ret = new Pair<>();
|
T a;
|
||||||
ret.a = x.elementAt(0);
|
U b;
|
||||||
ret.b = x.elementAt(1);
|
|
||||||
return ret;
|
public Pair() { }
|
||||||
|
public Pair(T a, U b) {
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T fst () {
|
||||||
eq(a, b) {
|
return a;
|
||||||
b = a;
|
|
||||||
return a == b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public U snd () {
|
||||||
compare( p) {
|
return b;
|
||||||
return eq(p.a, p.b);
|
|
||||||
//return p.a == p.b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void m(Pair<?, ?> p, Vector<?> b)
|
|
||||||
{
|
|
||||||
//this.compare(p); //1, type incorrect
|
|
||||||
this.compare(this.make(b)); //2, OK
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Pair<T, U> {
|
||||||
|
T a;
|
||||||
|
U b;
|
||||||
|
|
||||||
|
public Pair() { }
|
||||||
|
public Pair(T a, U b) {
|
||||||
|
System.out.println("Pair a; " + a + " b: " + b);
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T fst () {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public U snd () {
|
||||||
|
System.out.println("snd b: " + b);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Pair<"+a.toString()+","+b.toString()+">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
import java.util.stream.Stream;
|
||||||
|
//import java.util.stream.IntStream;
|
||||||
|
//import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.lang.Character;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
//import java.util.function.IntFunction;
|
||||||
|
|
||||||
|
import Pair;
|
||||||
|
|
||||||
|
|
||||||
|
public class Parser {
|
||||||
|
|
||||||
|
|
||||||
|
strToList(s) {
|
||||||
|
var al;
|
||||||
|
al = new ArrayList<>();
|
||||||
|
var i = 0;
|
||||||
|
while (i < s.length()) {
|
||||||
|
al.add(s.charAt(i));
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
return al;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
parser(p, inp) {
|
||||||
|
return p.map(y -> y.apply(
|
||||||
|
strToList(inp)//chars().mapToObj(c -> (Character) c)
|
||||||
|
//.toList()
|
||||||
|
))
|
||||||
|
|
||||||
|
//.flatMap(x -> x)
|
||||||
|
|
||||||
|
//.filter(x -> x.snd().isEmpty())
|
||||||
|
;
|
||||||
|
/*
|
||||||
|
.findFirst()
|
||||||
|
.get()
|
||||||
|
.fst()
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
satisfy(cond) {
|
||||||
|
return newToks -> failure().apply().map(x -> x.apply(newToks));
|
||||||
|
/*
|
||||||
|
return () -> Stream.of (toks -> {
|
||||||
|
if(toks.isEmpty()) {
|
||||||
|
return new ArrayList<>().stream();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var fst = toks.getFirst();
|
||||||
|
if (cond.apply(fst)) {
|
||||||
|
var newToks = List.copyOf(toks.subList(1, toks.size()));
|
||||||
|
this.getContent(
|
||||||
|
succeed(fst)
|
||||||
|
.apply().map(x -> x.apply(newToks))
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.Codegen;
|
|||||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
|
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
@@ -103,6 +104,7 @@ public class JavaTXCompiler {
|
|||||||
public DirectoryClassLoader getClassLoader() {
|
public DirectoryClassLoader getClassLoader() {
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
|
public final List<CompilerWarning> generatedWarnings = new ArrayList<>();
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Collections.singletonList(sourceFile), List.of(), new File("."), ConsoleInterface.inferTogether);
|
this(Collections.singletonList(sourceFile), List.of(), new File("."), ConsoleInterface.inferTogether);
|
||||||
@@ -131,6 +133,18 @@ public class JavaTXCompiler {
|
|||||||
// INSTANCE = this;
|
// INSTANCE = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void warn(CompilerWarning warning) {
|
||||||
|
this.generatedWarnings.add(warning);
|
||||||
|
}
|
||||||
|
public void checkWarnings() {
|
||||||
|
for (var warning : this.generatedWarnings) {
|
||||||
|
defaultLogger.error("[Warning] " + warning.getMessage());
|
||||||
|
}
|
||||||
|
if (!generatedWarnings.isEmpty()) {
|
||||||
|
throw new RuntimeException(generatedWarnings.size() + " warnings in code, aborting!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<SourceFileContext> generateSources(List<File> sources) throws IOException, ClassNotFoundException {
|
private List<SourceFileContext> generateSources(List<File> sources) throws IOException, ClassNotFoundException {
|
||||||
// TODO This should maybe be moved elsewhere
|
// TODO This should maybe be moved elsewhere
|
||||||
var treeList = new ArrayList<SourceFileContext>(sources.size());
|
var treeList = new ArrayList<SourceFileContext>(sources.size());
|
||||||
@@ -718,6 +732,7 @@ public class JavaTXCompiler {
|
|||||||
var sf = sourceFiles.get(file);
|
var sf = sourceFiles.get(file);
|
||||||
if (sf.isGenerated()) continue;
|
if (sf.isGenerated()) continue;
|
||||||
var classes = generateBytecode(sf, typeinferenceResult);
|
var classes = generateBytecode(sf, typeinferenceResult);
|
||||||
|
checkWarnings();
|
||||||
sf.setGenerated();
|
sf.setGenerated();
|
||||||
writeClassFile(classes, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
writeClassFile(classes, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
||||||
}
|
}
|
||||||
@@ -730,6 +745,7 @@ public class JavaTXCompiler {
|
|||||||
var sf = sourceFiles.get(file);
|
var sf = sourceFiles.get(file);
|
||||||
if (sf.isGenerated()) continue;
|
if (sf.isGenerated()) continue;
|
||||||
var classes = generateBytecode(file);
|
var classes = generateBytecode(file);
|
||||||
|
checkWarnings();
|
||||||
sf.setGenerated();
|
sf.setGenerated();
|
||||||
writeClassFile(classes, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
writeClassFile(classes, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.dhbwstuttgart.exceptions;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
public class CompilerWarning extends RuntimeException {
|
||||||
|
public CompilerWarning(Token offset, String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
|||||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||||
|
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
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;
|
||||||
@@ -20,9 +21,8 @@ import de.dhbwstuttgart.target.tree.type.*;
|
|||||||
import de.dhbwstuttgart.typeinference.result.*;
|
import de.dhbwstuttgart.typeinference.result.*;
|
||||||
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import javax.swing.text.html.Option;
|
|
||||||
import java.sql.Array;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -39,11 +39,16 @@ public class ASTToTargetAST {
|
|||||||
public static RefType OBJECT = ASTFactory.createObjectType(); // TODO It would be better if I could call this directly but the hashcode seems to change
|
public static RefType OBJECT = ASTFactory.createObjectType(); // TODO It would be better if I could call this directly but the hashcode seems to change
|
||||||
|
|
||||||
public List<Generics> all;
|
public List<Generics> all;
|
||||||
//public Generics generics;
|
|
||||||
//public List<Generics> currentMethodOverloads;
|
|
||||||
|
|
||||||
final Map<ClassOrInterface, Set<GenericTypeVar>> userDefinedGenerics = new HashMap<>();
|
final Map<ClassOrInterface, Set<GenericTypeVar>> userDefinedGenerics = new HashMap<>();
|
||||||
final Map<Method, Set<SignaturePair>> tphsInMethods = new HashMap<>();
|
final Map<Method, Set<SignaturePair>> tphsInMethods = new HashMap<>();
|
||||||
|
final Map<Method, Set<TypePlaceholder>> usedTPHsOfMethods = new HashMap<>();
|
||||||
|
|
||||||
|
void addTPHToMethod(TypePlaceholder tph) {
|
||||||
|
var set = usedTPHsOfMethods.get(currentMethod);
|
||||||
|
set.add(tph);
|
||||||
|
}
|
||||||
|
|
||||||
private Method currentMethod;
|
private Method currentMethod;
|
||||||
|
|
||||||
public final JavaTXCompiler compiler;
|
public final JavaTXCompiler compiler;
|
||||||
@@ -209,7 +214,7 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<TargetType> unify(TargetType a, TargetType b) {
|
private static Optional<TargetType> unify(TargetType a, TargetType b) {
|
||||||
if (typesStrictlyEqual(a, b)) return Optional.of(a);
|
if (typesStrictlyEqual(a, b)) return Optional.ofNullable(a);
|
||||||
var unify = new MartelliMontanariUnify();
|
var unify = new MartelliMontanariUnify();
|
||||||
var ua = toUnifyType(a);
|
var ua = toUnifyType(a);
|
||||||
var unifier = unify.unify(Set.of(ua, toUnifyType(b)));
|
var unifier = unify.unify(Set.of(ua, toUnifyType(b)));
|
||||||
@@ -306,9 +311,9 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("============== INPUT ==============");
|
Target.logger.info("============== INPUT ==============");
|
||||||
for (var m : a) {
|
for (var m : a) {
|
||||||
System.out.println(m);
|
Target.logger.info(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Algorithm
|
// Algorithm
|
||||||
@@ -326,22 +331,22 @@ public class ASTToTargetAST {
|
|||||||
var u_opt = unify(m, m1);
|
var u_opt = unify(m, m1);
|
||||||
if (u_opt.isPresent()) {
|
if (u_opt.isPresent()) {
|
||||||
var u = u_opt.get();
|
var u = u_opt.get();
|
||||||
//System.out.println("Unified " + m + " AND " + m1 + "\n\t" + u);
|
//Target.logger.info("Unified " + m + " AND " + m1 + "\n\t" + u);
|
||||||
i.remove(m1);
|
i.remove(m1);
|
||||||
R.remove(m);
|
R.remove(m);
|
||||||
R.remove(m1);
|
R.remove(m1);
|
||||||
R.add(u);
|
R.add(u);
|
||||||
a.add(u);
|
a.add(u);
|
||||||
} /*else {
|
} /*else {
|
||||||
System.out.println("Couldn't unify " + m + " AND " + m1);
|
Target.logger.info("Couldn't unify " + m + " AND " + m1);
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("============== OUTPUT ==============");
|
Target.logger.info("============== OUTPUT ==============");
|
||||||
for (var mg : R) {
|
for (var mg : R) {
|
||||||
System.out.println(mg.methods.size() + " " + mg);
|
Target.logger.info(mg.methods.size() + " " + mg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return R;
|
return R;
|
||||||
@@ -395,6 +400,32 @@ public class ASTToTargetAST {
|
|||||||
var bridge = generateBridgeMethod(input, genMethods);
|
var bridge = generateBridgeMethod(input, genMethods);
|
||||||
bridge.map(m1::add);
|
bridge.map(m1::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<List<TargetMethod>> pairs = new ArrayList<>();
|
||||||
|
for (int i = 0; i < m1.size(); i++) {
|
||||||
|
for (int j = i + 1; j < m1.size(); j++) {
|
||||||
|
pairs.add(List.of(m1.get(i), m1.get(j)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var duplicates = pairs.stream().filter(pair -> typesStrictlyEqual(
|
||||||
|
pair.get(0).signature().parameters().stream().map(p -> p.pattern().type()).toList(),
|
||||||
|
pair.get(1).signature().parameters().stream().map(p -> p.pattern().type()).toList())
|
||||||
|
).filter(m -> {
|
||||||
|
var a = m.get(0);
|
||||||
|
var b = m.get(1);
|
||||||
|
if (!Objects.equals(a.name(), b.name())) return false;
|
||||||
|
if (a.generics() == null || b.generics() == null) return true;
|
||||||
|
return typesAreDifferent(a.base(), a.generics(), b.generics());
|
||||||
|
}).collect(Collectors.toSet());
|
||||||
|
if (!duplicates.isEmpty()) {
|
||||||
|
for (var d : duplicates) {
|
||||||
|
var a = d.get(0);
|
||||||
|
var b = d.get(1);
|
||||||
|
compiler.warn(new CompilerWarning(a.base().getOffset(), "Duplicate Method definition " + a.name() +
|
||||||
|
" found, signature " + a.signature().getDescriptor() + " clashes with signature " + b.signature().getDescriptor()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var methods = new HashSet<>(m1).stream().toList();
|
var methods = new HashSet<>(m1).stream().toList();
|
||||||
|
|
||||||
TargetMethod staticConstructor = null;
|
TargetMethod staticConstructor = null;
|
||||||
@@ -460,6 +491,7 @@ public class ASTToTargetAST {
|
|||||||
List<TargetConstructor> result = new ArrayList<>();
|
List<TargetConstructor> result = new ArrayList<>();
|
||||||
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
||||||
this.currentMethod = input;
|
this.currentMethod = input;
|
||||||
|
this.usedTPHsOfMethods.put(input, new HashSet<>());
|
||||||
|
|
||||||
for (var s : all) {
|
for (var s : all) {
|
||||||
generics = s;
|
generics = s;
|
||||||
@@ -568,7 +600,7 @@ public class ASTToTargetAST {
|
|||||||
var body = new TargetBlock(List.of(generateCall(method, params, classType)));
|
var body = new TargetBlock(List.of(generateCall(method, params, classType)));
|
||||||
cases.add(new TargetSwitch.Case(List.of(lastPattern), body));
|
cases.add(new TargetSwitch.Case(List.of(lastPattern), body));
|
||||||
} else {
|
} else {
|
||||||
//candidates.forEach(m -> System.out.println(m.getSignature()));
|
//candidates.forEach(m -> Target.logger.info(m.getSignature()));
|
||||||
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType);
|
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType);
|
||||||
var body = new TargetBlock(List.of(caseBody));
|
var body = new TargetBlock(List.of(caseBody));
|
||||||
var case_ = new TargetSwitch.Case(List.of(lastPattern), body);
|
var case_ = new TargetSwitch.Case(List.of(lastPattern), body);
|
||||||
@@ -607,6 +639,7 @@ public class ASTToTargetAST {
|
|||||||
// TODO This only goes one layer deep, this is fine for records as they can't extend anything but fails for complex hierarchies
|
// TODO This only goes one layer deep, this is fine for records as they can't extend anything but fails for complex hierarchies
|
||||||
var intersection = new HashSet<>(cla.getSuperInterfaces());
|
var intersection = new HashSet<>(cla.getSuperInterfaces());
|
||||||
intersection.retainAll(clb.getSuperInterfaces());
|
intersection.retainAll(clb.getSuperInterfaces());
|
||||||
|
if (intersection.isEmpty()) return Optional.empty();
|
||||||
|
|
||||||
var intfclass = compiler.getClass(intersection.iterator().next().getName());
|
var intfclass = compiler.getClass(intersection.iterator().next().getName());
|
||||||
// We need to map the generics
|
// We need to map the generics
|
||||||
@@ -636,7 +669,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
var ta = pa.pattern().type();
|
var ta = pa.pattern().type();
|
||||||
var tb = pb.pattern().type();
|
var tb = pb.pattern().type();
|
||||||
//System.out.println(ta + " " + tb);
|
//Target.logger.info(ta + " " + tb);
|
||||||
|
|
||||||
if (Objects.equals(ta, tb)) continue;
|
if (Objects.equals(ta, tb)) continue;
|
||||||
var common = commonSealedInterface(ta, tb);
|
var common = commonSealedInterface(ta, tb);
|
||||||
@@ -727,7 +760,7 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var tMethod = convert(method, generics);
|
var tMethod = convert(method, generics);
|
||||||
res.add(new TargetMethod(tMethod.access(), name, tMethod.block(), tMethod.signature(), tMethod.txSignature()));
|
res.add(new TargetMethod(tMethod.access(), name, tMethod.block(), tMethod.signature(), tMethod.txSignature(), tMethod.base(), tMethod.generics()));
|
||||||
}
|
}
|
||||||
|
|
||||||
var parameters = signatureParams.stream().map( p -> new TargetLocalVar(p.pattern().type(), p.pattern().name())).toList();
|
var parameters = signatureParams.stream().map( p -> new TargetLocalVar(p.pattern().type(), p.pattern().name())).toList();
|
||||||
@@ -739,7 +772,7 @@ public class ASTToTargetAST {
|
|||||||
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType);
|
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType);
|
||||||
var block = new TargetBlock(List.of(stmt));
|
var block = new TargetBlock(List.of(stmt));
|
||||||
|
|
||||||
var bridgeMethod = new TargetMethod(firstMethod.access(), firstMethod.name(), block, group.signature.java, group.signature.tx);
|
var bridgeMethod = new TargetMethod(firstMethod.access(), firstMethod.name(), block, group.signature.java, group.signature.tx, firstMethod.base(), null);
|
||||||
res.add(bridgeMethod);
|
res.add(bridgeMethod);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -792,7 +825,8 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private TargetMethod convert(MethodWithTphs mtph, IGenerics generics) {
|
private TargetMethod convert(MethodWithTphs mtph, IGenerics generics) {
|
||||||
return new TargetMethod(mtph.method.modifier, mtph.method.name, convert(mtph.method.block, generics), mtph.signature.java(), mtph.signature.tx());
|
this.currentMethod = mtph.method;
|
||||||
|
return new TargetMethod(mtph.method.modifier, mtph.method.name, convert(mtph.method.block, generics), mtph.signature.java(), mtph.signature.tx(), mtph.method, generics);
|
||||||
}
|
}
|
||||||
|
|
||||||
record Signature(TargetMethod.Signature java, TargetMethod.Signature tx, Generics generics) {
|
record Signature(TargetMethod.Signature java, TargetMethod.Signature tx, Generics generics) {
|
||||||
@@ -810,9 +844,22 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean typesAreDifferent(Method m, IGenerics a, IGenerics b) {
|
||||||
|
if (m == null) return true;
|
||||||
|
var tphs = usedTPHsOfMethods.get(m);
|
||||||
|
for (var tph : tphs) {
|
||||||
|
var left = a.getTargetType(tph);
|
||||||
|
var right = b.getTargetType(tph);
|
||||||
|
Target.logger.info(tph + ": " + left + " & " + right);
|
||||||
|
if (!Objects.equals(left, right)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private Set<MethodWithTphs> convert(ClassOrInterface currentClass, Method method) {
|
private Set<MethodWithTphs> convert(ClassOrInterface currentClass, Method method) {
|
||||||
Set<MethodWithTphs> result = new HashSet<>();
|
Set<MethodWithTphs> result = new HashSet<>();
|
||||||
this.currentMethod = method;
|
this.currentMethod = method;
|
||||||
|
usedTPHsOfMethods.put(method, new HashSet<>());
|
||||||
|
|
||||||
List<Signature> signatures = new ArrayList<>();
|
List<Signature> signatures = new ArrayList<>();
|
||||||
for (var generics : all) {
|
for (var generics : all) {
|
||||||
@@ -836,14 +883,29 @@ public class ASTToTargetAST {
|
|||||||
var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method);
|
var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method);
|
||||||
|
|
||||||
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
|
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
|
||||||
//System.out.println(javaSignature.getDescriptor());
|
//Target.logger.info(javaSignature.getDescriptor());
|
||||||
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), generics.txGenerics, compiler));
|
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), generics.txGenerics, compiler));
|
||||||
|
|
||||||
signatures.add(new Signature(javaSignature, txSignature, generics));
|
signatures.add(new Signature(javaSignature, txSignature, generics));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!signatures.isEmpty()) {
|
||||||
|
var signature = signatures.getFirst();
|
||||||
|
// We need to convert once to find out what TPHs are existing in the given method
|
||||||
|
convert(new MethodWithTphs(method, signature.generics, signature));
|
||||||
|
}
|
||||||
|
|
||||||
for (var signature : signatures) {
|
for (var signature : signatures) {
|
||||||
result.add(new MethodWithTphs(method, signature.generics, signature));
|
var mtph = new MethodWithTphs(method, signature.generics, signature);
|
||||||
|
var duplicate = result.stream().filter(m -> m.signature.java.equals(signature.java))
|
||||||
|
.filter(m -> typesAreDifferent(method, m.generics.javaGenerics, signature.generics.javaGenerics)).findFirst();
|
||||||
|
if (duplicate.isPresent()) {
|
||||||
|
var d = duplicate.get();
|
||||||
|
compiler.warn(new CompilerWarning(method.block.getOffset(), "Duplicate Method definition " + method.name +
|
||||||
|
" found, signature " + d.signature.java.getDescriptor() + " clashes with signature " + signature.java.getDescriptor()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result.add(mtph);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -970,6 +1032,7 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, IGenerics generics) {
|
public TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, IGenerics generics) {
|
||||||
|
if (currentMethod != null && input instanceof TypePlaceholder tph) addTPHToMethod(tph);
|
||||||
return convert(input, generics, compiler);
|
return convert(input, generics, compiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
|||||||
final Map<Method, Set<Pair>> computedGenericsOfMethods = new HashMap<>();
|
final Map<Method, Set<Pair>> computedGenericsOfMethods = new HashMap<>();
|
||||||
final Map<ClassOrInterface, Set<Pair>> computedGenericsOfClasses = new HashMap<>();
|
final Map<ClassOrInterface, Set<Pair>> computedGenericsOfClasses = new HashMap<>();
|
||||||
|
|
||||||
final Map<Method, Set<TPH>> usedTPHsOfMethods = new HashMap<>();
|
final Map<Method, Set<TPH>> usedTPHsOfMethodSignatures = new HashMap<>();
|
||||||
final Map<Method, Set<Pair>> familyOfMethods = new HashMap<>();
|
final Map<Method, Set<Pair>> familyOfMethods = new HashMap<>();
|
||||||
|
|
||||||
final Set<PairLT> simplifiedConstraints = new HashSet<>();
|
final Set<PairLT> simplifiedConstraints = new HashSet<>();
|
||||||
@@ -583,7 +583,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
|||||||
referenced.addAll(typeVariablesOfClass);
|
referenced.addAll(typeVariablesOfClass);
|
||||||
|
|
||||||
generics(owner, method, result, referenced);
|
generics(owner, method, result, referenced);
|
||||||
usedTPHsOfMethods.put(method, usedTphs);
|
usedTPHsOfMethodSignatures.put(method, usedTphs);
|
||||||
|
|
||||||
normalize(result, classGenerics, usedTphs);
|
normalize(result, classGenerics, usedTphs);
|
||||||
|
|
||||||
@@ -782,7 +782,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
|||||||
}
|
}
|
||||||
doIterationForMethods(classOrInterface);
|
doIterationForMethods(classOrInterface);
|
||||||
for (var method : classOrInterface.getMethods()) {
|
for (var method : classOrInterface.getMethods()) {
|
||||||
var usedTPHs = usedTPHsOfMethods.get(method);
|
var usedTPHs = usedTPHsOfMethodSignatures.get(method);
|
||||||
if (usedTPHs != null)
|
if (usedTPHs != null)
|
||||||
referenced.addAll(usedTPHs);
|
referenced.addAll(usedTPHs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.dhbwstuttgart.target.tree;
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.target.generate.IGenerics;
|
||||||
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||||
import de.dhbwstuttgart.target.tree.expression.TargetPattern;
|
import de.dhbwstuttgart.target.tree.expression.TargetPattern;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
@@ -9,7 +11,11 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public record TargetMethod(int access, String name, TargetBlock block, Signature signature, Signature txSignature) {
|
public record TargetMethod(int access, String name, TargetBlock block, Signature signature, Signature txSignature, Method base, IGenerics generics) {
|
||||||
|
public TargetMethod(int access, String name, TargetBlock block, Signature signature, Signature txSignature) {
|
||||||
|
this(access, name, block, signature, txSignature, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public record Signature(Set<TargetGeneric> generics, List<MethodParameter> parameters, TargetType returnType) {
|
public record Signature(Set<TargetGeneric> generics, List<MethodParameter> parameters, TargetType returnType) {
|
||||||
public String getSignature() {
|
public String getSignature() {
|
||||||
return TargetMethod.getSignature(generics, parameters, returnType);
|
return TargetMethod.getSignature(generics, parameters, returnType);
|
||||||
|
|||||||
@@ -736,12 +736,12 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
|
|
||||||
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
|
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
|
||||||
// Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params)
|
// Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params)
|
||||||
ret.add(new Pair(foMethod.signature.get(i), assumption.getArgTypes().get(i), PairOperator.EQUALSDOT));
|
ret.add(new Pair(resolver.resolve(foMethod.signature.get(i)), resolver.resolve(assumption.getArgTypes().get(i)), PairOperator.EQUALSDOT));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zuordnung von MethodCall.signature(ReturnType) zu dem ReturnType der ausgewaehlten Methode (assumption.returnType)
|
// Zuordnung von MethodCall.signature(ReturnType) zu dem ReturnType der ausgewaehlten Methode (assumption.returnType)
|
||||||
ret.add(new Pair(foMethod.signature.getLast(), assumption.getReturnType(), PairOperator.EQUALSDOT));
|
ret.add(new Pair(resolver.resolve(foMethod.signature.getLast()), resolver.resolve(assumption.getReturnType()), PairOperator.EQUALSDOT));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -755,7 +755,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
UnifyType rhsType = pair.getRhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
|
if((!(lhsType instanceof ReferenceType) && !(lhsType instanceof FunNType)) || !(rhsType instanceof ExtendsType))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||||
@@ -781,7 +781,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
UnifyType rhsType = pair.getRhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
|
if((!(lhsType instanceof ReferenceType) && !(lhsType instanceof FunNType)) || !(rhsType instanceof SuperType))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
|
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
|
||||||
@@ -904,7 +904,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||||
var retType = fiArgs.getFirst();
|
var retType = fiArgs.getFirst();
|
||||||
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
|
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType); //FALSCHRUM????
|
||||||
var lhsRet = lhsArgs.getFirst();
|
var lhsRet = lhsArgs.getFirst();
|
||||||
|
|
||||||
Set<UnifyPair> result = new HashSet<>();
|
Set<UnifyPair> result = new HashSet<>();
|
||||||
@@ -972,16 +972,66 @@ public class RuleSet implements IRuleSet{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) {
|
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc) {
|
||||||
if(pair.getPairOp() != PairOperator.SMALLERDOT)
|
if(pair.getPairOp() != PairOperator.SMALLERDOT)
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
UnifyType rhsType = pair.getRhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
|
||||||
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
|
if(!(rhsType instanceof FunNType))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
|
/* muss nach angepasst werden */
|
||||||
|
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
|
||||||
|
if (lhsType instanceof ReferenceType) {
|
||||||
|
UnifyType typeFI = pair.getLhsType();
|
||||||
|
|
||||||
|
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
|
||||||
|
if(!opt.isPresent())
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||||
|
var retType = fiArgs.getFirst();
|
||||||
|
var rhsArgs = intf.getFunctionalInterfaceTypeArguments(rhsType);
|
||||||
|
var rhsRet = rhsArgs.getFirst();
|
||||||
|
|
||||||
|
Set<UnifyPair> result = new HashSet<>();
|
||||||
|
//if (retType instanceof ExtendsType) {
|
||||||
|
result.add(new UnifyPair(retType, rhsRet, PairOperator.SMALLER));
|
||||||
|
//} else if (retType instanceof SuperType) {
|
||||||
|
// return Optional.empty();
|
||||||
|
//} else {
|
||||||
|
// result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
|
||||||
|
//}
|
||||||
|
|
||||||
|
for (var i = 1; i < fiArgs.size(); i++) {
|
||||||
|
var rh = rhsArgs.get(i);
|
||||||
|
var lh = fiArgs.get(i);
|
||||||
|
|
||||||
|
//if (rh instanceof SuperType) {
|
||||||
|
result.add(new UnifyPair(rh, lh, PairOperator.SMALLER));
|
||||||
|
//} else if (rh instanceof ExtendsType) {
|
||||||
|
// return Optional.empty();
|
||||||
|
//} else {
|
||||||
|
// result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
if(!(lhsType instanceof PlaceholderType))
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FunNType funNRhsType = (FunNType) rhsType;
|
FunNType funNRhsType = (FunNType) rhsType;
|
||||||
|
|
||||||
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
||||||
@@ -1018,6 +1068,121 @@ public class RuleSet implements IRuleSet{
|
|||||||
return Optional.of(result);
|
return Optional.of(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Set<UnifyPair>> reduceFIFunN(UnifyPair pair, IFiniteClosure fc) {
|
||||||
|
if(pair.getPairOp() != PairOperator.EQUALSDOT)
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
UnifyType lhsType = pair.getLhsType();
|
||||||
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
|
||||||
|
if(!(rhsType instanceof FunNType))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
/* muss nach angepasst werden */
|
||||||
|
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
|
||||||
|
if (lhsType instanceof ReferenceType) {
|
||||||
|
UnifyType typeFI = pair.getLhsType();
|
||||||
|
|
||||||
|
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
|
||||||
|
if(!opt.isPresent())
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||||
|
var retType = fiArgs.getFirst();
|
||||||
|
var rhsArgs = intf.getFunctionalInterfaceTypeArguments(rhsType);
|
||||||
|
var rhsRet = rhsArgs.getFirst();
|
||||||
|
|
||||||
|
Set<UnifyPair> result = new HashSet<>();
|
||||||
|
//if (retType instanceof ExtendsType) {
|
||||||
|
result.add(new UnifyPair(retType, rhsRet, PairOperator.EQUALSDOT));
|
||||||
|
//} else if (retType instanceof SuperType) {
|
||||||
|
// return Optional.empty();
|
||||||
|
//} else {
|
||||||
|
// result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
|
||||||
|
//}
|
||||||
|
|
||||||
|
for (var i = 1; i < fiArgs.size(); i++) {
|
||||||
|
var rh = rhsArgs.get(i);
|
||||||
|
var lh = fiArgs.get(i);
|
||||||
|
|
||||||
|
//if (rh instanceof SuperType) {
|
||||||
|
result.add(new UnifyPair(rh, lh, PairOperator.EQUALSDOT));
|
||||||
|
//} else if (rh instanceof ExtendsType) {
|
||||||
|
// return Optional.empty();
|
||||||
|
//} else {
|
||||||
|
// result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Set<UnifyPair>> reduceFunNFi(UnifyPair pair, IFiniteClosure fc) {
|
||||||
|
if(pair.getPairOp() != PairOperator.EQUALSDOT)
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
UnifyType lhsType = pair.getLhsType();
|
||||||
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
|
||||||
|
if(!(lhsType instanceof FunNType))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
|
||||||
|
if (rhsType instanceof ReferenceType) {
|
||||||
|
UnifyType typeFI = pair.getRhsType();
|
||||||
|
|
||||||
|
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
|
||||||
|
if(!opt.isPresent())
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||||
|
var retType = fiArgs.getFirst();
|
||||||
|
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
|
||||||
|
var lhsRet = lhsArgs.getFirst();
|
||||||
|
|
||||||
|
Set<UnifyPair> result = new HashSet<>();
|
||||||
|
//if (retType instanceof ExtendsType) {
|
||||||
|
// result.add(new UnifyPair(lhsRet, retType, PairOperator.SMALLERDOTWC));
|
||||||
|
//} else if (retType instanceof SuperType) {
|
||||||
|
// return Optional.empty();
|
||||||
|
//} else {
|
||||||
|
result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
|
||||||
|
//}
|
||||||
|
|
||||||
|
for (var i = 1; i < fiArgs.size(); i++) {
|
||||||
|
var lh = lhsArgs.get(i);
|
||||||
|
var rh = fiArgs.get(i);
|
||||||
|
|
||||||
|
//if (rh instanceof SuperType) {
|
||||||
|
// result.add(new UnifyPair(lh, rh, PairOperator.SMALLERDOTWC));
|
||||||
|
//} else if (rh instanceof ExtendsType) {
|
||||||
|
// return Optional.empty();
|
||||||
|
//} else {
|
||||||
|
result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UnifyPair> reduceTph(UnifyPair pair) {
|
public Optional<UnifyPair> reduceTph(UnifyPair pair) {
|
||||||
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
||||||
@@ -1025,7 +1190,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
UnifyType rhsType = pair.getRhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType))
|
if(!(lhsType instanceof PlaceholderType) || (!(rhsType instanceof ReferenceType) && !(rhsType instanceof FunNType)))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||||
|
|||||||
@@ -1239,7 +1239,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
|||||||
// FunN Rules
|
// FunN Rules
|
||||||
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
|
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
|
||||||
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair, fc);
|
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair, fc);
|
||||||
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair);
|
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair, fc);
|
||||||
|
|
||||||
// One of the rules has been applied
|
// One of the rules has been applied
|
||||||
if (optSet.isPresent()) {
|
if (optSet.isPresent()) {
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public class UnifyResultModel {
|
|||||||
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet, UnifyContext context) {
|
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet, UnifyContext context) {
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet(context.placeholderRegistry()).subst(x.stream().map(y -> {
|
Optional<Set<UnifyPair>> res = new RuleSet(context.placeholderRegistry()).subst(x.stream().map(y -> {
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC)
|
||||||
|
y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ public interface IRuleSet {
|
|||||||
*/
|
*/
|
||||||
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair);
|
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair);
|
||||||
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair, IFiniteClosure fc);
|
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair, IFiniteClosure fc);
|
||||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair);
|
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc);
|
||||||
|
public Optional<Set<UnifyPair>> reduceFIFunN(UnifyPair pair, IFiniteClosure fc);
|
||||||
|
public Optional<Set<UnifyPair>> reduceFunNFi(UnifyPair pair, IFiniteClosure fc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the erase1-Rule applies to the pair.
|
* Checks whether the erase1-Rule applies to the pair.
|
||||||
|
|||||||
@@ -685,6 +685,7 @@ public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-1
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> getAncestors(UnifyType t) {
|
public Set<UnifyType> getAncestors(UnifyType t) {
|
||||||
if (!inheritanceGraph.containsKey(t))
|
if (!inheritanceGraph.containsKey(t))
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||||
|
|
||||||
public class AllgemeinTest {
|
public class AllgemeinTest {
|
||||||
|
|
||||||
@@ -29,6 +31,7 @@ public class AllgemeinTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
ConsoleInterface.logLevel = LogLevel.DEBUG;
|
||||||
//String className = "GenTest";
|
//String className = "GenTest";
|
||||||
//String className = "Overloading_Generics";
|
//String className = "Overloading_Generics";
|
||||||
//String className = "Generics";
|
//String className = "Generics";
|
||||||
@@ -55,6 +58,7 @@ public class AllgemeinTest {
|
|||||||
//String className = "WildcardCaptureConversionTest";
|
//String className = "WildcardCaptureConversionTest";
|
||||||
//String className = "CaptureConversion";
|
//String className = "CaptureConversion";
|
||||||
//String className = "Pair";
|
//String className = "Pair";
|
||||||
|
//String className = "DublicateWildcard";
|
||||||
//String className = "UseWildcardPair";
|
//String className = "UseWildcardPair";
|
||||||
//String className = "Assign";
|
//String className = "Assign";
|
||||||
//String className = "StreamTest";
|
//String className = "StreamTest";
|
||||||
@@ -63,11 +67,14 @@ public class AllgemeinTest {
|
|||||||
//String className = "Cycle";
|
//String className = "Cycle";
|
||||||
//String className = "TripleTest";
|
//String className = "TripleTest";
|
||||||
//String className = "WildcardList";
|
//String className = "WildcardList";
|
||||||
String className = "List";
|
//String className = "List";
|
||||||
//String className = "Box";
|
//String className = "Box";
|
||||||
//String className = "GenBox";
|
//String className = "GenBox";
|
||||||
//String className = "InnerInf";
|
//String className = "InnerInf";
|
||||||
//String className = "Foo";
|
//String className = "Foo";
|
||||||
|
//String className = "Kombinatoren_failure";
|
||||||
|
String className = "Kombinatoren_After_Lazy";
|
||||||
|
//String className = "Parser";
|
||||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
||||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
@@ -76,7 +83,7 @@ public class AllgemeinTest {
|
|||||||
///*
|
///*
|
||||||
compiler = new JavaTXCompiler(
|
compiler = new JavaTXCompiler(
|
||||||
Lists.newArrayList(new File(path)),
|
Lists.newArrayList(new File(path)),
|
||||||
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/")),
|
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/AllgemeinTest/")),
|
||||||
new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/"), true);
|
new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/"), true);
|
||||||
//*/
|
//*/
|
||||||
compiler.generateBytecode();
|
compiler.generateBytecode();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.ConsoleInterface;
|
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||||
import de.dhbwstuttgart.util.Logger;
|
import de.dhbwstuttgart.util.Logger;
|
||||||
|
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -993,6 +995,7 @@ public class TestComplete {
|
|||||||
System.out.println(zip.invoke(instance, list1, list2));
|
System.out.println(zip.invoke(instance, list1, list2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled("Invalid file, check this later")
|
||||||
@Test
|
@Test
|
||||||
public void testPatternMatchingZipJava() throws Exception {
|
public void testPatternMatchingZipJava() throws Exception {
|
||||||
var classFiles = generateClassFiles(createClassLoader(), false, "PatternMatchingJava.jav", "PatternMatchingJava2.jav");
|
var classFiles = generateClassFiles(createClassLoader(), false, "PatternMatchingJava.jav", "PatternMatchingJava2.jav");
|
||||||
@@ -1416,6 +1419,7 @@ public class TestComplete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Disabled("too slow")
|
||||||
public void testBug325() throws Exception {
|
public void testBug325() throws Exception {
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "Bug325.jav");
|
var classFiles = generateClassFiles(createClassLoader(), "Bug325.jav");
|
||||||
var clazz = classFiles.get("Bug325");
|
var clazz = classFiles.get("Bug325");
|
||||||
|
|||||||
Reference in New Issue
Block a user