From 7926c25c7d2254e7a607005c410991e17be7014d Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 27 Jun 2018 15:20:35 +0200 Subject: [PATCH] =?UTF-8?q?Soviel=20wie=20m=C3=B6glich=20unn=C3=B6tige=20T?= =?UTF-8?q?PHs=20aus=20Signaturen=20von=20Paramtrisierten=20Typen=20entfer?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bytecode/signature/Signature.java | 20 ++++- test/bytecode/javFiles/Lambda.jav | 4 +- test/logFiles/log | 83 +++++++++++++++++++ 3 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 test/logFiles/log diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index 09a2788f..11f3ca20 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -217,9 +217,11 @@ public class Signature { HashMap names = new HashMap<>(); for(GenericInsertPair pair : simplifiedPairs) { - String sub = pair.TA1.getName()+"$"; - String superT = pair.TA2.getName()+"$"; - names.put(sub, superT); + 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()) { @@ -241,6 +243,18 @@ public class Signature { } } } + + for(RefTypeOrTPHOrWildcardOrGeneric p: ref.getParaList()) { + if(p instanceof TypePlaceholder) { + String name = ((TypePlaceholder) p).getName() + "$"; + if(!genericsAndBoundsMethod.containsKey(name) && !genericsAndBounds.containsKey(name)) { + sw.visitFormalTypeParameter(name); + sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); + sw.visitClassBound().visitEnd(); + genericsAndBoundsMethod.put(name, Type.getInternalName(Object.class)); + } + } + } } private ArrayList getAllPairs(RefType ref) { diff --git a/test/bytecode/javFiles/Lambda.jav b/test/bytecode/javFiles/Lambda.jav index 5ee83868..620440cd 100644 --- a/test/bytecode/javFiles/Lambda.jav +++ b/test/bytecode/javFiles/Lambda.jav @@ -1,4 +1,5 @@ -//class Apply { } +import java.util.Vector; +class Apply { } public class Lambda { @@ -8,6 +9,7 @@ public class Lambda { }; // return lam1.apply(new Apply()); return lam1; +// return new Vector(); } } diff --git a/test/logFiles/log b/test/logFiles/log new file mode 100644 index 00000000..25a6eae5 --- /dev/null +++ b/test/logFiles/log @@ -0,0 +1,83 @@ +FC:\{java.util.AbstractList=Elem: Node(java.util.AbstractList) +Prec: [java.util.Collection, java.lang.Object, java.util.List, java.lang.Iterable, java.util.AbstractCollection] +Desc: [java.util.Vector] + +, java.util.Collection=Elem: Node(java.util.Collection) +Prec: [java.lang.Object, java.lang.Iterable] +Desc: [java.util.AbstractList, java.util.List, java.util.Vector, java.util.AbstractCollection] + +, java.lang.Cloneable=Elem: Node(java.lang.Cloneable) +Prec: [java.lang.Object] +Desc: [java.util.Vector] + +, java.lang.Object=Elem: Node(java.lang.Object) +Prec: [java.lang.Object] +Desc: [java.util.AbstractList, java.lang.Cloneable, java.util.Collection, java.lang.Object, java.util.RandomAccess, Lambda, java.io.Serializable, java.util.List, java.util.Vector, java.lang.Iterable, java.util.AbstractCollection, Apply] + +, java.util.RandomAccess=Elem: Node(java.util.RandomAccess) +Prec: [java.lang.Object] +Desc: [java.util.Vector] + +, java.util.List=Elem: Node(java.util.List) +Prec: [java.util.Collection, java.lang.Object, java.lang.Iterable] +Desc: [java.util.AbstractList, java.util.Vector] + +, Lambda=Elem: Node(Lambda) +Prec: [java.lang.Object] +Desc: [] + +, java.io.Serializable=Elem: Node(java.io.Serializable) +Prec: [java.lang.Object] +Desc: [java.util.Vector] + +, java.util.Vector=Elem: Node(java.util.Vector) +Prec: [java.util.AbstractList, java.lang.Cloneable, java.util.Collection, java.lang.Object, java.util.RandomAccess, java.io.Serializable, java.util.List, java.lang.Iterable, java.util.AbstractCollection] +Desc: [] + +, java.lang.Iterable=Elem: Node(java.lang.Iterable) +Prec: [java.lang.Object] +Desc: [java.util.AbstractList, java.util.Collection, java.util.List, java.util.Vector, java.util.AbstractCollection] + +, java.util.AbstractCollection=Elem: Node(java.util.AbstractCollection) +Prec: [java.util.Collection, java.lang.Object, java.lang.Iterable] +Desc: [java.util.AbstractList, java.util.Vector] + +, Apply=Elem: Node(Apply) +Prec: [java.lang.Object] +Desc: [] + +} +class Apply { + + Apply()({ + super(()); + })::TPH M + +}class Lambda { + + TPH X m()({ + TPH Y lam1; + (lam1)::TPH Y = ((TPH Z x) -> ({ + return (x)::TPH Z; + })::TPH AA)::TPH AD; + return (lam1)::TPH Y; + })::TPH AE + + Lambda()({ + super(()); + })::TPH AH + +}0 AA: [(AA =. BFC, 1, -1)] +1 Unifikation: [(AD =. Fun1, -1), (AA =. BFC, 1, -1), (Z <. AA, 1, 1), (AD <. Y, -1, -1), (Y <. X, -1, -1)] +1 AA: [(AA =. BFC, 1, -1)] +2 Unifikation: [(Fun1 <. Y, , -1), (AD =. Fun1, -1), (Z <. BFC, 1, -1), (AA =. BFC, 1, -1), (Y <. X, -1, -1)] +2 AA: [(AA =. BFC, 1, -1)] +3 Unifikation: [(Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (Fun1 <. X, , -1), (BFC <. gen_bf, -1, -1), (gen_hv <. Z, 1, 1)] +3 AA: [(AA =. BFC, 1, -1)] +4 Unifikation: [(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)] +[(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)] +Result1 [[(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)]] +Result1 [[(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)]] +Result1 [[(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)]] +Result1 [[(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)]] +RES: [[(gen_ah <. gen_hv, 1, 1), (Z <. BFC, 1, -1), (AD =. Fun1, -1), (AA =. BFC, 1, -1), (Y =. Fun1, -1), (gen_bf <. gen_sr, -1, -1), (BFC <. gen_bf, -1, -1), (X =. Fun1, -1), (gen_hv <. Z, 1, 1)]]