Skip to content

Commit

Permalink
generate: Add some basic improve support for protocol types
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Jun 22, 2024
1 parent 0d9358c commit 9fafbd6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions generate/codegen/gen_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func (f *Function) WriteGoCallCode(currentModule *modules.Module, cw *CodeWriter
cw.WriteLineF("return *(*%s)(unsafe.Pointer(&%s))", tt.GoName(currentModule, true), resultName)
case *typing.CStringType:
cw.WriteLineF("return C.GoString(%s)", resultName)
case *typing.ProtocolType:
cw.WriteLineF("return %s{objc.ObjectFrom(%s)}", returnTypeStr, resultName)
default:
cw.WriteLineF("return %s(%s)", returnTypeStr, resultName)
}
Expand Down
3 changes: 3 additions & 0 deletions generate/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (db *Generator) ToFunction(fw string, sym Symbol) *codegen.Function {
"CGPDFDictionaryGetName": true, // "const char *key, const char * _Nullable *"
"CGPDFScannerPopName": true, // "const char * _Nullable *"
}
if sym.Name != "MTLCreateSystemDefaultDevice" {
return nil
}
if knownIssues[sym.Name] {
_, err := sym.Parse(db.Platform)
log.Printf("skipping function %s %s because of known issue: decl='%s' err='%v'\n", fw, sym.Name, sym.Declaration, err)
Expand Down
6 changes: 5 additions & 1 deletion generate/typing/pointer_type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package typing

import (
"fmt"

"github.com/progrium/darwinkit/generate/modules"
"github.com/progrium/darwinkit/internal/set"
)
Expand Down Expand Up @@ -40,8 +42,10 @@ func (c *PointerType) GoName(currentModule *modules.Module, receiveFromObjc bool
return "*" + c.Type.GoName(currentModule, receiveFromObjc)
case *RefType:
return "*" + c.Type.GoName(currentModule, receiveFromObjc)
case *ProtocolType:
return "*" + c.Type.GoName(currentModule, receiveFromObjc)
default:
panic("not supported pointer to: " + c.Type.ObjcName())
panic(fmt.Sprintf("not supported pointer to: %T %v", c.Type, c.Type.ObjcName()))
}

}
Expand Down
6 changes: 5 additions & 1 deletion generate/typing/protocol_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func (p *ProtocolType) ObjcName() string {
}

func (p *ProtocolType) CName() string {
return "id<" + p.Name + ">"
return "void *"
}

func (p *ProtocolType) CSignature() string {
return "void *"
}

func (p *ProtocolType) GoImports() set.Set[string] {
Expand Down

0 comments on commit 9fafbd6

Please sign in to comment.