1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00

Revert "cmd/vet: switch to go/types from std repo"

This reverts commit 5b72e8e9bb.

Change-Id: I75270045022d69444b7812f290cdd5861af13feb
Reviewed-on: https://go-review.googlesource.com/8915
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Robert Griesemer 2015-04-14 03:53:55 +00:00
parent 5b72e8e9bb
commit 850ba653f7
9 changed files with 31 additions and 21 deletions

View File

@ -11,7 +11,8 @@ import (
"fmt"
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/go/types"
)
func init() {

View File

@ -15,12 +15,14 @@ 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"
)
// TODO: Need a flag to set build tags when parsing the package.

View File

@ -12,7 +12,8 @@ package main
import (
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/go/types"
)
func init() {

View File

@ -10,12 +10,13 @@ import (
"bytes"
"flag"
"go/ast"
"go/exact"
"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")

View File

@ -34,7 +34,8 @@ import (
"flag"
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/go/types"
)
var strictShadowing = flag.Bool("shadowstrict", false, "whether to be strict about shadowing; can be noisy")

View File

@ -10,9 +10,10 @@ package main
import (
"go/ast"
"go/exact"
"go/token"
"go/types"
"golang.org/x/tools/go/exact"
"golang.org/x/tools/go/types"
)
func init() {

View File

@ -8,14 +8,14 @@ package main
import (
"go/ast"
"go/importer"
"go/token"
"go/types"
"golang.org/x/tools/go/types"
)
// The stdImporter implements importing from package files created by
// the compiler that built this binary.
var stdImporter = importer.Default()
// imports is the canonical map of imported packages we need for typechecking.
// It is created during initialization.
var imports = make(map[string]*types.Package)
var (
stringerMethodType = types.New("func() string")
@ -35,7 +35,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 := stdImporter.Import(path)
pkg, err := types.DefaultImport(imports, path)
if err != nil {
// This can happen if fmt hasn't been compiled yet.
// Since nothing uses formatterType anyway, don't complain.
@ -56,12 +56,12 @@ 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,
// 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) {},
// We use the same importer for all imports to ensure
// that everybody sees identical packages for the given paths.
Importer: stdImporter,
}
info := &types.Info{
Selections: pkg.selectors,

View File

@ -9,7 +9,8 @@ package main
import (
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/go/types"
)
func init() {

View File

@ -11,8 +11,10 @@ import (
"flag"
"go/ast"
"go/token"
"go/types"
"strings"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/types"
)
var unusedFuncsFlag = flag.String("unusedfuncs",
@ -54,11 +56,11 @@ func initUnusedFlags() {
}
func checkUnusedResult(f *File, n ast.Node) {
call, ok := unparen(n.(*ast.ExprStmt).X).(*ast.CallExpr)
call, ok := astutil.Unparen(n.(*ast.ExprStmt).X).(*ast.CallExpr)
if !ok {
return // not a call statement
}
fun := unparen(call.Fun)
fun := astutil.Unparen(call.Fun)
if f.pkg.types[fun].IsType() {
return // a conversion, not a call