Commit bb855f98 authored by Rob Pike's avatar Rob Pike

govet: make name-matching for printf etc. case-insensitive.

Update goyacc, cgo to be more canonical in their naming and silence the new warnings.

R=rsc, gri
CC=golang-dev
https://golang.org/cl/4417042
parent 4c60569e
...@@ -30,7 +30,7 @@ func parse(name string, flags uint) *ast.File { ...@@ -30,7 +30,7 @@ func parse(name string, flags uint) *ast.File {
} }
os.Exit(2) os.Exit(2)
} }
fatal("parsing %s: %s", name, err) fatalf("parsing %s: %s", name, err)
} }
return ast1 return ast1
} }
......
...@@ -79,7 +79,7 @@ NextLine: ...@@ -79,7 +79,7 @@ NextLine:
l = strings.TrimSpace(l[4:]) l = strings.TrimSpace(l[4:])
fields := strings.Split(l, ":", 2) fields := strings.Split(l, ":", 2)
if len(fields) != 2 { if len(fields) != 2 {
fatal("%s: bad #cgo line: %s", srcfile, line) fatalf("%s: bad #cgo line: %s", srcfile, line)
} }
var k string var k string
...@@ -97,17 +97,17 @@ NextLine: ...@@ -97,17 +97,17 @@ NextLine:
continue NextLine continue NextLine
} }
default: default:
fatal("%s: bad #cgo option: %s", srcfile, fields[0]) fatalf("%s: bad #cgo option: %s", srcfile, fields[0])
} }
if k != "CFLAGS" && k != "LDFLAGS" { if k != "CFLAGS" && k != "LDFLAGS" {
fatal("%s: unsupported #cgo option %s", srcfile, k) fatalf("%s: unsupported #cgo option %s", srcfile, k)
} }
v := strings.TrimSpace(fields[1]) v := strings.TrimSpace(fields[1])
args, err := splitQuoted(v) args, err := splitQuoted(v)
if err != nil { if err != nil {
fatal("%s: bad #cgo option %s: %s", srcfile, k, err.String()) fatalf("%s: bad #cgo option %s: %s", srcfile, k, err.String())
} }
if oldv, ok := p.CgoFlags[k]; ok { if oldv, ok := p.CgoFlags[k]; ok {
p.CgoFlags[k] = oldv + " " + v p.CgoFlags[k] = oldv + " " + v
...@@ -317,7 +317,7 @@ func (p *Package) guessKinds(f *File) []*Name { ...@@ -317,7 +317,7 @@ func (p *Package) guessKinds(f *File) []*Name {
b.WriteString("}\n") b.WriteString("}\n")
stderr := p.gccErrors(b.Bytes()) stderr := p.gccErrors(b.Bytes())
if stderr == "" { if stderr == "" {
fatal("gcc produced no output\non input:\n%s", b.Bytes()) fatalf("gcc produced no output\non input:\n%s", b.Bytes())
} }
names := make([]*Name, len(toSniff)) names := make([]*Name, len(toSniff))
...@@ -383,7 +383,7 @@ func (p *Package) guessKinds(f *File) []*Name { ...@@ -383,7 +383,7 @@ func (p *Package) guessKinds(f *File) []*Name {
error(token.NoPos, "could not determine kind of name for C.%s", n.Go) error(token.NoPos, "could not determine kind of name for C.%s", n.Go)
} }
if nerrors > 0 { if nerrors > 0 {
fatal("unresolved names") fatalf("unresolved names")
} }
return needType return needType
} }
...@@ -422,7 +422,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) { ...@@ -422,7 +422,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
for { for {
e, err := r.Next() e, err := r.Next()
if err != nil { if err != nil {
fatal("reading DWARF entry: %s", err) fatalf("reading DWARF entry: %s", err)
} }
if e == nil { if e == nil {
break break
...@@ -433,7 +433,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) { ...@@ -433,7 +433,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
for { for {
e, err := r.Next() e, err := r.Next()
if err != nil { if err != nil {
fatal("reading DWARF entry: %s", err) fatalf("reading DWARF entry: %s", err)
} }
if e.Tag == 0 { if e.Tag == 0 {
break break
...@@ -452,27 +452,27 @@ func (p *Package) loadDWARF(f *File, names []*Name) { ...@@ -452,27 +452,27 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
name, _ := e.Val(dwarf.AttrName).(string) name, _ := e.Val(dwarf.AttrName).(string)
typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset) typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset)
if name == "" || typOff == 0 { if name == "" || typOff == 0 {
fatal("malformed DWARF TagVariable entry") fatalf("malformed DWARF TagVariable entry")
} }
if !strings.HasPrefix(name, "__cgo__") { if !strings.HasPrefix(name, "__cgo__") {
break break
} }
typ, err := d.Type(typOff) typ, err := d.Type(typOff)
if err != nil { if err != nil {
fatal("loading DWARF type: %s", err) fatalf("loading DWARF type: %s", err)
} }
t, ok := typ.(*dwarf.PtrType) t, ok := typ.(*dwarf.PtrType)
if !ok || t == nil { if !ok || t == nil {
fatal("internal error: %s has non-pointer type", name) fatalf("internal error: %s has non-pointer type", name)
} }
i, err := strconv.Atoi(name[7:]) i, err := strconv.Atoi(name[7:])
if err != nil { if err != nil {
fatal("malformed __cgo__ name: %s", name) fatalf("malformed __cgo__ name: %s", name)
} }
if enums[i] != 0 { if enums[i] != 0 {
t, err := d.Type(enums[i]) t, err := d.Type(enums[i])
if err != nil { if err != nil {
fatal("loading DWARF type: %s", err) fatalf("loading DWARF type: %s", err)
} }
types[i] = t types[i] = t
} else { } else {
...@@ -632,14 +632,14 @@ func (p *Package) gccDebug(stdin []byte) *dwarf.Data { ...@@ -632,14 +632,14 @@ func (p *Package) gccDebug(stdin []byte) *dwarf.Data {
if f, err = elf.Open(gccTmp); err != nil { if f, err = elf.Open(gccTmp); err != nil {
if f, err = macho.Open(gccTmp); err != nil { if f, err = macho.Open(gccTmp); err != nil {
if f, err = pe.Open(gccTmp); err != nil { if f, err = pe.Open(gccTmp); err != nil {
fatal("cannot parse gcc output %s as ELF or Mach-O or PE object", gccTmp) fatalf("cannot parse gcc output %s as ELF or Mach-O or PE object", gccTmp)
} }
} }
} }
d, err := f.DWARF() d, err := f.DWARF()
if err != nil { if err != nil {
fatal("cannot load DWARF debug information from %s: %s", gccTmp, err) fatalf("cannot load DWARF debug information from %s: %s", gccTmp, err)
} }
return d return d
} }
...@@ -807,7 +807,7 @@ func (tr *TypeRepr) Set(repr string, fargs ...interface{}) { ...@@ -807,7 +807,7 @@ func (tr *TypeRepr) Set(repr string, fargs ...interface{}) {
func (c *typeConv) Type(dtype dwarf.Type) *Type { func (c *typeConv) Type(dtype dwarf.Type) *Type {
if t, ok := c.m[dtype]; ok { if t, ok := c.m[dtype]; ok {
if t.Go == nil { if t.Go == nil {
fatal("type conversion loop at %s", dtype) fatalf("type conversion loop at %s", dtype)
} }
return t return t
} }
...@@ -830,11 +830,11 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -830,11 +830,11 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
switch dt := dtype.(type) { switch dt := dtype.(type) {
default: default:
fatal("unexpected type: %s", dtype) fatalf("unexpected type: %s", dtype)
case *dwarf.AddrType: case *dwarf.AddrType:
if t.Size != c.ptrSize { if t.Size != c.ptrSize {
fatal("unexpected: %d-byte address type - %s", t.Size, dtype) fatalf("unexpected: %d-byte address type - %s", t.Size, dtype)
} }
t.Go = c.uintptr t.Go = c.uintptr
t.Align = t.Size t.Align = t.Size
...@@ -860,7 +860,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -860,7 +860,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
case *dwarf.CharType: case *dwarf.CharType:
if t.Size != 1 { if t.Size != 1 {
fatal("unexpected: %d-byte char type - %s", t.Size, dtype) fatalf("unexpected: %d-byte char type - %s", t.Size, dtype)
} }
t.Go = c.int8 t.Go = c.int8
t.Align = 1 t.Align = 1
...@@ -880,7 +880,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -880,7 +880,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
} }
switch t.Size + int64(signed) { switch t.Size + int64(signed) {
default: default:
fatal("unexpected: %d-byte enum type - %s", t.Size, dtype) fatalf("unexpected: %d-byte enum type - %s", t.Size, dtype)
case 1: case 1:
t.Go = c.uint8 t.Go = c.uint8
case 2: case 2:
...@@ -902,7 +902,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -902,7 +902,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
case *dwarf.FloatType: case *dwarf.FloatType:
switch t.Size { switch t.Size {
default: default:
fatal("unexpected: %d-byte float type - %s", t.Size, dtype) fatalf("unexpected: %d-byte float type - %s", t.Size, dtype)
case 4: case 4:
t.Go = c.float32 t.Go = c.float32
case 8: case 8:
...@@ -915,7 +915,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -915,7 +915,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
case *dwarf.ComplexType: case *dwarf.ComplexType:
switch t.Size { switch t.Size {
default: default:
fatal("unexpected: %d-byte complex type - %s", t.Size, dtype) fatalf("unexpected: %d-byte complex type - %s", t.Size, dtype)
case 8: case 8:
t.Go = c.complex64 t.Go = c.complex64
case 16: case 16:
...@@ -933,11 +933,11 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -933,11 +933,11 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
case *dwarf.IntType: case *dwarf.IntType:
if dt.BitSize > 0 { if dt.BitSize > 0 {
fatal("unexpected: %d-bit int type - %s", dt.BitSize, dtype) fatalf("unexpected: %d-bit int type - %s", dt.BitSize, dtype)
} }
switch t.Size { switch t.Size {
default: default:
fatal("unexpected: %d-byte int type - %s", t.Size, dtype) fatalf("unexpected: %d-byte int type - %s", t.Size, dtype)
case 1: case 1:
t.Go = c.int8 t.Go = c.int8
case 2: case 2:
...@@ -1022,18 +1022,18 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -1022,18 +1022,18 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
case *dwarf.UcharType: case *dwarf.UcharType:
if t.Size != 1 { if t.Size != 1 {
fatal("unexpected: %d-byte uchar type - %s", t.Size, dtype) fatalf("unexpected: %d-byte uchar type - %s", t.Size, dtype)
} }
t.Go = c.uint8 t.Go = c.uint8
t.Align = 1 t.Align = 1
case *dwarf.UintType: case *dwarf.UintType:
if dt.BitSize > 0 { if dt.BitSize > 0 {
fatal("unexpected: %d-bit uint type - %s", dt.BitSize, dtype) fatalf("unexpected: %d-bit uint type - %s", dt.BitSize, dtype)
} }
switch t.Size { switch t.Size {
default: default:
fatal("unexpected: %d-byte uint type - %s", t.Size, dtype) fatalf("unexpected: %d-byte uint type - %s", t.Size, dtype)
case 1: case 1:
t.Go = c.uint8 t.Go = c.uint8
case 2: case 2:
...@@ -1067,7 +1067,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { ...@@ -1067,7 +1067,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type {
} }
if t.C.Empty() { if t.C.Empty() {
fatal("internal error: did not create C name for %s", dtype) fatalf("internal error: did not create C name for %s", dtype)
} }
return t return t
...@@ -1229,7 +1229,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType) (expr *ast.StructType, csyntax s ...@@ -1229,7 +1229,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType) (expr *ast.StructType, csyntax s
off = dt.ByteSize off = dt.ByteSize
} }
if off != dt.ByteSize { if off != dt.ByteSize {
fatal("struct size calculation error") fatalf("struct size calculation error")
} }
buf.WriteString("}") buf.WriteString("}")
csyntax = buf.String() csyntax = buf.String()
......
...@@ -177,11 +177,11 @@ func main() { ...@@ -177,11 +177,11 @@ func main() {
arch := os.Getenv("GOARCH") arch := os.Getenv("GOARCH")
if arch == "" { if arch == "" {
fatal("$GOARCH is not set") fatalf("$GOARCH is not set")
} }
ptrSize := ptrSizeMap[arch] ptrSize := ptrSizeMap[arch]
if ptrSize == 0 { if ptrSize == 0 {
fatal("unknown $GOARCH %q", arch) fatalf("unknown $GOARCH %q", arch)
} }
// Clear locale variables so gcc emits English errors [sic]. // Clear locale variables so gcc emits English errors [sic].
...@@ -205,7 +205,7 @@ func main() { ...@@ -205,7 +205,7 @@ func main() {
for _, input := range goFiles { for _, input := range goFiles {
f, err := os.Open(input) f, err := os.Open(input)
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
io.Copy(h, f) io.Copy(h, f)
f.Close() f.Close()
......
...@@ -105,7 +105,7 @@ func dynimport(obj string) (syms, imports []string) { ...@@ -105,7 +105,7 @@ func dynimport(obj string) (syms, imports []string) {
if f, err1 = elf.Open(obj); err1 != nil { if f, err1 = elf.Open(obj); err1 != nil {
if f, err2 = pe.Open(obj); err2 != nil { if f, err2 = pe.Open(obj); err2 != nil {
if f, err3 = macho.Open(obj); err3 != nil { if f, err3 = macho.Open(obj); err3 != nil {
fatal("cannot parse %s as ELF (%v) or PE (%v) or Mach-O (%v)", obj, err1, err2, err3) fatalf("cannot parse %s as ELF (%v) or PE (%v) or Mach-O (%v)", obj, err1, err2, err3)
} }
isMacho = true isMacho = true
} }
...@@ -114,7 +114,7 @@ func dynimport(obj string) (syms, imports []string) { ...@@ -114,7 +114,7 @@ func dynimport(obj string) (syms, imports []string) {
var err os.Error var err os.Error
syms, err = f.ImportedSymbols() syms, err = f.ImportedSymbols()
if err != nil { if err != nil {
fatal("cannot load dynamic symbols: %v", err) fatalf("cannot load dynamic symbols: %v", err)
} }
if isMacho { if isMacho {
// remove leading _ that OS X insists on // remove leading _ that OS X insists on
...@@ -127,7 +127,7 @@ func dynimport(obj string) (syms, imports []string) { ...@@ -127,7 +127,7 @@ func dynimport(obj string) (syms, imports []string) {
imports, err = f.ImportedLibraries() imports, err = f.ImportedLibraries()
if err != nil { if err != nil {
fatal("cannot load dynamic imports: %v", err) fatalf("cannot load dynamic imports: %v", err)
} }
return return
......
...@@ -18,23 +18,23 @@ import ( ...@@ -18,23 +18,23 @@ import (
func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
cmd, err := exec.LookPath(argv[0]) cmd, err := exec.LookPath(argv[0])
if err != nil { if err != nil {
fatal("exec %s: %s", argv[0], err) fatalf("exec %s: %s", argv[0], err)
} }
r0, w0, err := os.Pipe() r0, w0, err := os.Pipe()
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
r1, w1, err := os.Pipe() r1, w1, err := os.Pipe()
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
r2, w2, err := os.Pipe() r2, w2, err := os.Pipe()
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
p, err := os.StartProcess(cmd, argv, &os.ProcAttr{Files: []*os.File{r0, w1, w2}}) p, err := os.StartProcess(cmd, argv, &os.ProcAttr{Files: []*os.File{r0, w1, w2}})
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
defer p.Release() defer p.Release()
r0.Close() r0.Close()
...@@ -58,14 +58,14 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { ...@@ -58,14 +58,14 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
w, err := p.Wait(0) w, err := p.Wait(0)
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
ok = w.Exited() && w.ExitStatus() == 0 ok = w.Exited() && w.ExitStatus() == 0
return return
} }
// Die with an error message. // Die with an error message.
func fatal(msg string, args ...interface{}) { func fatalf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...) fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(2) os.Exit(2)
} }
...@@ -97,7 +97,7 @@ func isName(s string) bool { ...@@ -97,7 +97,7 @@ func isName(s string) bool {
func creat(name string) *os.File { func creat(name string) *os.File {
f, err := os.Create(name) f, err := os.Create(name)
if err != nil { if err != nil {
fatal("%s", err) fatalf("%s", err)
} }
return f return f
} }
......
...@@ -63,6 +63,7 @@ func main() { ...@@ -63,6 +63,7 @@ func main() {
} }
name = name[:colon] name = name[:colon]
} }
name = strings.ToLower(name)
if name[len(name)-1] == 'f' { if name[len(name)-1] == 'f' {
printfList[name] = skip printfList[name] = skip
} else { } else {
...@@ -205,35 +206,38 @@ func (f *File) checkCallExpr(call *ast.CallExpr) { ...@@ -205,35 +206,38 @@ func (f *File) checkCallExpr(call *ast.CallExpr) {
} }
// printfList records the formatted-print functions. The value is the location // printfList records the formatted-print functions. The value is the location
// of the format parameter. // of the format parameter. Names are lower-cased so the lookup is
// case insensitive.
var printfList = map[string]int{ var printfList = map[string]int{
"Errorf": 0, "errorf": 0,
"Fatalf": 0, "fatalf": 0,
"Fprintf": 1, "fprintf": 1,
"Panicf": 0, "panicf": 0,
"Printf": 0, "printf": 0,
"Sprintf": 0, "sprintf": 0,
} }
// printList records the unformatted-print functions. The value is the location // printList records the unformatted-print functions. The value is the location
// of the first parameter to be printed. // of the first parameter to be printed. Names are lower-cased so the lookup is
// case insensitive.
var printList = map[string]int{ var printList = map[string]int{
"Error": 0, "error": 0,
"Fatal": 0, "fatal": 0,
"Fprint": 1, "Fprintln": 1, "fprint": 1, "fprintln": 1,
"Panic": 0, "Panicln": 0, "panic": 0, "panicln": 0,
"Print": 0, "Println": 0, "print": 0, "println": 0,
"Sprint": 0, "Sprintln": 0, "sprint": 0, "sprintln": 0,
} }
// checkCall triggers the print-specific checks if the call invokes a print function. // checkCall triggers the print-specific checks if the call invokes a print function.
func (f *File) checkCall(call *ast.CallExpr, name string) { func (f *File) checkCall(call *ast.CallExpr, Name string) {
name := strings.ToLower(Name)
if skip, ok := printfList[name]; ok { if skip, ok := printfList[name]; ok {
f.checkPrintf(call, name, skip) f.checkPrintf(call, Name, skip)
return return
} }
if skip, ok := printList[name]; ok { if skip, ok := printList[name]; ok {
f.checkPrint(call, name, skip) f.checkPrint(call, Name, skip)
return return
} }
} }
...@@ -362,8 +366,14 @@ func BadFunctionUsedInTests() { ...@@ -362,8 +366,14 @@ func BadFunctionUsedInTests() {
fmt.Printf("%s%%%d", "hi", 3) // right # percents fmt.Printf("%s%%%d", "hi", 3) // right # percents
fmt.Printf("%.*d", 3, 3) // right # percents, with a * fmt.Printf("%.*d", 3, 3) // right # percents, with a *
fmt.Printf("%.*d", 3, 3, 3) // wrong # percents, with a * fmt.Printf("%.*d", 3, 3, 3) // wrong # percents, with a *
printf("now is the time", "buddy") // no %s
Printf("now is the time", "buddy") // no %s Printf("now is the time", "buddy") // no %s
f := new(File) f := new(File)
f.Warn(0, "%s", "hello", 3) // % in call to added function f.Warn(0, "%s", "hello", 3) // % in call to added function
f.Warnf(0, "%s", "hello", 3) // wrong # %s in call to added function f.Warnf(0, "%s", "hello", 3) // wrong # %s in call to added function
} }
// printf is used by the test.
func printf(format string, args ...interface{}) {
panic("don't call - testing only")
}
This diff is collapsed.
...@@ -90,7 +90,7 @@ prog: ...@@ -90,7 +90,7 @@ prog:
$2.node = $3; $2.node = $3;
$2.node.dim[0] = 1; $2.node.dim[0] = 1;
if f != 0 { if f != 0 {
Error("redefinition of %v", $2.name); Errorf("redefinition of %v", $2.name);
} else } else
if vflag { if vflag {
fmt.Printf("%v\t%v\n", $2.name, &$2.node); fmt.Printf("%v\t%v\n", $2.name, &$2.node);
...@@ -106,7 +106,7 @@ prog: ...@@ -106,7 +106,7 @@ prog:
} }
} }
if i >= Ndim { if i >= Ndim {
Error("too many dimensions"); Errorf("too many dimensions");
i = Ndim-1; i = Ndim-1;
} }
fund[i] = $2; fund[i] = $2;
...@@ -116,7 +116,7 @@ prog: ...@@ -116,7 +116,7 @@ prog:
$2.node.dim[0] = 1; $2.node.dim[0] = 1;
$2.node.dim[i] = 1; $2.node.dim[i] = 1;
if f != 0 { if f != 0 {
Error("redefinition of %v", $2.name); Errorf("redefinition of %v", $2.name);
} else } else
if vflag { if vflag {
fmt.Printf("%v\t#\n", $2.name); fmt.Printf("%v\t#\n", $2.name);
...@@ -175,7 +175,7 @@ expr2: ...@@ -175,7 +175,7 @@ expr2:
for i=1; i<Ndim; i++ { for i=1; i<Ndim; i++ {
if $3.dim[i] != 0 { if $3.dim[i] != 0 {
Error("exponent has units"); Errorf("exponent has units");
$$ = $1; $$ = $1;
break; break;
} }
...@@ -183,7 +183,7 @@ expr2: ...@@ -183,7 +183,7 @@ expr2:
if i >= Ndim { if i >= Ndim {
i = int($3.vval); i = int($3.vval);
if float64(i) != $3.vval { if float64(i) != $3.vval {
Error("exponent not integral"); Errorf("exponent not integral");
} }
xpn(&$$, &$1, i); xpn(&$$, &$1, i);
} }
...@@ -200,7 +200,7 @@ expr0: ...@@ -200,7 +200,7 @@ expr0:
VAR VAR
{ {
if $1.node.dim[0] == 0 { if $1.node.dim[0] == 0 {
Error("undefined %v", $1.name); Errorf("undefined %v", $1.name);
$$ = one; $$ = one;
} else } else
$$ = $1.node; $$ = $1.node;
...@@ -284,7 +284,7 @@ numb: ...@@ -284,7 +284,7 @@ numb:
} }
func (UnitsLex) Error(s string) { func (UnitsLex) Error(s string) {
Error("syntax error, last name: %v", sym) Errorf("syntax error, last name: %v", sym)
} }
func main() { func main() {
...@@ -391,7 +391,7 @@ func rdigit(c int) bool { ...@@ -391,7 +391,7 @@ func rdigit(c int) bool {
return false return false
} }
func Error(s string, v ...interface{}) { func Errorf(s string, v ...interface{}) {
fmt.Printf("%v: %v\n\t", lineno, line) fmt.Printf("%v: %v\n\t", lineno, line)
fmt.Printf(s, v...) fmt.Printf(s, v...)
fmt.Printf("\n") fmt.Printf("\n")
...@@ -411,7 +411,7 @@ func add(c, a, b *Node) { ...@@ -411,7 +411,7 @@ func add(c, a, b *Node) {
d = a.dim[i] d = a.dim[i]
c.dim[i] = d c.dim[i] = d
if d != b.dim[i] { if d != b.dim[i] {
Error("add must be like units") Errorf("add must be like units")
} }
} }
c.vval = fadd(a.vval, b.vval) c.vval = fadd(a.vval, b.vval)
...@@ -425,7 +425,7 @@ func sub(c, a, b *Node) { ...@@ -425,7 +425,7 @@ func sub(c, a, b *Node) {
d = a.dim[i] d = a.dim[i]
c.dim[i] = d c.dim[i] = d
if d != b.dim[i] { if d != b.dim[i] {
Error("sub must be like units") Errorf("sub must be like units")
} }
} }
c.vval = fadd(a.vval, -b.vval) c.vval = fadd(a.vval, -b.vval)
...@@ -711,11 +711,11 @@ func fmul(a, b float64) float64 { ...@@ -711,11 +711,11 @@ func fmul(a, b float64) float64 {
} }
if l > Maxe { if l > Maxe {
Error("overflow in multiply") Errorf("overflow in multiply")
return 1 return 1
} }
if l < -Maxe { if l < -Maxe {
Error("underflow in multiply") Errorf("underflow in multiply")
return 0 return 0
} }
return a * b return a * b
...@@ -728,7 +728,7 @@ func fdiv(a, b float64) float64 { ...@@ -728,7 +728,7 @@ func fdiv(a, b float64) float64 {
if b <= 0 { if b <= 0 {
if b == 0 { if b == 0 {
Error("division by zero: %v %v", a, b) Errorf("division by zero: %v %v", a, b)
return 1 return 1
} }
l = math.Log(-b) l = math.Log(-b)
...@@ -746,11 +746,11 @@ func fdiv(a, b float64) float64 { ...@@ -746,11 +746,11 @@ func fdiv(a, b float64) float64 {
} }
if l < -Maxe { if l < -Maxe {
Error("overflow in divide") Errorf("overflow in divide")
return 1 return 1
} }
if l > Maxe { if l > Maxe {
Error("underflow in divide") Errorf("underflow in divide")
return 0 return 0
} }
return a / b return a / b
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment