本文整理汇总了Golang中go/types.Func.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Func.Name方法的具体用法?Golang Func.Name怎么用?Golang Func.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Func
的用法示例。
在下文中一共展示了Func.Name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: genConstructor
func (g *JavaGen) genConstructor(f *types.Func, n string, jcls bool) {
g.Printf("public %s(", n)
g.genFuncArgs(f, nil, false)
g.Printf(") {\n")
g.Indent()
sig := f.Type().(*types.Signature)
params := sig.Params()
if jcls {
g.Printf("super(")
for i := 0; i < params.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
g.Printf(g.paramName(params, i))
}
g.Printf(");\n")
}
g.Printf("this.ref = ")
g.Printf("__%s(", f.Name())
for i := 0; i < params.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
g.Printf(g.paramName(params, i))
}
g.Printf(");\n")
g.Outdent()
g.Printf("}\n\n")
g.Printf("private static native Seq.Ref __%s(", f.Name())
g.genFuncArgs(f, nil, false)
g.Printf(");\n\n")
}
示例2: genFuncSignature
func (g *goGen) genFuncSignature(o *types.Func, objName string) {
g.Printf("//export proxy%s_%s_%s\n", g.pkgPrefix, objName, o.Name())
g.Printf("func proxy%s_%s_%s(", g.pkgPrefix, objName, o.Name())
if objName != "" {
g.Printf("refnum C.int32_t")
}
sig := o.Type().(*types.Signature)
params := sig.Params()
for i := 0; i < params.Len(); i++ {
if objName != "" || i > 0 {
g.Printf(", ")
}
p := params.At(i)
g.Printf("param_%s C.%s", g.paramName(params, i), g.cgoType(p.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("C.%s", g.cgoType(res.At(i).Type()))
}
g.Printf(") ")
}
g.Printf("{\n")
}
示例3: genFunc
func (g *goGen) genFunc(o *types.Func) {
g.Printf("func proxy_%s(out, in *seq.Buffer) {\n", o.Name())
g.Indent()
g.genFuncBody(o, g.pkg.Name())
g.Outdent()
g.Printf("}\n\n")
}
示例4: findMethod
func findMethod(prog *ssa.Program, meth *types.Func, typ types.Type, infer *TypeInfer) *ssa.Function {
if meth != nil {
return prog.LookupMethod(typ, meth.Pkg(), meth.Name())
}
infer.Logger.Fatal(ErrMethodNotFound)
return nil
}
示例5: genMethodInterfaceProxy
func (g *javaGen) genMethodInterfaceProxy(oName string, m *types.Func) {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s with unsupported parameter or return types\n\n", oName)
return
}
sig := m.Type().(*types.Signature)
params := sig.Params()
res := sig.Results()
g.genInterfaceMethodSignature(m, oName, false)
g.Indent()
// Push a JNI reference frame with a conservative capacity of two for each per parameter (Seq.Ref and Seq.Object),
// plus extra space for the receiver, the return value, and exception (if any).
g.Printf("JNIEnv *env = go_seq_push_local_frame(%d);\n", 2*params.Len()+10)
g.Printf("jobject o = go_seq_from_refnum(env, refnum, proxy_class_%s_%s, proxy_class_%s_%s_cons);\n", g.pkgPrefix, oName, g.pkgPrefix, oName)
for i := 0; i < params.Len(); i++ {
pn := paramName(params, i)
g.genCToJava("_"+pn, pn, params.At(i).Type(), modeTransient)
}
if res.Len() > 0 && !isErrorType(res.At(0).Type()) {
t := res.At(0).Type()
g.Printf("%s res = (*env)->Call%sMethod(env, o, ", g.jniType(t), g.jniCallType(t))
} else {
g.Printf("(*env)->CallVoidMethod(env, o, ")
}
g.Printf("mid_%s_%s", oName, m.Name())
for i := 0; i < params.Len(); i++ {
g.Printf(", _%s", paramName(params, i))
}
g.Printf(");\n")
var retName string
if res.Len() > 0 {
var rets []string
t := res.At(0).Type()
if !isErrorType(t) {
g.genJavaToC("res", t, modeRetained)
retName = "_res"
rets = append(rets, retName)
}
if res.Len() == 2 || isErrorType(t) {
g.Printf("jstring exc = go_seq_get_exception_message(env);\n")
st := types.Typ[types.String]
g.genJavaToC("exc", st, modeRetained)
retName = "_exc"
rets = append(rets, "_exc")
}
if res.Len() > 1 {
g.Printf("cproxy%s_%s_%s_return sres = {\n", g.pkgPrefix, oName, m.Name())
g.Printf(" %s\n", strings.Join(rets, ", "))
g.Printf("};\n")
retName = "sres"
}
}
g.Printf("go_seq_pop_local_frame(env);\n")
if retName != "" {
g.Printf("return %s;\n", retName)
}
g.Outdent()
g.Printf("}\n\n")
}
示例6: emitFunc
func (w *Walker) emitFunc(f *types.Func) {
sig := f.Type().(*types.Signature)
if sig.Recv() != nil {
panic("method considered a regular function: " + f.String())
}
w.emitf("func %s%s", f.Name(), w.signatureString(sig))
}
示例7: genFunc
func (g *javaGen) genFunc(o *types.Func, method bool) {
if err := g.funcSignature(o, !method); err != nil {
g.errorf("%v", err)
return
}
sig := o.Type().(*types.Signature)
res := sig.Results()
g.Printf(" {\n")
g.Indent()
g.Printf("go.Seq _in = null;\n")
g.Printf("go.Seq _out = null;\n")
returnsError := false
var resultType types.Type
if res.Len() > 0 {
if !isErrorType(res.At(0).Type()) {
resultType = res.At(0).Type()
}
if res.Len() > 1 || isErrorType(res.At(0).Type()) {
returnsError = true
}
}
if resultType != nil || returnsError {
g.Printf("_out = new go.Seq();\n")
}
if resultType != nil {
t := g.javaType(resultType)
g.Printf("%s _result;\n", t)
}
params := sig.Params()
if method || params.Len() > 0 {
g.Printf("_in = new go.Seq();\n")
}
if method {
g.Printf("_in.writeRef(ref);\n")
}
for i := 0; i < params.Len(); i++ {
p := params.At(i)
g.Printf("_in.write%s;\n", seqWrite(p.Type(), paramName(params, i)))
}
g.Printf("Seq.send(DESCRIPTOR, CALL_%s, _in, _out);\n", o.Name())
if resultType != nil {
g.genRead("_result", "_out", resultType)
}
if returnsError {
g.Printf(`String _err = _out.readString();
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
`)
}
if resultType != nil {
g.Printf("return _result;\n")
}
g.Outdent()
g.Printf("}\n\n")
}
示例8: GoProto
func GoProto(fn *types.Func) (string, string, string) {
pkgname := "package " + fn.Pkg().Name() + "\n"
imports := ""
signature := fn.Type().(*types.Signature)
sig := strings.TrimPrefix(signature.String(), "func(")
fnproto := "func " + fn.Name() + "(" + sig + "\n"
return pkgname, imports, fnproto
}
示例9: genMethodInterfaceProxy
func (g *JavaGen) genMethodInterfaceProxy(oName string, m *types.Func) {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s with unsupported parameter or return types\n\n", oName)
return
}
sig := m.Type().(*types.Signature)
params := sig.Params()
res := sig.Results()
g.genInterfaceMethodSignature(m, oName, false, g.paramName)
g.Indent()
g.Printf("JNIEnv *env = go_seq_push_local_frame(%d);\n", params.Len())
g.Printf("jobject o = go_seq_from_refnum(env, refnum, proxy_class_%s_%s, proxy_class_%s_%s_cons);\n", g.pkgPrefix, oName, g.pkgPrefix, oName)
for i := 0; i < params.Len(); i++ {
pn := g.paramName(params, i)
g.genCToJava("_"+pn, pn, params.At(i).Type(), modeTransient)
}
if res.Len() > 0 && !isErrorType(res.At(0).Type()) {
t := res.At(0).Type()
g.Printf("%s res = (*env)->Call%sMethod(env, o, ", g.jniType(t), g.jniCallType(t))
} else {
g.Printf("(*env)->CallVoidMethod(env, o, ")
}
g.Printf("mid_%s_%s", oName, m.Name())
for i := 0; i < params.Len(); i++ {
g.Printf(", _%s", g.paramName(params, i))
}
g.Printf(");\n")
var retName string
if res.Len() > 0 {
var rets []string
t := res.At(0).Type()
if !isErrorType(t) {
g.genJavaToC("res", t, modeRetained)
retName = "_res"
rets = append(rets, retName)
}
if res.Len() == 2 || isErrorType(t) {
g.Printf("jobject exc = go_seq_get_exception(env);\n")
errType := types.Universe.Lookup("error").Type()
g.genJavaToC("exc", errType, modeRetained)
retName = "_exc"
rets = append(rets, "_exc")
}
if res.Len() > 1 {
g.Printf("cproxy%s_%s_%s_return sres = {\n", g.pkgPrefix, oName, m.Name())
g.Printf(" %s\n", strings.Join(rets, ", "))
g.Printf("};\n")
retName = "sres"
}
}
g.Printf("go_seq_pop_local_frame(env);\n")
if retName != "" {
g.Printf("return %s;\n", retName)
}
g.Outdent()
g.Printf("}\n\n")
}
示例10: genJNIFuncBody
func (g *JavaGen) genJNIFuncBody(o *types.Func, sName string, jm *java.Func, isjava bool) {
sig := o.Type().(*types.Signature)
res := sig.Results()
if sName != "" {
g.Printf("int32_t o = go_seq_to_refnum_go(env, __this__);\n")
}
params := sig.Params()
first := 0
if isjava && params.Len() > 0 && params.At(0).Name() == "this" {
// Start after the implicit this argument.
first = 1
g.Printf("int32_t _%s = go_seq_to_refnum(env, __this__);\n", g.paramName(params, 0))
}
for i := first; i < params.Len(); i++ {
name := g.paramName(params, i)
g.genJavaToC(name, params.At(i).Type(), modeTransient)
}
resPrefix := ""
if res.Len() > 0 {
if res.Len() == 1 {
g.Printf("%s r0 = ", g.cgoType(res.At(0).Type()))
} else {
resPrefix = "res."
g.Printf("struct proxy%s_%s_%s_return res = ", g.pkgPrefix, sName, o.Name())
}
}
g.Printf("proxy%s_%s_%s(", g.pkgPrefix, sName, o.Name())
if sName != "" {
g.Printf("o")
}
// Pass all arguments, including the implicit this argument.
for i := 0; i < params.Len(); i++ {
if i > 0 || sName != "" {
g.Printf(", ")
}
g.Printf("_%s", g.paramName(params, i))
}
g.Printf(");\n")
for i := first; i < params.Len(); i++ {
g.genRelease(g.paramName(params, i), params.At(i).Type(), modeTransient)
}
for i := 0; i < res.Len(); i++ {
tn := fmt.Sprintf("_r%d", i)
t := res.At(i).Type()
g.genCToJava(tn, fmt.Sprintf("%sr%d", resPrefix, i), t, modeRetained)
}
// Go backwards so that any exception is thrown before
// the return.
for i := res.Len() - 1; i >= 0; i-- {
t := res.At(i).Type()
if !isErrorType(t) {
g.Printf("return _r%d;\n", i)
} else {
g.Printf("go_seq_maybe_throw_exception(env, _r%d);\n", i)
}
}
}
示例11: genFuncH
func (g *ObjcGen) genFuncH(obj *types.Func) {
if !g.isSigSupported(obj.Type()) {
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", obj.Name())
return
}
if s := g.funcSummary(nil, obj); s != nil {
g.Printf("FOUNDATION_EXPORT %s;\n", s.asFunc(g))
}
}
示例12: lookupMethod
// lookupMethod returns the method set for type typ, which may be one
// of the interpreter's fake types.
func lookupMethod(i *interpreter, typ types.Type, meth *types.Func) *ssa.Function {
switch typ {
case rtypeType:
return i.rtypeMethods[meth.Id()]
case errorType:
return i.errorMethods[meth.Id()]
}
return i.prog.LookupMethod(typ, meth.Pkg(), meth.Name())
}
示例13: genFunc
func (g *goGen) genFunc(o *types.Func) {
if !g.isSigSupported(o.Type()) {
g.Printf("// skipped function %s with unsupported parameter or result types\n", o.Name())
return
}
g.genFuncSignature(o, "")
g.Indent()
g.genFuncBody(o, g.pkgName(g.Pkg))
g.Outdent()
g.Printf("}\n\n")
}
示例14: printFunc
func (p *printer) printFunc(recvType types.Type, obj *types.Func) {
p.print("func ")
sig := obj.Type().(*types.Signature)
if recvType != nil {
p.print("(")
p.writeType(p.pkg, recvType)
p.print(") ")
}
p.print(obj.Name())
p.writeSignature(p.pkg, sig)
}
示例15: genFuncSignature
func (g *javaGen) genFuncSignature(o *types.Func, static, header bool) {
sig := o.Type().(*types.Signature)
res := sig.Results()
var returnsError bool
var ret string
switch res.Len() {
case 2:
if !isErrorType(res.At(1).Type()) {
g.errorf("second result value must be of type error: %s", o)
return
}
returnsError = true
ret = g.javaType(res.At(0).Type())
case 1:
if isErrorType(res.At(0).Type()) {
returnsError = true
ret = "void"
} else {
ret = g.javaType(res.At(0).Type())
}
case 0:
ret = "void"
default:
g.errorf("too many result values: %s", o)
return
}
g.Printf("public ")
if static {
g.Printf("static ")
}
if !header {
g.Printf("native ")
}
oName := o.Name()
g.Printf("%s %s(", ret, oName)
params := sig.Params()
for i := 0; i < params.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
v := sig.Params().At(i)
name := paramName(params, i)
jt := g.javaType(v.Type())
g.Printf("%s %s", jt, name)
}
g.Printf(")")
if returnsError {
g.Printf(" throws Exception")
}
g.Printf(";\n")
}