mirror of
https://github.com/golang/go
synced 2024-11-18 20:04:52 -07:00
go.tools/go/types: towards permitting adding additional package files incrementally
Another small step towards resolving issue 7114. LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/72230043
This commit is contained in:
parent
d14a9d31e6
commit
4f1c486d35
@ -26,6 +26,14 @@ type exprInfo struct {
|
||||
val exact.Value // constant value; or nil (if not a constant)
|
||||
}
|
||||
|
||||
// funcInfo stores the information required for type-checking a function.
|
||||
type funcInfo struct {
|
||||
name string // for debugging/tracing only
|
||||
decl *declInfo // for cycle detection
|
||||
sig *Signature
|
||||
body *ast.BlockStmt
|
||||
}
|
||||
|
||||
// A context represents the context within which an object is type-checked.
|
||||
type context struct {
|
||||
decl *declInfo // package-level declaration whose init expression/function body is checked
|
||||
@ -83,6 +91,10 @@ func (check *checker) rememberUntyped(e ast.Expr, lhs bool, typ *Basic, val exac
|
||||
m[e] = exprInfo{lhs, typ, val}
|
||||
}
|
||||
|
||||
func (check *checker) later(name string, decl *declInfo, sig *Signature, body *ast.BlockStmt) {
|
||||
check.funcs = append(check.funcs, funcInfo{name, decl, sig, body})
|
||||
}
|
||||
|
||||
func (check *checker) delay(f func()) {
|
||||
check.delayed = append(check.delayed, f)
|
||||
}
|
||||
@ -175,12 +187,6 @@ func (check *checker) files(files []*ast.File) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// copy check.InitOrder back to incoming *info if necessary
|
||||
// (In case of early (error) bailout, this is not done, but we don't care in that case.)
|
||||
// if info != nil {
|
||||
// info.InitOrder = check.InitOrder
|
||||
// }
|
||||
|
||||
pkg.complete = true
|
||||
return
|
||||
}
|
||||
|
@ -265,13 +265,6 @@ func (check *checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, path []*
|
||||
delete(check.methods, obj.name) // we don't need them anymore
|
||||
}
|
||||
|
||||
type funcInfo struct {
|
||||
name string // for debugging/tracing only
|
||||
decl *declInfo // for cycle detection
|
||||
sig *Signature
|
||||
body *ast.BlockStmt
|
||||
}
|
||||
|
||||
func (check *checker) funcDecl(obj *Func, decl *declInfo) {
|
||||
assert(obj.typ == nil)
|
||||
|
||||
@ -290,7 +283,7 @@ func (check *checker) funcDecl(obj *Func, decl *declInfo) {
|
||||
// function body must be type-checked after global declarations
|
||||
// (functions implemented elsewhere have no body)
|
||||
if !check.conf.IgnoreFuncBodies && fdecl.Body != nil {
|
||||
check.funcs = append(check.funcs, funcInfo{obj.name, decl, sig, fdecl.Body})
|
||||
check.later(obj.name, decl, sig, fdecl.Body)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,10 +116,17 @@ func (check *checker) resolveFiles(files []*ast.File) {
|
||||
importer = DefaultImport
|
||||
}
|
||||
|
||||
// pkgImports is the set of packages already imported by any package file seen
|
||||
// so far. Used to avoid duplicate entries in pkg.imports. Allocate and populate
|
||||
// it (pkg.imports may not be empty if we are checking test files incrementally).
|
||||
var pkgImports = make(map[*Package]bool)
|
||||
for _, imp := range pkg.imports {
|
||||
pkgImports[imp] = true
|
||||
}
|
||||
|
||||
var (
|
||||
seenPkgs = make(map[*Package]bool) // imported packages that have been seen already
|
||||
fileScopes []*Scope // file scope for each file
|
||||
dotImports []map[*Package]token.Pos // positions of dot-imports for each file
|
||||
fileScopes []*Scope // file scope for each file
|
||||
dotImports []map[*Package]token.Pos // positions of dot-imports for each file
|
||||
)
|
||||
|
||||
for _, file := range files {
|
||||
@ -168,8 +175,8 @@ func (check *checker) resolveFiles(files []*ast.File) {
|
||||
// add package to list of explicit imports
|
||||
// (this functionality is provided as a convenience
|
||||
// for clients; it is not needed for type-checking)
|
||||
if !seenPkgs[imp] {
|
||||
seenPkgs[imp] = true
|
||||
if !pkgImports[imp] {
|
||||
pkgImports[imp] = true
|
||||
if imp != Unsafe {
|
||||
pkg.imports = append(pkg.imports, imp)
|
||||
}
|
||||
@ -343,7 +350,7 @@ func (check *checker) resolveFiles(files []*ast.File) {
|
||||
}
|
||||
}
|
||||
}
|
||||
seenPkgs = nil // not needed anymore
|
||||
pkgImports = nil // not needed anymore
|
||||
|
||||
// Phase 2: Verify that objects in package and file scopes have different names.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user