mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
genbindings: move type renderering to CppParameter methods
This commit is contained in:
parent
4b803eb453
commit
179c37dfe0
@ -13,7 +13,7 @@ func emitParametersCpp(params []CppParameter, selfType string) string {
|
||||
}
|
||||
|
||||
for _, p := range params {
|
||||
tmp = append(tmp, p.ParameterName+" "+p.ParameterType)
|
||||
tmp = append(tmp, p.RenderTypeCpp()+" "+p.ParameterName)
|
||||
}
|
||||
return strings.Join(tmp, ", ")
|
||||
}
|
||||
@ -55,7 +55,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
for _, m := range c.Methods {
|
||||
ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", m.ReturnType, c.ClassName, m.SafeMethodName(), emitParametersCpp(m.Parameters, "P"+c.ClassName)))
|
||||
ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", m.ReturnType.RenderTypeCpp(), c.ClassName, m.SafeMethodName(), emitParametersCpp(m.Parameters, "P"+c.ClassName)))
|
||||
}
|
||||
|
||||
ret.WriteString("\n")
|
||||
@ -93,11 +93,11 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
|
||||
// Need to take an extra 'self' parameter
|
||||
|
||||
shouldReturn := "return "
|
||||
if m.ReturnType == "void" {
|
||||
if m.ReturnType.ParameterType == "void" {
|
||||
shouldReturn = ""
|
||||
}
|
||||
|
||||
ret.WriteString(fmt.Sprintf("%s %s_%s(%s) {\n\t%sstatic_cast<%s*>(self)->%s(%s);\n}\n\n", m.ReturnType, c.ClassName, m.SafeMethodName(), emitParametersCpp(m.Parameters, "P"+c.ClassName),
|
||||
ret.WriteString(fmt.Sprintf("%s %s_%s(%s) {\n\t%sstatic_cast<%s*>(self)->%s(%s);\n}\n\n", m.ReturnType.RenderTypeCpp(), c.ClassName, m.SafeMethodName(), emitParametersCpp(m.Parameters, "P"+c.ClassName),
|
||||
shouldReturn, c.ClassName, m.MethodName, emitParametersNames(m.Parameters, c.ClassName),
|
||||
))
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func emitParametersGo(params []CppParameter) string {
|
||||
tmp := make([]string, 0, len(params))
|
||||
for _, p := range params {
|
||||
tmp = append(tmp, p.ParameterType+" "+p.ParameterName)
|
||||
tmp = append(tmp, p.ParameterName+" "+p.RenderTypeGo())
|
||||
}
|
||||
return strings.Join(tmp, ", ")
|
||||
}
|
||||
@ -61,14 +61,14 @@ import "C"
|
||||
// TODO for any known pointer type, call its cPointer() method instead of passing it directly
|
||||
|
||||
shouldReturn := "return "
|
||||
returnTypeDecl := m.ReturnType
|
||||
returnTypeDecl := m.ReturnType.ParameterType // FIXME handle byRef/const here too
|
||||
if returnTypeDecl == "void" {
|
||||
shouldReturn = ""
|
||||
returnTypeDecl = ""
|
||||
}
|
||||
|
||||
ret.WriteString(`
|
||||
func (this *` + c.ClassName + `) ` + m.MethodName + `(` + emitParametersGo(m.Parameters) + `) ` + returnTypeDecl + ` {
|
||||
func (this *` + c.ClassName + `) ` + m.SafeMethodName() + `(` + emitParametersGo(m.Parameters) + `) ` + returnTypeDecl + ` {
|
||||
` + shouldReturn + ` C.` + c.ClassName + `_` + m.SafeMethodName() + `(` + emitParametersNames(m.Parameters, c.ClassName) + `)
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,34 @@ type CppParameter struct {
|
||||
ByRef bool
|
||||
}
|
||||
|
||||
func (p CppParameter) RenderTypeCpp() string {
|
||||
ret := ""
|
||||
if p.ByRef {
|
||||
ret += "&"
|
||||
}
|
||||
ret += p.ParameterType
|
||||
if p.Pointer {
|
||||
ret += "*"
|
||||
}
|
||||
return ret // ignore const
|
||||
}
|
||||
|
||||
func (p CppParameter) RenderTypeGo() string {
|
||||
if p.Pointer && p.ParameterType == "char" {
|
||||
return "string"
|
||||
}
|
||||
|
||||
ret := ""
|
||||
if p.ByRef || p.Pointer {
|
||||
/*
|
||||
if p.ParameterType[0] == 'Q' {
|
||||
ret += "C.P" // use our void typedef instead
|
||||
} else {
|
||||
*/
|
||||
ret += "*"
|
||||
}
|
||||
ret += p.ParameterType
|
||||
return ret // ignore const
|
||||
}
|
||||
|
||||
type CppProperty struct {
|
||||
|
Loading…
Reference in New Issue
Block a user