Skip to content

Commit

Permalink
generate: improve support for protocol type handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Jun 22, 2024
1 parent 9fafbd6 commit a0f1afa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions generate/codegen/gen_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
sb.WriteString(cw.IndentStr + fmt.Sprintf(" (*C.%s)(unsafe.Pointer(&%s))", tt.CName(), p.GoName()))
case *typing.DispatchType:
sb.WriteString(cw.IndentStr + fmt.Sprintf(" (*C.%s)(unsafe.Pointer(&%s))", tt.CName(), p.GoName()))
case *typing.IDType:
sb.WriteString(cw.IndentStr + fmt.Sprintf(" %s.Ptr()", p.GoName()))
default:
sb.WriteString(cw.IndentStr + p.GoName())
}
Expand All @@ -196,6 +198,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
cw.WriteLineF("return C.GoString(%s)", resultName)
case *typing.ProtocolType:
cw.WriteLineF("return %s{objc.ObjectFrom(%s)}", returnTypeStr, resultName)
case *typing.AliasType:
cw.WriteLineF("return *(*%s)(unsafe.Pointer(&%s))", returnTypeStr, resultName)
default:
cw.WriteLineF("return %s(%s)", returnTypeStr, resultName)
}
Expand Down Expand Up @@ -290,6 +294,7 @@ func (f *Function) WriteCSignature(currentModule *modules.Module, cw *CodeWriter
if cs, ok := rt.(hasCSignature); ok {
returnTypeStr = cs.CSignature()
}

if hasBlockParam(f.Parameters) {
cw.WriteLineF("// // TODO: %v not implemented (missing block param support)", f.Name)
return
Expand Down
14 changes: 11 additions & 3 deletions generate/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ var unhandledStructTypes = map[string]bool{
"CFUUIDBytes": true,
"dispatch_queue_t": true, // for return values, not parameters
"va_list": true,

"MTLIndirectCommandBufferExecutionRange": true,
"MTLPackedFloat3": true,
}

func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
Expand All @@ -70,9 +73,8 @@ func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
"CGPDFArrayGetName": true, // "const char * _Nullable *"
"CGPDFDictionaryGetName": true, // "const char *key, const char * _Nullable *"
"CGPDFScannerPopName": true, // "const char * _Nullable *"
}
if sym.Name != "MTLCreateSystemDefaultDevice" {
return nil

"MTLSizeMake": true, // duplicate symbol issue
}
if knownIssues[sym.Name] {
_, err := sym.Parse(db.Platform)
Expand Down Expand Up @@ -134,6 +136,12 @@ func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
fmt.Printf("skipping %s because of unhandled struct type %s\n", sym.Name, fntyp.ReturnType.ObjcName())
return nil
}

// we (unfortuantely) don't handle array returns cleanly yet:
if _, ok := fntyp.ReturnType.(*typing.ArrayType); ok {
fmt.Printf("skipping %s because of array return type\n", sym.Name)
return nil
}
// populate return type
if fntyp.ReturnType != nil {
fn.ReturnType = fntyp.ReturnType
Expand Down
2 changes: 1 addition & 1 deletion generate/typing/id_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (i *IDType) ObjcName() string {
}

func (i *IDType) CName() string {
return "id"
return "void *"
}

func (i *IDType) DeclareModule() *modules.Module {
Expand Down

0 comments on commit a0f1afa

Please sign in to comment.