mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/syntax: simpler position base update for line directives (cleanup)
The existing code was somewhat convoluted and made several assumptions about the encoding of position bases: 1) The position's base for a file contained a position whose base pointed to itself (which is true but an implementation detail of src.Pos). 2) Updating the position base for a line directive required finding the base of the most recent's base position. This change simply stores the file's position base and keeps using it directly for each line directive (instead of getting it from the most recently updated base). Change-Id: I4d80da513bededb636eab0ce53257fda73f0dbc0 Reviewed-on: https://go-review.googlesource.com/95736 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
e02d6bb621
commit
e2a86b6bd9
1 changed files with 9 additions and 7 deletions
|
|
@ -16,23 +16,24 @@ const debug = false
|
||||||
const trace = false
|
const trace = false
|
||||||
|
|
||||||
type parser struct {
|
type parser struct {
|
||||||
base *src.PosBase
|
file *src.PosBase
|
||||||
errh ErrorHandler
|
errh ErrorHandler
|
||||||
fileh FilenameHandler
|
fileh FilenameHandler
|
||||||
mode Mode
|
mode Mode
|
||||||
scanner
|
scanner
|
||||||
|
|
||||||
first error // first error encountered
|
base *src.PosBase // current position base
|
||||||
errcnt int // number of errors encountered
|
first error // first error encountered
|
||||||
pragma Pragma // pragma flags
|
errcnt int // number of errors encountered
|
||||||
|
pragma Pragma // pragma flags
|
||||||
|
|
||||||
fnest int // function nesting level (for error handling)
|
fnest int // function nesting level (for error handling)
|
||||||
xnest int // expression nesting level (for complit ambiguity resolution)
|
xnest int // expression nesting level (for complit ambiguity resolution)
|
||||||
indent []byte // tracing support
|
indent []byte // tracing support
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) init(base *src.PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, fileh FilenameHandler, mode Mode) {
|
func (p *parser) init(file *src.PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, fileh FilenameHandler, mode Mode) {
|
||||||
p.base = base
|
p.file = file
|
||||||
p.errh = errh
|
p.errh = errh
|
||||||
p.fileh = fileh
|
p.fileh = fileh
|
||||||
p.mode = mode
|
p.mode = mode
|
||||||
|
|
@ -65,6 +66,7 @@ func (p *parser) init(base *src.PosBase, r io.Reader, errh ErrorHandler, pragh P
|
||||||
directives,
|
directives,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
p.base = file
|
||||||
p.first = nil
|
p.first = nil
|
||||||
p.errcnt = 0
|
p.errcnt = 0
|
||||||
p.pragma = 0
|
p.pragma = 0
|
||||||
|
|
@ -113,7 +115,7 @@ func (p *parser) updateBase(line, col uint, text string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(gri) pass column n2 to NewLinePragmaBase
|
// TODO(gri) pass column n2 to NewLinePragmaBase
|
||||||
p.base = src.NewLinePragmaBase(src.MakePos(p.base.Pos().Base(), line, col), filename, absFilename, uint(n) /*uint(n2)*/)
|
p.base = src.NewLinePragmaBase(src.MakePos(p.file, line, col), filename, absFilename, uint(n) /*uint(n2)*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
func commentText(s string) string {
|
func commentText(s string) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue