cmd/gotype: make it compile against Go 1.8 and earlier

types.SizesFor was introduced for Go 1.9. Need to provide
a local implementation to have gotype build against earlier
versions.

Fixes golang/go#19545.

Change-Id: I6fdbe414e6574eda00c01295b666230daff2dfdc
Reviewed-on: https://go-review.googlesource.com/38157
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2017-03-14 14:44:29 -07:00
parent 381149a2d6
commit 2f69a5922b
3 changed files with 59 additions and 5 deletions

View File

@ -2,15 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// gotype.go is a 1:1 copy of the original source maintained in
// $GOROOT/src/go/types/gotype.go.
// gotype.go is a copy of the original source maintained
// in $GOROOT/src/go/types/gotype.go, but with the call
// to types.SizesFor factored out so we can provide a local
// implementation when compiling against Go 1.8 and earlier.
//
// This copy is here for the sole purpose of satisfying existing
// This code is here for the sole purpose of satisfying historic
// references to this location, and for making gotype accessible
// via 'go get'.
//
// Do NOT make changes to this version as they will not be maintained
// (and possibly overwritten). Any changes should be made to the original.
// (and possibly overwritten). Any changes should be made to the original
// and then ported to here.
/*
The gotype command, like the front-end of a Go compiler, parses and
@ -282,7 +285,7 @@ func checkPkgFiles(files []*ast.File) {
report(err)
},
Importer: importer.For(*compiler, nil),
Sizes: types.SizesFor(build.Default.Compiler, build.Default.GOARCH),
Sizes: SizesFor(build.Default.Compiler, build.Default.GOARCH),
}
defer func() {

38
cmd/gotype/sizesFor18.go Normal file
View File

@ -0,0 +1,38 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.9
// This file contains a copy of the implementation of types.SizesFor
// since this function is not available in go/types before Go 1.9.
package main
import "go/types"
var gcArchSizes = map[string]*types.StdSizes{
"386": {4, 4},
"arm": {4, 4},
"arm64": {8, 8},
"amd64": {8, 8},
"amd64p32": {4, 8},
"mips": {4, 4},
"mipsle": {4, 4},
"mips64": {8, 8},
"mips64le": {8, 8},
"ppc64": {8, 8},
"ppc64le": {8, 8},
"s390x": {8, 8},
}
func SizesFor(compiler, arch string) types.Sizes {
if compiler != "gc" {
return nil
}
s, ok := gcArchSizes[arch]
if !ok {
return nil
}
return s
}

13
cmd/gotype/sizesFor19.go Normal file
View File

@ -0,0 +1,13 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.9
package main
import "go/types"
func SizesFor(compiler, arch string) types.Sizes {
return types.SizesFor(compiler, arch)
}