patch sync/atomic; typepatch fix (don't change types)
This commit is contained in:
@@ -22,6 +22,17 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type typesPackage struct {
|
||||
path string
|
||||
name string
|
||||
scope *types.Scope
|
||||
imports []*types.Package
|
||||
complete bool
|
||||
fake bool // scope lookup errors are silently dropped if package is fake (internal use only)
|
||||
cgo bool // uses of this package will be rewritten into uses of declarations from _cgo_gotypes.go
|
||||
goVersion string // minimum Go version required for package (by Config.GoVersion, typically from go.mod)
|
||||
}
|
||||
|
||||
type typesScope struct {
|
||||
parent *types.Scope
|
||||
children []*types.Scope
|
||||
@@ -44,23 +55,42 @@ type iface struct {
|
||||
data unsafe.Pointer
|
||||
}
|
||||
|
||||
func setScope(pkg *types.Package, scope *types.Scope) {
|
||||
p := (*typesPackage)(unsafe.Pointer(pkg))
|
||||
p.scope = scope
|
||||
}
|
||||
|
||||
func setPkg(o types.Object, pkg *types.Package) {
|
||||
data := (*iface)(unsafe.Pointer(&o)).data
|
||||
(*object)(data).pkg = pkg
|
||||
}
|
||||
|
||||
func setObject(scope *types.Scope, name string, o types.Object) {
|
||||
func getElems(scope *types.Scope) map[string]types.Object {
|
||||
s := (*typesScope)(unsafe.Pointer(scope))
|
||||
s.elems[name] = o
|
||||
return s.elems
|
||||
}
|
||||
|
||||
func setElems(scope *types.Scope, elems map[string]types.Object) {
|
||||
s := (*typesScope)(unsafe.Pointer(scope))
|
||||
s.elems = elems
|
||||
}
|
||||
|
||||
func Pkg(pkg, alt *types.Package) *types.Package {
|
||||
scope := pkg.Scope()
|
||||
altScope := alt.Scope()
|
||||
for _, name := range altScope.Names() {
|
||||
o := altScope.Lookup(name)
|
||||
setPkg(o, pkg)
|
||||
setObject(scope, name, o)
|
||||
ret := *pkg
|
||||
scope := *pkg.Scope()
|
||||
|
||||
old := getElems(&scope)
|
||||
elems := make(map[string]types.Object, len(old))
|
||||
for name, o := range old {
|
||||
elems[name] = o
|
||||
}
|
||||
return pkg
|
||||
|
||||
altScope := alt.Scope()
|
||||
for name, o := range getElems(altScope) {
|
||||
setPkg(o, pkg)
|
||||
elems[name] = o
|
||||
}
|
||||
setElems(&scope, elems)
|
||||
setScope(&ret, &scope)
|
||||
return &ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user