// visitFunc analyses function body. func visitFunc(fn *ssa.Function, infer *TypeInfer, f *Function) { infer.Env.MigoProg.AddFunction(f.FuncDef) infer.Logger.Printf(f.Sprintf(FuncEnterSymbol+"───── func %s ─────", fn.Name())) defer infer.Logger.Printf(f.Sprintf(FuncExitSymbol+"───── func %s ─────", fn.Name())) if fn.Name() == "init" { if _, ok := f.Prog.InitPkgs[fn.Package()]; !ok { f.Prog.InitPkgs[fn.Package()] = true } f.hasBody = true return } for val, instance := range f.locals { infer.Logger.Printf(f.Sprintf(ParamSymbol+"%s = %s", val.Name(), instance)) f.revlookup[instance.String()] = val.Name() // If it comes from params.. } if fn.Blocks == nil { infer.Logger.Print(f.Sprintf(MoreSymbol + "« no function body »")) f.hasBody = false // No body return } // When entering function, always visit as block 0 block0 := NewBlock(f, fn.Blocks[0], 0) visitBasicBlock(fn.Blocks[0], infer, f, block0, &Loop{Parent: f}) f.hasBody = true }
func (l langType) FuncName(fnx *ssa.Function) string { pn := "" if fnx.Signature.Recv() != nil { pn = fnx.Signature.Recv().Type().String() // NOTE no use of underlying here } else { pn, _ = pogo.FuncPathName(fnx) //fmt.Sprintf("fn%d", fnx.Pos()) fn := ssa.EnclosingFunction(fnx.Package(), []ast.Node{fnx.Syntax()}) if fn == nil { fn = fnx } if fn.Pkg != nil { if fn.Pkg.Object != nil { pn = fn.Pkg.Object.Path() // was .Name() } } else { if fn.Object() != nil { if fn.Object().Pkg() != nil { pn = fn.Object().Pkg().Path() // was .Name() } } } } return l.LangName(pn, fnx.Name()) }