aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2015-04-10 17:50:06 -0700
committerRobert Griesemer <gri@golang.org>2015-04-15 02:28:53 +0000
commite5b76747c9f30a736c38137ad7f5939c02b3e285 (patch)
treea3da1b4dae9c3512d4e99431772a4eb9eee5b3fb /src/cmd/api
parent2d0c962b1c13e451d0cce79032c92551c607b1bd (diff)
downloadgo-e5b76747c9f30a736c38137ad7f5939c02b3e285.tar.gz
go-e5b76747c9f30a736c38137ad7f5939c02b3e285.zip
go/importer: added go/importer package, adjusted go/types
- The go/importer package provides access to compiler-specific importers. - Adjusted go/internal/gcimporter and go/types as needed. - types.Check was removed - not much simpler than calling types.Config.Check. - Package "unsafe" is now handled by the type checker; importers are not called for it anymore. - In std lib tests, re-use importer for faster testing (no need to re-import previously imported packages). - Minor cleanups. The code still needs cleanups before submitting. Change-Id: Idd456da2e9641688fe056504367348926feb0755 Reviewed-on: https://go-review.googlesource.com/8767 Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/api')
-rw-r--r--src/cmd/api/goapi.go21
-rw-r--r--src/cmd/api/goapi_test.go6
2 files changed, 13 insertions, 14 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go
index 7b2c643e11..01b6defb5f 100644
--- a/src/cmd/api/goapi.go
+++ b/src/cmd/api/goapi.go
@@ -152,7 +152,8 @@ func main() {
// w.Import(name) will return nil
continue
}
- w.export(w.Import(name))
+ pkg, _ := w.Import(name)
+ w.export(pkg)
}
}
@@ -417,13 +418,13 @@ func tagKey(dir string, context *build.Context, tags []string) string {
// for a package that is in the process of being imported.
var importing types.Package
-func (w *Walker) Import(name string) (pkg *types.Package) {
- pkg = w.imported[name]
+func (w *Walker) Import(name string) (*types.Package, error) {
+ pkg := w.imported[name]
if pkg != nil {
if pkg == &importing {
log.Fatalf("cycle importing package %q", name)
}
- return pkg
+ return pkg, nil
}
w.imported[name] = &importing
@@ -447,7 +448,7 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
key = tagKey(dir, context, tags)
if pkg := pkgCache[key]; pkg != nil {
w.imported[name] = pkg
- return pkg
+ return pkg, nil
}
}
}
@@ -455,7 +456,7 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
info, err := context.ImportDir(dir, 0)
if err != nil {
if _, nogo := err.(*build.NoGoError); nogo {
- return
+ return nil, nil
}
log.Fatalf("pkg %q, dir %q: ScanDir: %v", name, dir, err)
}
@@ -484,11 +485,7 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
conf := types.Config{
IgnoreFuncBodies: true,
FakeImportC: true,
- Import: func(imports map[string]*types.Package, name string) (*types.Package, error) {
- pkg := w.Import(name)
- imports[name] = pkg
- return pkg, nil
- },
+ Importer: w,
}
pkg, err = conf.Check(name, fset, files, nil)
if err != nil {
@@ -504,7 +501,7 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
}
w.imported[name] = pkg
- return
+ return pkg, nil
}
// pushScope enters a new scope (walking a package, type, node, etc)
diff --git a/src/cmd/api/goapi_test.go b/src/cmd/api/goapi_test.go
index 00c45c3bcd..6184e14477 100644
--- a/src/cmd/api/goapi_test.go
+++ b/src/cmd/api/goapi_test.go
@@ -39,7 +39,8 @@ func TestGolden(t *testing.T) {
// TODO(gri) remove extra pkg directory eventually
goldenFile := filepath.Join("testdata", "src", "pkg", fi.Name(), "golden.txt")
w := NewWalker(nil, "testdata/src/pkg")
- w.export(w.Import(fi.Name()))
+ pkg, _ := w.Import(fi.Name())
+ w.export(pkg)
if *updateGolden {
os.Remove(goldenFile)
@@ -178,7 +179,8 @@ func BenchmarkAll(b *testing.B) {
w := NewWalker(context, filepath.Join(build.Default.GOROOT, "src"))
for _, name := range pkgNames {
if name != "unsafe" && !strings.HasPrefix(name, "cmd/") {
- w.export(w.Import(name))
+ pkg, _ := w.Import(name)
+ w.export(pkg)
}
}
w.Features()