forked from i21017/JavaCompilerCore
Compare commits
8 Commits
58c3947167
...
parseSigna
Author | SHA1 | Date | |
---|---|---|---|
|
904bdca2f4 | ||
|
af4db1817a | ||
|
d945947362 | ||
|
a0c25a517d | ||
|
c35577f948 | ||
|
fc7844c6a4 | ||
|
4078239815 | ||
|
39bde24df7 |
3
Makefile
3
Makefile
@@ -1,3 +0,0 @@
|
||||
NoOptParallel:
|
||||
mvn -DskipTests package
|
||||
cp target/JavaTXcompiler-0.1-jar-with-dependencies.jar target/JavaTXcompiler-0.1-jar-with-dependencies_NoOptParallel.jar
|
21
pom.xml
21
pom.xml
@@ -44,23 +44,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<artifactId>asm</artifactId>
|
||||
<version>7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
<version>1.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.17.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -71,8 +54,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
<source>19</source>
|
||||
<target>19</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
//import java.util.Vector;
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Float;
|
||||
//import java.lang.Byte;
|
||||
@@ -6,11 +6,21 @@ import java.lang.Float;
|
||||
|
||||
public class Scalar extends Vector<Integer> {
|
||||
|
||||
Scalar(v) {
|
||||
Integer i;
|
||||
i = 0;
|
||||
while(i < v.size()) {
|
||||
this.add(v.elementAt(i));
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
mul(v) {
|
||||
var ret = 0;
|
||||
var i = 0;
|
||||
while(i < size()) {
|
||||
ret = ret + this.elementAt(i) * v.elementAt(i);
|
||||
i = i+1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
11
resources/bytecode/javFiles/TXGenerics.jav
Normal file
11
resources/bytecode/javFiles/TXGenerics.jav
Normal file
@@ -0,0 +1,11 @@
|
||||
import java.lang.String;
|
||||
|
||||
class TXGenerics {
|
||||
a;
|
||||
b;
|
||||
|
||||
test() {
|
||||
var c = new Cycle();
|
||||
c.m(a, b);
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ public class TestContraVariant {
|
||||
x = y;
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
main(x) {
|
||||
return m(x);
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
public class TestTwoCalls {
|
||||
|
||||
// <O> O -> O
|
||||
id(b) {
|
||||
var c = b;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// <T, S> (S, T) -> T
|
||||
main(x,y) {
|
||||
id(x);
|
||||
return id(y);
|
||||
|
2
server-tests/.gitignore
vendored
2
server-tests/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
out
|
||||
outputs
|
@@ -1,13 +0,0 @@
|
||||
|
||||
class Apply { }
|
||||
|
||||
public class Lambda {
|
||||
|
||||
m () {
|
||||
var lam1 = (x) -> {
|
||||
return x;
|
||||
};
|
||||
return lam1.apply(new Apply());
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +0,0 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
|
||||
class Matrix extends Vector<Vector<Integer>> {
|
||||
Integer mul1(Integer x, Integer y) { return x;}
|
||||
Integer add1(Integer x, Integer y) { return x;}
|
||||
mul(m) {
|
||||
var ret = new Matrix();
|
||||
var i = 0;
|
||||
while(i < size()) {
|
||||
var v1 = this.elementAt(i);
|
||||
var v2 = new Vector<Integer>();
|
||||
var j = 0;
|
||||
while(j < v1.size()) {
|
||||
var erg = 0;
|
||||
var k = 0;
|
||||
while(k < v1.size()) {
|
||||
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
|
||||
//erg = add1(erg, mul1(v1.elementAt(k),
|
||||
// m.elementAt(k).elementAt(j)));
|
||||
k++; }
|
||||
v2.addElement(new Integer(erg));
|
||||
j++; }
|
||||
ret.addElement(v2);
|
||||
i++; }
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
|
||||
class SomeEvenMoreAbstractList<A, B> extends Vector<A> {
|
||||
}
|
||||
|
||||
class SomeAbstractList<A, B> extends SomeEvenMoreAbstractList<A, B> {
|
||||
}
|
||||
|
||||
class SomeList extends SomeAbstractList<Integer, Integer> {
|
||||
|
||||
mul(otherList) {
|
||||
var result = new SomeList();
|
||||
|
||||
var i = 0;
|
||||
while (i < 4) {
|
||||
i++;
|
||||
var a = this.elementAt(i);
|
||||
var b = otherList.elementAt(i);
|
||||
result.addElement(a * b);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# build the compiler if -c is set
|
||||
if [[ "${@,,}" == *"-c"* ]]; then
|
||||
(cd .. && make || exit)
|
||||
fi
|
||||
|
||||
# a very small and short running example
|
||||
# JAV_FILE="Lambda.jav"
|
||||
|
||||
# a medium and average running example
|
||||
JAV_FILE="SomeList.jav"
|
||||
|
||||
# a very large and long running example
|
||||
# JAV_FILE="Matrix.jav"
|
||||
|
||||
|
||||
# remove old generated files and run the compiler
|
||||
rm -rf ./out/client
|
||||
mkdir -p ./out/client \
|
||||
&& java -jar ../target/JavaTXcompiler-0.1-jar-with-dependencies.jar -d ./out/client -us ws://localhost:5000 $JAV_FILE
|
@@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# build the compiler if -c is set
|
||||
if [[ "${@,,}" == *"-c"* ]]; then
|
||||
(cd .. && make || exit)
|
||||
fi
|
||||
|
||||
# remove old generated files
|
||||
rm -rf ./out/server
|
||||
|
||||
# run the server
|
||||
mkdir -p ./out/server && java -jar ../target/JavaTXcompiler-0.1-jar-with-dependencies.jar -d ./out/server -server 5000
|
@@ -9,14 +9,11 @@ import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
import static de.dhbwstuttgart.target.tree.expression.TargetBinaryOp.*;
|
||||
import static de.dhbwstuttgart.target.tree.expression.TargetLiteral.*;
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class Codegen {
|
||||
private final TargetClass clazz;
|
||||
@@ -1003,7 +1000,7 @@ public class Codegen {
|
||||
private void generateConstructor(TargetConstructor constructor) {
|
||||
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
||||
if (constructor.txGenerics() != null)
|
||||
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(constructor.getTXSignature())));
|
||||
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
||||
|
||||
mv.visitCode();
|
||||
var state = new State(null, mv, 1);
|
||||
@@ -1030,7 +1027,7 @@ public class Codegen {
|
||||
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
||||
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
||||
if (method.txSignature() != null) {
|
||||
mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(method.getTXSignature())));
|
||||
mv.visitAttribute(new JavaTXSignatureAttribute(method.getTXSignature()));
|
||||
}
|
||||
|
||||
System.out.println(method.getDescriptor());
|
||||
@@ -1047,11 +1044,14 @@ public class Codegen {
|
||||
}
|
||||
|
||||
private static String generateSignature(TargetClass clazz, Set<TargetGeneric> generics) {
|
||||
String ret = "<";
|
||||
for (var generic : generics) {
|
||||
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
||||
String ret = "";
|
||||
if (generics.size() > 0) {
|
||||
ret += "<";
|
||||
for (var generic : generics) {
|
||||
ret += generic.name() + ":" + generic.bound().toDescriptor();
|
||||
}
|
||||
ret += ">";
|
||||
}
|
||||
ret += ">";
|
||||
ret += clazz.superType().toDescriptor();
|
||||
|
||||
return ret;
|
||||
@@ -1063,7 +1063,7 @@ public class Codegen {
|
||||
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
||||
);
|
||||
if (clazz.txGenerics() != null)
|
||||
cw.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(generateSignature(clazz, clazz.txGenerics()))));
|
||||
cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics())));
|
||||
|
||||
clazz.fields().forEach(this::generateField);
|
||||
clazz.constructors().forEach(this::generateConstructor);
|
||||
@@ -1072,4 +1072,4 @@ public class Codegen {
|
||||
cw.visitEnd();
|
||||
return cw.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import de.dhbwstuttgart.target.tree.TargetGeneric;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetGenericType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
@@ -119,4 +120,4 @@ public class FunNGenerator {
|
||||
throw new IndexOutOfBoundsException();
|
||||
return list.get(list.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,13 @@ package de.dhbwstuttgart.bytecode;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
public class JavaTXSignatureAttribute extends Attribute {
|
||||
final int signature;
|
||||
public String signature;
|
||||
|
||||
protected JavaTXSignatureAttribute(int signature) {
|
||||
public JavaTXSignatureAttribute() {
|
||||
super("JavaTXSignature");
|
||||
}
|
||||
protected JavaTXSignatureAttribute(String signature) {
|
||||
this();
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
@@ -14,13 +17,14 @@ public class JavaTXSignatureAttribute extends Attribute {
|
||||
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) {
|
||||
var data = new byte[length];
|
||||
System.arraycopy(classReader.b, offset, data, 0, length);
|
||||
return new JavaTXSignatureAttribute(data[0] << 8 | data[1]);
|
||||
var constantPoolOffset = data[0] << 8 | data[1];
|
||||
return new JavaTXSignatureAttribute((String) classReader.readConst(constantPoolOffset, charBuffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) {
|
||||
var data = new ByteVector();
|
||||
data.putShort(this.signature);
|
||||
data.putShort(classWriter.newConst(this.signature));
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package de.dhbwstuttgart.bytecode.constraint;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class TPHConstraint {
|
||||
protected String left;
|
||||
@@ -86,4 +87,4 @@ public class TPHConstraint {
|
||||
return left + " = " + right;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
|
||||
public class ConstraintsWithSameLeftSide {
|
||||
private List<TPHConstraint> constraints;
|
||||
|
||||
@@ -32,4 +32,4 @@ public class ConstraintsWithSameLeftSide {
|
||||
public String toString() {
|
||||
return "[" + constraints.toString() + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* The simplify results of a source file (package)
|
||||
@@ -48,4 +49,4 @@ public class GenericGenratorResultForSourceFile {
|
||||
}
|
||||
return new GenericsGeneratorResultForClass(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,10 @@
|
||||
*/
|
||||
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
*
|
||||
@@ -56,4 +56,4 @@ public class GenericsGeneratorResult {
|
||||
public String toString() {
|
||||
return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
*
|
||||
@@ -79,4 +81,4 @@ public class GenericsGeneratorResultForClass {
|
||||
ret = ret + "\n" + methodsAndTheirConstraints.toString();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,73 +2,43 @@ package de.dhbwstuttgart.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.*;
|
||||
public class ConsoleInterface {
|
||||
private static final String directory = System.getProperty("user.dir");
|
||||
private static final String directory = System.getProperty("user.dir");
|
||||
|
||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||
List<File> input = new ArrayList<>();
|
||||
List<File> classpath = new ArrayList<>();
|
||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||
List<File> input = new ArrayList<>();
|
||||
List<File> classpath = new ArrayList<>();
|
||||
String outputPath = null;
|
||||
int runAsServerWithPort = -1;
|
||||
String unificationServer = null;
|
||||
|
||||
Iterator<String> it = Arrays.asList(args).iterator();
|
||||
if (args.length == 0) {
|
||||
Iterator<String> it = Arrays.asList(args).iterator();
|
||||
if(args.length == 0){
|
||||
System.out.println("No input files given. Get help with --help");
|
||||
System.exit(1);
|
||||
} else if (args.length == 1 && args[0].equals("--help")) {
|
||||
}else if(args.length == 1 && args[0].equals("--help")){
|
||||
System.out.println("Usage: javatx [OPTION]... [FILE]...\n" +
|
||||
"\t-cp\tSet Classpath\n" +
|
||||
"\t-d\tSet destination directory\n" +
|
||||
"\t-s\tRun the compiler in server mode and listen for incoming requests on the given port\n" +
|
||||
"\t-us\tSet the address of a remote server for the unification process"
|
||||
);
|
||||
"\t-d\tSet destination directory");
|
||||
System.exit(1);
|
||||
}
|
||||
while (it.hasNext()) {
|
||||
while(it.hasNext()){
|
||||
String arg = it.next();
|
||||
if (arg.equals("-d")) {
|
||||
if(arg.equals("-d")){
|
||||
outputPath = it.next();
|
||||
}
|
||||
else if (arg.startsWith("-d")) {
|
||||
}else if(arg.startsWith("-d")) {
|
||||
outputPath = arg.substring(2);
|
||||
}
|
||||
else if (arg.equals("-cp") || arg.equals("-classpath")) {
|
||||
}else if(arg.equals("-cp") || arg.equals("-classpath")){
|
||||
String[] cps = it.next().split(":");
|
||||
for (String cp : cps) {
|
||||
for(String cp : cps){
|
||||
classpath.add(new File(cp));
|
||||
}
|
||||
}
|
||||
else if (arg.equals("-s") || arg.equals("-server")) {
|
||||
if (unificationServer != null) {
|
||||
throw new IllegalArgumentException("Cannot run in server-Mode and use unification server at the same time");
|
||||
}
|
||||
runAsServerWithPort = Integer.parseInt(it.next());
|
||||
}
|
||||
else if (arg.equals("-us") || arg.equals("-unification-server")) {
|
||||
if (runAsServerWithPort != -1) {
|
||||
throw new IllegalArgumentException("Cannot run in server-Mode and use unification server at the same time");
|
||||
}
|
||||
unificationServer = it.next();
|
||||
} else {
|
||||
}else{
|
||||
input.add(new File(arg));
|
||||
}
|
||||
}
|
||||
|
||||
if (runAsServerWithPort != -1) {
|
||||
JavaTXServer server = new JavaTXServer(runAsServerWithPort);
|
||||
}
|
||||
else {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath, unificationServer);
|
||||
//compiler.typeInference();
|
||||
compiler.generateBytecode(outputPath);
|
||||
}
|
||||
}
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath);
|
||||
//compiler.typeInference();
|
||||
compiler.generateBytecode(outputPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
import de.dhbwstuttgart.server.SocketServer;
|
||||
|
||||
public class JavaTXServer {
|
||||
|
||||
JavaTXServer(int port) {
|
||||
try {
|
||||
SocketServer socketServer = new SocketServer(port);
|
||||
socketServer.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,22 +1,21 @@
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||
import de.dhbwstuttgart.parser.scope.GatherNames;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||
import de.dhbwstuttgart.parser.scope.GatherNames;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
|
||||
/**
|
||||
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt
|
||||
@@ -107,4 +106,4 @@ public class CompilationEnvironment {
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -33,4 +36,4 @@ public class DirectoryClassLoader extends URLClassLoader implements IByteArrayCl
|
||||
public Class _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError {
|
||||
return defineClass(name, code, i, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
package de.dhbwstuttgart.environment;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.ResourcesScanner;
|
||||
import org.reflections.scanners.SubTypesScanner;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import org.reflections.vfs.SystemDir;
|
||||
|
||||
/**
|
||||
* Hilft beim Durchsuchen von Packages
|
||||
@@ -74,4 +74,4 @@ public class PackageCrawler {
|
||||
}
|
||||
return nameList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,19 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaTXParser {
|
||||
public static Java8Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
|
||||
@@ -29,4 +34,4 @@ public class JavaTXParser {
|
||||
return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
|
||||
public class AssignToLocal extends AssignLeftSide {
|
||||
@@ -16,4 +17,4 @@ public class AssignToLocal extends AssignLeftSide {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,12 +8,13 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class FCGenerator {
|
||||
/**
|
||||
* Baut die FiniteClosure aus availableClasses.
|
||||
@@ -173,4 +174,4 @@ public class FCGenerator {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,12 +5,14 @@ import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr.Operation;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
@@ -974,4 +976,4 @@ public class StatementGenerator {
|
||||
//funNParams, name.getStart());
|
||||
return new LambdaExpression(lambdaType, params, block, expression.getStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,4 +40,4 @@ public class SyntacticSugar {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,10 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import java.lang.ClassNotFoundException;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.parser.scope.GatherNames;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
@@ -10,19 +13,22 @@ import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.sql.Ref;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
//import jdk.internal.dynalink.support.TypeConverterFactory;
|
||||
import org.antlr.v4.runtime.CommonToken;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SyntaxTreeGenerator{
|
||||
private JavaClassRegistry reg;
|
||||
private final GenericsRegistry globalGenerics;
|
||||
@@ -507,4 +513,4 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -2,14 +2,21 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -213,4 +220,4 @@ public class TypeGenerator {
|
||||
if(ctx.classOrInterfaceType() != null)throw new NotImplementedException();
|
||||
return convertTypeName(ctx.Identifier().getText(), ctx.typeArguments(), ctx.getStart(), reg, generics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,17 @@
|
||||
package de.dhbwstuttgart.parser.scope;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.parser.antlr.Java8BaseListener;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GatherNames {
|
||||
|
||||
|
@@ -2,10 +2,7 @@ package de.dhbwstuttgart.parser.scope;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Speichert die Klassen f<>r einen bestimmten Projektscope
|
||||
@@ -49,4 +46,4 @@ public class JavaClassRegistry {
|
||||
public int getNumberOfGenerics(String name) {
|
||||
return existingClasses.get(new JavaClassName(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,133 +0,0 @@
|
||||
package de.dhbwstuttgart.server;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import de.dhbwstuttgart.server.packet.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.enums.ReadyState;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* The Client-side of the websocket
|
||||
*/
|
||||
public class SocketClient extends WebSocketClient {
|
||||
|
||||
// use a latch to wait until the connection is closed by the remote host
|
||||
private final CountDownLatch closeLatch = new CountDownLatch(1);
|
||||
// temporarily: The received unify result packet
|
||||
private UnifyResultPacket unifyResultPacket = null;
|
||||
|
||||
public SocketClient(String url) {
|
||||
super(URI.create(url));
|
||||
// make sure, the url is in a valid format
|
||||
final String regex = "^wss?://(\\w+(\\.\\w+)?)*:(\\d+)$";
|
||||
final Matcher matcher = Pattern.compile(regex).matcher(url);
|
||||
if (!matcher.find()) {
|
||||
throw new RuntimeException("Provided string \"" + url + "\" is not a valid server URL! Use pattern ws(s?)://<host.name>:<port>");
|
||||
}
|
||||
}
|
||||
|
||||
public SocketClient(String host, int port, boolean secure) {
|
||||
super(URI.create(String.format("%s://%s:%d/", secure ? "wss" : "ws", host, port)));
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method for connecting, requesting and waiting for the server to unify.
|
||||
* This is synchronized to prevent multiple webSockets connections at the moment, but it is not called from any
|
||||
* thread except the main thread right now and is not necessary at all, probably. Maybe remove it later
|
||||
*/
|
||||
synchronized public List<ResultSet> execute(
|
||||
IFiniteClosure finiteClosure,
|
||||
ConstraintSet<Pair> constraints,
|
||||
ConstraintSet<UnifyPair> unifyConstraints
|
||||
) throws JsonProcessingException {
|
||||
try {
|
||||
// wait for the connection to be set up
|
||||
this.connectBlocking();
|
||||
// make sure the connection has been established successfully
|
||||
if (this.getReadyState() != ReadyState.OPEN) {
|
||||
throw new RuntimeException("WebSocket Client could not connect to remote host at " + this.uri);
|
||||
}
|
||||
|
||||
// send the unify task request
|
||||
UnifyRequestPacket packet = UnifyRequestPacket.create(finiteClosure, constraints, unifyConstraints);
|
||||
String json = PacketContainer.serialize(packet);
|
||||
this.send(json);
|
||||
|
||||
// block the thread, until the connection is closed by the remote host (usually after sending the results)
|
||||
this.waitUntilClosed();
|
||||
// wait for the connection to fully close
|
||||
this.closeBlocking();
|
||||
} catch (InterruptedException exception) {
|
||||
System.err.println("Interrupted: " + exception);
|
||||
this.notifyAll();
|
||||
}
|
||||
|
||||
// detect error cases, in which no error was thrown, but also no result was sent back from the server
|
||||
if (this.unifyResultPacket == null) {
|
||||
throw new RuntimeException("Did not receive server response but closed connection already");
|
||||
}
|
||||
|
||||
return unifyResultPacket.getResultSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific client-side implementations to handle incomming packets
|
||||
*/
|
||||
protected void handleReceivedPacket(IPacket packet) {
|
||||
if (packet instanceof InvalidPacket) {
|
||||
System.err.println("[socket] " + ((InvalidPacket) packet).error);
|
||||
} else if (packet instanceof MessagePacket) {
|
||||
System.out.println("[socket] " + ((MessagePacket) packet).message);
|
||||
} else if (packet instanceof ErrorPacket) {
|
||||
System.err.println("[socket] " + ((ErrorPacket) packet).error);
|
||||
} else if (packet instanceof UnifyResultPacket) {
|
||||
System.out.println("[socket] Received unify result");
|
||||
unifyResultPacket = (UnifyResultPacket) packet;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
System.out.println("Connected to server with status " + handshakedata.getHttpStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
// System.out.println("received: " + message);
|
||||
IPacket packet = PacketContainer.deserialize(message);
|
||||
this.handleReceivedPacket(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
System.out.println(
|
||||
"Disconnected from server " +
|
||||
"with code " + code + " " +
|
||||
(reason.isEmpty() ? "" : "and reason " + reason + " ") +
|
||||
"(closed by remote: " + remote + ")"
|
||||
);
|
||||
this.closeLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void waitUntilClosed() throws InterruptedException {
|
||||
closeLatch.await();
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.server;
|
||||
|
||||
/**
|
||||
* The data that is associated server-side with any connected client.
|
||||
* This makes it possible to store information that can be mapped to any existing connection.
|
||||
*/
|
||||
public class SocketData {
|
||||
|
||||
public final String id;
|
||||
// used for the timeout of 10 seconds, until an unused open connection is automatically closed
|
||||
public boolean hasSentTask = false;
|
||||
|
||||
public SocketData(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@@ -1,135 +0,0 @@
|
||||
package de.dhbwstuttgart.server;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.*;
|
||||
import de.dhbwstuttgart.typeinference.TypeInference;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SocketServer extends WebSocketServer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SocketServer.class);
|
||||
|
||||
public SocketServer(int port) {
|
||||
super(new InetSocketAddress(port));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
|
||||
System.out.println("New connection: " + webSocket.getResourceDescriptor());
|
||||
webSocket.setAttachment(new SocketData(UUID.randomUUID().toString()));
|
||||
|
||||
try {
|
||||
sendMessage(webSocket, "Welcome to the server!");
|
||||
|
||||
// wait 10 seconds for the client to send a task and close the connection, if nothing has been received until then
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
Runnable task = () -> {
|
||||
if (webSocket.<SocketData>getAttachment().hasSentTask || !webSocket.isOpen()) {
|
||||
return;
|
||||
}
|
||||
sendMessage(webSocket, "No task received after 10 seconds. Closing connection...");
|
||||
webSocket.close();
|
||||
};
|
||||
executor.schedule(task, 10, TimeUnit.SECONDS);
|
||||
executor.shutdown();
|
||||
|
||||
// and finally, when your program wants to exit
|
||||
} catch (Exception e) {
|
||||
log.error("e: ", e);
|
||||
webSocket.close(1, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(WebSocket webSocket, int code, String reason, boolean remote) {
|
||||
System.out.println("Connection closed: " + webSocket.getResourceDescriptor());
|
||||
System.out.println(
|
||||
"Disconnected client " + webSocket.getResourceDescriptor() + " " +
|
||||
"with code " + code + " " +
|
||||
(reason.isEmpty() ? "" : "and reason " + reason + " ") +
|
||||
"(closed by client: " + remote + ")"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocket webSocket, String s) {
|
||||
// System.out.println("Received: " + s.substring(0, 50));
|
||||
IPacket reconstructedPacket = PacketContainer.deserialize(s);
|
||||
this.onPacketReceived(webSocket, reconstructedPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(WebSocket webSocket, Exception e) {
|
||||
webSocket.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
System.out.println("Websocket server started");
|
||||
}
|
||||
|
||||
/**
|
||||
* A shorthand method for sending informational messages to the client
|
||||
*/
|
||||
public void sendMessage(WebSocket webSocket, String text) {
|
||||
try {
|
||||
MessagePacket message = new MessagePacket();
|
||||
message.message = text;
|
||||
webSocket.send(PacketContainer.serialize(message));
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to send message: " + text);
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The server-side implementation on how to handle certain packets when received
|
||||
*/
|
||||
private void onPacketReceived(WebSocket webSocket, IPacket packet) {
|
||||
if (packet instanceof UnifyRequestPacket unifyRequestPacket) {
|
||||
|
||||
// TODO: this static property will be a problem once we send more than one request per server and
|
||||
// should be replaced by a dynamic object property
|
||||
PlaceholderType.EXISTING_PLACEHOLDERS.clear();
|
||||
sendMessage(webSocket, "You requested a unify! Please wait until I calculated everything...");
|
||||
System.out.println("Client " + webSocket.<SocketData>getAttachment().id + " requested a unification. Starting now...");
|
||||
webSocket.<SocketData>getAttachment().hasSentTask = true;
|
||||
|
||||
try {
|
||||
// start the unification algorithm from the received data
|
||||
List<ResultSet> result = TypeInference.executeWithoutContext(
|
||||
unifyRequestPacket.retrieveFiniteClosure(),
|
||||
unifyRequestPacket.retrieveConstraints(),
|
||||
unifyRequestPacket.retrieveUnifyConstraints()
|
||||
);
|
||||
System.out.println("Finished unification for client " + webSocket.<SocketData>getAttachment().id);
|
||||
sendMessage(webSocket, "Unification finished. Found " + result.size() + " result sets");
|
||||
|
||||
if (webSocket.isOpen()) {
|
||||
UnifyResultPacket resultPacket = UnifyResultPacket.create(result);
|
||||
webSocket.send(PacketContainer.serialize(resultPacket));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
log.error("e: ", e);
|
||||
}
|
||||
|
||||
webSocket.close();
|
||||
} else {
|
||||
sendMessage(webSocket, "The package of type " + packet.getClass().getName() + " is not handled by the server!");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
/**
|
||||
* A packet to send simple error messages between the client and the server
|
||||
*/
|
||||
public class ErrorPacket implements IPacket {
|
||||
|
||||
/**
|
||||
* The error endpoint for messages from the server, that should be logged out outputted
|
||||
*/
|
||||
public String error;
|
||||
|
||||
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
/**
|
||||
* The shared interface for all packet of the server connection.
|
||||
* A packet must always:
|
||||
* - Have a default / no-parameter constructor
|
||||
* - Have only serializable public properties (or disable them via jackson annotations)
|
||||
* A packet should have, for easy usage and consisteny:
|
||||
* - a static create() method
|
||||
*/
|
||||
public interface IPacket {
|
||||
|
||||
interface IDataContainer<T> {
|
||||
T toObject();
|
||||
}
|
||||
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
/**
|
||||
* A fallback packet that is generated, if the received json could not be mapped to an existing package
|
||||
*/
|
||||
public class InvalidPacket implements IPacket {
|
||||
|
||||
/**
|
||||
* If available, the error that caused this package to appear
|
||||
*/
|
||||
public String error = "<unknown error>";
|
||||
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
/**
|
||||
* A packet to send simple informational messages between the client and the server
|
||||
*/
|
||||
public class MessagePacket implements IPacket {
|
||||
|
||||
/**
|
||||
* The informational message from the server, that should be logged out outputted
|
||||
*/
|
||||
public String message;
|
||||
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* A wrapper for the packet to ensure correct serialization/deserialization and make it possible to detect the matching
|
||||
* packet type for deserialization.
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PacketContainer {
|
||||
|
||||
// The jackson serializer / deserializer tool
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/*
|
||||
* The available packet types. The one type that is represented in the JSON should always be the ONLY non-null value.
|
||||
* They have to be public (for the moment) to let jackson fill them in while deserializing
|
||||
*/
|
||||
public ErrorPacket errorPacket = null;
|
||||
public MessagePacket messagePacket = null;
|
||||
public InvalidPacket invalidPacket = null;
|
||||
public UnifyRequestPacket unifyRequestPacket = null;
|
||||
public UnifyResultPacket unifyResultPacket = null;
|
||||
|
||||
|
||||
/**
|
||||
* Generate the JSON string for the given packet
|
||||
*
|
||||
* @param packet The packet to serialize
|
||||
* @return The json representation of the packet
|
||||
*/
|
||||
public static String serialize(IPacket packet) throws JsonProcessingException {
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
PacketContainer container = new PacketContainer();
|
||||
|
||||
if (packet instanceof ErrorPacket)
|
||||
container.errorPacket = (ErrorPacket) packet;
|
||||
else if (packet instanceof MessagePacket)
|
||||
container.messagePacket = (MessagePacket) packet;
|
||||
else if (packet instanceof UnifyRequestPacket)
|
||||
container.unifyRequestPacket = (UnifyRequestPacket) packet;
|
||||
else if (packet instanceof UnifyResultPacket)
|
||||
container.unifyResultPacket = (UnifyResultPacket) packet;
|
||||
// Add new packets here and in the deserialize method
|
||||
|
||||
return objectMapper.writeValueAsString(container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the JSON string to generate the matching packet object
|
||||
*
|
||||
* @param json The serialized representation of a packet container
|
||||
* @return The deserialized Packet object
|
||||
*/
|
||||
public static IPacket deserialize(String json) {
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
try {
|
||||
PacketContainer container = objectMapper.readValue(json, PacketContainer.class);
|
||||
|
||||
if (container.errorPacket != null)
|
||||
return container.errorPacket;
|
||||
if (container.messagePacket != null)
|
||||
return container.messagePacket;
|
||||
if (container.invalidPacket != null)
|
||||
return container.invalidPacket;
|
||||
if (container.unifyRequestPacket != null)
|
||||
return container.unifyRequestPacket;
|
||||
if (container.unifyResultPacket != null)
|
||||
return container.unifyResultPacket;
|
||||
// Add new packets here and in the serialize method
|
||||
|
||||
throw new RuntimeException("Cannot map received json to any known packet class");
|
||||
} catch (Exception e) {
|
||||
InvalidPacket packet = new InvalidPacket();
|
||||
packet.error = e.getMessage();
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedFiniteClosure;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedPairConstraintSet;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
/**
|
||||
* A packet to send all required data for the unification algorithm to the server and request the unification
|
||||
*/
|
||||
public class UnifyRequestPacket implements IPacket {
|
||||
|
||||
public SerializedFiniteClosure finiteClosure;
|
||||
public SerializedPairConstraintSet constraints;
|
||||
public SerializedUnifyConstraintSet unifyConstraints;
|
||||
|
||||
public static UnifyRequestPacket create(
|
||||
IFiniteClosure finiteClosure,
|
||||
ConstraintSet<Pair> constraints,
|
||||
ConstraintSet<UnifyPair> unifyConstraints
|
||||
) {
|
||||
UnifyRequestPacket packet = new UnifyRequestPacket();
|
||||
packet.finiteClosure = SerializedFiniteClosure.create(finiteClosure);
|
||||
packet.constraints = SerializedPairConstraintSet.create(constraints);
|
||||
packet.unifyConstraints = SerializedUnifyConstraintSet.create(unifyConstraints);
|
||||
return packet;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public IFiniteClosure retrieveFiniteClosure() {
|
||||
return this.finiteClosure.toObject();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public ConstraintSet<Pair> retrieveConstraints() {
|
||||
return this.constraints.toObject();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public ConstraintSet<UnifyPair> retrieveUnifyConstraints() {
|
||||
return this.unifyConstraints.toObject();
|
||||
}
|
||||
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedResultSet;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A packet to send all calculated data from the unification algorithm back to the client
|
||||
*/
|
||||
public class UnifyResultPacket implements IPacket {
|
||||
|
||||
public SerializedResultSet[] results;
|
||||
|
||||
public static UnifyResultPacket create(List<ResultSet> resultSets) {
|
||||
UnifyResultPacket serialized = new UnifyResultPacket();
|
||||
serialized.results = resultSets.stream().map(SerializedResultSet::create).toArray(SerializedResultSet[]::new);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public List<ResultSet> getResultSet() {
|
||||
return Arrays.stream(this.results).map(SerializedResultSet::toObject).toList();
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see IFiniteClosure
|
||||
*/
|
||||
public class SerializedFiniteClosure implements IPacket.IDataContainer<IFiniteClosure> {
|
||||
public SerializedUnifyPair[] pairs;
|
||||
|
||||
public static SerializedFiniteClosure create(IFiniteClosure finiteClosure) {
|
||||
SerializedFiniteClosure fc = new SerializedFiniteClosure();
|
||||
fc.pairs = finiteClosure.getPairs().stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||
return fc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFiniteClosure toObject() {
|
||||
return new FiniteClosure(
|
||||
new HashSet<>(Arrays.stream(pairs).map(SerializedUnifyPair::toObject).toList()),
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see Pair
|
||||
*/
|
||||
public class SerializedPair implements IPacket.IDataContainer<Pair> {
|
||||
|
||||
@JsonProperty("o")
|
||||
public PairOperator operator;
|
||||
public SerializedTokenWrapper ta1;
|
||||
public SerializedTokenWrapper ta2;
|
||||
|
||||
|
||||
public static SerializedPair create(Pair pair) {
|
||||
SerializedPair sPair = new SerializedPair();
|
||||
sPair.operator = pair.GetOperator();
|
||||
sPair.ta1 = SerializedTokenWrapper.create(pair.TA1);
|
||||
sPair.ta2 = SerializedTokenWrapper.create(pair.TA2);
|
||||
return sPair;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair toObject() {
|
||||
return new Pair(
|
||||
ta1.toObject(),
|
||||
ta2.toObject(),
|
||||
operator
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see Constraint<Pair>
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SerializedPairConstraint implements IPacket.IDataContainer<Constraint<Pair>> {
|
||||
|
||||
// serialize recursive structure
|
||||
public static final HashMap<Constraint<Pair>, String> UNIQUE_CONSTRAINT_KEY_MAP = new HashMap<>();
|
||||
public static final HashMap<String, SerializedPairConstraint> UNIQUE_CONSTRAINT_MAP = new HashMap<>();
|
||||
// deserialize recursive structure
|
||||
private static final HashMap<String, Constraint<Pair>> UNIQUE_OBJECT_MAP = new HashMap<>();
|
||||
|
||||
@JsonProperty("i")
|
||||
public boolean isInherited;
|
||||
@JsonProperty("u")
|
||||
public String uniqueKey;
|
||||
@JsonProperty("e")
|
||||
public String extendedConstraint = null;
|
||||
@JsonProperty("m")
|
||||
public SerializedPair[] methodSignatureConstraint;
|
||||
@JsonProperty("c")
|
||||
public SerializedPair[] constraintElements;
|
||||
|
||||
|
||||
public static SerializedPairConstraint create(Constraint<Pair> constraint) {
|
||||
final String uniqueKey = UNIQUE_CONSTRAINT_KEY_MAP.getOrDefault(constraint, "_" + UNIQUE_CONSTRAINT_MAP.size());
|
||||
|
||||
if (UNIQUE_CONSTRAINT_MAP.containsKey(uniqueKey)) {
|
||||
return UNIQUE_CONSTRAINT_MAP.get(uniqueKey);
|
||||
}
|
||||
|
||||
SerializedPairConstraint pairConstraint = new SerializedPairConstraint();
|
||||
pairConstraint.uniqueKey = uniqueKey;
|
||||
UNIQUE_CONSTRAINT_KEY_MAP.put(constraint, uniqueKey);
|
||||
UNIQUE_CONSTRAINT_MAP.put(uniqueKey, pairConstraint);
|
||||
|
||||
pairConstraint.constraintElements = constraint.stream().map(SerializedPair::create).toArray(SerializedPair[]::new);
|
||||
pairConstraint.isInherited = constraint.isInherited();
|
||||
pairConstraint.methodSignatureConstraint = constraint.getmethodSignatureConstraint().stream().map(SerializedPair::create).toArray(SerializedPair[]::new);
|
||||
if (constraint.getExtendConstraint() != null) {
|
||||
pairConstraint.extendedConstraint = SerializedPairConstraint.create(constraint.getExtendConstraint()).uniqueKey;
|
||||
}
|
||||
|
||||
return pairConstraint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Pair> toObject() {
|
||||
if (UNIQUE_OBJECT_MAP.containsKey(uniqueKey)) {
|
||||
return UNIQUE_OBJECT_MAP.get(uniqueKey);
|
||||
}
|
||||
|
||||
Constraint<Pair> constraint = new Constraint<>();
|
||||
UNIQUE_OBJECT_MAP.put(uniqueKey, constraint);
|
||||
|
||||
constraint.addAll(Arrays.stream(constraintElements).map(SerializedPair::toObject).toList());
|
||||
constraint.setIsInherited(isInherited);
|
||||
constraint.setmethodSignatureConstraint(new HashSet<>(
|
||||
Arrays.stream(methodSignatureConstraint).map(SerializedPair::toObject).toList()
|
||||
));
|
||||
SerializedPairConstraint extendedConstraint = this.extendedConstraint == null ? null :
|
||||
SerializedPairConstraint.UNIQUE_CONSTRAINT_MAP.get(this.extendedConstraint);
|
||||
if (extendedConstraint != null) {
|
||||
constraint.setExtendConstraint(extendedConstraint.toObject());
|
||||
}
|
||||
|
||||
return constraint;
|
||||
}
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ConstraintSet<Pair>
|
||||
*/
|
||||
public class SerializedPairConstraintSet implements IPacket.IDataContainer<ConstraintSet<Pair>> {
|
||||
|
||||
public SerializedPair[] undConstraints;
|
||||
public SerializedPairConstraint[][] oderConstraints;
|
||||
public Map<String, SerializedPairConstraint> uniqueConstraintMap = new HashMap<>();
|
||||
|
||||
public static SerializedPairConstraintSet create(ConstraintSet<Pair> constraints) {
|
||||
SerializedPairConstraintSet constraintSet = new SerializedPairConstraintSet();
|
||||
|
||||
constraintSet.undConstraints = constraints.getUndConstraints().stream().map(SerializedPair::create).toArray(SerializedPair[]::new);
|
||||
constraintSet.oderConstraints = constraints.getOderConstraints().stream().map(consSet ->
|
||||
consSet.stream().map(SerializedPairConstraint::create).toArray(SerializedPairConstraint[]::new)
|
||||
).toArray(SerializedPairConstraint[][]::new);
|
||||
|
||||
// add all the gathered constraints to a serializable property
|
||||
constraintSet.uniqueConstraintMap.putAll(SerializedPairConstraint.UNIQUE_CONSTRAINT_MAP);
|
||||
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet<Pair> toObject() {
|
||||
ConstraintSet<Pair> consSet = new ConstraintSet<>();
|
||||
|
||||
// read all the constraints from the serializable property
|
||||
SerializedPairConstraint.UNIQUE_CONSTRAINT_MAP.putAll(this.uniqueConstraintMap);
|
||||
|
||||
Constraint<Pair> undCons = new Constraint<>();
|
||||
undCons.addAll(Arrays.stream(undConstraints).map(SerializedPair::toObject).toList());
|
||||
consSet.addAllUndConstraint(undCons);
|
||||
|
||||
List<Set<Constraint<Pair>>> oderCons = new ArrayList<>(Arrays.stream(oderConstraints).map(cons ->
|
||||
new HashSet<>(
|
||||
Arrays.stream(cons).map(SerializedPairConstraint::toObject).toList()
|
||||
)
|
||||
).toList());
|
||||
consSet.addAllOderConstraint(oderCons);
|
||||
|
||||
return consSet;
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairNoResult;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairTPHEqualTPH;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.resultPairs.SerializedPairTPHsmallerTPH;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.result.*;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ResultPair
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SerializedResultPairWrapper implements IPacket.IDataContainer<ResultPair<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric>> {
|
||||
|
||||
@JsonProperty("nr")
|
||||
public SerializedPairNoResult noResult = null;
|
||||
@JsonProperty("teo")
|
||||
public SerializedPairTPHequalRefTypeOrWildcardType tphEqualOther = null;
|
||||
@JsonProperty("tet")
|
||||
public SerializedPairTPHEqualTPH tphEqualTph = null;
|
||||
@JsonProperty("tst")
|
||||
public SerializedPairTPHsmallerTPH tphSmallerTPH = null;
|
||||
|
||||
|
||||
public static <A extends RefTypeOrTPHOrWildcardOrGeneric, B extends RefTypeOrTPHOrWildcardOrGeneric> SerializedResultPairWrapper create(ResultPair<A, B> pair) {
|
||||
SerializedResultPairWrapper serialized = new SerializedResultPairWrapper();
|
||||
|
||||
if (pair instanceof PairNoResult noResult)
|
||||
serialized.noResult = SerializedPairNoResult.create(noResult);
|
||||
else if (pair instanceof PairTPHequalRefTypeOrWildcardType tphEqualOther)
|
||||
serialized.tphEqualOther = SerializedPairTPHequalRefTypeOrWildcardType.create(tphEqualOther);
|
||||
else if (pair instanceof PairTPHEqualTPH tphEqualTph)
|
||||
serialized.tphEqualTph = SerializedPairTPHEqualTPH.create(tphEqualTph);
|
||||
else if (pair instanceof PairTPHsmallerTPH tphSmallerTPH)
|
||||
serialized.tphSmallerTPH = SerializedPairTPHsmallerTPH.create(tphSmallerTPH);
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes") // this is not optimal, but we have to conform to interface specifications
|
||||
public ResultPair toObject() {
|
||||
if (noResult != null)
|
||||
return noResult.toObject();
|
||||
else if (tphEqualOther != null)
|
||||
return tphEqualOther.toObject();
|
||||
else if (tphEqualTph != null)
|
||||
return tphEqualTph.toObject();
|
||||
else if (tphSmallerTPH != null)
|
||||
return tphSmallerTPH.toObject();
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ResultSet
|
||||
*/
|
||||
public class SerializedResultSet implements IPacket.IDataContainer<ResultSet> {
|
||||
|
||||
public SerializedResultPairWrapper[] results;
|
||||
|
||||
public static SerializedResultSet create(ResultSet resultSet) {
|
||||
SerializedResultSet serialized = new SerializedResultSet();
|
||||
serialized.results = resultSet.results.stream().map(SerializedResultPairWrapper::create).toArray(SerializedResultPairWrapper[]::new);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public ResultSet toObject() {
|
||||
return new ResultSet(
|
||||
new HashSet<>(
|
||||
Arrays.stream(this.results).map(SerializedResultPairWrapper::toObject).toList()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.token.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see RefTypeOrTPHOrWildcardOrGeneric
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SerializedTokenWrapper implements IPacket.IDataContainer<RefTypeOrTPHOrWildcardOrGeneric> {
|
||||
|
||||
@JsonProperty("ew")
|
||||
public SerializedExtendsWildcardType extendsWildcardType = null;
|
||||
@JsonProperty("gr")
|
||||
public SerializedGenericRefType genericRefType = null;
|
||||
@JsonProperty("p")
|
||||
public SerializedPlaceholderType placeholderType = null;
|
||||
@JsonProperty("r")
|
||||
public SerializedRefType refType = null;
|
||||
@JsonProperty("sw")
|
||||
public SerializedSuperWildcardType superWildcardType = null;
|
||||
@JsonProperty("v")
|
||||
public SerializedVoidType voidType = null;
|
||||
|
||||
|
||||
public static SerializedTokenWrapper create(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
SerializedTokenWrapper wrapper = new SerializedTokenWrapper();
|
||||
|
||||
if (type instanceof ExtendsWildcardType)
|
||||
wrapper.extendsWildcardType = SerializedExtendsWildcardType.create((ExtendsWildcardType) type);
|
||||
else if (type instanceof GenericRefType)
|
||||
wrapper.genericRefType = SerializedGenericRefType.create((GenericRefType) type);
|
||||
else if (type instanceof TypePlaceholder)
|
||||
wrapper.placeholderType = SerializedPlaceholderType.create((TypePlaceholder) type);
|
||||
else if (type instanceof Void)
|
||||
wrapper.voidType = SerializedVoidType.create((Void) type);
|
||||
else if (type instanceof RefType)
|
||||
wrapper.refType = SerializedRefType.create((RefType) type);
|
||||
else if (type instanceof SuperWildcardType)
|
||||
wrapper.superWildcardType = SerializedSuperWildcardType.create((SuperWildcardType) type);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric toObject() {
|
||||
if (extendsWildcardType != null) return extendsWildcardType.toObject();
|
||||
if (genericRefType != null) return genericRefType.toObject();
|
||||
if (placeholderType != null) return placeholderType.toObject();
|
||||
if (refType != null) return refType.toObject();
|
||||
if (superWildcardType != null) return superWildcardType.toObject();
|
||||
if (voidType != null) return voidType.toObject();
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ConstraintSet<UnifyPair>
|
||||
*/
|
||||
public class SerializedUnifyConstraintSet implements IPacket.IDataContainer<ConstraintSet<UnifyPair>> {
|
||||
|
||||
public SerializedUnifyPair[] undConstraints;
|
||||
public SerializedUnifyPairConstraint[][] oderConstraints;
|
||||
|
||||
public static SerializedUnifyConstraintSet create(ConstraintSet<UnifyPair> unifyCons) {
|
||||
SerializedUnifyConstraintSet constraintSet = new SerializedUnifyConstraintSet();
|
||||
constraintSet.undConstraints = unifyCons.getUndConstraints().stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||
constraintSet.oderConstraints = unifyCons.getOderConstraints().stream().map(constraints ->
|
||||
constraints.stream().map(SerializedUnifyPairConstraint::create).toArray(SerializedUnifyPairConstraint[]::new)
|
||||
).toArray(SerializedUnifyPairConstraint[][]::new);
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet<UnifyPair> toObject() {
|
||||
ConstraintSet<UnifyPair> consSet = new ConstraintSet<>();
|
||||
|
||||
Constraint<UnifyPair> undCons = new Constraint<>();
|
||||
undCons.addAll(Arrays.stream(undConstraints).map(SerializedUnifyPair::toObject).toList());
|
||||
consSet.addAllUndConstraint(undCons);
|
||||
|
||||
List<Set<Constraint<UnifyPair>>> oderCons = new ArrayList<>(Arrays.stream(oderConstraints).map(oderConsSet ->
|
||||
new HashSet<>(
|
||||
Arrays.stream(oderConsSet).map(SerializedUnifyPairConstraint::toObject).toList()
|
||||
)
|
||||
).toList());
|
||||
consSet.addAllOderConstraint(oderCons);
|
||||
|
||||
return consSet;
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see UnifyPair
|
||||
*/
|
||||
public class SerializedUnifyPair implements IPacket.IDataContainer<UnifyPair> {
|
||||
|
||||
public SerializedUnifyTypeWrapper lhs;
|
||||
public SerializedUnifyTypeWrapper rhs;
|
||||
@JsonProperty("o")
|
||||
public PairOperator operator;
|
||||
|
||||
public static SerializedUnifyPair create(UnifyPair unifyPair) {
|
||||
SerializedUnifyPair pair = new SerializedUnifyPair();
|
||||
pair.lhs = SerializedUnifyTypeWrapper.create(unifyPair.getLhsType());
|
||||
pair.rhs = SerializedUnifyTypeWrapper.create(unifyPair.getRhsType());
|
||||
pair.operator = unifyPair.getPairOp();
|
||||
return pair;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyPair toObject() {
|
||||
return new UnifyPair(lhs.toObject(), rhs.toObject(), operator);
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see Constraint<UnifyPair>
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SerializedUnifyPairConstraint implements IPacket.IDataContainer<Constraint<UnifyPair>> {
|
||||
|
||||
@JsonProperty("i")
|
||||
public boolean isInherited;
|
||||
@JsonProperty("ec")
|
||||
public SerializedUnifyPairConstraint extendedConstraint = null;
|
||||
@JsonProperty("p")
|
||||
public SerializedUnifyPair[] methodSignatureConstraints;
|
||||
@JsonProperty("c")
|
||||
public SerializedUnifyPair[] constraintElements;
|
||||
|
||||
|
||||
public static SerializedUnifyPairConstraint create(Constraint<UnifyPair> constraint) {
|
||||
SerializedUnifyPairConstraint cons = new SerializedUnifyPairConstraint();
|
||||
cons.constraintElements = constraint.stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||
cons.isInherited = constraint.isInherited();
|
||||
if (constraint.getExtendConstraint() != null) {
|
||||
cons.extendedConstraint = SerializedUnifyPairConstraint.create(constraint.getExtendConstraint());
|
||||
}
|
||||
cons.methodSignatureConstraints = constraint.getmethodSignatureConstraint().stream().map(SerializedUnifyPair::create).toArray(SerializedUnifyPair[]::new);
|
||||
return cons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<UnifyPair> toObject() {
|
||||
Constraint<UnifyPair> cons = new Constraint<>();
|
||||
|
||||
cons.addAll(Arrays.stream(constraintElements).map(SerializedUnifyPair::toObject).toList());
|
||||
cons.setIsInherited(isInherited);
|
||||
if (extendedConstraint != null) {
|
||||
cons.setExtendConstraint(extendedConstraint.toObject());
|
||||
}
|
||||
cons.setmethodSignatureConstraint(new HashSet<>(Arrays.stream(methodSignatureConstraints).map(SerializedUnifyPair::toObject).toList()));
|
||||
return cons;
|
||||
}
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.unifyType.*;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see UnifyType
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SerializedUnifyTypeWrapper implements IPacket.IDataContainer<UnifyType> {
|
||||
|
||||
@JsonProperty("e")
|
||||
public SerializedExtendsType extendsType = null;
|
||||
@JsonProperty("s")
|
||||
public SerializedSuperType superType = null;
|
||||
@JsonProperty("r")
|
||||
public SerializedReferenceType referenceType = null;
|
||||
@JsonProperty("f")
|
||||
public SerializedFunNType funNType = null;
|
||||
@JsonProperty("p")
|
||||
public SerializedPlaceholderType placeholderType = null;
|
||||
|
||||
|
||||
public static SerializedUnifyTypeWrapper create(UnifyType unifyType) {
|
||||
SerializedUnifyTypeWrapper wrapper = new SerializedUnifyTypeWrapper();
|
||||
|
||||
if (unifyType instanceof ExtendsType)
|
||||
wrapper.extendsType = SerializedExtendsType.create((ExtendsType) unifyType);
|
||||
else if (unifyType instanceof SuperType)
|
||||
wrapper.superType = SerializedSuperType.create((SuperType) unifyType);
|
||||
else if (unifyType instanceof ReferenceType)
|
||||
wrapper.referenceType = SerializedReferenceType.create((ReferenceType) unifyType);
|
||||
else if (unifyType instanceof FunNType)
|
||||
wrapper.funNType = SerializedFunNType.create((FunNType) unifyType);
|
||||
else if (unifyType instanceof PlaceholderType)
|
||||
wrapper.placeholderType = SerializedPlaceholderType.create((PlaceholderType) unifyType);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UnifyType toObject() {
|
||||
if (extendsType != null) return extendsType.toObject();
|
||||
if (superType != null) return superType.toObject();
|
||||
if (referenceType != null) return referenceType.toObject();
|
||||
if (funNType != null) return funNType.toObject();
|
||||
if (placeholderType != null) return placeholderType.toObject();
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||
import de.dhbwstuttgart.typeinference.result.PairNoResult;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see PairNoResult
|
||||
*/
|
||||
public class SerializedPairNoResult implements IPacket.IDataContainer<PairNoResult> {
|
||||
|
||||
@JsonProperty("l")
|
||||
public SerializedTokenWrapper left;
|
||||
@JsonProperty("r")
|
||||
public SerializedTokenWrapper right;
|
||||
|
||||
/**
|
||||
* Use a static create method to leave the default constructor and simplify list conversions
|
||||
*/
|
||||
public static SerializedPairNoResult create(PairNoResult pair) {
|
||||
SerializedPairNoResult serialized = new SerializedPairNoResult();
|
||||
serialized.left = SerializedTokenWrapper.create(pair.getLeft());
|
||||
serialized.right = SerializedTokenWrapper.create(pair.getRight());
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PairNoResult toObject() {
|
||||
return new PairNoResult(
|
||||
left.toObject(),
|
||||
right.toObject()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see PairTPHEqualTPH
|
||||
*/
|
||||
public class SerializedPairTPHEqualTPH implements IPacket.IDataContainer<PairTPHEqualTPH> {
|
||||
|
||||
@JsonProperty("l")
|
||||
public SerializedPlaceholderType left;
|
||||
@JsonProperty("r")
|
||||
public SerializedPlaceholderType right;
|
||||
|
||||
public static SerializedPairTPHEqualTPH create(PairTPHEqualTPH pair) {
|
||||
SerializedPairTPHEqualTPH serialized = new SerializedPairTPHEqualTPH();
|
||||
serialized.left = SerializedPlaceholderType.create(pair.getLeft());
|
||||
serialized.right = SerializedPlaceholderType.create(pair.getRight());
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PairTPHEqualTPH toObject() {
|
||||
return new PairTPHEqualTPH(
|
||||
left.toObject(),
|
||||
right.toObject()
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see PairTPHequalRefTypeOrWildcardType
|
||||
*/
|
||||
public class SerializedPairTPHequalRefTypeOrWildcardType implements IPacket.IDataContainer<PairTPHequalRefTypeOrWildcardType> {
|
||||
|
||||
@JsonProperty("l")
|
||||
public SerializedPlaceholderType left;
|
||||
@JsonProperty("r")
|
||||
public SerializedTokenWrapper right;
|
||||
|
||||
public static SerializedPairTPHequalRefTypeOrWildcardType create(PairTPHequalRefTypeOrWildcardType pair) {
|
||||
SerializedPairTPHequalRefTypeOrWildcardType serialized = new SerializedPairTPHequalRefTypeOrWildcardType();
|
||||
serialized.left = SerializedPlaceholderType.create(pair.left);
|
||||
serialized.right = SerializedTokenWrapper.create(pair.right);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PairTPHequalRefTypeOrWildcardType toObject() {
|
||||
return new PairTPHequalRefTypeOrWildcardType(
|
||||
left.toObject(),
|
||||
right.toObject()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.resultPairs;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.token.SerializedPlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see PairTPHsmallerTPH
|
||||
*/
|
||||
public class SerializedPairTPHsmallerTPH implements IPacket.IDataContainer<PairTPHsmallerTPH> {
|
||||
|
||||
@JsonProperty("l")
|
||||
public SerializedPlaceholderType left;
|
||||
@JsonProperty("r")
|
||||
public SerializedPlaceholderType right;
|
||||
|
||||
public static SerializedPairTPHsmallerTPH create(PairTPHsmallerTPH pair) {
|
||||
SerializedPairTPHsmallerTPH serialized = new SerializedPairTPHsmallerTPH();
|
||||
serialized.left = SerializedPlaceholderType.create(pair.left);
|
||||
serialized.right = SerializedPlaceholderType.create(pair.right);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PairTPHsmallerTPH toObject() {
|
||||
return new PairTPHsmallerTPH(
|
||||
left.toObject(),
|
||||
right.toObject()
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ExtendsWildcardType
|
||||
*/
|
||||
public class SerializedExtendsWildcardType implements IPacket.IDataContainer<ExtendsWildcardType> {
|
||||
|
||||
@JsonProperty("e")
|
||||
public SerializedTokenWrapper extendsType;
|
||||
|
||||
public static SerializedExtendsWildcardType create(ExtendsWildcardType extendsWildcardType) {
|
||||
SerializedExtendsWildcardType type = new SerializedExtendsWildcardType();
|
||||
type.extendsType = SerializedTokenWrapper.create(extendsWildcardType.getInnerType());
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendsWildcardType toObject() {
|
||||
return new ExtendsWildcardType(extendsType.toObject(), new NullToken());
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see GenericRefType
|
||||
*/
|
||||
public class SerializedGenericRefType implements IPacket.IDataContainer<GenericRefType> {
|
||||
|
||||
@JsonProperty("n")
|
||||
public String name;
|
||||
|
||||
public static SerializedGenericRefType create(GenericRefType genericRefType) {
|
||||
SerializedGenericRefType serialized = new SerializedGenericRefType();
|
||||
serialized.name = genericRefType.getParsedName();
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericRefType toObject() {
|
||||
return new GenericRefType(name, new NullToken());
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see TypePlaceholder
|
||||
*/
|
||||
public class SerializedPlaceholderType implements IPacket.IDataContainer<TypePlaceholder> {
|
||||
|
||||
@JsonProperty("n")
|
||||
public String name;
|
||||
|
||||
public static SerializedPlaceholderType create(TypePlaceholder typePlaceholder) {
|
||||
SerializedPlaceholderType serialized = new SerializedPlaceholderType();
|
||||
serialized.name = typePlaceholder.getName();
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypePlaceholder toObject() {
|
||||
return (TypePlaceholder) TypePlaceholder.of(name);
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see RefType
|
||||
*/
|
||||
public class SerializedRefType implements IPacket.IDataContainer<RefType> {
|
||||
|
||||
@JsonProperty("n")
|
||||
public String name;
|
||||
@JsonProperty("p")
|
||||
public SerializedTokenWrapper[] parameters;
|
||||
|
||||
public static SerializedRefType create(RefType refType) {
|
||||
SerializedRefType serialized = new SerializedRefType();
|
||||
|
||||
serialized.name = refType.getName().toString();
|
||||
serialized.parameters = refType.getParaList().stream().map(SerializedTokenWrapper::create).toArray(SerializedTokenWrapper[]::new);
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefType toObject() {
|
||||
return new RefType(
|
||||
new JavaClassName(name),
|
||||
Arrays.stream(parameters).map(SerializedTokenWrapper::toObject).toList(),
|
||||
new NullToken()
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedTokenWrapper;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see SuperWildcardType
|
||||
*/
|
||||
public class SerializedSuperWildcardType implements IPacket.IDataContainer<SuperWildcardType> {
|
||||
|
||||
@JsonProperty("s")
|
||||
public SerializedTokenWrapper superType;
|
||||
|
||||
public static SerializedSuperWildcardType create(SuperWildcardType superWildcardType) {
|
||||
SerializedSuperWildcardType type = new SerializedSuperWildcardType();
|
||||
type.superType = SerializedTokenWrapper.create(superWildcardType.getInnerType());
|
||||
type.superType = SerializedTokenWrapper.create(superWildcardType.getInnerType());
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperWildcardType toObject() {
|
||||
return new SuperWildcardType(superType.toObject(), new NullToken());
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.token;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see Void
|
||||
*/
|
||||
public class SerializedVoidType implements IPacket.IDataContainer<Void> {
|
||||
|
||||
public int i = 0;
|
||||
|
||||
public static SerializedVoidType create(Void voidType) {
|
||||
return new SerializedVoidType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void toObject() {
|
||||
return new Void(new NullToken());
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ExtendsType
|
||||
*/
|
||||
public class SerializedExtendsType extends SerializedWildcardType implements IPacket.IDataContainer<ExtendsType> {
|
||||
|
||||
public static SerializedExtendsType create(ExtendsType extendsType) {
|
||||
SerializedExtendsType type = new SerializedExtendsType();
|
||||
type.readWildcardTypeValues(extendsType);
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendsType toObject() {
|
||||
return new ExtendsType(
|
||||
this.wildcardedType.toObject()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see FunNType
|
||||
*/
|
||||
public class SerializedFunNType extends SerializedUnifyType implements IPacket.IDataContainer<FunNType> {
|
||||
|
||||
|
||||
public static SerializedFunNType create(FunNType funN) {
|
||||
SerializedFunNType type = new SerializedFunNType();
|
||||
type.readUnifyTypeValues(funN);
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunNType toObject() {
|
||||
return FunNType.getFunNType(
|
||||
new TypeParams(
|
||||
Arrays.stream(this.params).map(SerializedUnifyTypeWrapper::toObject).toList()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see PlaceholderType
|
||||
*/
|
||||
public class SerializedPlaceholderType extends SerializedUnifyType implements IPacket.IDataContainer<PlaceholderType> {
|
||||
|
||||
public boolean isGenerated;
|
||||
public boolean isInnerType;
|
||||
public int variance;
|
||||
public byte orCons;
|
||||
|
||||
|
||||
public static SerializedPlaceholderType create(PlaceholderType placeholder) {
|
||||
SerializedPlaceholderType type = new SerializedPlaceholderType();
|
||||
type.readUnifyTypeValues(placeholder);
|
||||
type.isGenerated = placeholder.isGenerated();
|
||||
type.isInnerType = placeholder.isInnerType();
|
||||
type.variance = placeholder.getVariance();
|
||||
type.orCons = placeholder.getOrCons();
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceholderType toObject() {
|
||||
PlaceholderType placeholderType = new PlaceholderType(this.name, this.isGenerated);
|
||||
placeholderType.setInnerType(this.isInnerType);
|
||||
placeholderType.setVariance(this.variance);
|
||||
placeholderType.setOrCons(this.orCons);
|
||||
return placeholderType;
|
||||
}
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see ReferenceType
|
||||
*/
|
||||
public class SerializedReferenceType extends SerializedUnifyType implements IPacket.IDataContainer<ReferenceType> {
|
||||
|
||||
@JsonProperty("gt")
|
||||
public boolean genericTypeVar;
|
||||
|
||||
public static SerializedReferenceType create(ReferenceType referenceType) {
|
||||
SerializedReferenceType type = new SerializedReferenceType();
|
||||
type.readUnifyTypeValues(referenceType);
|
||||
type.genericTypeVar = referenceType.isGenTypeVar();
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceType toObject() {
|
||||
ReferenceType referenceType = new ReferenceType(this.name, this.genericTypeVar);
|
||||
return (ReferenceType) referenceType.setTypeParams(
|
||||
new TypeParams(
|
||||
Arrays.stream(this.params).map(SerializedUnifyTypeWrapper::toObject).toList()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.IPacket;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
|
||||
/**
|
||||
* Serializable container of
|
||||
*
|
||||
* @see SuperType
|
||||
*/
|
||||
public class SerializedSuperType extends SerializedWildcardType implements IPacket.IDataContainer<SuperType> {
|
||||
|
||||
public static SerializedSuperType create(SuperType superType) {
|
||||
SerializedSuperType type = new SerializedSuperType();
|
||||
type.readWildcardTypeValues(superType);
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperType toObject() {
|
||||
return new SuperType(
|
||||
this.wildcardedType.toObject()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Serializable abstract container of
|
||||
*
|
||||
* @see UnifyType
|
||||
*/
|
||||
abstract class SerializedUnifyType {
|
||||
|
||||
@JsonProperty("n")
|
||||
public String name;
|
||||
@JsonProperty("p")
|
||||
public SerializedUnifyTypeWrapper[] params = new SerializedUnifyTypeWrapper[]{};
|
||||
|
||||
public void readUnifyTypeValues(UnifyType unifyType) {
|
||||
name = unifyType.getName();
|
||||
params = Arrays.stream(unifyType.getTypeParams().get()).map(SerializedUnifyTypeWrapper::create).toArray(SerializedUnifyTypeWrapper[]::new);
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package de.dhbwstuttgart.server.packet.dataContainers.unifyType;
|
||||
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.SerializedUnifyTypeWrapper;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
||||
|
||||
/**
|
||||
* Serializable abstract container of
|
||||
*
|
||||
* @see WildcardType
|
||||
*/
|
||||
abstract class SerializedWildcardType extends SerializedUnifyType {
|
||||
|
||||
public SerializedUnifyTypeWrapper wildcardedType;
|
||||
|
||||
public void readWildcardTypeValues(WildcardType wildcardType) {
|
||||
this.readUnifyTypeValues(wildcardType);
|
||||
wildcardedType = SerializedUnifyTypeWrapper.create(wildcardType.getWildcardedType());
|
||||
}
|
||||
|
||||
}
|
@@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -265,4 +266,4 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
public void visit(SuperCall superCall) {
|
||||
this.visit((MethodCall)superCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,18 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -157,4 +164,4 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
public String toString() {
|
||||
return this.name.toString() + this.genericClassParameters.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,13 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Constructor extends Method {
|
||||
@@ -34,4 +36,4 @@ public class Constructor extends Method {
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/**
|
||||
* Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung
|
||||
* Beispiel: 'public Feld FeldVar = FeldWert;'
|
||||
@@ -24,4 +25,4 @@ public class FieldDeclaration extends Field{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,12 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,4 +49,17 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
public String toString() {
|
||||
return this.gtvs.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GenericDeclarationList that = (GenericDeclarationList) o;
|
||||
return gtvs.equals(that.gtvs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(gtvs);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Entspricht einem GenericTypeVar, jedoch mit Bounds
|
||||
@@ -44,7 +46,7 @@ public class GenericTypeVar extends SyntaxTreeNode
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "BoGTV " + this.name;
|
||||
return "BoGTV " + this.name + " " + this.bounds;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
@@ -60,4 +62,17 @@ public class GenericTypeVar extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GenericTypeVar that = (GenericTypeVar) o;
|
||||
return bounds.equals(that.bounds) && name.equals(that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(bounds, name);
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,18 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPEStmt;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
|
||||
/**
|
||||
* Stellt eine Methode dar. Problem: Parser kann nicht zwischen Methode und
|
||||
@@ -88,4 +93,4 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
//import sun.security.x509.X509CertInfo;
|
||||
|
||||
|
||||
@@ -57,4 +56,4 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,10 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
//import org.antlr.v4.runtime.misc.Pair;
|
||||
|
||||
@@ -16,4 +20,4 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
}
|
||||
|
||||
public abstract void accept(ASTVisitor visitor);
|
||||
}
|
||||
}
|
||||
|
@@ -2,9 +2,11 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public interface TypeScope {
|
||||
Iterable<? extends GenericTypeVar> getGenerics();
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric getReturnType();
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,32 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.JavaTXSignatureAttribute;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||
import de.dhbwstuttgart.util.Pair;
|
||||
import javassist.bytecode.SignatureAttribute;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.objectweb.asm.*;
|
||||
import org.objectweb.asm.signature.SignatureReader;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
|
||||
/**
|
||||
* Anmerkung:
|
||||
@@ -23,21 +36,76 @@ import java.util.*;
|
||||
public class ASTFactory {
|
||||
|
||||
public static ClassOrInterface createClass(java.lang.Class jreClass){
|
||||
|
||||
// TODO Inner classes
|
||||
|
||||
var methodSignatures = new HashMap<Pair<String, String>, String>();
|
||||
String classSignature = null;
|
||||
|
||||
// Load class with asm to figure out if there's a JavaTX signature
|
||||
try {
|
||||
var path = jreClass.getName().replace('.', '/') + ".class";
|
||||
var classLoader = jreClass.getClassLoader();
|
||||
if (classLoader != null) {
|
||||
var bytes = IOUtils.toByteArray(Objects.requireNonNull(classLoader.getResourceAsStream(path)));
|
||||
var classReader = new ClassReader(bytes);
|
||||
var classVisitor = new ClassVisitor(Opcodes.ASM7) {
|
||||
String classSignature;
|
||||
@Override
|
||||
public void visitAttribute(Attribute attribute) {
|
||||
if (attribute.type.equals("JavaTXSignature")) {
|
||||
classSignature = ((JavaTXSignatureAttribute) attribute).signature;
|
||||
}
|
||||
super.visitAttribute(attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
classSignature = signature;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
|
||||
methodSignatures.put(new Pair<>(name, descriptor), signature);
|
||||
return new MethodVisitor(Opcodes.ASM7) {
|
||||
@Override
|
||||
public void visitAttribute(Attribute attribute) {
|
||||
if (attribute.type.equals("JavaTXSignature")) {
|
||||
methodSignatures.put(new Pair<>(name, descriptor), ((JavaTXSignatureAttribute) attribute).signature);
|
||||
}
|
||||
super.visitAttribute(attribute);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
classReader.accept(classVisitor, new Attribute[]{new JavaTXSignatureAttribute()}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
classSignature = classVisitor.classSignature;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Skip
|
||||
}
|
||||
|
||||
JavaClassName name = new JavaClassName(jreClass.getName());
|
||||
List<Method> methoden = new ArrayList<>();
|
||||
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
||||
for(java.lang.reflect.Constructor constructor : jreClass.getDeclaredConstructors()){
|
||||
createConstructor(constructor, jreClass).map(c -> konstruktoren.add(c));
|
||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||
var signature = methodSignatures.get(new Pair<>(constructor.getName(), org.objectweb.asm.Type.getConstructorDescriptor(constructor)));
|
||||
createConstructor(constructor, signature, jreClass).map(c -> konstruktoren.add(c));
|
||||
}
|
||||
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||
Set<java.lang.reflect.Method> allInheritedMethods = new HashSet<>(allMethods);
|
||||
allInheritedMethods.removeAll(allDeclaredMethods);
|
||||
for(java.lang.reflect.Method method : allDeclaredMethods){
|
||||
methoden.add(createMethod(method, jreClass, false));
|
||||
var signature = methodSignatures.get(new Pair<>(method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
|
||||
methoden.add(createMethod(method, signature, jreClass, false));
|
||||
}
|
||||
for(java.lang.reflect.Method method : allInheritedMethods){
|
||||
methoden.add(createMethod(method, jreClass, true));
|
||||
var signature = methodSignatures.get(new Pair<>(method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
|
||||
methoden.add(createMethod(method, signature, jreClass, true));
|
||||
}
|
||||
List<Field> felder = new ArrayList<>();
|
||||
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
||||
@@ -63,7 +131,8 @@ public class ASTFactory {
|
||||
for(Type jreInterface : jreClass.getGenericInterfaces()){
|
||||
implementedInterfaces.add((RefType) createType(jreInterface));
|
||||
}
|
||||
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
|
||||
|
||||
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null, classSignature);
|
||||
|
||||
Token offset = new NullToken(); //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
||||
|
||||
@@ -78,7 +147,7 @@ public class ASTFactory {
|
||||
// return createClass(classType).getType();
|
||||
//}
|
||||
|
||||
private static Optional<de.dhbwstuttgart.syntaxtree.Constructor> createConstructor(Constructor constructor, Class inClass) {
|
||||
private static Optional<de.dhbwstuttgart.syntaxtree.Constructor> createConstructor(Constructor constructor, String signature, Class inClass) {
|
||||
String name = constructor.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
||||
Parameter[] jreParams = constructor.getParameters();
|
||||
@@ -92,7 +161,7 @@ public class ASTFactory {
|
||||
}
|
||||
ParameterList parameterList = new ParameterList(params, new NullToken());
|
||||
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
||||
GenericDeclarationList gtvDeclarations = createGenerics(constructor.getTypeParameters(), inClass, constructor.getName());
|
||||
GenericDeclarationList gtvDeclarations = createGenerics(constructor.getTypeParameters(), inClass, constructor.getName(), signature);
|
||||
Token offset = new NullToken();
|
||||
int modifier = constructor.getModifiers();
|
||||
|
||||
@@ -103,7 +172,7 @@ public class ASTFactory {
|
||||
return Optional.of(new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */));
|
||||
}
|
||||
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, String signature, java.lang.Class inClass, Boolean isInherited){
|
||||
String name = jreMethod.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
Type jreRetType;
|
||||
@@ -124,19 +193,142 @@ public class ASTFactory {
|
||||
}
|
||||
ParameterList parameterList = new ParameterList(params, new NullToken());
|
||||
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName(), signature);
|
||||
Token offset = new NullToken();
|
||||
|
||||
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
||||
}
|
||||
|
||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
||||
List<de.dhbwstuttgart.syntaxtree.GenericTypeVar> gtvs = new ArrayList<>();
|
||||
for(TypeVariable jreTV : typeParameters){
|
||||
de.dhbwstuttgart.syntaxtree.GenericTypeVar gtv = createGeneric(jreTV, jreTV.getName(), context, methodName);
|
||||
gtvs.add(gtv);
|
||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName, String signature) {
|
||||
if (signature == null) {
|
||||
List<de.dhbwstuttgart.syntaxtree.GenericTypeVar> gtvs = new ArrayList<>();
|
||||
for(TypeVariable jreTV : typeParameters){
|
||||
de.dhbwstuttgart.syntaxtree.GenericTypeVar gtv = createGeneric(jreTV, jreTV.getName(), context, methodName);
|
||||
gtvs.add(gtv);
|
||||
}
|
||||
return new GenericDeclarationList(gtvs, new NullToken());
|
||||
} else {
|
||||
var res = createGenerics(signature);
|
||||
return res;
|
||||
}
|
||||
return new GenericDeclarationList(gtvs,new NullToken());
|
||||
}
|
||||
|
||||
public static GenericDeclarationList createGenerics(String signature) {
|
||||
if (signature == null) return new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
||||
|
||||
var gtvs = new ArrayList<GenericTypeVar>();
|
||||
var signatureVisitor = new SignatureVisitor(Opcodes.ASM7) {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = new ArrayList<>();
|
||||
final Stack<RefTypeOrTPHOrWildcardOrGeneric> bound = new Stack<>();
|
||||
final Stack<RefType> classTypes = new Stack<>();
|
||||
|
||||
// All hail the mighty visitor pattern
|
||||
final SignatureVisitor doNothing = new SignatureVisitor(Opcodes.ASM7) {};
|
||||
|
||||
char wildcard = '=';
|
||||
|
||||
@Override
|
||||
public SignatureVisitor visitSuperclass() {
|
||||
return doNothing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignatureVisitor visitParameterType() {
|
||||
return doNothing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignatureVisitor visitReturnType() {
|
||||
return doNothing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignatureVisitor visitExceptionType() {
|
||||
return doNothing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFormalTypeParameter(String name) {
|
||||
bounds = new ArrayList<>();
|
||||
gtvs.add(new GenericTypeVar(name, bounds, new NullToken(), new NullToken()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeVariable(String name) {
|
||||
var refType = new GenericRefType(name, new NullToken());
|
||||
if (classTypes.isEmpty()) {
|
||||
((List<RefTypeOrTPHOrWildcardOrGeneric>) gtvs.get(gtvs.size() - 1).getBounds()).add(refType);
|
||||
} else {
|
||||
pushType(refType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassType(String name) {
|
||||
var refType = new RefType(new JavaClassName(name.replaceAll("/", ".")), new ArrayList<>(), new NullToken());
|
||||
classTypes.push(refType);
|
||||
pushType(refType);
|
||||
}
|
||||
|
||||
void pushType(RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
if (wildcard == SignatureVisitor.SUPER) {
|
||||
bound.push(new SuperWildcardType(refType, new NullToken()));
|
||||
} else if (wildcard == SignatureVisitor.EXTENDS) {
|
||||
bound.push(new ExtendsWildcardType(refType, new NullToken()));
|
||||
} else {
|
||||
bound.push(refType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignatureVisitor visitTypeArgument(char wildcard) {
|
||||
this.wildcard = wildcard;
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean equals(RefTypeOrTPHOrWildcardOrGeneric a, RefTypeOrTPHOrWildcardOrGeneric b) {
|
||||
if (b instanceof SuperWildcardType wc)
|
||||
return equals(a, wc.getInnerType());
|
||||
else if (b instanceof ExtendsWildcardType wc)
|
||||
return equals(a, wc.getInnerType());
|
||||
return a == b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
wildcard = '=';
|
||||
var classType = (RefType) classTypes.pop();
|
||||
if (!classTypes.isEmpty()) {
|
||||
var next = classTypes.peek();
|
||||
var par = bound.pop();
|
||||
var toAdd = new ArrayList<RefTypeOrTPHOrWildcardOrGeneric>();
|
||||
while (!equals(next, par)) {
|
||||
toAdd.add(par);
|
||||
par = bound.pop();
|
||||
}
|
||||
var element = par;
|
||||
if (par instanceof WildcardType wc) {
|
||||
element = wc.getInnerType();
|
||||
}
|
||||
Collections.reverse(toAdd);
|
||||
((RefType) element).getParaList().addAll(toAdd);
|
||||
|
||||
bound.push(par);
|
||||
} else {
|
||||
if (bound.peek() != classType) {
|
||||
classType.getParaList().add(bound.pop());
|
||||
bounds.add(classType);
|
||||
} else {
|
||||
bounds.add(bound.pop());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var sr = new SignatureReader(signature);
|
||||
sr.accept(signatureVisitor);
|
||||
|
||||
return new GenericDeclarationList(gtvs, new NullToken());
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type){
|
||||
|
@@ -1,27 +1,30 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.*;
|
||||
import de.dhbwstuttgart.typeinference.result.PairNoResult;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UnifyTypeFactory {
|
||||
|
||||
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
||||
@@ -182,7 +185,7 @@ public class UnifyTypeFactory {
|
||||
if (lhs.getName().equals("AQ")) {
|
||||
System.out.println("");
|
||||
}
|
||||
((PlaceholderType)rhs).enableWildcardable();
|
||||
((PlaceholderType)rhs).enableWildcardtable();
|
||||
}
|
||||
|
||||
if (((rhs = ret.getLhsType()) instanceof PlaceholderType)
|
||||
@@ -191,7 +194,7 @@ public class UnifyTypeFactory {
|
||||
if (rhs.getName().equals("AQ")) {
|
||||
System.out.println("");
|
||||
}
|
||||
((PlaceholderType)lhs).enableWildcardable();
|
||||
((PlaceholderType)lhs).enableWildcardtable();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@@ -2,6 +2,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
/*
|
||||
@@ -23,4 +26,4 @@ public class Assign extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@@ -8,4 +9,4 @@ public abstract class AssignLeftSide extends TypableStatement{
|
||||
public AssignLeftSide(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
||||
super(type, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Block extends Statement
|
||||
{
|
||||
@@ -28,4 +28,6 @@ public class Block extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
||||
@@ -19,4 +22,4 @@ public class CastExpr extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class DoStmt extends WhileStmt
|
||||
@@ -14,4 +15,4 @@ public class DoStmt extends WhileStmt
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
||||
@@ -16,4 +19,4 @@ public class EmptyStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,12 @@
|
||||
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public abstract class Expression extends TypableStatement
|
||||
@@ -9,4 +14,4 @@ public abstract class Expression extends TypableStatement
|
||||
public Expression(RefTypeOrTPHOrWildcardOrGeneric type, Token offset){
|
||||
super(type, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class ExpressionReceiver extends Receiver
|
||||
{
|
||||
@@ -16,4 +18,4 @@ public class ExpressionReceiver extends Receiver
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,18 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FieldVar extends Expression {
|
||||
|
||||
public final String fieldVarName;
|
||||
@@ -19,4 +28,4 @@ public class FieldVar extends Expression {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
|
||||
public class ForStmt extends Statement
|
||||
{
|
||||
|
@@ -2,6 +2,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
||||
@@ -24,4 +27,4 @@ public class IfStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class JavaInternalExpression extends Statement{
|
||||
public JavaInternalExpression(RefTypeOrTPHOrWildcardOrGeneric retType, Token offset){
|
||||
super(retType, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
//import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -36,4 +39,4 @@ public class LambdaExpression extends Expression implements TypeScope {
|
||||
//return type.getParaList().get(0);
|
||||
return methodBody.getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class Literal extends Expression
|
||||
@@ -18,4 +21,4 @@ public class Literal extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
||||
@@ -25,4 +28,4 @@ public class LocalVarDecl extends Statement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user