1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // ----------------------------------------------------------------------------
10 // A SpotInfo value describes a particular identifier spot in a given file;
11 // It encodes three values: the SpotKind (declaration or use), a line or
12 // snippet index "lori", and whether it's a line or index.
14 // The following encoding is used:
17 // value [lori|kind|isIndex]
21 // SpotKind describes whether an identifier is declared (and what kind of
22 // declaration) or used.
26 PackageClause SpotKind = iota
38 // These must match the SpotKind values above.
52 func (x SpotKind) Name() string { return name[x] }
55 // sanity check: if nKinds is too large, the SpotInfo
56 // accessor functions may need to be updated
58 panic("internal error: nKinds > 8")
62 // makeSpotInfo makes a SpotInfo.
63 func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo {
64 // encode lori: bits [4..32)
65 x := SpotInfo(lori) << 4
66 if int(x>>4) != lori {
67 // lori value doesn't fit - since snippet indices are
68 // most certainly always smaller then 1<<28, this can
69 // only happen for line numbers; give it no line number (= 0)
72 // encode kind: bits [1..4)
73 x |= SpotInfo(kind) << 1
74 // encode isIndex: bit 0
81 func (x SpotInfo) Kind() SpotKind { return SpotKind(x >> 1 & 7) }
82 func (x SpotInfo) Lori() int { return int(x >> 4) }
83 func (x SpotInfo) IsIndex() bool { return x&1 != 0 }