forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer_type.go
45 lines (37 loc) · 1.4 KB
/
pointer_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
package typing
import (
"github.com/progrium/macdriver/generate/modules"
"github.com/progrium/macdriver/internal/set"
)
var _ Type = (*PointerType)(nil)
// PointerType is c pointer type
type PointerType struct {
Type Type
}
func (c *PointerType) GoImports() set.Set[string] {
return c.Type.GoImports()
}
func (c *PointerType) GoName(currentModule *modules.Module, receiveFromObjc bool) string {
switch UnwrapAlias(c.Type).(type) {
case *StructType, *PrimitiveType, *KernelType:
return "*" + c.Type.GoName(currentModule, receiveFromObjc)
case *ClassType:
return "*" + c.Type.GoName(currentModule, true)
case *StringType:
return "*" + (&ClassType{Name: "NSString", GName: "String", Module: modules.Get("foundation")}).GoName(currentModule, true)
case *DataType:
return "*" + (&ClassType{Name: "NSData", GName: "Data", Module: modules.Get("foundation")}).GoName(currentModule, true)
case *ArrayType:
return "*" + (&ClassType{Name: "NSArray", GName: "Array", Module: modules.Get("foundation")}).GoName(currentModule, true)
case *DictType:
return "*" + (&ClassType{Name: "NSDictionary", GName: "Dictionary", Module: modules.Get("foundation")}).GoName(currentModule, true)
default:
panic("not supported pointer to: " + c.Type.ObjcName())
}
}
func (c *PointerType) ObjcName() string {
return c.Type.ObjcName() + "*"
}
func (c *PointerType) DeclareModule() *modules.Module {
return c.Type.DeclareModule()
}