Skip to content

Commit

Permalink
JACOBIN-345 Initial logic for adding a method table to classes
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Sep 1, 2023
1 parent 61d2f9c commit 7819158
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/classloader/classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ type Klass struct {
}

type ClData struct {
Name string
Superclass string
Module string
Pkg string // package name, if any. (so named, b/c 'package' is a golang keyword)
Interfaces []uint16 // indices into UTF8Refs
Fields []Field
Methods []Method
Attributes []Attr
SourceFile string
Bootstraps []BootstrapMethod
CP CPool
Access AccessFlags
ClInit byte // 0 = no clinit, 1 = clinit not run, 2 clinit run
Name string
Superclass string
Module string
Pkg string // package name, if any. (so named, b/c 'package' is a golang keyword)
Interfaces []uint16 // indices into UTF8Refs
Fields []Field
MethodTable map[string]*Method
Methods []Method
Attributes []Attr
SourceFile string
Bootstraps []BootstrapMethod
CP CPool
Access AccessFlags
ClInit byte // 0 = no clinit, 1 = clinit not run, 2 clinit run
}

type CPool struct {
Expand Down
7 changes: 7 additions & 0 deletions src/classloader/classloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,14 @@ func convertToPostableClass(fullyParsedClass *ParsedClass) ClData {
}
}

kd.MethodTable = make(map[string]*Method)
if len(fullyParsedClass.methods) > 0 {
for i := 0; i < len(fullyParsedClass.methods); i++ {
kdm := Method{}
kdm.Name = uint16(fullyParsedClass.methods[i].name)
methName := fullyParsedClass.utf8Refs[int(kdm.Name)].content
kdm.Desc = uint16(fullyParsedClass.methods[i].description)
methDesc := fullyParsedClass.utf8Refs[int(kdm.Desc)].content
kdm.AccessFlags = fullyParsedClass.methods[i].accessFlags
kdm.CodeAttr.MaxStack = fullyParsedClass.methods[i].codeAttr.maxStack
kdm.CodeAttr.MaxLocals = fullyParsedClass.methods[i].codeAttr.maxLocals
Expand Down Expand Up @@ -531,8 +534,12 @@ func convertToPostableClass(fullyParsedClass *ParsedClass) ClData {
}
kdm.Deprecated = fullyParsedClass.methods[i].deprecated
kd.Methods = append(kd.Methods, kdm)

methodTableKey := methName + methDesc
kd.MethodTable[methodTableKey] = &kdm
}
}

if len(fullyParsedClass.attributes) > 0 {
for i := 0; i < len(fullyParsedClass.attributes); i++ {
kda := Attr{
Expand Down

0 comments on commit 7819158

Please sign in to comment.