aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/source.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2018-12-05 14:42:47 -0800
committerRobert Griesemer <gri@golang.org>2018-12-05 23:15:21 +0000
commitdc7808d4f2989fa0514fc0e4014616fdb8c4a764 (patch)
tree1d29468c03f46b49da813b807c4b91dfca151d92 /src/cmd/compile/internal/syntax/source.go
parent940e5bc5617ed86fcbf845fdd1973be984259a59 (diff)
downloadgo-dc7808d4f2989fa0514fc0e4014616fdb8c4a764.tar.gz
go-dc7808d4f2989fa0514fc0e4014616fdb8c4a764.zip
cmd/compile/internal/syntax: remove unused field in (scanner) source
The source.offs field was intended for computing line offsets which may allow a tiny optimization (see TODO in source.go). We haven't done the optimization, so for now just remove the field to avoid confusion. It's trivially added if needed. While at it, also: - Fix comment for ungetr2. - Make sure sentinel is present even if reading from the io.Reader failed. Change-Id: Ib056c6478030b3fe5fec29045362c8161ff3d19e Reviewed-on: https://go-review.googlesource.com/c/152763 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/source.go')
-rw-r--r--src/cmd/compile/internal/syntax/source.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/syntax/source.go b/src/cmd/compile/internal/syntax/source.go
index 62eb0fdc30..c6168b8594 100644
--- a/src/cmd/compile/internal/syntax/source.go
+++ b/src/cmd/compile/internal/syntax/source.go
@@ -33,7 +33,6 @@ type source struct {
// source buffer
buf [4 << 10]byte
- offs int // source offset of buf
r0, r, w int // previous/current read and write buf positions, excluding sentinel
line0, line uint // previous/current line
col0, col uint // previous/current column (byte offsets from line start)
@@ -51,7 +50,6 @@ func (s *source) init(src io.Reader, errh func(line, pos uint, msg string)) {
s.errh = errh
s.buf[0] = utf8.RuneSelf // terminate with sentinel
- s.offs = 0
s.r0, s.r, s.w = 0, 0, 0
s.line0, s.line = 0, linebase
s.col0, s.col = 0, colbase
@@ -68,7 +66,8 @@ func (s *source) ungetr() {
// ungetr2 is like ungetr but enables a 2nd ungetr.
// It must not be called if one of the runes seen
-// was a newline.
+// was a newline or had a UTF-8 encoding longer than
+// 1 byte.
func (s *source) ungetr2() {
s.ungetr()
// line must not have changed
@@ -167,7 +166,6 @@ func (s *source) fill() {
}
n := s.r0 - 1
copy(s.buf[:], s.buf[n:s.w])
- s.offs += n
s.r0 = 1 // eqv: s.r0 -= n
s.r -= n
s.w -= n
@@ -189,6 +187,7 @@ func (s *source) fill() {
}
}
+ s.buf[s.w] = utf8.RuneSelf // sentinel
s.ioerr = io.ErrNoProgress
}