func (p *exporter) signature(sig *types.Signature) { // We need the receiver information (T vs *T) // for methods associated with named types. // We do not record interface receiver types in the // export data because 1) the importer can derive them // from the interface type and 2) they create cycles // in the type graph. if recv := sig.Recv(); recv != nil { if _, ok := recv.Type().Underlying().(*types.Interface); !ok { // 1-element tuple p.int(1) p.param(recv) } else { // 0-element tuple p.int(0) } } else { // 0-element tuple p.int(0) } p.tuple(sig.Params()) p.tuple(sig.Results()) if sig.Variadic() { p.int(1) } else { p.int(0) } }
func newSignatureFrom(pkg *Package, sig *types.Signature) *Signature { var recv *Var if sig.Recv() != nil { recv = newVarFrom(pkg, sig.Recv()) } return &Signature{ ret: newVarsFrom(pkg, sig.Results()), args: newVarsFrom(pkg, sig.Params()), recv: recv, } }
func (b *Builder) convertSignature(u types.Universe, t *tc.Signature) *types.Signature { signature := &types.Signature{} for i := 0; i < t.Params().Len(); i++ { signature.Parameters = append(signature.Parameters, b.walkType(u, nil, t.Params().At(i).Type())) } for i := 0; i < t.Results().Len(); i++ { signature.Results = append(signature.Results, b.walkType(u, nil, t.Results().At(i).Type())) } if r := t.Recv(); r != nil { signature.Receiver = b.walkType(u, nil, r.Type()) } signature.Variadic = t.Variadic() return signature }
// writeSignature writes to buf the signature sig in declaration syntax. func writeSignature(buf *bytes.Buffer, from *types.Package, name string, sig *types.Signature, params []*Parameter) { buf.WriteString("func ") if recv := sig.Recv(); recv != nil { buf.WriteString("(") if n := params[0].Name(); n != "" { buf.WriteString(n) buf.WriteString(" ") } types.WriteType(buf, params[0].Type(), types.RelativeTo(from)) buf.WriteString(") ") } buf.WriteString(name) types.WriteSignature(buf, sig, types.RelativeTo(from)) }
func (c *converter) convertSignature(v *gotypes.Signature) *types.Signature { if v == nil { return nil } if v, ok := c.converted[v]; ok { return v.(*types.Signature) } ret := types.NewSignature( c.convertParamVar(v.Recv()), c.convertTuple(v.Params(), c.convertParamVar), c.convertTuple(v.Results(), c.convertParamVar), v.Variadic(), ) c.converted[v] = ret return ret }