diff --git a/cmd/genbindings/intermediate.go b/cmd/genbindings/intermediate.go index 3c08d88e..11d222c5 100644 --- a/cmd/genbindings/intermediate.go +++ b/cmd/genbindings/intermediate.go @@ -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 diff --git a/cmd/genbindings/main.go b/cmd/genbindings/main.go index a212af40..c951ae27 100644 --- a/cmd/genbindings/main.go +++ b/cmd/genbindings/main.go @@ -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) } diff --git a/cmd/genbindings/statetracker.go b/cmd/genbindings/statetracker.go new file mode 100644 index 00000000..c14639c5 --- /dev/null +++ b/cmd/genbindings/statetracker.go @@ -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 */} + } +}