/
var.go
82 lines (60 loc) · 1.9 KB
/
var.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
package turbine
// func varGroups(vs []*types.Var, fs []*ast.Field) (joined, ordered, original, split []*VarGroup) {
// if len(fs) == 0 {
// for _, v := range vs {
// var g = &VarGroup{Type: newType(v.Type(), nil)}
// joined = append(joined, g)
// ordered = append(ordered, g)
// original = append(original, g)
// split = append(split, g)
// }
// sort.Sort(byType(ordered))
// return
// }
// var varindex int
// var syntaxids = map[string][]*Ident{}
// var syntaxtype = map[string]*Type{}
// for _, f := range fs {
// var v = vs[varindex]
// var t = newType(v.Type(), f.Type)
// var g = &VarGroup{Type: t}
// var s = t.Syntax
// syntaxtype[s] = t
// for _, n := range f.Names {
// var id = newIdent(n.Name)
// g.Idents = append(g.Idents, id)
// split = append(split, &VarGroup{Idents: []*Ident{id}, Type: t})
// varindex++
// }
// original = append(original, g)
// if last := len(joined) - 1; len(joined) == 0 || joined[last].Type.Syntax != s {
// joined = append(joined, g)
// } else {
// joined[last].Idents = append(joined[last].Idents, g.Idents...)
// }
// syntaxids[s] = append(syntaxids[s], g.Idents...)
// syntaxtype[s] = t
// }
// for s, t := range syntaxtype {
// sort.Sort(byName(syntaxids[s]))
// ordered = append(ordered, &VarGroup{Idents: syntaxids[s], Type: t})
// }
// sort.Sort(byType(ordered))
// return
// }
type Var struct {
Name Name
Type *Type
}
type VarGroup struct {
Names []Name
Type *Type
}
type byName []Name
func (b byName) Len() int { return len(b) }
func (b byName) Less(i, j int) bool { return b[i] < b[j] }
func (b byName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
type byType []*VarGroup
func (b byType) Len() int { return len(b) }
func (b byType) Less(i, j int) bool { return b[i].Type.String() < b[j].Type.String() }
func (b byType) Swap(i, j int) { b[i], b[j] = b[j], b[i] }