Skip to content

Commit c8f5646

Browse files
committed
generate: Further iteration on function support
1 parent c7397a7 commit c8f5646

File tree

6 files changed

+91
-116
lines changed

6 files changed

+91
-116
lines changed

generate/codegen/gen_function.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ var reservedWords = map[string]bool{
3838
"type": true,
3939
}
4040

41+
var typeMap = map[string]string{
42+
"*kernel.Boolean_t": "*int",
43+
"*kernel.UniChar": "*uint16",
44+
"kernel.Boolean_t": "int",
45+
"kernel.Pid_t": "int32",
46+
}
47+
4148
// GoArgs return go function args
4249
func (f *Function) GoArgs(currentModule *modules.Module) string {
4350
log.Println("rendering function", f.Name)
@@ -54,7 +61,11 @@ func (f *Function) GoArgs(currentModule *modules.Module) string {
5461
p.Name = fmt.Sprintf("arg%d", blankArgCounter)
5562
blankArgCounter++
5663
}
57-
args = append(args, fmt.Sprintf("%s %s", p.Name, p.Type.GoName(currentModule, true)))
64+
typ := p.Type.GoName(currentModule, false)
65+
if v, ok := typeMap[typ]; ok {
66+
typ = v
67+
}
68+
args = append(args, fmt.Sprintf("%s %s", p.Name, typ))
5869
}
5970
return strings.Join(args, ", ")
6071
}
@@ -65,7 +76,11 @@ func (f *Function) GoReturn(currentModule *modules.Module) string {
6576
return ""
6677
}
6778
// log.Printf("rendering GoReturn function return: %s %T", f.ReturnType, f.ReturnType)
68-
return f.ReturnType.GoName(currentModule, true)
79+
typ := f.ReturnType.GoName(currentModule, true)
80+
if v, ok := typeMap[typ]; ok {
81+
typ = v
82+
}
83+
return typ
6984
}
7085

7186
// CArgs return go function args

generate/codegen/modulewriter.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ func shouldSkipFunction(f *Function) bool {
147147
return true
148148
}
149149
if _, ok := map[string]bool{
150-
"CGDirectDisplayCopyCurrentMetalDevice": true,
150+
"CGDirectDisplayCopyCurrentMetalDevice": true,
151+
"CGColorSpaceCreateWithPropertyList": true,
152+
"CGDisplayIOServicePort": true,
153+
"CGGetEventTapList": true,
154+
"CGColorConversionInfoCreateFromListWithArguments": true,
151155
}[f.Name]; ok {
152156
return true
153157
}
@@ -234,6 +238,9 @@ func (m *ModuleWriter) WriteFunctionWrappers() {
234238
//TODO: determine appropriate imports
235239
cw.WriteLineF("#import \"%s\"", m.Module.Header)
236240
for _, f := range m.Functions {
241+
if shouldSkipFunction(f) {
242+
continue
243+
}
237244
f.WriteObjcWrapper(&m.Module, cw)
238245
}
239246
}

macos/corefoundation/corefoundation_structs.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@ import (
44
"unsafe"
55
)
66

7-
type RunLoopRef = unsafe.Pointer
8-
type TypeRef = unsafe.Pointer
9-
type StringRef = unsafe.Pointer
10-
type ReadStreamRef = unsafe.Pointer
117
type AllocatorRef = unsafe.Pointer
12-
type RunLoopObserverRef = unsafe.Pointer
13-
type RunLoopTimerRef = unsafe.Pointer
14-
type XMLExternalID = unsafe.Pointer
8+
type ArrayRef = unsafe.Pointer
9+
type DataRef = unsafe.Pointer
10+
type DateRef = unsafe.Pointer
11+
type DictionaryRef = unsafe.Pointer
12+
type FileDescriptorRef = unsafe.Pointer
1513
type MachPortRef = unsafe.Pointer
14+
type MessagePortRef = unsafe.Pointer
1615
type NotificationCenterRef = unsafe.Pointer
17-
type UserNotificationRef = unsafe.Pointer
1816
type NotificationName = unsafe.Pointer
19-
type DictionaryRef = unsafe.Pointer
20-
type MessagePortRef = unsafe.Pointer
21-
type DataRef = unsafe.Pointer
22-
type SocketRef = unsafe.Pointer
23-
type WriteStreamRef = unsafe.Pointer
24-
type FileDescriptorRef = unsafe.Pointer
2517
type PlugInInstanceRef = unsafe.Pointer
18+
type PropertyListRef = unsafe.Pointer
19+
type ReadStreamRef = unsafe.Pointer
20+
type RunLoopObserverRef = unsafe.Pointer
21+
type RunLoopRef = unsafe.Pointer
22+
type RunLoopSourceRef = unsafe.Pointer
23+
type RunLoopTimerRef = unsafe.Pointer
24+
type SocketRef = unsafe.Pointer
25+
type StringRef = unsafe.Pointer
26+
type TypeRef = unsafe.Pointer
27+
type URLRef = unsafe.Pointer
2628
type UUIDRef = unsafe.Pointer
27-
type ArrayRef = unsafe.Pointer
29+
type UserNotificationRef = unsafe.Pointer
30+
type WriteStreamRef = unsafe.Pointer
31+
type XMLExternalID = unsafe.Pointer

macos/coregraphics/coregraphics_structs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type Rect struct {
3131
Size Size
3232
}
3333

34+
type Vector struct {
35+
Dx Float
36+
Dy Float
37+
}
38+
3439
type Size struct {
3540
Width Float
3641
Height Float

0 commit comments

Comments
 (0)