Rename token.IDMap to token.Map.

This commit is contained in:
Nigel Tao committed 2017-06-08 13:10:01 +10:00
1 parent f6cc7950ff
commit 6e7e566232
15 files changed
+230 -230

No files matched your search

+3 -3
View File
@@ -36,7 +36,7 @@ const (
flagsUnused = Flags(0x8000)
)
// Key is the high 16 bits of an ID. It is the map key for an IDMap.
// Key is the high 16 bits of an ID. It is the map key for a Map.
type Key uint32
const (
@@ -51,7 +51,7 @@ const (
type ID uint32
// String returns a string form of x.
func (x ID) String(m *IDMap) string { return m.ByID(x) }
func (x ID) String(m *Map) string { return m.ByID(x) }
func (x ID) AmbiguousForm() ID { return ambiguousForms[0xFF&(x>>KeyShift)] }
func (x ID) UnaryForm() ID { return unaryForms[0xFF&(x>>KeyShift)] }
@@ -83,7 +83,7 @@ func (x ID) IsNumType() bool { return Flags(x)&FlagsNumType != 0 }
type QID [2]ID
// String returns a string form of x.
func (x QID) String(m *IDMap) string {
func (x QID) String(m *Map) string {
if x[0] == 0 {
return m.ByID(x[1])
}
+7 -7
View File
@@ -13,12 +13,12 @@ const (
maxTokenSize = 1023
)
type IDMap struct {
type Map struct {
byName map[string]ID
byKey []string
}
func (m *IDMap) insert(name string) (ID, error) {
func (m *Map) insert(name string) (ID, error) {
if name == "" {
return 0, nil
}
@@ -50,7 +50,7 @@ func (m *IDMap) insert(name string) (ID, error) {
return id, nil
}
func (m *IDMap) ByName(name string) ID {
func (m *Map) ByName(name string) ID {
if id, ok := builtInsByName[name]; ok {
return id
}
@@ -60,10 +60,10 @@ func (m *IDMap) ByName(name string) ID {
return 0
}
func (m *IDMap) ByID(x ID) string { return m.ByKey(Key(x >> KeyShift)) }
func (m *IDMap) ByToken(t Token) string { return m.ByKey(Key(t.ID >> KeyShift)) }
func (m *Map) ByID(x ID) string { return m.ByKey(Key(x >> KeyShift)) }
func (m *Map) ByToken(t Token) string { return m.ByKey(Key(t.ID >> KeyShift)) }
func (m *IDMap) ByKey(k Key) string {
func (m *Map) ByKey(k Key) string {
if k < nBuiltInKeys {
return builtInsByKey[k].name
}
@@ -102,7 +102,7 @@ func hasPrefix(a []byte, s string) bool {
return true
}
func Tokenize(m *IDMap, filename string, src []byte) (tokens []Token, comments []string, retErr error) {
func Tokenize(m *Map, filename string, src []byte) (tokens []Token, comments []string, retErr error) {
line := uint32(1)
loop:
for i := 0; i < len(src); {