本文整理汇总了Golang中golang.org/x/tools/go/types.Slice类的典型用法代码示例。如果您正苦于以下问题:Golang Slice类的具体用法?Golang Slice怎么用?Golang Slice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Slice类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: descriptorSlice
func (d *DIBuilder) descriptorSlice(t *types.Slice, name string) llvm.Value {
sliceStruct := types.NewStruct([]*types.Var{
types.NewVar(0, nil, "ptr", types.NewPointer(t.Elem())),
types.NewVar(0, nil, "len", types.Typ[types.Int]),
types.NewVar(0, nil, "cap", types.Typ[types.Int]),
}, nil)
return d.typeDebugDescriptor(sliceStruct, name)
}
示例2: translateArgs
func (c *funcContext) translateArgs(sig *types.Signature, argExprs []ast.Expr, ellipsis, clone bool) []string {
if len(argExprs) == 1 {
if tuple, isTuple := c.p.TypeOf(argExprs[0]).(*types.Tuple); isTuple {
tupleVar := c.newVariable("_tuple")
c.Printf("%s = %s;", tupleVar, c.translateExpr(argExprs[0]))
argExprs = make([]ast.Expr, tuple.Len())
for i := range argExprs {
argExprs[i] = c.newIdent(c.formatExpr("%s[%d]", tupleVar, i).String(), tuple.At(i).Type())
}
}
}
paramsLen := sig.Params().Len()
var varargType *types.Slice
if sig.Variadic() && !ellipsis {
varargType = sig.Params().At(paramsLen - 1).Type().(*types.Slice)
}
preserveOrder := false
for i := 1; i < len(argExprs); i++ {
preserveOrder = preserveOrder || c.Blocking[argExprs[i]]
}
args := make([]string, len(argExprs))
for i, argExpr := range argExprs {
var argType types.Type
switch {
case varargType != nil && i >= paramsLen-1:
argType = varargType.Elem()
default:
argType = sig.Params().At(i).Type()
}
var arg string
switch {
case clone:
arg = c.translateImplicitConversionWithCloning(argExpr, argType).String()
default:
arg = c.translateImplicitConversion(argExpr, argType).String()
}
if preserveOrder && c.p.Types[argExpr].Value == nil {
argVar := c.newVariable("_arg")
c.Printf("%s = %s;", argVar, arg)
arg = argVar
}
args[i] = arg
}
if varargType != nil {
return append(args[:paramsLen-1], fmt.Sprintf("new %s([%s])", c.typeName(varargType), strings.Join(args[paramsLen-1:], ", ")))
}
return args
}
示例3: Slice
func Slice(path string, st reflect.StructTag, u *types.Slice) IObj {
und := u.Elem()
if p, ok := und.(*types.Pointer); ok {
und = p.Elem()
}
rv := ISlice{}
rv.name = strings.Split(st.Get("json"), ",")[0]
rv.typ = "[]" + typefmt(und)
rv.description = st.Get("description")
rv.path = pathAppend(path, rv.name)
c := dump(rv.path, und, reflect.StructTag(""))
if st, ok := c.(IStruct); ok {
rv.items = st.items
} else {
rv.valtyp = typefmt(und)
}
return rv
}