mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
compiler: refactor typeinfo functions
This commit is contained in:
parent
b9b1066435
commit
70d0ff869d
4 changed files with 93 additions and 114 deletions
|
@ -205,50 +205,6 @@ func isBuiltin(expr ast.Expr) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (c *codegen) isCompoundArrayType(t ast.Expr) bool {
|
||||
switch s := t.(type) {
|
||||
case *ast.ArrayType:
|
||||
return true
|
||||
case *ast.Ident:
|
||||
arr, ok := c.typeInfo.Types[s].Type.Underlying().(*types.Slice)
|
||||
return ok && !isByte(arr.Elem())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isByte(t types.Type) bool {
|
||||
e, ok := t.(*types.Basic)
|
||||
return ok && e.Kind() == types.Byte
|
||||
}
|
||||
|
||||
func (c *codegen) isStructType(t ast.Expr) (int, bool) {
|
||||
switch s := t.(type) {
|
||||
case *ast.StructType:
|
||||
return s.Fields.NumFields(), true
|
||||
case *ast.Ident:
|
||||
st, ok := c.typeInfo.Types[s].Type.Underlying().(*types.Struct)
|
||||
if ok {
|
||||
return st.NumFields(), true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func isByteArray(lit *ast.CompositeLit, tInfo *types.Info) bool {
|
||||
if len(lit.Elts) == 0 {
|
||||
if typ, ok := lit.Type.(*ast.ArrayType); ok {
|
||||
if name, ok := typ.Elt.(*ast.Ident); ok {
|
||||
return name.Name == "byte" || name.Name == "uint8"
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
typ := tInfo.Types[lit.Elts[0]].Type.Underlying()
|
||||
return isByte(typ)
|
||||
}
|
||||
|
||||
func isSyscall(fun *funcScope) bool {
|
||||
if fun.selector == nil {
|
||||
return false
|
||||
|
@ -256,11 +212,3 @@ func isSyscall(fun *funcScope) bool {
|
|||
_, ok := syscalls[fun.selector.Name][fun.name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func isByteArrayType(t types.Type) bool {
|
||||
return t.String() == "[]byte"
|
||||
}
|
||||
|
||||
func isStringType(t types.Type) bool {
|
||||
return t.String() == "string"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue