Skip to content

Commit a0f1afa

Browse files
committed
generate: improve support for protocol type handling
1 parent 9fafbd6 commit a0f1afa

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

generate/codegen/gen_function.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
175175
sb.WriteString(cw.IndentStr + fmt.Sprintf(" (*C.%s)(unsafe.Pointer(&%s))", tt.CName(), p.GoName()))
176176
case *typing.DispatchType:
177177
sb.WriteString(cw.IndentStr + fmt.Sprintf(" (*C.%s)(unsafe.Pointer(&%s))", tt.CName(), p.GoName()))
178+
case *typing.IDType:
179+
sb.WriteString(cw.IndentStr + fmt.Sprintf(" %s.Ptr()", p.GoName()))
178180
default:
179181
sb.WriteString(cw.IndentStr + p.GoName())
180182
}
@@ -196,6 +198,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
196198
cw.WriteLineF("return C.GoString(%s)", resultName)
197199
case *typing.ProtocolType:
198200
cw.WriteLineF("return %s{objc.ObjectFrom(%s)}", returnTypeStr, resultName)
201+
case *typing.AliasType:
202+
cw.WriteLineF("return *(*%s)(unsafe.Pointer(&%s))", returnTypeStr, resultName)
199203
default:
200204
cw.WriteLineF("return %s(%s)", returnTypeStr, resultName)
201205
}
@@ -290,6 +294,7 @@ func (f *Function) WriteCSignature(currentModule *modules.Module, cw *CodeWriter
290294
if cs, ok := rt.(hasCSignature); ok {
291295
returnTypeStr = cs.CSignature()
292296
}
297+
293298
if hasBlockParam(f.Parameters) {
294299
cw.WriteLineF("// // TODO: %v not implemented (missing block param support)", f.Name)
295300
return

generate/function.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ var unhandledStructTypes = map[string]bool{
4545
"CFUUIDBytes": true,
4646
"dispatch_queue_t": true, // for return values, not parameters
4747
"va_list": true,
48+
49+
"MTLIndirectCommandBufferExecutionRange": true,
50+
"MTLPackedFloat3": true,
4851
}
4952

5053
func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
@@ -70,9 +73,8 @@ func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
7073
"CGPDFArrayGetName": true, // "const char * _Nullable *"
7174
"CGPDFDictionaryGetName": true, // "const char *key, const char * _Nullable *"
7275
"CGPDFScannerPopName": true, // "const char * _Nullable *"
73-
}
74-
if sym.Name != "MTLCreateSystemDefaultDevice" {
75-
return nil
76+
77+
"MTLSizeMake": true, // duplicate symbol issue
7678
}
7779
if knownIssues[sym.Name] {
7880
_, err := sym.Parse(db.Platform)
@@ -134,6 +136,12 @@ func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
134136
fmt.Printf("skipping %s because of unhandled struct type %s\n", sym.Name, fntyp.ReturnType.ObjcName())
135137
return nil
136138
}
139+
140+
// we (unfortuantely) don't handle array returns cleanly yet:
141+
if _, ok := fntyp.ReturnType.(*typing.ArrayType); ok {
142+
fmt.Printf("skipping %s because of array return type\n", sym.Name)
143+
return nil
144+
}
137145
// populate return type
138146
if fntyp.ReturnType != nil {
139147
fn.ReturnType = fntyp.ReturnType

generate/typing/id_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (i *IDType) ObjcName() string {
2525
}
2626

2727
func (i *IDType) CName() string {
28-
return "id"
28+
return "void *"
2929
}
3030

3131
func (i *IDType) DeclareModule() *modules.Module {

0 commit comments

Comments
 (0)