forked from therecipe/qt
/
body_output_cpp.go
114 lines (93 loc) · 2.67 KB
/
body_output_cpp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package converter
import (
"fmt"
"github.com/dsandor/qt/internal/binding/parser"
)
func CppOutputParameters(function *parser.Function, name string) string {
if function.Meta == parser.CONSTRUCTOR {
return CppOutput(name, function.Name, function)
}
return CppOutput(name, function.Output, function)
}
func CppOutputParametersFailed(function *parser.Function) string {
var output = GoOutputParametersFromCFailed(function)
if output == "nil" {
output = "NULL"
}
if output == "\"\"" {
c, _ := function.Class()
output = fmt.Sprintf("%v_PackedString {}", c.Module)
}
return output
}
func CppOutputParametersDeducedFromGeneric(function *parser.Function) string {
if function.TemplateModeGo != "" {
return fmt.Sprintf("<%v>", function.TemplateModeGo)
}
switch function.TemplateModeJNI {
case "Int":
{
return "<jint>"
}
case "Boolean":
{
return "<jboolean>"
}
case "Void":
{
return "<void>"
}
case "Object", "String":
{
if function.Name == "callObjectMethod" || function.Name == "callStaticObjectMethod" {
if function.OverloadNumber == "2" || function.OverloadNumber == "4" {
return ""
}
}
return "<jobject>"
}
}
return ""
}
func CppOutputParametersJNIGenericModes(function *parser.Function) []string {
switch function.Name {
case "callMethod", "callStaticMethod":
{
return []string{"Int", "Boolean", "Void"} //TODO: more primitives
}
case "getField", "setField", "getStaticField", "setStaticField":
{
return []string{"Int", "Boolean"} //TODO: more primitives
}
case "getObjectField", "getStaticObjectField", "callObjectMethod", "callStaticObjectMethod":
{
return []string{"Object", "String"} //TODO: add []string, []int, []object, ...
}
}
return make([]string, 0)
}
func CppOutputTemplateJS(function *parser.Function) string {
out := parser.CleanValue(function.Output)
switch out {
case "char", "qint8", "uchar", "quint8", "GLubyte", "QString", "QStringList":
return "emscripten::val"
case "longlong", "long long", "qlonglong", "qint64":
if function.BoundByEmscripten || function.SignalMode == parser.CALLBACK {
return "long"
}
case "ulonglong", "unsigned long long", "qulonglong", "quint64":
if function.BoundByEmscripten || function.SignalMode == parser.CALLBACK {
return "unsigned long"
}
}
switch {
case len(out) == 0:
return "void"
case isClass(out) || parser.IsPackedList(out) || parser.IsPackedMap(out) || cppType(function, function.Output) == "void*" || cppType(function, function.Output) == "uintptr_t":
return "uintptr_t"
case isEnum(function.ClassName(), out) && (function.BoundByEmscripten || function.SignalMode == parser.CALLBACK):
return "long"
default:
return out
}
}