func getFnPath(fn *ssa.Function) string { if fn == nil { //println("DEBUG getFnPath nil function") return "" } ob := fn.Object() if ob == nil { //println("DEBUG getFnPath nil object: name,synthetic=", fn.Name(), ",", fn.Synthetic) return "" } pk := ob.Pkg() if pk == nil { //println("DEBUG getFnPath nil package: name,synthetic=", fn.Name(), ",", fn.Synthetic) return "" } return pk.Path() }
func IsOverloaded(f *ssa.Function) bool { pn := "unknown" // Defensive, as some synthetic or other edge-case functions may not have a valid package name rx := f.Signature.Recv() if rx == nil { // ordinary function if f.Pkg != nil { if f.Pkg.Object != nil { pn = f.Pkg.Object.Path() //was .Name() } } else { if f.Object() != nil { if f.Object().Pkg() != nil { pn = f.Object().Pkg().Path() //was .Name() } } } } else { // determine the package information from the type description typ := rx.Type() ts := typ.String() if ts[0] == '*' { ts = ts[1:] } tss := strings.Split(ts, ".") if len(tss) >= 2 { ts = tss[len(tss)-2] // take the part before the final dot } else { ts = tss[0] // no dot! } pn = ts } tss := strings.Split(pn, "/") // TODO check this also works in Windows ts := tss[len(tss)-1] // take the last part of the path pn = ts // TODO this is incorrect, but not currently a problem as there is no function overloading //println("DEBUG package name: " + pn) if LanguageList[TargetLang].FunctionOverloaded(pn, f.Name()) || strings.HasPrefix(pn, "_") { // the package is not in the target language, signaled by a leading underscore and return true } return false }