genbindings: refactor class handling

This commit is contained in:
mappu 2024-08-10 12:53:26 +12:00
parent aaa9340808
commit c06acd0a1b
2 changed files with 22 additions and 15 deletions

View File

@ -33,23 +33,19 @@ func parseHeader(inner []interface{}) (*CppParsedHeader, error) {
}
fmt.Printf("-> %q name=%q\n", kind, nodename)
if classInner, ok := node["inner"].([]interface{}); ok {
// Check if this was 'struct' (default visible) or 'class' (default invisible)
visible := true
if tagUsed, ok := node["tagUsed"].(string); ok && tagUsed == "class" {
visible = false
}
// Process the inner class definition
obj, err := processType(classInner, nodename, visible)
if err != nil {
panic(err)
}
ret.Classes = append(ret.Classes, obj)
if _, ok := node["inner"]; !ok {
continue // Forward class declaration only, do not include
}
// Process the inner class definition
obj, err := processClassType(node, nodename)
if err != nil {
panic(err)
}
ret.Classes = append(ret.Classes, obj)
case "StaticAssertDecl":
// ignore
@ -61,10 +57,17 @@ func parseHeader(inner []interface{}) (*CppParsedHeader, error) {
return &ret, nil // done
}
func processType(inner []interface{}, className string, visibility bool) (CppClass, error) {
func processClassType(node map[string]interface{}, className string) (CppClass, error) {
var ret CppClass
ret.ClassName = className
inner, _ := node["inner"].([]interface{}) // Cannot fail, the parent call already checked that `inner` was present
// Check if this was 'struct' (default visible) or 'class' (default invisible)
visibility := true
if tagUsed, ok := node["tagUsed"].(string); ok && tagUsed == "class" {
visibility = false
}
nextMethod:
for _, node := range inner {
node, ok := node.(map[string]interface{})
@ -97,6 +100,9 @@ nextMethod:
case "FriendDecl":
// Safe to ignore
case "VisibilityAttr":
// These seem to have no useful content
case "CXXConstructorDecl":

View File

@ -69,6 +69,7 @@ func (nm CppMethod) SafeMethodName() string {
type CppClass struct {
ClassName string
Abstract bool
Ctors []CppMethod // only use the parameters
Extends []string
Methods []CppMethod