genbindings: replace const_cast<>(self) with const self*

This commit is contained in:
mappu 2024-09-11 17:40:52 +12:00
parent cf6dc40a1f
commit 0689949bc2
2 changed files with 10 additions and 5 deletions

View File

@ -460,7 +460,7 @@ extern "C" {
} }
for _, m := range c.Methods { for _, m := range c.Methods {
ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), emitParametersCabi(m, cClassName+"*"))) ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+cClassName+"*")))
if m.IsSignal { if m.IsSignal {
ret.WriteString(fmt.Sprintf("%s %s_connect_%s(%s* self, void* slot);\n", emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), cClassName)) ret.WriteString(fmt.Sprintf("%s %s_connect_%s(%s* self, void* slot);\n", emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), cClassName))
@ -687,8 +687,6 @@ extern "C" {
if m.IsStatic { if m.IsStatic {
callTarget = c.ClassName + "::" callTarget = c.ClassName + "::"
} else if m.IsConst {
callTarget = "const_cast<const " + c.ClassName + "*>(self)->"
} }
if m.LinuxOnly { if m.LinuxOnly {
@ -704,7 +702,7 @@ extern "C" {
"#endif\n"+ "#endif\n"+
"}\n"+ "}\n"+
"\n", "\n",
emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), emitParametersCabi(m, cClassName+"*"), emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+cClassName+"*"),
preamble, preamble,
shouldReturn, callTarget, nativeMethodName, forwarding, shouldReturn, callTarget, nativeMethodName, forwarding,
afterCall, afterCall,
@ -720,7 +718,7 @@ extern "C" {
"%s"+ "%s"+
"}\n"+ "}\n"+
"\n", "\n",
emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), emitParametersCabi(m, cClassName+"*"), emitReturnTypeCabi(m.ReturnType), cClassName, m.SafeMethodName(), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+cClassName+"*"),
preamble, preamble,
shouldReturn, callTarget, nativeMethodName, forwarding, shouldReturn, callTarget, nativeMethodName, forwarding,
afterCall, afterCall,

View File

@ -27,3 +27,10 @@ func prettyPrint(obj interface{}) {
log.Println(string(jb)) log.Println(string(jb))
} }
func ifv[T any](condition bool, trueval T, falseval T) T {
if condition {
return trueval
}
return falseval
}