@@ -38,7 +38,7 @@ var reservedWords = map[string]bool{
38
38
"string" : true ,
39
39
}
40
40
41
- var typeMap = map [string ]string {
41
+ var goTypeFixupMap = map [string ]string {
42
42
"*kernel.Boolean_t" : "*int" ,
43
43
"*kernel.UniChar" : "*uint16" ,
44
44
"kernel.Boolean_t" : "int" ,
@@ -47,6 +47,12 @@ var typeMap = map[string]string{
47
47
"uint8_t" : "byte" ,
48
48
}
49
49
50
+ var objCtoCMap = map [string ]string {
51
+ "NSInteger" : "int" ,
52
+ "NSUInteger" : "uint" ,
53
+ "BOOL" : "bool" ,
54
+ }
55
+
50
56
// GoArgs return go function args
51
57
func (f * Function ) GoArgs (currentModule * modules.Module ) string {
52
58
// log.Println("rendering function", f.Name)
@@ -64,7 +70,7 @@ func (f *Function) GoArgs(currentModule *modules.Module) string {
64
70
p .Name = p .Name + "_"
65
71
}
66
72
typ := p .Type .GoName (currentModule , true )
67
- if v , ok := typeMap [typ ]; ok {
73
+ if v , ok := goTypeFixupMap [typ ]; ok {
68
74
typ = v
69
75
}
70
76
args = append (args , fmt .Sprintf ("%s %s" , p .Name , typ ))
@@ -79,7 +85,7 @@ func (f *Function) GoReturn(currentModule *modules.Module) string {
79
85
}
80
86
// log.Printf("rendering GoReturn function return: %s %T", f.ReturnType, f.ReturnType)
81
87
typ := f .ReturnType .GoName (currentModule , true )
82
- if v , ok := typeMap [typ ]; ok {
88
+ if v , ok := goTypeFixupMap [typ ]; ok {
83
89
typ = v
84
90
}
85
91
return typ
@@ -93,6 +99,7 @@ func (f *Function) CArgs(currentModule *modules.Module) string {
93
99
// log.Printf("rendering cfunction arg: %s %s %T", p.Name, p.Type, p.Type)
94
100
typ := p .Type .CName ()
95
101
if cs , ok := p .Type .(CSignatureer ); ok {
102
+ fmt .Printf ("has CSignatureer: %T %v -> %v\n " , p .Type , typ , cs .CSignature ())
96
103
typ = cs .CSignature ()
97
104
}
98
105
// check reserved words
@@ -174,7 +181,12 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
174
181
case * typing.PrimitiveType :
175
182
sb .WriteString (cw .IndentStr + fmt .Sprintf (" C.%s(%s)" , tt .CName (), p .GoName ()))
176
183
case * typing.PointerType :
177
- sb .WriteString (cw .IndentStr + fmt .Sprintf (" (*C.%s)(unsafe.Pointer(%s))" , tt .Type .ObjcName (), p .GoName ()))
184
+ cTyp := tt .Type .CName ()
185
+ if v , ok := objCtoCMap [cTyp ]; ok {
186
+ // note: we should drive use of this branch down
187
+ cTyp = v
188
+ }
189
+ sb .WriteString (cw .IndentStr + fmt .Sprintf (" (*C.%s)(unsafe.Pointer(%s))" , cTyp , p .GoName ()))
178
190
default :
179
191
sb .WriteString (cw .IndentStr + p .GoName ())
180
192
}
@@ -192,6 +204,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
192
204
switch tt := f .ReturnType .(type ) {
193
205
case * typing.StructType , * typing.PointerType :
194
206
cw .WriteLineF ("return *(*%s)(unsafe.Pointer(&%s))" , tt .GoName (currentModule , true ), resultName )
207
+ case * typing.CStringType :
208
+ cw .WriteLineF ("return C.GoString(%s)" , resultName )
195
209
default :
196
210
cw .WriteLineF ("return %s(%s)" , returnTypeStr , resultName )
197
211
}
@@ -253,7 +267,10 @@ func (f *Function) WriteObjcWrapper(currentModule *modules.Module, cw *CodeWrite
253
267
var conv string
254
268
switch tt := p .Type .(type ) {
255
269
case * typing.PointerType :
270
+ cw .WriteLineF ("// -> %T" , tt .Type )
256
271
conv = tt .ObjcName ()
272
+ // case *typing.AliasType:
273
+ // conv = tt.ObjcName() + "*"
257
274
default :
258
275
conv = tt .ObjcName ()
259
276
}
@@ -279,11 +296,7 @@ func (f *Function) WriteCSignature(currentModule *modules.Module, cw *CodeWriter
279
296
var returnTypeStr string
280
297
rt := f .Type .ReturnType
281
298
returnTypeStr = rt .CName ()
282
- if v , ok := map [string ]string {
283
- "NSInteger" : "int" ,
284
- "NSUInteger" : "uint" ,
285
- "BOOL" : "bool" ,
286
- }[returnTypeStr ]; ok {
299
+ if v , ok := objCtoCMap [returnTypeStr ]; ok {
287
300
returnTypeStr = v
288
301
}
289
302
if hasBlockParam (f .Parameters ) {
0 commit comments