本文整理汇总了Golang中go/types.Func类的典型用法代码示例。如果您正苦于以下问题:Golang Func类的具体用法?Golang Func怎么用?Golang Func使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Func类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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")
}
开发者ID:stmuk,项目名称:mobile,代码行数:7,代码来源:gengo.go
示例2: 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
}
开发者ID:nickng,项目名称:dingo-hunter,代码行数:7,代码来源:call.go
示例3: identicalSansNames
// identicalSansNames compares two functions to check if their types are identical
// according to the names. e.g.
// - It does not care if the names of the parameters or return values differ
// - It does not care if the implementations of the types differ
func identicalSansNames(fa, fb *types.Func) bool {
// must always succeed
sigA := fa.Type().(*types.Signature)
sigB := fb.Type().(*types.Signature)
var (
lenParams = sigA.Params().Len()
lenResults = sigA.Results().Len()
)
if sigB.Params().Len() != lenParams {
return false
}
if sigB.Results().Len() != lenResults {
return false
}
for i := 0; i < lenParams; i++ {
if types.TypeString(sigA.Params().At(i).Type(), nil) != types.TypeString(sigB.Params().At(i).Type(), nil) {
return false
}
}
for i := 0; i < lenResults; i++ {
if types.TypeString(sigA.Results().At(i).Type(), nil) != types.TypeString(sigB.Results().At(i).Type(), nil) {
return false
}
}
return true
}
开发者ID:motemen,项目名称:gompatible,代码行数:36,代码来源:func.go
示例4: 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")
}
开发者ID:Christeefym,项目名称:lantern,代码行数:59,代码来源:genjava.go
示例5: isCallable
func isCallable(t *types.Func) bool {
// TODO(crawshaw): functions that are not implementable from
// another language may still be callable (for example, a
// returned value with an unexported type can be treated as
// an opaque value by the caller). This restriction could be
// lifted.
return isImplementable(t.Type().(*types.Signature))
}
开发者ID:pankona,项目名称:mobile,代码行数:8,代码来源:types.go
示例6: 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))
}
}
开发者ID:pankona,项目名称:mobile,代码行数:9,代码来源:genobjc.go
示例7: addFunction
func (b *Builder) addFunction(u types.Universe, useName *types.Name, in *tc.Func) *types.Type {
name := tcFuncNameToName(in.String())
if useName != nil {
name = *useName
}
out := u.Function(name)
out.Kind = types.DeclarationOf
out.Underlying = b.walkType(u, nil, in.Type())
return out
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:10,代码来源:parse.go
示例8: 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)
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:11,代码来源:print.go
示例9: 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")
}
开发者ID:pankona,项目名称:mobile,代码行数:11,代码来源:gengo.go
示例10: 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")
}
开发者ID:ych1,项目名称:mobile,代码行数:53,代码来源:genjava.go
示例11: getReturnVar
func getReturnVar(ctx Ctx, fn *types.Func) []*ssaRetVar {
signature := fn.Type().(*types.Signature)
if signature.Recv() != nil {
panic("methods unsupported (only functions are supported)")
}
var results []*ssaRetVar
for i := 0; i < signature.Results().Len(); i++ {
ret := signature.Results().At(i)
n := ssaRetVar{v: ret, ctx: ctx}
results = append(results, &n)
}
return results
}
开发者ID:bjwbell,项目名称:gir,代码行数:13,代码来源:builder.go
示例12: getParameters
func getParameters(ctx Ctx, fn *types.Func) []*ssaParam {
signature := fn.Type().(*types.Signature)
if signature.Recv() != nil {
panic("methods unsupported (only functions are supported)")
}
var params []*ssaParam
for i := 0; i < signature.Params().Len(); i++ {
param := signature.Params().At(i)
n := ssaParam{v: param, ctx: ctx}
params = append(params, &n)
}
return params
}
开发者ID:bjwbell,项目名称:gir,代码行数:13,代码来源:builder.go
示例13: genFuncSignature
func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis 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("%s ", ret)
if jm != nil {
g.Printf(jm.Name)
} else {
g.Printf(javaNameReplacer(lowerFirst(o.Name())))
}
g.Printf("(")
g.genFuncArgs(o, jm, hasThis)
g.Printf(")")
if returnsError {
if jm != nil {
if jm.Throws == "" {
g.errorf("%s declares an error return value but the overriden method does not throw", o)
return
}
g.Printf(" throws %s", jm.Throws)
} else {
g.Printf(" throws Exception")
}
}
g.Printf(";\n")
}
开发者ID:pankona,项目名称:mobile,代码行数:50,代码来源:genjava.go
示例14: 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")
}
开发者ID:ych1,项目名称:mobile,代码行数:60,代码来源:genjava.go
示例15: getLocalDecls
func getLocalDecls(ctx Ctx, fnDecl *ast.FuncDecl, fn *types.Func) []*ssaLocal {
scope := fn.Scope()
names := scope.Names()
var locals []*ssaLocal
for i := 0; i < len(names); i++ {
name := names[i]
obj := scope.Lookup(name)
if isParam(ctx, fn, obj) {
continue
}
node := ssaLocal{obj: obj, ctx: ctx}
locals = append(locals, &node)
}
return locals
}
开发者ID:bjwbell,项目名称:gir,代码行数:15,代码来源:builder.go
示例16: 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")
}
开发者ID:pankona,项目名称:mobile,代码行数:58,代码来源:genjava.go
示例17: genFuncBody
func (g *goGen) genFuncBody(o *types.Func, selectorLHS string) {
sig := o.Type().(*types.Signature)
params := sig.Params()
for i := 0; i < params.Len(); i++ {
p := params.At(i)
pn := "param_" + g.paramName(params, i)
g.genRead("_"+pn, pn, p.Type(), modeTransient)
}
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 values, and optionally an error")
return
}
if res.Len() > 0 {
for i := 0; i < res.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
g.Printf("res_%d", i)
}
g.Printf(" := ")
}
g.Printf("%s%s(", selectorLHS, o.Name())
for i := 0; i < params.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
g.Printf("_param_%s", g.paramName(params, i))
}
g.Printf(")\n")
for i := 0; i < res.Len(); i++ {
pn := fmt.Sprintf("res_%d", i)
g.genWrite("_"+pn, pn, res.At(i).Type(), modeRetained)
}
if res.Len() > 0 {
g.Printf("return ")
for i := 0; i < res.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
g.Printf("_res_%d", i)
}
g.Printf("\n")
}
}
开发者ID:pankona,项目名称:mobile,代码行数:48,代码来源:gengo.go
示例18: method
func (p *exporter) method(m *types.Func) {
sig := m.Type().(*types.Signature)
if sig.Recv() == nil {
log.Fatalf("gcimporter: method expected")
}
p.pos(m)
p.string(m.Name())
if m.Name() != "_" && !ast.IsExported(m.Name()) {
p.pkg(m.Pkg(), false)
}
// interface method; no need to encode receiver.
p.paramList(sig.Params(), sig.Variadic())
p.paramList(sig.Results(), false)
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:16,代码来源:bexport.go
示例19: 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())
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:11,代码来源:interp.go
示例20: genJNIFuncSignature
func (g *javaGen) genJNIFuncSignature(o *types.Func, sName string, proxy bool) {
sig := o.Type().(*types.Signature)
res := sig.Results()
var ret string
switch res.Len() {
case 2:
ret = g.jniType(res.At(0).Type())
case 1:
if isErrorType(res.At(0).Type()) {
ret = "void"
} else {
ret = g.jniType(res.At(0).Type())
}
case 0:
ret = "void"
default:
g.errorf("too many result values: %s", o)
return
}
g.Printf("JNIEXPORT %s JNICALL\n", ret)
g.Printf("Java_%s_%s", g.jniPkgName(), g.className())
if sName != "" {
// 0024 is the mangled form of $, for naming inner classes.
g.Printf("_00024")
if proxy {
g.Printf("proxy")
}
g.Printf("%s", sName)
}
g.Printf("_%s(JNIEnv* env, ", o.Name())
if sName != "" {
g.Printf("jobject this")
} else {
g.Printf("jclass clazz")
}
params := sig.Params()
for i := 0; i < params.Len(); i++ {
g.Printf(", ")
v := sig.Params().At(i)
name := paramName(params, i)
jt := g.jniType(v.Type())
g.Printf("%s %s", jt, name)
}
g.Printf(")")
}
开发者ID:ych1,项目名称:mobile,代码行数:47,代码来源:genjava.go
注:本文中的go/types.Func类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论