本文整理汇总了Golang中code/google/com/p/go/tools/go/types.Signature类的典型用法代码示例。如果您正苦于以下问题:Golang Signature类的具体用法?Golang Signature怎么用?Golang Signature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Signature类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: evalCallArgs
func (c *compiler) evalCallArgs(ftype *types.Signature, args []ast.Expr) []Value {
var argValues []Value
if len(args) == 0 {
return argValues
}
arg0 := args[0]
if _, ok := c.types.expr[arg0].Type.(*types.Tuple); ok {
// f(g(...)), where g is multi-value return
argValues = c.destructureExpr(args[0])
} else {
argValues = make([]Value, len(args))
for i, x := range args {
var paramtyp types.Type
params := ftype.Params()
if ftype.IsVariadic() && i >= int(params.Len()-1) {
paramtyp = params.At(int(params.Len() - 1)).Type()
} else {
paramtyp = params.At(i).Type()
}
c.convertUntyped(x, paramtyp)
argValues[i] = c.VisitExpr(x)
}
}
return argValues
}
开发者ID:hzmangel,项目名称:llgo,代码行数:25,代码来源:expr.go
示例2: makeFunc
func (c *compiler) makeFunc(ident *ast.Ident, ftyp *types.Signature) *LLVMValue {
fname := ident.String()
if ftyp.Recv() == nil && fname == "init" {
// Make "init" functions anonymous.
fname = ""
} else {
var pkgname string
if recv := ftyp.Recv(); recv != nil {
var recvname string
switch recvtyp := recv.Type().(type) {
case *types.Pointer:
if named, ok := recvtyp.Elem().(*types.Named); ok {
obj := named.Obj()
recvname = "*" + obj.Name()
pkgname = obj.Pkg().Path()
}
case *types.Named:
named := recvtyp
obj := named.Obj()
recvname = obj.Name()
pkgname = obj.Pkg().Path()
}
if recvname != "" {
fname = fmt.Sprintf("%s.%s", recvname, fname)
} else {
// If the receiver is an unnamed struct, we're
// synthesising a method for an unnamed struct
// type. There's no meaningful name to give the
// function, so leave it up to LLVM.
fname = ""
}
} else {
obj := c.typeinfo.Objects[ident]
pkgname = obj.Pkg().Path()
}
if fname != "" {
fname = pkgname + "." + fname
}
}
// gcimporter may produce multiple AST objects for the same function.
llvmftyp := c.types.ToLLVM(ftyp)
var fn llvm.Value
if fname != "" {
fn = c.module.Module.NamedFunction(fname)
}
if fn.IsNil() {
llvmfptrtyp := llvmftyp.StructElementTypes()[0].ElementType()
fn = llvm.AddFunction(c.module.Module, fname, llvmfptrtyp)
}
fn = llvm.ConstInsertValue(llvm.ConstNull(llvmftyp), fn, []uint32{0})
return c.NewValue(fn, ftyp)
}
开发者ID:qioixiy,项目名称:llgo,代码行数:54,代码来源:decl.go
示例3: writeSignature
// writeSignature writes to buf the signature sig in declaration syntax.
func writeSignature(buf *bytes.Buffer, pkg *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(" ")
}
buf.WriteString(relType(params[0].Type(), pkg))
buf.WriteString(") ")
}
buf.WriteString(name)
types.WriteSignature(buf, pkg, sig)
}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:15,代码来源:func.go
示例4: signature
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)
}
}
开发者ID:4honor,项目名称:obdi,代码行数:28,代码来源:export.go
示例5: funcRuntimeType
func (tm *TypeMap) funcRuntimeType(f *types.Signature) (global, ptr llvm.Value) {
rtype := tm.makeRtype(f, reflect.Func)
funcType := llvm.ConstNull(tm.runtimeFuncType)
funcType = llvm.ConstInsertValue(funcType, rtype, []uint32{0})
// dotdotdot
if f.IsVariadic() {
variadic := llvm.ConstInt(llvm.Int1Type(), 1, false)
funcType = llvm.ConstInsertValue(funcType, variadic, []uint32{1})
}
// TODO in
//funcType = llvm.ConstInsertValue(funcType, tm.ToRuntime(p.Elt()), []uint32{2})
// TODO out
//funcType = llvm.ConstInsertValue(funcType, tm.ToRuntime(p.Elt()), []uint32{3})
return tm.makeRuntimeTypeGlobal(funcType)
}
开发者ID:hzmangel,项目名称:llgo,代码行数:15,代码来源:typemap.go
示例6: changeRecv
// changeRecv returns sig with Recv prepended to Params().
func changeRecv(sig *types.Signature) *types.Signature {
params := sig.Params()
n := params.Len()
p2 := make([]*types.Var, n+1)
p2[0] = sig.Recv()
for i := 0; i < n; i++ {
p2[i+1] = params.At(i)
}
return types.NewSignature(nil, nil, types.NewTuple(p2...), sig.Results(), sig.IsVariadic())
}
开发者ID:ufo22940268,项目名称:two-server-others,代码行数:11,代码来源:reflect.go
示例7: evalCallArgs
func (c *compiler) evalCallArgs(ftype *types.Signature, args []ast.Expr, dotdotdot bool) []Value {
var argValues []Value
if len(args) == 0 {
return argValues
}
var argtypes []types.Type
if t, ok := c.typeinfo.Types[args[0]].(*types.Tuple); ok {
argtypes = make([]types.Type, t.Len())
} else {
argtypes = make([]types.Type, len(args))
}
params := ftype.Params()
for i := range argtypes {
if ftype.IsVariadic() && i >= int(params.Len()-1) {
argtypes[i] = params.At(int(params.Len() - 1)).Type()
argtypes[i] = argtypes[i].(*types.Slice).Elem()
} else {
argtypes[i] = params.At(i).Type()
}
}
if len(argtypes) > len(args) {
// f(g(...)), where g is multi-value return
argValues = c.destructureExpr(args[0])
} else {
argValues = make([]Value, len(args))
for i, x := range args {
c.convertUntyped(x, argtypes[i])
argValues[i] = c.VisitExpr(x)
}
}
for i, v := range argValues {
if !dotdotdot || i < int(params.Len()-1) {
argValues[i] = v.Convert(argtypes[i])
}
}
return argValues
}
开发者ID:quarnster,项目名称:llgo,代码行数:41,代码来源:expr.go
示例8: signature
func (cdd *CDD) signature(sig *types.Signature, recv bool, pnames int) (res results, params string) {
params = "("
res = cdd.results(sig.Results())
if r := sig.Recv(); r != nil && recv {
typ, dim, acds := cdd.TypeStr(r.Type())
res.acds = append(res.acds, acds...)
var pname string
switch pnames {
case numNames:
pname = "_0"
case orgNames:
pname = cdd.NameStr(r, true)
}
if pname == "" {
params += typ + dimFuncPtr("", dim)
} else {
params += typ + " " + dimFuncPtr(pname, dim)
}
if sig.Params() != nil {
params += ", "
}
}
if p := sig.Params(); p != nil {
for i, n := 0, p.Len(); i < n; i++ {
if i != 0 {
params += ", "
}
v := p.At(i)
typ, dim, acds := cdd.TypeStr(v.Type())
res.acds = append(res.acds, acds...)
var pname string
switch pnames {
case numNames:
pname = "_" + strconv.Itoa(i+1)
case orgNames:
pname = cdd.NameStr(v, true)
if pname == "_$" {
pname = "unused" + cdd.gtc.uniqueId()
}
}
if pname == "" {
params += typ + dimFuncPtr("", dim)
} else {
params += typ + " " + dimFuncPtr(pname, dim)
}
}
}
params += ")"
return
}
开发者ID:rjammala,项目名称:emgo,代码行数:50,代码来源:type.go
示例9: translateArgs
func (c *funcContext) translateArgs(sig *types.Signature, args []ast.Expr, ellipsis bool) []string {
params := make([]string, sig.Params().Len())
for i := range params {
if sig.Variadic() && i == len(params)-1 && !ellipsis {
varargType := sig.Params().At(i).Type().(*types.Slice)
varargs := make([]string, len(args)-i)
for j, arg := range args[i:] {
varargs[j] = c.translateImplicitConversionWithCloning(arg, varargType.Elem()).String()
}
params[i] = fmt.Sprintf("new %s([%s])", c.typeName(varargType), strings.Join(varargs, ", "))
break
}
argType := sig.Params().At(i).Type()
params[i] = c.translateImplicitConversionWithCloning(args[i], argType).String()
}
return params
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:17,代码来源:utils.go
示例10: translateArgs
func (c *PkgContext) translateArgs(sig *types.Signature, args []ast.Expr, ellipsis bool) string {
params := make([]string, sig.Params().Len())
for i := range params {
if sig.IsVariadic() && i == len(params)-1 && !ellipsis {
varargType := sig.Params().At(i).Type().(*types.Slice)
varargs := make([]string, len(args)-i)
for j, arg := range args[i:] {
varargs[j] = c.translateExprToType(arg, varargType.Elem())
}
params[i] = fmt.Sprintf("new %s(%s)", c.typeName(varargType), createListComposite(varargType.Elem(), varargs))
break
}
argType := sig.Params().At(i).Type()
params[i] = c.translateExprToType(args[i], argType)
}
return strings.Join(params, ", ")
}
开发者ID:umisama,项目名称:gopherjs,代码行数:17,代码来源:package.go
示例11: writeSignature
func (w *Walker) writeSignature(buf *bytes.Buffer, sig *types.Signature) {
w.writeParams(buf, sig.Params(), sig.IsVariadic())
switch res := sig.Results(); res.Len() {
case 0:
// nothing to do
case 1:
buf.WriteByte(' ')
w.writeType(buf, res.At(0).Type())
default:
buf.WriteByte(' ')
w.writeParams(buf, res, false)
}
}
开发者ID:bryanxu,项目名称:go-zh,代码行数:13,代码来源:goapi.go
示例12: writeSignature
// writeSignature writes to w the signature sig in declaration syntax.
// Derived from types.Signature.String().
//
func writeSignature(w io.Writer, name string, sig *types.Signature, params []*Parameter) {
io.WriteString(w, "func ")
if recv := sig.Recv(); recv != nil {
io.WriteString(w, "(")
if n := params[0].Name(); n != "" {
io.WriteString(w, n)
io.WriteString(w, " ")
}
io.WriteString(w, params[0].Type().String())
io.WriteString(w, ") ")
params = params[1:]
}
io.WriteString(w, name)
io.WriteString(w, "(")
for i, v := range params {
if i > 0 {
io.WriteString(w, ", ")
}
io.WriteString(w, v.Name())
io.WriteString(w, " ")
if sig.IsVariadic() && i == len(params)-1 {
io.WriteString(w, "...")
io.WriteString(w, v.Type().Underlying().(*types.Slice).Elem().String())
} else {
io.WriteString(w, v.Type().String())
}
}
io.WriteString(w, ")")
if n := sig.Results().Len(); n > 0 {
io.WriteString(w, " ")
r := sig.Results()
if n == 1 && r.At(0).Name() == "" {
io.WriteString(w, r.At(0).Type().String())
} else {
io.WriteString(w, r.String())
}
}
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:41,代码来源:func.go
示例13: signature
func (p *exporter) signature(sig *types.Signature) {
// TODO(gri) We only need to record the receiver type
// for interface methods if we flatten them
// out. If we track embedded types instead,
// the information is already present.
// We do need the receiver information (T vs *T)
// for methods associated with named types.
if recv := sig.Recv(); recv != nil {
// 1-element tuple
p.int(1)
p.param(recv)
} 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)
}
}
开发者ID:hackrole,项目名称:daily-program,代码行数:23,代码来源:export.go
示例14: Visit
func (v funcTypeVisitor) Visit(node ast.Node) ast.Visitor {
var sig *types.Signature
var noderecv *ast.FieldList
var astfunc *ast.FuncType
switch node := node.(type) {
case *ast.FuncDecl:
sig = v.objects[node.Name].Type().(*types.Signature)
astfunc = node.Type
noderecv = node.Recv
case *ast.FuncLit:
sig = v.exprtypes[node].Type.(*types.Signature)
astfunc = node.Type
default:
return v
}
// go/types creates a separate types.Var for
// internal and external usage. We need to
// associate them at the object data level.
paramIdents := fieldlistIdents(astfunc.Params)
resultIdents := fieldlistIdents(astfunc.Results)
if recv := sig.Recv(); recv != nil {
id := fieldlistIdents(noderecv)[0]
if obj, ok := v.objects[id]; ok {
v.objectdata[recv] = v.objectdata[obj]
}
}
for i, id := range paramIdents {
if obj, ok := v.objects[id]; ok {
v.objectdata[sig.Params().At(i)] = v.objectdata[obj]
}
}
for i, id := range resultIdents {
if obj, ok := v.objects[id]; ok {
v.objectdata[sig.Results().At(i)] = v.objectdata[obj]
}
}
return v
}
开发者ID:hzmangel,项目名称:llgo,代码行数:40,代码来源:check.go
示例15: funcRuntimeType
func (tm *TypeMap) funcRuntimeType(f *types.Signature) (global, ptr llvm.Value) {
rtype := tm.makeRtype(f, reflect.Func)
funcType := llvm.ConstNull(tm.runtime.funcType.llvm)
global, ptr = tm.makeRuntimeTypeGlobal(funcType, typeString(f))
tm.types.Set(f, runtimeTypeInfo{global, ptr})
funcType = llvm.ConstInsertValue(funcType, rtype, []uint32{0})
// dotdotdot
if f.Variadic() {
variadic := llvm.ConstInt(llvm.Int1Type(), 1, false)
funcType = llvm.ConstInsertValue(funcType, variadic, []uint32{1})
}
// in
intypes := tm.rtypeSlice(f.Params())
funcType = llvm.ConstInsertValue(funcType, intypes, []uint32{2})
// out
outtypes := tm.rtypeSlice(f.Results())
funcType = llvm.ConstInsertValue(funcType, outtypes, []uint32{3})
global.SetInitializer(funcType)
return global, ptr
}
开发者ID:minux,项目名称:llgo,代码行数:20,代码来源:typemap.go
示例16: writeSignatureInternal
func (p *printer) writeSignatureInternal(this *types.Package, sig *types.Signature, visited []types.Type) {
p.writeTuple(this, sig.Params(), sig.Variadic(), visited)
res := sig.Results()
n := res.Len()
if n == 0 {
// no result
return
}
p.print(" ")
if n == 1 && res.At(0).Name() == "" {
// single unnamed result
p.writeTypeInternal(this, res.At(0).Type(), visited)
return
}
// multiple or named result(s)
p.writeTuple(this, res, false, visited)
}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:20,代码来源:writetype.go
示例17: writeSignature
func (ts *TypeStringer) writeSignature(buf *bytes.Buffer, sig *types.Signature, unique bool) {
if recv := sig.Recv(); recv != nil {
if _, ok := recv.Type().Underlying().(*types.Interface); !ok {
ts.writeType(buf, recv.Type(), unique)
buf.WriteByte(' ')
}
}
ts.writeParams(buf, sig.Params(), sig.IsVariadic(), unique)
if sig.Results().Len() == 0 {
// no result
return
}
buf.WriteByte(' ')
if sig.Results().Len() == 1 {
// single unnamed result
ts.writeType(buf, sig.Results().At(0).Type(), unique)
return
}
// multiple or named result(s)
ts.writeParams(buf, sig.Results(), false, unique)
}
开发者ID:qioixiy,项目名称:llgo,代码行数:24,代码来源:types.go
示例18: call
func (f *Finder) call(sig *types.Signature, args []ast.Expr) {
if len(args) == 0 {
return
}
// Ellipsis call? e.g. f(x, y, z...)
if _, ok := args[len(args)-1].(*ast.Ellipsis); ok {
for i, arg := range args {
// The final arg is a slice, and so is the final param.
f.assign(sig.Params().At(i).Type(), f.expr(arg))
}
return
}
var argtypes []types.Type
// Gather the effective actual parameter types.
if tuple, ok := f.info.Types[args[0]].Type.(*types.Tuple); ok {
// f(g()) call where g has multiple results?
f.expr(args[0])
// unpack the tuple
for i := 0; i < tuple.Len(); i++ {
argtypes = append(argtypes, tuple.At(i).Type())
}
} else {
for _, arg := range args {
argtypes = append(argtypes, f.expr(arg))
}
}
// Assign the actuals to the formals.
if !sig.Variadic() {
for i, argtype := range argtypes {
f.assign(sig.Params().At(i).Type(), argtype)
}
} else {
// The first n-1 parameters are assigned normally.
nnormals := sig.Params().Len() - 1
for i, argtype := range argtypes[:nnormals] {
f.assign(sig.Params().At(i).Type(), argtype)
}
// Remaining args are assigned to elements of varargs slice.
tElem := sig.Params().At(nnormals).Type().(*types.Slice).Elem()
for i := nnormals; i < len(argtypes); i++ {
f.assign(tElem, argtypes[i])
}
}
}
开发者ID:bryanxu,项目名称:go-zh.tools,代码行数:48,代码来源:find.go
示例19: writeSignature
func (ts *TypeStringer) writeSignature(buf *bytes.Buffer, sig *types.Signature) {
if recv := sig.Recv(); recv != nil {
ts.writeType(buf, recv.Type())
buf.WriteByte(' ')
}
ts.writeParams(buf, sig.Params(), sig.IsVariadic())
if sig.Results().Len() == 0 {
// no result
return
}
buf.WriteByte(' ')
if sig.Results().Len() == 1 {
// single unnamed result
ts.writeType(buf, sig.Results().At(0).Type())
return
}
// multiple or named result(s)
ts.writeParams(buf, sig.Results(), false)
}
开发者ID:hzmangel,项目名称:llgo,代码行数:22,代码来源:types.go
示例20: funcLLVMType
func (tm *LLVMTypeMap) funcLLVMType(tstr string, f *types.Signature) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
// If there's a receiver change the receiver to an
// additional (first) parameter, and take the value of
// the resulting signature instead.
var param_types []llvm.Type
if recv := f.Recv(); recv != nil {
params := f.Params()
paramvars := make([]*types.Var, int(params.Len()+1))
paramvars[0] = recv
for i := 0; i < int(params.Len()); i++ {
paramvars[i+1] = params.At(i)
}
params = types.NewTuple(paramvars...)
f := types.NewSignature(nil, params, f.Results(), f.IsVariadic())
return tm.ToLLVM(f)
}
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
params := f.Params()
nparams := int(params.Len())
for i := 0; i < nparams; i++ {
typ := params.At(i).Type()
if f.IsVariadic() && i == nparams-1 {
typ = types.NewSlice(typ)
}
llvmtyp := tm.ToLLVM(typ)
param_types = append(param_types, llvmtyp)
}
var return_type llvm.Type
results := f.Results()
switch nresults := int(results.Len()); nresults {
case 0:
return_type = llvm.VoidType()
case 1:
return_type = tm.ToLLVM(results.At(0).Type())
default:
elements := make([]llvm.Type, nresults)
for i := range elements {
result := results.At(i)
elements[i] = tm.ToLLVM(result.Type())
}
return_type = llvm.StructType(elements, false)
}
fntyp := llvm.FunctionType(return_type, param_types, false)
fnptrtyp := llvm.PointerType(fntyp, 0)
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
elements := []llvm.Type{fnptrtyp, i8ptr} // func, closure
typ.StructSetBody(elements, false)
}
return typ
}
开发者ID:hzmangel,项目名称:llgo,代码行数:57,代码来源:typemap.go
注:本文中的code/google/com/p/go/tools/go/types.Signature类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论