summaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/parser.go
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2017-09-13 19:04:25 -0400
committerDavid Crawshaw <crawshaw@golang.org>2017-09-15 17:18:43 +0000
commit27e80f7c4d8001598367e15a1617fa524bd0fb11 (patch)
tree30eaac4762d4fd16c635ef629f358d2b7bdc09fa /src/cmd/compile/internal/syntax/parser.go
parentaf860838123548e67232373d86453cdc4838e9d6 (diff)
downloadgo-git-27e80f7c4d8001598367e15a1617fa524bd0fb11.tar.gz
cmd/compile: replace GOROOT in //line directives
The compiler replaces any path of the form /path/to/goroot/src/net/port.go with GOROOT/src/net/port.go so that the same object file is produced if the GOROOT is moved. It was skipping this transformation for any absolute path into the GOROOT that came from //line directives, such as those generated by cmd/cgo. Fixes #21373 Fixes #21720 Fixes #21825 Change-Id: I2784c701b4391cfb92e23efbcb091a84957d61dd Reviewed-on: https://go-review.googlesource.com/63693 Run-TryBot: David Crawshaw <crawshaw@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser.go')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index bcf56d5faa..b9129b0d9c 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -16,9 +16,10 @@ const debug = false
const trace = false
type parser struct {
- base *src.PosBase
- errh ErrorHandler
- mode Mode
+ base *src.PosBase
+ errh ErrorHandler
+ fileh FilenameHandler
+ mode Mode
scanner
first error // first error encountered
@@ -29,9 +30,10 @@ type parser struct {
indent []byte // tracing support
}
-func (p *parser) init(base *src.PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode) {
+func (p *parser) init(base *src.PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, fileh FilenameHandler, mode Mode) {
p.base = base
p.errh = errh
+ p.fileh = fileh
p.mode = mode
p.scanner.init(
r,
@@ -76,7 +78,11 @@ func (p *parser) updateBase(line, col uint, text string) {
p.error_at(p.pos_at(line, col+uint(i+1)), "invalid line number: "+nstr)
return
}
- p.base = src.NewLinePragmaBase(src.MakePos(p.base.Pos().Base(), line, col), text[:i], uint(n))
+ absFile := text[:i]
+ if p.fileh != nil {
+ absFile = p.fileh(absFile)
+ }
+ p.base = src.NewLinePragmaBase(src.MakePos(p.base.Pos().Base(), line, col), absFile, uint(n))
}
func (p *parser) got(tok token) bool {