func alpacaf(strukt *types.Struct, typename *types.TypeName, docpkg *doc.Package) { schema := makeSchema(makeIOutput(strukt, typename)) delete(schema["properties"].(JsonObject), "status") write("alpaca/out/schema-"+typename.Name()+".json", schema) options := makeOptions(makeIOutput(strukt, typename)) delete(options["fields"].(JsonObject), "status") write("alpaca/out/options-"+typename.Name()+".json", options) }
func newStruct(p *Package, obj *types.TypeName) (Struct, error) { sym := p.syms.symtype(obj.Type()) if sym == nil { panic(fmt.Errorf("no such object [%s] in symbols table", obj.Id())) } sym.doc = p.getDoc("", obj) s := Struct{ pkg: p, sym: sym, obj: obj, } return s, nil }
// methodsFor returns the named type and corresponding methods if the type // denoted by obj is not an interface and has methods. Otherwise it returns // the zero value. func methodsFor(obj *types.TypeName) (*types.Named, []*types.Selection) { named, _ := obj.Type().(*types.Named) if named == nil { // A type name's type can also be the // exported basic type unsafe.Pointer. return nil, nil } if _, ok := named.Underlying().(*types.Interface); ok { // ignore interfaces return nil, nil } methods := combinedMethodSet(named) if len(methods) == 0 { return nil, nil } return named, methods }
func (g *objcGen) genStructH(obj *types.TypeName, t *types.Struct) { g.Printf("@interface %s%s : NSObject {\n", g.namePrefix, obj.Name()) g.Printf("}\n") g.Printf("@property(strong, readonly) id ref;\n") g.Printf("\n") g.Printf("- (id)initWithRef:(id)ref;\n") // accessors to exported fields. for _, f := range exportedFields(t) { // TODO(hyangah): error type field? name, typ := f.Name(), g.objcType(f.Type()) g.Printf("- (%s)%s;\n", typ, name) g.Printf("- (void)set%s:(%s)v;\n", name, typ) } // exported methods for _, m := range exportedMethodSet(types.NewPointer(obj.Type())) { s := g.funcSummary(m) g.Printf("- %s;\n", s.asMethod(g)) } g.Printf("@end\n") }
func docf(strukt *types.Struct, typename *types.TypeName, docpkg *doc.Package) { s := typename.Name() + "\n" s += strings.Repeat("=", len(typename.Name())) + "\n\n" for _, t := range docpkg.Types { if t.Name == typename.Name() { s += t.Doc + "\n" break } } iobj := makeIOutput(strukt, typename) for _, item := range iobj.(IStruct).items { s += makeDoc("", item) } fmt.Printf("%s\n", s) }
func makeIOutput(strukt *types.Struct, typename *types.TypeName) IObj { iobj := dump(typename.Name(), strukt, reflect.StructTag("")).(IStruct) for i := range iobj.items { if item, ok := iobj.items[i].(IBasic); ok { switch item.name { case "kind": item.options = typename.Name() iobj.items[i] = item case "apiVersion": item.options = typename.Pkg().Name() iobj.items[i] = item } } } return iobj }
func (g *javaGen) genInterface(o *types.TypeName) { iface := o.Type().(*types.Named).Underlying().(*types.Interface) g.Printf("public interface %s extends go.Seq.Object {\n", o.Name()) g.Indent() methodSigErr := false for i := 0; i < iface.NumMethods(); i++ { if err := g.funcSignature(iface.Method(i), false); err != nil { methodSigErr = true g.errorf("%v", err) } g.Printf(";\n\n") } if methodSigErr { return // skip stub generation, more of the same errors } g.genInterfaceStub(o, iface) g.Printf(javaProxyPreamble, o.Name()) g.Indent() for i := 0; i < iface.NumMethods(); i++ { g.genFunc(iface.Method(i), true) } for i := 0; i < iface.NumMethods(); i++ { g.Printf("static final int CALL_%s = 0x%x0a;\n", iface.Method(i).Name(), i+1) } g.Outdent() g.Printf("}\n") g.Outdent() g.Printf("}\n\n") }
func (g *javaGen) genStruct(obj *types.TypeName, T *types.Struct) { fields := exportedFields(T) methods := exportedMethodSet(types.NewPointer(obj.Type())) g.Printf("public static final class %s implements go.Seq.Object {\n", obj.Name()) g.Indent() g.Printf("private static final String DESCRIPTOR = \"go.%s.%s\";\n", g.pkg.Name(), obj.Name()) for i, f := range fields { g.Printf("private static final int FIELD_%s_GET = 0x%x0f;\n", f.Name(), i) g.Printf("private static final int FIELD_%s_SET = 0x%x1f;\n", f.Name(), i) } for i, m := range methods { g.Printf("private static final int CALL_%s = 0x%x0c;\n", m.Name(), i) } g.Printf("\n") g.Printf("private go.Seq.Ref ref;\n\n") n := obj.Name() g.Printf("private %s(go.Seq.Ref ref) { this.ref = ref; }\n\n", n) g.Printf(`public go.Seq.Ref ref() { return ref; } public void call(int code, go.Seq in, go.Seq out) { throw new RuntimeException("internal error: cycle: cannot call concrete proxy"); } `) for _, f := range fields { g.Printf("public %s get%s() {\n", g.javaType(f.Type()), f.Name()) g.Indent() g.Printf("Seq in = new Seq();\n") g.Printf("Seq out = new Seq();\n") g.Printf("in.writeRef(ref);\n") g.Printf("Seq.send(DESCRIPTOR, FIELD_%s_GET, in, out);\n", f.Name()) if seqType(f.Type()) == "Ref" { g.Printf("return new %s(out.read%s);\n", g.javaType(f.Type()), seqRead(f.Type())) } else { g.Printf("return out.read%s;\n", seqRead(f.Type())) } g.Outdent() g.Printf("}\n\n") g.Printf("public void set%s(%s v) {\n", f.Name(), g.javaType(f.Type())) g.Indent() g.Printf("Seq in = new Seq();\n") g.Printf("Seq out = new Seq();\n") g.Printf("in.writeRef(ref);\n") g.Printf("in.write%s;\n", seqWrite(f.Type(), "v")) g.Printf("Seq.send(DESCRIPTOR, FIELD_%s_SET, in, out);\n", f.Name()) g.Outdent() g.Printf("}\n\n") } for _, m := range methods { g.genFunc(m, true) } g.Printf("@Override public boolean equals(Object o) {\n") g.Indent() g.Printf("if (o == null || !(o instanceof %s)) {\n return false;\n}\n", n) g.Printf("%s that = (%s)o;\n", n, n) for _, f := range fields { nf := f.Name() g.Printf("%s this%s = get%s();\n", g.javaType(f.Type()), nf, nf) g.Printf("%s that%s = that.get%s();\n", g.javaType(f.Type()), nf, nf) if isJavaPrimitive(f.Type()) { g.Printf("if (this%s != that%s) {\n return false;\n}\n", nf, nf) } else { g.Printf("if (this%s == null) {\n", nf) g.Indent() g.Printf("if (that%s != null) {\n return false;\n}\n", nf) g.Outdent() g.Printf("} else if (!this%s.equals(that%s)) {\n return false;\n}\n", nf, nf) } } g.Printf("return true;\n") g.Outdent() g.Printf("}\n\n") g.Printf("@Override public int hashCode() {\n") g.Printf(" return java.util.Arrays.hashCode(new Object[] {") for i, f := range fields { if i > 0 { g.Printf(", ") } g.Printf("get%s()", f.Name()) } g.Printf("});\n") g.Printf("}\n\n") // TODO(crawshaw): use String() string if it is defined. g.Printf("@Override public String toString() {\n") g.Indent() g.Printf("StringBuilder b = new StringBuilder();\n") g.Printf(`b.append("%s").append("{");`, obj.Name()) g.Printf("\n") for _, f := range fields { n := f.Name() g.Printf(`b.append("%s:").append(get%s()).append(",");`, n, n) g.Printf("\n") } g.Printf(`return b.append("}").toString();`) g.Printf("\n") g.Outdent() g.Printf("}\n\n") g.Outdent() g.Printf("}\n\n") }
func (g *javaGen) genInterfaceStub(o *types.TypeName, m *types.Interface) { g.Printf("public static abstract class Stub implements %s {\n", o.Name()) g.Indent() g.Printf("static final String DESCRIPTOR = \"go.%s.%s\";\n\n", g.pkg.Name(), o.Name()) g.Printf("private final go.Seq.Ref ref;\n") g.Printf("public Stub() {\n ref = go.Seq.createRef(this);\n}\n\n") g.Printf("public go.Seq.Ref ref() { return ref; }\n\n") g.Printf("public void call(int code, go.Seq in, go.Seq out) {\n") g.Indent() g.Printf("switch (code) {\n") for i := 0; i < m.NumMethods(); i++ { f := m.Method(i) g.Printf("case Proxy.CALL_%s: {\n", f.Name()) g.Indent() sig := f.Type().(*types.Signature) params := sig.Params() for i := 0; i < params.Len(); i++ { p := sig.Params().At(i) jt := g.javaType(p.Type()) g.Printf("%s param_%s;\n", jt, paramName(params, i)) g.genRead("param_"+paramName(params, i), "in", p.Type()) } res := sig.Results() var returnsError bool var numRes = res.Len() if (res.Len() == 1 && isErrorType(res.At(0).Type())) || (res.Len() == 2 && isErrorType(res.At(1).Type())) { numRes -= 1 returnsError = true } if returnsError { g.Printf("try {\n") g.Indent() } if numRes > 0 { g.Printf("%s result = ", g.javaType(res.At(0).Type())) } g.Printf("this.%s(", f.Name()) for i := 0; i < params.Len(); i++ { if i > 0 { g.Printf(", ") } g.Printf("param_%s", paramName(params, i)) } g.Printf(");\n") if numRes > 0 { g.Printf("out.write%s;\n", seqWrite(res.At(0).Type(), "result")) } if returnsError { g.Printf("out.writeString(null);\n") g.Outdent() g.Printf("} catch (Exception e) {\n") g.Indent() if numRes > 0 { resTyp := res.At(0).Type() g.Printf("%s result = %s;\n", g.javaType(resTyp), g.javaTypeDefault(resTyp)) g.Printf("out.write%s;\n", seqWrite(resTyp, "result")) } g.Printf("out.writeString(e.getMessage());\n") g.Outdent() g.Printf("}\n") } g.Printf("return;\n") g.Outdent() g.Printf("}\n") } g.Printf("default:\n throw new RuntimeException(\"unknown code: \"+ code);\n") g.Printf("}\n") g.Outdent() g.Printf("}\n") g.Outdent() g.Printf("}\n\n") }
func (g *objcGen) genStructM(obj *types.TypeName, t *types.Struct) { fields := exportedFields(t) methods := exportedMethodSet(types.NewPointer(obj.Type())) desc := fmt.Sprintf("_GO_%s_%s", g.pkgName, obj.Name()) g.Printf("#define %s_DESCRIPTOR_ \"go.%s.%s\"\n", desc, g.pkgName, obj.Name()) for i, f := range fields { g.Printf("#define %s_FIELD_%s_GET_ (0x%x0f)\n", desc, f.Name(), i) g.Printf("#define %s_FIELD_%s_SET_ (0x%x1f)\n", desc, f.Name(), i) } for i, m := range methods { g.Printf("#define %s_%s_ (0x%x0c)\n", desc, m.Name(), i) } g.Printf("\n") g.Printf("@implementation %s%s {\n", g.namePrefix, obj.Name()) g.Printf("}\n\n") g.Printf("- (id)initWithRef:(id)ref {\n") g.Indent() g.Printf("self = [super init];\n") g.Printf("if (self) { _ref = ref; }\n") g.Printf("return self;\n") g.Outdent() g.Printf("}\n\n") for _, f := range fields { // getter // TODO(hyangah): support error type fields? s := &funcSummary{ name: f.Name(), ret: g.objcType(f.Type()), } s.retParams = append(s.retParams, paramInfo{typ: f.Type(), name: "ret_"}) g.Printf("- %s {\n", s.asMethod(g)) g.Indent() g.genFunc(desc+"_DESCRIPTOR_", desc+"_FIELD_"+f.Name()+"_GET_", s, true) g.Outdent() g.Printf("}\n\n") // setter s = &funcSummary{ name: "set" + f.Name(), ret: "void", } s.params = append(s.params, paramInfo{typ: f.Type(), name: "v"}) g.Printf("- %s {\n", s.asMethod(g)) g.Indent() g.genFunc(desc+"_DESCRIPTOR_", desc+"_FIELD_"+f.Name()+"_SET_", s, true) g.Outdent() g.Printf("}\n\n") } for _, m := range methods { s := g.funcSummary(m) g.Printf("- %s {\n", s.asMethod(g)) g.Indent() g.genFunc(desc+"_DESCRIPTOR_", desc+"_"+m.Name()+"_", s, true) g.Outdent() g.Printf("}\n\n") } g.Printf("@end\n") }
func (g *objcGen) genInterfaceM(obj *types.TypeName, t *types.Interface) { log.Printf("TODO: %s", obj.Name()) }
func (a *analysis) namedType(obj *types.TypeName, implements map[*types.Named]implementsFacts) { qualifier := types.RelativeTo(obj.Pkg()) T := obj.Type().(*types.Named) v := &TypeInfoJSON{ Name: obj.Name(), Size: sizes.Sizeof(T), Align: sizes.Alignof(T), Methods: []anchorJSON{}, // (JS wants non-nil) } // addFact adds the fact "is implemented by T" (by) or // "implements T" (!by) to group. addFact := func(group *implGroupJSON, T types.Type, by bool) { Tobj := deref(T).(*types.Named).Obj() var byKind string if by { // Show underlying kind of implementing type, // e.g. "slice", "array", "struct". s := reflect.TypeOf(T.Underlying()).String() byKind = strings.ToLower(strings.TrimPrefix(s, "*types.")) } group.Facts = append(group.Facts, implFactJSON{ ByKind: byKind, Other: anchorJSON{ Href: a.posURL(Tobj.Pos(), len(Tobj.Name())), Text: types.TypeString(T, qualifier), }, }) } // IMPLEMENTS if r, ok := implements[T]; ok { if isInterface(T) { // "T is implemented by <conc>" ... // "T is implemented by <iface>"... // "T implements <iface>"... group := implGroupJSON{ Descr: types.TypeString(T, qualifier), } // Show concrete types first; use two passes. for _, sub := range r.to { if !isInterface(sub) { addFact(&group, sub, true) } } for _, sub := range r.to { if isInterface(sub) { addFact(&group, sub, true) } } for _, super := range r.from { addFact(&group, super, false) } v.ImplGroups = append(v.ImplGroups, group) } else { // T is concrete. if r.from != nil { // "T implements <iface>"... group := implGroupJSON{ Descr: types.TypeString(T, qualifier), } for _, super := range r.from { addFact(&group, super, false) } v.ImplGroups = append(v.ImplGroups, group) } if r.fromPtr != nil { // "*C implements <iface>"... group := implGroupJSON{ Descr: "*" + types.TypeString(T, qualifier), } for _, psuper := range r.fromPtr { addFact(&group, psuper, false) } v.ImplGroups = append(v.ImplGroups, group) } } } // METHOD SETS for _, sel := range typeutil.IntuitiveMethodSet(T, &a.prog.MethodSets) { meth := sel.Obj().(*types.Func) pos := meth.Pos() // may be 0 for error.Error v.Methods = append(v.Methods, anchorJSON{ Href: a.posURL(pos, len(meth.Name())), Text: types.SelectionString(sel, qualifier), }) } // Since there can be many specs per decl, we // can't attach the link to the keyword 'type' // (as we do with 'func'); we use the Ident. fi, offset := a.fileAndOffset(obj.Pos()) fi.addLink(aLink{ start: offset, end: offset + len(obj.Name()), title: fmt.Sprintf("type info for %s", obj.Name()), onclick: fmt.Sprintf("onClickTypeInfo(%d)", fi.addData(v)), }) // Add info for exported package-level types to the package info. if obj.Exported() && isPackageLevel(obj) { // TODO(adonovan): Path is not unique! // It is possible to declare a non-test package called x_test. a.result.pkgInfo(obj.Pkg().Path()).addType(v) } }
func (g *goGen) genInterface(obj *types.TypeName) { iface := obj.Type().(*types.Named).Underlying().(*types.Interface) ifaceDesc := fmt.Sprintf("go.%s.%s", g.pkg.Name(), obj.Name()) // Descriptor and code for interface methods. g.Printf("const (\n") g.Indent() g.Printf("proxy%s_Descriptor = %q\n", obj.Name(), ifaceDesc) for i := 0; i < iface.NumMethods(); i++ { g.Printf("proxy%s_%s_Code = 0x%x0a\n", obj.Name(), iface.Method(i).Name(), i+1) } g.Outdent() g.Printf(")\n\n") // Define the entry points. for i := 0; i < iface.NumMethods(); i++ { m := iface.Method(i) g.Printf("func proxy%s_%s(out, in *seq.Buffer) {\n", obj.Name(), m.Name()) g.Indent() g.Printf("ref := in.ReadRef()\n") g.Printf("v := ref.Get().(%s.%s)\n", g.pkg.Name(), obj.Name()) g.genFuncBody(m, "v") g.Outdent() g.Printf("}\n\n") } // Register the method entry points. g.Printf("func init() {\n") g.Indent() for i := 0; i < iface.NumMethods(); i++ { g.Printf("seq.Register(proxy%s_Descriptor, proxy%s_%s_Code, proxy%s_%s)\n", obj.Name(), obj.Name(), iface.Method(i).Name(), obj.Name(), iface.Method(i).Name()) } g.Outdent() g.Printf("}\n\n") // Define a proxy interface. g.Printf("type proxy%s seq.Ref\n\n", obj.Name()) for i := 0; i < iface.NumMethods(); i++ { m := iface.Method(i) sig := m.Type().(*types.Signature) params := sig.Params() res := sig.Results() if res.Len() > 2 || (res.Len() == 2 && !isErrorType(res.At(1).Type())) { g.errorf("functions and methods must return either zero or one value, and optionally an error: %s.%s", obj.Name(), m.Name()) continue } g.Printf("func (p *proxy%s) %s(", obj.Name(), m.Name()) for i := 0; i < params.Len(); i++ { if i > 0 { g.Printf(", ") } g.Printf("%s %s", paramName(params, i), g.typeString(params.At(i).Type())) } g.Printf(") ") if res.Len() == 1 { g.Printf(g.typeString(res.At(0).Type())) } else if res.Len() == 2 { g.Printf("(%s, error)", g.typeString(res.At(0).Type())) } g.Printf(" {\n") g.Indent() g.Printf("in := new(seq.Buffer)\n") for i := 0; i < params.Len(); i++ { g.genWrite(paramName(params, i), "in", params.At(i).Type()) } if res.Len() == 0 { g.Printf("seq.Transact((*seq.Ref)(p), %q, proxy%s_%s_Code, in)\n", ifaceDesc, obj.Name(), m.Name()) } else { g.Printf("out := seq.Transact((*seq.Ref)(p), %q, proxy%s_%s_Code, in)\n", ifaceDesc, obj.Name(), m.Name()) var rvs []string for i := 0; i < res.Len(); i++ { rv := fmt.Sprintf("res_%d", i) g.genRead(rv, "out", res.At(i).Type()) rvs = append(rvs, rv) } g.Printf("return %s\n", strings.Join(rvs, ",")) } g.Outdent() g.Printf("}\n\n") } }
func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) { fields := exportedFields(T) methods := exportedMethodSet(types.NewPointer(obj.Type())) g.Printf("const (\n") g.Indent() g.Printf("proxy%s_Descriptor = \"go.%s.%s\"\n", obj.Name(), g.pkg.Name(), obj.Name()) for i, f := range fields { g.Printf("proxy%s_%s_Get_Code = 0x%x0f\n", obj.Name(), f.Name(), i) g.Printf("proxy%s_%s_Set_Code = 0x%x1f\n", obj.Name(), f.Name(), i) } for i, m := range methods { g.Printf("proxy%s_%s_Code = 0x%x0c\n", obj.Name(), m.Name(), i) } g.Outdent() g.Printf(")\n\n") g.Printf("type proxy%s seq.Ref\n\n", obj.Name()) for _, f := range fields { seqTyp := seqType(f.Type()) g.Printf("func proxy%s_%s_Set(out, in *seq.Buffer) {\n", obj.Name(), f.Name()) g.Indent() g.Printf("ref := in.ReadRef()\n") g.Printf("v := in.Read%s()\n", seqTyp) if seqTyp == "Ref" { g.Printf("ref.Get().(*%s.%s).%s = v.Get().(%s)\n", g.pkg.Name(), obj.Name(), f.Name(), g.typeString(f.Type())) } else { // TODO(crawshaw): other kinds of non-ptr types. g.Printf("ref.Get().(*%s.%s).%s = v\n", g.pkg.Name(), obj.Name(), f.Name()) } g.Outdent() g.Printf("}\n\n") g.Printf("func proxy%s_%s_Get(out, in *seq.Buffer) {\n", obj.Name(), f.Name()) g.Indent() g.Printf("ref := in.ReadRef()\n") g.Printf("v := ref.Get().(*%s.%s).%s\n", g.pkg.Name(), obj.Name(), f.Name()) if seqTyp == "Ref" { g.Printf("out.WriteGoRef(v)\n") } else { g.Printf("out.Write%s(v)\n", seqTyp) } g.Outdent() g.Printf("}\n\n") } for _, m := range methods { g.Printf("func proxy%s_%s(out, in *seq.Buffer) {\n", obj.Name(), m.Name()) g.Indent() g.Printf("ref := in.ReadRef()\n") g.Printf("v := ref.Get().(*%s.%s)\n", g.pkg.Name(), obj.Name()) g.genFuncBody(m, "v") g.Outdent() g.Printf("}\n\n") } g.Printf("func init() {\n") g.Indent() for _, f := range fields { n := f.Name() g.Printf("seq.Register(proxy%s_Descriptor, proxy%s_%s_Set_Code, proxy%s_%s_Set)\n", obj.Name(), obj.Name(), n, obj.Name(), n) g.Printf("seq.Register(proxy%s_Descriptor, proxy%s_%s_Get_Code, proxy%s_%s_Get)\n", obj.Name(), obj.Name(), n, obj.Name(), n) } for _, m := range methods { n := m.Name() g.Printf("seq.Register(proxy%s_Descriptor, proxy%s_%s_Code, proxy%s_%s)\n", obj.Name(), obj.Name(), n, obj.Name(), n) } g.Outdent() g.Printf("}\n\n") }
func (g *goGen) genStruct(obj *types.TypeName, typ *types.Struct) { //fmt.Printf("obj: %#v\ntyp: %#v\n", obj, typ) pkgname := obj.Pkg().Name() g.Printf("//export GoPy_%[1]s\n", obj.Name()) g.Printf("type GoPy_%[1]s unsafe.Pointer\n\n", obj.Name()) for i := 0; i < typ.NumFields(); i++ { f := typ.Field(i) if !f.Exported() { continue } ft := f.Type() ftname := g.qualifiedType(ft) if needWrapType(ft) { ftname = fmt.Sprintf("GoPy_%[1]s_field_%d", obj.Name(), i+1) g.Printf("//export %s\n", ftname) g.Printf("type %s unsafe.Pointer\n\n", ftname) } g.Printf("//export GoPy_%[1]s_getter_%[2]d\n", obj.Name(), i+1) g.Printf("func GoPy_%[1]s_getter_%[2]d(self GoPy_%[1]s) %[3]s {\n", obj.Name(), i+1, ftname, ) g.Indent() g.Printf( "ret := (*%[1]s)(unsafe.Pointer(self))\n", pkgname+"."+obj.Name(), ) if needWrapType(f.Type()) { dt := getTypedesc(f.Type()) g.Printf("%s(unsafe.Pointer(&ret.%s))\n", dt.cgotype, f.Name()) } else { g.Printf("return ret.%s\n", f.Name()) } g.Outdent() g.Printf("}\n\n") } g.Printf("//export GoPy_%[1]s_new\n", obj.Name()) g.Printf("func GoPy_%[1]s_new() GoPy_%[1]s {\n", obj.Name()) g.Indent() g.Printf("return (GoPy_%[1]s)(unsafe.Pointer(&%[2]s.%[1]s{}))\n", obj.Name(), pkgname, ) g.Outdent() g.Printf("}\n\n") }
func (g *goGen) genInterface(obj *types.TypeName) { iface := obj.Type().(*types.Named).Underlying().(*types.Interface) g.Printf("const (\n") g.Indent() g.Printf("proxy%sDescriptor = \"go.%s.%s\"\n", obj.Name(), g.pkg.Name(), obj.Name()) for i := 0; i < iface.NumMethods(); i++ { g.Printf("proxy%s%sCode = 0x%x0a\n", obj.Name(), iface.Method(i).Name(), i+1) } g.Outdent() g.Printf(")\n\n") g.Printf("type proxy%s seq.Ref\n\n", obj.Name()) for i := 0; i < iface.NumMethods(); i++ { m := iface.Method(i) sig := m.Type().(*types.Signature) params := sig.Params() g.Printf("func (p *proxy%s) %s(", obj.Name(), m.Name()) for i := 0; i < params.Len(); i++ { if i > 0 { g.Printf(", ") } g.Printf("%s %s", paramName(params, i), params.At(i).Type()) } g.Printf(") ") res := sig.Results() if res.Len() > 0 { g.Printf("(") } for i := 0; i < res.Len(); i++ { if i > 0 { g.Printf(", ") } g.Printf("res_%d %s", i, res.At(i).Type()) } if res.Len() > 0 { g.Printf(")") } g.Printf(" {\n") g.Indent() g.Printf("out := new(seq.Buffer)\n") for i := 0; i < params.Len(); i++ { p := params.At(i) g.Printf("out.Write%s\n", seqWrite(p.Type(), paramName(params, i))) } g.Printf("seq.Transact((*seq.Ref)(p), proxy%s%sCode, out)\n", obj.Name(), m.Name()) g.Outdent() g.Printf("}\n\n") } }