Commit a7d2d483 authored by Robert Griesemer's avatar Robert Griesemer

cmd/vet: adjust vet to use go/types and friends from std repo

- s|"golang.org/x/tools/go/exact"|"go/constant"|
- s|"golang.org/x/tools/go/types"|"go/types"|
- removed import of gcimporter
- import "go/importer" instead
- trivial adjustments to make use of go/importer
- adjusted import paths for whitelist.go

Change-Id: I43488ff44c329cd869c92dcc31193fb31bebfd29
Reviewed-on: https://go-review.googlesource.com/10695Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 1b8b2c15
......@@ -7,11 +7,10 @@
package main
import (
"cmd/vet/whitelist"
"flag"
"go/ast"
"strings"
"golang.org/x/tools/cmd/vet/whitelist"
)
var compositeWhiteList = flag.Bool("compositewhitelist", true, "use composite white list; for testing only")
......
......@@ -11,8 +11,7 @@ import (
"fmt"
"go/ast"
"go/token"
"golang.org/x/tools/go/types"
"go/types"
)
func init() {
......
......@@ -15,14 +15,12 @@ import (
"go/parser"
"go/printer"
"go/token"
"go/types"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
_ "golang.org/x/tools/go/gcimporter"
"golang.org/x/tools/go/types"
)
var (
......
......@@ -12,8 +12,7 @@ package main
import (
"go/ast"
"go/token"
"golang.org/x/tools/go/types"
"go/types"
)
func init() {
......
......@@ -10,13 +10,12 @@ import (
"bytes"
"flag"
"go/ast"
"go/constant"
"go/token"
"go/types"
"strconv"
"strings"
"unicode/utf8"
"golang.org/x/tools/go/exact"
"golang.org/x/tools/go/types"
)
var printfuncs = flag.String("printfuncs", "", "comma-separated list of print function names to check")
......@@ -160,11 +159,11 @@ func (f *File) checkPrintf(call *ast.CallExpr, name string, formatIndex int) {
}
return
}
if lit.Kind() != exact.String {
if lit.Kind() != constant.String {
f.Badf(call.Pos(), "constant %v not a string in call to %s", lit, name)
return
}
format := exact.StringVal(lit)
format := constant.StringVal(lit)
firstArg := formatIndex + 1 // Arguments are immediately after format string.
if !strings.Contains(format, "%") {
if len(call.Args) > firstArg {
......
......@@ -34,8 +34,7 @@ import (
"flag"
"go/ast"
"go/token"
"golang.org/x/tools/go/types"
"go/types"
)
var strictShadowing = flag.Bool("shadowstrict", false, "whether to be strict about shadowing; can be noisy")
......
......@@ -10,10 +10,9 @@ package main
import (
"go/ast"
"go/constant"
"go/token"
"golang.org/x/tools/go/exact"
"golang.org/x/tools/go/types"
"go/types"
)
func init() {
......@@ -46,7 +45,7 @@ func checkLongShift(f *File, node ast.Node, x, y ast.Expr) {
if v == nil {
return
}
amt, ok := exact.Int64Val(v)
amt, ok := constant.Int64Val(v)
if !ok {
return
}
......
......@@ -8,14 +8,15 @@ package main
import (
"go/ast"
"go/importer"
"go/token"
"golang.org/x/tools/go/types"
"go/types"
)
// imports is the canonical map of imported packages we need for typechecking.
// It is created during initialization.
var imports = make(map[string]*types.Package)
// stdImporter is the importer we use to import packages.
// It is created during initialization so that all packages
// are imported by the same importer.
var stdImporter = importer.Default()
var (
stringerMethodType = types.New("func() string")
......@@ -35,7 +36,7 @@ func init() {
// path.name, and adds the respective package to the imports map
// as a side effect.
func importType(path, name string) types.Type {
pkg, err := types.DefaultImport(imports, path)
pkg, err := stdImporter.Import(path)
if err != nil {
// This can happen if fmt hasn't been compiled yet.
// Since nothing uses formatterType anyway, don't complain.
......@@ -56,9 +57,9 @@ func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) error {
pkg.spans = make(map[types.Object]Span)
pkg.types = make(map[ast.Expr]types.TypeAndValue)
config := types.Config{
// We provide the same packages map for all imports to ensure
// that everybody sees identical packages for the given paths.
Packages: imports,
// We use the same importer for all imports to ensure that
// everybody sees identical packages for the given paths.
Importer: stdImporter,
// By providing a Config with our own error function, it will continue
// past the first error. There is no need for that function to do anything.
Error: func(error) {},
......
......@@ -9,8 +9,7 @@ package main
import (
"go/ast"
"go/token"
"golang.org/x/tools/go/types"
"go/types"
)
func init() {
......
......@@ -11,9 +11,8 @@ import (
"flag"
"go/ast"
"go/token"
"go/types"
"strings"
"golang.org/x/tools/go/types"
)
var unusedFuncsFlag = flag.String("unusedfuncs",
......
......@@ -87,7 +87,7 @@ func TestTags(t *testing.T) {
"-v", // We're going to look at the files it examines.
"testdata/tagtest",
}
cmd = exec.Command(filepath.Join(".", binary), args...)
cmd = exec.Command("./"+binary, args...)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
......
......@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// Package whitelist defines exceptions for the vet tool.
package whitelist // import "golang.org/x/tools/cmd/vet/whitelist"
package whitelist // import "cmd/vet/whitelist"
// UnkeyedLiteral are types that are actually slices, but
// syntactically, we cannot tell whether the Typ in pkg.Typ{1, 2, 3}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment