genbindings/cabi: inline return statements in emitAssignCppToCabi

This commit is contained in:
mappu 2024-11-15 15:10:52 +13:00
parent caee076af8
commit 598b8bdb89

View File

@ -345,6 +345,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
if p.Void() { if p.Void() {
shouldReturn = "" shouldReturn = ""
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if p.ParameterType == "QString" { } else if p.ParameterType == "QString" {
@ -368,6 +369,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
afterCall += indent + namePrefix + "_ms.data = static_cast<char*>(malloc(" + namePrefix + "_ms.len));\n" afterCall += indent + namePrefix + "_ms.data = static_cast<char*>(malloc(" + namePrefix + "_ms.len));\n"
afterCall += indent + "memcpy(" + namePrefix + "_ms.data, " + namePrefix + "_b.data(), " + namePrefix + "_ms.len);\n" afterCall += indent + "memcpy(" + namePrefix + "_ms.data, " + namePrefix + "_b.data(), " + namePrefix + "_ms.len);\n"
afterCall += indent + assignExpression + namePrefix + "_ms;\n" afterCall += indent + assignExpression + namePrefix + "_ms;\n"
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if p.ParameterType == "QByteArray" { } else if p.ParameterType == "QByteArray" {
// C++ has given us a QByteArray. CABI needs this as a struct miqt_string // C++ has given us a QByteArray. CABI needs this as a struct miqt_string
@ -380,6 +382,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
afterCall += indent + namePrefix + "_ms.data = static_cast<char*>(malloc(" + namePrefix + "_ms.len));\n" afterCall += indent + namePrefix + "_ms.data = static_cast<char*>(malloc(" + namePrefix + "_ms.len));\n"
afterCall += indent + "memcpy(" + namePrefix + "_ms.data, " + namePrefix + "_qb.data(), " + namePrefix + "_ms.len);\n" afterCall += indent + "memcpy(" + namePrefix + "_ms.data, " + namePrefix + "_qb.data(), " + namePrefix + "_ms.len);\n"
afterCall += indent + assignExpression + namePrefix + "_ms;\n" afterCall += indent + assignExpression + namePrefix + "_ms;\n"
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if t, ok := p.QListOf(); ok { } else if t, ok := p.QListOf(); ok {
@ -402,6 +405,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
afterCall += indent + "" + namePrefix + "_out.data = static_cast<void*>(" + namePrefix + "_arr);\n" afterCall += indent + "" + namePrefix + "_out.data = static_cast<void*>(" + namePrefix + "_arr);\n"
afterCall += indent + assignExpression + "" + namePrefix + "_out;\n" afterCall += indent + assignExpression + "" + namePrefix + "_out;\n"
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if t, ok := p.QSetOf(); ok { } else if t, ok := p.QSetOf(); ok {
@ -420,6 +424,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
afterCall += indent + "" + namePrefix + "_out.data = static_cast<void*>(" + namePrefix + "_arr);\n" afterCall += indent + "" + namePrefix + "_out.data = static_cast<void*>(" + namePrefix + "_arr);\n"
afterCall += indent + assignExpression + "" + namePrefix + "_out;\n" afterCall += indent + assignExpression + "" + namePrefix + "_out;\n"
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if kType, vType, ok := p.QMapOf(); ok { } else if kType, vType, ok := p.QMapOf(); ok {
// QMap<K,V> // QMap<K,V>
@ -444,6 +449,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
afterCall += indent + "" + namePrefix + "_out.values = static_cast<void*>(" + namePrefix + "_varr);\n" afterCall += indent + "" + namePrefix + "_out.values = static_cast<void*>(" + namePrefix + "_varr);\n"
afterCall += indent + assignExpression + "" + namePrefix + "_out;\n" afterCall += indent + assignExpression + "" + namePrefix + "_out;\n"
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if p.QtClassType() && p.ByRef { } else if p.QtClassType() && p.ByRef {
// It's a pointer in disguise, just needs one cast // It's a pointer in disguise, just needs one cast
@ -459,6 +465,7 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
} else { } else {
afterCall += indent + "" + assignExpression + "&" + namePrefix + "_ret;\n" afterCall += indent + "" + assignExpression + "&" + namePrefix + "_ret;\n"
} }
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if p.QtClassType() && !p.Pointer { } else if p.QtClassType() && !p.Pointer {
@ -474,9 +481,11 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
} else { } else {
afterCall += indent + "" + assignExpression + "static_cast<" + p.RenderTypeCabi() + ">(" + namePrefix + "_ret);\n" afterCall += indent + "" + assignExpression + "static_cast<" + p.RenderTypeCabi() + ">(" + namePrefix + "_ret);\n"
} }
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else if p.Const { } else if p.Const {
shouldReturn += "(" + p.RenderTypeCabi() + ") " shouldReturn += "(" + p.RenderTypeCabi() + ") "
return indent + shouldReturn + rvalue + ";\n" + afterCall
} else { } else {
// Basic type // Basic type
@ -485,9 +494,9 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
shouldReturn += "&" shouldReturn += "&"
} }
return indent + shouldReturn + rvalue + ";\n" + afterCall
} }
return indent + shouldReturn + rvalue + ";\n" + afterCall
} }
// getReferencedTypes finds all referenced Qt types in this file. // getReferencedTypes finds all referenced Qt types in this file.