forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
114 lines (94 loc) · 2.21 KB
/
model.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package gen
import (
"embed"
"io"
"text/template"
)
//go:embed "template/*.tmpl"
var templateFS embed.FS
var templates = template.Must(template.ParseFS(templateFS, "template/*.tmpl"))
type Import struct {
Path string
Alias string
}
type Primitive struct {
ctype string
toCGoFmt string
}
var (
PrimitiveULong = Primitive{"unsigned long", "C.ulong(%s)"}
PrimitiveLong = Primitive{"long", "C.long(%s)"}
PrimitiveUShort = Primitive{"unsigned short", "C.ushort(%s)"}
PrimitiveDouble = Primitive{"double", "C.double(%s)"}
)
// PackageContents describes the Objective-C wrapper types found in a Go wrapper
// package. It's used to locate where to import a type name in the Go code, as
// well as whether it's a class, or another C type.
type PackageContents struct {
// Import can be `nil` if this is representing the contents of the package
// currently being generated, which don't need to be "imported".
Import *Import
Classes map[string]bool
Primitives map[string]Primitive
// TODO structs
}
type Arg struct {
Name string
Type string
}
type SelectorPart struct {
Key string
Arg *Arg
}
type CGoMsgSend struct {
Name string
Class string
Selector []SelectorPart
Return string
}
func (m CGoMsgSend) HasReturn() bool {
return m.Return != "void"
}
type CGoWrapperArg struct {
Name string
Type string
ToCGoFmt string
}
type CGoWrapperReturn struct {
Type string
FromCGoFmt string
}
type CGoWrapperFunc struct {
Name string
Args []CGoWrapperArg
Returns []CGoWrapperReturn
}
func (f CGoWrapperFunc) HasReturn() bool {
return len(f.Returns) > 0
}
type MethodDef struct {
Name string
WrappedFunc CGoWrapperFunc
}
type ClassDef struct {
Name string
Base string
ClassMethods []MethodDef
InstanceMethods []MethodDef
}
type PackageDescription struct {
Name string
LinkFrameworks []string
CIncludes []string
}
type GoPackage struct {
PackageDescription
Imports []Import
ClassMsgSendWrappers []CGoMsgSend
MsgSendWrappers []CGoMsgSend
CGoWrapperFuncs []MethodDef
Classes []ClassDef
}
func (p *GoPackage) Generate(w io.Writer) error {
return templates.ExecuteTemplate(w, "main", p)
}