Remove token ID/Key distinction, part 11 of N

This commit is contained in:
Nigel Tao committed 2018-04-15 17:57:10 +10:00
1 parent b24a929ec7
commit eeebd58d7b
20 files changed
+1218 -1425

No files matched your search

+16 -16
View File
@@ -263,15 +263,15 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
// No-op.
case KExpr:
switch o.id0.Key() {
switch o.id0 {
default:
return nil
case t.KeyError, t.KeyStatus, t.KeySuspension:
case t.IDError, t.IDStatus, t.IDSuspension:
// No-op.
}
case KTypeExpr:
if o.id0.Key() != 0 {
if o.id0 != 0 {
return nil
}
}
@@ -664,17 +664,17 @@ func (n *TypeExpr) Innermost() *TypeExpr {
}
func (n *TypeExpr) Pointee() *TypeExpr {
for ; n != nil && n.id0.Key() == t.KeyPtr; n = n.Inner() {
for ; n != nil && n.id0 == t.IDPtr; n = n.Inner() {
}
return n
}
func (n *TypeExpr) IsBool() bool {
return n.id0 == 0 && n.id2.Key() == t.KeyBool
return n.id0 == 0 && n.id2 == t.IDBool
}
func (n *TypeExpr) IsIdeal() bool {
return n.id0 == 0 && n.id2.Key() == t.KeyDoubleZ
return n.id0 == 0 && n.id2 == t.IDDoubleZ
}
func (n *TypeExpr) IsNumType() bool {
@@ -682,35 +682,35 @@ func (n *TypeExpr) IsNumType() bool {
}
func (n *TypeExpr) IsNumTypeOrIdeal() bool {
return n.id0 == 0 && (n.id2.IsNumType() || n.id2.Key() == t.KeyDoubleZ)
return n.id0 == 0 && (n.id2.IsNumType() || n.id2 == t.IDDoubleZ)
}
func (n *TypeExpr) IsRefined() bool {
return n.id0.Key() != t.KeyArray && (n.lhs != nil || n.mhs != nil)
return n.id0 != t.IDArray && (n.lhs != nil || n.mhs != nil)
}
func (n *TypeExpr) IsArrayType() bool {
return n.id0.Key() == t.KeyArray
return n.id0 == t.IDArray
}
func (n *TypeExpr) IsSliceType() bool {
return n.id0.Key() == t.KeySlice
return n.id0 == t.IDSlice
}
func (n *TypeExpr) IsUnsignedInteger() bool {
return n.id0 == 0 && (n.id2.Key() == t.KeyU8 || n.id2.Key() == t.KeyU16 ||
n.id2.Key() == t.KeyU32 || n.id2.Key() == t.KeyU64)
return n.id0 == 0 &&
(n.id2 == t.IDU8 || n.id2 == t.IDU16 || n.id2 == t.IDU32 || n.id2 == t.IDU64)
}
func (n *TypeExpr) HasPointers() bool {
for ; n != nil; n = n.Inner() {
switch n.id0.Key() {
switch n.id0 {
case 0:
switch n.id2.Key() {
case t.KeyIOReader, t.KeyIOWriter:
switch n.id2 {
case t.IDIOReader, t.IDIOWriter:
return true
}
case t.KeyPtr, t.KeyNptr, t.KeySlice:
case t.IDPtr, t.IDNptr, t.IDSlice:
return true
}
}
+2 -2
View File
@@ -46,7 +46,7 @@ func (n *Expr) Eq(o *Expr) bool {
return false
}
if n.id0.Key() == t.KeyXBinaryAs {
if n.id0 == t.IDXBinaryAs {
if !n.rhs.TypeExpr().Eq(o.rhs.TypeExpr()) {
return false
}
@@ -72,7 +72,7 @@ func (n *Expr) Mentions(o *Expr) bool {
if n.Eq(o) ||
n.lhs.Expr().Mentions(o) ||
n.mhs.Expr().Mentions(o) ||
(n.id0.Key() != t.KeyXBinaryAs && n.rhs.Expr().Mentions(o)) {
(n.id0 != t.IDXBinaryAs && n.rhs.Expr().Mentions(o)) {
return true
}
for _, x := range n.list0 {
+53 -53
View File
@@ -42,7 +42,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
if n.id0.IsXOp() {
switch {
case n.id0.IsXUnaryOp():
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
buf = append(buf, opStrings[0xFF&n.id0]...)
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
case n.id0.IsXBinaryOp():
@@ -50,8 +50,8 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
buf = append(buf, '(')
}
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
if n.id0.Key() == t.KeyXBinaryAs {
buf = append(buf, opStrings[0xFF&n.id0]...)
if n.id0 == t.IDXBinaryAs {
buf = append(buf, n.rhs.TypeExpr().Str(tm)...)
} else {
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
@@ -64,7 +64,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
if parenthesize {
buf = append(buf, '(')
}
op := opStrings[0xFF&n.id0.Key()]
op := opStrings[0xFF&n.id0]
for i, o := range n.list0 {
if i != 0 {
buf = append(buf, op...)
@@ -77,14 +77,14 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
}
} else {
switch n.id0.Key() {
case t.KeyError, t.KeyStatus, t.KeySuspension:
switch n.id0.Key() {
case t.KeyError:
switch n.id0 {
case t.IDError, t.IDStatus, t.IDSuspension:
switch n.id0 {
case t.IDError:
buf = append(buf, "error "...)
case t.KeyStatus:
case t.IDStatus:
buf = append(buf, "status "...)
case t.KeySuspension:
case t.IDSuspension:
buf = append(buf, "suspension "...)
}
if n.id1 != 0 {
@@ -96,11 +96,11 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
case 0:
buf = append(buf, tm.ByID(n.id2)...)
case t.KeyTry:
case t.IDTry:
buf = append(buf, "try "...)
fallthrough
case t.KeyOpenParen:
case t.IDOpenParen:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
if n.flags&FlagsSuspendible != 0 {
buf = append(buf, '?')
@@ -118,13 +118,13 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
}
buf = append(buf, ')')
case t.KeyOpenBracket:
case t.IDOpenBracket:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyColon:
case t.IDColon:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.mhs.Expr().appendStr(buf, tm, false, depth)
@@ -132,12 +132,12 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyDot:
case t.IDDot:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '.')
buf = append(buf, tm.ByID(n.id2)...)
case t.KeyDollar:
case t.IDDollar:
buf = append(buf, "$("...)
for i, o := range n.list0 {
if i != 0 {
@@ -153,40 +153,40 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
}
var opStrings = [256]string{
t.KeyXUnaryPlus: "+",
t.KeyXUnaryMinus: "-",
t.KeyXUnaryNot: "not ",
t.KeyXUnaryRef: "ref ",
t.KeyXUnaryDeref: "deref ",
t.IDXUnaryPlus: "+",
t.IDXUnaryMinus: "-",
t.IDXUnaryNot: "not ",
t.IDXUnaryRef: "ref ",
t.IDXUnaryDeref: "deref ",
t.KeyXBinaryPlus: " + ",
t.KeyXBinaryMinus: " - ",
t.KeyXBinaryStar: " * ",
t.KeyXBinarySlash: " / ",
t.KeyXBinaryShiftL: " << ",
t.KeyXBinaryShiftR: " >> ",
t.KeyXBinaryAmp: " & ",
t.KeyXBinaryAmpHat: " &^ ",
t.KeyXBinaryPipe: " | ",
t.KeyXBinaryHat: " ^ ",
t.KeyXBinaryNotEq: " != ",
t.KeyXBinaryLessThan: " < ",
t.KeyXBinaryLessEq: " <= ",
t.KeyXBinaryEqEq: " == ",
t.KeyXBinaryGreaterEq: " >= ",
t.KeyXBinaryGreaterThan: " > ",
t.KeyXBinaryAnd: " and ",
t.KeyXBinaryOr: " or ",
t.KeyXBinaryAs: " as ",
t.KeyXBinaryTildePlus: " ~+ ",
t.IDXBinaryPlus: " + ",
t.IDXBinaryMinus: " - ",
t.IDXBinaryStar: " * ",
t.IDXBinarySlash: " / ",
t.IDXBinaryShiftL: " << ",
t.IDXBinaryShiftR: " >> ",
t.IDXBinaryAmp: " & ",
t.IDXBinaryAmpHat: " &^ ",
t.IDXBinaryPipe: " | ",
t.IDXBinaryHat: " ^ ",
t.IDXBinaryNotEq: " != ",
t.IDXBinaryLessThan: " < ",
t.IDXBinaryLessEq: " <= ",
t.IDXBinaryEqEq: " == ",
t.IDXBinaryGreaterEq: " >= ",
t.IDXBinaryGreaterThan: " > ",
t.IDXBinaryAnd: " and ",
t.IDXBinaryOr: " or ",
t.IDXBinaryAs: " as ",
t.IDXBinaryTildePlus: " ~+ ",
t.KeyXAssociativePlus: " + ",
t.KeyXAssociativeStar: " * ",
t.KeyXAssociativeAmp: " & ",
t.KeyXAssociativePipe: " | ",
t.KeyXAssociativeHat: " ^ ",
t.KeyXAssociativeAnd: " and ",
t.KeyXAssociativeOr: " or ",
t.IDXAssociativePlus: " + ",
t.IDXAssociativeStar: " * ",
t.IDXAssociativeAmp: " & ",
t.IDXAssociativePipe: " | ",
t.IDXAssociativeHat: " ^ ",
t.IDXAssociativeAnd: " and ",
t.IDXAssociativeOr: " or ",
}
// Str returns a string form of n.
@@ -209,21 +209,21 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
return append(buf, "!invalid_type!"...)
}
switch n.Decorator().Key() {
switch n.Decorator() {
case 0:
buf = append(buf, n.QID().Str(tm)...)
case t.KeyPtr:
case t.IDPtr:
buf = append(buf, "ptr "...)
return n.Inner().appendStr(buf, tm, depth)
case t.KeyArray:
case t.IDArray:
buf = append(buf, "array["...)
buf = n.ArrayLength().appendStr(buf, tm, false, 0)
buf = append(buf, "] "...)
return n.Inner().appendStr(buf, tm, depth)
case t.KeySlice:
case t.IDSlice:
buf = append(buf, "slice "...)
return n.Inner().appendStr(buf, tm, depth)
case t.KeyOpenParen:
case t.IDOpenParen:
buf = append(buf, "func "...)
buf = n.Receiver().appendStr(buf, tm, depth)
buf = append(buf, '.')