]> Cypherpunks repositories - gostls13.git/commitdiff
gotype: use go/types GcImporter
authorRobert Griesemer <gri@golang.org>
Fri, 8 Apr 2011 04:42:30 +0000 (21:42 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 8 Apr 2011 04:42:30 +0000 (21:42 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/4358043

src/cmd/gotype/gotype.go
src/cmd/gotype/gotype_test.go

index 10694a327ca48163e18d0574757c3283df8c4a96..56846732273e77e5cf3da07354dcc78e4f06ab6a 100644 (file)
@@ -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",
-       )
-}
index f5eccab765af434cd044294865f64e9c941f8905..9c8f8f2a77258811f1ed246bdf1f24815429fbb6 100644 (file)
@@ -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"},
 }