Skip to content

Commit

Permalink
Adjust mangling
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Jul 10, 2024
1 parent 5f35991 commit 4804806
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ private PatternBytecodeName() { }
/**
* Mangles the binary name of a deconstructor.
*
* @param pattern the pattern itself
* @param enclosingClass the enclosing class that contains the deconstructor
* @param bindingTypes the types of bindings
*
* @return the symbolic name
*/
public static String mangle(Class<?> pattern, Class<?> ...bindingTypes) {
public static String mangle(Class<?> enclosingClass, Class<?>...bindingTypes) {
String postFix = Arrays.stream(bindingTypes)
.map(param -> BytecodeName.toBytecodeName(param.descriptorString()))
.collect(Collectors.joining("\u005C\\u0025"));
.map(param ->{
String mangled = BytecodeName.toBytecodeName(param.descriptorString());
mangled = mangled.toString().replaceFirst("\\\\=", "");
return mangled;
}).collect(Collectors.joining(":"));

return pattern.getSimpleName() + "\\\u0025" + postFix;
return enclosingClass.getSimpleName() + ":" + postFix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2079,13 +2079,17 @@ public Name externalName(Types types) {
}

private Name mangledBytecodePatternName(Types types) {
Name postFix = name.table.names.fromString(bindings().map(param -> {
List<String> parts = bindings().map(param -> {
var g = new UnSharedSignatureGenerator(types, name.table.names);
g.assembleSig(param.erasure(types));
return name.table.names.fromString(BytecodeName.toBytecodeName(g.toName().toString()));
}).stream().collect(Collectors.joining("\\\u0025")));
String mangled = name.table.names.fromString(BytecodeName.toBytecodeName(g.toName().toString())).toString();
mangled = mangled.toString().replaceFirst("\\\\=", "");
return mangled;
});

return name.table.names.fromString(owner.name.toString() + "\\\u0025" + postFix);
String postFix = String.join(":", parts);

return name.table.names.fromString(owner.name.toString() + ":" + postFix);
}

static class UnSharedSignatureGenerator extends Types.SignatureGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public pattern Test(String name, String username) {
.run()
.getOutput(Task.OutputKind.DIRECT);

if (!javapOut.contains("public static java.lang.Object Test\\%\\=Ljava\\|lang\\|String\\?\\%\\=Ljava\\|lang\\|String\\?(test.Test)"))
if (!javapOut.contains("public static java.lang.Object Test:Ljava\\|lang\\|String\\?:Ljava\\|lang\\|String\\?(test.Test)"))
throw new AssertionError("Wrongly generated signature of pattern declaration:\n" + javapOut);
}
}
Expand Down

0 comments on commit 4804806

Please sign in to comment.