1 Star 1 Fork 0

wzshiming/gotype

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
types_value_bind.go 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
package gotype
func newTypeValueBind(typ, val Type, info *info) Type {
switch typ.Kind() {
case Struct:
if v, ok := val.(*typeValuePairs); ok {
nt := &typeStruct{}
fl := typ.NumField()
for i := 0; i != fl; i++ {
f := typ.Field(i)
name := f.Name()
b := f
if val, ok := v.li.Search(name); ok {
b = newTypeValueBind(f, val, info)
}
nt.fields = append(nt.fields, b)
}
return nt
}
case Declaration:
name := typ.Name()
t := newTypeValueBind(typ.Declaration(), val, info)
if typ.Origin() != nil {
t = newTypeOrigin(t, typ.Origin(), info, typ.Doc(), typ.Comment())
}
return newDeclaration(name, t)
}
return newValueBind(typ, val.Value)
}
func newValueBind(typ Type, valfunc func() string) *typeValueBind {
if tv, ok := typ.(*typeValueBind); ok {
return newValueBind(tv.Type, tv.Value)
}
return &typeValueBind{
Type: typ,
valfunc: valfunc,
}
}
func newEvalBind(val Type, index int64, info *info) Type {
ori := val.Origin()
val = newValueBind(val, func() string {
v, err := constantEval(ori, int64(index), info)
if err != nil {
return ""
}
return v.ExactString()
})
return val
}
type typeValueBind struct {
Type
valfunc func() string
val string
}
func (t *typeValueBind) Value() string {
if t.val == "" {
t.val = t.valfunc()
}
return t.val
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wzshiming/gotype.git
git@gitee.com:wzshiming/gotype.git
wzshiming
gotype
gotype
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385