forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitive_type.go
100 lines (81 loc) · 2.67 KB
/
primitive_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
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
package typing
import (
"github.com/progrium/macdriver/generate/modules"
"github.com/progrium/macdriver/internal/set"
)
var Bool = &PrimitiveType{GoName_: "bool", ObjcName_: "BOOL"}
var Int = &PrimitiveType{GoName_: "int", ObjcName_: "NSInteger"}
var UInt = &PrimitiveType{GoName_: "uint", ObjcName_: "NSUInteger"}
var Float = &PrimitiveType{GoName_: "float64", ObjcName_: "float"}
var Double = &PrimitiveType{GoName_: "float64", ObjcName_: "double"}
var Int8 = &PrimitiveType{GoName_: "int8", ObjcName_: "int8_t"}
var UInt8 = &PrimitiveType{GoName_: "uint8", ObjcName_: "uint8_t"}
var Byte = &PrimitiveType{GoName_: "byte", ObjcName_: "char"}
var Int16 = &PrimitiveType{GoName_: "int16", ObjcName_: "int16_t"}
var UInt16 = &PrimitiveType{GoName_: "uint16", ObjcName_: "uint16_t"}
var Int32 = &PrimitiveType{GoName_: "int32", ObjcName_: "int32_t"}
var UInt32 = &PrimitiveType{GoName_: "uint32", ObjcName_: "uint32_t"}
var Int64 = &PrimitiveType{GoName_: "int64", ObjcName_: "int64_t"}
var UInt64 = &PrimitiveType{GoName_: "uint64", ObjcName_: "uint64_t"}
var primitiveMap map[string]*PrimitiveType
func init() {
primitiveMap = map[string]*PrimitiveType{}
for _, pt := range []*PrimitiveType{Bool, Int, UInt, Float, Double, Int8, UInt8, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64} {
primitiveMap[pt.ObjcName_] = pt
}
primitiveMap["char"] = UInt8
primitiveMap["bool"] = Bool
primitiveMap["int"] = Int
primitiveMap["short"] = Int
primitiveMap["long"] = Int32
primitiveMap["long long"] = Int64
primitiveMap["size_t"] = UInt
primitiveMap["uintptr_t"] = UInt
primitiveMap["Boolean"] = Bool
primitiveMap["SInt8"] = Int8
primitiveMap["SInt16"] = Int16
primitiveMap["SInt32"] = Int32
primitiveMap["SInt64"] = Int64
primitiveMap["UInt8"] = UInt8
primitiveMap["UInt16"] = UInt16
primitiveMap["UInt32"] = UInt32
primitiveMap["UInt64"] = UInt64
primitiveMap["Float32"] = Float
}
func GetPrimitiveType(typeName string) (*PrimitiveType, bool) {
pt, ok := primitiveMap[typeName]
return pt, ok
}
// PrimitiveType primitive types
type PrimitiveType struct {
GoName_ string // go type name
ObjcName_ string // objc type name
}
func (p *PrimitiveType) GoImports() set.Set[string] {
return nil
}
func (p *PrimitiveType) GoName(currentModule *modules.Module, receiveFromObjc bool) string {
return p.GoName_
}
func (p *PrimitiveType) ObjcName() string {
return p.ObjcName_
}
func (p *PrimitiveType) DeclareModule() *modules.Module {
return nil
}
func (p *PrimitiveType) ToUnsigned() *PrimitiveType {
switch p.GoName_ {
case "int":
return UInt
case "int8":
return UInt8
case "int16":
return UInt16
case "int32":
return UInt32
case "int64":
return UInt64
default:
return p
}
}