1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:04:52 -07:00

go.tools/go/types: add mode to typecheck pkg-level decls only

This is useful for situations where one only cares about
exports, for instance (as in the goapi checker).

R=adonovan, bradfitz
CC=golang-dev
https://golang.org/cl/12292043
This commit is contained in:
Robert Griesemer 2013-08-01 16:37:56 -07:00
parent 61a33ecd43
commit 4ceda807d5
3 changed files with 15 additions and 3 deletions

View File

@ -48,6 +48,10 @@ func Check(path string, fset *token.FileSet, files []*ast.File) (*Package, error
// A Config specifies the configuration for type checking.
// The zero value for Config is a ready-to-use default configuration.
type Config struct {
// If IgnoreFuncBodies is set, function bodies are not
// type-checked.
IgnoreFuncBodies bool
// If Error != nil, it is called with each error found
// during type checking. The error strings of errors with
// detailed position information are formatted as follows:
@ -99,7 +103,9 @@ type Info struct {
// If Objects != nil, it records the identifier and corresponding object
// for each identifier that is type-checked (including package names,
// dots "." of dot-imports, and blank "_" identifiers). For identifiers
// that were not declared due to an error, the corresponding object is nil.
// that are not declared (due to an error, or because they are symbolic
// as the t in t := x.(type) of a type switch header), the corresponding
// object is nil.
// BUG(gri) Label identifiers in break, continue, or goto statements
// are not recorded.
Objects map[*ast.Ident]Object

View File

@ -71,7 +71,7 @@ type funcInfo struct {
// later appends a function with non-empty body to check.funcList.
func (check *checker) later(f *Func, sig *Signature, body *ast.BlockStmt) {
// functions implemented elsewhere (say in assembly) have no body
if body != nil {
if !check.conf.IgnoreFuncBodies && body != nil {
check.funcList = append(check.funcList, funcInfo{f, sig, body})
}
}

View File

@ -42,9 +42,15 @@ func TestSelf(t *testing.T) {
return // skip benchmark in short mode
}
benchmark(fset, files, false)
benchmark(fset, files, true)
}
func benchmark(fset *token.FileSet, files []*ast.File, full bool) {
b := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
Check("go/types", fset, files)
conf := Config{IgnoreFuncBodies: !full}
conf.Check("go/types", fset, files, nil)
}
})