ssa: set method.name to pkg.name if private

This commit is contained in:
visualfc
2024-06-05 22:24:51 +08:00
parent 226fd29af8
commit 2fce2318ed
14 changed files with 1056 additions and 32 deletions

Binary file not shown.

View File

@@ -246,7 +246,19 @@ type Method struct {
// Exported reports whether the method is exported.
func (p *Method) Exported() bool {
return IsExported(p.Name_)
return lastDot(p.Name_) == -1
}
// Name returns the tag string for method.
func (p *Method) Name() string {
_, name := splitName(p.Name_)
return name
}
// PkgPath returns the pkgpath string for method, or empty if there is none.
func (p *Method) PkgPath() string {
pkg, _ := splitName(p.Name_)
return pkg
}
// UncommonType is present only for defined types or types with methods
@@ -280,6 +292,23 @@ type Imethod struct {
Typ_ *FuncType // .(*FuncType) underneath
}
// Exported reports whether the imethod is exported.
func (p *Imethod) Exported() bool {
return lastDot(p.Name_) == -1
}
// Name returns the tag string for imethod.
func (p *Imethod) Name() string {
_, name := splitName(p.Name_)
return name
}
// PkgPath returns the pkgpath string for imethod, or empty if there is none.
func (p *Imethod) PkgPath() string {
pkg, _ := splitName(p.Name_)
return pkg
}
func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) }
// Size returns the size of data with type t.
@@ -450,4 +479,20 @@ func addChecked(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
}
func splitName(s string) (pkg string, name string) {
i := lastDot(s)
if i == -1 {
return s, ""
}
return s[:i], s[i+1:]
}
func lastDot(s string) int {
i := len(s) - 1
for i >= 0 && s[i] != '.' {
i--
}
return i
}
// -----------------------------------------------------------------------------