diff --git a/cmd/gotype/gotype.go b/cmd/gotype/gotype.go index a85bfa01b0..7d68d815a2 100644 --- a/cmd/gotype/gotype.go +++ b/cmd/gotype/gotype.go @@ -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() { diff --git a/cmd/gotype/sizesFor18.go b/cmd/gotype/sizesFor18.go new file mode 100644 index 0000000000..579da8650d --- /dev/null +++ b/cmd/gotype/sizesFor18.go @@ -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 +} diff --git a/cmd/gotype/sizesFor19.go b/cmd/gotype/sizesFor19.go new file mode 100644 index 0000000000..090ec65f0c --- /dev/null +++ b/cmd/gotype/sizesFor19.go @@ -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) +}