From a72f52ae0153567049230d77932877130e7a13d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCdemann?= Date: Wed, 21 Feb 2018 18:19:10 +0100 Subject: [PATCH 1/2] [TG-2585] Support implicitly generic superclasses Before only generic superclasses where supported for the java generic symbols, as the detection was to match on the suffix `>;`. This commit changes it to match an opening `<` in the superclass reference in order to detect a generic superclass which will also succeed in the case of an implicitly generic one. --- src/java_bytecode/java_bytecode_convert_class.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_class.cpp b/src/java_bytecode/java_bytecode_convert_class.cpp index 8b45d2692a1..2355de33bec 100644 --- a/src/java_bytecode/java_bytecode_convert_class.cpp +++ b/src/java_bytecode/java_bytecode_convert_class.cpp @@ -112,8 +112,10 @@ extract_generic_superclass_reference(const optionalt &signature) signature.value().substr(start, (end - start) + 1); // if the superclass is generic then the reference is of form - // Lsuperclass-name; - if(has_suffix(superclass_ref, ">;")) + // `Lsuperclass-name;` if it is implicitly generic, then the + // reference is of the form + // `Lsuperclass-name.Innerclass-Name` + if(superclass_ref.find('<') != std::string::npos) return superclass_ref; } return {}; From 25eb1a3adcba575be5645f8ca30396c73e173f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCdemann?= Date: Wed, 21 Feb 2018 19:51:03 +0100 Subject: [PATCH 2/2] Add unit test for implicitly generic super class --- .../DerivedGenerics.class | Bin 1297 -> 1794 bytes .../DerivedGenerics.java | 25 +++++++ .../GenericBase$ExtendImplicit.class | Bin 0 -> 436 bytes ...enericBase$ExtendImplicitAndExplicit.class | Bin 0 -> 518 bytes ...nericBase$ImplicitAndExplicitGeneric.class | Bin 0 -> 434 bytes .../GenericBase$ImplicitGeneric.class | Bin 0 -> 349 bytes .../GenericBase.class | Bin 0 -> 562 bytes ...nericBase2$ExtendImplicitAndExplicit.class | Bin 0 -> 505 bytes ...ericBase2$ImplicitAndExplicitGeneric.class | Bin 0 -> 438 bytes .../GenericBase2.class | Bin 0 -> 469 bytes .../parse_derived_generic_class.cpp | 64 ++++++++++++++++++ 11 files changed, 89 insertions(+) create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ExtendImplicit.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ExtendImplicitAndExplicit.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ImplicitAndExplicitGeneric.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ImplicitGeneric.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase2$ExtendImplicitAndExplicit.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase2$ImplicitAndExplicitGeneric.class create mode 100644 unit/java_bytecode/java_bytecode_parse_generics/GenericBase2.class diff --git a/unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.class b/unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.class index bd6fb9644fe7cebff9f16a5f997dbeacfe621e24..5943ed714d82428cfc31a6015fa2c3a663b83a24 100644 GIT binary patch delta 681 zcmaJ<%TB^T6g{^UCqcu;u#jNX1k{v=Qc*xE3RscEjUV8GKo=xfjU|y?6aT>UD_pWN zap4E>H~xU}(iAeO@ObtAU*QYZ;D z2{CgtwCrB{;c3wC_J@S^wryL_%|XX;EQgT1ZCT9w-A2c;Qh&`=!nQ0MS}h-P_*rFv zE5c?VxDc2R@1IPi;!6S=?Lk?qI9sp4Pj5RF1a&dZDvgJWARhYC^H?qQ1~|h zHoTpccNfr*2O-KU3J$p*;dsuA%ui67^D=h?9*%33wJo0m5$yvs<^_Vmb(L}2D>!FV XP(zL}!Lb=MkmbI>s56RFnA7GLAz8M{ delta 181 zcmZqTo5&@4>ff$?3=9k=3}##m%nZit3?}RhrW-|LnI|7%(a;m}$xlwq2}>->Oiap2 z4FM613@jxXnZ=9@f<7*(MVV!(DekFxKt^)0_2gG9YRp;;+LMJ@Rk;`x8JK`3GB5~C zzRbGPgOP!e0Vo9|b%0{}K$;OqvubT;VB82~Ffr%?Nj9(`BZD50%>z*YRB8a^F)|o} HRT%*QLB$}! diff --git a/unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.java b/unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.java index caf7bd5e178..14aa3ecef53 100644 --- a/unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.java +++ b/unit/java_bytecode/java_bytecode_parse_generics/DerivedGenerics.java @@ -15,6 +15,9 @@ public class DerivedGenerics { ExtendsAndImplementsSameInterface new14; ExtendsAndImplementsSameInterface2 new15; ExtendsAndImplementsSameInterfaceGeneric new16; + GenericBase.ExtendImplicit new17; + GenericBase.ExtendImplicitAndExplicit new18; + GenericBase2.ExtendImplicitAndExplicit new19; } class DerivedGenericInst extends Generic @@ -189,3 +192,25 @@ public Class someMethod(){ return null; } } + +// This class exists to test that subclasses of implicit generic classes have a +// base class entry which is a Java generic symbol. +class GenericBase { + class ImplicitGeneric { + } + class ExtendImplicit extends ImplicitGeneric { + } + class ImplicitAndExplicitGeneric { + } + class ExtendImplicitAndExplicit extends ImplicitAndExplicitGeneric { + } +} + +// This class exists to test the subclasses of generic and implicitly generic +// classes have a base class entry which is a Java generic symbol. +class GenericBase2 { + class ImplicitAndExplicitGeneric { + } + class ExtendImplicitAndExplicit extends ImplicitAndExplicitGeneric { + } +} diff --git a/unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ExtendImplicit.class b/unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ExtendImplicit.class new file mode 100644 index 0000000000000000000000000000000000000000..928ee536ca0283de2117c6dfb8f1b703fa07c2cf GIT binary patch literal 436 zcmZ8d%TB^T6g^XFYac*Gd_*@!StumLg*ylf@evZ@hQ|HSPIOEeOdrJGa$!tdxYv&| z-Zo$=narF!_nbNR&i(%R_yll)eG3(A+0fB2(KNBkV5E;SX`M4v$G1X>SO%9o5j`UM zQpt3{;GO4_XGgQ=NCq-p`ZBm9MHPk- zPZE(Z9G89jzTX>k*Pc)t_GF&Lfw+;mee;SMT!?V#m~@}`g1gv&;ljkGi9Lpc(l=Vy zFR4)B%9WwEo;WP4SGvE3of3;9nw?H#WS*B-%p=-Vme8W;1R5>CX?Nbh+MRc3uZ75_ e(89cHSH2?c?PYzzMeU$YQks1r-%l6&nn>_+CV{V}?@iic1~}@7#^J zK><@p5nBxU;g87C9fQ&y`<$WN6O!LdMtvSSZa<)xye$UOjVB@To$lx%5T1z7q~Do+ z(S-zq)|DjI4%{f>5yQ19JFrxL+-_fl@>M~$FQ1z*EAj5u*i489#2A# zUy8&}^@2K@a(|&4H4_aDOUP+Zv8-Z~VL#P(tuu?c^nX!d*#0MWkgoB|@9(~gsYLA3 zG!z;P)Ahts!f2B(!aT7(WM~1!dgBSK-grjlah_D5GdE9urxHcFWw3(s9CefkEA*mZ L4I1$*;X3dMXupGR literal 0 HcmV?d00001 diff --git a/unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ImplicitAndExplicitGeneric.class b/unit/java_bytecode/java_bytecode_parse_generics/GenericBase$ImplicitAndExplicitGeneric.class new file mode 100644 index 0000000000000000000000000000000000000000..c2e509fa680a7a00d823562a249bba930c820451 GIT binary patch literal 434 zcmaJ-O-sW-5Ph50#H6W>T0ih4QY5WlJ$SOEp!I`7(L==hCSB^5bSv4k__sWW;K3iD z|4E$09;$*YyYKD1Vdl-ef4;r}IL5Y(0xAxQ@GPuZ*kCZzd#P(j4CVfnP$H4h8P}pk zLR%`Cb{IVWhf=>|D0U|U!BFW-C9bFAP$aiJj45IVa;SJZO^EyL;G{p|Gv1838a8jj zk%-b(=WmF?2`1Ad5|=WoQ9UOYGclOk(T7TJ!rglmlrKrirFswmj^@Q!K;ZM zWq2hVFs5ny-ptF)v_HR}UjQy~Sb>jPgaA7diNwA@SiWl8yb!1j@5oT0v#zpq#l*EX zy1WrcT7Q_+XMvzM9g#qNs14oECMgw9D$N;*9;dS+qg(BoMxW*8G+OK0^Rb$%7+VNq zNHio41dcXLn}f+)t}|V(F*f*z!~?@2d%3cfEN63)om`oh&O;7sveS zfImPaiF0=qZ;5TbD_otx;{`&0^a*-CgL+(&3-dq<<3KlJvYgyk2-dNC3Oi( A%m4rY literal 0 HcmV?d00001 diff --git a/unit/java_bytecode/java_bytecode_parse_generics/GenericBase.class b/unit/java_bytecode/java_bytecode_parse_generics/GenericBase.class new file mode 100644 index 0000000000000000000000000000000000000000..ccce4e1d77a7071cceab2e72488d2ab2ad5a482f GIT binary patch literal 562 zcmZvZOHaZ;6ot>_Re1=g_y9C9L=C!-jVmQ2ifBlPE+FoQc0z`f!L)_&w_KUHaOuJy zWxU0bv}&97+@AZ*={!Ea-rfORU_XO6whinU*fp?6D0dc~)K+)$Y%5cF*V^hVeo8{F ztF?66ws2kP8YmMg|8Vz`A!Qn<5c1J9164v{H6{QFsixA(YZ2o0(0Pz{T7*o0I&(~Ur~Hi4El+MP zt>EYGxu224I`V{UVBQFq$>Q&H!f^;ViY_g(Q72(;wcHR9w0Zx+U^I|W4L4UQfrmrH z_~iVH_~GfZ7PvZK^_}F|E9hm}F7i9IG(ULA27kq{iLIrUxC7LX;5&vS*9PkvYnnB~ Inq|!a-;WNFdjJ3c literal 0 HcmV?d00001 diff --git a/unit/java_bytecode/java_bytecode_parse_generics/GenericBase2$ExtendImplicitAndExplicit.class b/unit/java_bytecode/java_bytecode_parse_generics/GenericBase2$ExtendImplicitAndExplicit.class new file mode 100644 index 0000000000000000000000000000000000000000..358f4bc35a40d4e84344cbce7ca34e361e2f8f1d GIT binary patch literal 505 zcmaJ;T}uK%6g{KcZmXML+2>P`^r0XT(TgIKSqRdLOYh_EP!l@F&MN+`9wO+WAJ7lz z=R|imAr~x$nR8~&oqO)(etf;X131IBjWmiG7${jNTi9eU!w0D=Ck(mXjZh+x-X+)K zv_VQ!DjBvIibqN5_>RG7kA1J~Ts|1mi`|#^iieYc_-=RfG?bnUFO=Vz z{m{7ygVR-H*B)}Mg=RQUcr;zN;r1J?`rjFvkxpf1`r}F9iEA0Tm#?UUsqp76y8g(g z+`$S=2NqT>Y%v@x_F3u7LZSR6HVixeXora;OTPd1xfqE(8h}BwV1+_dRm5mhX@oYh weWYjs*=p?ttXg|T>NyU|&}qiOpOhj?w-j>7$5_A`VToQ0tivImCfoqN0n%xG@&Et; literal 0 HcmV?d00001 diff --git a/unit/java_bytecode/java_bytecode_parse_generics/GenericBase2$ImplicitAndExplicitGeneric.class b/unit/java_bytecode/java_bytecode_parse_generics/GenericBase2$ImplicitAndExplicitGeneric.class new file mode 100644 index 0000000000000000000000000000000000000000..3704ae8c7937b5b9615110dbbcc1e023681e7891 GIT binary patch literal 438 zcmaJ-O-sW-5Pj3c#>CjBT0ih4Qm|IABA#q1X#Jp2^ic7>O_#bQ-AX=+f6Idi9{d5G z{XOC&_D~gM*?n*44Kr`%{qyw=z%e#$7$`b0;aOO*utvzo_bRF!5(?cbsb#4AGZD$7 z1}jaaRoo(!sz0T@JA&Ds3?!l0Ra#yrIz;c^4MeEo=~W=iOF1 l+kXbtUXXjravXm1S?&i{SmIv}E|xPapv>s7YM_Kw;0umRW`h6# literal 0 HcmV?d00001 diff --git a/unit/java_bytecode/java_bytecode_parse_generics/GenericBase2.class b/unit/java_bytecode/java_bytecode_parse_generics/GenericBase2.class new file mode 100644 index 0000000000000000000000000000000000000000..7c2d9b77cd2de0c1d4b2a2292b44099234eedaa3 GIT binary patch literal 469 zcmaJ-O-sW-5Pj3H*cffCRZtK-h*}RV6i*roTB{U_9#Xt-lBH}(w~~+2zvW5r;1BTX z{}Cs#2S2I{v+wPjx3jbJ`u_X^;1t^?^4Ks?Gq7o(PT1+qW2ycA3WOfD?%c8T;&W$-*7dz+$hhH5B|4ilRoAK{~U>`XicDjgz+hAN}w#S$%#giw{W0tmfFJZ*4(q67Smg{*W2L}RWNt9703WifcsT$7 literal 0 HcmV?d00001 diff --git a/unit/java_bytecode/java_bytecode_parse_generics/parse_derived_generic_class.cpp b/unit/java_bytecode/java_bytecode_parse_generics/parse_derived_generic_class.cpp index 6c00ae92065..3095615b8fb 100644 --- a/unit/java_bytecode/java_bytecode_parse_generics/parse_derived_generic_class.cpp +++ b/unit/java_bytecode/java_bytecode_parse_generics/parse_derived_generic_class.cpp @@ -559,4 +559,68 @@ SCENARIO( // TODO: Check that specialised superclass is created. TG-1418, TG-1419 } + + THEN("There should be a symbol for the `ExtendImplicit` class") + { + std::string class_prefix = "java::GenericBase$ExtendImplicit"; + REQUIRE(new_symbol_table.has_symbol(class_prefix)); + + const symbolt &derived_symbol = new_symbol_table.lookup_ref(class_prefix); + const class_typet &derived_class_type = + require_type::require_java_implicitly_generic_class(derived_symbol.type); + + THEN("The base for superclass is implicitly generic") + { + REQUIRE(derived_class_type.bases().size() == 1); + const typet &base_type = derived_class_type.bases().at(0).type(); + require_type::require_java_generic_symbol_type( + base_type, + "java::GenericBase$ImplicitGeneric", + {{require_type::type_argument_kindt::Var, "java::GenericBase::T"}}); + } + } + + THEN("There should be a symbol for the `ExtendImplicitAndExplicit` class") + { + std::string class_prefix = "java::GenericBase$ExtendImplicitAndExplicit"; + REQUIRE(new_symbol_table.has_symbol(class_prefix)); + + const symbolt &derived_symbol = new_symbol_table.lookup_ref(class_prefix); + const class_typet &derived_class_type = + require_type::require_java_implicitly_generic_class(derived_symbol.type); + + THEN("The base for superclass is generic *and* implicitly generic") + { + REQUIRE(derived_class_type.bases().size() == 1); + const typet &base_type = derived_class_type.bases().at(0).type(); + require_type::require_java_generic_symbol_type( + base_type, + "java::GenericBase$ImplicitAndExplicitGeneric", + {{require_type::type_argument_kindt::Var, "java::GenericBase::T"}, + {require_type::type_argument_kindt::Var, + "java::GenericBase$ExtendImplicitAndExplicit::S"}}); + } + } + + THEN("There should be a symbol for the `ExtendImplicitAndExplicit` class") + { + std::string class_prefix = "java::GenericBase2$ExtendImplicitAndExplicit"; + REQUIRE(new_symbol_table.has_symbol(class_prefix)); + + const symbolt &derived_symbol = new_symbol_table.lookup_ref(class_prefix); + const class_typet &derived_class_type = + require_type::require_java_implicitly_generic_class(derived_symbol.type); + + THEN("The base for superclass is generic *and* implicitly generic") + { + REQUIRE(derived_class_type.bases().size() == 1); + const typet &base_type = derived_class_type.bases().at(0).type(); + require_type::require_java_generic_symbol_type( + base_type, + "java::GenericBase2$ImplicitAndExplicitGeneric", + {{require_type::type_argument_kindt::Var, "java::GenericBase2::T"}, + {require_type::type_argument_kindt::Var, "java::GenericBase2::S"}, + {require_type::type_argument_kindt::Var, "java::GenericBase2::S"}}); + } + } }