Skip to content

Commit

Permalink
Merge pull request #45 from roscopeco/feature/fix-literal-name-const-arg
Browse files Browse the repository at this point in the history
Fix literal names in const args
  • Loading branch information
roscopeco authored Sep 16, 2022
2 parents 76d87e9 + eb49010 commit 87278ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/com/roscopeco/jasm/JasmAssemblingVisitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class JasmAssemblingVisitor(
}

override fun visitLabel(ctx: JasmParser.LabelContext) {
val label = declareLabel(ctx.LABEL()?.text ?: ctx.LITERAL_NAME().text)
val label = declareLabel(ctx.LABEL()?.text ?: LiteralNames.unescape(ctx.LITERAL_NAME().text))
methodVisitor.visitLabel(label.label)
}

Expand Down Expand Up @@ -454,7 +454,7 @@ class JasmAssemblingVisitor(
}

override fun visitInsn_goto(ctx: JasmParser.Insn_gotoContext)
= methodVisitor.visitJumpInsn(Opcodes.GOTO, getLabel(ctx.NAME()?.text ?: ctx.LITERAL_NAME().text).label)
= methodVisitor.visitJumpInsn(Opcodes.GOTO, getLabel(ctx.NAME()?.text ?: LiteralNames.unescape(ctx.LITERAL_NAME().text)).label)

override fun visitInsn_i2b(ctx: JasmParser.Insn_i2bContext) = methodVisitor.visitInsn(Opcodes.I2B)

Expand Down Expand Up @@ -899,7 +899,7 @@ class JasmAssemblingVisitor(
ctx.string_atom() != null -> unescapeConstantString(ctx.string_atom().text)
ctx.bool_atom() != null -> if (java.lang.Boolean.parseBoolean(ctx.bool_atom().text)) 1 else 0
ctx.NAME() != null -> Type.getType("L" + ctx.NAME().text + ";")
ctx.LITERAL_NAME() != null -> Type.getType("L" + ctx.LITERAL_NAME().text + ";")
ctx.LITERAL_NAME() != null -> Type.getType("L" + LiteralNames.unescape(ctx.LITERAL_NAME().text) + ";")
ctx.QNAME() != null -> Type.getType("L" + ctx.QNAME().text + ";")
ctx.method_handle() != null -> buildBootstrapHandle(ctx.method_handle())
ctx.method_descriptor() != null -> Type.getMethodType(typeVisitor.visitMethod_descriptor(ctx.method_descriptor()))
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/com/roscopeco/jasm/e2e/AssemblerE2ETests.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void shouldAssembleLdcAconstNullAreturnToValidJavaClass() {
assertThat(clz.getDeclaredFields()).isEmpty();

assertThat(clz.getDeclaredConstructors()).hasSize(1);
assertThat(clz.getDeclaredMethods()).hasSize(11);
assertThat(clz.getDeclaredMethods()).hasSize(12);

final var obj = instantiate(clz, LdcAconstAreturn.class);

Expand Down Expand Up @@ -186,6 +186,9 @@ void shouldAssembleLdcAconstNullAreturnToValidJavaClass() {
// Tests LDC(class), ARETURN
assertThat(obj.testLdcClass()).isEqualTo(List.class);

// Tests LDC(class), ARETURN
assertThat(obj.testLdcClassWithLiteralName()).isEqualTo(List.class);

// Tests LDC(methodtype), ARETURN
assertThat(obj.testLdcMethodType().returnType()).isEqualTo(int.class);
assertThat(obj.testLdcMethodType().parameterList()).containsExactly(List.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ void shouldDisassembleClassWithFields() {

@Test
void shouldDisassembleInvokeDynamic() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
System.out.println(disassemble("InvokeDynamicTest"));
final var source = disassemble("InvokeDynamicTest");
final var test = doParseString(source);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface LdcAconstAreturn {
fun testLdcDouble(): Double
fun testLdcBool(): Boolean
fun testLdcClass(): Class<*>
fun testLdcClassWithLiteralName(): Class<*>
fun testLdcMethodType(): MethodType
fun testLdcMethodHandle(): MethodHandle
fun testLdcDynamicConst(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class com/roscopeco/jasm/LdcAconstAreturn implements com/roscopeco/jasm/model/Ld
areturn
}

public testLdcClassWithLiteralName()java/lang/Class {
ldc `java/util/List`
areturn
}

public testLdcMethodType()java/lang/invoke/MethodType {
ldc (java/util/List)I
areturn
Expand Down

0 comments on commit 87278ad

Please sign in to comment.