mirror of
https://github.com/golang/go
synced 2024-11-19 11:04:47 -07:00
[dev.inline] cmd/compile: reorganize file parsing logic
Preparation for concurrent parsing. No behavior change. Change-Id: Ic1ec45fc3cb316778c29065cf055c82e92ffa874 Reviewed-on: https://go-review.googlesource.com/35125 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e48919bcde
commit
b90aed020d
@ -325,16 +325,7 @@ func Main() {
|
|||||||
loadsys()
|
loadsys()
|
||||||
|
|
||||||
timings.Start("fe", "parse")
|
timings.Start("fe", "parse")
|
||||||
var lines uint
|
lines := parseFiles(flag.Args())
|
||||||
for _, infile := range flag.Args() {
|
|
||||||
block = 1
|
|
||||||
iota_ = -1000000
|
|
||||||
imported_unsafe = false
|
|
||||||
lines += parseFile(infile)
|
|
||||||
if nsyntaxerrors != 0 {
|
|
||||||
errorexit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timings.Stop()
|
timings.Stop()
|
||||||
timings.AddEvent(int64(lines), "lines")
|
timings.AddEvent(int64(lines), "lines")
|
||||||
|
|
||||||
|
@ -16,6 +16,17 @@ import (
|
|||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func parseFiles(filenames []string) uint {
|
||||||
|
var lines uint
|
||||||
|
for _, filename := range filenames {
|
||||||
|
lines += parseFile(filename)
|
||||||
|
if nsyntaxerrors != 0 {
|
||||||
|
errorexit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
func parseFile(filename string) uint {
|
func parseFile(filename string) uint {
|
||||||
f, err := os.Open(filename)
|
f, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -30,12 +41,6 @@ func parseFile(filename string) uint {
|
|||||||
|
|
||||||
p.file(file)
|
p.file(file)
|
||||||
|
|
||||||
if !imported_unsafe {
|
|
||||||
for _, pos := range p.linknames {
|
|
||||||
p.error(syntax.Error{Pos: pos, Msg: "//go:linkname only allowed in Go files that import \"unsafe\""})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if nsyntaxerrors == 0 {
|
if nsyntaxerrors == 0 {
|
||||||
testdclstack()
|
testdclstack()
|
||||||
}
|
}
|
||||||
@ -55,11 +60,21 @@ type noder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *noder) file(file *syntax.File) {
|
func (p *noder) file(file *syntax.File) {
|
||||||
|
block = 1
|
||||||
|
iota_ = -1000000
|
||||||
|
imported_unsafe = false
|
||||||
|
|
||||||
p.lineno(file.PkgName)
|
p.lineno(file.PkgName)
|
||||||
mkpackage(file.PkgName.Value)
|
mkpackage(file.PkgName.Value)
|
||||||
|
|
||||||
xtop = append(xtop, p.decls(file.DeclList)...)
|
xtop = append(xtop, p.decls(file.DeclList)...)
|
||||||
|
|
||||||
|
if !imported_unsafe {
|
||||||
|
for _, pos := range p.linknames {
|
||||||
|
p.error(syntax.Error{Pos: pos, Msg: "//go:linkname only allowed in Go files that import \"unsafe\""})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For compatibility with old code only (comparisons w/ toolstash):
|
// For compatibility with old code only (comparisons w/ toolstash):
|
||||||
// The old line number tracking simply continued incrementing the
|
// The old line number tracking simply continued incrementing the
|
||||||
// virtual line number (lexlineno) and using it also for lineno.
|
// virtual line number (lexlineno) and using it also for lineno.
|
||||||
|
Loading…
Reference in New Issue
Block a user