lang/ast: add TypeExpr.IsXxx methods

This commit is contained in:
Nigel Tao committed 2023-10-04 17:09:59 +11:00
1 parent 2f5108978d
commit 6f79c182ea
2 files changed
+18

No files matched your search

+12
View File
@@ -917,6 +917,10 @@ func (n *TypeExpr) IsCPUArchType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsBuiltInCPUArch()
}
func (n *TypeExpr) IsEmptyStruct() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDEmptyStruct
}
func (n *TypeExpr) IsEtcUtilityType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsEtcUtility()
}
@@ -953,6 +957,14 @@ func (n *TypeExpr) IsNumTypeOrIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumTypeOrIdeal()
}
func (n *TypeExpr) IsRangeType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsRangeType()
}
func (n *TypeExpr) IsRectType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsRectType()
}
func (n *TypeExpr) IsRefined() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumType() && (n.lhs != nil || n.mhs != nil)
}
+6
View File
@@ -123,6 +123,8 @@ func (x ID) IsClose() bool { return minClose <= x && x <= maxClose }
func (x ID) IsKeyword() bool { return minKeyword <= x && x <= maxKeyword }
func (x ID) IsNumType() bool { return minNumType <= x && x <= maxNumType }
func (x ID) IsNumTypeOrIdeal() bool { return minNumTypeOrIdeal <= x && x <= maxNumTypeOrIdeal }
func (x ID) IsRangeType() bool { return minRangeType <= x && x <= maxRangeType }
func (x ID) IsRectType() bool { return minRectType <= x && x <= maxRectType }
func (x ID) IsOpen() bool { return minOpen <= x && x <= maxOpen }
func (x ID) IsImplicitSemicolon(m *Map) bool {
@@ -431,6 +433,10 @@ const (
minNumType = 0x110
maxNumType = 0x117
maxNumTypeOrIdeal = 0x117
minRangeType = 0x130
maxRangeType = 0x133
minRectType = 0x134
maxRectType = 0x135
maxBuiltInIdent = 0x3FF
// -------- 0x100 block.