Tighten some more ast.TypeExpr methods

This commit is contained in:
Nigel Tao committed 2018-04-16 08:19:54 +10:00
1 parent 6c6a647cab
commit 6656b6e5e9
2 files changed
+21 -13

No files matched your search

+9 -7
View File
@@ -670,11 +670,11 @@ func (n *TypeExpr) Pointee() *TypeExpr {
}
func (n *TypeExpr) IsBool() bool {
return n.id0 == 0 && n.id2 == t.IDBool
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDBool
}
func (n *TypeExpr) IsIdeal() bool {
return n.id0 == 0 && n.id2 == t.IDDoubleZ
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDDoubleZ
}
func (n *TypeExpr) IsNumType() bool {
@@ -682,7 +682,7 @@ func (n *TypeExpr) IsNumType() bool {
}
func (n *TypeExpr) IsNumTypeOrIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && (n.id2.IsNumType() || n.id2 == t.IDDoubleZ)
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumTypeOrIdeal()
}
func (n *TypeExpr) IsRefined() bool {
@@ -698,7 +698,7 @@ func (n *TypeExpr) IsSliceType() bool {
}
func (n *TypeExpr) IsUnsignedInteger() bool {
return n.id0 == 0 &&
return n.id0 == 0 && n.id1 == t.IDBase &&
(n.id2 == t.IDU8 || n.id2 == t.IDU16 || n.id2 == t.IDU32 || n.id2 == t.IDU64)
}
@@ -706,9 +706,11 @@ func (n *TypeExpr) HasPointers() bool {
for ; n != nil; n = n.Inner() {
switch n.id0 {
case 0:
switch n.id2 {
case t.IDIOReader, t.IDIOWriter:
return true
if n.id1 == t.IDBase {
switch n.id2 {
case t.IDIOReader, t.IDIOWriter:
return true
}
}
case t.IDPtr, t.IDNptr, t.IDSlice:
return true
+12 -6
View File
@@ -104,8 +104,9 @@ func (x ID) IsClose() bool { return x < ID(len(isClose)) && isClose[x] }
func (x ID) IsTightLeft() bool { return x < ID(len(isTightLeft)) && isTightLeft[x] }
func (x ID) IsTightRight() bool { return x < ID(len(isTightRight)) && isTightRight[x] }
func (x ID) IsAssign() bool { return minAssign <= x && x <= maxAssign }
func (x ID) IsNumType() bool { return minNumType <= x && x <= maxNumType }
func (x ID) IsAssign() bool { return minAssign <= x && x <= maxAssign }
func (x ID) IsNumType() bool { return minNumType <= x && x <= maxNumType }
func (x ID) IsNumTypeOrIdeal() bool { return minNumTypeOrIdeal <= x && x <= maxNumTypeOrIdeal }
func (x ID) IsImplicitSemicolon(m *Map) bool {
return x.IsLiteral(m) || x.IsIdent(m) ||
@@ -336,10 +337,12 @@ const (
)
const (
minBuiltInIdent = 0x98
minNumType = 0x98
maxNumType = 0x9F
maxBuiltInIdent = 0xFF
minBuiltInIdent = 0x98
minNumTypeOrIdeal = 0x98
minNumType = 0x98
maxNumType = 0x9F
maxNumTypeOrIdeal = 0xA0
maxBuiltInIdent = 0xFF
IDI8 = ID(0x98)
IDI16 = ID(0x99)
@@ -350,7 +353,10 @@ const (
IDU32 = ID(0x9E)
IDU64 = ID(0x9F)
// It is important that IDDoubleZ is right next to the IDI8..IDU64 block.
// See the ID.IsNumTypeOrIdeal method.
IDDoubleZ = ID(0xA0)
IDDiamond = ID(0xA1)
IDUnderscore = ID(0xA2)