all: merge dev.inline into master

Change-Id: I7715581a04e513dcda9918e853fa6b1ddc703770
This commit is contained in:
Russ Cox 2017-02-01 09:35:27 -05:00
commit 47ce87877b
124 changed files with 6096 additions and 5655 deletions

View file

@ -11,6 +11,7 @@ import (
"bytes"
"cmd/compile/internal/ssa"
"cmd/internal/obj"
"cmd/internal/src"
"cmd/internal/sys"
"flag"
"fmt"
@ -187,7 +188,7 @@ func Main() {
obj.Flagcount("r", "debug generated wrappers", &Debug['r'])
flag.BoolVar(&flag_race, "race", false, "enable race detector")
obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
flag.StringVar(&Ctxt.LineHist.TrimPathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
flag.StringVar(&pathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
flag.BoolVar(&safemode, "u", false, "reject unsafe code")
obj.Flagcount("v", "increase debug verbosity", &Debug['v'])
obj.Flagcount("w", "debug type checking", &Debug['w'])
@ -219,6 +220,26 @@ func Main() {
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()
if flag_race {
@ -301,33 +322,15 @@ func Main() {
blockgen = 1
dclcontext = PEXTERN
nerrors = 0
lexlineno = 1
timings.Start("fe", "loadsys")
loadsys()
timings.Start("fe", "parse")
lexlineno0 := lexlineno
for _, infile = range flag.Args() {
linehistpush(infile)
block = 1
iota_ = -1000000
imported_unsafe = false
parseFile(infile)
if nsyntaxerrors != 0 {
errorexit()
}
// Instead of converting EOF into '\n' in getc and count it as an extra line
// for the line history to work, and which then has to be corrected elsewhere,
// just add a line here.
lexlineno++
linehistpop()
}
lines := parseFiles(flag.Args())
timings.Stop()
timings.AddEvent(int64(lexlineno-lexlineno0), "lines")
timings.AddEvent(int64(lines), "lines")
mkpackage(localpkg.Name) // final import not used checks
finishUniverse()
typecheckok = true
@ -792,7 +795,8 @@ func importfile(f *Val, indent []byte) {
defer impf.Close()
imp := bufio.NewReader(impf)
if strings.HasSuffix(file, ".a") {
const pkgSuffix = ".a"
if strings.HasSuffix(file, pkgSuffix) {
if !skiptopkgdef(imp) {
yyerror("import %s: not a package file", file)
errorexit()
@ -840,9 +844,9 @@ func importfile(f *Val, indent []byte) {
yyerror("cannot import unsafe package %q", importpkg.Path)
}
// assume files move (get installed)
// so don't record the full path.
linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
// assume files move (get installed) so don't record the full path
// (e.g., for file "/Users/foo/go/pkg/darwin_amd64/math.a" record "math.a")
Ctxt.AddImport(file[len(file)-len(path_)-len(pkgSuffix):])
// In the importfile, if we find:
// $$\n (textual format): not supported anymore
@ -885,7 +889,7 @@ func importfile(f *Val, indent []byte) {
}
}
func pkgnotused(lineno int32, path string, name string) {
func pkgnotused(lineno src.XPos, path string, name string) {
// If the package was imported with a name other than the final
// import path element, show it explicitly in the error message.
// Note that this handles both renamed imports and imports of
@ -913,54 +917,37 @@ func mkpackage(pkgname string) {
if pkgname != localpkg.Name {
yyerror("package %s; expected %s", pkgname, localpkg.Name)
}
for _, s := range localpkg.Syms {
if s.Def == nil {
continue
}
if s.Def.Op == OPACK {
// throw away top-level package name leftover
// from previous file.
// leave s->block set to cause redeclaration
// errors if a conflicting top-level name is
// introduced by a different file.
if !s.Def.Used && nsyntaxerrors == 0 {
pkgnotused(s.Def.Lineno, s.Def.Name.Pkg.Path, s.Name)
}
s.Def = nil
continue
}
if s.isAlias() {
// throw away top-level name left over
// from previous import . "x"
if s.Def.Name != nil && s.Def.Name.Pack != nil && !s.Def.Name.Pack.Used && nsyntaxerrors == 0 {
pkgnotused(s.Def.Name.Pack.Lineno, s.Def.Name.Pack.Name.Pkg.Path, "")
s.Def.Name.Pack.Used = true
}
s.Def = nil
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
}
}
func clearImports() {
for _, s := range localpkg.Syms {
if s.Def == nil {
continue
}
if s.Def.Op == OPACK {
// throw away top-level package name leftover
// from previous file.
// leave s->block set to cause redeclaration
// errors if a conflicting top-level name is
// introduced by a different file.
if !s.Def.Used && nsyntaxerrors == 0 {
pkgnotused(s.Def.Pos, s.Def.Name.Pkg.Path, s.Name)
}
s.Def = nil
continue
}
if s.isAlias() {
// throw away top-level name left over
// from previous import . "x"
if s.Def.Name != nil && s.Def.Name.Pack != nil && !s.Def.Name.Pack.Used && nsyntaxerrors == 0 {
pkgnotused(s.Def.Name.Pack.Pos, s.Def.Name.Pack.Name.Pkg.Path, "")
s.Def.Name.Pack.Used = true
}
s.Def = nil
continue
}
}
}