Rename some TypeExprFoo variables.

This commit is contained in:
Nigel Tao committed 2017-06-03 12:28:19 +10:00
1 parent 1758637f89
commit 40229f0158
3 files changed
+22 -22

No files matched your search

+1 -1
View File
@@ -36,7 +36,7 @@ var (
func init() { func init() {
zeroExpr.SetConstValue(zero) zeroExpr.SetConstValue(zero)
zeroExpr.SetMType(TypeExprIdealNumber) zeroExpr.SetMType(TypeExprIdeal)
} }
func btoi(b bool) *big.Int { func btoi(b bool) *big.Int {
+5 -5
View File
@@ -50,12 +50,12 @@ func (e *Error) Error() string {
// TypeExprFoo is an *ast.Node MType (implicit type). // TypeExprFoo is an *ast.Node MType (implicit type).
var ( var (
TypeExprBoolean = a.NewTypeExpr(0, t.IDBool, nil, nil, nil) TypeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
TypeExprIdealNumber = a.NewTypeExpr(0, t.IDIdeal, nil, nil, nil) TypeExprIdeal = a.NewTypeExpr(0, t.IDIdeal, nil, nil, nil)
TypeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil) TypeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
) )
func numeric(n *a.TypeExpr) bool { return n == TypeExprIdealNumber || n.IsNumType() } func numeric(n *a.TypeExpr) bool { return n == TypeExprIdeal || n.IsNumType() }
// TypeMap maps from variable names (as token IDs) to types. // TypeMap maps from variable names (as token IDs) to types.
type TypeMap map[t.ID]*a.TypeExpr type TypeMap map[t.ID]*a.TypeExpr
@@ -364,7 +364,7 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
if typ := o.MType(); typ == nil { if typ := o.MType(); typ == nil {
return fmt.Errorf("check: internal error: expression %q has no (implicit) type", return fmt.Errorf("check: internal error: expression %q has no (implicit) type",
o.String(q.idMap)) o.String(q.idMap))
} else if typ == TypeExprIdealNumber && o.ConstValue() == nil { } else if typ == TypeExprIdeal && o.ConstValue() == nil {
return fmt.Errorf("check: internal error: expression %q has ideal number type "+ return fmt.Errorf("check: internal error: expression %q has ideal number type "+
"but no const value", o.String(q.idMap)) "but no const value", o.String(q.idMap))
} }
+16 -16
View File
@@ -56,7 +56,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if err := q.tcheckExpr(cond, 0); err != nil { if err := q.tcheckExpr(cond, 0); err != nil {
return err return err
} }
if !cond.MType().Eq(TypeExprBoolean) { if !cond.MType().Eq(TypeExprBool) {
return fmt.Errorf("check: if condition %q, of type %q, does not have a boolean type", return fmt.Errorf("check: if condition %q, of type %q, does not have a boolean type",
cond.String(q.idMap), cond.MType().String(q.idMap)) cond.String(q.idMap), cond.MType().String(q.idMap))
} }
@@ -128,7 +128,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if err := q.tcheckExpr(cond, 0); err != nil { if err := q.tcheckExpr(cond, 0); err != nil {
return err return err
} }
if !cond.MType().Eq(TypeExprBoolean) { if !cond.MType().Eq(TypeExprBool) {
return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type", return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type",
cond.String(q.idMap), cond.MType().String(q.idMap)) cond.String(q.idMap), cond.MType().String(q.idMap))
} }
@@ -161,7 +161,7 @@ func (q *checker) tcheckAssert(n *a.Assert) error {
if err := q.tcheckExpr(cond, 0); err != nil { if err := q.tcheckExpr(cond, 0); err != nil {
return err return err
} }
if !cond.MType().Eq(TypeExprBoolean) { if !cond.MType().Eq(TypeExprBool) {
return fmt.Errorf("check: assert condition %q, of type %q, does not have a boolean type", return fmt.Errorf("check: assert condition %q, of type %q, does not have a boolean type",
cond.String(q.idMap), cond.MType().String(q.idMap)) cond.String(q.idMap), cond.MType().String(q.idMap))
} }
@@ -188,7 +188,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
rTyp := rhs.MType() rTyp := rhs.MType()
if n.Operator().Key() == t.KeyEq { if n.Operator().Key() == t.KeyEq {
if (rTyp == TypeExprIdealNumber && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) { if (rTyp == TypeExprIdeal && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) {
return nil return nil
} }
return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q", return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q",
@@ -209,7 +209,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
n.Operator().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap)) n.Operator().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap))
} }
if rTyp == TypeExprIdealNumber || lTyp.EqIgnoringRefinements(rTyp) { if rTyp == TypeExprIdeal || lTyp.EqIgnoringRefinements(rTyp) {
return nil return nil
} }
return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types", return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types",
@@ -260,7 +260,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return fmt.Errorf("check: invalid numeric literal %q", s) return fmt.Errorf("check: invalid numeric literal %q", s)
} }
n.SetConstValue(z) n.SetConstValue(z)
n.SetMType(TypeExprIdealNumber) n.SetMType(TypeExprIdeal)
return nil return nil
} else if id1.IsIdent() { } else if id1.IsIdent() {
@@ -276,12 +276,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
switch id1.Key() { switch id1.Key() {
case t.KeyFalse: case t.KeyFalse:
n.SetConstValue(zero) n.SetConstValue(zero)
n.SetMType(TypeExprBoolean) n.SetMType(TypeExprBool)
return nil return nil
case t.KeyTrue: case t.KeyTrue:
n.SetConstValue(one) n.SetConstValue(one)
n.SetMType(TypeExprBoolean) n.SetMType(TypeExprBool)
return nil return nil
case t.KeyUnderscore: case t.KeyUnderscore:
@@ -400,14 +400,14 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
return nil return nil
case t.KeyXUnaryNot: case t.KeyXUnaryNot:
if !rTyp.Eq(TypeExprBoolean) { if !rTyp.Eq(TypeExprBool) {
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type", return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type",
n.ID0().AmbiguousForm().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap)) n.ID0().AmbiguousForm().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap))
} }
if cv := rhs.ConstValue(); cv != nil { if cv := rhs.ConstValue(); cv != nil {
n.SetConstValue(btoi(cv.Cmp(zero) == 0)) n.SetConstValue(btoi(cv.Cmp(zero) == 0))
} }
n.SetMType(TypeExprBoolean) n.SetMType(TypeExprBool)
return nil return nil
} }
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprUnaryOp", n.ID0().Key()) return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprUnaryOp", n.ID0().Key())
@@ -451,11 +451,11 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
case t.KeyXBinaryNotEq, t.KeyXBinaryEqEq: case t.KeyXBinaryNotEq, t.KeyXBinaryEqEq:
// No-op. // No-op.
case t.KeyXBinaryAnd, t.KeyXBinaryOr: case t.KeyXBinaryAnd, t.KeyXBinaryOr:
if lTyp != TypeExprBoolean { if lTyp != TypeExprBool {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type", return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type",
op.AmbiguousForm().String(q.idMap), lhs.String(q.idMap), lTyp.String(q.idMap)) op.AmbiguousForm().String(q.idMap), lhs.String(q.idMap), lTyp.String(q.idMap))
} }
if rTyp != TypeExprBoolean { if rTyp != TypeExprBool {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type", return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type",
op.AmbiguousForm().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap)) op.AmbiguousForm().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap))
} }
@@ -463,7 +463,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
switch op.Key() { switch op.Key() {
default: default:
if !lTyp.EqIgnoringRefinements(rTyp) && lTyp != TypeExprIdealNumber && rTyp != TypeExprIdealNumber { if !lTyp.EqIgnoringRefinements(rTyp) && lTyp != TypeExprIdeal && rTyp != TypeExprIdeal {
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have compatible types", return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have compatible types",
op.AmbiguousForm().String(q.idMap), op.AmbiguousForm().String(q.idMap),
lhs.String(q.idMap), rhs.String(q.idMap), lhs.String(q.idMap), rhs.String(q.idMap),
@@ -471,7 +471,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
) )
} }
case t.KeyXBinaryShiftL, t.KeyXBinaryShiftR: case t.KeyXBinaryShiftL, t.KeyXBinaryShiftR:
if (lTyp == TypeExprIdealNumber) && (rTyp != TypeExprIdealNumber) { if (lTyp == TypeExprIdeal) && (rTyp != TypeExprIdeal) {
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+ return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+
"cannot shift an ideal number by a non-ideal number", "cannot shift an ideal number by a non-ideal number",
op.AmbiguousForm().String(q.idMap), op.AmbiguousForm().String(q.idMap),
@@ -488,8 +488,8 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
} }
if comparisonOps[0xFF&op.Key()] { if comparisonOps[0xFF&op.Key()] {
n.SetMType(TypeExprBoolean) n.SetMType(TypeExprBool)
} else if lTyp != TypeExprIdealNumber { } else if lTyp != TypeExprIdeal {
n.SetMType(lTyp) n.SetMType(lTyp)
} else { } else {
n.SetMType(rTyp) n.SetMType(rTyp)