mirror of
https://github.com/mappu/miqt.git
synced 2025-02-08 14:10:22 +00:00
genbindings: replace virtualbase wrapper with friend function
This commit is contained in:
parent
1e26114255
commit
83989fd87e
@ -1086,22 +1086,13 @@ extern "C" {
|
|||||||
// real Qt parameters, in case there are protected enum types
|
// real Qt parameters, in case there are protected enum types
|
||||||
// (e.g. QAbstractItemView::CursorAction)
|
// (e.g. QAbstractItemView::CursorAction)
|
||||||
|
|
||||||
var parametersCabi []string
|
// Because (in the Go projection) this is only exposed as a
|
||||||
for _, p := range m.Parameters {
|
// super() argument to a real virtual override, we know that
|
||||||
parametersCabi = append(parametersCabi, p.RenderTypeCabi()+" "+p.cParameterName())
|
// the pointer type correctly points to our subclass and
|
||||||
}
|
// therefore no dynamic_cast<> validation is required
|
||||||
vbpreamble, vbforwarding := emitParametersCABI2CppForwarding(m.Parameters, "\t\t")
|
|
||||||
|
|
||||||
vbCallTarget := methodPrefixName + "::" + m.CppCallTarget() + "(" + vbforwarding + ")"
|
|
||||||
|
|
||||||
ret.WriteString(
|
ret.WriteString(
|
||||||
"\t// Wrapper to allow calling protected method\n" +
|
"\tfriend " + m.ReturnType.RenderTypeCabi() + " " + cabiVirtualBaseName(c, m) + "(" + emitParametersCabi(m, ifv(m.IsConst, "const ", "")+"void*") + ");\n\n",
|
||||||
"\t" + m.ReturnType.RenderTypeCabi() + " virtualbase_" + m.SafeMethodName() + "(" + strings.Join(parametersCabi, ", ") + ") " + ifv(m.IsConst, "const ", "") + "{\n" +
|
|
||||||
vbpreamble + "\n" +
|
|
||||||
emitAssignCppToCabi("\t\treturn ", m.ReturnType, vbCallTarget) + "\n" +
|
|
||||||
"\t}\n" +
|
|
||||||
|
|
||||||
"\n",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1343,26 +1334,24 @@ extern "C" {
|
|||||||
|
|
||||||
if !m.IsPureVirtual {
|
if !m.IsPureVirtual {
|
||||||
// This is not generally exposed in the Go binding, but when overriding
|
// This is not generally exposed in the Go binding, but when overriding
|
||||||
// the method, allows Go code to call super()
|
// the method, allows Go code to call super().
|
||||||
|
|
||||||
// It uses CABI-CABI, the CABI-QtC++ type conversion will be done
|
// This calls the target Qt C++ method directly using fully
|
||||||
// inside the class method so as to allow for accessing protected
|
// qualified syntax (`MiqtSubclass->QFoo::Bar()`). This method
|
||||||
// types.
|
// takes and returns CABI types.
|
||||||
// Both the parameters and return type are given in CABI format.
|
|
||||||
|
|
||||||
var parameterNames []string
|
var parametersCabi []string
|
||||||
for _, param := range m.Parameters {
|
for _, p := range m.Parameters {
|
||||||
parameterNames = append(parameterNames, param.cParameterName())
|
parametersCabi = append(parametersCabi, p.RenderTypeCabi()+" "+p.cParameterName())
|
||||||
}
|
}
|
||||||
|
vbpreamble, vbforwarding := emitParametersCABI2CppForwarding(m.Parameters, "\t")
|
||||||
|
|
||||||
// callTarget is an rvalue representing the full C++ function call.
|
callTarget := "( (" + ifv(m.IsConst, "const ", "") + cppClassName + "*)(self) )->" + c.ClassName + "::" + m.CppCallTarget() + "(" + vbforwarding + ")"
|
||||||
// These are never static
|
|
||||||
|
|
||||||
callTarget := "( (" + ifv(m.IsConst, "const ", "") + cppClassName + "*)(self) )->virtualbase_" + m.SafeMethodName() + "(" + strings.Join(parameterNames, `, `) + ")"
|
|
||||||
|
|
||||||
ret.WriteString(
|
ret.WriteString(
|
||||||
m.ReturnType.RenderTypeCabi() + " " + cabiVirtualBaseName(c, m) + "(" + emitParametersCabi(m, ifv(m.IsConst, "const ", "")+"void*") + ") {\n" +
|
m.ReturnType.RenderTypeCabi() + " " + cabiVirtualBaseName(c, m) + "(" + emitParametersCabi(m, ifv(m.IsConst, "const ", "")+"void*") + ") {\n" +
|
||||||
"\t" + ifv(m.ReturnType.Void(), "", "return ") + callTarget + ";\n" +
|
vbpreamble + "\n" +
|
||||||
|
fixupProtectedReferences(emitAssignCppToCabi("\treturn ", m.ReturnType, callTarget)) + "\n" +
|
||||||
"}\n" +
|
"}\n" +
|
||||||
"\n",
|
"\n",
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user