• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.Struct类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/tools/go/types.Struct的典型用法代码示例。如果您正苦于以下问题:Golang Struct类的具体用法?Golang Struct怎么用?Golang Struct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Struct类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: descriptorStruct

func (d *DIBuilder) descriptorStruct(t *types.Struct, name string) llvm.Value {
	fields := make([]*types.Var, t.NumFields())
	for i := range fields {
		fields[i] = t.Field(i)
	}
	offsets := d.sizes.Offsetsof(fields)
	members := make([]llvm.Value, len(fields))
	for i, f := range fields {
		// TODO(axw) file/line where member is defined.
		t := f.Type()
		members[i] = d.builder.CreateMemberType(d.cu, llvm.DIMemberType{
			Name:         f.Name(),
			Type:         d.DIType(t),
			SizeInBits:   uint64(d.sizes.Sizeof(t) * 8),
			AlignInBits:  uint64(d.sizes.Alignof(t) * 8),
			OffsetInBits: uint64(offsets[i] * 8),
		})
	}
	// TODO(axw) file/line where struct is defined.
	return d.builder.CreateStructType(d.cu, llvm.DIStructType{
		Name:        name,
		SizeInBits:  uint64(d.sizes.Sizeof(t) * 8),
		AlignInBits: uint64(d.sizes.Alignof(t) * 8),
		Elements:    members,
	})
}
开发者ID:hinike,项目名称:llgo,代码行数:26,代码来源:debug.go


示例2: loadStruct

func (c *funcContext) loadStruct(array, target string, s *types.Struct) string {
	view := c.newVariable("_view")
	code := fmt.Sprintf("%s = new DataView(%s.buffer, %s.byteOffset)", view, array, array)
	var fields []*types.Var
	var collectFields func(s *types.Struct, path string)
	collectFields = func(s *types.Struct, path string) {
		for i := 0; i < s.NumFields(); i++ {
			field := s.Field(i)
			if fs, isStruct := field.Type().Underlying().(*types.Struct); isStruct {
				collectFields(fs, path+"."+fieldName(s, i))
				continue
			}
			fields = append(fields, types.NewVar(0, nil, path+"."+fieldName(s, i), field.Type()))
		}
	}
	collectFields(s, target)
	offsets := sizes32.Offsetsof(fields)
	for i, field := range fields {
		switch t := field.Type().Underlying().(type) {
		case *types.Basic:
			if isNumeric(t) {
				if is64Bit(t) {
					code += fmt.Sprintf(", %s = new %s(%s.getUint32(%d, true), %s.getUint32(%d, true))", field.Name(), c.typeName(field.Type()), view, offsets[i]+4, view, offsets[i])
					break
				}
				code += fmt.Sprintf(", %s = %s.get%s(%d, true)", field.Name(), view, toJavaScriptType(t), offsets[i])
			}
		case *types.Array:
			code += fmt.Sprintf(`, %s = new ($nativeArray(%s))(%s.buffer, $min(%s.byteOffset + %d, %s.buffer.byteLength))`, field.Name(), typeKind(t.Elem()), array, array, offsets[i], array)
		}
	}
	return code
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:33,代码来源:expressions.go


示例3: fieldName

func fieldName(t *types.Struct, i int) string {
	name := t.Field(i).Name()
	if name == "_" || reservedKeywords[name] {
		return fmt.Sprintf("%s$%d", name, i)
	}
	return name
}
开发者ID:mcanthony,项目名称:gopherjs,代码行数:7,代码来源:utils.go


示例4: matchStructArgType

// matchStructArgType reports whether all the elements of the struct match the expected
// type. For instance, with "%d" all the elements must be printable with the "%d" format.
func (f *File) matchStructArgType(t printfArgType, typ *types.Struct, arg ast.Expr, inProgress map[types.Type]bool) bool {
	for i := 0; i < typ.NumFields(); i++ {
		if !f.matchArgTypeInternal(t, typ.Field(i).Type(), arg, inProgress) {
			return false
		}
	}
	return true
}
开发者ID:Lane391,项目名称:golangdemo,代码行数:10,代码来源:types.go


示例5: exportedFields

func exportedFields(T *types.Struct) []*types.Var {
	var fields []*types.Var
	for i := 0; i < T.NumFields(); i++ {
		f := T.Field(i)
		if !f.Exported() {
			continue
		}
		fields = append(fields, f)
	}
	return fields
}
开发者ID:sunqb,项目名称:mobile,代码行数:11,代码来源:gengo.go


示例6: genStruct

func (g *goGen) genStruct(obj *types.TypeName, typ *types.Struct) {
	//fmt.Printf("obj: %#v\ntyp: %#v\n", obj, typ)
	pkgname := obj.Pkg().Name()
	g.Printf("//export GoPy_%[1]s\n", obj.Name())
	g.Printf("type GoPy_%[1]s unsafe.Pointer\n\n", obj.Name())

	for i := 0; i < typ.NumFields(); i++ {
		f := typ.Field(i)
		if !f.Exported() {
			continue
		}

		ft := f.Type()
		ftname := g.qualifiedType(ft)
		if needWrapType(ft) {
			ftname = fmt.Sprintf("GoPy_%[1]s_field_%d", obj.Name(), i+1)
			g.Printf("//export %s\n", ftname)
			g.Printf("type %s unsafe.Pointer\n\n", ftname)
		}

		g.Printf("//export GoPy_%[1]s_getter_%[2]d\n", obj.Name(), i+1)
		g.Printf("func GoPy_%[1]s_getter_%[2]d(self GoPy_%[1]s) %[3]s {\n",
			obj.Name(), i+1,
			ftname,
		)
		g.Indent()
		g.Printf(
			"ret := (*%[1]s)(unsafe.Pointer(self))\n",
			pkgname+"."+obj.Name(),
		)

		if needWrapType(f.Type()) {
			dt := getTypedesc(f.Type())
			g.Printf("%s(unsafe.Pointer(&ret.%s))\n", dt.cgotype, f.Name())
		} else {
			g.Printf("return ret.%s\n", f.Name())
		}
		g.Outdent()
		g.Printf("}\n\n")
	}

	g.Printf("//export GoPy_%[1]s_new\n", obj.Name())
	g.Printf("func GoPy_%[1]s_new() GoPy_%[1]s {\n", obj.Name())
	g.Indent()
	g.Printf("return (GoPy_%[1]s)(unsafe.Pointer(&%[2]s.%[1]s{}))\n",
		obj.Name(),
		pkgname,
	)
	g.Outdent()
	g.Printf("}\n\n")
}
开发者ID:justinfx,项目名称:gopy,代码行数:51,代码来源:gengo.go


示例7: optimalSize

func optimalSize(str *types.Struct, sizes *gcSizes) int64 {
	nf := str.NumFields()
	fields := make([]*types.Var, nf)
	alignofs := make([]int64, nf)
	sizeofs := make([]int64, nf)
	for i := 0; i < nf; i++ {
		fields[i] = str.Field(i)
		ft := fields[i].Type()
		alignofs[i] = sizes.Alignof(ft)
		sizeofs[i] = sizes.Sizeof(ft)
	}
	sort.Sort(&byAlignAndSize{fields, alignofs, sizeofs})
	return sizes.Sizeof(types.NewStruct(fields, nil))
}
开发者ID:patrickToca,项目名称:maligned,代码行数:14,代码来源:maligned.go


示例8: assignStructFieldPaths

func (g *Grapher) assignStructFieldPaths(styp *types.Struct, prefix []string, pkgscope bool) {
	for i := 0; i < styp.NumFields(); i++ {
		f := styp.Field(i)
		path := append(append([]string{}, prefix...), f.Name())
		g.paths[f] = path

		g.exported[f] = ast.IsExported(f.Name())
		g.pkgscope[f] = pkgscope

		// recurse to anonymous structs (named structs are assigned directly)
		// TODO(sqs): handle arrays of structs, etc.
		if styp, ok := derefType(f.Type()).(*types.Struct); ok {
			g.assignStructFieldPaths(styp, path, pkgscope)
		}
	}
}
开发者ID:ildarisaev,项目名称:srclib-go,代码行数:16,代码来源:scope.go


示例9: fieldOffset

func fieldOffset(str *types.Struct, fldNum int) int64 {
	fieldList := make([]*types.Var, str.NumFields())
	for f := 0; f < str.NumFields(); f++ {
		fieldList[f] = str.Field(f)
	}
	return haxeStdSizes.Offsetsof(fieldList)[fldNum]
}
开发者ID:henrylee2cn,项目名称:tardisgo,代码行数:7,代码来源:offsets.go


示例10: processFields

// Returns which field index is an embedded storable.Document, or -1 if none.
func (p *Processor) processFields(s *types.Struct, done []*types.Struct) (base int, fields []*Field) {
	c := s.NumFields()

	base = -1
	fields = make([]*Field, 0)

	for i := 0; i < c; i++ {
		f := s.Field(i)
		if !f.Exported() {
			continue
		}

		t := reflect.StructTag(s.Tag(i))
		if f.Type().String() == BaseDocument {
			base = i
		}

		field := NewField(f.Name(), f.Type().Underlying().String(), t)
		field.CheckedNode = f
		str := p.tryGetStruct(f.Type())
		if f.Type().String() != BaseDocument && str != nil {
			field.Type = getStructType(f.Type())

			d := false
			for _, v := range done {
				if v == str {
					d = true
					break
				}
			}
			if !d {
				_, subfs := p.processFields(str, append(done, str))
				field.SetFields(subfs)
			}
		}

		fields = append(fields, field)
	}

	return base, fields
}
开发者ID:vsouza,项目名称:storable,代码行数:42,代码来源:processor.go


示例11: findStructFields

//iterate over a struct's fields recursively and add its fields to the candidate list
func findStructFields(str *types.Struct, prefix string, fset *token.FileSet) []UnexportCandidate {
	candidates := []UnexportCandidate{}
	for i := 0; i < str.NumFields(); i++ {
		field := str.Field(i)
		if !field.Exported() || field.Anonymous() {
			continue
		}
		// Tags are a likely indicator that this field is used by something
		// like json or xml that uses reflection. Skip it to be safe.
		// TODO: override flag? whitelist?
		if str.Tag(i) != "" {
			continue
		}
		candidate := UnexportCandidate{field.Name(), prefix + "." + field.Name(), fset.Position(field.Pos())}
		candidates = append(candidates, candidate)
		if nested, ok := field.Type().(*types.Struct); ok {
			candidates = append(candidates, findStructFields(nested, candidate.DisplayName, fset)...)
		}
	}
	return candidates
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:22,代码来源:main.go


示例12: Struct

func Struct(path string, st reflect.StructTag, u *types.Struct, named *types.Named) IObj {
	rv := IStruct{}
	rv.name = strings.Split(st.Get("json"), ",")[0]
	rv.typ = getname(named, u)
	rv.description = st.Get("description")
	rv.path = pathAppend(path, rv.name)

	for i := 0; i < u.NumFields(); i++ {
		rv2 := dump(rv.path, u.Field(i).Type(), reflect.StructTag(u.Tag(i)))
		if rv2 == nil {
			continue
		}
		if st, ok := rv2.(IStruct); ok && st.name == "" {
			for _, j := range st.items {
				rv.items = append(rv.items, j)
			}
		} else {
			rv.items = append(rv.items, rv2)
		}
	}

	return rv
}
开发者ID:johan--,项目名称:kube-annotator,代码行数:23,代码来源:intermediate.go


示例13: processFields

func (p *Processor) processFields(s *types.Struct) int {
	c := s.NumFields()

	base := -1
	fields := make([]*Field, 0)
	if _, ok := p.fieldsForStr[s]; !ok {
		p.fieldsForStr[s] = &fields
	}

	for i := 0; i < c; i++ {
		f := s.Field(i)
		if !f.Exported() {
			continue
		}

		t := reflect.StructTag(s.Tag(i))
		if f.Type().String() == BaseDocument {
			base = i
		}

		field := NewField(f.Name(), f.Type().Underlying().String(), t)
		str := p.tryGetStruct(f.Type())
		if f.Type().String() != BaseDocument && str != nil {
			field.Type = getStructType(f.Type())
			field.CheckedNode = f
			_, ok := p.fieldsForStr[str]
			if !ok {
				p.processFields(str)
			}
		}

		fields = append(fields, field)
	}

	return base
}
开发者ID:dripolles,项目名称:storable,代码行数:36,代码来源:processor.go



注:本文中的golang.org/x/tools/go/types.Struct类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.Tuple类代码示例发布时间:2022-05-28
下一篇:
Golang types.Slice类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap