forked from JavaTX/JavaCompilerCore
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 String path;
|
||||||
private SourceFile sf;
|
private SourceFile sf;
|
||||||
private IStatement statement = null;
|
private IStatement statement = null;
|
||||||
|
private boolean isReturnStmt = false;
|
||||||
|
|
||||||
private boolean needDUP = false;
|
private boolean needDUP = false;
|
||||||
|
|
||||||
@ -780,8 +781,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
if(isBinaryExp)
|
if(isBinaryExp)
|
||||||
doUnboxing(getResolvedType(methodCall.getType()));
|
doUnboxing(getResolvedType(methodCall.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null && !isReturnStmt) {
|
||||||
if(isBinaryExp)
|
if(isBinaryExp)
|
||||||
doUnboxing(getResolvedType(methodCall.getType()));
|
doUnboxing(getResolvedType(methodCall.getType()));
|
||||||
}
|
}
|
||||||
@ -958,6 +959,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return aReturn) {
|
public void visit(Return aReturn) {
|
||||||
statement = new ReturnStmt(aReturn.retexpr);
|
statement = new ReturnStmt(aReturn.retexpr);
|
||||||
|
isReturnStmt = true;
|
||||||
isBinaryExp = statement.isExprBinary();
|
isBinaryExp = statement.isExprBinary();
|
||||||
boolean isBinary = isBinaryExp;
|
boolean isBinary = isBinaryExp;
|
||||||
if(aReturn.retexpr instanceof UnaryExpr)
|
if(aReturn.retexpr instanceof UnaryExpr)
|
||||||
@ -970,8 +972,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
doBoxing(getResolvedType(binary.getType()));
|
doBoxing(getResolvedType(binary.getType()));
|
||||||
// isBinaryExp = false;
|
// isBinaryExp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mv.visitInsn(Opcodes.ARETURN);
|
mv.visitInsn(Opcodes.ARETURN);
|
||||||
|
isReturnStmt = false;
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +117,21 @@ public class Signature {
|
|||||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||||
if(!isConstructor) {
|
if(!isConstructor) {
|
||||||
String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
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")) {
|
if(!ret.equals("V")) {
|
||||||
// TODO TypeToSignature nochmal kontrollieren und schauen ob man dort wirklich
|
// TODO TypeToSignature nochmal kontrollieren und schauen ob man dort wirklich
|
||||||
// T... braucht und L ...
|
// T... braucht und L ...
|
||||||
@ -131,15 +146,15 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret.contains("<")) {
|
// if(ret.contains("<")) {
|
||||||
RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
|
// RefType ref = (RefType) resultSet.resolveType(method.getReturnType()).resolvedType;
|
||||||
if(hasTPHs(ref)) {
|
// if(hasTPHs(ref)) {
|
||||||
createSignatureForParameterizedType(ref);
|
// createSignatureForParameterizedType(ref);
|
||||||
}
|
// }
|
||||||
System.out.println("HAS WC = " + hasWC(ref));
|
// System.out.println("HAS WC = " + hasWC(ref));
|
||||||
if(hasWC(ref))
|
// if(hasWC(ref))
|
||||||
createSigForParamTypeWithWC(ref);
|
// createSigForParamTypeWithWC(ref);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,14 +188,14 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pT.contains("<")) {
|
// if(pT.contains("<")) {
|
||||||
RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
// RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
||||||
if(hasTPHs(ref))
|
// if(hasTPHs(ref))
|
||||||
createSignatureForParameterizedType(ref);
|
// createSignatureForParameterizedType(ref);
|
||||||
|
//
|
||||||
if(hasWC(ref))
|
// if(hasWC(ref))
|
||||||
createSigForParamTypeWithWC(ref);
|
// createSigForParamTypeWithWC(ref);
|
||||||
}
|
// }
|
||||||
|
|
||||||
for(GenericInsertPair p:methodPairs) {
|
for(GenericInsertPair p:methodPairs) {
|
||||||
String name = p.TA1.getName()+"$";
|
String name = p.TA1.getName()+"$";
|
||||||
@ -228,6 +243,41 @@ public class Signature {
|
|||||||
// sw.visitEnd();
|
// 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) {
|
private void createSigForParamTypeWithWC(RefType ref) {
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||||
if(p instanceof WildcardType) {
|
if(p instanceof WildcardType) {
|
||||||
@ -264,39 +314,39 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createSignatureForParameterizedType(RefType ref) {
|
private void createSignatureForParameterizedType(RefType ref) {
|
||||||
ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
// ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
||||||
allPairs.addAll(methodPairs);
|
// allPairs.addAll(methodPairs);
|
||||||
ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
// ArrayList<GenericInsertPair> simplifiedPairs = simplifyPairs(allPairs);
|
||||||
|
//
|
||||||
HashMap<String, String> names = new HashMap<>();
|
// HashMap<String, String> names = new HashMap<>();
|
||||||
|
//
|
||||||
for(GenericInsertPair pair : simplifiedPairs) {
|
// for(GenericInsertPair pair : simplifiedPairs) {
|
||||||
if(ref.getParaList().contains(pair.TA1)) {
|
// if(ref.getParaList().contains(pair.TA1)) {
|
||||||
String sub = pair.TA1.getName()+"$";
|
// String sub = pair.TA1.getName()+"$";
|
||||||
String superT = pair.TA2.getName()+"$";
|
// String superT = pair.TA2.getName()+"$";
|
||||||
names.put(sub, superT);
|
// names.put(sub, superT);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for(String sub : names.keySet()) {
|
// for(String sub : names.keySet()) {
|
||||||
if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
// if(!genericsAndBoundsMethod.containsKey(sub) && !genericsAndBounds.containsKey(sub)) {
|
||||||
sw.visitFormalTypeParameter(sub);
|
// sw.visitFormalTypeParameter(sub);
|
||||||
String bound = names.get(sub);
|
// String bound = names.get(sub);
|
||||||
sw.visitClassBound().visitTypeVariable(bound);
|
// sw.visitClassBound().visitTypeVariable(bound);
|
||||||
genericsAndBoundsMethod.put(sub, bound);
|
// genericsAndBoundsMethod.put(sub, bound);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for(String superT : names.values()) {
|
// for(String superT : names.values()) {
|
||||||
if(!names.containsKey(superT)) {
|
// if(!names.containsKey(superT)) {
|
||||||
if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
// if(!genericsAndBoundsMethod.containsKey(superT) && !genericsAndBounds.containsKey(superT)) {
|
||||||
sw.visitFormalTypeParameter(superT);
|
// sw.visitFormalTypeParameter(superT);
|
||||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
// sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||||
sw.visitClassBound().visitEnd();
|
// sw.visitClassBound().visitEnd();
|
||||||
genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
// genericsAndBoundsMethod.put(superT, Type.getInternalName(Object.class));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric p: ref.getParaList()) {
|
for(RefTypeOrTPHOrWildcardOrGeneric p: ref.getParaList()) {
|
||||||
if(p instanceof TypePlaceholder) {
|
if(p instanceof TypePlaceholder) {
|
||||||
@ -314,16 +364,35 @@ public class Signature {
|
|||||||
private ArrayList<GenericInsertPair> getAllPairs(RefType ref) {
|
private ArrayList<GenericInsertPair> getAllPairs(RefType ref) {
|
||||||
final ArrayList<GenericInsertPair> res = new ArrayList<>();
|
final ArrayList<GenericInsertPair> res = new ArrayList<>();
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
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) {
|
if(resolved instanceof TypePlaceholder) {
|
||||||
resultSet.resolveType(p).additionalGenerics.forEach(ag ->{
|
resType.additionalGenerics.forEach(ag ->{
|
||||||
if(!contains(res,ag)) {
|
if(!contains(res,ag)) {
|
||||||
res.add(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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +410,8 @@ public class Signature {
|
|||||||
|
|
||||||
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
HashMap<TypePlaceholder, TypePlaceholder> subAndSuperTph = new HashMap<>();
|
||||||
for(GenericInsertPair p : allPairs) {
|
for(GenericInsertPair p : allPairs) {
|
||||||
subAndSuperTph.put(p.TA1, p.TA2);
|
if(!p.TA1.equals(p.TA2))
|
||||||
|
subAndSuperTph.put(p.TA1, p.TA2);
|
||||||
}
|
}
|
||||||
|
|
||||||
subAndSuperTph.forEach((k,v)->System.out.println(k.getName() + " || " + v.getName()));
|
subAndSuperTph.forEach((k,v)->System.out.println(k.getName() + " || " + v.getName()));
|
||||||
|
Loading…
Reference in New Issue
Block a user