genbindings/cabi: move method renaming to helper function

This commit is contained in:
mappu 2024-09-11 18:06:17 +12:00
parent 7880f14c52
commit d3a159a462
3 changed files with 12 additions and 8 deletions

View File

@ -198,6 +198,16 @@ func (m CppMethod) CppCallTarget() string {
return m.MethodName
}
func (m *CppMethod) Rename(newName string) {
if m.OverrideMethodName == "" {
m.OverrideMethodName = m.MethodName
} else {
// If it was already set, we're already a level of overload resolution deep - preserve it
}
m.MethodName = newName
}
func IsArgcArgv(params []CppParameter, pos int) bool {
// Check if the arguments starting at position=pos are the argc/argv pattern.
// QApplication/QGuiApplication constructors are the only expected example of this.

View File

@ -33,8 +33,7 @@ func astTransformOptional(parsed *CppParsedHeader) {
// Add method copies
for x := optionalStart; x < len(m.Parameters); x++ {
dupMethod := m // copy
dupMethod.MethodName = m.MethodName + fmt.Sprintf("%d", x+1)
dupMethod.OverrideMethodName = m.MethodName
dupMethod.Rename(m.MethodName + fmt.Sprintf("%d", x+1))
dupMethod.Parameters = m.Parameters[0 : x+1]
dupMethod.HiddenParams = m.Parameters[x+1:]

View File

@ -63,12 +63,7 @@ func astTransformOverloads(parsed *CppParsedHeader) {
}
existing[proposedName] = struct{}{}
if m.OverrideMethodName == "" {
m.OverrideMethodName = m.MethodName
} else {
// If it was already set, we're already a level of overload resolution deep - preserve it
}
m.MethodName = proposedName
m.Rename(proposedName)
c.Methods[j] = m
}