cmd/internal/obj: update callers to Linkline{fmt,hist} and remove

Does the TODOs added by https://golang.org/cl/7623.

Passes rsc.io/toolstash/buildall.

Change-Id: I23913a8f03834640e9795d48318febb3f88c10f9
Reviewed-on: https://go-review.googlesource.com/9160
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Matthew Dempsky 2015-04-20 13:32:40 -07:00
parent 82e1651a24
commit 1467776b17
10 changed files with 44 additions and 76 deletions

View file

@ -13,7 +13,6 @@ import (
"text/scanner" "text/scanner"
"cmd/asm/internal/flags" "cmd/asm/internal/flags"
"cmd/internal/obj"
) )
// Input is the main input: a stack of readers and some macro definitions. // Input is the main input: a stack of readers and some macro definitions.
@ -436,7 +435,7 @@ func (in *Input) line() {
if tok != '\n' { if tok != '\n' {
in.Error("unexpected token at end of #line: ", tok) in.Error("unexpected token at end of #line: ", tok)
} }
obj.Linklinehist(linkCtxt, histLine, file, line) linkCtxt.LineHist.Update(histLine, file, line)
in.Stack.SetPos(line, file) in.Stack.SetPos(line, file)
} }

View file

@ -10,8 +10,6 @@ import (
"strings" "strings"
"text/scanner" "text/scanner"
"unicode" "unicode"
"cmd/internal/obj"
) )
// A Tokenizer is a simple wrapping of text/scanner.Scanner, configured // A Tokenizer is a simple wrapping of text/scanner.Scanner, configured
@ -40,7 +38,7 @@ func NewTokenizer(name string, r io.Reader, file *os.File) *Tokenizer {
s.Position.Filename = name s.Position.Filename = name
s.IsIdentRune = isIdentRune s.IsIdentRune = isIdentRune
if file != nil { if file != nil {
obj.Linklinehist(linkCtxt, histLine, name, 0) linkCtxt.LineHist.Push(histLine, name)
} }
return &Tokenizer{ return &Tokenizer{
s: &s, s: &s,
@ -149,6 +147,6 @@ func (t *Tokenizer) Close() {
if t.file != nil { if t.file != nil {
t.file.Close() t.file.Close()
// It's an open file, so pop the line history. // It's an open file, so pop the line history.
obj.Linklinehist(linkCtxt, histLine, "<pop>", 0) linkCtxt.LineHist.Pop(histLine)
} }
} }

View file

@ -149,7 +149,7 @@ func newfile(s string, f *os.File) {
} }
fi.P = nil fi.P = nil
obj.Linklinehist(Ctxt, int(Lineno), s, 0) Ctxt.LineHist.Push(int(Lineno), s)
} }
var thetext *obj.LSym var thetext *obj.LSym
@ -630,7 +630,7 @@ loop:
n, _ = i.F.Read(i.B[:]) n, _ = i.F.Read(i.B[:])
if n == 0 { if n == 0 {
i.F.Close() i.F.Close()
obj.Linklinehist(Ctxt, int(Lineno), "<pop>", 0) Ctxt.LineHist.Pop(int(Lineno))
goto pop goto pop
} }
fi.P = i.B[1:n] fi.P = i.B[1:n]

View file

@ -32,7 +32,6 @@ package asm
import ( import (
"bytes" "bytes"
"cmd/internal/obj"
"fmt" "fmt"
"os" "os"
"strings" "strings"
@ -683,7 +682,7 @@ func maclin() {
} }
nn: nn:
obj.Linklinehist(Ctxt, int(Lineno), symb, int(n)) Ctxt.LineHist.Update(int(Lineno), symb, int(n))
return return
bad: bad:
@ -796,7 +795,7 @@ func macprag() {
/* /*
* put pragma-line in as a funny history * put pragma-line in as a funny history
*/ */
obj.Linklinehist(Ctxt, int(Lineno), symb, -1) Ctxt.AddImport(symb)
return return
} }
if s != nil && s.Name == "pack" { if s != nil && s.Name == "pack" {

View file

@ -313,7 +313,7 @@ func Main() {
lexlineno = 1 lexlineno = 1
for _, infile = range flag.Args() { for _, infile = range flag.Args() {
linehist(infile, 0, 0) linehistpush(infile)
curio.infile = infile curio.infile = infile
var err error var err error
@ -344,7 +344,7 @@ func Main() {
errorexit() errorexit()
} }
linehist("<pop>", 0, 0) linehistpop()
if curio.bin != nil { if curio.bin != nil {
obj.Bterm(curio.bin) obj.Bterm(curio.bin)
} }
@ -763,7 +763,7 @@ func importfile(f *Val, line int) {
// assume files move (get installed) // assume files move (get installed)
// so don't record the full path. // so don't record the full path.
linehist(file[len(file)-len(path_)-2:], -1, 1) // acts as #pragma lib linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
/* /*
* position the input right * position the input right
@ -1654,7 +1654,7 @@ func getlinepragma() int {
} }
name = text[:linep-1] name = text[:linep-1]
linehist(name, int32(n), 0) linehistupdate(name, n)
return c return c
out: out:

View file

@ -199,26 +199,32 @@ func Fatal(fmt_ string, args ...interface{}) {
errorexit() errorexit()
} }
func linehist(file string, off int32, relative int) { func linehistpragma(file string) {
if Debug['i'] != 0 { if Debug['i'] != 0 {
if file != "" { fmt.Printf("pragma %s at line %v\n", file, Ctxt.Line(int(lexlineno)))
if off < 0 {
fmt.Printf("pragma %s", file)
} else if off > 0 {
fmt.Printf("line %s", file)
} else {
fmt.Printf("import %s", file)
}
} else {
fmt.Printf("end of import")
}
fmt.Printf(" at line %v\n", Ctxt.Line(int(lexlineno)))
} }
Ctxt.AddImport(file)
}
if off < 0 && file[0] != '/' && relative == 0 { func linehistpush(file string) {
file = fmt.Sprintf("%s/%s", Ctxt.Pathname, file) if Debug['i'] != 0 {
fmt.Printf("import %s at line %v\n", file, Ctxt.Line(int(lexlineno)))
} }
obj.Linklinehist(Ctxt, int(lexlineno), file, int(off)) Ctxt.LineHist.Push(int(lexlineno), file)
}
func linehistpop() {
if Debug['i'] != 0 {
fmt.Printf("end of import at line %v\n", Ctxt.Line(int(lexlineno)))
}
Ctxt.LineHist.Pop(int(lexlineno))
}
func linehistupdate(file string, off int) {
if Debug['i'] != 0 {
fmt.Printf("line %s at line %v\n", file, Ctxt.Line(int(lexlineno)))
}
Ctxt.LineHist.Update(int(lexlineno), file, off)
} }
func setlineno(n *Node) int32 { func setlineno(n *Node) int32 {
@ -2345,7 +2351,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
lineno = lexlineno lineno = lexlineno
if genwrapper_linehistdone == 0 { if genwrapper_linehistdone == 0 {
// All the wrappers can share the same linehist entry. // All the wrappers can share the same linehist entry.
linehist("<autogenerated>", 0, 0) linehistpush("<autogenerated>")
genwrapper_linehistdone = 1 genwrapper_linehistdone = 1
} }

View file

@ -1,7 +1,6 @@
package gc package gc
import ( import (
"cmd/internal/obj"
"os" "os"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
@ -10,7 +9,7 @@ import (
) )
func (n *Node) Line() string { func (n *Node) Line() string {
return obj.Linklinefmt(Ctxt, int(n.Lineno), false, false) return Ctxt.LineHist.LineString(int(n.Lineno))
} }
func atoi(s string) int { func atoi(s string) int {

View file

@ -13,13 +13,13 @@ func TestLineHist(t *testing.T) {
ctxt := new(Link) ctxt := new(Link)
ctxt.Hash = make(map[SymVer]*LSym) ctxt.Hash = make(map[SymVer]*LSym)
Linklinehist(ctxt, 1, "a.c", 0) ctxt.LineHist.Push(1, "a.c")
Linklinehist(ctxt, 3, "a.h", 0) ctxt.LineHist.Push(3, "a.h")
Linklinehist(ctxt, 5, "<pop>", 0) ctxt.LineHist.Pop(5)
Linklinehist(ctxt, 7, "linedir", 2) ctxt.LineHist.Update(7, "linedir", 2)
Linklinehist(ctxt, 9, "<pop>", 0) ctxt.LineHist.Pop(9)
Linklinehist(ctxt, 11, "b.c", 0) ctxt.LineHist.Push(11, "b.c")
Linklinehist(ctxt, 13, "<pop>", 0) ctxt.LineHist.Pop(13)
var expect = []string{ var expect = []string{
0: "??:0", 0: "??:0",

View file

@ -241,12 +241,6 @@ func (h *LineHist) LineString(lineno int) string {
return text return text
} }
// TODO(rsc): Replace call sites with use of ctxt.LineHist.
// Note that all call sites use showAll=false, showFullPath=false.
func Linklinefmt(ctxt *Link, lineno int, showAll, showFullPath bool) string {
return ctxt.LineHist.LineString(lineno)
}
// FileLine returns the file name and line number // FileLine returns the file name and line number
// at the top of the stack for the given lineno. // at the top of the stack for the given lineno.
func (h *LineHist) FileLine(lineno int) (file string, line int) { func (h *LineHist) FileLine(lineno int) (file string, line int) {
@ -287,30 +281,3 @@ func linkgetline(ctxt *Link, lineno int32, f **LSym, l *int32) {
func Linkprfile(ctxt *Link, line int) { func Linkprfile(ctxt *Link, line int) {
fmt.Printf("%s ", ctxt.LineHist.LineString(line)) fmt.Printf("%s ", ctxt.LineHist.LineString(line))
} }
// Linklinehist pushes, amends, or pops an entry on the line history stack.
// If f != "<pop>" and n == 0, the call pushes the start of a new file named f at lineno.
// If f != "<pop>" and n > 0, the call amends the top of the stack to record that lineno
// now corresponds to f at line n.
// If f == "<pop>", the call pops the topmost entry from the stack, picking up
// the parent file at the line following the one where the corresponding push occurred.
//
// If n < 0, linklinehist records f as a package required by the current compilation
// (nothing to do with line numbers).
//
// TODO(rsc): Replace uses with direct calls to ctxt.Hist methods.
func Linklinehist(ctxt *Link, lineno int, f string, n int) {
switch {
case n < 0:
ctxt.AddImport(f)
case f == "<pop>":
ctxt.LineHist.Pop(lineno)
case n == 0:
ctxt.LineHist.Push(lineno, f)
default:
ctxt.LineHist.Update(lineno, f, n)
}
}

View file

@ -241,7 +241,7 @@ func Atoi(s string) int {
} }
func (p *Prog) Line() string { func (p *Prog) Line() string {
return Linklinefmt(p.Ctxt, int(p.Lineno), false, false) return p.Ctxt.LineHist.LineString(int(p.Lineno))
} }
var armCondCode = []string{ var armCondCode = []string{
@ -340,7 +340,7 @@ func (ctxt *Link) NewProg() *Prog {
} }
func (ctxt *Link) Line(n int) string { func (ctxt *Link) Line(n int) string {
return Linklinefmt(ctxt, n, false, false) return ctxt.LineHist.LineString(n)
} }
func Getcallerpc(interface{}) uintptr { func Getcallerpc(interface{}) uintptr {