Bugs 89 und 90

This commit is contained in:
Fayez Abu Alia 2018-07-18 13:51:05 +02:00
parent fd64b84072
commit 2d5f03a3e0
6 changed files with 79 additions and 33 deletions

View File

@ -131,7 +131,8 @@ public class BytecodeGen implements ASTVisitor {
* Signature looks like: * 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("<")) {
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs); Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs);
sig = signature.toString(); sig = signature.toString();
System.out.println("Signature: => " + sig); System.out.println("Signature: => " + sig);
@ -232,13 +233,15 @@ 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.subSequence(0, 4).equals("TPH ") ||
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*/
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());
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")) { String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")||sigOfParam.contains("<")) {
hasGenInParameterList = true; hasGenInParameterList = true;
break; break;
} }
@ -252,11 +255,9 @@ public class BytecodeGen implements ASTVisitor {
/* 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||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) { if(hasGen||resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString()).equals("TPH")) {
ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs); ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs);
System.out.println(method.name + " => Simplified Pairs: "); System.out.println(method.name + " => Simplified Pairs: ");
pairs.forEach(p->System.out.println(p.TA1.getName() + " -> "+p.TA2.getName())); pairs.forEach(p->System.out.println(p.TA1.getName() + " -> "+p.TA2.getName()));

View File

@ -113,24 +113,28 @@ public class Signature {
if(!isConstructor) { if(!isConstructor) {
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()); String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
System.out.println("RET:::: " + ret); System.out.println("RET:::: " + ret);
// if(ret.substring(0,4).equals("TPH ")) { if(!ret.equals("V")) {
// String g = ret.substring(4,ret.length())+"$"; // TODO TypeToSignature nochmal kontrollieren und schauen ob man dort wirklich
if(genericsAndBounds.containsKey(ret)) { // T... braucht und L ...
genericsAndBoundsMethod.put(ret, genericsAndBounds.get(ret)); if(ret.contains("$") && !ret.contains("$$")) {
}else { // String g = ret.substring(4,ret.length())+"$";
sw.visitFormalTypeParameter(ret); if(genericsAndBounds.containsKey(ret)) {
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); genericsAndBoundsMethod.put(ret.substring(1), genericsAndBounds.get(ret.substring(1)));
genericsAndBoundsMethod.put(ret, Type.getInternalName(Object.class)); }else {
sw.visitClassBound().visitEnd(); sw.visitFormalTypeParameter(ret.substring(1));
} sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
// } genericsAndBoundsMethod.put(ret.substring(1), Type.getInternalName(Object.class));
sw.visitClassBound().visitEnd();
if(ret.contains("<")) { }
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
if(hasTPHs(ref)) {
createSignatureForParameterizedType(ref);
} }
if(ret.contains("<")) {
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
if(hasTPHs(ref)) {
createSignatureForParameterizedType(ref);
}
}
} }
} }
@ -143,12 +147,12 @@ public class Signature {
if(t instanceof TypePlaceholder) { if(t instanceof TypePlaceholder) {
// String gP = pT.substring(4,pT.length())+"$"; // String gP = pT.substring(4,pT.length())+"$";
String gP = t.acceptTV(new TypeToSignature()); String gP = t.acceptTV(new TypeToSignature());
if(!genericsAndBounds.containsKey(gP) && !genericsAndBoundsMethod.containsKey(gP)) { if(!genericsAndBounds.containsKey(gP.substring(1)) && !genericsAndBoundsMethod.containsKey(gP.substring(1))) {
sw.visitFormalTypeParameter(gP); sw.visitFormalTypeParameter(gP.substring(1));
String bound = Type.getInternalName(Object.class); String bound = Type.getInternalName(Object.class);
boolean isTypeVar = false; boolean isTypeVar = false;
for(GenericInsertPair pair : methodPairs) { for(GenericInsertPair pair : methodPairs) {
if(pT.substring(0,pT.length()).equals(pair.TA1.getName())) { if(pT.substring(1,pT.length()-1).equals(pair.TA1.getName())) {
bound = pair.TA2.getName()+"$"; bound = pair.TA2.getName()+"$";
isTypeVar = true; isTypeVar = true;
break; break;
@ -162,7 +166,7 @@ public class Signature {
sw.visitClassBound().visitEnd(); sw.visitClassBound().visitEnd();
} }
genericsAndBoundsMethod.put(gP, bound); genericsAndBoundsMethod.put(gP.substring(1), bound);
} }
} }
@ -207,7 +211,8 @@ public class Signature {
// parameter type deswegen ist true // parameter type deswegen ist true
doVisitParamsOrReturn(t,true); doVisitParamsOrReturn(t,true);
} }
if(isConstructor) { if(isConstructor ||
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).equals("V")) {
sw.visitReturnType().visitBaseType('V'); sw.visitReturnType().visitBaseType('V');
}else { }else {
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType(); RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
@ -378,7 +383,7 @@ public class Signature {
break; break;
case "GRT": case "GRT":
GenericRefType g = (GenericRefType) t; GenericRefType g = (GenericRefType) t;
sv.visitTypeVariable(g.acceptTV(new TypeToSignature())); sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
break; break;
case "TPH": case "TPH":
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType; RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
@ -448,7 +453,8 @@ public class Signature {
} }
} }
} }
sw.visitSuperclass().visitClassType(classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()));; String sClass = classOrInterface.getSuperClass().acceptTV(new TypeToSignature());
sw.visitSuperclass().visitClassType(sClass.substring(1, sClass.length()-1));
sw.visitEnd(); sw.visitEnd();
} }
/** /**

View File

@ -15,6 +15,8 @@ public class TypeToSignature implements TypeVisitor<String> {
@Override @Override
public String visit(RefType refType) { public String visit(RefType refType) {
if(refType.getName().toString().equals("void"))
return "V";
// return refType.toString().replace(".", "/"); // return refType.toString().replace(".", "/");
String params = ""; String params = "";
if(refType.getParaList().size()>0){ if(refType.getParaList().size()>0){
@ -32,7 +34,7 @@ public class TypeToSignature implements TypeVisitor<String> {
// params += "L"+param.toString().replace(".", "/"); // params += "L"+param.toString().replace(".", "/");
// } // }
params += param.acceptTV(new TypeToSignature()); params += param.acceptTV(new TypeToSignature());
if(it.hasNext())params += ";"; // if(it.hasNext())params += ";";
} }
params += ">"; params += ">";
} }

View File

@ -0,0 +1,27 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class SubMatTest {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static String pathToClassFile;
@Test
public void test() throws ClassNotFoundException, IOException {
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/SubMatrix.jav";
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
compiler.generateBytecode(pathToClassFile);
}
}

View File

@ -2,9 +2,9 @@ import java.lang.Integer;
import java.lang.Double; import java.lang.Double;
class OL { public class OL {
m(java.lang.Integer x) { return x + x; } m(x) { return x + x; }
//m(x) { return x || x; } //m(x) { return x || x; }

View File

@ -1,3 +1,13 @@
public class SubMatrix extends Matrix { import java.util.Vector;
import java.lang.Integer;
public class Matrix2 extends Vector<Integer> {
}
public class SubMatrix extends Matrix2 {
m(){
Vector<Integer> v = new Vector<Integer>();
v.add(1);
}
} }