...
1
2
3
4
5
6
7
8
9
10 package stdlib
11
12 import (
13 "fmt"
14 "strings"
15 )
16
17 type Symbol struct {
18 Name string
19 Kind Kind
20 Version Version
21 }
22
23
24
25 type Kind int8
26
27 const (
28 Invalid Kind = iota
29 Type
30 Func
31 Var
32 Const
33 Field
34 Method
35 )
36
37 func (kind Kind) String() string {
38 return [...]string{
39 Invalid: "invalid",
40 Type: "type",
41 Func: "func",
42 Var: "var",
43 Const: "const",
44 Field: "field",
45 Method: "method",
46 }[kind]
47 }
48
49
50 type Version int8
51
52
53 func (v Version) String() string { return versions[v] }
54
55 var versions [30]string
56
57 func init() {
58 for i := range versions {
59 versions[i] = fmt.Sprintf("go1.%d", i)
60 }
61 }
62
63
64
65 func HasPackage(path string) bool {
66 _, ok := PackageSymbols[path]
67 return ok
68 }
69
70
71
72
73
74 func (sym *Symbol) SplitField() (typename, name string) {
75 if sym.Kind != Field {
76 panic("not a field")
77 }
78 typename, name, _ = strings.Cut(sym.Name, ".")
79 return
80 }
81
82
83
84
85
86 func (sym *Symbol) SplitMethod() (ptr bool, recv, name string) {
87 if sym.Kind != Method {
88 panic("not a method")
89 }
90 recv, name, _ = strings.Cut(sym.Name, ".")
91 recv = recv[len("(") : len(recv)-len(")")]
92 ptr = recv[0] == '*'
93 if ptr {
94 recv = recv[len("*"):]
95 }
96 return
97 }
98
View as plain text