Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea3ce98530 | |||
| bcd0c28038 | |||
| 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.Object;
|
||||
|
||||
class Pair<U, T> {
|
||||
U a;
|
||||
T b;
|
||||
import java.util.List;
|
||||
|
||||
make(x) {
|
||||
var ret = new Pair<>();
|
||||
ret.a = x.elementAt(0);
|
||||
ret.b = x.elementAt(1);
|
||||
return ret;
|
||||
class Pair<T, U> {
|
||||
T a;
|
||||
U b;
|
||||
|
||||
public Pair() { }
|
||||
public Pair(T a, U b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
|
||||
eq(a, b) {
|
||||
b = a;
|
||||
return a == b;
|
||||
public T fst () {
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
compare( p) {
|
||||
return eq(p.a, p.b);
|
||||
//return p.a == p.b;
|
||||
public U snd () {
|
||||
return 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))
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,9 +1,10 @@
|
||||
import java.lang.System;
|
||||
import java.lang.String;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Object;
|
||||
|
||||
public class HelloWorld {
|
||||
public static hello() {
|
||||
System.out.println("Hello World!");
|
||||
System.out.println((Object)"Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import de.dhbwstuttgart.bytecode.Codegen;
|
||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
@@ -103,6 +105,7 @@ public class JavaTXCompiler {
|
||||
public DirectoryClassLoader getClassLoader() {
|
||||
return classLoader;
|
||||
}
|
||||
public final List<CompilerWarning> generatedWarnings = new ArrayList<>();
|
||||
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Collections.singletonList(sourceFile), List.of(), new File("."), ConsoleInterface.inferTogether);
|
||||
@@ -131,6 +134,18 @@ public class JavaTXCompiler {
|
||||
// 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 WarningsException(generatedWarnings.size() + " warnings in code, aborting!", this.generatedWarnings);
|
||||
}
|
||||
}
|
||||
|
||||
private List<SourceFileContext> generateSources(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
// TODO This should maybe be moved elsewhere
|
||||
var treeList = new ArrayList<SourceFileContext>(sources.size());
|
||||
@@ -605,7 +620,13 @@ public class JavaTXCompiler {
|
||||
urm.addUnifyResultListener(li);
|
||||
TypeUnify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, context);
|
||||
generateBytecode(sf, li.getResults());
|
||||
return new LanguageServerTransferObject(li.getResults(), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||
List<CompilerWarning> warnings = List.of();
|
||||
try {
|
||||
checkWarnings();
|
||||
} catch (WarningsException e) {
|
||||
warnings = e.compilerWarnings;
|
||||
}
|
||||
return new LanguageServerTransferObject(sf, ASTTypePrinter.print(sf), generatedGenerics, warnings);
|
||||
}
|
||||
/* UnifyResultModel End */
|
||||
else {
|
||||
@@ -627,7 +648,13 @@ public class JavaTXCompiler {
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
generateBytecode(sf, results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons), context.placeholderRegistry())))).collect(Collectors.toList()));
|
||||
return new LanguageServerTransferObject(results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons), context.placeholderRegistry())))).collect(Collectors.toList()), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||
List<CompilerWarning> warnings = List.of();
|
||||
try {
|
||||
checkWarnings();
|
||||
} catch (WarningsException e) {
|
||||
warnings = e.compilerWarnings;
|
||||
}
|
||||
return new LanguageServerTransferObject(sf, ASTTypePrinter.print(sf), generatedGenerics, warnings);
|
||||
}
|
||||
|
||||
|
||||
@@ -718,8 +745,9 @@ public class JavaTXCompiler {
|
||||
var sf = sourceFiles.get(file);
|
||||
if (sf.isGenerated()) continue;
|
||||
var classes = generateBytecode(sf, typeinferenceResult);
|
||||
checkWarnings();
|
||||
sf.setGenerated();
|
||||
writeClassFile(classes, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
||||
writeClassFile(classes, file);
|
||||
}
|
||||
} else {
|
||||
var treeList = generateSources(sources);
|
||||
@@ -730,8 +758,9 @@ public class JavaTXCompiler {
|
||||
var sf = sourceFiles.get(file);
|
||||
if (sf.isGenerated()) continue;
|
||||
var classes = generateBytecode(file);
|
||||
checkWarnings();
|
||||
sf.setGenerated();
|
||||
writeClassFile(classes, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
||||
writeClassFile(classes, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -849,6 +878,7 @@ public class JavaTXCompiler {
|
||||
}
|
||||
|
||||
public synchronized Map<JavaClassName, byte[]> generateBytecode(SourceFile sf, List<ResultSet> typeInferenceResult) {
|
||||
this.generatedWarnings.clear();
|
||||
var converter = new ASTToTargetAST(this, typeInferenceResult, sf, classLoader);
|
||||
var generatedClasses = new HashMap<JavaClassName, byte[]>();
|
||||
for (var clazz : sf.getClasses()) {
|
||||
@@ -866,6 +896,10 @@ public class JavaTXCompiler {
|
||||
return generatedClasses;
|
||||
}
|
||||
|
||||
public void writeClassFile(Map<JavaClassName, byte[]> classFiles, File file) throws IOException {
|
||||
writeClassFile(classFiles, outputPath == null ? file.getParentFile() : outputPath, outputPath == null);
|
||||
}
|
||||
|
||||
public synchronized void writeClassFile(Map<JavaClassName, byte[]> classFiles, File path, boolean preserveHierarchy) throws IOException {
|
||||
FileOutputStream output;
|
||||
for (JavaClassName name : classFiles.keySet()) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.dhbwstuttgart.exceptions;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class CompilerWarning extends RuntimeException {
|
||||
private final Token offset;
|
||||
|
||||
public CompilerWarning(Token offset, String message) {
|
||||
super(message);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Token getOffset() {
|
||||
return this.offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.dhbwstuttgart.exceptions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class WarningsException extends RuntimeException {
|
||||
|
||||
public final List<CompilerWarning> compilerWarnings;
|
||||
|
||||
public WarningsException(String message, List<CompilerWarning> warnings) {
|
||||
super(message);
|
||||
this.compilerWarnings = Collections.unmodifiableList(warnings);
|
||||
}
|
||||
}
|
||||
+15
-4
@@ -4,6 +4,8 @@ package de.dhbwstuttgart.languageServerInterface;
|
||||
import de.dhbwstuttgart.bytecode.Codegen;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
@@ -31,7 +33,7 @@ import java.util.stream.Stream;
|
||||
public class LanguageServerInterface {
|
||||
|
||||
|
||||
public LanguageServerTransferObject getResultSetAndAbastractSyntax(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
NameGenerator.resetTo(resetNamesTo);
|
||||
return getResultSetAndAbstractSyntax(path);
|
||||
|
||||
@@ -57,13 +59,22 @@ public class LanguageServerInterface {
|
||||
var path = Path.of(uri);
|
||||
var file = path.toFile();
|
||||
Files.createDirectories(path.getParent().resolve("out"));
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile(), false);
|
||||
compiler.generateBytecode();
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile(), true);
|
||||
compiler.parseAll();
|
||||
|
||||
List<CompilerWarning> warnings = List.of();
|
||||
var parsedSource = compiler.sourceFiles.get(file);
|
||||
var tiResults = compiler.typeInference(file);
|
||||
var classFiles = compiler.generateBytecode(parsedSource, tiResults);
|
||||
|
||||
return new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
||||
try {
|
||||
compiler.checkWarnings();
|
||||
compiler.writeClassFile(classFiles, file);
|
||||
} catch(WarningsException e) {
|
||||
warnings = e.compilerWarnings;
|
||||
}
|
||||
|
||||
return new LanguageServerTransferObject(parsedSource, "", compiler.getGeneratedGenerics(), warnings);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
+5
-5
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.languageServerInterface.model;
|
||||
|
||||
|
||||
|
||||
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
@@ -11,21 +12,20 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LanguageServerTransferObject {
|
||||
List<ResultSet> resultSets;
|
||||
SourceFile Ast;
|
||||
String printedAst;
|
||||
Map<SourceFile, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
||||
List<CompilerWarning> warnings;
|
||||
|
||||
|
||||
public LanguageServerTransferObject(List<ResultSet> resultSets, SourceFile Ast, String printedAst, Map<SourceFile, List<GenericsResult>> generatedGenerics) {
|
||||
this.resultSets = resultSets;
|
||||
public LanguageServerTransferObject(SourceFile Ast, String printedAst, Map<SourceFile, List<GenericsResult>> generatedGenerics, List<CompilerWarning> warnings) {
|
||||
this.Ast = Ast;
|
||||
this.printedAst = printedAst;
|
||||
this.generatedGenerics = generatedGenerics;
|
||||
this.warnings = warnings;
|
||||
}
|
||||
|
||||
public List<ResultSet> getResultSets() {return resultSets;}
|
||||
public SourceFile getAst() {return Ast;}
|
||||
public String getPrintedAst() {return printedAst;}
|
||||
public Map<SourceFile, List<GenericsResult>> getGeneratedGenerics() {return generatedGenerics;}
|
||||
public List<CompilerWarning> getWarnings() { return warnings; };
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
@@ -20,9 +21,8 @@ import de.dhbwstuttgart.target.tree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.result.*;
|
||||
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
||||
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.stream.Collectors;
|
||||
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 List<Generics> all;
|
||||
//public Generics generics;
|
||||
//public List<Generics> currentMethodOverloads;
|
||||
|
||||
final Map<ClassOrInterface, Set<GenericTypeVar>> userDefinedGenerics = 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;
|
||||
|
||||
public final JavaTXCompiler compiler;
|
||||
@@ -209,7 +214,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
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 ua = toUnifyType(a);
|
||||
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) {
|
||||
System.out.println(m);
|
||||
Target.logger.info(m);
|
||||
}
|
||||
|
||||
// Algorithm
|
||||
@@ -326,22 +331,22 @@ public class ASTToTargetAST {
|
||||
var u_opt = unify(m, m1);
|
||||
if (u_opt.isPresent()) {
|
||||
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);
|
||||
R.remove(m);
|
||||
R.remove(m1);
|
||||
R.add(u);
|
||||
a.add(u);
|
||||
} /*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) {
|
||||
System.out.println(mg.methods.size() + " " + mg);
|
||||
Target.logger.info(mg.methods.size() + " " + mg);
|
||||
}
|
||||
|
||||
return R;
|
||||
@@ -395,6 +400,32 @@ public class ASTToTargetAST {
|
||||
var bridge = generateBridgeMethod(input, genMethods);
|
||||
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();
|
||||
|
||||
TargetMethod staticConstructor = null;
|
||||
@@ -460,6 +491,7 @@ public class ASTToTargetAST {
|
||||
List<TargetConstructor> result = new ArrayList<>();
|
||||
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
||||
this.currentMethod = input;
|
||||
this.usedTPHsOfMethods.put(input, new HashSet<>());
|
||||
|
||||
for (var s : all) {
|
||||
generics = s;
|
||||
@@ -568,7 +600,7 @@ public class ASTToTargetAST {
|
||||
var body = new TargetBlock(List.of(generateCall(method, params, classType)));
|
||||
cases.add(new TargetSwitch.Case(List.of(lastPattern), body));
|
||||
} 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 body = new TargetBlock(List.of(caseBody));
|
||||
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
|
||||
var intersection = new HashSet<>(cla.getSuperInterfaces());
|
||||
intersection.retainAll(clb.getSuperInterfaces());
|
||||
if (intersection.isEmpty()) return Optional.empty();
|
||||
|
||||
var intfclass = compiler.getClass(intersection.iterator().next().getName());
|
||||
// We need to map the generics
|
||||
@@ -636,7 +669,7 @@ public class ASTToTargetAST {
|
||||
|
||||
var ta = pa.pattern().type();
|
||||
var tb = pb.pattern().type();
|
||||
//System.out.println(ta + " " + tb);
|
||||
//Target.logger.info(ta + " " + tb);
|
||||
|
||||
if (Objects.equals(ta, tb)) continue;
|
||||
var common = commonSealedInterface(ta, tb);
|
||||
@@ -727,7 +760,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
}
|
||||
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();
|
||||
@@ -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 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);
|
||||
return res;
|
||||
}
|
||||
@@ -792,7 +825,8 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -810,9 +844,21 @@ 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);
|
||||
if (!Objects.equals(left, right)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Set<MethodWithTphs> convert(ClassOrInterface currentClass, Method method) {
|
||||
Set<MethodWithTphs> result = new HashSet<>();
|
||||
this.currentMethod = method;
|
||||
usedTPHsOfMethods.put(method, new HashSet<>());
|
||||
|
||||
List<Signature> signatures = new ArrayList<>();
|
||||
for (var generics : all) {
|
||||
@@ -836,14 +882,29 @@ public class ASTToTargetAST {
|
||||
var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method);
|
||||
|
||||
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));
|
||||
|
||||
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) {
|
||||
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;
|
||||
@@ -970,6 +1031,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
public TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, IGenerics generics) {
|
||||
if (currentMethod != null && input instanceof TypePlaceholder tph) addTPHToMethod(tph);
|
||||
return convert(input, generics, compiler);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.stream.Stream;
|
||||
public abstract class GenerateGenerics implements IGenerics {
|
||||
|
||||
private final JavaTXCompiler compiler;
|
||||
private final ResultSet constraints;
|
||||
|
||||
public class TPH {
|
||||
private final TypePlaceholder wrap;
|
||||
@@ -129,7 +130,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
||||
final Map<Method, Set<Pair>> computedGenericsOfMethods = 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 Set<PairLT> simplifiedConstraints = new HashSet<>();
|
||||
@@ -138,6 +139,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
||||
|
||||
GenerateGenerics(JavaTXCompiler compiler, ResultSet constraints) {
|
||||
this.compiler = compiler;
|
||||
this.constraints = constraints;
|
||||
for (var constraint : constraints.results) {
|
||||
if (constraint instanceof PairTPHsmallerTPH p) {
|
||||
Target.logger.info(p.left + " " + p.left.getVariance());
|
||||
@@ -583,7 +585,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
||||
referenced.addAll(typeVariablesOfClass);
|
||||
|
||||
generics(owner, method, result, referenced);
|
||||
usedTPHsOfMethods.put(method, usedTphs);
|
||||
usedTPHsOfMethodSignatures.put(method, usedTphs);
|
||||
|
||||
normalize(result, classGenerics, usedTphs);
|
||||
|
||||
@@ -782,7 +784,7 @@ public abstract class GenerateGenerics implements IGenerics {
|
||||
}
|
||||
doIterationForMethods(classOrInterface);
|
||||
for (var method : classOrInterface.getMethods()) {
|
||||
var usedTPHs = usedTPHsOfMethods.get(method);
|
||||
var usedTPHs = usedTPHsOfMethodSignatures.get(method);
|
||||
if (usedTPHs != null)
|
||||
referenced.addAll(usedTPHs);
|
||||
}
|
||||
@@ -981,6 +983,11 @@ public abstract class GenerateGenerics implements IGenerics {
|
||||
} while (foundInfima);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getResultSet() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypePlaceholder getEqualType(TypePlaceholder tph) {
|
||||
return this.equality.getOrDefault(tph, tph);
|
||||
|
||||
@@ -15,6 +15,10 @@ public class GenericsResult {
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
public IGenerics getGenerics() {
|
||||
return this.generics;
|
||||
}
|
||||
|
||||
public GenericsResultSet get(ClassOrInterface clazz) {
|
||||
var generics = this.generics.generics(clazz);
|
||||
return new GenericsResultSet(generics, this.generics);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package de.dhbwstuttgart.target.generate;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -18,7 +20,12 @@ public class GenericsResultSet extends AbstractSet<GenerateGenerics.Pair> {
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
public IGenerics getGenerics() {
|
||||
return this.generics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Iterator<GenerateGenerics.Pair> iterator() {
|
||||
return backing.iterator();
|
||||
}
|
||||
@@ -28,17 +35,8 @@ public class GenericsResultSet extends AbstractSet<GenerateGenerics.Pair> {
|
||||
return backing.size();
|
||||
}
|
||||
|
||||
public Optional<ResultPair<?, ?>> getResultPairFor(TypePlaceholder tph) {
|
||||
public Optional<GenerateGenerics.Pair> getResultPairFor(TypePlaceholder tph) {
|
||||
var tph2 = generics.getEqualType(tph);
|
||||
return this.stream().filter(pair -> {
|
||||
return pair.left.resolve().equals(tph2);
|
||||
}).findFirst().map(pair -> {
|
||||
ResultPair<?, ?> res = null;
|
||||
if (pair instanceof GenerateGenerics.PairLT lt)
|
||||
res = new PairTPHsmallerTPH(lt.left.resolve(), lt.right.resolve());
|
||||
else if (pair instanceof GenerateGenerics.PairEQ eq)
|
||||
res = new PairTPHequalRefTypeOrWildcardType(eq.left.resolve(), eq.right);
|
||||
return res;
|
||||
});
|
||||
return this.stream().filter(pair -> pair.left.resolve().equals(tph2)).findFirst();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -19,4 +20,6 @@ public interface IGenerics {
|
||||
TypePlaceholder getEqualType(TypePlaceholder tph);
|
||||
|
||||
TargetType getTargetType(RefTypeOrTPHOrWildcardOrGeneric in);
|
||||
|
||||
ResultSet getResultSet();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetGenericType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -57,4 +58,9 @@ public class OverlayGenerics implements IGenerics {
|
||||
}
|
||||
return ASTToTargetAST.convert(in, this, converter.compiler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getResultSet() {
|
||||
return wrapped.getResultSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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.TargetPattern;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
@@ -9,7 +11,11 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
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 String getSignature() {
|
||||
return TargetMethod.getSignature(generics, parameters, returnType);
|
||||
|
||||
@@ -187,14 +187,14 @@ class TypeToInsertString implements ResultSetVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
ResultPair<?, ?> resultPair = null;
|
||||
GenerateGenerics.Pair resultPair = null;
|
||||
if (constraints != null)
|
||||
resultPair = constraints.getResultPairFor(typePlaceholder).orElse(null);
|
||||
if (resultPair == null)
|
||||
resultPair = classConstraints.getResultPairFor(typePlaceholder).orElse(null);
|
||||
|
||||
if (resultPair != null)
|
||||
insert += ((TypePlaceholder)resultPair.getLeft()).getName();
|
||||
insert += resultPair.left.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -736,12 +736,12 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
|
||||
// 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)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -755,7 +755,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
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.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 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.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 retType = fiArgs.getFirst();
|
||||
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
|
||||
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType); //FALSCHRUM????
|
||||
var lhsRet = lhsArgs.getFirst();
|
||||
|
||||
Set<UnifyPair> result = new HashSet<>();
|
||||
@@ -972,16 +972,66 @@ public class RuleSet implements IRuleSet{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) {
|
||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc) {
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOT)
|
||||
return Optional.empty();
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
||||
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
|
||||
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.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;
|
||||
|
||||
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
||||
@@ -1018,6 +1068,121 @@ public class RuleSet implements IRuleSet{
|
||||
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
|
||||
public Optional<UnifyPair> reduceTph(UnifyPair pair) {
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
||||
@@ -1025,7 +1190,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
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.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
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
|
||||
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
|
||||
if (optSet.isPresent()) {
|
||||
|
||||
@@ -39,7 +39,8 @@ public class UnifyResultModel {
|
||||
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet, UnifyContext context) {
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
||||
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
|
||||
}).collect(Collectors.toCollection(HashSet::new)));
|
||||
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>> 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.
|
||||
|
||||
@@ -685,6 +685,7 @@ public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-1
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<UnifyType> getAncestors(UnifyType t) {
|
||||
if (!inheritanceGraph.containsKey(t))
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||
|
||||
public class AllgemeinTest {
|
||||
|
||||
@@ -29,6 +31,7 @@ public class AllgemeinTest {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
ConsoleInterface.logLevel = LogLevel.DEBUG;
|
||||
//String className = "GenTest";
|
||||
//String className = "Overloading_Generics";
|
||||
//String className = "Generics";
|
||||
@@ -55,6 +58,7 @@ public class AllgemeinTest {
|
||||
//String className = "WildcardCaptureConversionTest";
|
||||
//String className = "CaptureConversion";
|
||||
//String className = "Pair";
|
||||
//String className = "DublicateWildcard";
|
||||
//String className = "UseWildcardPair";
|
||||
//String className = "Assign";
|
||||
//String className = "StreamTest";
|
||||
@@ -63,11 +67,14 @@ public class AllgemeinTest {
|
||||
//String className = "Cycle";
|
||||
//String className = "TripleTest";
|
||||
//String className = "WildcardList";
|
||||
String className = "List";
|
||||
//String className = "List";
|
||||
//String className = "Box";
|
||||
//String className = "GenBox";
|
||||
//String className = "InnerInf";
|
||||
//String className = "Foo";
|
||||
//String className = "Kombinatoren_failure";
|
||||
String className = "Kombinatoren_After_Lazy";
|
||||
//String className = "Parser";
|
||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||
@@ -76,7 +83,7 @@ public class AllgemeinTest {
|
||||
///*
|
||||
compiler = new JavaTXCompiler(
|
||||
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);
|
||||
//*/
|
||||
compiler.generateBytecode();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -974,7 +976,6 @@ public class TestComplete {
|
||||
|
||||
@Test
|
||||
public void testPatternMatchingZip() throws Exception {
|
||||
//ConsoleInterface.logLevel = Logger.LogLevel.DEBUG;
|
||||
var classFiles = generateClassFiles(createClassLoader(), "PatternMatching.jav");
|
||||
var clazz = classFiles.get("PatternMatching");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
@@ -993,6 +994,7 @@ public class TestComplete {
|
||||
System.out.println(zip.invoke(instance, list1, list2));
|
||||
}
|
||||
|
||||
@Disabled("Invalid file, check this later")
|
||||
@Test
|
||||
public void testPatternMatchingZipJava() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), false, "PatternMatchingJava.jav", "PatternMatchingJava2.jav");
|
||||
@@ -1416,6 +1418,7 @@ public class TestComplete {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("too slow")
|
||||
public void testBug325() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug325.jav");
|
||||
var clazz = classFiles.get("Bug325");
|
||||
|
||||
Reference in New Issue
Block a user