func (r *describePackageResult) toSerial(res *serial.Result, fset *token.FileSet) { var members []*serial.DescribeMember for _, mem := range r.members { typ := mem.obj.Type() var val string switch mem := mem.obj.(type) { case *types.Const: val = mem.Val().String() case *types.TypeName: typ = typ.Underlying() } members = append(members, &serial.DescribeMember{ Name: mem.obj.Name(), Type: typ.String(), Value: val, Pos: fset.Position(mem.obj.Pos()).String(), Kind: tokenOf(mem.obj), Methods: methodsToSerial(r.pkg, mem.methods, fset), }) } res.Describe = &serial.Describe{ Desc: r.description, Pos: fset.Position(r.node.Pos()).String(), Detail: "package", Package: &serial.DescribePackage{ Path: r.pkg.Path(), Members: members, }, } }
func (r *describeStmtResult) toSerial(res *serial.Result, fset *token.FileSet) { res.Describe = &serial.Describe{ Desc: r.description, Pos: fset.Position(r.node.Pos()).String(), Detail: "unknown", } }
func (r *implementsResult) toSerial(res *serial.Result, fset *token.FileSet) { res.Implements = &serial.Implements{ T: makeImplementsType(r.t, fset), AssignableTo: makeImplementsTypes(r.to, fset), AssignableFrom: makeImplementsTypes(r.from, fset), AssignableFromPtr: makeImplementsTypes(r.fromPtr, fset), } }
func (r *definitionResult) toSerial(res *serial.Result, fset *token.FileSet) { definition := &serial.Definition{ Desc: r.obj.String(), } if pos := r.obj.Pos(); pos != token.NoPos { // Package objects have no Pos() definition.ObjPos = fset.Position(pos).String() } res.Definition = definition }
func (r *callersResult) toSerial(res *serial.Result, fset *token.FileSet) { var callers []serial.Caller for _, edge := range r.edges { callers = append(callers, serial.Caller{ Caller: edge.Caller.Func.String(), Pos: fset.Position(edge.Pos()).String(), Desc: edge.Description(), }) } res.Callers = callers }
func (r *calleesResult) toSerial(res *serial.Result, fset *token.FileSet) { j := &serial.Callees{ Pos: fset.Position(r.site.Pos()).String(), Desc: r.site.Common().Description(), } for _, callee := range r.funcs { j.Callees = append(j.Callees, &serial.CalleesItem{ Name: callee.String(), Pos: fset.Position(callee.Pos()).String(), }) } res.Callees = j }
func (r *referrersResult) toSerial(res *serial.Result, fset *token.FileSet) { referrers := &serial.Referrers{ Pos: fset.Position(r.query.Pos()).String(), Desc: r.obj.String(), } if pos := r.obj.Pos(); pos != token.NoPos { // Package objects have no Pos() referrers.ObjPos = fset.Position(pos).String() } for _, ref := range r.refs { referrers.Refs = append(referrers.Refs, fset.Position(ref.NamePos).String()) } res.Referrers = referrers }
func (r *freevarsResult) toSerial(res *serial.Result, fset *token.FileSet) { var refs []*serial.FreeVar for _, ref := range r.refs { refs = append(refs, &serial.FreeVar{ Pos: fset.Position(ref.obj.Pos()).String(), Kind: ref.kind, Ref: ref.ref, Type: ref.typ.String(), }) } res.Freevars = refs }
func (r *calleesTypesResult) toSerial(res *serial.Result, fset *token.FileSet) { j := &serial.Callees{ Pos: fset.Position(r.site.Pos()).String(), Desc: "static function call", } j.Callees = []*serial.CalleesItem{ &serial.CalleesItem{ Name: r.callee.FullName(), Pos: fset.Position(r.callee.Pos()).String(), }, } res.Callees = j }
func (r *callgraphResult) toSerial(res *serial.Result, fset *token.FileSet) { cg := make([]serial.CallGraph, len(r.nodes)) for _, n := range r.nodes { j := &cg[n.ID] fn := n.Func j.Name = fn.String() j.Pos = fset.Position(fn.Pos()).String() for callee := range callgraph.CalleesOf(n) { j.Children = append(j.Children, callee.ID) } sort.Ints(j.Children) } res.Callgraph = cg }
func (r *whatResult) toSerial(res *serial.Result, fset *token.FileSet) { var enclosing []serial.SyntaxNode for _, n := range r.path { enclosing = append(enclosing, serial.SyntaxNode{ Description: astutil.NodeDescription(n), Start: fset.Position(n.Pos()).Offset, End: fset.Position(n.End()).Offset, }) } res.What = &serial.What{ Modes: r.modes, SrcDir: r.srcdir, ImportPath: r.importPath, Enclosing: enclosing, } }
func (r *callstackResult) toSerial(res *serial.Result, fset *token.FileSet) { var callers []serial.Caller for i := len(r.callpath) - 1; i >= 0; i-- { // (innermost first) edge := r.callpath[i] callers = append(callers, serial.Caller{ Pos: fset.Position(edge.Pos()).String(), Caller: edge.Caller.Func.String(), Desc: edge.Description(), }) } res.Callstack = &serial.CallStack{ Pos: fset.Position(r.target.Pos()).String(), Target: r.target.String(), Callers: callers, } }
func (r *implementsResult) toSerial(res *serial.Result, fset *token.FileSet) { res.Implements = &serial.Implements{ T: makeImplementsType(r.t, fset), AssignableTo: makeImplementsTypes(r.to, fset), AssignableFrom: makeImplementsTypes(r.from, fset), AssignableFromPtr: makeImplementsTypes(r.fromPtr, fset), AssignableToMethod: methodsToSerial(r.qpos.info.Pkg, r.toMethod, fset), AssignableFromMethod: methodsToSerial(r.qpos.info.Pkg, r.fromMethod, fset), AssignableFromPtrMethod: methodsToSerial(r.qpos.info.Pkg, r.fromPtrMethod, fset), } if r.method != nil { res.Implements.Method = &serial.DescribeMethod{ Name: r.qpos.objectString(r.method), Pos: fset.Position(r.method.Pos()).String(), } } }
func (r *whicherrsResult) toSerial(res *serial.Result, fset *token.FileSet) { we := &serial.WhichErrs{} we.ErrPos = fset.Position(r.errpos).String() for _, g := range r.globals { we.Globals = append(we.Globals, fset.Position(g.Pos()).String()) } for _, c := range r.consts { we.Constants = append(we.Constants, fset.Position(c.Pos()).String()) } for _, t := range r.types { var et serial.WhichErrsType et.Type = r.qpos.typeString(t.typ) et.Position = fset.Position(t.obj.Pos()).String() we.Types = append(we.Types, et) } res.WhichErrs = we }
func (r *describeTypeResult) toSerial(res *serial.Result, fset *token.FileSet) { var namePos, nameDef string if nt, ok := r.typ.(*types.Named); ok { namePos = fset.Position(nt.Obj().Pos()).String() nameDef = nt.Underlying().String() } res.Describe = &serial.Describe{ Desc: r.description, Pos: fset.Position(r.node.Pos()).String(), Detail: "type", Type: &serial.DescribeType{ Type: r.qpos.TypeString(r.typ), NamePos: namePos, NameDef: nameDef, Methods: methodsToSerial(r.qpos.info.Pkg, r.methods, fset), }, } }
func (r *peersResult) toSerial(res *serial.Result, fset *token.FileSet) { peers := &serial.Peers{ Pos: fset.Position(r.queryPos).String(), Type: r.queryType.String(), } for _, alloc := range r.makes { peers.Allocs = append(peers.Allocs, fset.Position(alloc).String()) } for _, send := range r.sends { peers.Sends = append(peers.Sends, fset.Position(send).String()) } for _, receive := range r.receives { peers.Receives = append(peers.Receives, fset.Position(receive).String()) } for _, clos := range r.closes { peers.Closes = append(peers.Closes, fset.Position(clos).String()) } res.Peers = peers }
func (r *describeValueResult) toSerial(res *serial.Result, fset *token.FileSet) { var value, objpos string if r.constVal != nil { value = r.constVal.String() } if r.obj != nil { objpos = fset.Position(r.obj.Pos()).String() } res.Describe = &serial.Describe{ Desc: astutil.NodeDescription(r.expr), Pos: fset.Position(r.expr.Pos()).String(), Detail: "value", Value: &serial.DescribeValue{ Type: r.qpos.TypeString(r.typ), Value: value, ObjPos: objpos, }, } }
func (r *pointstoResult) toSerial(res *serial.Result, fset *token.FileSet) { var pts []serial.PointsTo for _, ptr := range r.ptrs { var namePos string if nt, ok := deref(ptr.typ).(*types.Named); ok { namePos = fset.Position(nt.Obj().Pos()).String() } var labels []serial.PointsToLabel for _, l := range ptr.labels { labels = append(labels, serial.PointsToLabel{ Pos: fset.Position(l.Pos()).String(), Desc: l.String(), }) } pts = append(pts, serial.PointsTo{ Type: r.qpos.typeString(ptr.typ), NamePos: namePos, Labels: labels, }) } res.PointsTo = pts }
func (r *describeUnknownResult) toSerial(res *serial.Result, fset *token.FileSet) { res.Describe = &serial.Describe{ Desc: astutil.NodeDescription(r.node), Pos: fset.Position(r.node.Pos()).String(), } }