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

+10 -10
View File
@@ -431,11 +431,11 @@ func (g *gen) sizeof(typ *a.TypeExpr) (uint32, error) {
return 8, nil
}
}
return 0, fmt.Errorf("unknown sizeof for %q", typ.String(g.tm))
return 0, fmt.Errorf("unknown sizeof for %q", typ.Str(g.tm))
}
func (g *gen) gatherStatuses(b *buffer, n *a.Status) error {
raw := n.Message().String(g.tm)
raw := n.Message().Str(g.tm)
msg, ok := t.Unescape(raw)
if !ok {
return fmt.Errorf("bad status message %q", raw)
@@ -459,7 +459,7 @@ func (g *gen) writeConst(b *buffer, n *a.Const) error {
b.writes("static ")
}
b.writes("const ")
if err := g.writeCTypeName(b, n.XType(), g.pkgPrefix, n.Name().String(g.tm)); err != nil {
if err := g.writeCTypeName(b, n.XType(), g.pkgPrefix, n.Name().Str(g.tm)); err != nil {
return err
}
b.writes(" = ")
@@ -484,7 +484,7 @@ func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
}
b.writeb('}')
default:
return fmt.Errorf("invalid const value %q", n.String(g.tm))
return fmt.Errorf("invalid const value %q", n.Str(g.tm))
}
return nil
}
@@ -495,7 +495,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
// set "self->private_impl.status = WUFFS_ETC__ERROR_BAD_WUFFS_VERSION;"
// regardless of the sizeof(*self) struct reserved by the caller and even
// if the caller and callee were built with different versions.
structName := n.Name().String(g.tm)
structName := n.Name().Str(g.tm)
b.writes("typedef struct {\n")
b.writes("// Do not access the private_impl's fields directly. There is no API/ABI\n")
b.writes("// compatibility or safety guarantee if you do so. Instead, use the\n")
@@ -513,7 +513,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
for _, o := range n.Fields() {
o := o.Field()
if err := g.writeCTypeName(b, o.XType(), fPrefix, o.Name().String(g.tm)); err != nil {
if err := g.writeCTypeName(b, o.XType(), fPrefix, o.Name().Str(g.tm)); err != nil {
return err
}
b.writes(";\n")
@@ -546,7 +546,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
if k.usesScratch {
b.writes("uint64_t scratch;\n")
}
b.printf("} %s%s[%d];\n", cPrefix, o.Name().String(g.tm), maxDepth)
b.printf("} %s%s[%d];\n", cPrefix, o.Name().Str(g.tm), maxDepth)
}
}
}
@@ -556,7 +556,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
}
func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) error {
structName := n.Name().String(g.tm)
structName := n.Name().Str(g.tm)
if public {
b.printf("// %s%s__initialize is an initializer function.\n", g.pkgPrefix, structName)
b.printf("//\n")
@@ -605,7 +605,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
f := f.Field()
if dv := f.DefaultValue(); dv != nil {
// TODO: set default values for array types.
b.printf("self->private_impl.%s%s = %d;\n", fPrefix, f.Name().String(g.tm), dv.ConstValue())
b.printf("self->private_impl.%s%s = %d;\n", fPrefix, f.Name().Str(g.tm), dv.ConstValue())
}
}
@@ -622,7 +622,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
}
b.printf("%s%s__initialize(&self->private_impl.%s%s,"+
"WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);\n",
g.pkgPrefix, x.Name().String(g.tm), fPrefix, f.Name().String(g.tm))
g.pkgPrefix, x.Name().Str(g.tm), fPrefix, f.Name().Str(g.tm))
}
b.writes("}\n\n")
+10 -10
View File
@@ -52,7 +52,7 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
} else if cv.Cmp(one) == 0 {
b.writes("true")
} else {
return fmt.Errorf("%v has type bool but constant value %v is neither 0 or 1", n.String(g.tm), cv)
return fmt.Errorf("%v has type bool but constant value %v is neither 0 or 1", n.Str(g.tm), cv)
}
return nil
}
@@ -92,7 +92,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
} else {
b.writes(vPrefix)
}
b.writes(id1.String(g.tm))
b.writes(id1.Str(g.tm))
}
return nil
@@ -305,7 +305,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
p0, p1 := "", ""
if o := n.LHS().Expr().LHS().Expr(); o != nil {
// TODO: don't hard-code these.
switch o.String(g.tm) {
switch o.Str(g.tm) {
case "in.dst":
p0 = bPrefix + "wend_dst"
p1 = bPrefix + "wptr_dst"
@@ -423,7 +423,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
lhs := n.LHS().Expr()
if lhs.ID1().Key() == t.KeyIn {
b.writes(aPrefix)
b.writes(n.ID1().String(g.tm))
b.writes(n.ID1().Str(g.tm))
return nil
}
@@ -436,13 +436,13 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
b.writes(".")
}
b.writes("private_impl." + fPrefix)
b.writes(n.ID1().String(g.tm))
b.writes(n.ID1().Str(g.tm))
return nil
case t.KeyError, t.KeyStatus, t.KeySuspension:
status := g.statusMap[n.ID1()]
if status.name == "" {
msg := builtin.TrimQuotes(n.ID1().String(g.tm))
msg := builtin.TrimQuotes(n.ID1().Str(g.tm))
z := builtin.StatusMap[msg]
if z.Message == "" {
return fmt.Errorf("no status code for %q", msg)
@@ -530,7 +530,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
b.writes(varName)
return nil
}
return fmt.Errorf("cannot convert Wuffs type %q to C", n.String(g.tm))
return fmt.Errorf("cannot convert Wuffs type %q to C", n.Str(g.tm))
}
// maxNumPointers is an arbitrary implementation restriction.
@@ -545,13 +545,13 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
// TODO: "nptr T", not just "ptr T".
if p := innermost.Decorator().Key(); p == t.KeyPtr {
if numPointers == maxNumPointers {
return fmt.Errorf("cannot convert Wuffs type %q to C: too many ptr's", n.String(g.tm))
return fmt.Errorf("cannot convert Wuffs type %q to C: too many ptr's", n.Str(g.tm))
}
numPointers++
continue
}
// TODO: fix this.
return fmt.Errorf("cannot convert Wuffs type %q to C", n.String(g.tm))
return fmt.Errorf("cannot convert Wuffs type %q to C", n.Str(g.tm))
}
fallback := true
@@ -562,7 +562,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
}
}
if fallback {
b.printf("%s%s", g.pkgPrefix, innermost.Name().String(g.tm))
b.printf("%s%s", g.pkgPrefix, innermost.Name().Str(g.tm))
}
for i := 0; i < numPointers; i++ {
+9 -9
View File
@@ -59,9 +59,9 @@ func (k *funk) jumpTarget(n a.Loop) (uint32, error) {
func (g *gen) funcCName(n *a.Func) string {
if r := n.Receiver(); r != 0 {
return g.pkgPrefix + r.String(g.tm) + "__" + n.Name().String(g.tm)
return g.pkgPrefix + r.Str(g.tm) + "__" + n.Name().Str(g.tm)
}
return g.pkgPrefix + n.Name().String(g.tm)
return g.pkgPrefix + n.Name().Str(g.tm)
}
func (g *gen) writeFuncSignature(b *buffer, n *a.Func) error {
@@ -88,7 +88,7 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func) error {
comma := false
if r := n.Receiver(); r != 0 {
b.printf("%s%s *self", g.pkgPrefix, r.String(g.tm))
b.printf("%s%s *self", g.pkgPrefix, r.Str(g.tm))
comma = true
}
for _, o := range n.In().Fields() {
@@ -97,7 +97,7 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func) error {
}
comma = true
o := o.Field()
if err := g.writeCTypeName(b, o.XType(), aPrefix, o.Name().String(g.tm)); err != nil {
if err := g.writeCTypeName(b, o.XType(), aPrefix, o.Name().Str(g.tm)); err != nil {
return err
}
}
@@ -224,7 +224,7 @@ func (g *gen) writeFuncImplBodyResume(b *buffer) error {
if g.currFunk.suspendible {
// TODO: don't hard-code [0], and allow recursive coroutines.
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0].coro_susp_point;\n",
cPrefix, g.currFunk.astFunc.Name().String(g.tm))
cPrefix, g.currFunk.astFunc.Name().Str(g.tm))
b.printf("if (coro_susp_point) {\n")
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), false); err != nil {
return err
@@ -256,14 +256,14 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
b.writes("\ngoto ok;\n") // Avoid the "unused label" warning.
b.writes("ok:\n")
b.printf("self->private_impl.%s%s[0].coro_susp_point = 0;\n",
cPrefix, g.currFunk.astFunc.Name().String(g.tm))
cPrefix, g.currFunk.astFunc.Name().Str(g.tm))
b.writes("goto exit; }\n\n") // Close the coroutine switch.
b.writes("goto suspend;\n") // Avoid the "unused label" warning.
b.writes("suspend:\n")
b.printf("self->private_impl.%s%s[0].coro_susp_point = coro_susp_point;\n",
cPrefix, g.currFunk.astFunc.Name().String(g.tm))
cPrefix, g.currFunk.astFunc.Name().Str(g.tm))
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), true); err != nil {
return err
}
@@ -319,7 +319,7 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error {
switch {
case oTyp.Decorator().Key() == t.KeyPtr:
checks = append(checks, fmt.Sprintf("!%s%s", aPrefix, o.Name().String(g.tm)))
checks = append(checks, fmt.Sprintf("!%s%s", aPrefix, o.Name().Str(g.tm)))
case oTyp.IsRefined():
bounds := [2]*big.Int{}
@@ -345,7 +345,7 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error {
if i != 0 {
op = '>'
}
checks = append(checks, fmt.Sprintf("%s%s %c %s", aPrefix, o.Name().String(g.tm), op, bound))
checks = append(checks, fmt.Sprintf("%s%s %c %s", aPrefix, o.Name().Str(g.tm), op, bound))
}
}
}
+20 -20
View File
@@ -162,7 +162,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
return fmt.Errorf("TODO: iterate over more than one variable")
}
v := vars[0].Var()
name := v.Name().String(g.tm)
name := v.Name().Str(g.tm)
b.writes("{\n")
// TODO: don't assume that the slice is a slice of u8. In particular,
@@ -252,7 +252,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
b.writes("return ")
if len(g.currFunk.astFunc.Out().Fields()) == 0 {
if retExpr != nil {
return fmt.Errorf("return expression %q incompatible with empty return type", retExpr.String(g.tm))
return fmt.Errorf("return expression %q incompatible with empty return type", retExpr.Str(g.tm))
}
} else if retExpr == nil {
// TODO: should a bare "return" imply "return out"?
@@ -277,15 +277,15 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
// cv := n.XType().ArrayLength().ConstValue()
// // TODO: check that cv is within size_t's range.
// g.printf("{ size_t i; for (i = 0; i < %d; i++) { %s%s[i] = $DEFAULT_VALUE; }}\n",
// cv, vPrefix, n.Name().String(g.tm))
// cv, vPrefix, n.Name().Str(g.tm))
return fmt.Errorf("TODO: array initializers for non-zero default values")
}
// TODO: arrays of arrays.
name := n.Name().String(g.tm)
name := n.Name().Str(g.tm)
b.printf("memset(%s%s, 0, sizeof(%s%s));\n", vPrefix, name, vPrefix, name)
default:
b.printf("%s%s = ", vPrefix, n.Name().String(g.tm))
b.printf("%s%s = ", vPrefix, n.Name().Str(g.tm))
if v := n.Value(); v != nil {
if err := g.writeExpr(b, v, replaceCallSuspendibles, parenthesesMandatory, 0); err != nil {
return err
@@ -482,7 +482,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
g.currFunk.usesScratch = true
// TODO: don't hard-code [0], and allow recursive coroutines.
scratchName := fmt.Sprintf("self->private_impl.%s%s[0].scratch",
cPrefix, g.currFunk.astFunc.Name().String(g.tm))
cPrefix, g.currFunk.astFunc.Name().Str(g.tm))
b.printf("%s = ", scratchName)
x := n.Args()[0].Arg().Value()
@@ -521,7 +521,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_header", 1) {
b.printf("status = %s%s__decode_header(self, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -531,7 +531,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_lsd", 1) {
b.printf("status = %s%s__decode_lsd(self, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -539,7 +539,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_extension", 1) {
b.printf("status = %s%s__decode_extension(self, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -547,7 +547,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_id", 2) {
b.printf("status = %s%s__decode_id(self, %sdst, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -563,7 +563,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
b.printf("%sstatus %s%d = %s%s__decode_blocks(self, %sdst, %ssrc);\n",
g.pkgPrefix, tPrefix, temp,
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -571,7 +571,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_uncompressed", 2) {
b.printf("status = %s%s__decode_uncompressed(self, %sdst, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -579,7 +579,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_huffman_fast", 2) {
b.printf("status = %s%s__decode_huffman_fast(self, %sdst, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -587,7 +587,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "decode_huffman_slow", 2) {
b.printf("status = %s%s__decode_huffman_slow(self, %sdst, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -595,7 +595,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "init_fixed_huffman", 0) {
b.printf("status = %s%s__init_fixed_huffman(self);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm))
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm))
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -603,7 +603,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "init_dynamic_huffman", 1) {
b.printf("status = %s%s__init_dynamic_huffman(self, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix)
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm), aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
@@ -611,7 +611,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
} else if isThisMethod(g.tm, n, "init_huff", 4) {
b.printf("status = %s%s__init_huff(self,",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm))
g.pkgPrefix, g.currFunk.astFunc.Receiver().Str(g.tm))
for i, o := range n.Args() {
if i != 0 {
b.writes(",")
@@ -667,14 +667,14 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
// TODO: check if tPrefix_temp is an error, and return?
default:
return fmt.Errorf("cannot convert Wuffs call %q to C", n.String(g.tm))
return fmt.Errorf("cannot convert Wuffs call %q to C", n.Str(g.tm))
}
} else {
// TODO: fix this.
//
// This might involve calling g.writeExpr with replaceNothing??
return fmt.Errorf("cannot convert Wuffs call %q to C", n.String(g.tm))
return fmt.Errorf("cannot convert Wuffs call %q to C", n.Str(g.tm))
}
return nil
}
@@ -706,7 +706,7 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
g.currFunk.usesScratch = true
// TODO: don't hard-code [0], and allow recursive coroutines.
scratchName := fmt.Sprintf("self->private_impl.%s%s[0].scratch",
cPrefix, g.currFunk.astFunc.Name().String(g.tm))
cPrefix, g.currFunk.astFunc.Name().Str(g.tm))
b.printf("if (WUFFS_BASE__LIKELY(%srend_src - %srptr_src >= %d)) {", bPrefix, bPrefix, size/8)
b.printf("%s%d = wuffs_base__load_u%d%s(%srptr_src);\n", tPrefix, temp1, size, endianness, bPrefix)
+10 -10
View File
@@ -79,7 +79,7 @@ func (g *gen) findDerivedVars() {
func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header bool) error {
// TODO: remove this hack. We're picking up the wrong name for "src:r,
// dummy:in.src".
if name.String(g.tm) == "dummy" {
if name.Str(g.tm) == "dummy" {
name = g.tm.ByName("src")
}
@@ -89,7 +89,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
if _, ok := g.currFunk.derivedVars[name]; !ok {
return nil
}
nameStr := name.String(g.tm)
nameStr := name.Str(g.tm)
switch typ.Name().Key() {
case t.KeyReader1:
if header {
@@ -156,7 +156,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer bool) error {
// TODO: remove this hack. We're picking up the wrong name for "src:r,
// dummy:in.src".
if name.String(g.tm) == "dummy" {
if name.Str(g.tm) == "dummy" {
name = g.tm.ByName("src")
}
@@ -166,7 +166,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
if _, ok := g.currFunk.derivedVars[name]; !ok {
return nil
}
nameStr := name.String(g.tm)
nameStr := name.Str(g.tm)
switch typ.Name().Key() {
case t.KeyReader1:
b.printf("if (%s%s.buf) {", aPrefix, nameStr)
@@ -223,7 +223,7 @@ func (g *gen) writeLoadExprDerivedVars(b *buffer, n *a.Expr) error {
for _, o := range n.Args() {
o := o.Arg()
// TODO: don't hard-code these.
if s := o.Value().String(g.tm); s != "in.dst" && s != "in.src" {
if s := o.Value().Str(g.tm); s != "in.dst" && s != "in.src" {
continue
}
if err := g.writeLoadDerivedVar(b, o.Name(), o.Value().MType(), false); err != nil {
@@ -243,7 +243,7 @@ func (g *gen) writeSaveExprDerivedVars(b *buffer, n *a.Expr) error {
for _, o := range n.Args() {
o := o.Arg()
// TODO: don't hard-code these.
if s := o.Value().String(g.tm); s != "in.dst" && s != "in.src" {
if s := o.Value().Str(g.tm); s != "in.dst" && s != "in.src" {
continue
}
if err := g.writeSaveDerivedVar(b, o.Name(), o.Value().MType(), false); err != nil {
@@ -294,7 +294,7 @@ func (g *gen) visitVars(b *buffer, block []*a.Node, depth uint32, f func(*gen, *
}
func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
local := fmt.Sprintf("%s%s", vPrefix, n.Name().String(g.tm))
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
if typ := n.XType(); typ.HasPointers() {
if suspend {
@@ -319,7 +319,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
} else {
lhs := local
// TODO: don't hard-code [0], and allow recursive coroutines.
rhs := fmt.Sprintf("self->private_impl.%s%s[0].%s", cPrefix, g.currFunk.astFunc.Name().String(g.tm), lhs)
rhs := fmt.Sprintf("self->private_impl.%s%s[0].%s", cPrefix, g.currFunk.astFunc.Name().Str(g.tm), lhs)
if suspend {
lhs, rhs = rhs, lhs
}
@@ -342,7 +342,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
}
return fmt.Errorf("cannot resume or suspend a local variable %q of type %q",
n.Name().String(g.tm), n.XType().String(g.tm))
n.Name().Str(g.tm), n.XType().Str(g.tm))
}
func (g *gen) writeResumeSuspend(b *buffer, block []*a.Node, suspend bool) error {
@@ -359,7 +359,7 @@ func (g *gen) writeVars(b *buffer, block []*a.Node, skipPointerTypes bool, skipI
if skipIterateVariables && n.IterateVariable() {
return nil
}
if err := g.writeCTypeName(b, n.XType(), vPrefix, n.Name().String(g.tm)); err != nil {
if err := g.writeCTypeName(b, n.XType(), vPrefix, n.Name().Str(g.tm)); err != nil {
return err
}
b.writes(";\n")
+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])
}