[dev.inline] cmd/compile: split mkpackage into separate functions

Previously, mkpackage jumbled together three unrelated tasks: handling
package declarations, clearing imports from processing previous source
files, and assigning a default value to outfile.

Change-Id: I1e124335768aeabfd1a6d9cc2499fbb980d951cf
Reviewed-on: https://go-review.googlesource.com/35124
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:
Matthew Dempsky 2017-01-11 15:20:38 -08:00
parent 33c036867f
commit e48919bcde
3 changed files with 55 additions and 53 deletions

View file

@ -113,8 +113,6 @@ var sizeof_String int // runtime sizeof(String)
var pragcgobuf string var pragcgobuf string
var infile string
var outfile string var outfile string
var linkobj string var linkobj string

View file

@ -218,6 +218,26 @@ func Main() {
usage() usage()
} }
if outfile == "" {
p := flag.Arg(0)
if i := strings.LastIndex(p, "/"); i >= 0 {
p = p[i+1:]
}
if runtime.GOOS == "windows" {
if i := strings.LastIndex(p, `\`); i >= 0 {
p = p[i+1:]
}
}
if i := strings.LastIndex(p, "."); i >= 0 {
p = p[:i]
}
suffix := ".o"
if writearchive {
suffix = ".a"
}
outfile = p + suffix
}
startProfile() startProfile()
if flag_race { if flag_race {
@ -306,7 +326,7 @@ func Main() {
timings.Start("fe", "parse") timings.Start("fe", "parse")
var lines uint var lines uint
for _, infile = range flag.Args() { for _, infile := range flag.Args() {
block = 1 block = 1
iota_ = -1000000 iota_ = -1000000
imported_unsafe = false imported_unsafe = false
@ -319,7 +339,6 @@ func Main() {
timings.AddEvent(int64(lines), "lines") timings.AddEvent(int64(lines), "lines")
testdclstack() testdclstack()
mkpackage(localpkg.Name) // final import not used checks
finishUniverse() finishUniverse()
typecheckok = true typecheckok = true
@ -900,6 +919,10 @@ func mkpackage(pkgname string) {
if pkgname != localpkg.Name { if pkgname != localpkg.Name {
yyerror("package %s; expected %s", pkgname, localpkg.Name) yyerror("package %s; expected %s", pkgname, localpkg.Name)
} }
}
}
func clearImports() {
for _, s := range localpkg.Syms { for _, s := range localpkg.Syms {
if s.Def == nil { if s.Def == nil {
continue continue
@ -929,25 +952,4 @@ func mkpackage(pkgname string) {
continue continue
} }
} }
}
if outfile == "" {
p := infile
if i := strings.LastIndex(p, "/"); i >= 0 {
p = p[i+1:]
}
if runtime.GOOS == "windows" {
if i := strings.LastIndex(p, `\`); i >= 0 {
p = p[i+1:]
}
}
if i := strings.LastIndex(p, "."); i >= 0 {
p = p[:i]
}
suffix := ".o"
if writearchive {
suffix = ".a"
}
outfile = p + suffix
}
} }

View file

@ -70,6 +70,8 @@ func (p *noder) file(file *syntax.File) {
// TODO(gri) fix this once we switched permanently to the new // TODO(gri) fix this once we switched permanently to the new
// position information. // position information.
lineno = MakePos(file.Pos().Base(), uint(file.Lines), 0) lineno = MakePos(file.Pos().Base(), uint(file.Lines), 0)
clearImports()
} }
func (p *noder) decls(decls []syntax.Decl) (l []*Node) { func (p *noder) decls(decls []syntax.Decl) (l []*Node) {