forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatch_type.go
50 lines (42 loc) · 1.1 KB
/
dispatch_type.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
package typing
import (
"strings"
"unicode"
"github.com/progrium/macdriver/generate/modules"
"github.com/progrium/macdriver/internal/set"
)
func GetDispatchType(typeName string) (Type, bool) {
if typeName == "dispatch_block_t" {
return &BlockType{
ReturnType: &VoidType{},
}, true
}
for _, name := range []string{
"dispatch_queue_t",
"dispatch_data_t",
} {
if typeName == name {
return &DispatchType{ObjcName_: typeName}, true
}
}
return nil, false
}
type DispatchType struct {
ObjcName_ string // objc type name
}
func (d *DispatchType) GoImports() set.Set[string] {
return set.New("github.com/progrium/macdriver/dispatch")
}
func (d *DispatchType) GoName(currentModule *modules.Module, receiveFromObjc bool) string {
name := strings.TrimPrefix(d.ObjcName_, "dispatch_")
name = strings.TrimSuffix(name, "_t")
r := []rune(name)
r[0] = unicode.ToUpper(r[0])
return FullGoName(*d.DeclareModule(), string(r), *currentModule)
}
func (d *DispatchType) ObjcName() string {
return d.ObjcName_
}
func (d *DispatchType) DeclareModule() *modules.Module {
return modules.Get("dispatch")
}