From c0f5ebec87ade1c1c3c09c591eb3eb231f134b5e Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 20 May 2017 12:41:21 +1000 Subject: [PATCH] Rename some "c *checker" receivers for consistency. --- lang/check/bounds.go | 84 ++++++++++----------- lang/check/type.go | 176 +++++++++++++++++++++---------------------- 2 files changed, 130 insertions(+), 130 deletions(-) diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 7d40c9d1..197588e4 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -48,8 +48,8 @@ func neg(i *big.Int) *big.Int { return big.NewInt(0).Neg(i) } -func (c *checker) bcheckStatement(n *a.Node) error { - c.errFilename, c.errLine = n.Raw().FilenameLine() +func (q *checker) bcheckStatement(n *a.Node) error { + q.errFilename, q.errLine = n.Raw().FilenameLine() switch n.Kind() { case a.KAssert: @@ -57,34 +57,34 @@ func (c *checker) bcheckStatement(n *a.Node) error { condition := o.Condition() err := errFailed if reasonID := o.Reason(); reasonID != 0 { - if reasonFunc := c.reasonMap[reasonID.Key()]; reasonFunc != nil { - err = reasonFunc(c, o) + if reasonFunc := q.reasonMap[reasonID.Key()]; reasonFunc != nil { + err = reasonFunc(q, o) } else { - err = fmt.Errorf("no such reason %s", reasonID.String(c.idMap)) + err = fmt.Errorf("no such reason %s", reasonID.String(q.idMap)) } } else if condition.ID0().IsBinaryOp() && condition.ID0().Key() != t.KeyAs { - if c.proveBinaryOp(condition.ID0().Key(), condition.LHS().Expr(), condition.RHS().Expr()) { + if q.proveBinaryOp(condition.ID0().Key(), condition.LHS().Expr(), condition.RHS().Expr()) { err = nil } } if err != nil { if err == errFailed { - return fmt.Errorf("check: cannot prove %q", condition.String(c.idMap)) + return fmt.Errorf("check: cannot prove %q", condition.String(q.idMap)) } - return fmt.Errorf("check: cannot prove %q: %v", condition.String(c.idMap), err) + return fmt.Errorf("check: cannot prove %q: %v", condition.String(q.idMap), err) } - c.facts.appendFact(condition) + q.facts.appendFact(condition) case a.KAssign: o := n.Assign() - return c.bcheckAssignment(o.LHS(), o.LHS().MType(), o.Operator(), o.RHS()) + return q.bcheckAssignment(o.LHS(), o.LHS().MType(), o.Operator(), o.RHS()) case a.KVar: o := n.Var() - return c.bcheckAssignment(nil, o.XType(), t.IDEq, o.Value()) + return q.bcheckAssignment(nil, o.XType(), t.IDEq, o.Value()) case a.KWhile: - return c.bcheckWhile(n.While()) + return q.bcheckWhile(n.While()) case a.KIf: // TODO. @@ -102,15 +102,15 @@ func (c *checker) bcheckStatement(n *a.Node) error { return nil } -func (c *checker) bcheckAssignment(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs *a.Expr) error { - if err := c.bcheckAssignment1(lhs, lTyp, op, rhs); err != nil { +func (q *checker) bcheckAssignment(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs *a.Expr) error { + if err := q.bcheckAssignment1(lhs, lTyp, op, rhs); err != nil { return err } // TODO: drop any facts involving lhs. return nil } -func (c *checker) bcheckAssignment1(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs *a.Expr) error { +func (q *checker) bcheckAssignment1(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs *a.Expr) error { switch lTyp.PackageOrDecorator().Key() { case t.KeyPtr: // TODO: handle. @@ -123,7 +123,7 @@ func (c *checker) bcheckAssignment1(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs return nil } - lMin, lMax, err := c.bcheckTypeExpr(lTyp) + lMin, lMax, err := q.bcheckTypeExpr(lTyp) if err != nil { return err } @@ -141,9 +141,9 @@ func (c *checker) bcheckAssignment1(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs } return nil } - rMin, rMax, err = c.bcheckExpr(rhs, 0) + rMin, rMax, err = q.bcheckExpr(rhs, 0) } else { - rMin, rMax, err = c.bcheckExprBinaryOp(lhs, op.BinaryForm().Key(), rhs, 0) + rMin, rMax, err = q.bcheckExprBinaryOp(lhs, op.BinaryForm().Key(), rhs, 0) } if err != nil { return err @@ -151,18 +151,18 @@ func (c *checker) bcheckAssignment1(lhs *a.Expr, lTyp *a.TypeExpr, op t.ID, rhs if rMin.Cmp(lMin) < 0 || rMax.Cmp(lMax) > 0 { if op == t.IDEq { return fmt.Errorf("check: expression %q bounds [%v..%v] is not within bounds [%v..%v]", - rhs.String(c.idMap), rMin, rMax, lMin, lMax) + rhs.String(q.idMap), rMin, rMax, lMin, lMax) } else { return fmt.Errorf("check: assignment %q bounds [%v..%v] is not within bounds [%v..%v]", - lhs.String(c.idMap)+" "+op.String(c.idMap)+" "+rhs.String(c.idMap), + lhs.String(q.idMap)+" "+op.String(q.idMap)+" "+rhs.String(q.idMap), rMin, rMax, lMin, lMax) } } return nil } -func (c *checker) bcheckWhile(n *a.While) error { - if _, _, err := c.bcheckExpr(n.Condition(), 0); err != nil { +func (q *checker) bcheckWhile(n *a.While) error { + if _, _, err := q.bcheckExpr(n.Condition(), 0); err != nil { return err } @@ -176,16 +176,16 @@ func (c *checker) bcheckWhile(n *a.While) error { // Assume the pre and assert conditions, and the while condition. Check // the body. - c.facts = c.facts[:0] + q.facts = q.facts[:0] for _, m := range n.Asserts() { if m.Assert().Keyword().Key() == t.KeyPost { continue } - c.facts.appendFact(m.Assert().Condition()) + q.facts.appendFact(m.Assert().Condition()) } - c.facts.appendFact(n.Condition()) + q.facts.appendFact(n.Condition()) for _, m := range n.Body() { - if err := c.bcheckStatement(m); err != nil { + if err := q.bcheckStatement(m); err != nil { return err } } @@ -193,17 +193,17 @@ func (c *checker) bcheckWhile(n *a.While) error { // TODO: check the assert and post conditions on exit. // Assume the assert and post conditions. - c.facts = c.facts[:0] + q.facts = q.facts[:0] for _, m := range n.Asserts() { if m.Assert().Keyword().Key() == t.KeyPre { continue } - c.facts.appendFact(m.Assert().Condition()) + q.facts.appendFact(m.Assert().Condition()) } return nil } -func (c *checker) bcheckExpr(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { +func (q *checker) bcheckExpr(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { if depth > a.MaxExprDepth { return nil, nil, fmt.Errorf("check: expression recursion depth too large") } @@ -214,28 +214,28 @@ func (c *checker) bcheckExpr(n *a.Expr, depth uint32) (*big.Int, *big.Int, error switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) { case 0: - nMin, nMax, err := c.bcheckTypeExpr(n.MType()) + nMin, nMax, err := q.bcheckTypeExpr(n.MType()) if err != nil { return nil, nil, err } - nMin, nMax = c.facts.refine(n, nMin, nMax) + nMin, nMax = q.facts.refine(n, nMin, nMax) return nMin, nMax, nil case t.FlagsUnaryOp: - return c.bcheckExprUnaryOp(n, depth) + return q.bcheckExprUnaryOp(n, depth) case t.FlagsBinaryOp: if n.ID0().Key() == t.KeyXBinaryAs { // TODO. return zero, zero, nil } - return c.bcheckExprBinaryOp(n.LHS().Expr(), n.ID0().Key(), n.RHS().Expr(), depth) + return q.bcheckExprBinaryOp(n.LHS().Expr(), n.ID0().Key(), n.RHS().Expr(), depth) case t.FlagsAssociativeOp: - return c.bcheckExprAssociativeOp(n, depth) + return q.bcheckExprAssociativeOp(n, depth) } return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExpr", n.ID0().Key()) } -func (c *checker) bcheckExprUnaryOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { - rMin, rMax, err := c.bcheckExpr(n.RHS().Expr(), depth) +func (q *checker) bcheckExprUnaryOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { + rMin, rMax, err := q.bcheckExpr(n.RHS().Expr(), depth) if err != nil { return nil, nil, err } @@ -252,12 +252,12 @@ func (c *checker) bcheckExprUnaryOp(n *a.Expr, depth uint32) (*big.Int, *big.Int return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprUnaryOp", n.ID0().Key()) } -func (c *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth uint32) (*big.Int, *big.Int, error) { - lMin, lMax, err := c.bcheckExpr(lhs, depth) +func (q *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth uint32) (*big.Int, *big.Int, error) { + lMin, lMax, err := q.bcheckExpr(lhs, depth) if err != nil { return nil, nil, err } - rMin, rMax, err := c.bcheckExpr(rhs, depth) + rMin, rMax, err := q.bcheckExpr(rhs, depth) if err != nil { return nil, nil, err } @@ -292,17 +292,17 @@ func (c *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth u return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprBinaryOp", op) } -func (c *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { +func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.ID0().Key()) } -func (c *checker) bcheckTypeExpr(n *a.TypeExpr) (*big.Int, *big.Int, error) { +func (q *checker) bcheckTypeExpr(n *a.TypeExpr) (*big.Int, *big.Int, error) { b := [2]*big.Int{} if key := n.Name().Key(); key < t.Key(len(numTypeBounds)) { b = numTypeBounds[key] } if b[0] == nil || b[1] == nil { - return nil, nil, fmt.Errorf("check: internal error: unknown bounds for %q", n.String(c.idMap)) + return nil, nil, fmt.Errorf("check: internal error: unknown bounds for %q", n.String(q.idMap)) } if n.IsRefined() { if x := n.InclMin(); x != nil { diff --git a/lang/check/type.go b/lang/check/type.go index 560524fb..7930beca 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -11,24 +11,24 @@ import ( t "github.com/google/puffs/lang/token" ) -func (c *checker) tcheckVars(n *a.Node) error { - c.errFilename, c.errLine = n.Raw().FilenameLine() +func (q *checker) tcheckVars(n *a.Node) error { + q.errFilename, q.errLine = n.Raw().FilenameLine() if n.Kind() == a.KVar { v := n.Var() name := v.Name() - if _, ok := c.f.LocalVars[name]; ok { - return fmt.Errorf("check: duplicate var %q", c.idMap.ByID(name)) + if _, ok := q.f.LocalVars[name]; ok { + return fmt.Errorf("check: duplicate var %q", q.idMap.ByID(name)) } - if err := c.tcheckTypeExpr(v.XType(), 0); err != nil { + if err := q.tcheckTypeExpr(v.XType(), 0); err != nil { return err } - c.f.LocalVars[name] = v.XType() + q.f.LocalVars[name] = v.XType() return nil } for _, l := range n.Raw().SubLists() { for _, m := range l { - if err := c.tcheckVars(m); err != nil { + if err := q.tcheckVars(m); err != nil { return err } } @@ -36,27 +36,27 @@ func (c *checker) tcheckVars(n *a.Node) error { return nil } -func (c *checker) tcheckStatement(n *a.Node) error { - c.errFilename, c.errLine = n.Raw().FilenameLine() +func (q *checker) tcheckStatement(n *a.Node) error { + q.errFilename, q.errLine = n.Raw().FilenameLine() switch n.Kind() { case a.KAssert: - if err := c.tcheckAssert(n.Assert()); err != nil { + if err := q.tcheckAssert(n.Assert()); err != nil { return err } case a.KAssign: - if err := c.tcheckAssign(n.Assign()); err != nil { + if err := q.tcheckAssign(n.Assign()); err != nil { return err } case a.KVar: o := n.Var() if !o.XType().Node().TypeChecked() { - return fmt.Errorf("check: internal error: unchecked type expression %q", o.XType().String(c.idMap)) + return fmt.Errorf("check: internal error: unchecked type expression %q", o.XType().String(q.idMap)) } if value := o.Value(); value != nil { - if err := c.tcheckExpr(value, 0); err != nil { + if err := q.tcheckExpr(value, 0); err != nil { return err } // TODO: check that value.Type is assignable to o.TypeExpr(). @@ -65,21 +65,21 @@ func (c *checker) tcheckStatement(n *a.Node) error { case a.KWhile: o := n.While() cond := o.Condition() - if err := c.tcheckExpr(cond, 0); err != nil { + if err := q.tcheckExpr(cond, 0); err != nil { return err } if !cond.MType().Eq(TypeExprBoolean) { return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type", - cond.String(c.idMap), cond.MType().String(c.idMap)) + cond.String(q.idMap), cond.MType().String(q.idMap)) } for _, m := range o.Asserts() { - if err := c.tcheckAssert(m.Assert()); err != nil { + if err := q.tcheckAssert(m.Assert()); err != nil { return err } m.SetTypeChecked() } for _, m := range o.Body() { - if err := c.tcheckStatement(m); err != nil { + if err := q.tcheckStatement(m); err != nil { return err } } @@ -87,20 +87,20 @@ func (c *checker) tcheckStatement(n *a.Node) error { case a.KIf: for o := n.If(); o != nil; o = o.ElseIf() { cond := o.Condition() - if err := c.tcheckExpr(cond, 0); err != nil { + if err := q.tcheckExpr(cond, 0); err != nil { return err } if !cond.MType().Eq(TypeExprBoolean) { return fmt.Errorf("check: if condition %q, of type %q, does not have a boolean type", - cond.String(c.idMap), cond.MType().String(c.idMap)) + cond.String(q.idMap), cond.MType().String(q.idMap)) } for _, m := range o.BodyIfTrue() { - if err := c.tcheckStatement(m); err != nil { + if err := q.tcheckStatement(m); err != nil { return err } } for _, m := range o.BodyIfFalse() { - if err := c.tcheckStatement(m); err != nil { + if err := q.tcheckStatement(m); err != nil { return err } } @@ -109,7 +109,7 @@ func (c *checker) tcheckStatement(n *a.Node) error { case a.KReturn: o := n.Return() if value := o.Value(); value != nil { - if err := c.tcheckExpr(value, 0); err != nil { + if err := q.tcheckExpr(value, 0); err != nil { return err } // TODO: type-check that value is assignable to the return value. @@ -127,17 +127,17 @@ func (c *checker) tcheckStatement(n *a.Node) error { return nil } -func (c *checker) tcheckAssert(n *a.Assert) error { +func (q *checker) tcheckAssert(n *a.Assert) error { cond := n.Condition() - if err := c.tcheckExpr(cond, 0); err != nil { + if err := q.tcheckExpr(cond, 0); err != nil { return err } if !cond.MType().Eq(TypeExprBoolean) { return fmt.Errorf("check: assert condition %q, of type %q, does not have a boolean type", - cond.String(c.idMap), cond.MType().String(c.idMap)) + cond.String(q.idMap), cond.MType().String(q.idMap)) } for _, a := range n.Args() { - if err := c.tcheckExpr(a.Arg().Value(), 0); err != nil { + if err := q.tcheckExpr(a.Arg().Value(), 0); err != nil { return err } a.SetTypeChecked() @@ -146,13 +146,13 @@ func (c *checker) tcheckAssert(n *a.Assert) error { return nil } -func (c *checker) tcheckAssign(n *a.Assign) error { +func (q *checker) tcheckAssign(n *a.Assign) error { lhs := n.LHS() rhs := n.RHS() - if err := c.tcheckExpr(lhs, 0); err != nil { + if err := q.tcheckExpr(lhs, 0); err != nil { return err } - if err := c.tcheckExpr(rhs, 0); err != nil { + if err := q.tcheckExpr(rhs, 0); err != nil { return err } lTyp := lhs.MType() @@ -163,12 +163,12 @@ func (c *checker) tcheckAssign(n *a.Assign) error { return nil } return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q", - rhs.String(c.idMap), rTyp.String(c.idMap), lhs.String(c.idMap), lTyp.String(c.idMap)) + rhs.String(q.idMap), rTyp.String(q.idMap), lhs.String(q.idMap), lTyp.String(q.idMap)) } if !lTyp.IsNumType() { return fmt.Errorf("check: assignment %q: assignee %q, of type %q, does not have numeric type", - c.idMap.ByID(n.Operator()), lhs.String(c.idMap), lTyp.String(c.idMap)) + q.idMap.ByID(n.Operator()), lhs.String(q.idMap), lTyp.String(q.idMap)) } switch n.Operator().Key() { @@ -177,20 +177,20 @@ func (c *checker) tcheckAssign(n *a.Assign) error { return nil } return fmt.Errorf("check: assignment %q: shift %q, of type %q, does not have numeric type", - c.idMap.ByID(n.Operator()), rhs.String(c.idMap), rTyp.String(c.idMap)) + q.idMap.ByID(n.Operator()), rhs.String(q.idMap), rTyp.String(q.idMap)) } if rTyp == TypeExprIdealNumber || lTyp.EqIgnoringRefinements(rTyp) { return nil } return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types", - c.idMap.ByID(n.Operator()), - lhs.String(c.idMap), rhs.String(c.idMap), - lTyp.String(c.idMap), rTyp.String(c.idMap), + q.idMap.ByID(n.Operator()), + lhs.String(q.idMap), rhs.String(q.idMap), + lTyp.String(q.idMap), rTyp.String(q.idMap), ) } -func (c *checker) tcheckExpr(n *a.Expr, depth uint32) error { +func (q *checker) tcheckExpr(n *a.Expr, depth uint32) error { if depth > a.MaxExprDepth { return fmt.Errorf("check: expression recursion depth too large") } @@ -198,19 +198,19 @@ func (c *checker) tcheckExpr(n *a.Expr, depth uint32) error { switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) { case 0: - if err := c.tcheckExprOther(n, depth); err != nil { + if err := q.tcheckExprOther(n, depth); err != nil { return err } case t.FlagsUnaryOp: - if err := c.tcheckExprUnaryOp(n, depth); err != nil { + if err := q.tcheckExprUnaryOp(n, depth); err != nil { return err } case t.FlagsBinaryOp: - if err := c.tcheckExprBinaryOp(n, depth); err != nil { + if err := q.tcheckExprBinaryOp(n, depth); err != nil { return err } case t.FlagsAssociativeOp: - if err := c.tcheckExprAssociativeOp(n, depth); err != nil { + if err := q.tcheckExprAssociativeOp(n, depth); err != nil { return err } default: @@ -220,13 +220,13 @@ func (c *checker) tcheckExpr(n *a.Expr, depth uint32) error { return nil } -func (c *checker) tcheckExprOther(n *a.Expr, depth uint32) error { +func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { switch n.ID0().Key() { case 0: id1 := n.ID1() if id1.IsNumLiteral() { z := big.NewInt(0) - s := c.idMap.ByID(id1) + s := q.idMap.ByID(id1) if _, ok := z.SetString(s, 0); !ok { return fmt.Errorf("check: invalid numeric literal %q", s) } @@ -235,14 +235,14 @@ func (c *checker) tcheckExprOther(n *a.Expr, depth uint32) error { return nil } else if id1.IsIdent() { - if c.f.LocalVars != nil { - if typ, ok := c.f.LocalVars[id1]; ok { + if q.f.LocalVars != nil { + if typ, ok := q.f.LocalVars[id1]; ok { n.SetMType(typ) return nil } } // TODO: look for (global) names (constants, funcs, structs). - return fmt.Errorf("check: unrecognized identifier %q", c.idMap.ByID(id1)) + return fmt.Errorf("check: unrecognized identifier %q", q.idMap.ByID(id1)) } switch id1.Key() { case t.KeyFalse: @@ -275,14 +275,14 @@ func (c *checker) tcheckExprOther(n *a.Expr, depth uint32) error { // TODO. case t.KeyDot: - return c.tcheckDot(n, depth) + return q.tcheckDot(n, depth) } return fmt.Errorf("check: unrecognized token.Key (0x%X) for checkExprOther", n.ID0().Key()) } -func (c *checker) tcheckDot(n *a.Expr, depth uint32) error { +func (q *checker) tcheckDot(n *a.Expr, depth uint32) error { lhs := n.LHS().Expr() - if err := c.tcheckExpr(lhs, depth); err != nil { + if err := q.tcheckExpr(lhs, depth); err != nil { return err } lTyp := lhs.MType() @@ -295,19 +295,19 @@ func (c *checker) tcheckDot(n *a.Expr, depth uint32) error { } s := (*a.Struct)(nil) - if c.f.Func != nil { + if q.f.Func != nil { switch name := lTyp.Name(); name.Key() { case t.KeyIn: - s = c.f.Func.In() + s = q.f.Func.In() case t.KeyOut: - s = c.f.Func.Out() + s = q.f.Func.Out() default: - s = c.c.structs[name].Struct + s = q.c.structs[name].Struct } } if s == nil { return fmt.Errorf("check: no struct type %q found for expression %q", - lTyp.Name().String(c.idMap), lhs.String(c.idMap)) + lTyp.Name().String(q.idMap), lhs.String(q.idMap)) } for _, field := range s.Fields() { @@ -318,12 +318,12 @@ func (c *checker) tcheckDot(n *a.Expr, depth uint32) error { } } return fmt.Errorf("check: no field named %q found in struct type %q for expression %q", - n.ID1().String(c.idMap), lTyp.Name().String(c.idMap), n.String(c.idMap)) + n.ID1().String(q.idMap), lTyp.Name().String(q.idMap), n.String(q.idMap)) } -func (c *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error { +func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error { rhs := n.RHS().Expr() - if err := c.tcheckExpr(rhs, depth); err != nil { + if err := q.tcheckExpr(rhs, depth); err != nil { return err } rTyp := rhs.MType() @@ -332,7 +332,7 @@ func (c *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error { case t.KeyXUnaryPlus, t.KeyXUnaryMinus: if !numeric(rTyp) { return fmt.Errorf("check: unary %q: %q, of type %q, does not have a numeric type", - c.idMap.ByID(n.ID0().AmbiguousForm()), rhs.String(c.idMap), rTyp.String(c.idMap)) + q.idMap.ByID(n.ID0().AmbiguousForm()), rhs.String(q.idMap), rTyp.String(q.idMap)) } if cv := rhs.ConstValue(); cv != nil { if n.ID0().Key() == t.KeyXUnaryMinus { @@ -346,7 +346,7 @@ func (c *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error { case t.KeyXUnaryNot: if !rTyp.Eq(TypeExprBoolean) { return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type", - c.idMap.ByID(n.ID0().AmbiguousForm()), rhs.String(c.idMap), rTyp.String(c.idMap)) + q.idMap.ByID(n.ID0().AmbiguousForm()), rhs.String(q.idMap), rTyp.String(q.idMap)) } if cv := rhs.ConstValue(); cv != nil { n.SetConstValue(btoi(cv.Cmp(zero) == 0)) @@ -357,16 +357,16 @@ func (c *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error { return fmt.Errorf("check: unrecognized token.Key (0x%X) for checkExprUnaryOp", n.ID0().Key()) } -func (c *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { +func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { lhs := n.LHS().Expr() - if err := c.tcheckExpr(lhs, depth); err != nil { + if err := q.tcheckExpr(lhs, depth); err != nil { return err } lTyp := lhs.MType() op := n.ID0() if op.Key() == t.KeyXBinaryAs { rhs := n.RHS().TypeExpr() - if err := c.tcheckTypeExpr(rhs, 0); err != nil { + if err := q.tcheckTypeExpr(rhs, 0); err != nil { return err } if numeric(lTyp) && rhs.IsNumType() { @@ -374,10 +374,10 @@ func (c *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { return nil } return fmt.Errorf("check: cannot convert expression %q, of type %q, as type %q", - lhs.String(c.idMap), lTyp.String(c.idMap), rhs.String(c.idMap)) + lhs.String(q.idMap), lTyp.String(q.idMap), rhs.String(q.idMap)) } rhs := n.RHS().Expr() - if err := c.tcheckExpr(rhs, depth); err != nil { + if err := q.tcheckExpr(rhs, depth); err != nil { return err } rTyp := rhs.MType() @@ -386,22 +386,22 @@ func (c *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { default: if !numeric(lTyp) { return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type", - c.idMap.ByID(op.AmbiguousForm()), lhs.String(c.idMap), lTyp.String(c.idMap)) + q.idMap.ByID(op.AmbiguousForm()), lhs.String(q.idMap), lTyp.String(q.idMap)) } if !numeric(rTyp) { return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type", - c.idMap.ByID(op.AmbiguousForm()), rhs.String(c.idMap), rTyp.String(c.idMap)) + q.idMap.ByID(op.AmbiguousForm()), rhs.String(q.idMap), rTyp.String(q.idMap)) } case t.KeyXBinaryNotEq, t.KeyXBinaryEqEq: // No-op. case t.KeyXBinaryAnd, t.KeyXBinaryOr: if lTyp != TypeExprBoolean { return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type", - c.idMap.ByID(op.AmbiguousForm()), lhs.String(c.idMap), lTyp.String(c.idMap)) + q.idMap.ByID(op.AmbiguousForm()), lhs.String(q.idMap), lTyp.String(q.idMap)) } if rTyp != TypeExprBoolean { return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type", - c.idMap.ByID(op.AmbiguousForm()), rhs.String(c.idMap), rTyp.String(c.idMap)) + q.idMap.ByID(op.AmbiguousForm()), rhs.String(q.idMap), rTyp.String(q.idMap)) } } @@ -409,24 +409,24 @@ func (c *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { default: if !lTyp.EqIgnoringRefinements(rTyp) && lTyp != TypeExprIdealNumber && rTyp != TypeExprIdealNumber { return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have compatible types", - c.idMap.ByID(op.AmbiguousForm()), - lhs.String(c.idMap), rhs.String(c.idMap), - lTyp.String(c.idMap), rTyp.String(c.idMap), + q.idMap.ByID(op.AmbiguousForm()), + lhs.String(q.idMap), rhs.String(q.idMap), + lTyp.String(q.idMap), rTyp.String(q.idMap), ) } case t.KeyXBinaryShiftL, t.KeyXBinaryShiftR: if (lTyp == TypeExprIdealNumber) && (rTyp != TypeExprIdealNumber) { return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+ "cannot shift an ideal number by a non-ideal number", - c.idMap.ByID(op.AmbiguousForm()), - lhs.String(c.idMap), rhs.String(c.idMap), - lTyp.String(c.idMap), rTyp.String(c.idMap), + q.idMap.ByID(op.AmbiguousForm()), + lhs.String(q.idMap), rhs.String(q.idMap), + lTyp.String(q.idMap), rTyp.String(q.idMap), ) } } if l, r := lhs.ConstValue(), rhs.ConstValue(); l != nil && r != nil { - if err := c.setConstValueBinaryOp(n, l, r); err != nil { + if err := q.setConstValueBinaryOp(n, l, r); err != nil { return err } } @@ -442,7 +442,7 @@ func (c *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { return nil } -func (c *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error { +func (q *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error { switch n.ID0().Key() { case t.KeyXBinaryPlus: n.SetConstValue(big.NewInt(0).Add(l, r)) @@ -452,7 +452,7 @@ func (c *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error n.SetConstValue(big.NewInt(0).Mul(l, r)) case t.KeyXBinarySlash: if r.Cmp(zero) == 0 { - return fmt.Errorf("check: division by zero in const expression %q", n.String(c.idMap)) + return fmt.Errorf("check: division by zero in const expression %q", n.String(q.idMap)) } // TODO: decide on Euclidean division vs other definitions. See "go doc // math/big int.divmod" for details. @@ -460,13 +460,13 @@ func (c *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error case t.KeyXBinaryShiftL: if r.Cmp(zero) < 0 || r.Cmp(ffff) > 0 { return fmt.Errorf("check: shift %q out of range in const expression %q", - n.RHS().Expr().String(c.idMap), n.String(c.idMap)) + n.RHS().Expr().String(q.idMap), n.String(q.idMap)) } n.SetConstValue(big.NewInt(0).Lsh(l, uint(r.Uint64()))) case t.KeyXBinaryShiftR: if r.Cmp(zero) < 0 || r.Cmp(ffff) > 0 { return fmt.Errorf("check: shift %q out of range in const expression %q", - n.RHS().Expr().String(c.idMap), n.String(c.idMap)) + n.RHS().Expr().String(q.idMap), n.String(q.idMap)) } n.SetConstValue(big.NewInt(0).Rsh(l, uint(r.Uint64()))) case t.KeyXBinaryAmp: @@ -497,12 +497,12 @@ func (c *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error return nil } -func (c *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error { +func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error { // TODO. return fmt.Errorf("check: unrecognized token.Key (0x%X) for checkExprAssociativeOp", n.ID0().Key()) } -func (c *checker) tcheckTypeExpr(n *a.TypeExpr, depth uint32) error { +func (q *checker) tcheckTypeExpr(n *a.TypeExpr, depth uint32) error { if depth > a.MaxTypeExprDepth { return fmt.Errorf("check: type expression recursion depth too large") } @@ -515,11 +515,11 @@ func (c *checker) tcheckTypeExpr(n *a.TypeExpr, depth uint32) error { if bound == nil { continue } - if err := c.tcheckExpr(bound, 0); err != nil { + if err := q.tcheckExpr(bound, 0); err != nil { return err } if bound.ConstValue() == nil { - return fmt.Errorf("check: %q is not constant", bound.String(c.idMap)) + return fmt.Errorf("check: %q is not constant", bound.String(q.idMap)) } } break @@ -528,28 +528,28 @@ func (c *checker) tcheckTypeExpr(n *a.TypeExpr, depth uint32) error { // TODO: reject. } // TODO: see if name refers to a struct type. - return fmt.Errorf("check: %q is not a type", c.idMap.ByID(n.Name())) + return fmt.Errorf("check: %q is not a type", q.idMap.ByID(n.Name())) case t.KeyPtr: - if err := c.tcheckTypeExpr(n.Inner(), depth); err != nil { + if err := q.tcheckTypeExpr(n.Inner(), depth); err != nil { return err } case t.KeyOpenBracket: aLen := n.ArrayLength() - if err := c.tcheckExpr(aLen, 0); err != nil { + if err := q.tcheckExpr(aLen, 0); err != nil { return err } if aLen.ConstValue() == nil { - return fmt.Errorf("check: %q is not constant", aLen.String(c.idMap)) + return fmt.Errorf("check: %q is not constant", aLen.String(q.idMap)) } - if err := c.tcheckTypeExpr(n.Inner(), depth); err != nil { + if err := q.tcheckTypeExpr(n.Inner(), depth); err != nil { return err } default: // TODO: delete this hack. - if n.PackageOrDecorator() == c.idMap.ByName("io") && n.Name() == c.idMap.ByName("buf1") { + if n.PackageOrDecorator() == q.idMap.ByName("io") && n.Name() == q.idMap.ByName("buf1") { break }