Unboxing fuer methodcall wird nicht gemacht wenn es sich in Returnstatement befindet. SimplifyPairs fuer Paramtrisierte Typen wird einmal vor die Signatureerzeugung ausgefuehrt und nicht separat. getAllPairs in Signature gefixt.
This commit is contained in:
parent
8e220b81d5
commit
b56f18c16e
@ -70,6 +70,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
private String path;
|
||||
private SourceFile sf;
|
||||
private IStatement statement = null;
|
||||
private boolean isReturnStmt = false;
|
||||
|
||||
private boolean needDUP = false;
|
||||
|
||||
@ -781,7 +782,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
doUnboxing(getResolvedType(methodCall.getType()));
|
||||
}
|
||||
|
||||
if(methodRefl == null) {
|
||||
if(methodRefl == null && !isReturnStmt) {
|
||||
if(isBinaryExp)
|
||||
doUnboxing(getResolvedType(methodCall.getType()));
|
||||
}
|
||||
@ -958,6 +959,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
statement = new ReturnStmt(aReturn.retexpr);
|
||||
isReturnStmt = true;
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
boolean isBinary = isBinaryExp;
|
||||
if(aReturn.retexpr instanceof UnaryExpr)
|
||||
@ -972,6 +974,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
isReturnStmt = false;
|
||||
statement = null;
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,21 @@ public class Signature {
|
||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||
if(!isConstructor) {
|
||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||
ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
||||
if(ret.contains("<")) {
|
||||
allPairs = getAllPairs((RefType) resultSet.resolveType(method.getReturnType()).resolvedType);
|
||||
}
|
||||
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName);
|
||||
String pT = t.acceptTV(new TypeToSignature());
|
||||
|
||||
if(pT.contains("<"))
|
||||
allPairs.addAll(getAllPairs((RefType) t));
|
||||
}
|
||||
|
||||
createTypeVars(allPairs);
|
||||
|
||||
if(!ret.equals("V")) {
|
||||
// TODO TypeToSignature nochmal kontrollieren und schauen ob man dort wirklich
|
||||
// T... braucht und L ...
|
||||
@ -131,15 +146,15 @@ public class Signature {
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.contains("<")) {
|
||||
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
|
||||
if(hasTPHs(ref)) {
|
||||
createSignatureForParameterizedType(ref);
|
||||
}
|
||||
System.out.println("HAS WC = " + hasWC(ref));
|
||||
if(hasWC(ref))
|
||||
createSigForParamTypeWithWC(ref);
|
||||
}
|
||||
// if(ret.contains("<")) {
|
||||
// RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
|
||||
// if(hasTPHs(ref)) {
|
||||
// createSignatureForParameterizedType(ref);
|
||||
// }
|
||||
// System.out.println("HAS WC = " + hasWC(ref));
|
||||
// if(hasWC(ref))
|
||||
// createSigForParamTypeWithWC(ref);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,14 +188,14 @@ public class Signature {
|
||||
}
|
||||
}
|
||||
|
||||
if(pT.contains("<")) {
|
||||
RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
||||
if(hasTPHs(ref))
|
||||
createSignatureForParameterizedType(ref);
|
||||
|
||||
if(hasWC(ref))
|
||||
createSigForParamTypeWithWC(ref);
|
||||
}
|
||||
// if(pT.contains("<")) {
|
||||
// RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
||||
// if(hasTPHs(ref))
|
||||
// createSignatureForParameterizedType(ref);
|
||||
//
|
||||
// if(hasWC(ref))
|
||||
// createSigForParamTypeWithWC(ref);
|
||||
// }
|
||||
|
||||
for(GenericInsertPair p:methodPairs) {
|
||||
String name = p.TA1.getName()+"$";
|
||||
@ -228,6 +243,41 @@ public class Signature {
|
||||
// sw.visitEnd();
|
||||
}
|
||||
|
||||
private void createTypeVars(ArrayList<GenericInsertPair> allPairs) {
|
||||
allPairs.addAll(methodPairs);
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
||||
|
||||
HashMap<String, String> names = new HashMap<>();
|
||||
|
||||
for(GenericInsertPair pair : simplifiedPairs) {
|
||||
// if(ref.getParaList().contains(pair.TA1)) {
|
||||
String sub = pair.TA1.getName()+"$";
|
||||
String superT = pair.TA2.getName()+"$";
|
||||
names.put(sub, superT);
|
||||
// }
|
||||
}
|
||||
|
||||
for(String sub : names.keySet()) {
|
||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||
sw.visitFormalTypeParameter(sub);
|
||||
String bound = names.get(sub);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBoundsMethod.put(sub, bound);
|
||||
}
|
||||
}
|
||||
|
||||
for(String superT : names.values()) {
|
||||
if(!names.containsKey(superT)) {
|
||||
if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
||||
sw.visitFormalTypeParameter(superT);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createSigForParamTypeWithWC(RefType ref) {
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
if(p instanceof WildcardType) {
|
||||
@ -264,39 +314,39 @@ public class Signature {
|
||||
}
|
||||
|
||||
private void createSignatureForParameterizedType(RefType ref) {
|
||||
ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
||||
allPairs.addAll(methodPairs);
|
||||
ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
||||
|
||||
HashMap<String, String> names = new HashMap<>();
|
||||
|
||||
for(GenericInsertPair pair : simplifiedPairs) {
|
||||
if(ref.getParaList().contains(pair.TA1)) {
|
||||
String sub = pair.TA1.getName()+"$";
|
||||
String superT = pair.TA2.getName()+"$";
|
||||
names.put(sub, superT);
|
||||
}
|
||||
}
|
||||
|
||||
for(String sub : names.keySet()) {
|
||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||
sw.visitFormalTypeParameter(sub);
|
||||
String bound = names.get(sub);
|
||||
sw.visitClassBound().visitTypeVariable(bound);
|
||||
genericsAndBoundsMethod.put(sub, bound);
|
||||
}
|
||||
}
|
||||
|
||||
for(String superT : names.values()) {
|
||||
if(!names.containsKey(superT)) {
|
||||
if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
||||
sw.visitFormalTypeParameter(superT);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
// ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
||||
// allPairs.addAll(methodPairs);
|
||||
// ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
||||
//
|
||||
// HashMap<String, String> names = new HashMap<>();
|
||||
//
|
||||
// for(GenericInsertPair pair : simplifiedPairs) {
|
||||
// if(ref.getParaList().contains(pair.TA1)) {
|
||||
// String sub = pair.TA1.getName()+"$";
|
||||
// String superT = pair.TA2.getName()+"$";
|
||||
// names.put(sub, superT);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for(String sub : names.keySet()) {
|
||||
// if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||
// sw.visitFormalTypeParameter(sub);
|
||||
// String bound = names.get(sub);
|
||||
// sw.visitClassBound().visitTypeVariable(bound);
|
||||
// genericsAndBoundsMethod.put(sub, bound);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for(String superT : names.values()) {
|
||||
// if(!names.containsKey(superT)) {
|
||||
// if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
||||
// sw.visitFormalTypeParameter(superT);
|
||||
// sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
// sw.visitClassBound().visitEnd();
|
||||
// genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p: ref.getParaList()) {
|
||||
if(p instanceof TypePlaceholder) {
|
||||
@ -314,16 +364,35 @@ public class Signature {
|
||||
private ArrayList<GenericInsertPair> getAllPairs(RefType ref) {
|
||||
final ArrayList<GenericInsertPair> res = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resultSet.resolveType(p).resolvedType;
|
||||
ResolvedType resType;
|
||||
if(p instanceof WildcardType) {
|
||||
resType = resultSet.resolveType(((WildcardType) p).getInnerType());
|
||||
}else {
|
||||
resType = resultSet.resolveType(p);
|
||||
}
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
||||
if(resolved instanceof TypePlaceholder) {
|
||||
resultSet.resolveType(p).additionalGenerics.forEach(ag ->{
|
||||
resType.additionalGenerics.forEach(ag ->{
|
||||
if(!contains(res,ag)) {
|
||||
res.add(ag);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(resolved instanceof WildcardType) {
|
||||
WildcardType resWC = (WildcardType) resolved;
|
||||
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
||||
if(resType2.resolvedType instanceof TypePlaceholder) {
|
||||
resType2.additionalGenerics.forEach(ag ->{
|
||||
if(!contains(res,ag)) {
|
||||
res.add(ag);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("RES GIP === " + res.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -341,6 +410,7 @@ public class Signature {
|
||||
|
||||
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
||||
for(GenericInsertPair p : allPairs) {
|
||||
if(!p.TA1.equals(p.TA2))
|
||||
subAndSuperTph.put(p.TA1, p.TA2);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user