Rename String(*token.Map) to Str(*token.Map)

This commit is contained in:
Nigel Tao committed 2017-12-01 11:22:08 +11:00
1 parent 638d8eee77
commit 7601fb45ce
15 files changed
+219 -219

No files matched your search

+28 -28
View File
@@ -18,18 +18,18 @@ import (
t "github.com/google/wuffs/lang/token"
)
// String returns a string form of n.
func (n *Expr) String(tm *t.Map) string {
// Str returns a string form of n.
func (n *Expr) Str(tm *t.Map) string {
if n == nil {
return ""
}
if n.id0 == 0 {
return tm.ByID(n.id1)
}
return string(n.appendString(nil, tm, false, 0))
return string(n.appendStr(nil, tm, false, 0))
}
func (n *Expr) appendString(buf []byte, tm *t.Map, parenthesize bool, depth uint32) []byte {
func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32) []byte {
if depth > MaxExprDepth {
return append(buf, "!expr_recursion_depth_too_large!"...)
}
@@ -47,7 +47,7 @@ func (n *Expr) appendString(buf []byte, tm *t.Map, parenthesize bool, depth uint
fallthrough
case t.KeyOpenParen:
buf = n.lhs.Expr().appendString(buf, tm, true, depth)
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
if n.flags&FlagsSuspendible != 0 {
buf = append(buf, '?')
}
@@ -58,26 +58,26 @@ func (n *Expr) appendString(buf []byte, tm *t.Map, parenthesize bool, depth uint
}
buf = append(buf, tm.ByID(o.Arg().Name())...)
buf = append(buf, ':')
buf = o.Arg().Value().appendString(buf, tm, false, depth)
buf = o.Arg().Value().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
case t.KeyOpenBracket:
buf = n.lhs.Expr().appendString(buf, tm, true, depth)
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.rhs.Expr().appendString(buf, tm, false, depth)
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyColon:
buf = n.lhs.Expr().appendString(buf, tm, true, depth)
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.mhs.Expr().appendString(buf, tm, false, depth)
buf = n.mhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ':')
buf = n.rhs.Expr().appendString(buf, tm, false, depth)
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyDot:
buf = n.lhs.Expr().appendString(buf, tm, true, depth)
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '.')
buf = append(buf, tm.ByID(n.id1)...)
@@ -87,25 +87,25 @@ func (n *Expr) appendString(buf []byte, tm *t.Map, parenthesize bool, depth uint
if i != 0 {
buf = append(buf, ", "...)
}
buf = o.Expr().appendString(buf, tm, false, depth)
buf = o.Expr().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
}
case t.FlagsUnaryOp:
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
buf = n.rhs.Expr().appendString(buf, tm, true, depth)
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
case t.FlagsBinaryOp:
if parenthesize {
buf = append(buf, '(')
}
buf = n.lhs.Expr().appendString(buf, tm, true, depth)
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, n.rhs.TypeExpr().String(tm)...)
buf = append(buf, n.rhs.TypeExpr().Str(tm)...)
} else {
buf = n.rhs.Expr().appendString(buf, tm, true, depth)
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
}
if parenthesize {
buf = append(buf, ')')
@@ -120,7 +120,7 @@ func (n *Expr) appendString(buf []byte, tm *t.Map, parenthesize bool, depth uint
if i != 0 {
buf = append(buf, op...)
}
buf = o.Expr().appendString(buf, tm, true, depth)
buf = o.Expr().appendStr(buf, tm, true, depth)
}
if parenthesize {
buf = append(buf, ')')
@@ -168,18 +168,18 @@ var opStrings = [256]string{
t.KeyXAssociativeOr: " or ",
}
// String returns a string form of n.
func (n *TypeExpr) String(tm *t.Map) string {
// Str returns a string form of n.
func (n *TypeExpr) Str(tm *t.Map) string {
if n == nil {
return ""
}
if n.Decorator() == 0 && n.Min() == nil && n.Max() == nil {
return tm.ByID(n.Name())
}
return string(n.appendString(nil, tm, 0))
return string(n.appendStr(nil, tm, 0))
}
func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte {
func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
if depth > MaxTypeExprDepth {
return append(buf, "!type_expr_recursion_depth_too_large!"...)
}
@@ -193,15 +193,15 @@ func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte {
buf = append(buf, tm.ByID(n.Name())...)
case t.KeyPtr:
buf = append(buf, "ptr "...)
return n.Inner().appendString(buf, tm, depth)
return n.Inner().appendStr(buf, tm, depth)
case t.KeyOpenBracket:
buf = append(buf, '[')
buf = n.ArrayLength().appendString(buf, tm, false, 0)
buf = n.ArrayLength().appendStr(buf, tm, false, 0)
buf = append(buf, "] "...)
return n.Inner().appendString(buf, tm, depth)
return n.Inner().appendStr(buf, tm, depth)
case t.KeyColon:
buf = append(buf, "[] "...)
return n.Inner().appendString(buf, tm, depth)
return n.Inner().appendStr(buf, tm, depth)
default:
buf = append(buf, tm.ByID(n.Decorator())...)
buf = append(buf, '.')
@@ -209,9 +209,9 @@ func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte {
}
if n.Min() != nil || n.Max() != nil {
buf = append(buf, '[')
buf = n.Min().appendString(buf, tm, false, 0)
buf = n.Min().appendStr(buf, tm, false, 0)
buf = append(buf, ".."...)
buf = n.Max().appendString(buf, tm, false, 0)
buf = n.Max().appendStr(buf, tm, false, 0)
buf = append(buf, ']')
}
return buf
+1 -1
View File
@@ -82,7 +82,7 @@ func TestString(t *testing.T) {
t.Errorf("ParseExpr(%q): %v", tc, err)
continue
}
got := expr.String(tm)
got := expr.Str(tm)
if got != tc {
t.Errorf("got %q, want %q", got, tc)
continue
+2 -2
View File
@@ -160,7 +160,7 @@ func (z facts) refine(n *a.Expr, nMin *big.Int, nMax *big.Int, tm *t.Map) (*big.
if changed && nMin.Cmp(nMax) > 0 {
return nil, nil, fmt.Errorf("check: expression %q bounds [%v..%v] inconsistent with fact %q",
n.String(tm), originalNMin, originalNMax, x.String(tm))
n.Str(tm), originalNMin, originalNMax, x.Str(tm))
}
}
@@ -351,7 +351,7 @@ func proveReasonRequirement(q *checker, op t.ID, lhs *a.Expr, rhs *a.Expr) error
}
if err := q.proveBinaryOp(op.Key(), lhs, rhs); err != nil {
n := a.NewExpr(a.FlagsTypeChecked, op, 0, lhs.Node(), nil, rhs.Node(), nil)
return fmt.Errorf("cannot prove %q: %v", n.String(q.tm), err)
return fmt.Errorf("cannot prove %q: %v", n.Str(q.tm), err)
}
return nil
}
+30 -30
View File
@@ -110,10 +110,10 @@ func bitMask(nBits int) *big.Int {
func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
if !n.MType().IsBool() {
return nil, fmt.Errorf("check: invert(%q) called on non-bool-typed expression", n.String(tm))
return nil, fmt.Errorf("check: invert(%q) called on non-bool-typed expression", n.Str(tm))
}
if cv := n.ConstValue(); cv != nil {
return nil, fmt.Errorf("check: invert(%q) called on constant expression", n.String(tm))
return nil, fmt.Errorf("check: invert(%q) called on constant expression", n.Str(tm))
}
id0, lhs, rhs, args := n.ID0(), n.LHS().Expr(), n.RHS().Expr(), []*a.Node(nil)
switch id0.Key() {
@@ -179,14 +179,14 @@ func typeBounds(tm *t.Map, typ *a.TypeExpr) (*big.Int, *big.Int, error) {
if o := typ.Min(); o != nil {
cv := o.ConstValue()
if cv.Cmp(b[0]) < 0 {
return nil, nil, fmt.Errorf("check: type refinement %v for %q is out of bounds", cv, typ.String(tm))
return nil, nil, fmt.Errorf("check: type refinement %v for %q is out of bounds", cv, typ.Str(tm))
}
b[0] = cv
}
if o := typ.Max(); o != nil {
cv := o.ConstValue()
if cv.Cmp(b[1]) > 0 {
return nil, nil, fmt.Errorf("check: type refinement %v for %q is out of bounds", cv, typ.String(tm))
return nil, nil, fmt.Errorf("check: type refinement %v for %q is out of bounds", cv, typ.Str(tm))
}
b[1] = cv
}
@@ -202,7 +202,7 @@ func bcheckField(tm *t.Map, n *a.Field) error {
if nMin == nil {
if n.DefaultValue() != nil {
return fmt.Errorf("check: explicit default value %v for field %q of non-numeric innermost type %q",
n.DefaultValue().ConstValue(), n.Name().String(tm), innTyp.String(tm))
n.DefaultValue().ConstValue(), n.Name().Str(tm), innTyp.Str(tm))
}
return nil
}
@@ -212,7 +212,7 @@ func bcheckField(tm *t.Map, n *a.Field) error {
}
if dv.Cmp(nMin) < 0 || dv.Cmp(nMax) > 0 {
return fmt.Errorf("check: default value %v is not within bounds [%v..%v] for field %q",
dv, nMin, nMax, n.Name().String(tm))
dv, nMin, nMax, n.Name().Str(tm))
}
return nil
}
@@ -327,7 +327,7 @@ func (q *checker) bcheckAssert(n *a.Assert) error {
if reasonFunc := q.reasonMap[reasonID.Key()]; reasonFunc != nil {
err = reasonFunc(q, n)
} else {
err = fmt.Errorf("no such reason %s", reasonID.String(q.tm))
err = fmt.Errorf("no such reason %s", reasonID.Str(q.tm))
}
} else if condition.ID0().IsBinaryOp() && condition.ID0().Key() != t.KeyAs {
err = q.proveBinaryOp(condition.ID0().Key(), condition.LHS().Expr(), condition.RHS().Expr())
@@ -335,9 +335,9 @@ func (q *checker) bcheckAssert(n *a.Assert) error {
if err != nil {
if err == errFailed {
return fmt.Errorf("check: cannot prove %q", condition.String(q.tm))
return fmt.Errorf("check: cannot prove %q", condition.Str(q.tm))
}
return fmt.Errorf("check: cannot prove %q: %v", condition.String(q.tm), err)
return fmt.Errorf("check: cannot prove %q: %v", condition.Str(q.tm), err)
}
o, err := simplify(q.tm, condition)
if err != nil {
@@ -455,10 +455,10 @@ func (q *checker) bcheckAssignment1(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
if op == t.IDEq {
return fmt.Errorf("check: expression %q bounds [%v..%v] is not within bounds [%v..%v]",
rhs.String(q.tm), rMin, rMax, lMin, lMax)
rhs.Str(q.tm), rMin, rMax, lMin, lMax)
} else {
return fmt.Errorf("check: assignment %q bounds [%v..%v] is not within bounds [%v..%v]",
lhs.String(q.tm)+" "+op.String(q.tm)+" "+rhs.String(q.tm),
lhs.Str(q.tm)+" "+op.Str(q.tm)+" "+rhs.Str(q.tm),
rMin, rMax, lMin, lMax)
}
}
@@ -518,12 +518,12 @@ func (q *checker) unify(branches [][]*a.Expr) error {
m := map[string]int{}
for _, b := range branches {
for _, f := range b {
m[f.String(q.tm)]++
m[f.Str(q.tm)]++
}
}
return q.facts.update(func(n *a.Expr) (*a.Expr, error) {
if m[n.String(q.tm)] == len(branches) {
if m[n.Str(q.tm)] == len(branches) {
return n, nil
}
return nil, nil
@@ -713,7 +713,7 @@ func (q *checker) bcheckExpr(n *a.Expr, depth uint32) (*big.Int, *big.Int, error
}
if (nMin != nil && tMin != nil && nMin.Cmp(tMin) < 0) || (nMax != nil && tMax != nil && nMax.Cmp(tMax) > 0) {
return nil, nil, fmt.Errorf("check: expression %q bounds [%v..%v] is not within bounds [%v..%v]",
n.String(q.tm), nMin, nMax, tMin, tMax)
n.Str(q.tm), nMin, nMax, tMin, tMax)
}
if err := q.optimizeNonSuspendible(n); err != nil {
return nil, nil, err
@@ -799,7 +799,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
// TODO: sixtyFour should actually be 8 * sizeof(n.LHS().Expr()).
if aMax.Cmp(sixtyFour) > 0 {
return nil, nil, fmt.Errorf("check: low_bits argument %q is possibly too large", a.String(q.tm))
return nil, nil, fmt.Errorf("check: low_bits argument %q is possibly too large", a.Str(q.tm))
}
return zero, bitMask(int(aMax.Int64())), nil
}
@@ -817,7 +817,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
return nil, nil, err
}
if aMin.Cmp(big.NewInt(2)) < 0 || aMax.Cmp(big.NewInt(8)) > 0 {
return nil, nil, fmt.Errorf("check: %q not in range [2..8]", a.String(q.tm))
return nil, nil, fmt.Errorf("check: %q not in range [2..8]", a.Str(q.tm))
}
return nil, nil, nil
}
@@ -918,7 +918,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
lTyp := n.LHS().Expr().MType()
return nil, nil, fmt.Errorf("check: no field named %q found in struct type %q for expression %q",
n.ID1().String(q.tm), lTyp.Name().String(q.tm), n.String(q.tm))
n.ID1().Str(q.tm), lTyp.Name().Str(q.tm), n.Str(q.tm))
}
if _, _, err := q.bcheckExpr(n.LHS().Expr(), depth); err != nil {
@@ -1005,10 +1005,10 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
// TODO: handle multiplication by negative numbers. Note that this
// might reverse the inequality: if 0 < a < b but c < 0 then a*c > b*c.
if lMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: multiply op argument %q is possibly negative", lhs.String(q.tm))
return nil, nil, fmt.Errorf("check: multiply op argument %q is possibly negative", lhs.Str(q.tm))
}
if rMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: multiply op argument %q is possibly negative", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: multiply op argument %q is possibly negative", rhs.Str(q.tm))
}
return big.NewInt(0).Mul(lMin, rMin), big.NewInt(0).Mul(lMax, rMax), nil
@@ -1017,22 +1017,22 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
case t.KeyXBinaryShiftL:
if lMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.String(q.tm))
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.Str(q.tm))
}
if rMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", rhs.Str(q.tm))
}
if rMax.Cmp(ffff) > 0 {
return nil, nil, fmt.Errorf("check: shift %q out of range", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: shift %q out of range", rhs.Str(q.tm))
}
return big.NewInt(0).Lsh(lMin, uint(rMin.Uint64())), big.NewInt(0).Lsh(lMax, uint(rMax.Uint64())), nil
case t.KeyXBinaryShiftR:
if lMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.String(q.tm))
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.Str(q.tm))
}
if rMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", rhs.Str(q.tm))
}
if rMin.Cmp(maxIntBits) >= 0 {
return zero, zero, nil
@@ -1047,16 +1047,16 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
// TODO: should type-checking ensure that bitwise ops only apply to
// *unsigned* integer types?
if lMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly negative", lhs.String(q.tm))
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly negative", lhs.Str(q.tm))
}
if lMax.Cmp(numTypeBounds[t.KeyU64][1]) > 0 {
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly too large", lhs.String(q.tm))
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly too large", lhs.Str(q.tm))
}
if rMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly negative", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly negative", rhs.Str(q.tm))
}
if rMax.Cmp(numTypeBounds[t.KeyU64][1]) > 0 {
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly too large", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: bitwise op argument %q is possibly too large", rhs.Str(q.tm))
}
z := (*big.Int)(nil)
if op == t.KeyXBinaryAmp {
@@ -1076,10 +1076,10 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
case t.KeyXBinaryPercent:
if lMin.Cmp(zero) < 0 {
return nil, nil, fmt.Errorf("check: modulus op argument %q is possibly negative", lhs.String(q.tm))
return nil, nil, fmt.Errorf("check: modulus op argument %q is possibly negative", lhs.Str(q.tm))
}
if rMin.Cmp(zero) <= 0 {
return nil, nil, fmt.Errorf("check: modulus op argument %q is possibly non-positive", rhs.String(q.tm))
return nil, nil, fmt.Errorf("check: modulus op argument %q is possibly non-positive", rhs.Str(q.tm))
}
return zero, big.NewInt(0).Sub(rMax, one), nil
+26 -26
View File
@@ -53,7 +53,7 @@ func (e *Error) Error() string {
b := append([]byte(s), ". Facts:\n"...)
for _, f := range e.Facts {
b = append(b, '\t')
b = append(b, f.String(e.TMap)...)
b = append(b, f.Str(e.TMap)...)
b = append(b, '\n')
}
return string(b)
@@ -209,7 +209,7 @@ func (c *Checker) checkPackageID(node *a.Node) error {
OtherLine: c.otherPackageID.Line(),
}
}
raw := n.ID().String(c.tm)
raw := n.ID().Str(c.tm)
s, ok := t.Unescape(raw)
if !ok {
return &Error{
@@ -241,7 +241,7 @@ func (c *Checker) checkStatus(node *a.Node) error {
id := n.Message()
if other, ok := c.statuses[id]; ok {
return &Error{
Err: fmt.Errorf("check: duplicate status %q", builtin.TrimQuotes(id.String(c.tm))),
Err: fmt.Errorf("check: duplicate status %q", builtin.TrimQuotes(id.Str(c.tm))),
Filename: n.Filename(),
Line: n.Line(),
OtherFilename: other.Status.Filename(),
@@ -261,7 +261,7 @@ func (c *Checker) checkConst(node *a.Node) error {
id := n.Name()
if other, ok := c.consts[id]; ok {
return &Error{
Err: fmt.Errorf("check: duplicate const %q", id.String(c.tm)),
Err: fmt.Errorf("check: duplicate const %q", id.Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
OtherFilename: other.Const.Filename(),
@@ -278,10 +278,10 @@ func (c *Checker) checkConst(node *a.Node) error {
tm: c.tm,
}
if err := q.tcheckTypeExpr(n.XType(), 0); err != nil {
return fmt.Errorf("%v in const %q", err, id.String(c.tm))
return fmt.Errorf("%v in const %q", err, id.Str(c.tm))
}
if err := q.tcheckExpr(n.Value(), 0); err != nil {
return fmt.Errorf("%v in const %q", err, id.String(c.tm))
return fmt.Errorf("%v in const %q", err, id.Str(c.tm))
}
nLists := 0
@@ -294,17 +294,17 @@ func (c *Checker) checkConst(node *a.Node) error {
typ = typ.Inner()
}
if typ.Decorator() != 0 {
return fmt.Errorf("check: invalid const type %q for %q", n.XType().String(c.tm), id.String(c.tm))
return fmt.Errorf("check: invalid const type %q for %q", n.XType().Str(c.tm), id.Str(c.tm))
}
nMin, nMax, err := q.bcheckTypeExpr(typ)
if err != nil {
return err
}
if nMin == nil || nMax == nil {
return fmt.Errorf("check: invalid const type %q for %q", n.XType().String(c.tm), id.String(c.tm))
return fmt.Errorf("check: invalid const type %q for %q", n.XType().Str(c.tm), id.Str(c.tm))
}
if err := c.checkConstElement(n.Value(), nMin, nMax, nLists); err != nil {
return fmt.Errorf("check: %v for %q", err, id.String(c.tm))
return fmt.Errorf("check: %v for %q", err, id.Str(c.tm))
}
n.Node().SetTypeChecked()
return nil
@@ -314,7 +314,7 @@ func (c *Checker) checkConstElement(n *a.Expr, nMin *big.Int, nMax *big.Int, nLi
if nLists > 0 {
nLists--
if n.ID0().Key() != t.KeyDollar {
return fmt.Errorf("invalid const value %q", n.String(c.tm))
return fmt.Errorf("invalid const value %q", n.Str(c.tm))
}
for _, o := range n.Args() {
if err := c.checkConstElement(o.Expr(), nMin, nMax, nLists); err != nil {
@@ -324,7 +324,7 @@ func (c *Checker) checkConstElement(n *a.Expr, nMin *big.Int, nMax *big.Int, nLi
return nil
}
if cv := n.ConstValue(); cv == nil || cv.Cmp(nMin) < 0 || cv.Cmp(nMax) > 0 {
return fmt.Errorf("invalid const value %q not within [%v..%v]", n.String(c.tm), nMin, nMax)
return fmt.Errorf("invalid const value %q not within [%v..%v]", n.Str(c.tm), nMin, nMax)
}
return nil
}
@@ -334,7 +334,7 @@ func (c *Checker) checkStructDecl(node *a.Node) error {
id := n.Name()
if other, ok := c.structs[id]; ok {
return &Error{
Err: fmt.Errorf("check: duplicate struct %q", id.String(c.tm)),
Err: fmt.Errorf("check: duplicate struct %q", id.Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
OtherFilename: other.Struct.Filename(),
@@ -360,7 +360,7 @@ func (c *Checker) checkStructFields(node *a.Node) error {
n := node.Struct()
if err := c.checkFields(n.Fields(), true); err != nil {
return &Error{
Err: fmt.Errorf("%v in struct %q", err, n.Name().String(c.tm)),
Err: fmt.Errorf("%v in struct %q", err, n.Name().Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
}
@@ -382,19 +382,19 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool) error {
for _, n := range fields {
f := n.Field()
if _, ok := fieldNames[f.Name()]; ok {
return fmt.Errorf("check: duplicate field %q", f.Name().String(c.tm))
return fmt.Errorf("check: duplicate field %q", f.Name().Str(c.tm))
}
if err := q.tcheckTypeExpr(f.XType(), 0); err != nil {
return fmt.Errorf("%v in field %q", err, f.Name().String(c.tm))
return fmt.Errorf("%v in field %q", err, f.Name().Str(c.tm))
}
if banPtrTypes && f.XType().HasPointers() {
return fmt.Errorf("check: pointer-containing type %q not allowed for field %q",
f.XType().String(c.tm), f.Name().String(c.tm))
f.XType().Str(c.tm), f.Name().Str(c.tm))
}
if dv := f.DefaultValue(); dv != nil {
if f.XType().Decorator() != 0 {
return fmt.Errorf("check: cannot set default value for qualified type %q for field %q",
f.XType().String(c.tm), f.Name().String(c.tm))
f.XType().Str(c.tm), f.Name().Str(c.tm))
}
if err := q.tcheckExpr(dv, 0); err != nil {
return err
@@ -414,7 +414,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
n := node.Func()
if err := c.checkFields(n.In().Fields(), false); err != nil {
return &Error{
Err: fmt.Errorf("%v in in-params for func %q", err, n.Name().String(c.tm)),
Err: fmt.Errorf("%v in in-params for func %q", err, n.Name().Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
}
@@ -422,7 +422,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
n.In().Node().SetTypeChecked()
if err := c.checkFields(n.Out().Fields(), false); err != nil {
return &Error{
Err: fmt.Errorf("%v in out-params for func %q", err, n.Name().String(c.tm)),
Err: fmt.Errorf("%v in out-params for func %q", err, n.Name().Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
}
@@ -436,7 +436,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
qid := n.QID()
if other, ok := c.funcs[qid]; ok {
return &Error{
Err: fmt.Errorf("check: duplicate function %q", qid.String(c.tm)),
Err: fmt.Errorf("check: duplicate function %q", qid.Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
OtherFilename: other.Func.Filename(),
@@ -455,7 +455,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
if qid[0] != 0 {
if _, ok := c.structs[qid[0]]; !ok {
return &Error{
Err: fmt.Errorf("check: no receiver struct defined for function %q", qid.String(c.tm)),
Err: fmt.Errorf("check: no receiver struct defined for function %q", qid.Str(c.tm)),
Filename: n.Filename(),
Line: n.Line(),
}
@@ -540,10 +540,10 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
switch o.Kind() {
case a.KExpr:
return fmt.Errorf("check: internal error: unchecked %s node %q",
o.Kind(), o.Expr().String(q.tm))
o.Kind(), o.Expr().Str(q.tm))
case a.KTypeExpr:
return fmt.Errorf("check: internal error: unchecked %s node %q",
o.Kind(), o.TypeExpr().String(q.tm))
o.Kind(), o.TypeExpr().Str(q.tm))
}
return fmt.Errorf("check: internal error: unchecked %s node", o.Kind())
}
@@ -551,10 +551,10 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
o := o.Expr()
if typ := o.MType(); typ == nil {
return fmt.Errorf("check: internal error: expression %q has no (implicit) type",
o.String(q.tm))
o.Str(q.tm))
} else if typ.IsIdeal() && o.ConstValue() == nil {
return fmt.Errorf("check: internal error: expression %q has ideal number type "+
"but no const value", o.String(q.tm))
"but no const value", o.Str(q.tm))
}
}
return nil
@@ -571,7 +571,7 @@ func (c *Checker) checkFieldMethodCollisions(node *a.Node) error {
qid := t.QID{n.Name(), o.Field().Name()}
if _, ok := c.funcs[qid]; ok {
return fmt.Errorf("check: struct %q has both a field and method named %q",
qid[0].String(c.tm), qid[1].String(c.tm))
qid[0].Str(c.tm), qid[1].Str(c.tm))
}
}
return nil
+3 -3
View File
@@ -123,15 +123,15 @@ func TestCheck(t *testing.T) {
break
}
if got, want := fooBar.QID.String(tm), "foo.bar"; got != want {
if got, want := fooBar.QID.Str(tm), "foo.bar"; got != want {
t.Fatalf("Funcs[0] name: got %q, want %q", got, want)
}
got := [][2]string(nil)
for id, typ := range fooBar.LocalVars {
got = append(got, [2]string{
id.String(tm),
typ.String(tm),
id.Str(tm),
typ.Str(tm),
})
}
sort.Slice(got, func(i, j int) bool {
+1 -1
View File
@@ -294,7 +294,7 @@ func (q *checker) optimizeIOMethodAdvance(n *a.Expr, receiver *a.Expr, advance *
o.SetMType(typeExprIdeal)
if !n.CallSuspendible() {
return nil, fmt.Errorf("check: internal error: inconsistent suspendible-ness for %q", n.String(q.tm))
return nil, fmt.Errorf("check: internal error: inconsistent suspendible-ness for %q", n.Str(q.tm))
}
n.SetProvenNotToSuspend()
+63 -63
View File
@@ -51,7 +51,7 @@ func (q *checker) tcheckVars(block []*a.Node) error {
o := o.Var()
name := o.Name()
if _, ok := q.f.LocalVars[name]; ok {
return fmt.Errorf("check: duplicate var %q", name.String(q.tm))
return fmt.Errorf("check: duplicate var %q", name.Str(q.tm))
}
if err := q.tcheckTypeExpr(o.XType(), 0); err != nil {
return err
@@ -92,7 +92,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
}
if !cond.MType().IsBool() {
return fmt.Errorf("check: if condition %q, of type %q, does not have a boolean type",
cond.String(q.tm), cond.MType().String(q.tm))
cond.Str(q.tm), cond.MType().Str(q.tm))
}
for _, o := range n.BodyIfTrue() {
if err := q.tcheckStatement(o); err != nil {
@@ -117,7 +117,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return err
}
if cv := unroll.ConstValue(); cv == nil {
return fmt.Errorf("check: unroll count %q is not constant", unroll.String(q.tm))
return fmt.Errorf("check: unroll count %q is not constant", unroll.Str(q.tm))
}
for _, o := range n.Variables() {
if err := q.tcheckStatement(o); err != nil {
@@ -144,10 +144,10 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if jumpTarget == nil {
sepStr, labelStr := "", ""
if id := n.Label(); id != 0 {
sepStr, labelStr = ":", id.String(q.tm)
sepStr, labelStr = ":", id.Str(q.tm)
}
return fmt.Errorf("no matching while/iterate statement for %s%s%s",
n.Keyword().String(q.tm), sepStr, labelStr)
n.Keyword().Str(q.tm), sepStr, labelStr)
}
if n.Keyword().Key() == t.KeyBreak {
jumpTarget.SetHasBreak()
@@ -169,7 +169,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
case a.KVar:
n := n.Var()
if !n.XType().Node().TypeChecked() {
return fmt.Errorf("check: internal error: unchecked type expression %q", n.XType().String(q.tm))
return fmt.Errorf("check: internal error: unchecked type expression %q", n.XType().Str(q.tm))
}
if value := n.Value(); value != nil {
if err := q.tcheckExpr(value, 0); err != nil {
@@ -180,16 +180,16 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if n.IterateVariable() {
if lTyp.Decorator().Key() != t.KeyPtr {
return fmt.Errorf("check: iterate variable %q, of type %q, does not have a pointer type",
n.Name().String(q.tm), lTyp.String(q.tm))
n.Name().Str(q.tm), lTyp.Str(q.tm))
}
if rTyp.Decorator().Key() != t.KeyColon {
return fmt.Errorf("check: iterate range %q, of type %q, does not have a slice type",
value.String(q.tm), rTyp.String(q.tm))
value.Str(q.tm), rTyp.Str(q.tm))
}
if !lTyp.Inner().Eq(rTyp.Inner()) {
return fmt.Errorf("check: cannot iterate %q of type %q over %q of type %q "+
"as their inner types don't match",
n.Name().String(q.tm), lTyp.String(q.tm), value.String(q.tm), rTyp.String(q.tm))
n.Name().Str(q.tm), lTyp.Str(q.tm), value.Str(q.tm), rTyp.Str(q.tm))
}
} else if (rTyp.IsIdeal() && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) {
@@ -197,7 +197,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
} else {
return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q",
value.String(q.tm), rTyp.String(q.tm), n.Name().String(q.tm), lTyp.String(q.tm))
value.Str(q.tm), rTyp.Str(q.tm), n.Name().Str(q.tm), lTyp.Str(q.tm))
}
} else {
// TODO: check that the default zero value is assignable to n.XType().
@@ -211,7 +211,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
}
if !cond.MType().IsBool() {
return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type",
cond.String(q.tm), cond.MType().String(q.tm))
cond.Str(q.tm), cond.MType().Str(q.tm))
}
if err := q.tcheckLoop(n); err != nil {
return err
@@ -232,7 +232,7 @@ func (q *checker) tcheckAssert(n *a.Assert) error {
}
if !cond.MType().IsBool() {
return fmt.Errorf("check: assert condition %q, of type %q, does not have a boolean type",
cond.String(q.tm), cond.MType().String(q.tm))
cond.Str(q.tm), cond.MType().Str(q.tm))
}
for _, o := range n.Args() {
if err := q.tcheckExpr(o.Arg().Value(), 0); err != nil {
@@ -261,25 +261,25 @@ func (q *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(q.tm), rTyp.String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
rhs.Str(q.tm), rTyp.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
if !lTyp.IsNumType() {
return fmt.Errorf("check: assignment %q: assignee %q, of type %q, does not have numeric type",
n.Operator().String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
n.Operator().Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
switch n.Operator().Key() {
case t.KeyShiftLEq, t.KeyShiftREq:
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: assignment %q: shift %q, of type %q, does not have numeric type",
n.Operator().String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
n.Operator().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
return nil
case t.KeyTildePlusEq:
if !lTyp.IsUnsignedInteger() {
return fmt.Errorf("check: assignment %q: %q, of type %q, does not have unsigned integer type",
n.Operator().String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
n.Operator().Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
}
@@ -287,9 +287,9 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
return nil
}
return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types",
n.Operator().String(q.tm),
lhs.String(q.tm), rhs.String(q.tm),
lTyp.String(q.tm), rTyp.String(q.tm),
n.Operator().Str(q.tm),
lhs.Str(q.tm), rhs.Str(q.tm),
lTyp.Str(q.tm), rTyp.Str(q.tm),
)
}
@@ -356,7 +356,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
id1 := n.ID1()
if id1.IsNumLiteral() {
z := big.NewInt(0)
s := id1.String(q.tm)
s := id1.Str(q.tm)
if _, ok := z.SetString(s, 0); !ok {
return fmt.Errorf("check: invalid numeric literal %q", s)
}
@@ -379,7 +379,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return nil
}
// TODO: look for other (global) names: funcs, structs.
return fmt.Errorf("check: unrecognized identifier %q", id1.String(q.tm))
return fmt.Errorf("check: unrecognized identifier %q", id1.Str(q.tm))
}
switch id1.Key() {
case t.KeyFalse:
@@ -574,12 +574,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
lTyp := lhs.MType()
if key := lTyp.Decorator().Key(); key != t.KeyOpenBracket && key != t.KeyColon {
return fmt.Errorf("check: %s is an index expression but %s has type %s, not an array or slice type",
n.String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
rTyp := rhs.MType()
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: %s is an index expression but %s has type %s, not a numeric type",
n.String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
n.Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
n.SetMType(lTyp.Inner())
return nil
@@ -595,7 +595,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
mTyp := mhs.MType()
if !mTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not a numeric type",
n.String(q.tm), mhs.String(q.tm), mTyp.String(q.tm))
n.Str(q.tm), mhs.Str(q.tm), mTyp.Str(q.tm))
}
}
if rhs := n.RHS().Expr(); rhs != nil {
@@ -605,7 +605,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
rTyp := rhs.MType()
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not a numeric type",
n.String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
n.Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
}
lhs := n.LHS().Expr()
@@ -616,7 +616,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
switch lTyp.Decorator().Key() {
default:
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not an array or slice type",
n.String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
n.Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
case t.KeyOpenBracket:
n.SetMType(a.NewTypeExpr(t.IDColon, 0, nil, nil, lTyp.Inner()))
case t.KeyColon:
@@ -633,7 +633,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
if s, ok := q.c.statuses[n.ID1()]; ok {
declaredKeyword = s.Status.Keyword()
} else {
msg := builtin.TrimQuotes(n.ID1().String(q.tm))
msg := builtin.TrimQuotes(n.ID1().Str(q.tm))
z, ok := builtin.StatusMap[msg]
if !ok {
return fmt.Errorf("check: no error or status with message %q", msg)
@@ -642,7 +642,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
}
if nominalKeyword != declaredKeyword {
return fmt.Errorf("check: status literal says %q but declaration says %q",
nominalKeyword.String(q.tm), declaredKeyword.String(q.tm))
nominalKeyword.Str(q.tm), declaredKeyword.Str(q.tm))
}
n.SetMType(typeExprStatus)
return nil
@@ -658,7 +658,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return nil
}
return fmt.Errorf("check: unrecognized token.Key (0x%X) in expression %q for tcheckExprOther",
n.ID0().Key(), n.String(q.tm))
n.ID0().Key(), n.Str(q.tm))
}
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
@@ -768,7 +768,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
}
if s == nil {
return fmt.Errorf("check: no struct type %q found for expression %q",
lTyp.Name().String(q.tm), lhs.String(q.tm))
lTyp.Name().Str(q.tm), lhs.Str(q.tm))
}
for _, field := range s.Fields() {
@@ -785,7 +785,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
}
return fmt.Errorf("check: no field or method named %q found in struct type %q for expression %q",
n.ID1().String(q.tm), lTyp.Name().String(q.tm), n.String(q.tm))
n.ID1().Str(q.tm), lTyp.Name().Str(q.tm), n.Str(q.tm))
}
func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
@@ -799,7 +799,7 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
case t.KeyXUnaryPlus, t.KeyXUnaryMinus:
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a numeric type",
n.ID0().AmbiguousForm().String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
n.ID0().AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
if cv := rhs.ConstValue(); cv != nil {
if n.ID0().Key() == t.KeyXUnaryMinus {
@@ -813,7 +813,7 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
case t.KeyXUnaryNot:
if !rTyp.IsBool() {
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type",
n.ID0().AmbiguousForm().String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
n.ID0().AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
if cv := rhs.ConstValue(); cv != nil {
n.SetConstValue(btoi(cv.Cmp(zero) == 0))
@@ -827,7 +827,7 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
case t.KeyXUnaryDeref:
if rTyp.Decorator().Key() != t.KeyPtr { // TODO: t.KeyNptr?
return fmt.Errorf("check: %q is a dereference of a non-pointer type %q",
n.String(q.tm), rTyp.String(q.tm))
n.Str(q.tm), rTyp.Str(q.tm))
}
n.SetMType(rTyp.Inner())
return nil
@@ -852,7 +852,7 @@ func (q *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(q.tm), lTyp.String(q.tm), rhs.String(q.tm))
lhs.Str(q.tm), lTyp.Str(q.tm), rhs.Str(q.tm))
}
rhs := n.RHS().Expr()
if err := q.tcheckExpr(rhs, depth); err != nil {
@@ -864,22 +864,22 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
default:
if !lTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type",
op.AmbiguousForm().String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
op.AmbiguousForm().Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type",
op.AmbiguousForm().String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
op.AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
case t.KeyXBinaryNotEq, t.KeyXBinaryEqEq:
// No-op.
case t.KeyXBinaryAnd, t.KeyXBinaryOr:
if !lTyp.IsBool() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type",
op.AmbiguousForm().String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
op.AmbiguousForm().Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
if !rTyp.IsBool() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type",
op.AmbiguousForm().String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
op.AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
}
@@ -887,18 +887,18 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
default:
if !lTyp.EqIgnoringRefinements(rTyp) && !lTyp.IsIdeal() && !rTyp.IsIdeal() {
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have compatible types",
op.AmbiguousForm().String(q.tm),
lhs.String(q.tm), rhs.String(q.tm),
lTyp.String(q.tm), rTyp.String(q.tm),
op.AmbiguousForm().Str(q.tm),
lhs.Str(q.tm), rhs.Str(q.tm),
lTyp.Str(q.tm), rTyp.Str(q.tm),
)
}
case t.KeyXBinaryShiftL, t.KeyXBinaryShiftR:
if lTyp.IsIdeal() && !rTyp.IsIdeal() {
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+
"cannot shift an ideal number by a non-ideal number",
op.AmbiguousForm().String(q.tm),
lhs.String(q.tm), rhs.String(q.tm),
lTyp.String(q.tm), rTyp.String(q.tm),
op.AmbiguousForm().Str(q.tm),
lhs.Str(q.tm), rhs.Str(q.tm),
lTyp.Str(q.tm), rTyp.Str(q.tm),
)
}
}
@@ -910,17 +910,17 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
typ = rTyp
if typ.IsIdeal() {
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have non-ideal types",
op.AmbiguousForm().String(q.tm),
lhs.String(q.tm), rhs.String(q.tm),
lTyp.String(q.tm), rTyp.String(q.tm),
op.AmbiguousForm().Str(q.tm),
lhs.Str(q.tm), rhs.Str(q.tm),
lTyp.Str(q.tm), rTyp.Str(q.tm),
)
}
}
if !typ.IsUnsignedInteger() {
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have unsigned integer types",
op.AmbiguousForm().String(q.tm),
lhs.String(q.tm), rhs.String(q.tm),
lTyp.String(q.tm), rTyp.String(q.tm),
op.AmbiguousForm().Str(q.tm),
lhs.Str(q.tm), rhs.Str(q.tm),
lTyp.Str(q.tm), rTyp.Str(q.tm),
)
}
}
@@ -954,7 +954,7 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
return big.NewInt(0).Mul(l, r), nil
case t.KeyXBinarySlash:
if r.Cmp(zero) == 0 {
return nil, fmt.Errorf("check: division by zero in const expression %q", n.String(tm))
return nil, fmt.Errorf("check: division by zero in const expression %q", n.Str(tm))
}
// TODO: decide on Euclidean division vs other definitions. See "go doc
// math/big int.divmod" for details.
@@ -962,13 +962,13 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
case t.KeyXBinaryShiftL:
if r.Cmp(zero) < 0 || r.Cmp(ffff) > 0 {
return nil, fmt.Errorf("check: shift %q out of range in const expression %q",
n.RHS().Expr().String(tm), n.String(tm))
n.RHS().Expr().Str(tm), n.Str(tm))
}
return big.NewInt(0).Lsh(l, uint(r.Uint64())), nil
case t.KeyXBinaryShiftR:
if r.Cmp(zero) < 0 || r.Cmp(ffff) > 0 {
return nil, fmt.Errorf("check: shift %q out of range in const expression %q",
n.RHS().Expr().String(tm), n.String(tm))
n.RHS().Expr().Str(tm), n.Str(tm))
}
return big.NewInt(0).Rsh(l, uint(r.Uint64())), nil
case t.KeyXBinaryAmp:
@@ -981,7 +981,7 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
return big.NewInt(0).Xor(l, r), nil
case t.KeyXBinaryPercent:
if r.Cmp(zero) == 0 {
return nil, fmt.Errorf("check: division by zero in const expression %q", n.String(tm))
return nil, fmt.Errorf("check: division by zero in const expression %q", n.Str(tm))
}
return big.NewInt(0).Mod(l, r), nil
case t.KeyXBinaryNotEq:
@@ -1023,7 +1023,7 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
}
if !oTyp.IsNumType() {
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a numeric type",
n.ID0().AmbiguousForm().String(q.tm), o.String(q.tm), oTyp.String(q.tm))
n.ID0().AmbiguousForm().Str(q.tm), o.Str(q.tm), oTyp.Str(q.tm))
}
if typ == nil {
expr, typ = o, oTyp.Unrefined()
@@ -1032,9 +1032,9 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
if !typ.EqIgnoringRefinements(oTyp) {
return fmt.Errorf("check: associative %q: %q and %q, of types %q and %q, "+
"do not have compatible types",
n.ID0().AmbiguousForm().String(q.tm),
expr.String(q.tm), o.String(q.tm),
expr.MType().String(q.tm), o.MType().String(q.tm))
n.ID0().AmbiguousForm().Str(q.tm),
expr.Str(q.tm), o.Str(q.tm),
expr.MType().Str(q.tm), o.MType().Str(q.tm))
}
}
if typ == nil {
@@ -1051,7 +1051,7 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
}
if !o.MType().IsBool() {
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a boolean type",
n.ID0().AmbiguousForm().String(q.tm), o.String(q.tm), o.MType().String(q.tm))
n.ID0().AmbiguousForm().Str(q.tm), o.Str(q.tm), o.MType().Str(q.tm))
}
}
n.SetMType(typeExprBool)
@@ -1079,7 +1079,7 @@ swtch:
return err
}
if b.ConstValue() == nil {
return fmt.Errorf("check: %q is not constant", b.String(q.tm))
return fmt.Errorf("check: %q is not constant", b.Str(q.tm))
}
}
break
@@ -1096,7 +1096,7 @@ swtch:
break swtch
}
}
return fmt.Errorf("check: %q is not a type", n.Name().String(q.tm))
return fmt.Errorf("check: %q is not a type", n.Name().Str(q.tm))
case t.KeyOpenBracket:
aLen := n.ArrayLength()
@@ -1104,7 +1104,7 @@ swtch:
return err
}
if aLen.ConstValue() == nil {
return fmt.Errorf("check: %q is not constant", aLen.String(q.tm))
return fmt.Errorf("check: %q is not constant", aLen.Str(q.tm))
}
fallthrough
+2 -2
View File
@@ -100,7 +100,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
}
p.src = p.src[1:]
if k == t.KeyPackageID {
raw := path.String(p.tm)
raw := path.Str(p.tm)
s, ok := t.Unescape(raw)
if !ok {
return nil, fmt.Errorf(`parse: %q is not a valid packageid`, raw)
@@ -801,7 +801,7 @@ func (p *parser) parseTryExpr() (*a.Expr, error) {
}
if call.ID0() != t.IDOpenParen {
return nil, fmt.Errorf(`parse: expected function call after "try", got %q at %s:%d`,
call.String(p.tm), p.filename, p.line())
call.Str(p.tm), p.filename, p.line())
}
return a.NewExpr(call.Node().Raw().Flags(), t.IDTry, call.ID1(),
call.LHS(), call.MHS(), call.RHS(), call.Args()), nil
+4 -4
View File
@@ -63,8 +63,8 @@ const (
// ID combines a Key and Flags.
type ID uint32
// String returns a string form of x.
func (x ID) String(m *Map) string { return m.ByID(x) }
// Str returns a string form of x.
func (x ID) Str(m *Map) string { return m.ByID(x) }
func (x ID) AmbiguousForm() ID { return ambiguousForms[0xFF&(x>>KeyShift)] }
func (x ID) UnaryForm() ID { return unaryForms[0xFF&(x>>KeyShift)] }
@@ -99,8 +99,8 @@ func (x ID) IsXAssociativeOp() bool { return x.Key().isXOp() && x.IsAssociativeO
// "bar"'s. QID[0] may be 0 for a plain "bar".
type QID [2]ID
// String returns a string form of x.
func (x QID) String(m *Map) string {
// Str returns a string form of x.
func (x QID) Str(m *Map) string {
if x[0] == 0 {
return m.ByID(x[1])
}