]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: adjust vet to use go/types and friends from std repo
authorRobert Griesemer <gri@golang.org>
Thu, 4 Jun 2015 20:07:22 +0000 (13:07 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 4 Jun 2015 21:24:52 +0000 (21:24 +0000)
- 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/10695
Reviewed-by: Rob Pike <r@golang.org>
12 files changed:
src/cmd/vet/composite.go
src/cmd/vet/copylock.go
src/cmd/vet/main.go
src/cmd/vet/nilfunc.go
src/cmd/vet/print.go
src/cmd/vet/shadow.go
src/cmd/vet/shift.go
src/cmd/vet/types.go
src/cmd/vet/unsafeptr.go
src/cmd/vet/unused.go
src/cmd/vet/vet_test.go
src/cmd/vet/whitelist/whitelist.go

index 0c3f9165583ad5693df2a49500b49c610d289eb1..80b45e2064fc03bd98fb61e7c47a989fa295ddad 100644 (file)
@@ -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")
index e8a6820fce9a79033e9049be9f2293736a03a443..95cecc799c4c3bb4a91b60115ccd510ff4bcb333 100644 (file)
@@ -11,8 +11,7 @@ import (
        "fmt"
        "go/ast"
        "go/token"
-
-       "golang.org/x/tools/go/types"
+       "go/types"
 )
 
 func init() {
index e4b68770b032e99beb973047eb3bc956787546bb..453cfe0ce0c448cd9c3e6aa3dc888f24af979dc3 100644 (file)
@@ -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 (
index fa1bac7e64b15eb684a32c542cfe9dc902719064..bfe05e3353da9a098ac2c84e749876cdbae93ad7 100644 (file)
@@ -12,8 +12,7 @@ package main
 import (
        "go/ast"
        "go/token"
-
-       "golang.org/x/tools/go/types"
+       "go/types"
 )
 
 func init() {
index b20d935ef4af0ff474bb884da968dcc9acb324a0..d79b0967ab7ffd9a7d6cdc28b744b9cdaec43690 100644 (file)
@@ -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 {
index 34e5db90911796041a2793c8dd095303b0d118b4..b3f362a080677f3676dda1bab942cc45e8eed8ca 100644 (file)
@@ -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")
index 2385c23fdb9bf623443fe9918cfbb5737ec87a20..8c038b4bdd792b916fbaf71e374cd1d23508a30d 100644 (file)
@@ -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
        }
index 89e9989d9a0663b14665f174f4223e95b7ba8a63..112b26a53f9bf950319c80b32501d71e22c49a22 100644 (file)
@@ -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) {},
index ca15f725789647085025c97408d083d5ce6cf166..9ca27dce0e5c8d36d5c3a07634c1028d3e18eb58 100644 (file)
@@ -9,8 +9,7 @@ package main
 import (
        "go/ast"
        "go/token"
-
-       "golang.org/x/tools/go/types"
+       "go/types"
 )
 
 func init() {
index db988fe1de6d14fb9deeb62bef26b5107e26ff3c..4287638586f730485e53ea9db020272db1e4a29d 100644 (file)
@@ -11,9 +11,8 @@ import (
        "flag"
        "go/ast"
        "go/token"
+       "go/types"
        "strings"
-
-       "golang.org/x/tools/go/types"
 )
 
 var unusedFuncsFlag = flag.String("unusedfuncs",
index 33e54ae900773f3675156f40ba7bca51375d821c..0027a1f3291f31199a1e7ad9cd3980a3d479e3b2 100644 (file)
@@ -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)
index d6f0dce8215b5399436665e291e439b798fdcfc8..bf4b4bf48a0c8a11c657746b75876e000fd1567a 100644 (file)
@@ -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}