1
0
mirror of https://github.com/golang/go synced 2024-11-20 01:14:40 -07:00

gotype: use go/types GcImporter

R=rsc
CC=golang-dev
https://golang.org/cl/4358043
This commit is contained in:
Robert Griesemer 2011-04-07 21:42:30 -07:00
parent a87382e7b3
commit 1baffa7da0
2 changed files with 4 additions and 78 deletions

View 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",
)
}

View 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"},
}