forked from JavaTX/JavaCompilerCore
Compare commits
55 Commits
plugin
...
unify-test
Author | SHA1 | Date | |
---|---|---|---|
|
0233426979 | ||
|
3d0d11adb7 | ||
|
212144db86 | ||
|
bd0517ae29 | ||
|
f210dd3c25 | ||
|
4602e95f09 | ||
|
1ef228a045 | ||
|
c3c0a11572 | ||
|
d14406e474 | ||
|
a149b0c391 | ||
|
bfbce81409 | ||
|
985704c0b0 | ||
|
1f20fecfee | ||
|
4b8b0ec362 | ||
|
e48f2b2fd5 | ||
|
11bee80969 | ||
|
448c489a49 | ||
|
1e1eb2a2f2 | ||
|
4a7c124fd6 | ||
|
7d01c866a9 | ||
|
73f412d22d | ||
|
9ffc74467b | ||
|
5950fcc0a9 | ||
|
d2fb17ad4e | ||
|
d9f084cd0f | ||
|
481986e8ab | ||
|
23c37a8cc2 | ||
|
6a519ff6dc | ||
|
5b527ec8ab | ||
|
709041f024 | ||
|
905d9e25a2 | ||
|
e086ff187e | ||
|
588212389a | ||
|
1454281628 | ||
|
602216d9e2 | ||
|
e53c29f582 | ||
|
656c77d16b | ||
|
9d16855ce2 | ||
|
9d2fdf9692 | ||
|
5c5b1ea2b1 | ||
|
2e2227b701 | ||
|
16baa5eaa8 | ||
|
588b9ef83a | ||
|
ee932892c6 | ||
|
547ad9601a | ||
|
6c94404f27 | ||
|
2b5b677682 | ||
|
1edc023ed9 | ||
|
df0f26c021 | ||
|
53d1f20a40 | ||
|
ec4defd087 | ||
|
6a2a8313e6 | ||
|
d4a59517d3 | ||
|
f4b5124fd3 | ||
|
c921330b55 |
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<artifactId>JavaTXcompiler</artifactId>
|
<artifactId>JavaTXcompiler</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<version>0.1</version>
|
<version>0.2</version>
|
||||||
<name>JavaTXcompiler</name>
|
<name>JavaTXcompiler</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -127,7 +127,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<!-- specify your depencies here -->
|
<!-- specify your depencies here -->
|
||||||
<!-- groupId:artifactId:version -->
|
<!-- groupId:artifactId:version -->
|
||||||
<artifact>
|
<artifact>
|
||||||
<id>de.dhbwstuttgart:JavaTXcompiler:0.1</id>
|
<id>de.dhbwstuttgart:JavaTXcompiler:0.2</id>
|
||||||
</artifact>
|
</artifact>
|
||||||
<artifact>
|
<artifact>
|
||||||
<id>org.reflections:reflections:0.9.11</id>
|
<id>org.reflections:reflections:0.9.11</id>
|
||||||
|
@@ -1,25 +1,22 @@
|
|||||||
package de.dhbwstuttgart.bytecode;
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.FieldVisitor;
|
import org.objectweb.asm.FieldVisitor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
@@ -29,9 +26,47 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@@ -39,8 +74,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class BytecodeGen implements ASTVisitor {
|
public class BytecodeGen implements ASTVisitor {
|
||||||
@@ -52,7 +85,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
||||||
String className;
|
String className;
|
||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private List<ResultSet> listOfResultSets;
|
private Collection<ResultSet> listOfResultSets;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private SourceFile sf;
|
private SourceFile sf;
|
||||||
private String path;
|
private String path;
|
||||||
@@ -63,9 +96,10 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
private String superClass;
|
private String superClass;
|
||||||
|
|
||||||
private ArrayList<TypePlaceholder> tphsClass;
|
private ArrayList<String> tphsClass;
|
||||||
|
|
||||||
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
// stores parameter, local vars and the next index on the local variable table,
|
||||||
|
// which use for aload_i, astore_i,...
|
||||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||||
// stores generics and their bounds of class
|
// stores generics and their bounds of class
|
||||||
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
||||||
@@ -79,9 +113,24 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
byte[] bytecode;
|
byte[] bytecode;
|
||||||
HashMap<String, byte[]> classFiles;
|
HashMap<String, byte[]> classFiles;
|
||||||
|
|
||||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
|
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
|
private HashMap<String, SimplifyResult> simplifyResults = new HashMap<>();
|
||||||
|
private List<HashMap<String, SimplifyResult>> simplifyResultsList = new ArrayList<>();
|
||||||
|
|
||||||
|
private final ArrayList<String> fieldNameSignature = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<HashMap<String, SimplifyResult>> getSimplifyResultsList() {
|
||||||
|
return simplifyResultsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSimplifyResultsList(List<HashMap<String, SimplifyResult>> simplifyResultsList) {
|
||||||
|
this.simplifyResultsList = simplifyResultsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BytecodeGen(HashMap<String, byte[]> classFiles, Collection<ResultSet> listOfResultSets, SourceFile sf,
|
||||||
|
String path) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
@@ -94,13 +143,14 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
|
simplifyResultsList.add(classGen.getSimplifyResults());
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associates the bytecode of the class that was build with the classWriter {@link #cw}
|
* Associates the bytecode of the class that was build with the classWriter
|
||||||
* with the class name in the map {@link #classFiles}
|
* {@link #cw} with the class name in the map {@link #classFiles}
|
||||||
*
|
*
|
||||||
* @param name name of the class with which the the bytecode is to be associated
|
* @param name name of the class with which the the bytecode is to be associated
|
||||||
*/
|
*/
|
||||||
@@ -114,7 +164,6 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
return classFiles;
|
return classFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
|
||||||
@@ -124,16 +173,19 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
isInterface = (classOrInterface.getModifiers() & 512) == 512;
|
isInterface = (classOrInterface.getModifiers() & 512) == 512;
|
||||||
|
|
||||||
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
int acc = isInterface ? classOrInterface.getModifiers() + Opcodes.ACC_ABSTRACT
|
||||||
|
: classOrInterface.getModifiers() + Opcodes.ACC_SUPER;
|
||||||
|
|
||||||
fieldInitializations = classOrInterface.getfieldInitializations();
|
fieldInitializations = classOrInterface.getfieldInitializations();
|
||||||
|
|
||||||
// resultSet = listOfResultSets.get(0);
|
// resultSet = listOfResultSets.get(0);
|
||||||
boolean isConsWithNoParamsVisited = false;
|
boolean isConsWithNoParamsVisited = false;
|
||||||
boolean isVisited = false;
|
boolean isVisited = false;
|
||||||
for(ResultSet rs : listOfResultSets) {
|
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
||||||
|
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||||
|
//for (ResultSet rs : listOfResultSets) {
|
||||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||||
resultSet = rs;
|
resultSet = listOfResultSetsList.get(i);
|
||||||
tphExtractor.setResultSet(resultSet);
|
tphExtractor.setResultSet(resultSet);
|
||||||
|
|
||||||
// Nur einmal ausführen!!
|
// Nur einmal ausführen!!
|
||||||
@@ -143,43 +195,62 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
getCommonTPHS(tphExtractor);
|
getCommonTPHS(tphExtractor);
|
||||||
|
|
||||||
tphsClass = new ArrayList<>();
|
tphsClass = new ArrayList<>();
|
||||||
for(TypePlaceholder t : tphExtractor.allTPHS.keySet()) {
|
for (String t : tphExtractor.allTPHS.keySet()) {
|
||||||
if (!tphExtractor.allTPHS.get(t))
|
if (!tphExtractor.allTPHS.get(t))
|
||||||
tphsClass.add(t);
|
tphsClass.add(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sig = null;
|
String sig = null;
|
||||||
/* if class has generics then creates signature
|
/*
|
||||||
* Signature looks like:
|
* if class has generics then creates signature Signature looks like:
|
||||||
* <E:Ljava/...>Superclass
|
* <E:Ljava/...>Superclass
|
||||||
*/
|
*/
|
||||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
if (classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty()
|
||||||
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
|| classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
||||||
|| !tphsClass.isEmpty()) {
|
|| !tphsClass.isEmpty()) {
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraintsClass(tphExtractor,tphsClass);
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify
|
||||||
|
.simplifyConstraintsClass(tphExtractor, tphsClass);
|
||||||
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
||||||
for (TPHConstraint cons : constraints.keySet()) {
|
for (TPHConstraint cons : constraints.keySet()) {
|
||||||
TypePlaceholder right = null;
|
String right = null;
|
||||||
for(TypePlaceholder tph : tphsClass) {
|
boolean isToAdd = false;
|
||||||
if(cons.getLeft().equals(tph.getName())) {
|
for (String tph : tphsClass) {
|
||||||
|
if (cons.getLeft().equals(tph)) {
|
||||||
|
|
||||||
consClass.add(cons);
|
consClass.add(cons);
|
||||||
|
try {
|
||||||
right = getTPH(cons.getRight());
|
right = getTPH(cons.getRight());
|
||||||
|
isToAdd = true;
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(right != null) {
|
if (isToAdd) {
|
||||||
tphsClass.add(right);
|
tphsClass.add(right);
|
||||||
removeFromMethod(right.getName());
|
removeFromMethod(right);
|
||||||
right = null;
|
right = null;
|
||||||
|
isToAdd = false;
|
||||||
}
|
}
|
||||||
|
// if(right != null) {
|
||||||
|
// tphsClass.add(right);
|
||||||
|
// removeFromMethod(right);
|
||||||
|
// right = null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass);
|
|
||||||
|
SimplifyResult sRes = new SimplifyResult(consClass, tphsClass, new HashMap<>());
|
||||||
|
simplifyResults.put(className, sRes);
|
||||||
|
|
||||||
|
Signature signature = new Signature(classOrInterface, genericsAndBounds, commonPairs, tphsClass,
|
||||||
|
consClass);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
System.out.println("Signature: => " + sig);
|
System.out.println("Signature: => " + sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString(), sig,
|
||||||
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||||
|
|
||||||
isVisited = true;
|
isVisited = true;
|
||||||
}
|
}
|
||||||
@@ -222,9 +293,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypePlaceholder getTPH(String name) {
|
private String getTPH(String name) {
|
||||||
for(TypePlaceholder tph: tphExtractor.allTPHS.keySet()) {
|
for (String tph : tphExtractor.allTPHS.keySet()) {
|
||||||
if(tph.getName().equals(name))
|
if (tph.equals(name))
|
||||||
return tph;
|
return tph;
|
||||||
}
|
}
|
||||||
throw new NoSuchElementException("TPH " + name + " does not exist");
|
throw new NoSuchElementException("TPH " + name + " does not exist");
|
||||||
@@ -232,9 +303,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
||||||
// Gemeinsame TPHs
|
// Gemeinsame TPHs
|
||||||
ArrayList<TypePlaceholder> cTPHs = new ArrayList<>();
|
ArrayList<String> cTPHs = new ArrayList<>();
|
||||||
// Alle TPHs der Felder speichern
|
// Alle TPHs der Felder speichern
|
||||||
for(TypePlaceholder tph : tphExtractor.allTPHS.keySet()) {
|
for (String tph : tphExtractor.allTPHS.keySet()) {
|
||||||
if (!tphExtractor.allTPHS.get(tph))
|
if (!tphExtractor.allTPHS.get(tph))
|
||||||
cTPHs.add(tph);
|
cTPHs.add(tph);
|
||||||
}
|
}
|
||||||
@@ -275,15 +346,15 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
for (String paramName : methodParamsAndTypes.keySet()) {
|
for (String paramName : methodParamsAndTypes.keySet()) {
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||||
System.out.println(typeOfParam);
|
System.out.println(typeOfParam);
|
||||||
if(genericsAndBounds.containsKey(typeOfParam) ||typeOfParam.contains("$")
|
if (genericsAndBounds.containsKey(typeOfParam) || typeOfParam.contains("$") || typeOfParam.contains("<")) {
|
||||||
|| typeOfParam.contains("<")) {
|
|
||||||
hasGen = true;
|
hasGen = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String sig = null;
|
String sig = null;
|
||||||
if (hasGen) {
|
if (hasGen) {
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,tphsClass);
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,
|
||||||
|
tphsClass);
|
||||||
Signature signature = new Signature(field, genericsAndBounds, methodParamsAndTypes, resultSet, constraints);
|
Signature signature = new Signature(field, genericsAndBounds, methodParamsAndTypes, resultSet, constraints);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
}
|
}
|
||||||
@@ -302,7 +373,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, field, mv, paramsAndLocals, cw,
|
BytecodeGenMethod gen = new BytecodeGenMethod(className, superClass, resultSet, field, mv, paramsAndLocals, cw,
|
||||||
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, block, constructorPos);
|
genericsAndBoundsMethod, genericsAndBounds, isInterface, classFiles, sf, path, block, constructorPos);
|
||||||
if(!field.getParameterList().iterator().hasNext() && !(field.block.statements.get(field.block.statements.size()-1) instanceof ReturnVoid)) {
|
if (!field.getParameterList().iterator().hasNext()
|
||||||
|
&& !(field.block.statements.get(field.block.statements.size() - 1) instanceof ReturnVoid)) {
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
}
|
}
|
||||||
mv.visitMaxs(0, 0);
|
mv.visitMaxs(0, 0);
|
||||||
@@ -311,7 +383,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
// TODO: check if the method is static => if static then the first param will be stored in pos 0
|
// TODO: check if the method is static => if static then the first param will be
|
||||||
|
// stored in pos 0
|
||||||
// else it will be stored in pos 1 and this will be stored in pos 0
|
// else it will be stored in pos 1 and this will be stored in pos 0
|
||||||
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
// String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
// String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
@@ -339,37 +412,54 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println(acc);
|
System.out.println(acc);
|
||||||
|
|
||||||
/* Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist */
|
/* Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist */
|
||||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ") ||
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ")
|
||||||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).contains("<");
|
|| resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature())
|
||||||
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
|
.contains("<");
|
||||||
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
|
/*
|
||||||
|
* Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature,
|
||||||
|
* wenn nicht, prüfe, ob einer der Parameter Typ-Variable als Typ hat
|
||||||
|
*/
|
||||||
if (!hasGenInParameterList) {
|
if (!hasGenInParameterList) {
|
||||||
for (String paramName : methodParamsAndTypes.keySet()) {
|
for (String paramName : methodParamsAndTypes.keySet()) {
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||||
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")||sigOfParam.contains("<")) {
|
if (genericsAndBounds.containsKey(typeOfParam) || typeOfParam.contains("TPH ")
|
||||||
|
|| sigOfParam.contains("<")) {
|
||||||
hasGenInParameterList = true;
|
hasGenInParameterList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
|
// TODO: Test if the return-type or any of the parameter is a parameterized
|
||||||
|
// type. (VP)
|
||||||
// then create the descriptor with the new syntax.
|
// then create the descriptor with the new syntax.
|
||||||
|
|
||||||
String sig = null;
|
String sig = null;
|
||||||
/* method.getGenerics: <....> RT method(..)
|
/*
|
||||||
* */
|
* method.getGenerics: <....> RT method(..)
|
||||||
|
*/
|
||||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||||
/* if method has generics or return type is TPH, create signature */
|
/* if method has generics or return type is TPH, create signature */
|
||||||
// zwite operand muss weggelassen werden
|
// zwite operand muss weggelassen werden
|
||||||
if(hasGen||resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString()).equals("TPH")) {
|
if (hasGen || resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString())
|
||||||
|
.equals("TPH")) {
|
||||||
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
||||||
tphExtractor.allCons.forEach(c -> System.out.println(c.toString()));
|
tphExtractor.allCons.forEach(c -> System.out.println(c.toString()));
|
||||||
System.out.println("----------------");
|
System.out.println("----------------");
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name, tphExtractor, tphsClass);
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name,
|
||||||
|
tphExtractor, tphsClass);
|
||||||
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
||||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,
|
||||||
|
methodParamsAndTypes, resultSet, constraints);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
|
if (simplifyResults.containsKey(className)) {
|
||||||
|
simplifyResults.get(className).getMethodsConstraints().put(methParamTypes, constraints);
|
||||||
|
} else {
|
||||||
|
SimplifyResult sRes = new SimplifyResult(new ArrayList<>(), new ArrayList<>(), new HashMap<>());
|
||||||
|
sRes.getMethodsConstraints().put(methParamTypes, constraints);
|
||||||
|
simplifyResults.put(className, sRes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
System.out.println(method.getName() + " ==> " + sig);
|
System.out.println(method.getName() + " ==> " + sig);
|
||||||
NormalMethod meth = new NormalMethod(method, genericsAndBounds, genericsAndBoundsMethod, hasGen);
|
NormalMethod meth = new NormalMethod(method, genericsAndBounds, genericsAndBoundsMethod, hasGen);
|
||||||
@@ -386,6 +476,10 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, SimplifyResult> getSimplifyResults() {
|
||||||
|
return simplifyResults;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
paramsAndLocals = new HashMap<>();
|
paramsAndLocals = new HashMap<>();
|
||||||
@@ -440,7 +534,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
public void visit(FieldVar fieldVar) {
|
public void visit(FieldVar fieldVar) {
|
||||||
System.out.println("In FieldVar ---");
|
System.out.println("In FieldVar ---");
|
||||||
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
|
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
|
||||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L"+fieldVar.getType()+";", null, null);
|
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L" + fieldVar.getType() + ";",
|
||||||
|
null, null);
|
||||||
fv.visitEnd();
|
fv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,9 +555,18 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
if (sig.charAt(sig.length() - 1) != (";").charAt(0)) {
|
if (sig.charAt(sig.length() - 1) != (";").charAt(0)) {
|
||||||
sig += ";";
|
sig += ";";
|
||||||
}
|
}
|
||||||
cw.visitField(field.modifier, field.getName(),
|
String nameAndDesc = field.getName() + "%%" + des;
|
||||||
des, sig,
|
String nameAndSig = field.getName() + "%%" + sig;
|
||||||
null);
|
if (fieldNameAndParamsT.contains(nameAndDesc)) {
|
||||||
|
if (fieldNameSignature.contains(nameAndSig)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new BytecodeGeneratorError("Bytecode generation aborted due to duplicate field name&signature");
|
||||||
|
}
|
||||||
|
fieldNameAndParamsT.add(nameAndDesc);
|
||||||
|
fieldNameSignature.add(nameAndSig);
|
||||||
|
|
||||||
|
cw.visitField(field.modifier, field.getName(), des, sig, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -643,5 +747,4 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -33,12 +33,14 @@ import org.objectweb.asm.Type;
|
|||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodCallHelper;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
@@ -52,6 +54,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import javassist.NotFoundException;
|
||||||
|
|
||||||
public class BytecodeGenMethod implements StatementVisitor {
|
public class BytecodeGenMethod implements StatementVisitor {
|
||||||
|
|
||||||
@@ -675,7 +678,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
methSig.visitReturnType().visitTypeVariable("R");
|
methSig.visitReturnType().visitTypeVariable("R");
|
||||||
// ")"+lam.getReturn.getBounds
|
// ")"+lam.getReturn.getBounds
|
||||||
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
Signature sig = new Signature(numberOfParams);
|
||||||
String name = "Fun" + numberOfParams + "$$";
|
String name = "Fun" + numberOfParams + "$$";
|
||||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
Type.getInternalName(Object.class), null);
|
Type.getInternalName(Object.class), null);
|
||||||
@@ -772,7 +775,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
java.lang.reflect.Method methodRefl = null;
|
java.lang.reflect.Method methodRefl = null;
|
||||||
String clazz = receiverName.replace("/", ".");
|
String clazz = receiverName.replace("/", ".");
|
||||||
// if(!receiverName.equals(className)) {
|
|
||||||
|
String mDesc = "";
|
||||||
|
|
||||||
|
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
||||||
|
|
||||||
|
boolean toCreate = false;
|
||||||
|
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
||||||
// This will be used if the class is not standard class (not in API)
|
// This will be used if the class is not standard class (not in API)
|
||||||
ClassLoader cLoader2;
|
ClassLoader cLoader2;
|
||||||
@@ -789,28 +798,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
methodRefl = getMethod(methodCall.name, methodCall.arglist.getArguments().size(), methods);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// try {
|
|
||||||
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
|
||||||
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
|
||||||
// System.out.println("Methods of " + receiverName + " ");
|
|
||||||
// for(int i = 0; i<methods.length; i++) {
|
|
||||||
// System.out.println(methods[i]);
|
|
||||||
// }
|
|
||||||
// methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
|
||||||
// }catch (Exception e2) {
|
|
||||||
String superClass = "";
|
String superClass = "";
|
||||||
// TODO: Test SubMatrix.jav
|
|
||||||
while(true) {
|
while(true) {
|
||||||
for(ClassOrInterface cl : sf.getClasses()) {
|
try {
|
||||||
if(receiverName.equals(cl.getClassName().toString())) {
|
superClass = helper.getSuperClass(receiverName);
|
||||||
superClass = cl.getSuperClass().getName().toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(superClass);
|
|
||||||
|
|
||||||
if(superClass.equals(""))
|
|
||||||
break;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String superClazz = superClass.replace("/", ".");
|
String superClazz = superClass.replace("/", ".");
|
||||||
@@ -832,12 +823,26 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
receiverName = superClass;
|
receiverName = superClass;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} catch (NotInCurrentPackageException e2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null) {
|
||||||
|
toCreate = !receiverName.equals(className) && helper.isInCurrPkg(clazz);
|
||||||
|
if(toCreate) {
|
||||||
|
try {
|
||||||
|
mDesc = helper.getDesc(clazz);
|
||||||
|
} catch (NotInCurrentPackageException | NotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else if(!helper.isInCurrPkg(clazz)){
|
||||||
|
if(clazz.contains("$$")) {
|
||||||
|
mDesc = helper.generateBCForFunN();
|
||||||
|
}else {
|
||||||
try {
|
try {
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
@@ -848,24 +853,24 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
||||||
}
|
}
|
||||||
catch (Exception e2) {
|
catch (Exception e2) {
|
||||||
System.out.println("");
|
e2.printStackTrace();
|
||||||
//do nothing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
|
|
||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
String mDesc = "";
|
|
||||||
List<Boolean> argListMethCall = new LinkedList<>();
|
List<Boolean> argListMethCall = new LinkedList<>();
|
||||||
String receiverRefl="";
|
String receiverRefl="";
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null && receiverName.equals(className)) {
|
||||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||||
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
} else {
|
} else if(methodRefl != null) {
|
||||||
System.out.println(methodCall.name + " -> Refl != null");
|
System.out.println(methodCall.name + " -> Refl != null");
|
||||||
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
||||||
for(Parameter p:methodRefl.getParameters()) {
|
for(Parameter p:methodRefl.getParameters()) {
|
||||||
@@ -880,6 +885,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
al.accept(argV);
|
al.accept(argV);
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
methodCall.arglist.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Methodcall ("+ methodCall.name +") Desc : " + mDesc);
|
System.out.println("Methodcall ("+ methodCall.name +") Desc : " + mDesc);
|
||||||
@@ -917,6 +924,19 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDescForMethInCurrPkg(String name) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInCurrPkg(String superClass) {
|
||||||
|
for(ClassOrInterface cl : sf.KlassenVektor) {
|
||||||
|
if(superClass.equals(cl.getClassName().toString()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private String[] getTypes(List<Expression> arguments) {
|
private String[] getTypes(List<Expression> arguments) {
|
||||||
String[] types = new String[arguments.size()];
|
String[] types = new String[arguments.size()];
|
||||||
for(int i = 0; i<arguments.size(); ++i) {
|
for(int i = 0; i<arguments.size(); ++i) {
|
||||||
@@ -1252,10 +1272,16 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
visitBooleanLiteral((Boolean) value);
|
visitBooleanLiteral((Boolean) value);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case "java/lang/Byte":
|
||||||
|
if(value instanceof Double)
|
||||||
visitByteLiteral(((Double) value).byteValue(), false);
|
visitByteLiteral(((Double) value).byteValue(), false);
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitByteLiteral(((Integer) value).byteValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case "java/lang/Short":
|
||||||
|
if(value instanceof Double)
|
||||||
visitShortLiteral(((Double) value).shortValue(), false);
|
visitShortLiteral(((Double) value).shortValue(), false);
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitShortLiteral(((Integer) value).shortValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Integer":
|
case "java/lang/Integer":
|
||||||
// zweite Argument isLong
|
// zweite Argument isLong
|
||||||
@@ -1266,10 +1292,16 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
visitIntegerLiteral(((Integer) value).intValue(), false);
|
visitIntegerLiteral(((Integer) value).intValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case "java/lang/Long":
|
||||||
|
if(value instanceof Double)
|
||||||
|
visitLongLiteral(((Double) value).longValue(), true);
|
||||||
|
if(value instanceof Integer)
|
||||||
visitLongLiteral(((Integer) value).longValue(), true);
|
visitLongLiteral(((Integer) value).longValue(), true);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case "java/lang/Float":
|
||||||
|
if(value instanceof Double)
|
||||||
visitFloatLiteral(((Double) value).floatValue());
|
visitFloatLiteral(((Double) value).floatValue());
|
||||||
|
if(value instanceof Integer)
|
||||||
|
visitFloatLiteral(((Integer) value).floatValue());
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case "java/lang/Double":
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
|
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BytecodeGeneratorError extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public BytecodeGeneratorError(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NotFoundException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public NotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NotInCurrentPackageException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public NotInCurrentPackageException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -5,7 +5,11 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
@@ -13,13 +17,18 @@ import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
|
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.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,14 +38,14 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
public class TPHExtractor extends AbstractASTWalker {
|
public class TPHExtractor extends AbstractASTWalker {
|
||||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
final HashMap<TypePlaceholder, Boolean> allTPHS = new HashMap<>();
|
final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
|
|
||||||
Boolean inMethod = false;
|
Boolean inMethod = false;
|
||||||
boolean inLocalOrParam = false;
|
boolean inLocalOrParam = false;
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
|
|
||||||
@@ -58,19 +67,80 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
allTPHS.put(resolvedTPH, inMethod);
|
allTPHS.put(resolvedTPH.getName(), inMethod);
|
||||||
resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
// final List<TPHConstraint> cons = new ArrayList<>();
|
||||||
if (ag.contains(resolvedTPH) && ag.TA1.equals(resolvedTPH) && !contains(allPairs, ag)) {
|
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
||||||
|
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
|
// cons.add(con);
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// Map<TPHConstraint, Boolean> visitMap = new HashMap<>();
|
||||||
|
// for(TPHConstraint cc : cons) {
|
||||||
|
// visitMap.put(cc, false);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// String left = resolvedTPH.getName();
|
||||||
|
// for (TPHConstraint cc : visitMap.keySet()) {
|
||||||
|
//
|
||||||
|
// if(visitMap.get(cc))
|
||||||
|
// continue;
|
||||||
|
//
|
||||||
|
// if (cc.getLeft().equals(left)) {
|
||||||
|
// allCons.add(cc);
|
||||||
|
// List<TPHConstraint> toVisit = getToVisitCons(cons,cc.getRight(), visitMap);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
//resultSet.resolveType(tph).getAdditionalGenerics().forEach(ag -> {
|
||||||
|
resultSet.genIns.forEach(ag -> {
|
||||||
|
|
||||||
|
// if (ag.contains(resolvedTPH) /* && ag.TA1.equals(resolvedTPH) */ && !contains(allPairs, ag)) {
|
||||||
if (inMethod)
|
if (inMethod)
|
||||||
methodAndTph.getPairs().add(ag);
|
methodAndTph.getPairs().add(ag);
|
||||||
allPairs.add(ag);
|
allPairs.add(ag);
|
||||||
TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
||||||
|
if(!containsConstraint(allCons,con))
|
||||||
allCons.add(con);
|
allCons.add(con);
|
||||||
}
|
// }
|
||||||
});
|
});
|
||||||
|
} else if (resultSet.resolveType(tph).resolvedType instanceof RefType) {
|
||||||
|
RefType rt = (RefType) resultSet.resolveType(tph).resolvedType;
|
||||||
|
rt.accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
||||||
|
for(TPHConstraint con:allCons) {
|
||||||
|
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TPHConstraint> getToVisitCons(List<TPHConstraint> cons, String right, Map<TPHConstraint, Boolean> visitMap) {
|
||||||
|
List<TPHConstraint> res = new ArrayList<>();
|
||||||
|
for(TPHConstraint cc : cons) {
|
||||||
|
if(cc.getLeft().equals(right)) {
|
||||||
|
res.add(cc);
|
||||||
|
if(visitMap.get(cc))
|
||||||
|
visitMap.replace(cc, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(GenericRefType genericRefType) {
|
||||||
|
String name = genericRefType.getParsedName();
|
||||||
|
if (inMethod) {
|
||||||
|
methodAndTph.getLocalTphs().add(name);
|
||||||
|
if (inLocalOrParam)
|
||||||
|
methodAndTph.getLocalTphs().add(name);
|
||||||
|
}
|
||||||
|
allTPHS.put(name, inMethod);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||||
for (int i = 0; i < pairs.size(); ++i) {
|
for (int i = 0; i < pairs.size(); ++i) {
|
||||||
GenericInsertPair p = pairs.get(i);
|
GenericInsertPair p = pairs.get(i);
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.bytecode.descriptor;
|
package de.dhbwstuttgart.bytecode.descriptor;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
@@ -44,20 +45,31 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
if(method.hasGen()) {
|
if(method.hasGen()) {
|
||||||
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
|
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
|
||||||
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
|
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
|
||||||
desc += "L"+method.getGenericsAndBoundsMethod().get(fpDesc)+ ";";
|
String bound = getBound(fpDesc, method.getGenericsAndBoundsMethod());
|
||||||
|
desc += "L"+bound+ ";";
|
||||||
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
|
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
|
||||||
desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";";
|
String bound = getBound(fpDesc, method.getGenericsAndBounds());
|
||||||
|
desc += "L"+bound+ ";";
|
||||||
}else {
|
}else {
|
||||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
||||||
// Bound ist immer Object
|
// Bound ist immer Object
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
|
} else {
|
||||||
|
// TODO::
|
||||||
|
if(method.getGenericsAndBounds().containsKey(resType)) {
|
||||||
|
String bound = getBound(resType, method.getGenericsAndBounds());
|
||||||
|
desc += "L"+bound+ ";";
|
||||||
|
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
|
||||||
|
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
|
||||||
|
desc += "L"+bound+ ";";
|
||||||
} else {
|
} else {
|
||||||
desc += "L"+resType+ ";";
|
desc += "L"+resType+ ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//TODO: generate a class java%% ... %%
|
//TODO: generate a class java%% ... %%
|
||||||
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
|
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
|
||||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
|
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
|
||||||
@@ -78,11 +90,21 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
||||||
}else {
|
}else {
|
||||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
||||||
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
} else {
|
} else {
|
||||||
desc += ")" + "L"+resType+ ";";
|
// TODO::
|
||||||
|
if(method.getGenericsAndBounds().containsKey(resType)) {
|
||||||
|
String bound = getBound(resType, method.getGenericsAndBounds());
|
||||||
|
desc += ")L"+bound+ ";";
|
||||||
|
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
|
||||||
|
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
|
||||||
|
desc += ")L"+bound+ ";";
|
||||||
|
} else {
|
||||||
|
desc += ")L"+resType+ ";";
|
||||||
|
}
|
||||||
|
// desc += ")" + "L"+resType+ ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
@@ -93,6 +115,15 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getBound(String fpDesc, HashMap<String, String> genericsAndBounds) {
|
||||||
|
String start = genericsAndBounds.get(fpDesc);
|
||||||
|
while(genericsAndBounds.containsKey(start)) {
|
||||||
|
start = genericsAndBounds.get(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(NormalConstructor constructor) {
|
public String visit(NormalConstructor constructor) {
|
||||||
String desc = "(";
|
String desc = "(";
|
||||||
@@ -131,7 +162,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
while(itr.hasNext()) {
|
while(itr.hasNext()) {
|
||||||
FormalParameter fp = itr.next();
|
FormalParameter fp = itr.next();
|
||||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
if(d.contains("TPH ") ||d.contains("<")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + "L"+ d + ";";
|
desc = desc + "L"+ d + ";";
|
||||||
@@ -140,7 +171,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
|
|
||||||
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
if(retType.contains("TPH ")|| retType.contains("<")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")"+"L"+retType+";";
|
desc = desc + ")"+"L"+retType+";";
|
||||||
@@ -156,7 +187,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
if(d.contains("TPH ") ||d.contains("<")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc += "L"+ d + ";";
|
desc += "L"+ d + ";";
|
||||||
@@ -165,7 +196,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}
|
}
|
||||||
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
if(retType.contains("TPH ")|| retType.contains("<")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")"+"L"+retType+";";
|
desc = desc + ")"+"L"+retType+";";
|
||||||
@@ -179,7 +210,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.substring(0, 4).equals("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
if(d.contains("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||||
@@ -196,7 +227,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
System.out.println("DescriptorToString retType = " + retType);
|
System.out.println("DescriptorToString retType = " + retType);
|
||||||
if(retType.equals("void")) {
|
if(retType.equals("void")) {
|
||||||
desc += ")V";
|
desc += ")V";
|
||||||
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
}else if(retType.contains("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
||||||
|
@@ -41,11 +41,11 @@ public class Signature {
|
|||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private ArrayList<GenericInsertPair> commonPairs;
|
private ArrayList<GenericInsertPair> commonPairs;
|
||||||
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
||||||
private ArrayList<TypePlaceholder> tphsClass;
|
private ArrayList<String> tphsClass;
|
||||||
private ArrayList<TPHConstraint> consClass;
|
private ArrayList<TPHConstraint> consClass;
|
||||||
|
|
||||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||||
ArrayList<GenericInsertPair> commonPairs, ArrayList<TypePlaceholder> tphsClass, ArrayList<TPHConstraint> consClass) {
|
ArrayList<GenericInsertPair> commonPairs, ArrayList<String> tphsClass, ArrayList<TPHConstraint> consClass) {
|
||||||
this.classOrInterface = classOrInterface;
|
this.classOrInterface = classOrInterface;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.commonPairs = commonPairs;
|
this.commonPairs = commonPairs;
|
||||||
@@ -80,12 +80,12 @@ public class Signature {
|
|||||||
createSignatureForConsOrMethod(this.method,false);
|
createSignatureForConsOrMethod(this.method,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(LambdaExpression lambdaExpression,int numberOfParams) {
|
public Signature(int numberOfParams) {
|
||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForFunN(lambdaExpression, numberOfParams);
|
createSignatureForFunN(numberOfParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
|
private void createSignatureForFunN(int numberOfParams) {
|
||||||
|
|
||||||
// sw.visitClassBound().visitEnd();
|
// sw.visitClassBound().visitEnd();
|
||||||
for(int i = 0;i<numberOfParams;i++) {
|
for(int i = 0;i<numberOfParams;i++) {
|
||||||
@@ -235,8 +235,9 @@ public class Signature {
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
||||||
if(resolved instanceof TypePlaceholder) {
|
if(resolved instanceof TypePlaceholder) {
|
||||||
resType.additionalGenerics.forEach(ag ->{
|
//resType.getAdditionalGenerics().forEach(ag ->{
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
resultSet.genIns.forEach(ag ->{
|
||||||
|
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
||||||
if(!contains(res,constr)) {
|
if(!contains(res,constr)) {
|
||||||
res.add(constr);
|
res.add(constr);
|
||||||
}
|
}
|
||||||
@@ -246,8 +247,9 @@ public class Signature {
|
|||||||
WildcardType resWC = (WildcardType) resolved;
|
WildcardType resWC = (WildcardType) resolved;
|
||||||
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
||||||
if(resType2.resolvedType instanceof TypePlaceholder) {
|
if(resType2.resolvedType instanceof TypePlaceholder) {
|
||||||
resType2.additionalGenerics.forEach(ag ->{
|
//resType2.getAdditionalGenerics().forEach(ag ->{
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
resultSet.genIns.forEach(ag ->{
|
||||||
|
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
||||||
if(!contains(res,constr)) {
|
if(!contains(res,constr)) {
|
||||||
res.add(constr);
|
res.add(constr);
|
||||||
}
|
}
|
||||||
@@ -290,7 +292,8 @@ public class Signature {
|
|||||||
break;
|
break;
|
||||||
case "GRT":
|
case "GRT":
|
||||||
GenericRefType g = (GenericRefType) t;
|
GenericRefType g = (GenericRefType) t;
|
||||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
// sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
||||||
|
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
||||||
break;
|
break;
|
||||||
case "TPH":
|
case "TPH":
|
||||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||||
@@ -301,16 +304,27 @@ public class Signature {
|
|||||||
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
||||||
//
|
//
|
||||||
String sig2 = r.acceptTV(new TypeToSignature());
|
String sig2 = r.acceptTV(new TypeToSignature());
|
||||||
String eqTPH = getEqualTPH(methodConstraints, sig2.substring(1, sig2.length()-1))+"$";
|
if(r instanceof GenericRefType) {
|
||||||
if(!(r instanceof TypePlaceholder)) {
|
sv.visitTypeVariable(sig2);
|
||||||
|
}else if(!(r instanceof TypePlaceholder)) {
|
||||||
if(sig2.contains("$$")) {
|
if(sig2.contains("$$")) {
|
||||||
System.out.println(" Signature FUN$$: "+r);
|
System.out.println(" Signature FUN$$: "+r);
|
||||||
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
||||||
} else {
|
} else {
|
||||||
sv.visitClassType(sig2.substring(1, sig2.length()));
|
// Kann zwischen GenericRefType und RefType nicht unterscheiden
|
||||||
|
// Deswegen wird immer geprüft, ob der Name in Generic Maps liegt
|
||||||
|
String n = sig2.substring(1, sig2.length()-1);
|
||||||
|
// if(genericsAndBoundsMethod.containsKey(n) || genericsAndBounds.containsKey(n)) {
|
||||||
|
// sv.visitTypeVariable(n);
|
||||||
|
// } else {
|
||||||
|
sv.visitClassType(n);
|
||||||
|
sv.visitEnd();
|
||||||
|
// }
|
||||||
|
// sv.visitClassType(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
String eqTPH = getEqualTPH(methodConstraints, sig2.substring(1, sig2.length()-1))+"$";
|
||||||
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
||||||
sv.visitTypeVariable(eqTPH);
|
sv.visitTypeVariable(eqTPH);
|
||||||
}
|
}
|
||||||
@@ -456,10 +470,15 @@ public class Signature {
|
|||||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||||
// System.out.println("GetBounds: " + boundDesc);
|
// System.out.println("GetBounds: " + boundDesc);
|
||||||
// Ensure that <...> extends java.lang.Object OR ...
|
// Ensure that <...> extends java.lang.Object OR ...
|
||||||
|
if(b instanceof GenericRefType) {
|
||||||
|
sw.visitClassBound().visitTypeVariable(boundDesc);
|
||||||
|
} else {
|
||||||
sw.visitClassBound().visitClassType(boundDesc);
|
sw.visitClassBound().visitClassType(boundDesc);
|
||||||
|
sw.visitClassBound().visitEnd();
|
||||||
|
}
|
||||||
genAndBounds.put(g.getName(), boundDesc);
|
genAndBounds.put(g.getName(), boundDesc);
|
||||||
}
|
}
|
||||||
sw.visitClassBound().visitEnd();
|
// sw.visitClassBound().visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@@ -2,14 +2,17 @@ package de.dhbwstuttgart.bytecode.utilities;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
public class MethodAndTPH {
|
public class MethodAndTPH {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private final ArrayList<String> tphs = new ArrayList<>();
|
private final ArrayList<String> tphs = new ArrayList<>();
|
||||||
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
//private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||||
|
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||||
// tphs of local variables and parameters
|
// tphs of local variables and parameters
|
||||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
|
|
||||||
@@ -21,7 +24,10 @@ public class MethodAndTPH {
|
|||||||
return tphs;
|
return tphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<GenericInsertPair> getPairs(){
|
// public ArrayList<GenericInsertPair> getPairs(){
|
||||||
|
// return pairs;
|
||||||
|
// }
|
||||||
|
public ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> getPairs(){
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,255 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
||||||
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import javassist.NotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MethodCallHelper {
|
||||||
|
private MethodCall methCall;
|
||||||
|
private SourceFile sourceFile;
|
||||||
|
private ResultSet resultSet;
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param methCall
|
||||||
|
* @param sourceFile
|
||||||
|
* @param resultSet
|
||||||
|
* @param path TODO
|
||||||
|
*/
|
||||||
|
public MethodCallHelper(MethodCall methCall, SourceFile sourceFile, ResultSet resultSet, String path) {
|
||||||
|
this.methCall = methCall;
|
||||||
|
this.sourceFile = sourceFile;
|
||||||
|
this.resultSet = resultSet;
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
|
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInCurrPkg(String className) {
|
||||||
|
for (ClassOrInterface cl : sourceFile.KlassenVektor) {
|
||||||
|
if (className.equals(cl.getClassName().toString()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuperClass(String className) throws NotInCurrentPackageException {
|
||||||
|
|
||||||
|
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
|
if (className.equals(cl.getClassName().toString())) {
|
||||||
|
return cl.getSuperClass().getName().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotInCurrentPackageException("Class " + className + " is not in the current package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassOrInterface getClassFromCurrPkg(String className) throws NotInCurrentPackageException {
|
||||||
|
for (ClassOrInterface cl : sourceFile.KlassenVektor) {
|
||||||
|
if (className.equals(cl.getClassName().toString()))
|
||||||
|
return cl;
|
||||||
|
}
|
||||||
|
throw new NotInCurrentPackageException("Class of " + className + " is not in the current package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc(String className) throws NotInCurrentPackageException, NotFoundException {
|
||||||
|
String name = methCall.name;
|
||||||
|
ClassOrInterface clazz = getClassFromCurrPkg(className);
|
||||||
|
|
||||||
|
Map<String, String> genAndBoundsClass = getGenericsAndBounds(clazz.getGenerics());
|
||||||
|
modifyGenAndBounds(genAndBoundsClass);
|
||||||
|
for (Method m : clazz.getMethods()) {
|
||||||
|
if (name.equals(m.getName())) {
|
||||||
|
Map<String, String> genAndBoundsMethod = getGenericsAndBoundsMethod(m.getGenerics());
|
||||||
|
modifyGenAndBounds(genAndBoundsMethod);
|
||||||
|
boolean hasGen = hasGen(m, genAndBoundsClass);
|
||||||
|
NormalMethod nm = new NormalMethod(m, (HashMap<String, String>) genAndBoundsClass,
|
||||||
|
(HashMap<String, String>) genAndBoundsMethod, hasGen);
|
||||||
|
return nm.accept(new DescriptorToString(resultSet));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotFoundException("Method " + name + " is not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasGen(Method m, Map<String, String> genericsAndBounds) {
|
||||||
|
String retType = resultSet.resolveType(m.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
|
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
||||||
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ") || retType.contains("<");
|
||||||
|
|
||||||
|
Map<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
||||||
|
Iterator<FormalParameter> itr = m.getParameterList().iterator();
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
FormalParameter fp = itr.next();
|
||||||
|
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
|
||||||
|
}
|
||||||
|
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
|
||||||
|
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
|
||||||
|
if(!hasGenInParameterList) {
|
||||||
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
|
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||||
|
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.contains("TPH ")||sigOfParam.contains("<")) {
|
||||||
|
hasGenInParameterList = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getGenericsAndBoundsMethod(Iterable<? extends GenericTypeVar> generics) {
|
||||||
|
Map<String, String> genAndBounds = new HashMap<>();
|
||||||
|
Iterator<? extends GenericTypeVar> itr = generics.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
GenericTypeVar gtv = itr.next();
|
||||||
|
getBoundsOfTypeVar(gtv, genAndBounds);
|
||||||
|
}
|
||||||
|
return genAndBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyGenAndBounds(Map<String, String> genAndBoundsClass) {
|
||||||
|
List<String> visited = new ArrayList<>(genAndBoundsClass.size());
|
||||||
|
Map<String, String> toReplace = new HashMap<>();
|
||||||
|
for (String tv : genAndBoundsClass.keySet()) {
|
||||||
|
|
||||||
|
if (visited.contains(tv))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
List<String> types = new LinkedList<>();
|
||||||
|
String bound = genAndBoundsClass.get(tv);
|
||||||
|
types.add(tv);
|
||||||
|
visited.add(tv);
|
||||||
|
boolean doReplace = false;
|
||||||
|
while (genAndBoundsClass.keySet().contains(bound)) {
|
||||||
|
doReplace = true;
|
||||||
|
types.add(bound);
|
||||||
|
visited.add(bound);
|
||||||
|
bound = genAndBoundsClass.get(bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doReplace) {
|
||||||
|
for (String tt : types) {
|
||||||
|
toReplace.put(tt, bound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String key : toReplace.keySet()) {
|
||||||
|
genAndBoundsClass.replace(key, toReplace.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getGenericsAndBounds(GenericDeclarationList generics) {
|
||||||
|
Map<String, String> genAndBounds = new HashMap<>();
|
||||||
|
Iterator<GenericTypeVar> itr = generics.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
GenericTypeVar gtv = itr.next();
|
||||||
|
getBoundsOfTypeVar(gtv, genAndBounds);
|
||||||
|
}
|
||||||
|
return genAndBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getBoundsOfTypeVar(GenericTypeVar g, Map<String, String> genAndBounds) {
|
||||||
|
|
||||||
|
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
||||||
|
while (bItr.hasNext()) {
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric b = bItr.next();
|
||||||
|
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||||
|
genAndBounds.put(g.getName(), boundDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateBCForFunN() {
|
||||||
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
|
|
||||||
|
int numberOfParams = 0;
|
||||||
|
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||||
|
Iterator<Expression> itr1 = methCall.arglist.getArguments().iterator();
|
||||||
|
String methDesc = "(";
|
||||||
|
while(itr1.hasNext()) {
|
||||||
|
numberOfParams++;
|
||||||
|
// getBounds
|
||||||
|
paramVisitor.visitTypeVariable("T" + numberOfParams);
|
||||||
|
methDesc += "L" + Type.getInternalName(Object.class) + ";";
|
||||||
|
itr1.next();
|
||||||
|
}
|
||||||
|
methDesc += ")L" + Type.getInternalName(Object.class) + ";";
|
||||||
|
|
||||||
|
methSig.visitReturnType().visitTypeVariable("R");
|
||||||
|
// ")"+lam.getReturn.getBounds
|
||||||
|
Signature sig = new Signature(numberOfParams);
|
||||||
|
String name = "Fun" + numberOfParams + "$$";
|
||||||
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
|
Type.getInternalName(Object.class), null);
|
||||||
|
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||||
|
methSig.toString(), null);
|
||||||
|
mvApply.visitEnd();
|
||||||
|
writeClassFile(classWriter.toByteArray(), name);
|
||||||
|
return methDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeClassFile(byte[] bytecode, String name) {
|
||||||
|
FileOutputStream output;
|
||||||
|
try {
|
||||||
|
System.out.println("generating " + name + ".class file...");
|
||||||
|
output = new FileOutputStream(
|
||||||
|
new File(path + name + ".class"));
|
||||||
|
output.write(bytecode);
|
||||||
|
output.close();
|
||||||
|
System.out.println(name + ".class file generated");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -23,6 +23,7 @@ public class MethodFromMethodCall {
|
|||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArgumentList getArgList() {
|
public ArgumentList getArgList() {
|
||||||
return argList;
|
return argList;
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
public class Simplify {
|
public class Simplify {
|
||||||
|
|
||||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
||||||
ArrayList<TypePlaceholder> tphsClass) {
|
ArrayList<String> tphsClass) {
|
||||||
// 1. check if there are any simple cycles like L<R and R<L:
|
// 1. check if there are any simple cycles like L<R and R<L:
|
||||||
// a) yes => set L=R and:
|
// a) yes => set L=R and:
|
||||||
// * remove both constraints
|
// * remove both constraints
|
||||||
@@ -38,9 +38,11 @@ public class Simplify {
|
|||||||
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
|
|
||||||
for(TPHConstraint c : tphExtractor.allCons) {
|
for(TPHConstraint c : tphExtractor.allCons) {
|
||||||
|
if(!containsConstraint(allCons,c)) {
|
||||||
TPHConstraint nc = new TPHConstraint(c.getLeft(), c.getRight(), c.getRel());
|
TPHConstraint nc = new TPHConstraint(c.getLeft(), c.getRight(), c.getRel());
|
||||||
allCons.add(nc);
|
allCons.add(nc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||||
|
|
||||||
// get all tph of the method
|
// get all tph of the method
|
||||||
@@ -382,7 +384,7 @@ public class Simplify {
|
|||||||
|
|
||||||
if (!containTPH(methodTphs, superTphRes)) {
|
if (!containTPH(methodTphs, superTphRes)) {
|
||||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons, superTphRes);
|
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons, superTphRes);
|
||||||
if (classTPHSContainsTPH(tphsClass, superTphRes)) {
|
if (tphsClass.contains(superTphRes)/*classTPHSContainsTPH(tphsClass, superTphRes)*/) {
|
||||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||||
} else {
|
} else {
|
||||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS),
|
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS),
|
||||||
@@ -450,6 +452,15 @@ public class Simplify {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
||||||
|
for(TPHConstraint con:allCons) {
|
||||||
|
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static void updateEqualCons(Map<String, List<String>> replRes, ArrayList<TPHConstraint> eqCons) {
|
private static void updateEqualCons(Map<String, List<String>> replRes, ArrayList<TPHConstraint> eqCons) {
|
||||||
List<String> oldNames = replRes.values().iterator().next();
|
List<String> oldNames = replRes.values().iterator().next();
|
||||||
String newName = replRes.keySet().iterator().next();
|
String newName = replRes.keySet().iterator().next();
|
||||||
@@ -463,7 +474,7 @@ public class Simplify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraintsClass(TPHExtractor tphExtractor,
|
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraintsClass(TPHExtractor tphExtractor,
|
||||||
ArrayList<TypePlaceholder> tphsClass) {
|
ArrayList<String> tphsClass) {
|
||||||
// all constraints that will be simplified
|
// all constraints that will be simplified
|
||||||
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||||
@@ -627,7 +638,9 @@ public class Simplify {
|
|||||||
if (isTPHInConstraint(result, sub))
|
if (isTPHInConstraint(result, sub))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!classTPHSContainsTPH(tphsClass, sub))
|
// if (!classTPHSContainsTPH(tphsClass, sub))
|
||||||
|
// continue;
|
||||||
|
if (!tphsClass.contains(sub))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (numOfVisitedPairs >= size)
|
if (numOfVisitedPairs >= size)
|
||||||
@@ -656,7 +669,7 @@ public class Simplify {
|
|||||||
// add X at the beginning of the list.
|
// add X at the beginning of the list.
|
||||||
while (subAndSuper.containsValue(subTphRes)) {
|
while (subAndSuper.containsValue(subTphRes)) {
|
||||||
for (String tph : subAndSuper.keySet()) {
|
for (String tph : subAndSuper.keySet()) {
|
||||||
if (classTPHSContainsTPH(tphsClass, tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
if (/*classTPHSContainsTPH(tphsClass, tph)*/tphsClass.contains(tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
||||||
subTphRes = tph;
|
subTphRes = tph;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SimplifyResult {
|
||||||
|
private final ArrayList<TPHConstraint> classConstraints;
|
||||||
|
private final ArrayList<String> tphsClass;
|
||||||
|
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
|
||||||
|
|
||||||
|
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<String> tphsClass,
|
||||||
|
HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints) {
|
||||||
|
super();
|
||||||
|
this.classConstraints = classConstraints;
|
||||||
|
this.tphsClass = tphsClass;
|
||||||
|
this.methodsConstraints = methodsConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<TPHConstraint> getClassConstraints() {
|
||||||
|
return classConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, HashMap<TPHConstraint, HashSet<String>>> getMethodsConstraints() {
|
||||||
|
return methodsConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getTphsClass() {
|
||||||
|
return tphsClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -3,6 +3,8 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
|
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@@ -37,6 +39,7 @@ import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -50,14 +53,23 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
//import org.apache.commons.io.output.NullOutputStream;
|
//import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
Boolean resultmodel = false;
|
Boolean resultmodel = true;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||||
|
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Äußerste Liste der Source-Files.
|
||||||
|
* Danach Liste der Klassen in Source File.
|
||||||
|
* Danach Map Klassenname
|
||||||
|
*/
|
||||||
|
private List<List<HashMap<String, SimplifyResult>>> simplifyResultsSF = new ArrayList<>();
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile));
|
this(Arrays.asList(sourceFile));
|
||||||
@@ -407,7 +419,7 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
@@ -428,7 +440,7 @@ public class JavaTXCompiler {
|
|||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||||
new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
@@ -547,7 +559,7 @@ public class JavaTXCompiler {
|
|||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
||||||
System.out.println("RESULT Final: " + li.getResults());
|
System.out.println("RESULT Final: " + li.getResults());
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString()+"\n");
|
logFile.write("RES_FINAL: " + li.getResults().toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
@@ -555,8 +567,8 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
//Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
||||||
//Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
@@ -642,7 +654,7 @@ public class JavaTXCompiler {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// um pfad erweitern
|
// um pfad erweitern
|
||||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
|
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
for(File f : sourceFiles.keySet()) {
|
for(File f : sourceFiles.keySet()) {
|
||||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
@@ -650,6 +662,7 @@ public class JavaTXCompiler {
|
|||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
||||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
|
this.simplifyResultsSF.add(bytecodeGen.getSimplifyResultsList());
|
||||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -666,4 +679,8 @@ public class JavaTXCompiler {
|
|||||||
System.out.println(name+".class file generated");
|
System.out.println(name+".class file generated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<List<HashMap<String, SimplifyResult>>> getSimplifyResults() {
|
||||||
|
return simplifyResultsSF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -100,7 +100,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
|
ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
|
||||||
}else{
|
}else{
|
||||||
ret = new ReferenceType(t.getName().toString());
|
ret = new ReferenceType(t.getName().toString(), false);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(GenericRefType t, Boolean innerType){
|
public static UnifyType convert(GenericRefType t, Boolean innerType){
|
||||||
return new ReferenceType(t.getParsedName());
|
return new ReferenceType(t.getParsedName(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(WildcardType t, Boolean innerType){
|
public static UnifyType convert(WildcardType t, Boolean innerType){
|
||||||
@@ -222,12 +222,15 @@ public class UnifyTypeFactory {
|
|||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
||||||
}else if(tr instanceof WildcardType){
|
}else if(tr instanceof WildcardType){
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
||||||
|
}else if(tr instanceof GenericRefType){
|
||||||
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr);
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||||
if(JavaClassName.Void.equals(t.getName()))return new Void(new NullToken());
|
if(JavaClassName.Void.equals(t.getName()))return new Void(new NullToken());
|
||||||
|
if (t.isGenTypeVar()) return new GenericRefType(t.getName(),new NullToken());
|
||||||
RefType ret = new RefType(new JavaClassName(t.getName()),convert(t.getTypeParams(), tphs),new NullToken());
|
RefType ret = new RefType(new JavaClassName(t.getName()),convert(t.getTypeParams(), tphs),new NullToken());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +1,23 @@
|
|||||||
package de.dhbwstuttgart.typedeployment;
|
package de.dhbwstuttgart.typedeployment;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
public class TypeInsert {
|
public class TypeInsert {
|
||||||
/**
|
/**
|
||||||
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
|
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
|
||||||
*/
|
*/
|
||||||
public final TypeInsertPoint point;
|
public final TypeInsertPoint point;
|
||||||
Set<TypeInsertPoint> inserts;
|
Set<TypeInsertPoint> inserts;
|
||||||
|
ResultPair<?, ?> resultPair;
|
||||||
|
|
||||||
public TypeInsert(TypeInsertPoint point, Set<TypeInsertPoint> additionalPoints){
|
public TypeInsert(TypeInsertPoint point, Set<TypeInsertPoint> additionalPoints, ResultPair<?, ?> resultPair){
|
||||||
this.point = point;
|
this.point = point;
|
||||||
inserts = additionalPoints;
|
inserts = additionalPoints;
|
||||||
|
this.resultPair = resultPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String insert(String intoSource){
|
public String insert(String intoSource){
|
||||||
@@ -34,6 +35,10 @@ public class TypeInsert {
|
|||||||
return point.getInsertString();
|
return point.getInsertString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResultPair<?, ?> getResultPair() {
|
||||||
|
return this.resultPair;
|
||||||
|
}
|
||||||
|
|
||||||
/* PL 2018-06-18
|
/* PL 2018-06-18
|
||||||
* Zwei TypeInsert's sind gleich, wenn ihre point's und ihre inserts' gleich sind
|
* Zwei TypeInsert's sind gleich, wenn ihre point's und ihre inserts' gleich sind
|
||||||
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
||||||
|
@@ -32,7 +32,7 @@ public class TypeInsertFactory {
|
|||||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
ResolvedType resolvedType = resultSet.resolveType(type);
|
||||||
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
||||||
new TypeToInsertString(resolvedType.resolvedType).insert);
|
new TypeToInsertString(resolvedType.resolvedType).insert);
|
||||||
return new TypeInsert(insertPoint, new HashSet<>(Arrays.asList(createGenericInsert(resolvedType.additionalGenerics, cl, m))));
|
return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){
|
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){
|
||||||
|
@@ -4,12 +4,14 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TypeInsertPoint {
|
public class TypeInsertPoint {
|
||||||
public final Token point;
|
public Token point;
|
||||||
private String insertString;
|
private String insertString;
|
||||||
|
private int extraOffset = 0;
|
||||||
|
|
||||||
public TypeInsertPoint(Token point, String toInsert){
|
public TypeInsertPoint(Token point, String toInsert){
|
||||||
this.point = point;
|
this.point = point;
|
||||||
@@ -21,13 +23,21 @@ public class TypeInsertPoint {
|
|||||||
//token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
|
//token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
|
||||||
token.point.getStartIndex() <= point.getStartIndex()))
|
token.point.getStartIndex() <= point.getStartIndex()))
|
||||||
.mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
|
.mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
|
||||||
return new StringBuilder(intoSource).insert(point.getStartIndex()+offset, insertString).toString();
|
return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInsertString() {
|
public String getInsertString() {
|
||||||
return insertString;
|
return insertString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addExtraOffset(int toAdd) {
|
||||||
|
this.extraOffset += toAdd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPositionInCode() {
|
||||||
|
return point.getStartIndex() + extraOffset;
|
||||||
|
}
|
||||||
|
|
||||||
/* PL 2018-06-19
|
/* PL 2018-06-19
|
||||||
* Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
|
* Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
|
||||||
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
||||||
|
@@ -23,4 +23,9 @@ public class GenericInsertPair {
|
|||||||
if(TA2.equals(additionalTPH))return true;
|
if(TA2.equals(additionalTPH))return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GenIns(" + TA1.toString() + " < " + TA2.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,4 +21,9 @@ public class PairTPHequalRefTypeOrWildcardType extends ResultPair{
|
|||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "(" + left.toString() + " = " + right.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,4 +20,9 @@ public class PairTPHsmallerTPH extends ResultPair{
|
|||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "(" + left.toString() + " < " + right.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,21 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ResolvedType{
|
public class ResolvedType{
|
||||||
|
private ResultPair<?, ?> resultPair;
|
||||||
|
|
||||||
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
|
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
|
||||||
public final Set<GenericInsertPair> additionalGenerics;
|
//public final Set<GenericInsertPair> additionalGenerics;
|
||||||
|
|
||||||
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
|
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
|
||||||
this.resolvedType = resolvedType;
|
this.resolvedType = resolvedType;
|
||||||
this.additionalGenerics = additionalGenerics;
|
//this.additionalGenerics = additionalGenerics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResultPair(ResultPair<?, ?> resultPair) {
|
||||||
|
this.resultPair = resultPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultPair<?, ?> getResultPair() {
|
||||||
|
return resultPair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,4 +27,36 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "(" + left.toString() + ", " + right.toString() + ")";
|
return "(" + left.toString() + ", " + right.toString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode());
|
||||||
|
result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ResultPair<?,?> other = (ResultPair<?,?>) obj;
|
||||||
|
if (left == null) {
|
||||||
|
if (other.left != null)
|
||||||
|
return false;
|
||||||
|
} else if (!left.getOffset().equals(other.left.getOffset()))
|
||||||
|
return false;
|
||||||
|
if (right == null) {
|
||||||
|
if (other.right != null)
|
||||||
|
return false;
|
||||||
|
} else if (!right.getOffset().equals(other.right.getOffset()))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,34 @@
|
|||||||
package de.dhbwstuttgart.typeinference.result;
|
package de.dhbwstuttgart.typeinference.result;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public class ResultSet {
|
public class ResultSet {
|
||||||
|
|
||||||
public final Set<ResultPair> results;
|
public final Set<ResultPair> results;
|
||||||
public ResultSet(Set<ResultPair> results){
|
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
||||||
this.results = results;
|
|
||||||
|
public ResultSet(Set<ResultPair> set){
|
||||||
|
this.results = set;
|
||||||
|
this.genIns = new HashSet<>();
|
||||||
|
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(ResultPair toCheck) {
|
||||||
|
return this.results.contains(toCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(ResultPair toCheck) {
|
||||||
|
results.remove(toCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
@@ -27,12 +45,24 @@ public class ResultSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Beim Einsetzen eines Generics, müssen die new und Methodenaufrufe verändert werden
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return results.toString();
|
return results.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o instanceof ResultSet) {
|
||||||
|
ResultSet other = (ResultSet)o;
|
||||||
|
return this.results.equals(other.results);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return results.hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Resolver implements ResultSetVisitor {
|
class Resolver implements ResultSetVisitor {
|
||||||
@@ -40,6 +70,7 @@ class Resolver implements ResultSetVisitor {
|
|||||||
private TypePlaceholder toResolve;
|
private TypePlaceholder toResolve;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric resolved;
|
private RefTypeOrTPHOrWildcardOrGeneric resolved;
|
||||||
private final Set<GenericInsertPair> additionalTPHs = new HashSet<>();
|
private final Set<GenericInsertPair> additionalTPHs = new HashSet<>();
|
||||||
|
private ResultPair<?,?> currentPair;
|
||||||
|
|
||||||
public Resolver(ResultSet resultPairs){
|
public Resolver(ResultSet resultPairs){
|
||||||
this.result = resultPairs;
|
this.result = resultPairs;
|
||||||
@@ -49,23 +80,28 @@ class Resolver implements ResultSetVisitor {
|
|||||||
toResolve = tph;
|
toResolve = tph;
|
||||||
resolved = null;
|
resolved = null;
|
||||||
System.out.println(tph.toString());
|
System.out.println(tph.toString());
|
||||||
for(ResultPair resultPair : result.results){
|
for(ResultPair<?,?> resultPair : result.results) {
|
||||||
if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
|
if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
|
||||||
|
currentPair = resultPair;
|
||||||
return resolve(((PairTPHEqualTPH) resultPair).getRight());
|
return resolve(((PairTPHEqualTPH) resultPair).getRight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(ResultPair resultPair : result.results){
|
for(ResultPair<?,?> resultPair : result.results){
|
||||||
|
currentPair = resultPair;
|
||||||
resultPair.accept(this);
|
resultPair.accept(this);
|
||||||
}
|
}
|
||||||
if(resolved==null){//TPH kommt nicht im Result vor:
|
if(resolved==null){//TPH kommt nicht im Result vor:
|
||||||
resolved = tph;
|
resolved = tph;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResolvedType(resolved, additionalTPHs);//resolved;
|
ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved;
|
||||||
|
result.setResultPair(currentPair);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(PairTPHsmallerTPH p) {
|
public void visit(PairTPHsmallerTPH p) {
|
||||||
|
currentPair = p;
|
||||||
if(p.left.equals(toResolve)){
|
if(p.left.equals(toResolve)){
|
||||||
additionalTPHs.add(new GenericInsertPair(p.left, p.right));
|
additionalTPHs.add(new GenericInsertPair(p.left, p.right));
|
||||||
additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
|
additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
|
||||||
@@ -76,6 +112,7 @@ class Resolver implements ResultSetVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
||||||
|
currentPair = p;
|
||||||
if(p.left.equals(toResolve)){
|
if(p.left.equals(toResolve)){
|
||||||
resolved = p.right;
|
resolved = p.right;
|
||||||
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
|
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
|
||||||
@@ -121,6 +158,7 @@ class Resolver implements ResultSetVisitor {
|
|||||||
/**
|
/**
|
||||||
* Sucht aus dem Result Set den Sub/supertyp für einen TPH
|
* Sucht aus dem Result Set den Sub/supertyp für einen TPH
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
class TPHResolver implements ResultSetVisitor {
|
class TPHResolver implements ResultSetVisitor {
|
||||||
|
|
||||||
private final TypePlaceholder tph;
|
private final TypePlaceholder tph;
|
||||||
@@ -189,6 +227,7 @@ class TPHResolver implements ResultSetVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
class RelatedTypeWalker implements ResultSetVisitor {
|
class RelatedTypeWalker implements ResultSetVisitor {
|
||||||
|
|
||||||
final Set<GenericInsertPair> relatedTPHs = new HashSet<>();
|
final Set<GenericInsertPair> relatedTPHs = new HashSet<>();
|
||||||
|
@@ -312,6 +312,9 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(numericAdditionOrStringConcatenation.size()<1){
|
||||||
|
throw new TypeinferenceException("Kein Typ für " + binary.operation.toString() + " vorhanden", binary.getOffset());
|
||||||
|
}
|
||||||
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
||||||
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
||||||
@@ -355,6 +358,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
||||||
*/
|
*/
|
||||||
//Testeise eingefuegt PL 2018-05-24
|
//Testeise eingefuegt PL 2018-05-24
|
||||||
|
//Hier sollte evtl. noch importe angefragt werden PL 2019-05-07
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
//Rückgabetyp ist Boolean
|
//Rückgabetyp ist Boolean
|
||||||
|
@@ -3,10 +3,12 @@ package de.dhbwstuttgart.typeinference.unify;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
@@ -26,8 +28,8 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
@@ -52,8 +54,8 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -70,8 +72,8 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
@@ -103,8 +105,8 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
try {
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
||||||
|
@@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -17,8 +18,8 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> setToFlatten;
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
}
|
}
|
||||||
@@ -38,9 +39,17 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
*/
|
*/
|
||||||
|
|
||||||
noOfThread--;
|
noOfThread--;
|
||||||
|
synchronized (usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
|
else {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void closeLogFile() {
|
public void closeLogFile() {
|
||||||
|
|
||||||
|
@@ -19,6 +19,10 @@ import java.util.function.BinaryOperator;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
@@ -44,6 +48,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Pair;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
@@ -117,6 +122,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
static Integer noShortendElements = 0;
|
static Integer noShortendElements = 0;
|
||||||
|
|
||||||
|
Boolean myIsCanceled = false;
|
||||||
|
|
||||||
|
volatile UnifyTaskModel usedTasks;
|
||||||
|
|
||||||
public TypeUnifyTask() {
|
public TypeUnifyTask() {
|
||||||
rules = new RuleSet();
|
rules = new RuleSet();
|
||||||
}
|
}
|
||||||
@@ -136,7 +145,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||||
@@ -163,14 +172,26 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
thNo = totalnoOfThread;
|
thNo = totalnoOfThread;
|
||||||
writeLog("thNo2 " + thNo);
|
writeLog("thNo2 " + thNo);
|
||||||
try {
|
try {
|
||||||
this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo));
|
this.logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||||
|
new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
|
||||||
|
logFile.write("");
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("log-File nicht vorhanden");
|
System.err.println("log-File nicht vorhanden");
|
||||||
}
|
}
|
||||||
|
/*Abbruchtest
|
||||||
|
if (thNo > 10) {
|
||||||
|
System.out.println("cancel");
|
||||||
|
usedTasks.cancel();
|
||||||
|
writeLog(nOfUnify.toString() + "cancel");
|
||||||
|
System.out.println("cancel");
|
||||||
|
}
|
||||||
|
*/
|
||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
this.rekTiefeField = rekTiefe;
|
this.rekTiefeField = rekTiefe;
|
||||||
this.urm = urm;
|
this.urm = urm;
|
||||||
|
this.usedTasks = usedTasks;
|
||||||
|
this.usedTasks.add(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +227,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
void myCancel(Boolean b) {
|
||||||
|
myIsCanceled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean myIsCancelled() {
|
||||||
|
return myIsCanceled;
|
||||||
|
}
|
||||||
|
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
if (one) {
|
if (one) {
|
||||||
@@ -228,8 +256,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
catch (IOException ioE) {
|
catch (IOException ioE) {
|
||||||
System.err.println("no log-File");
|
System.err.println("no log-File");
|
||||||
}
|
}
|
||||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
if (isUndefinedPairSetSet(res)) {
|
||||||
else return res;
|
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
synchronized (usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@Override
|
@Override
|
||||||
@@ -263,6 +302,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/*
|
/*
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
rekTiefe++;
|
rekTiefe++;
|
||||||
nOfUnify++;
|
nOfUnify++;
|
||||||
writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
||||||
@@ -422,6 +462,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// .collect(Collectors.toCollection(HashSet::new));
|
// .collect(Collectors.toCollection(HashSet::new));
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
@@ -478,15 +520,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
||||||
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
||||||
//try {
|
//try {
|
||||||
if (isSolvedForm(eqPrime)) {
|
//if (isSolvedForm(eqPrime)) {
|
||||||
writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
// writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
||||||
}
|
//}
|
||||||
//}
|
//}
|
||||||
//catch (IOException e) {
|
//catch (IOException e) {
|
||||||
// System.err.println("log-File nicht vorhanden");
|
// System.err.println("log-File nicht vorhanden");
|
||||||
//}
|
//}
|
||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
if (finalresult) {
|
if (finalresult && isSolvedForm(eqPrime)) {
|
||||||
|
writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
||||||
urm.notify(eqPrimePrimeSet);
|
urm.notify(eqPrimePrimeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -530,6 +573,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||||
|
|
||||||
fstElems.addAll(topLevelSets.stream()
|
fstElems.addAll(topLevelSets.stream()
|
||||||
.filter(x -> x.size()==1)
|
.filter(x -> x.size()==1)
|
||||||
.map(y -> y.stream().findFirst().get())
|
.map(y -> y.stream().findFirst().get())
|
||||||
@@ -794,9 +838,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
|
synchronized(usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
|
}
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -841,10 +890,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
|
synchronized(usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -887,9 +941,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
|
synchronized(usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
|
}
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -934,10 +993,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
|
synchronized(usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -981,9 +1045,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
|
synchronized(usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
|
}
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -997,10 +1066,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
|
synchronized(usedTasks) {
|
||||||
|
if (this.myIsCancelled()) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -1036,9 +1110,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
result = res;
|
result = res;
|
||||||
if (res.iterator().next() instanceof WildcardType) {
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||||
@@ -1066,8 +1137,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
||||||
//System.out.println(a_last);
|
//System.out.println(a_last);
|
||||||
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});
|
|
||||||
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
||||||
|
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht.
|
||||||
List<PlaceholderType> varsLast_a =
|
List<PlaceholderType> varsLast_a =
|
||||||
a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||||
&& (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType))
|
&& (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType))
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class UnifyTaskModel {
|
||||||
|
|
||||||
|
ArrayList<TypeUnifyTask> usedTasks = new ArrayList<>();
|
||||||
|
|
||||||
|
public synchronized void add(TypeUnifyTask t) {
|
||||||
|
usedTasks.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void cancel() {
|
||||||
|
for(TypeUnifyTask t : usedTasks) {
|
||||||
|
t.myCancel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -11,26 +11,43 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
|||||||
* @author Florian Steurer
|
* @author Florian Steurer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class ReferenceType extends UnifyType {
|
public class ReferenceType extends UnifyType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The buffered hashCode
|
* The buffered hashCode
|
||||||
*/
|
*/
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gibt an, ob der ReferenceType eine generische Typvariable ist
|
||||||
|
*/
|
||||||
|
private final boolean genericTypeVar;
|
||||||
|
|
||||||
|
|
||||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||||
return visitor.visit(this, ht);
|
return visitor.visit(this, ht);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReferenceType(String name, Boolean genericTypeVar) {
|
||||||
|
super(name, new TypeParams());
|
||||||
|
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
||||||
|
this.genericTypeVar = genericTypeVar;
|
||||||
|
}
|
||||||
|
|
||||||
public ReferenceType(String name, UnifyType... params) {
|
public ReferenceType(String name, UnifyType... params) {
|
||||||
super(name, new TypeParams(params));
|
super(name, new TypeParams(params));
|
||||||
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
||||||
|
genericTypeVar = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReferenceType(String name, TypeParams params) {
|
public ReferenceType(String name, TypeParams params) {
|
||||||
super(name, params);
|
super(name, params);
|
||||||
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
||||||
|
genericTypeVar = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGenTypeVar () {
|
||||||
|
return genericTypeVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -137,7 +137,7 @@ public class UnifyPair {
|
|||||||
undefinedPair = true;
|
undefinedPair = true;
|
||||||
}
|
}
|
||||||
public Set<UnifyPair> getSubstitution() {
|
public Set<UnifyPair> getSubstitution() {
|
||||||
return substitution;
|
return new HashSet<>(substitution);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyPair getBasePair() {
|
public UnifyPair getBasePair() {
|
||||||
@@ -149,9 +149,9 @@ public class UnifyPair {
|
|||||||
|
|
||||||
public Set<UnifyPair> getAllSubstitutions () {
|
public Set<UnifyPair> getAllSubstitutions () {
|
||||||
Set<UnifyPair> ret = new HashSet<>();
|
Set<UnifyPair> ret = new HashSet<>();
|
||||||
ret.addAll(getSubstitution());
|
ret.addAll(new ArrayList<>(getSubstitution()));
|
||||||
if (basePair != null) {
|
if (basePair != null) {
|
||||||
ret.addAll(basePair.getAllSubstitutions());
|
ret.addAll(new ArrayList<>(basePair.getAllSubstitutions()));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
37
src/test/java/bytecode/ClassGenLamTest.java
Normal file
37
src/test/java/bytecode/ClassGenLamTest.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class ClassGenLamTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateBC() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/ClassGenLam.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("ClassGenLam");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -12,7 +12,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
public class FunOLTest {
|
public class OLFunTest {
|
||||||
private static String path;
|
private static String path;
|
||||||
private static File fileToTest;
|
private static File fileToTest;
|
||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
@@ -23,13 +23,13 @@ public class FunOLTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateBC() throws Exception {
|
public void generateBC() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/FunOL.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("FunOL");
|
classToTest = loader.loadClass("OLFun");
|
||||||
/*
|
/*
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
38
src/test/java/bytecode/TypedIDTest.java
Normal file
38
src/test/java/bytecode/TypedIDTest.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class TypedIDTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/TypedID.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("TypedID");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
package bytecode;
|
package bytecode;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
8
src/test/resources/bytecode/javFiles/ClassGenLam.jav
Normal file
8
src/test/resources/bytecode/javFiles/ClassGenLam.jav
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class ClassGenLam {
|
||||||
|
lam = x-> x;
|
||||||
|
// public ClassGenLam() {
|
||||||
|
// lam = x->x;
|
||||||
|
// }
|
||||||
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
|
import java.lang.Long;
|
||||||
|
import java.lang.Short;
|
||||||
|
|
||||||
public class Faculty {
|
public class Faculty {
|
||||||
public fact;
|
public fact;
|
||||||
@@ -17,6 +19,7 @@ public class Faculty {
|
|||||||
public getFact(x) {
|
public getFact(x) {
|
||||||
return fact.apply(x);
|
return fact.apply(x);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// m (x) {
|
// m (x) {
|
||||||
//
|
//
|
||||||
//// var fact = (x) -> {
|
//// var fact = (x) -> {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
public class Id<FTU extends FTT,FTT> {
|
public class Id {
|
||||||
|
|
||||||
id(FTU b){
|
id(b){
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,3 +8,4 @@ public class Lambda {
|
|||||||
};
|
};
|
||||||
return lam1;
|
return lam1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -19,7 +19,7 @@ public class Matrix extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mul(java.util.Vector<? extends Vector<? extends java.lang.Integer>> m) {
|
mul(m) {
|
||||||
var ret = new Matrix();
|
var ret = new Matrix();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Byte;
|
//import java.lang.Byte;
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class MatrixOP extends Vector<Vector<Integer>> {
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
@@ -18,7 +18,7 @@ public class MatrixOP extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Fun2$$<java.util.Vector<? extends java.util.Vector<? extends java.lang.Byte>>, java.util.Vector<? extends java.util.Vector<? extends java.lang.Byte>>, MatrixOP> mul = (m1, m2) -> {
|
public mul = (m1, m2) -> {
|
||||||
var ret = new MatrixOP();
|
var ret = new MatrixOP();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < m1.size()) {
|
while(i < m1.size()) {
|
||||||
|
@@ -10,8 +10,6 @@ public class OL {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OLMain {
|
public class OLMain {
|
||||||
|
|
||||||
main(x) {
|
main(x) {
|
||||||
|
17
src/test/resources/bytecode/javFiles/OLFun.jav
Normal file
17
src/test/resources/bytecode/javFiles/OLFun.jav
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Double;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class OLFun {
|
||||||
|
|
||||||
|
//f = x -> {return x + x;};
|
||||||
|
|
||||||
|
m(f, x) {
|
||||||
|
x = f.apply(x+x);
|
||||||
|
}
|
||||||
|
}
|
12
src/test/resources/bytecode/javFiles/TypedID.jav
Normal file
12
src/test/resources/bytecode/javFiles/TypedID.jav
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
public class TypedID/*<L extends K,K> */ {
|
||||||
|
|
||||||
|
lam = x-> x;
|
||||||
|
|
||||||
|
id(b){
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
m(){
|
||||||
|
return lam;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user