From 1baffa7da0b70cfc4a85fe319bb1f6b3dfa14d74 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 7 Apr 2011 21:42:30 -0700 Subject: [PATCH] gotype: use go/types GcImporter R=rsc CC=golang-dev https://golang.org/cl/4358043 --- src/cmd/gotype/gotype.go | 70 +---------------------------------- src/cmd/gotype/gotype_test.go | 12 +----- 2 files changed, 4 insertions(+), 78 deletions(-) diff --git a/src/cmd/gotype/gotype.go b/src/cmd/gotype/gotype.go index 10694a327c..5684673227 100644 --- a/src/cmd/gotype/gotype.go +++ b/src/cmd/gotype/gotype.go @@ -11,6 +11,7 @@ import ( "go/parser" "go/scanner" "go/token" + "go/types" "io/ioutil" "os" "path/filepath" @@ -170,13 +171,9 @@ func processFiles(filenames []string, allFiles bool) { } -// TODO(gri) Replace this with a fully functioning importer. -// For now a dummy importer is set up by gotype_test.go. -var importer ast.Importer - func processPackage(fset *token.FileSet, files map[string]*ast.File) { // make a package (resolve all identifiers) - pkg, err := ast.NewPackage(fset, files, importer, universe) + pkg, err := ast.NewPackage(fset, files, types.GcImporter, types.Universe) if err != nil { report(err) return @@ -199,66 +196,3 @@ func main() { os.Exit(exitCode) } - - -// TODO(gri) Move universe and its initialization in to the right package. -var universe *ast.Scope - -func define(kind ast.ObjKind, names ...string) { - for _, name := range names { - obj := ast.NewObj(kind, name) - if universe.Insert(obj) != nil { - panic("gotype internal error: incorrect universe scope") - } - } -} - - -func init() { - universe = ast.NewScope(nil) - - define(ast.Typ, - "bool", - "byte", - "complex64", - "complex128", - "float32", - "float64", - "int8", - "int16", - "int32", - "int64", - "string", - "uint8", - "uint16", - "uint32", - "uint64", - "int", - "uint", - "uintptr", - ) - - define(ast.Con, - "true", - "false", - "iota", - "nil", - ) - - define(ast.Fun, - "append", - "cap", - "close", - "complex", - "copy", - "imag", - "len", - "make", - "new", - "panic", - "print", - "println", - "real", - "recover", - ) -} diff --git a/src/cmd/gotype/gotype_test.go b/src/cmd/gotype/gotype_test.go index f5eccab765..9c8f8f2a77 100644 --- a/src/cmd/gotype/gotype_test.go +++ b/src/cmd/gotype/gotype_test.go @@ -5,26 +5,16 @@ package main import ( - "go/ast" - "os" "path/filepath" "runtime" - "path" "testing" ) -func testImporter(importPath string) (string, *ast.Scope, os.Error) { - _, pkgName := path.Split(importPath) // filename is package name for std library - return pkgName, ast.NewScope(nil), nil -} - - func runTest(t *testing.T, path, pkg string) { exitCode = 0 *pkgName = pkg *recursive = false - importer = testImporter if pkg == "" { processFiles([]string{path}, true) @@ -47,9 +37,11 @@ var tests = []struct { // directories {filepath.Join(runtime.GOROOT(), "src/pkg/go/ast"), "ast"}, + {filepath.Join(runtime.GOROOT(), "src/pkg/go/doc"), "doc"}, {filepath.Join(runtime.GOROOT(), "src/pkg/go/token"), "scanner"}, {filepath.Join(runtime.GOROOT(), "src/pkg/go/scanner"), "scanner"}, {filepath.Join(runtime.GOROOT(), "src/pkg/go/parser"), "parser"}, + {filepath.Join(runtime.GOROOT(), "src/pkg/go/types"), "types"}, }