-
Notifications
You must be signed in to change notification settings - Fork 3
/
ident.go
63 lines (54 loc) · 1009 Bytes
/
ident.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
package humanize
import "go/ast"
// IdentType is the normal type name
type IdentType struct {
pkg *Package
Ident string
}
func (i *IdentType) String() string {
return i.Ident
}
// Package get the package of ident
func (i *IdentType) Package() *Package {
return i.pkg
}
// Equal check if two ident are equal
func (i *IdentType) Equal(t Type) bool {
v, ok := t.(*IdentType)
if !ok {
return false
}
if !i.pkg.Equal(v.pkg) {
return false
}
return i.Ident == v.Ident
}
func (i *IdentType) lateBind() error {
if i.pkg == nil {
i.pkg = getBuiltin()
}
return nil
}
func getIdent(p *Package, _ *File, t *ast.Ident) Type {
// ident is the simplest one (I was wrong :)) ).
ident := nameFromIdent(t)
if isBuiltinIdent(ident) {
p = nil
}
return &IdentType{
pkg: p,
Ident: nameFromIdent(t),
}
}
func getBasicIdent(t string) Type {
return &IdentType{
Ident: t,
pkg: nil,
}
}
func nameFromIdent(i *ast.Ident) (name string) {
if i != nil {
name = i.String()
}
return
}