mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
4c60569e7c
commit
bb855f985a
8 changed files with 141 additions and 131 deletions
|
|
@ -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:
|
||||||
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:
|
||||||
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 {
|
||||||
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 {
|
||||||
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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
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 {
|
||||||
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{}) {
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
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 {
|
||||||
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 {
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
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() {
|
||||||
|
|
||||||
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() {
|
||||||
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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
|
|
||||||
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 (
|
||||||
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) {
|
||||||
|
|
||||||
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 {
|
||||||
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() {
|
||||||
}
|
}
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
||||||
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")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,7 @@ outer:
|
||||||
for {
|
for {
|
||||||
switch t {
|
switch t {
|
||||||
default:
|
default:
|
||||||
error("syntax error tok=%v", t-PRIVATE)
|
errorf("syntax error tok=%v", t-PRIVATE)
|
||||||
|
|
||||||
case MARK, ENDFILE:
|
case MARK, ENDFILE:
|
||||||
break outer
|
break outer
|
||||||
|
|
@ -392,14 +392,14 @@ outer:
|
||||||
case START:
|
case START:
|
||||||
t = gettok()
|
t = gettok()
|
||||||
if t != IDENTIFIER {
|
if t != IDENTIFIER {
|
||||||
error("bad %%start construction")
|
errorf("bad %%start construction")
|
||||||
}
|
}
|
||||||
start = chfind(1, tokname)
|
start = chfind(1, tokname)
|
||||||
|
|
||||||
case TYPEDEF:
|
case TYPEDEF:
|
||||||
t = gettok()
|
t = gettok()
|
||||||
if t != TYPENAME {
|
if t != TYPENAME {
|
||||||
error("bad syntax in %%type")
|
errorf("bad syntax in %%type")
|
||||||
}
|
}
|
||||||
ty = numbval
|
ty = numbval
|
||||||
for {
|
for {
|
||||||
|
|
@ -410,7 +410,7 @@ outer:
|
||||||
if t < NTBASE {
|
if t < NTBASE {
|
||||||
j = TYPE(toklev[t])
|
j = TYPE(toklev[t])
|
||||||
if j != 0 && j != ty {
|
if j != 0 && j != ty {
|
||||||
error("type redeclaration of token ",
|
errorf("type redeclaration of token ",
|
||||||
tokset[t].name)
|
tokset[t].name)
|
||||||
} else {
|
} else {
|
||||||
toklev[t] = SETTYPE(toklev[t], ty)
|
toklev[t] = SETTYPE(toklev[t], ty)
|
||||||
|
|
@ -418,7 +418,7 @@ outer:
|
||||||
} else {
|
} else {
|
||||||
j = nontrst[t-NTBASE].value
|
j = nontrst[t-NTBASE].value
|
||||||
if j != 0 && j != ty {
|
if j != 0 && j != ty {
|
||||||
error("type redeclaration of nonterminal %v",
|
errorf("type redeclaration of nonterminal %v",
|
||||||
nontrst[t-NTBASE].name)
|
nontrst[t-NTBASE].name)
|
||||||
} else {
|
} else {
|
||||||
nontrst[t-NTBASE].value = ty
|
nontrst[t-NTBASE].value = ty
|
||||||
|
|
@ -464,18 +464,18 @@ outer:
|
||||||
case IDENTIFIER:
|
case IDENTIFIER:
|
||||||
j = chfind(0, tokname)
|
j = chfind(0, tokname)
|
||||||
if j >= NTBASE {
|
if j >= NTBASE {
|
||||||
error("%v defined earlier as nonterminal", tokname)
|
errorf("%v defined earlier as nonterminal", tokname)
|
||||||
}
|
}
|
||||||
if lev != 0 {
|
if lev != 0 {
|
||||||
if ASSOC(toklev[j]) != 0 {
|
if ASSOC(toklev[j]) != 0 {
|
||||||
error("redeclaration of precedence of %v", tokname)
|
errorf("redeclaration of precedence of %v", tokname)
|
||||||
}
|
}
|
||||||
toklev[j] = SETASC(toklev[j], lev)
|
toklev[j] = SETASC(toklev[j], lev)
|
||||||
toklev[j] = SETPLEV(toklev[j], i)
|
toklev[j] = SETPLEV(toklev[j], i)
|
||||||
}
|
}
|
||||||
if ty != 0 {
|
if ty != 0 {
|
||||||
if TYPE(toklev[j]) != 0 {
|
if TYPE(toklev[j]) != 0 {
|
||||||
error("redeclaration of type of %v", tokname)
|
errorf("redeclaration of type of %v", tokname)
|
||||||
}
|
}
|
||||||
toklev[j] = SETTYPE(toklev[j], ty)
|
toklev[j] = SETTYPE(toklev[j], ty)
|
||||||
}
|
}
|
||||||
|
|
@ -498,7 +498,7 @@ outer:
|
||||||
}
|
}
|
||||||
|
|
||||||
if t == ENDFILE {
|
if t == ENDFILE {
|
||||||
error("unexpected EOF before %%")
|
errorf("unexpected EOF before %%")
|
||||||
}
|
}
|
||||||
|
|
||||||
// put out non-literal terminals
|
// put out non-literal terminals
|
||||||
|
|
@ -533,7 +533,7 @@ outer:
|
||||||
curprod := make([]int, RULEINC)
|
curprod := make([]int, RULEINC)
|
||||||
t = gettok()
|
t = gettok()
|
||||||
if t != IDENTCOLON {
|
if t != IDENTCOLON {
|
||||||
error("bad syntax on first rule")
|
errorf("bad syntax on first rule")
|
||||||
}
|
}
|
||||||
|
|
||||||
if start == 0 {
|
if start == 0 {
|
||||||
|
|
@ -557,11 +557,11 @@ outer:
|
||||||
} else if t == IDENTCOLON {
|
} else if t == IDENTCOLON {
|
||||||
curprod[mem] = chfind(1, tokname)
|
curprod[mem] = chfind(1, tokname)
|
||||||
if curprod[mem] < NTBASE {
|
if curprod[mem] < NTBASE {
|
||||||
error("token illegal on LHS of grammar rule")
|
errorf("token illegal on LHS of grammar rule")
|
||||||
}
|
}
|
||||||
mem++
|
mem++
|
||||||
} else {
|
} else {
|
||||||
error("illegal rule: missing semicolon or | ?")
|
errorf("illegal rule: missing semicolon or | ?")
|
||||||
}
|
}
|
||||||
|
|
||||||
// read rule body
|
// read rule body
|
||||||
|
|
@ -582,11 +582,11 @@ outer:
|
||||||
}
|
}
|
||||||
if t == PREC {
|
if t == PREC {
|
||||||
if gettok() != IDENTIFIER {
|
if gettok() != IDENTIFIER {
|
||||||
error("illegal %%prec syntax")
|
errorf("illegal %%prec syntax")
|
||||||
}
|
}
|
||||||
j = chfind(2, tokname)
|
j = chfind(2, tokname)
|
||||||
if j >= NTBASE {
|
if j >= NTBASE {
|
||||||
error("nonterminal " + nontrst[j-NTBASE].name + " illegal after %%prec")
|
errorf("nonterminal " + nontrst[j-NTBASE].name + " illegal after %%prec")
|
||||||
}
|
}
|
||||||
levprd[nprod] = toklev[j]
|
levprd[nprod] = toklev[j]
|
||||||
t = gettok()
|
t = gettok()
|
||||||
|
|
@ -642,7 +642,7 @@ outer:
|
||||||
// no explicit action, LHS has value
|
// no explicit action, LHS has value
|
||||||
tempty := curprod[1]
|
tempty := curprod[1]
|
||||||
if tempty < 0 {
|
if tempty < 0 {
|
||||||
error("must return a value, since LHS has a type")
|
errorf("must return a value, since LHS has a type")
|
||||||
}
|
}
|
||||||
if tempty >= NTBASE {
|
if tempty >= NTBASE {
|
||||||
tempty = nontrst[tempty-NTBASE].value
|
tempty = nontrst[tempty-NTBASE].value
|
||||||
|
|
@ -650,7 +650,7 @@ outer:
|
||||||
tempty = TYPE(toklev[tempty])
|
tempty = TYPE(toklev[tempty])
|
||||||
}
|
}
|
||||||
if tempty != nontrst[curprod[0]-NTBASE].value {
|
if tempty != nontrst[curprod[0]-NTBASE].value {
|
||||||
error("default action causes potential type clash")
|
errorf("default action causes potential type clash")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(fcode, "\ncase %v:", nprod)
|
fmt.Fprintf(fcode, "\ncase %v:", nprod)
|
||||||
fmt.Fprintf(fcode, "\n\t%sVAL.%v = %sS[%spt-0].%v;",
|
fmt.Fprintf(fcode, "\n\t%sVAL.%v = %sS[%spt-0].%v;",
|
||||||
|
|
@ -773,7 +773,7 @@ func defin(nt int, s string) int {
|
||||||
case 'v':
|
case 'v':
|
||||||
val = '\v'
|
val = '\v'
|
||||||
default:
|
default:
|
||||||
error("invalid escape %v", s[1:3])
|
errorf("invalid escape %v", s[1:3])
|
||||||
}
|
}
|
||||||
} else if s[2] == 'u' && len(s) == 2+1+4 { // \unnnn sequence
|
} else if s[2] == 'u' && len(s) == 2+1+4 { // \unnnn sequence
|
||||||
val = 0
|
val = 0
|
||||||
|
|
@ -788,16 +788,16 @@ func defin(nt int, s string) int {
|
||||||
case c >= 'A' && c <= 'F':
|
case c >= 'A' && c <= 'F':
|
||||||
c -= 'A' - 10
|
c -= 'A' - 10
|
||||||
default:
|
default:
|
||||||
error("illegal \\unnnn construction")
|
errorf("illegal \\unnnn construction")
|
||||||
}
|
}
|
||||||
val = val*16 + c
|
val = val*16 + c
|
||||||
s = s[1:]
|
s = s[1:]
|
||||||
}
|
}
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
error("'\\u0000' is illegal")
|
errorf("'\\u0000' is illegal")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error("unknown escape")
|
errorf("unknown escape")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val = extval
|
val = extval
|
||||||
|
|
@ -855,7 +855,7 @@ func gettok() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c != '>' {
|
if c != '>' {
|
||||||
error("unterminated < ... > clause")
|
errorf("unterminated < ... > clause")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 1; i <= ntypes; i++ {
|
for i = 1; i <= ntypes; i++ {
|
||||||
|
|
@ -881,7 +881,7 @@ func gettok() int {
|
||||||
for {
|
for {
|
||||||
c = getrune(finput)
|
c = getrune(finput)
|
||||||
if c == '\n' || c == EOF {
|
if c == '\n' || c == EOF {
|
||||||
error("illegal or missing ' or \"")
|
errorf("illegal or missing ' or \"")
|
||||||
}
|
}
|
||||||
if c == '\\' {
|
if c == '\\' {
|
||||||
tokname += string('\\')
|
tokname += string('\\')
|
||||||
|
|
@ -926,7 +926,7 @@ func gettok() int {
|
||||||
return resrv[c].value
|
return resrv[c].value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error("invalid escape, or illegal reserved word: %v", tokname)
|
errorf("invalid escape, or illegal reserved word: %v", tokname)
|
||||||
|
|
||||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||||
numbval = c - '0'
|
numbval = c - '0'
|
||||||
|
|
@ -1004,7 +1004,7 @@ func fdtype(t int) int {
|
||||||
s = tokset[t].name
|
s = tokset[t].name
|
||||||
}
|
}
|
||||||
if v <= 0 {
|
if v <= 0 {
|
||||||
error("must specify type for %v", s)
|
errorf("must specify type for %v", s)
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
@ -1026,7 +1026,7 @@ func chfind(t int, s string) int {
|
||||||
|
|
||||||
// cannot find name
|
// cannot find name
|
||||||
if t > 1 {
|
if t > 1 {
|
||||||
error("%v should have been defined earlier", s)
|
errorf("%v should have been defined earlier", s)
|
||||||
}
|
}
|
||||||
return defin(t, s)
|
return defin(t, s)
|
||||||
}
|
}
|
||||||
|
|
@ -1047,7 +1047,7 @@ out:
|
||||||
for {
|
for {
|
||||||
c := getrune(finput)
|
c := getrune(finput)
|
||||||
if c == EOF {
|
if c == EOF {
|
||||||
error("EOF encountered while processing %%union")
|
errorf("EOF encountered while processing %%union")
|
||||||
}
|
}
|
||||||
ftable.WriteRune(c)
|
ftable.WriteRune(c)
|
||||||
switch c {
|
switch c {
|
||||||
|
|
@ -1097,7 +1097,7 @@ func cpycode() {
|
||||||
c = getrune(finput)
|
c = getrune(finput)
|
||||||
}
|
}
|
||||||
lineno = lno
|
lineno = lno
|
||||||
error("eof before %%}")
|
errorf("eof before %%}")
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -1115,11 +1115,11 @@ func skipcom() int {
|
||||||
}
|
}
|
||||||
c = getrune(finput)
|
c = getrune(finput)
|
||||||
}
|
}
|
||||||
error("EOF inside comment")
|
errorf("EOF inside comment")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if c != '*' {
|
if c != '*' {
|
||||||
error("illegal comment")
|
errorf("illegal comment")
|
||||||
}
|
}
|
||||||
|
|
||||||
nl := 0 // lines skipped
|
nl := 0 // lines skipped
|
||||||
|
|
@ -1196,7 +1196,7 @@ loop:
|
||||||
if c == '<' {
|
if c == '<' {
|
||||||
ungetrune(finput, c)
|
ungetrune(finput, c)
|
||||||
if gettok() != TYPENAME {
|
if gettok() != TYPENAME {
|
||||||
error("bad syntax on $<ident> clause")
|
errorf("bad syntax on $<ident> clause")
|
||||||
}
|
}
|
||||||
tok = numbval
|
tok = numbval
|
||||||
c = getrune(finput)
|
c = getrune(finput)
|
||||||
|
|
@ -1226,13 +1226,13 @@ loop:
|
||||||
ungetrune(finput, c)
|
ungetrune(finput, c)
|
||||||
j = j * s
|
j = j * s
|
||||||
if j >= max {
|
if j >= max {
|
||||||
error("Illegal use of $%v", j)
|
errorf("Illegal use of $%v", j)
|
||||||
}
|
}
|
||||||
} else if isword(c) || c == '_' || c == '.' {
|
} else if isword(c) || c == '_' || c == '.' {
|
||||||
// look for $name
|
// look for $name
|
||||||
ungetrune(finput, c)
|
ungetrune(finput, c)
|
||||||
if gettok() != IDENTIFIER {
|
if gettok() != IDENTIFIER {
|
||||||
error("$ must be followed by an identifier")
|
errorf("$ must be followed by an identifier")
|
||||||
}
|
}
|
||||||
tokn := chfind(2, tokname)
|
tokn := chfind(2, tokname)
|
||||||
fnd := -1
|
fnd := -1
|
||||||
|
|
@ -1240,7 +1240,7 @@ loop:
|
||||||
if c != '@' {
|
if c != '@' {
|
||||||
ungetrune(finput, c)
|
ungetrune(finput, c)
|
||||||
} else if gettok() != NUMBER {
|
} else if gettok() != NUMBER {
|
||||||
error("@ must be followed by number")
|
errorf("@ must be followed by number")
|
||||||
} else {
|
} else {
|
||||||
fnd = numbval
|
fnd = numbval
|
||||||
}
|
}
|
||||||
|
|
@ -1253,7 +1253,7 @@ loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if j >= max {
|
if j >= max {
|
||||||
error("$name or $name@number not found")
|
errorf("$name or $name@number not found")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fcode.WriteRune('$')
|
fcode.WriteRune('$')
|
||||||
|
|
@ -1268,7 +1268,7 @@ loop:
|
||||||
// put out the proper tag
|
// put out the proper tag
|
||||||
if ntypes != 0 {
|
if ntypes != 0 {
|
||||||
if j <= 0 && tok < 0 {
|
if j <= 0 && tok < 0 {
|
||||||
error("must specify type of $%v", j)
|
errorf("must specify type of $%v", j)
|
||||||
}
|
}
|
||||||
if tok < 0 {
|
if tok < 0 {
|
||||||
tok = fdtype(curprod[j])
|
tok = fdtype(curprod[j])
|
||||||
|
|
@ -1315,7 +1315,7 @@ loop:
|
||||||
fcode.WriteRune(c)
|
fcode.WriteRune(c)
|
||||||
c = getrune(finput)
|
c = getrune(finput)
|
||||||
}
|
}
|
||||||
error("EOF inside comment")
|
errorf("EOF inside comment")
|
||||||
|
|
||||||
case '\'', '"':
|
case '\'', '"':
|
||||||
// character string or constant
|
// character string or constant
|
||||||
|
|
@ -1333,16 +1333,16 @@ loop:
|
||||||
break swt
|
break swt
|
||||||
}
|
}
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
error("newline in string or char const")
|
errorf("newline in string or char const")
|
||||||
}
|
}
|
||||||
fcode.WriteRune(c)
|
fcode.WriteRune(c)
|
||||||
c = getrune(finput)
|
c = getrune(finput)
|
||||||
}
|
}
|
||||||
error("EOF in string or character constant")
|
errorf("EOF in string or character constant")
|
||||||
|
|
||||||
case EOF:
|
case EOF:
|
||||||
lineno = lno
|
lineno = lno
|
||||||
error("action does not terminate")
|
errorf("action does not terminate")
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
lineno++
|
lineno++
|
||||||
|
|
@ -1356,14 +1356,14 @@ func openup() {
|
||||||
infile = flag.Arg(0)
|
infile = flag.Arg(0)
|
||||||
finput = open(infile)
|
finput = open(infile)
|
||||||
if finput == nil {
|
if finput == nil {
|
||||||
error("cannot open %v", infile)
|
errorf("cannot open %v", infile)
|
||||||
}
|
}
|
||||||
|
|
||||||
foutput = nil
|
foutput = nil
|
||||||
if vflag != "" {
|
if vflag != "" {
|
||||||
foutput = create(vflag)
|
foutput = create(vflag)
|
||||||
if foutput == nil {
|
if foutput == nil {
|
||||||
error("can't create file %v", vflag)
|
errorf("can't create file %v", vflag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1373,7 +1373,7 @@ func openup() {
|
||||||
}
|
}
|
||||||
ftable = create(oflag)
|
ftable = create(oflag)
|
||||||
if ftable == nil {
|
if ftable == nil {
|
||||||
error("can't create file %v", oflag)
|
errorf("can't create file %v", oflag)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1433,7 +1433,7 @@ func cpres() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
error("nonterminal %v not defined", nontrst[i].name)
|
errorf("nonterminal %v not defined", nontrst[i].name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pres[i] = make([][]int, n)
|
pres[i] = make([][]int, n)
|
||||||
|
|
@ -1506,7 +1506,7 @@ more:
|
||||||
}
|
}
|
||||||
if pempty[i] != OK {
|
if pempty[i] != OK {
|
||||||
fatfl = 0
|
fatfl = 0
|
||||||
error("nonterminal " + nontrst[i].name + " never derives any token string")
|
errorf("nonterminal " + nontrst[i].name + " never derives any token string")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1921,11 +1921,11 @@ look:
|
||||||
// state is new
|
// state is new
|
||||||
zznewstate++
|
zznewstate++
|
||||||
if nolook != 0 {
|
if nolook != 0 {
|
||||||
error("yacc state/nolook error")
|
errorf("yacc state/nolook error")
|
||||||
}
|
}
|
||||||
pstate[nstate+2] = p2
|
pstate[nstate+2] = p2
|
||||||
if nstate+1 >= NSTATES {
|
if nstate+1 >= NSTATES {
|
||||||
error("too many states")
|
errorf("too many states")
|
||||||
}
|
}
|
||||||
if c >= NTBASE {
|
if c >= NTBASE {
|
||||||
mstates[nstate] = ntstates[c-NTBASE]
|
mstates[nstate] = ntstates[c-NTBASE]
|
||||||
|
|
@ -2061,7 +2061,7 @@ nextk:
|
||||||
}
|
}
|
||||||
return off + rr
|
return off + rr
|
||||||
}
|
}
|
||||||
error("no space in action table")
|
errorf("no space in action table")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2623,7 +2623,7 @@ nextgp:
|
||||||
if s > maxa {
|
if s > maxa {
|
||||||
maxa = s
|
maxa = s
|
||||||
if maxa >= ACTSIZE {
|
if maxa >= ACTSIZE {
|
||||||
error("a array overflow")
|
errorf("a array overflow")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if amem[s] != 0 {
|
if amem[s] != 0 {
|
||||||
|
|
@ -2646,7 +2646,7 @@ nextgp:
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
error("cannot place goto %v\n", i)
|
errorf("cannot place goto %v\n", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stin(i int) {
|
func stin(i int) {
|
||||||
|
|
@ -2705,7 +2705,7 @@ nextn:
|
||||||
maxa = s
|
maxa = s
|
||||||
}
|
}
|
||||||
if amem[s] != 0 && amem[s] != q[r+1] {
|
if amem[s] != 0 && amem[s] != q[r+1] {
|
||||||
error("clobber of a array, pos'n %v, by %v", s, q[r+1])
|
errorf("clobber of a array, pos'n %v, by %v", s, q[r+1])
|
||||||
}
|
}
|
||||||
amem[s] = q[r+1]
|
amem[s] = q[r+1]
|
||||||
}
|
}
|
||||||
|
|
@ -2715,7 +2715,7 @@ nextn:
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
error("Error; failure to place state %v", i)
|
errorf("Error; failure to place state %v", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -3014,7 +3014,7 @@ func getrune(f *bufio.Reader) int {
|
||||||
return EOF
|
return EOF
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error("read error: %v", err)
|
errorf("read error: %v", err)
|
||||||
}
|
}
|
||||||
//fmt.Printf("rune = %v n=%v\n", string(c), n);
|
//fmt.Printf("rune = %v n=%v\n", string(c), n);
|
||||||
return c
|
return c
|
||||||
|
|
@ -3038,7 +3038,7 @@ func write(f *bufio.Writer, b []byte, n int) int {
|
||||||
func open(s string) *bufio.Reader {
|
func open(s string) *bufio.Reader {
|
||||||
fi, err := os.Open(s)
|
fi, err := os.Open(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error("error opening %v: %v", s, err)
|
errorf("error opening %v: %v", s, err)
|
||||||
}
|
}
|
||||||
//fmt.Printf("open %v\n", s);
|
//fmt.Printf("open %v\n", s);
|
||||||
return bufio.NewReader(fi)
|
return bufio.NewReader(fi)
|
||||||
|
|
@ -3047,7 +3047,7 @@ func open(s string) *bufio.Reader {
|
||||||
func create(s string) *bufio.Writer {
|
func create(s string) *bufio.Writer {
|
||||||
fo, err := os.Create(s)
|
fo, err := os.Create(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error("error creating %v: %v", s, err)
|
errorf("error creating %v: %v", s, err)
|
||||||
}
|
}
|
||||||
//fmt.Printf("create %v mode %v\n", s);
|
//fmt.Printf("create %v mode %v\n", s);
|
||||||
return bufio.NewWriter(fo)
|
return bufio.NewWriter(fo)
|
||||||
|
|
@ -3056,7 +3056,7 @@ func create(s string) *bufio.Writer {
|
||||||
//
|
//
|
||||||
// write out error comment
|
// write out error comment
|
||||||
//
|
//
|
||||||
func error(s string, v ...interface{}) {
|
func errorf(s string, v ...interface{}) {
|
||||||
nerrors++
|
nerrors++
|
||||||
fmt.Fprintf(stderr, s, v...)
|
fmt.Fprintf(stderr, s, v...)
|
||||||
fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno)
|
fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno)
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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:
|
||||||
$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:
|
||||||
|
|
||||||
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:
|
||||||
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:
|
||||||
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:
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
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) {
|
||||||
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) {
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue