本文整理汇总了Golang中go/types.Struct类的典型用法代码示例。如果您正苦于以下问题:Golang Struct类的具体用法?Golang Struct怎么用?Golang Struct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Struct类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: findClass
func findClass(typ types.Type) (class Class) {
named, ok := typ.(*types.Named)
if !ok {
return Uninterested
}
var struc *types.Struct
if struc, ok = named.Underlying().(*types.Struct); !ok {
return Uninterested
}
for i := 0; i < struc.NumFields(); i++ {
f := struc.Field(i)
switch {
case !f.Anonymous():
continue
case f.Name() == "Base":
return ModelStruct
case f.Name() == "List":
return ListStruct
}
}
return Uninterested
}
开发者ID:wingyplus,项目名称:omise-go,代码行数:25,代码来源:extract_jobs.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:camlistore,项目名称:camlistore,代码行数: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:snyderep,项目名称:pongish,代码行数: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:Harvey-OS,项目名称:go,代码行数: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:pankona,项目名称:mobile,代码行数:11,代码来源:types.go
示例6: 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:mdempsky,项目名称:maligned,代码行数:14,代码来源:maligned.go
示例7: fieldList
func (p *exporter) fieldList(t *types.Struct) {
if trace && t.NumFields() > 0 {
p.tracef("fields {>\n")
defer p.tracef("<\n} ")
}
p.int(t.NumFields())
for i := 0; i < t.NumFields(); i++ {
if trace && i > 0 {
p.tracef("\n")
}
p.field(t.Field(i))
p.string(t.Tag(i))
}
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:15,代码来源:bexport.go
示例8: convertStruct
func (c *converter) convertStruct(v *gotypes.Struct) *types.Struct {
if v == nil {
return nil
}
if v, ok := c.converted[v]; ok {
return v.(*types.Struct)
}
fields := make([]*types.Var, 0, v.NumFields())
tags := make([]string, 0, v.NumFields())
for i := 0; i < v.NumFields(); i++ {
fields = append(fields, c.convertVar(v.Field(i)))
tags = append(tags, v.Tag(i))
}
ret := types.NewStruct(fields, tags)
c.converted[v] = ret
return ret
}
开发者ID:tcard,项目名称:sgo,代码行数:17,代码来源:importer.go
示例9: emitStructType
func (w *Walker) emitStructType(name string, typ *types.Struct) {
typeStruct := fmt.Sprintf("type %s struct", name)
w.emitf(typeStruct)
defer w.pushScope(typeStruct)()
for i := 0; i < typ.NumFields(); i++ {
f := typ.Field(i)
if !f.Exported() {
continue
}
typ := f.Type()
if f.Anonymous() {
w.emitf("embedded %s", w.typeString(typ))
continue
}
w.emitf("%s %s", f.Name(), w.typeString(typ))
}
}
开发者ID:pombredanne,项目名称:goapi,代码行数:18,代码来源:goapi.go
示例10: embeddedObjcTypes
// embeddedObjcTypes returns the possible empty list of Objc types embedded
// in the given struct type.
func embeddedObjcTypes(t *types.Struct) []string {
typeSet := make(map[string]struct{})
var typs []string
for i := 0; i < t.NumFields(); i++ {
f := t.Field(i)
if !f.Exported() {
continue
}
if ft := f.Type(); isObjcType(ft) {
name := ft.(*types.Named).Obj().Name()
if _, exists := typeSet[name]; !exists {
typeSet[name] = struct{}{}
typs = append(typs, name)
}
}
}
return typs
}
开发者ID:pankona,项目名称:mobile,代码行数:20,代码来源:genobjc.go
示例11: embeddedJavaClasses
// embeddedJavaClasses returns the possible empty list of Java types embedded
// in the given struct type.
func embeddedJavaClasses(t *types.Struct) []string {
clsSet := make(map[string]struct{})
var classes []string
for i := 0; i < t.NumFields(); i++ {
f := t.Field(i)
if !f.Exported() {
continue
}
if t := f.Type(); isJavaType(t) {
cls := classNameFor(t)
if _, exists := clsSet[cls]; !exists {
clsSet[cls] = struct{}{}
classes = append(classes, cls)
}
}
}
return classes
}
开发者ID:pankona,项目名称:mobile,代码行数:20,代码来源:genjava.go
示例12: findClass
func findClass(typ types.Type) (class Class) {
named, ok := typ.(*types.Named)
if !ok {
return Uninterested
}
name := named.Obj().Name()
switch name {
case "List", "Base":
return Uninterested
}
for i := 0; i < named.NumMethods(); i++ {
m := named.Method(i)
if m.Name() == "Op" {
return OperationStruct
}
}
var struc *types.Struct
if struc, ok = named.Underlying().(*types.Struct); !ok {
return Uninterested
}
for i := 0; i < struc.NumFields(); i++ {
f := struc.Field(i)
switch {
case !f.Anonymous():
continue
case f.Name() == "Base":
return ModelStruct
case f.Name() == "List":
return ListStruct
}
}
return Uninterested
}
开发者ID:gitter-badger,项目名称:omise-go,代码行数:38,代码来源:extract_jobs.go
示例13: collectFields
func collectFields(fields map[string]string, struc *types.Struct) {
// TODO:
for i := 0; i < struc.NumFields(); i++ {
f, tag := struc.Field(i), struc.Tag(i)
switch {
case f.Anonymous():
if named, ok := f.Type().(*types.Named); ok {
if struc_, ok := named.Underlying().(*types.Struct); ok {
collectFields(fields, struc_)
}
}
case strings.Contains(tag, `pretty:""`):
fields[f.Name()] = inflect.Underscore(f.Name())
}
}
}
开发者ID:wingyplus,项目名称:omise-go,代码行数:18,代码来源:gen_string_job.go
示例14: collectFields
func collectFields(struc *types.Struct) []string {
result := []string{}
for i := 0; i < struc.NumFields(); i++ {
f, tag := struc.Field(i), struc.Tag(i)
switch {
case f.Anonymous():
if named, ok := f.Type().(*types.Named); ok {
if struc_, ok := named.Underlying().(*types.Struct); ok {
result = append(result, collectFields(struc_)...)
}
}
case strings.Contains(tag, `pretty:""`):
result = append(result, f.Name())
}
}
return result
}
开发者ID:gitter-badger,项目名称:omise-go,代码行数:21,代码来源:extract_jobs.go
注:本文中的go/types.Struct类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论