Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bigRefactoring

This commit is contained in:
Martin Plümicke 2019-04-05 12:52:28 +02:00
commit 656c77d16b
15 changed files with 239 additions and 36 deletions

View File

@ -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>

View File

@ -29,6 +29,7 @@ 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.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.Literal; import de.dhbwstuttgart.syntaxtree.statement.Literal;
@ -81,6 +82,17 @@ public class BytecodeGen implements ASTVisitor {
ArrayList<String> methodNameAndParamsT = new ArrayList<>(); ArrayList<String> methodNameAndParamsT = new ArrayList<>();
private HashMap<String, SimplifyResult> simplifyResults = new HashMap<>();
private List<HashMap<String, SimplifyResult>> simplifyResultsList = 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, List<ResultSet> listOfResultSets,SourceFile sf ,String path) { public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
this.classFiles = classFiles; this.classFiles = classFiles;
this.listOfResultSets = listOfResultSets; this.listOfResultSets = listOfResultSets;
@ -94,6 +106,7 @@ 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());
} }
} }
@ -173,6 +186,10 @@ public class BytecodeGen implements ASTVisitor {
right = null; right = null;
} }
} }
SimplifyResult sRes = new SimplifyResult(consClass, tphsClass, new HashMap<>());
simplifyResults.put(className, sRes);
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass); 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);
@ -339,7 +356,7 @@ 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()).contains("<");
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht, /*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*/ * prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
@ -347,7 +364,7 @@ public class BytecodeGen implements ASTVisitor {
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;
} }
@ -370,6 +387,14 @@ public class BytecodeGen implements ASTVisitor {
// 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 +411,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<>();

View File

@ -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,17 +45,28 @@ 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 { } 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+ ";";
}
} }
} }
} }
@ -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)) {

View File

@ -290,7 +290,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 +302,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 +468,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 ...
sw.visitClassBound().visitClassType(boundDesc); if(b instanceof GenericRefType) {
sw.visitClassBound().visitTypeVariable(boundDesc);
} else {
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() {

View File

@ -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<TypePlaceholder> tphsClass;
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<TypePlaceholder> 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<TypePlaceholder> getTphsClass() {
return tphsClass;
}
}

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.core;
import de.dhbwstuttgart.bytecode.BytecodeGen; import de.dhbwstuttgart.bytecode.BytecodeGen;
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;
@ -58,7 +59,14 @@ public class JavaTXCompiler {
Boolean resultmodel = false; Boolean resultmodel = false;
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?
/**
* Ä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));
} }
@ -650,6 +658,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 +675,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;
}
} }

View File

@ -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;
} }

View File

@ -1,9 +1,6 @@
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;

View File

@ -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<>());
} }
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){ private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){

View File

@ -8,7 +8,7 @@ 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;
public TypeInsertPoint(Token point, String toInsert){ public TypeInsertPoint(Token point, String toInsert){
@ -28,6 +28,14 @@ public class TypeInsertPoint {
return insertString; return insertString;
} }
public Token getToken() {
return this.point;
}
public void setToken(Token point) {
this.point = point;
}
/* 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

View File

@ -11,28 +11,45 @@ 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
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) { Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
return fc.smArg(this, fBounded); return fc.smArg(this, fBounded);

View 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();
}
}

View File

@ -1,3 +1,4 @@
package bytecode; package bytecode;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -1,6 +1,7 @@
public class Id<FTU extends FTT,FTT> { public class Id {
<A> id(A b){
return b;
}
}
id(FTU b){
return b;
}
}

View File

@ -0,0 +1,6 @@
public class TypedID/*<L extends K,K> */ {
<K> id(K b){
return b;
}
}