genbindings: detect argcargv pattern at any location

This commit is contained in:
mappu 2024-08-18 15:57:29 +12:00
parent 2a93cbf2d3
commit 148d8ea6e0
2 changed files with 12 additions and 9 deletions

View File

@ -113,7 +113,7 @@ func emitParametersGo(params []CppParameter) string {
for i, p := range params { for i, p := range params {
if i == 0 && IsArgcArgv(params) { if IsArgcArgv(params, i) {
skipNext = true skipNext = true
tmp = append(tmp, "args []string") tmp = append(tmp, "args []string")
@ -140,7 +140,7 @@ func emitParametersGo2CABIForwarding(m CppMethod) (preamble string, fowarding st
for i, p := range m.Parameters { for i, p := range m.Parameters {
if i == 0 && IsArgcArgv(m.Parameters) { if IsArgcArgv(m.Parameters, i) {
skipNext = true skipNext = true
// QApplication constructor. Convert 'args' into Qt's wanted types // QApplication constructor. Convert 'args' into Qt's wanted types
// Qt has a warning in the docs saying these pointers must be valid // Qt has a warning in the docs saying these pointers must be valid

View File

@ -70,14 +70,17 @@ type CppMethod struct {
IsSignal bool IsSignal bool
} }
func IsArgcArgv(params []CppParameter) bool { 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. // QApplication/QGuiApplication constructors are the only expected example of this.
return (len(params) > 1 && return (len(params) > pos+1 &&
params[0].ParameterName == "argc" && params[pos].ParameterName == "argc" &&
params[0].ParameterType == "int" && params[pos].ParameterType == "int" &&
params[0].ByRef && params[pos].ByRef &&
params[1].ParameterName == "argv" && params[pos+1].ParameterName == "argv" &&
params[1].ParameterType == "char **") params[pos+1].ParameterType == "char **")
}
} }
func (nm CppMethod) SafeMethodName() string { func (nm CppMethod) SafeMethodName() string {