"go/parser"
"go/scanner"
"go/token"
+ "go/types"
"io/ioutil"
"os"
"path/filepath"
}
-// 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
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",
- )
-}
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)
// 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"},
}