Skip to content

Commit

Permalink
Fix bytecode parsing with empty methods
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed Oct 24, 2024
1 parent 10a7b72 commit 274ea21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class ByteCodeParser {
Error(e)
}
}

}

private fun PeekingIterator<String>.readClass(classHeader: String): Class {
Expand All @@ -107,9 +106,9 @@ private fun PeekingIterator<String>.readMethod(): Method {
val match = MethodRegex.matchEntire(next())
?: throw IllegalStateException("Expected method but got '${peek()}'")
val header = match.getValue("header")
if (next().trim() != "Code:") {
throw IllegalStateException("Expected 'Code:' but got '${peek()}'")
}
// A method can have no code
if (next().trim() != "Code:") return Method(header, InstructionSet(ISA.ByteCode, emptyList()))

val instructions = readInstructions()
val lineNumbers = readLineNumbers()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ class CodeTextArea(
if (sourceTextArea != null) {
addMouseListener(object : MouseAdapter() {
override fun mouseClicked(event: MouseEvent) {
val codeLine = getLineOfOffset(viewToModel2D(event.point))
val line = code?.getSourceLine(codeLine) ?: return
if (line == -1) return
sourceTextArea.gotoLine(this@CodeTextArea, line - 1)
if (isSyncLinesEnabled) {
val codeLine = getLineOfOffset(viewToModel2D(event.point))
val line = code?.getSourceLine(codeLine) ?: return
if (line == -1) return
sourceTextArea.gotoLine(this@CodeTextArea, line - 1)
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,8 @@ data class Instruction(
data class MethodReference(val address: Int, val name: String)

fun List<Instruction>.withLineNumbers(lineNumbers: IntIntMap): List<Instruction> {
return map { it.copy(lineNumber = lineNumbers.getOrDefault(it.address, -1)) }
return map {
val line = lineNumbers.getOrDefault(it.address, -1)
if (line != -1) it.copy(lineNumber = line) else it
}
}

0 comments on commit 274ea21

Please sign in to comment.