]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.inline] cmd/internal/obj: remove vestiges of LineHist - not used anymore
authorRobert Griesemer <gri@golang.org>
Thu, 29 Dec 2016 01:58:51 +0000 (17:58 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 9 Jan 2017 22:52:34 +0000 (22:52 +0000)
Change-Id: I9d3fcdd5b002953fa9d2f001bf7a834073443794
Reviewed-on: https://go-review.googlesource.com/34722
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/subr.go
src/cmd/internal/obj/line.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/sym.go

index a1559587692a306aa1c6a41145d3cc00b3bca65e..3ce9994eb1f8914f5f0b3340c00a6d429447ec82 100644 (file)
@@ -778,7 +778,8 @@ func importfile(f *Val, indent []byte) {
        defer impf.Close()
        imp := bufio.NewReader(impf)
 
-       if strings.HasSuffix(file, ".a") {
+       const pkgSuffix = ".a"
+       if strings.HasSuffix(file, pkgSuffix) {
                if !skiptopkgdef(imp) {
                        yyerror("import %s: not a package file", file)
                        errorexit()
@@ -826,9 +827,9 @@ func importfile(f *Val, indent []byte) {
                yyerror("cannot import unsafe package %q", importpkg.Path)
        }
 
-       // assume files move (get installed)
-       // so don't record the full path.
-       linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
+       // assume files move (get installed) so don't record the full path
+       // (e.g., for file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a")
+       Ctxt.AddImport(file[len(file)-len(path_)-len(pkgSuffix):])
 
        // In the importfile, if we find:
        // $$\n  (textual format): not supported anymore
index fdad1169944c8fd1a1615db5e3811151eeb0843a..f067ce86f28fa9fb4ec07258654a164dd1a15404 100644 (file)
@@ -180,14 +180,6 @@ func Fatalf(fmt_ string, args ...interface{}) {
        errorexit()
 }
 
-// TODO(gri) rename this function
-func linehistpragma(file string) {
-       // if Debug['i'] != 0 {
-       //      fmt.Printf("pragma %s at line %v\n", file, linestr(lexlineno))
-       // }
-       Ctxt.AddImport(file)
-}
-
 func setlineno(n *Node) src.XPos {
        lno := lineno
        if n != nil {
index 9e1f8ca6651ec138f67929625dbd557d0b4a7f24..c0a66ba84de71b6111f645b7816902c3c4e672f1 100644 (file)
@@ -6,86 +6,9 @@ package obj
 
 import (
        "cmd/internal/src"
-       "fmt"
        "path/filepath"
-       "sort"
-       "strings"
 )
 
-// LineHists are not used anymore. This code is only here for reference during a transition period.
-// TODO(gri) remove this eventually (we still need the LineHist independent functions, though).
-
-// A LineHist records the history of the file input stack, which maps the virtual line number,
-// an incrementing count of lines processed in any input file and typically named lineno,
-// to a stack of file:line pairs showing the path of inclusions that led to that position.
-// The first line directive (//line in Go, #line in assembly) is treated as pushing
-// a new entry on the stack, so that errors can report both the actual and translated
-// line number.
-//
-// In typical use, the virtual lineno begins at 1, and file line numbers also begin at 1,
-// but the only requirements placed upon the numbers by this code are:
-//     - calls to Push, Update, and Pop must be monotonically increasing in lineno
-//     - except as specified by those methods, virtual and file line number increase
-//       together, so that given (only) calls Push(10, "x.go", 1) and Pop(15),
-//       virtual line 12 corresponds to x.go line 3.
-type LineHist struct {
-       Top               *LineStack  // current top of stack
-       Ranges            []LineRange // ranges for lookup
-       Dir               string      // directory to qualify relative paths
-       TrimPathPrefix    string      // remove leading TrimPath from recorded file names
-       PrintFilenameOnly bool        // ignore path when pretty-printing a line; internal use only
-       GOROOT            string      // current GOROOT
-}
-
-// A LineStack is an entry in the recorded line history.
-// Although the history at any given line number is a stack,
-// the record for all line processed forms a tree, with common
-// stack prefixes acting as parents.
-type LineStack struct {
-       Parent    *LineStack // parent in inclusion stack
-       Lineno    int        // virtual line number where this entry takes effect
-       File      string     // file name used to open source file, for error messages
-       AbsFile   string     // absolute file name, for pcln tables
-       FileLine  int        // line number in file at Lineno
-       Directive bool
-       Sym       *LSym // for linkgetline - TODO(rsc): remove
-}
-
-func (stk *LineStack) fileLineAt(lineno int) int {
-       return stk.FileLine + lineno - stk.Lineno
-}
-
-// The span of valid linenos in the recorded line history can be broken
-// into a set of ranges, each with a particular stack.
-// A LineRange records one such range.
-type LineRange struct {
-       Start int        // starting lineno
-       Stack *LineStack // top of stack for this range
-}
-
-// startRange starts a new range with the given top of stack.
-func (h *LineHist) startRange(lineno int, top *LineStack) {
-       h.Top = top
-       h.Ranges = append(h.Ranges, LineRange{top.Lineno, top})
-}
-
-// setFile sets stk.File = file and also derives stk.AbsFile.
-func (h *LineHist) setFile(stk *LineStack, file string) {
-       // Note: The exclusion of stk.Directive may be wrong but matches what we've done before.
-       // The check for < avoids putting a path prefix on "<autogenerated>".
-       dir := h.Dir
-       if stk.Directive || strings.HasPrefix(file, "<") {
-               dir = ""
-       }
-
-       stk.AbsFile = AbsFile(dir, file, h.TrimPathPrefix)
-
-       if file == "" {
-               file = "??"
-       }
-       stk.File = file
-}
-
 // AbsFile returns the absolute filename for file in the given directory.
 // It also removes a leading pathPrefix, or else rewrites a leading $GOROOT
 // prefix to the literal "$GOROOT".
@@ -146,161 +69,11 @@ func hasPathPrefix(s string, t string) bool {
        return i >= len(s) || s[i] == '/' || s[i] == '\\'
 }
 
-// Push records that at that lineno a new file with the given name was pushed onto the input stack.
-func (h *LineHist) Push(lineno int, file string) {
-       stk := &LineStack{
-               Parent:   h.Top,
-               Lineno:   lineno,
-               FileLine: 1,
-       }
-       h.setFile(stk, file)
-       h.startRange(lineno, stk)
-}
-
-// Pop records that at lineno the current file was popped from the input stack.
-func (h *LineHist) Pop(lineno int) {
-       top := h.Top
-       if top == nil {
-               return
-       }
-       if top.Directive && top.Parent != nil { // pop #line level too
-               top = top.Parent
-       }
-       next := top.Parent
-       if next == nil {
-               h.Top = nil
-               h.Ranges = append(h.Ranges, LineRange{lineno, nil})
-               return
-       }
-
-       // Popping included file. Update parent offset to account for
-       // the virtual line number range taken by the included file.
-       // Cannot modify the LineStack directly, or else lookups
-       // for the earlier line numbers will get the wrong answers,
-       // so make a new one.
-       stk := new(LineStack)
-       *stk = *next
-       stk.Lineno = lineno
-       stk.FileLine = next.fileLineAt(top.Lineno)
-       h.startRange(lineno, stk)
-}
-
-// Update records that at lineno the file name and line number were changed using
-// a line directive (//line in Go, #line in assembly).
-func (h *LineHist) Update(lineno int, file string, line int) {
-       top := h.Top
-       if top == nil {
-               return // shouldn't happen
-       }
-       var stk *LineStack
-       if top.Directive {
-               // Update existing entry, except make copy to avoid changing earlier history.
-               stk = new(LineStack)
-               *stk = *top
-       } else {
-               // Push new entry.
-               stk = &LineStack{
-                       Parent:    top,
-                       Directive: true,
-               }
-       }
-       stk.Lineno = lineno
-       if stk.File != file {
-               h.setFile(stk, file) // only retain string if needed
-       }
-       stk.FileLine = line
-       h.startRange(lineno, stk)
-}
-
 // AddImport adds a package to the list of imported packages.
 func (ctxt *Link) AddImport(pkg string) {
        ctxt.Imports = append(ctxt.Imports, pkg)
 }
 
-// At returns the input stack in effect at lineno.
-func (h *LineHist) At(lineno int) *LineStack {
-       i := sort.Search(len(h.Ranges), func(i int) bool {
-               return h.Ranges[i].Start > lineno
-       })
-       // Found first entry beyond lineno.
-       if i == 0 {
-               return nil
-       }
-       return h.Ranges[i-1].Stack
-}
-
-// LineString returns a string giving the file and line number
-// corresponding to lineno, for use in error messages.
-func (h *LineHist) LineString(lineno int) string {
-       stk := h.At(lineno)
-       if stk == nil {
-               return "<unknown line number>"
-       }
-
-       filename := stk.File
-       if h.PrintFilenameOnly {
-               filename = filepath.Base(filename)
-       }
-       text := fmt.Sprintf("%s:%d", filename, stk.fileLineAt(lineno))
-       if stk.Directive && stk.Parent != nil {
-               stk = stk.Parent
-               filename = stk.File
-               if h.PrintFilenameOnly {
-                       filename = filepath.Base(filename)
-               }
-               text += fmt.Sprintf("[%s:%d]", filename, stk.fileLineAt(lineno))
-       }
-       const showFullStack = false // was used by old C compilers
-       if showFullStack {
-               for stk.Parent != nil {
-                       lineno = stk.Lineno - 1
-                       stk = stk.Parent
-                       text += fmt.Sprintf(" %s:%d", filename, stk.fileLineAt(lineno))
-                       if stk.Directive && stk.Parent != nil {
-                               stk = stk.Parent
-                               text += fmt.Sprintf("[%s:%d]", filename, stk.fileLineAt(lineno))
-                       }
-               }
-       }
-       return text
-}
-
-// FileLine returns the file name and line number
-// at the top of the stack for the given lineno.
-func (h *LineHist) FileLine(lineno int) (file string, line int) {
-       stk := h.At(lineno)
-       if stk == nil {
-               return "??", 0
-       }
-       return stk.File, stk.fileLineAt(lineno)
-}
-
-// AbsFileLine returns the absolute file name and line number
-// at the top of the stack for the given lineno.
-func (h *LineHist) AbsFileLine(lineno int) (file string, line int) {
-       stk := h.At(lineno)
-       if stk == nil {
-               return "??", 0
-       }
-       return stk.AbsFile, stk.fileLineAt(lineno)
-}
-
-// This is a simplified copy of linklinefmt above.
-// It doesn't allow printing the full stack, and it returns the file name and line number separately.
-// TODO: Unify with linklinefmt somehow.
-func linkgetline(ctxt *Link, lineno int32) (f *LSym, l int32) {
-       panic("defunct")
-       // stk := ctxt.LineHist.At(int(lineno))
-       // if stk == nil || stk.AbsFile == "" {
-       //      return Linklookup(ctxt, "??", HistVersion), 0
-       // }
-       // if stk.Sym == nil {
-       //      stk.Sym = Linklookup(ctxt, stk.AbsFile, HistVersion)
-       // }
-       // return stk.Sym, int32(stk.fileLineAt(int(lineno)))
-}
-
-// This is modified copy of linkgetline to work from src.Pos.
 func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f *LSym, l int32) {
        pos := ctxt.PosTable.Pos(xpos)
        filename := pos.AbsFilename()
@@ -311,11 +84,6 @@ func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f *LSym, l int32) {
        return Linklookup(ctxt, filename, HistVersion), int32(pos.RelLine())
 }
 
-func Linkprfile(ctxt *Link, line int) {
-       panic("defunct")
-       // fmt.Printf("%s ", ctxt.LineHist.LineString(line))
-}
-
 func fieldtrack(ctxt *Link, cursym *LSym) {
        p := cursym.Text
        if p == nil || p.Link == nil { // handle external functions and ELF section symbols
index b32e02daa16db2ba74b58a56211fd0cdd97568ac..ffc7a1b25b013e0ad6836d3036caec271e28038d 100644 (file)
@@ -222,8 +222,8 @@ const (
 // The Progs for a given function are arranged in a list linked through the Link field.
 //
 // Each Prog is charged to a specific source line in the debug information,
-// specified by Pos.Line(), an index into the line history (see LineHist).
-// Every Prog has a Ctxt field that defines various context, including the current LineHist.
+// specified by Pos.Line().
+// Every Prog has a Ctxt field that defines its context.
 // Progs should be allocated using ctxt.NewProg(), not new(Prog).
 //
 // The other fields not yet mentioned are for use by the back ends and should
index 5b4221ae6caaec52c81070949b1b38898cdc2a8a..8dd6e8f1777e57e995a10f9dbe13c09865b9769c 100644 (file)
@@ -56,10 +56,6 @@ func Linknew(arch *LinkArch) *Link {
        ctxt.Version = HistVersion
        ctxt.Pathname = WorkingDir()
 
-       // LineHist is not used anymore
-       // ctxt.LineHist.GOROOT = GOROOT
-       // ctxt.LineHist.Dir = ctxt.Pathname
-
        ctxt.Headtype.Set(GOOS)
        if ctxt.Headtype < 0 {
                log.Fatalf("unknown goos %s", GOOS)