genbindings/typedefs: collect child class typedefs

This commit is contained in:
mappu 2024-08-26 22:45:52 +12:00
parent f6336617a0
commit 02370ce0ea
2 changed files with 32 additions and 13 deletions

View File

@ -93,20 +93,11 @@ func parseHeader(topLevel []interface{}) (*CppParsedHeader, error) {
// Should be treated like a typedef
case "TypedefDecl":
// Must have a name
nodename, ok := node["name"].(string)
if !ok {
return nil, errors.New("node has no name")
}
if typ, ok := node["type"].(map[string]interface{}); ok {
if qualType, ok := typ["qualType"].(string); ok {
ret.Typedefs = append(ret.Typedefs, CppTypedef{
Alias: nodename,
UnderlyingType: qualType,
})
}
td, err := processTypedef(node, "")
if err != nil {
return nil, fmt.Errorf("processTypedef: %w", err)
}
ret.Typedefs = append(ret.Typedefs, td)
case "CXXMethodDecl":
// A C++ class method implementation directly in the header
@ -120,6 +111,25 @@ func parseHeader(topLevel []interface{}) (*CppParsedHeader, error) {
return &ret, nil // done
}
func processTypedef(node map[string]interface{}, addNamePrefix string) (CppTypedef, error) {
// Must have a name
nodename, ok := node["name"].(string)
if !ok {
return CppTypedef{}, errors.New("node has no name")
}
if typ, ok := node["type"].(map[string]interface{}); ok {
if qualType, ok := typ["qualType"].(string); ok {
return CppTypedef{
Alias: addNamePrefix + nodename,
UnderlyingType: parseSingleTypeString(qualType),
}, nil
}
}
return CppTypedef{}, errors.New("processTypedef: ???")
}
func processClassType(node map[string]interface{}, addNamePrefix string) (CppClass, error) {
var ret CppClass
ret.CanDelete = true
@ -257,6 +267,14 @@ nextMethod:
ret.ChildClassdefs = append(ret.ChildClassdefs, child)
case "TypedefDecl":
// Child class typedef
td, err := processTypedef(node, nodename+"::")
if err != nil {
panic(fmt.Errorf("processTypedef: %w", err)) // A real problem
}
ret.ChildTypedefs = append(ret.ChildTypedefs, td)
case "CXXConstructorDecl":
if isImplicit, ok := node["isImplicit"].(bool); ok && isImplicit {

View File

@ -185,6 +185,7 @@ type CppClass struct {
Props []CppProperty
CanDelete bool
ChildTypedefs []CppTypedef
ChildClassdefs []CppClass
}