...
1
2
3
4
5 package ssa
6
7 import (
8 "cmd/internal/src"
9 "fmt"
10 )
11
12 type lineRange struct {
13 first, last uint32
14 }
15
16
17
18
19
20 type xposmap struct {
21
22 maps map[int32]*biasedSparseMap
23
24 lastIndex int32
25 lastMap *biasedSparseMap
26 }
27
28
29
30
31 func newXposmap(x map[int]lineRange) *xposmap {
32 maps := make(map[int32]*biasedSparseMap)
33 for i, p := range x {
34 maps[int32(i)] = newBiasedSparseMap(int(p.first), int(p.last))
35 }
36 return &xposmap{maps: maps, lastIndex: -1}
37 }
38
39
40 func (m *xposmap) clear() {
41 for _, l := range m.maps {
42 if l != nil {
43 l.clear()
44 }
45 }
46 m.lastIndex = -1
47 m.lastMap = nil
48 }
49
50
51 func (m *xposmap) mapFor(index int32) *biasedSparseMap {
52 if index == m.lastIndex {
53 return m.lastMap
54 }
55 mf := m.maps[index]
56 m.lastIndex = index
57 m.lastMap = mf
58 return mf
59 }
60
61
62
63 func (m *xposmap) set(p src.XPos, v int32) {
64 s := m.mapFor(p.FileIndex())
65 if s == nil {
66 panic(fmt.Sprintf("xposmap.set(%d), file index not found in map\n", p.FileIndex()))
67 }
68 s.set(p.Line(), v)
69 }
70
71
72 func (m *xposmap) get(p src.XPos) int32 {
73 s := m.mapFor(p.FileIndex())
74 if s == nil {
75 return -1
76 }
77 return s.get(p.Line())
78 }
79
80
81
82
83 func (m *xposmap) add(p src.XPos) {
84 m.set(p, 0)
85 }
86
87
88
89 func (m *xposmap) contains(p src.XPos) bool {
90 s := m.mapFor(p.FileIndex())
91 if s == nil {
92 return false
93 }
94 return s.contains(p.Line())
95 }
96
97
98
99 func (m *xposmap) remove(p src.XPos) {
100 s := m.mapFor(p.FileIndex())
101 if s == nil {
102 return
103 }
104 s.remove(p.Line())
105 }
106
107
108 func (m *xposmap) foreachEntry(f func(j int32, l uint, v int32)) {
109 for j, mm := range m.maps {
110 s := mm.size()
111 for i := 0; i < s; i++ {
112 l, v := mm.getEntry(i)
113 f(j, l, v)
114 }
115 }
116 }
117
View as plain text