genbindings: refactor move state tracker to new file

This commit is contained in:
mappu 2024-11-15 14:24:24 +13:00
parent 6ae2235cb4
commit 4fbf4c702a
3 changed files with 41 additions and 36 deletions

View File

@ -5,33 +5,6 @@ import (
"strings"
)
type lookupResultClass struct {
PackageName string
Class CppClass
}
type lookupResultTypedef struct {
PackageName string
Typedef CppTypedef
}
type lookupResultEnum struct {
PackageName string
Enum CppEnum
}
var (
KnownClassnames map[string]lookupResultClass // Entries of the form QFoo::Bar if it is an inner class
KnownTypedefs map[string]lookupResultTypedef
KnownEnums map[string]lookupResultEnum
)
func flushKnownTypes() {
KnownClassnames = make(map[string]lookupResultClass)
KnownTypedefs = make(map[string]lookupResultTypedef)
KnownEnums = make(map[string]lookupResultEnum)
}
type CppParameter struct {
ParameterName string
ParameterType string

View File

@ -164,15 +164,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b
atr.Process(parsed)
// Update global state tracker (AFTER astTransformChildClasses)
for _, c := range parsed.Classes {
KnownClassnames[c.ClassName] = lookupResultClass{packageName, c /* copy */}
}
for _, td := range parsed.Typedefs {
KnownTypedefs[td.Alias] = lookupResultTypedef{packageName, td /* copy */}
}
for _, en := range parsed.Enums {
KnownEnums[en.EnumName] = lookupResultEnum{packageName, en /* copy */}
}
addKnownTypes(packageName, parsed)
processHeaders = append(processHeaders, parsed)
}

View File

@ -0,0 +1,40 @@
package main
type lookupResultClass struct {
PackageName string
Class *CppClass
}
type lookupResultTypedef struct {
PackageName string
Typedef CppTypedef
}
type lookupResultEnum struct {
PackageName string
Enum CppEnum
}
var (
KnownClassnames map[string]lookupResultClass // Entries of the form QFoo::Bar if it is an inner class
KnownTypedefs map[string]lookupResultTypedef
KnownEnums map[string]lookupResultEnum
)
func flushKnownTypes() {
KnownClassnames = make(map[string]lookupResultClass)
KnownTypedefs = make(map[string]lookupResultTypedef)
KnownEnums = make(map[string]lookupResultEnum)
}
func addKnownTypes(packageName string, parsed *CppParsedHeader) {
for i, c := range parsed.Classes {
KnownClassnames[c.ClassName] = lookupResultClass{packageName, &parsed.Classes[i] /* reference */}
}
for _, td := range parsed.Typedefs {
KnownTypedefs[td.Alias] = lookupResultTypedef{packageName, td /* copy */}
}
for _, en := range parsed.Enums {
KnownEnums[en.EnumName] = lookupResultEnum{packageName, en /* copy */}
}
}