forked from mkrautz/objc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeinfo.go
80 lines (71 loc) · 1.64 KB
/
typeinfo.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
// Copyright (c) 2012 The 'objc' Package Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package objc
import (
"reflect"
)
const (
encId = "@"
encClass = "#"
encSelector = ":"
encChar = "c"
encUChar = "C"
encShort = "s"
encUShort = "S"
encInt = "i"
encUInt = "I"
encLong = "l"
encULong = "L"
encLongLong = "q"
encULongLong = "Q"
encFloat = "f"
encDouble = "d"
encDFLD = "b"
encBool = "B"
encVoid = "v"
encUndef = "?"
encPtr = "^"
encCharPtr = "*"
encAtom = "%"
encArrayBegin = "["
encArrayEnd = "]"
encUnionBegin = "("
encUnionEnd = ")"
encStructBegin = "{"
encStructEnd = "}"
encVector = "!"
encConst = "r"
)
var (
objectInterfaceType = reflect.TypeOf((*Object)(nil)).Elem()
classInterfaceType = reflect.TypeOf((*Class)(nil)).Elem()
selectorInterfaceType = reflect.TypeOf((*Selector)(nil)).Elem()
)
// Returns the function's typeInfo
func funcTypeInfo(fn interface{}) string {
typ := reflect.TypeOf(fn)
kind := typ.Kind()
if kind != reflect.Func {
panic("not a func")
}
typeInfo := ""
numOut := typ.NumOut()
switch numOut {
case 0:
typeInfo += encVoid
case 1:
typeInfo += typeInfoForType(typ.Out(0))
default:
panic("too many output parameters")
}
if typ.NumIn() == 0 {
panic("funcTypeInfo: bad func")
}
typeInfo += typeInfoForType(typ.In(0))
typeInfo += encSelector
for i := 1; i < typ.NumIn(); i++ {
typeInfo += typeInfoForType(typ.In(i))
}
return typeInfo
}