Skip to content

Commit

Permalink
recurse attributes in Code
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Nov 13, 2022
1 parent 494ddfd commit ed263c1
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions demo/src/main/scala/org/polyvariant/classfile/demo/DemoMain.scala
Expand Up @@ -15,6 +15,7 @@ import scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.annotation.JSExport
import scala.scalajs.js.annotation.JSExportTopLevel
import org.scalajs.dom.html.TableRow

@js.native
@JSGlobal
Expand All @@ -28,33 +29,38 @@ object DemoMain {

val output = document.getElementById("output")

def renderAttributes(attributes: List[AttributeModel]) = table(
tbody(
attributes.map(renderAttribute)
)
)

def renderAttribute(attr: AttributeModel): TypedTag[Element] = {
val extras =
attr match {
case c: AttributeModel.Code =>
List(
td("max stack: " + c.maxStack),
td("max locals: " + c.maxLocals),
td("instruction count: " + c.code.length),
td("exception table count: " + c.exceptionTable.length),
td("attributes: ", renderAttributes(c.attributes)),
)

case AttributeModel.Unsupported(name, bytes) =>
td("attribute unknown: " + s" (0x${bytes.toHex})") :: Nil

case _ => td("attribute unknown") :: Nil
}

tr(td(attr.attrName), extras)
}

def renderMethod(method: MethodModel): TypedTag[Element] = tr(
td(method.name),
td(method.descriptor),
td(
table(
tbody(
method.attributes.map { attr =>
val extras =
attr match {
case c: AttributeModel.Code =>
List(
td("max stack: " + c.maxStack),
td("max locals: " + c.maxLocals),
td("instruction count: " + c.code.length),
td("exception table count: " + c.exceptionTable.length),
td("attribute count: " + c.attributes.length),
)
case _ => td("attribute unknown") :: Nil
}

tr(
td(attr.attrName),
extras,
)
}
)
)
renderAttributes(method.attributes)
),
)

Expand Down

0 comments on commit ed263c1

Please sign in to comment.