本文整理汇总了Golang中go/types.Tuple.Len方法的典型用法代码示例。如果您正苦于以下问题:Golang Tuple.Len方法的具体用法?Golang Tuple.Len怎么用?Golang Tuple.Len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Tuple
的用法示例。
在下文中一共展示了Tuple.Len方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tuplesCompatibleExtra
func tuplesCompatibleExtra(p1, p2 *types.Tuple, typeDirection cmp) []*types.Var {
len1 := p1.Len()
len2 := p2.Len()
if len1 > len2 {
return nil
}
vars := make([]*types.Var, len2-len1)
for i := 0; i < len2; i++ {
if i >= len1 {
v2 := p2.At(i)
vars[i-len1] = v2
continue
}
v1 := p1.At(i)
v2 := p2.At(i)
c := cmpTypes(v1.Type(), v2.Type())
if c == cmpEqual || c == typeDirection {
continue
}
return nil
}
return vars
}
示例2: tuple
func (p *exporter) tuple(t *types.Tuple) {
n := t.Len()
p.int(n)
for i := 0; i < n; i++ {
p.param(t.At(i))
}
}
示例3: newVarsFrom
func newVarsFrom(p *Package, tuple *types.Tuple) []*Var {
vars := make([]*Var, 0, tuple.Len())
for i := 0; i < tuple.Len(); i++ {
vars = append(vars, newVarFrom(p, tuple.At(i)))
}
return vars
}
示例4: toList
func toList(t *types.Tuple) []*types.Var {
var r []*types.Var
for i := 0; i < t.Len(); i++ {
r = append(r, t.At(i))
}
return r
}
示例5: tupleToSlice
func tupleToSlice(tu *types.Tuple) []Type {
ts := []Type{}
for i := 0; i < tu.Len(); i++ {
v := tu.At(i)
ts = append(ts, encodeType(v.Type()))
}
return ts
}
示例6: listTypes
func (m Method) listTypes(t *types.Tuple) []string {
num := t.Len()
list := make([]string, num)
for i := 0; i < num; i++ {
list[i] = types.TypeString(t.At(i).Type(), m.gen.qf)
}
return list
}
示例7: tupleContains
func tupleContains(tuple *types.Tuple, v *types.Var) bool {
for i := 0; i < tuple.Len(); i++ {
if tuple.At(i) == v {
return true
}
}
return false
}
示例8: hashTuple
func (h Hasher) hashTuple(tuple *types.Tuple) uint32 {
// See go/types.identicalTypes for rationale.
n := tuple.Len()
var hash uint32 = 9137 + 2*uint32(n)
for i := 0; i < n; i++ {
hash += 3 * h.Hash(tuple.At(i).Type())
}
return hash
}
示例9: processTuple
func (sym *symtab) processTuple(tuple *types.Tuple) {
if tuple == nil {
return
}
for i := 0; i < tuple.Len(); i++ {
ivar := tuple.At(i)
ityp := ivar.Type()
isym := sym.symtype(ityp)
if isym == nil {
sym.addType(ivar, ityp)
}
}
}
示例10: convertTuple
func (c *converter) convertTuple(v *gotypes.Tuple, conv func(*gotypes.Var) *types.Var) *types.Tuple {
if v == nil {
return nil
}
if v, ok := c.converted[v]; ok {
return v.(*types.Tuple)
}
vars := make([]*types.Var, 0, v.Len())
for i := 0; i < v.Len(); i++ {
vars = append(vars, conv(v.At(i)))
}
ret := types.NewTuple(vars...)
c.converted[v] = ret
return ret
}
示例11: writeParams
func (w *Walker) writeParams(buf *bytes.Buffer, t *types.Tuple, variadic bool) {
buf.WriteByte('(')
for i, n := 0, t.Len(); i < n; i++ {
if i > 0 {
buf.WriteString(", ")
}
typ := t.At(i).Type()
if variadic && i+1 == n {
buf.WriteString("...")
typ = typ.(*types.Slice).Elem()
}
w.writeType(buf, typ)
}
buf.WriteByte(')')
}
示例12: writeTuple
func (p *printer) writeTuple(this *types.Package, tup *types.Tuple, variadic bool, visited []types.Type) {
p.print("(")
for i, n := 0, tup.Len(); i < n; i++ {
if i > 0 {
p.print(", ")
}
v := tup.At(i)
if name := v.Name(); name != "" {
p.print(name)
p.print(" ")
}
typ := v.Type()
if variadic && i == n-1 {
p.print("...")
typ = typ.(*types.Slice).Elem()
}
p.writeTypeInternal(this, typ, visited)
}
p.print(")")
}
示例13: paramList
func (p *exporter) paramList(params *types.Tuple, variadic bool) {
// use negative length to indicate unnamed parameters
// (look at the first parameter only since either all
// names are present or all are absent)
n := params.Len()
if n > 0 && params.At(0).Name() == "" {
n = -n
}
p.int(n)
for i := 0; i < params.Len(); i++ {
q := params.At(i)
t := q.Type()
if variadic && i == params.Len()-1 {
t = &dddSlice{t.(*types.Slice).Elem()}
}
p.typ(t)
if n > 0 {
name := q.Name()
p.string(name)
if name != "_" {
p.pkg(q.Pkg(), false)
}
}
p.string("") // no compiler-specific info
}
}