mirror of
https://github.com/mappu/miqt.git
synced 2025-05-13 15:10:21 +00:00
genbindings: more work on integer types
This commit is contained in:
parent
c9cf8af452
commit
0e8b48d1b8
@ -37,7 +37,9 @@ func (p CppParameter) RenderTypeCabi() string {
|
|||||||
ret = "size_t"
|
ret = "size_t"
|
||||||
case "qreal":
|
case "qreal":
|
||||||
ret = "double"
|
ret = "double"
|
||||||
case "qintptr", "quintptr":
|
case "qintptr":
|
||||||
|
ret = "intptr_t"
|
||||||
|
case "quintptr":
|
||||||
ret = "uintptr_t"
|
ret = "uintptr_t"
|
||||||
case "QRgb":
|
case "QRgb":
|
||||||
ret = "unsigned int"
|
ret = "unsigned int"
|
||||||
@ -155,7 +157,8 @@ func emitParametersCabi(m CppMethod, selfType string) string {
|
|||||||
// CABI: memory is moved into C.malloc/C.free
|
// CABI: memory is moved into C.malloc/C.free
|
||||||
// Go: converted to native Go string
|
// Go: converted to native Go string
|
||||||
if m.ReturnType.ParameterType == "QString" {
|
if m.ReturnType.ParameterType == "QString" {
|
||||||
tmp = append(tmp, "char** _out, size_t* _out_Strlen")
|
// Normally we would use size_t for a strlen, but Go calls C.GoStringN which takes a C.int
|
||||||
|
tmp = append(tmp, "char** _out, int* _out_Strlen")
|
||||||
|
|
||||||
} else if t, ok := m.ReturnType.QListOf(); ok {
|
} else if t, ok := m.ReturnType.QListOf(); ok {
|
||||||
// +1 pointer indirection since it's a heap array
|
// +1 pointer indirection since it's a heap array
|
||||||
@ -166,7 +169,7 @@ func emitParametersCabi(m CppMethod, selfType string) string {
|
|||||||
|
|
||||||
if t.ParameterType == "QString" {
|
if t.ParameterType == "QString" {
|
||||||
// Combo
|
// Combo
|
||||||
tmp = append(tmp, "char*** _out, int64_t** _out_Lengths, size_t* _out_len")
|
tmp = append(tmp, "char*** _out, int** _out_Lengths, size_t* _out_len") // Each length is a C.int for C.GoStringN use
|
||||||
} else if t.QtClassType() && !t.Pointer {
|
} else if t.QtClassType() && !t.Pointer {
|
||||||
// QList<QByteArray> QByteArray::Split()
|
// QList<QByteArray> QByteArray::Split()
|
||||||
// We need to pointer-ify each of the interior elements too
|
// We need to pointer-ify each of the interior elements too
|
||||||
@ -490,7 +493,7 @@ extern "C" {
|
|||||||
shouldReturn = m.ReturnType.ParameterType + " ret = "
|
shouldReturn = m.ReturnType.ParameterType + " ret = "
|
||||||
afterCall += "\t// Convert QStringList from C++ memory to manually-managed C memory\n"
|
afterCall += "\t// Convert QStringList from C++ memory to manually-managed C memory\n"
|
||||||
afterCall += "\tchar** __out = static_cast<char**>(malloc(sizeof(char*) * ret.length()));\n"
|
afterCall += "\tchar** __out = static_cast<char**>(malloc(sizeof(char*) * ret.length()));\n"
|
||||||
afterCall += "\tint64_t* __out_Lengths = static_cast<int64_t*>(malloc(sizeof(int64_t) * ret.length()));\n"
|
afterCall += "\tint* __out_Lengths = static_cast<int*>(malloc(sizeof(int) * ret.length()));\n"
|
||||||
afterCall += "\tfor (size_t i = 0, e = ret.length(); i < e; ++i) {\n"
|
afterCall += "\tfor (size_t i = 0, e = ret.length(); i < e; ++i) {\n"
|
||||||
afterCall += "\t\t// Convert QString from UTF-16 in C++ RAII memory to UTF-8 in manually-managed C memory\n"
|
afterCall += "\t\t// Convert QString from UTF-16 in C++ RAII memory to UTF-8 in manually-managed C memory\n"
|
||||||
afterCall += "\t\tQByteArray b = ret[i].toUtf8();\n"
|
afterCall += "\t\tQByteArray b = ret[i].toUtf8();\n"
|
||||||
|
@ -83,13 +83,20 @@ func (p CppParameter) RenderTypeGo() string {
|
|||||||
ret += "float32"
|
ret += "float32"
|
||||||
case "double", "qreal":
|
case "double", "qreal":
|
||||||
ret += "float64"
|
ret += "float64"
|
||||||
case "qsizetype":
|
case "qsizetype", "size_t":
|
||||||
if C.sizeof_size_t == 4 {
|
if C.sizeof_size_t == 4 {
|
||||||
ret += "uint32"
|
ret += "uint32"
|
||||||
} else {
|
} else {
|
||||||
ret += "uint64"
|
ret += "uint64"
|
||||||
}
|
}
|
||||||
case "qintptr":
|
case "qintptr":
|
||||||
|
var ptr *int
|
||||||
|
if unsafe.Sizeof(ptr) == 8 {
|
||||||
|
ret += "int64"
|
||||||
|
} else {
|
||||||
|
ret += "int32"
|
||||||
|
}
|
||||||
|
case "quintptr":
|
||||||
var ptr *int
|
var ptr *int
|
||||||
if unsafe.Sizeof(ptr) == 8 {
|
if unsafe.Sizeof(ptr) == 8 {
|
||||||
ret += "uint64"
|
ret += "uint64"
|
||||||
@ -113,6 +120,7 @@ func (p CppParameter) parameterTypeCgo() string {
|
|||||||
if strings.HasPrefix(tmp, "unsigned ") {
|
if strings.HasPrefix(tmp, "unsigned ") {
|
||||||
tmp = "u" + tmp[9:] // Cgo uses uchar, uint instead of full name
|
tmp = "u" + tmp[9:] // Cgo uses uchar, uint instead of full name
|
||||||
}
|
}
|
||||||
|
tmp = strings.Replace(tmp, `long long`, `longlong`, -1)
|
||||||
return "C." + strings.Replace(tmp, " ", "_", -1)
|
return "C." + strings.Replace(tmp, " ", "_", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,6 +230,8 @@ func emitParametersGo2CABIForwarding(m CppMethod) (preamble string, fowarding st
|
|||||||
// We want our functions to accept the Go wrapper type, and forward as cPointer()
|
// We want our functions to accept the Go wrapper type, and forward as cPointer()
|
||||||
tmp = append(tmp, p.ParameterName+".cPointer()")
|
tmp = append(tmp, p.ParameterName+".cPointer()")
|
||||||
|
|
||||||
|
} else if p.IntType() || p.ParameterType == "bool" {
|
||||||
|
tmp = append(tmp, "("+p.parameterTypeCgo()+")("+p.ParameterName+")")
|
||||||
} else {
|
} else {
|
||||||
// Default
|
// Default
|
||||||
tmp = append(tmp, p.ParameterName)
|
tmp = append(tmp, p.ParameterName)
|
||||||
@ -331,7 +341,7 @@ import "C"
|
|||||||
returnTypeDecl = "string"
|
returnTypeDecl = "string"
|
||||||
|
|
||||||
preamble += "var _out *C.char = nil\n"
|
preamble += "var _out *C.char = nil\n"
|
||||||
preamble += "var _out_Strlen C.size_t = 0\n"
|
preamble += "var _out_Strlen C.int = 0\n" // I think size_t is "better" but GoStringN() requires C.int
|
||||||
afterword += "ret := C.GoStringN(_out, _out_Strlen)\n"
|
afterword += "ret := C.GoStringN(_out, _out_Strlen)\n"
|
||||||
afterword += "C.free(_out)\n"
|
afterword += "C.free(_out)\n"
|
||||||
afterword += "return ret"
|
afterword += "return ret"
|
||||||
@ -370,6 +380,11 @@ import "C"
|
|||||||
afterword += "return ret1"
|
afterword += "return ret1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if m.ReturnType.IntType() || m.ReturnType.ParameterType == "bool" {
|
||||||
|
// Need to cast Cgo type to Go int type
|
||||||
|
shouldReturn = "ret := "
|
||||||
|
afterword += "return (" + m.ReturnType.RenderTypeGo() + ")(ret)\n"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
receiverAndMethod := `(this *` + c.ClassName + `) ` + m.SafeMethodName()
|
receiverAndMethod := `(this *` + c.ClassName + `) ` + m.SafeMethodName()
|
||||||
|
@ -53,7 +53,8 @@ func (p CppParameter) IntType() bool {
|
|||||||
"long", "unsigned long", "ulong", "qint32", "quint32",
|
"long", "unsigned long", "ulong", "qint32", "quint32",
|
||||||
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
|
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
|
||||||
"QRgb", // unsigned int
|
"QRgb", // unsigned int
|
||||||
"qintptr",
|
"qintptr", "quintptr",
|
||||||
|
"qsizetype", "size_t",
|
||||||
"double", "float", "qreal":
|
"double", "float", "qreal":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user